CCSDSPack
C++ Library for CCSDS Space Packet manipulation. i.e. generation, extraction, analisys and more
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
CCSDS::Validator Class Reference

Handles validation of CCSDS packets. More...

#include <CCSDSValidator.h>

Collaboration diagram for CCSDS::Validator:
[legend]

Public Member Functions

 Validator ()=default
 Default constructor.
 
 ~Validator ()=default
 Default destructor.
 
 Validator (const Packet &templatePacket)
 Constructs a Validator with a template packet.
 
void setTemplatePacket (const Packet &templatePacket)
 Sets the template packet for validation.
 
void configure (bool validatePacketCoherence, bool validateSequenceCount, bool validateAgainstTemplate)
 Configures validation options.
 
bool validate (const Packet &packet)
 Validates a given packet.
 
std::vector< bool > getReport () const
 Returns a report of performed validation checks.
 
void clear ()
 Clears the validator, resets counter.
 

Private Attributes

Packet m_templatePacket
 Template packet used for validation.
 
bool m_validatePacketCoherence {true}
 Whether to validate packet length and CRC (default is true).
 
bool m_validateAgainstTemplate {false}
 Whether to validate against the template packet (default is false).
 
bool m_validateSegmentedCount {true}
 Whether to validate the count of segmented packets.
 
uint16_t m_sequenceCounter {1}
 Counter for segmented Packets.
 
std::vector< bool > m_report {}
 List of boolean results representing performed checks.
 
size_t m_reportSize {6}
 Expected size of the validation report.
 
CRC16Config m_CRCConfig
 

Detailed Description

Handles validation of CCSDS packets.

The Validator class checks packet coherence and compares packets against a template.

Definition at line 14 of file CCSDSValidator.h.

Constructor & Destructor Documentation

◆ Validator() [1/2]

CCSDS::Validator::Validator ( )
default

Default constructor.

◆ ~Validator()

CCSDS::Validator::~Validator ( )
default

Default destructor.

◆ Validator() [2/2]

CCSDS::Validator::Validator ( const Packet templatePacket)
inlineexplicit

Constructs a Validator with a template packet.

Parameters
templatePacketThe packet template to use for validation.

Definition at line 26 of file CCSDSValidator.h.

26 : m_templatePacket(templatePacket) {
27 };
Packet m_templatePacket
Template packet used for validation.

Member Function Documentation

◆ clear()

void CCSDS::Validator::clear ( )

Clears the validator, resets counter.

Definition at line 62 of file CCSDSValidator.cpp.

62 {
64 m_report.clear();
67}
void setUpdatePacketEnable(bool enable)
needs to be called as soon as possible, probably also from constructor.
uint16_t m_sequenceCounter
Counter for segmented Packets.
std::vector< bool > m_report
List of boolean results representing performed checks.

◆ configure()

void CCSDS::Validator::configure ( bool  validatePacketCoherence,
bool  validateSequenceCount,
bool  validateAgainstTemplate 
)

Configures validation options.

Parameters
validatePacketCoherenceEnables/disables packet coherence validation.
validateSequenceCount
validateAgainstTemplateEnables/disables comparison against the template.

Definition at line 4 of file CCSDSValidator.cpp.

4 {
5 m_validatePacketCoherence = validatePacketCoherence;
6 m_validateAgainstTemplate = validateAgainstTemplate;
7}
bool m_validatePacketCoherence
Whether to validate packet length and CRC (default is true).
bool m_validateAgainstTemplate
Whether to validate against the template packet (default is false).
Here is the caller graph for this function:

◆ getReport()

std::vector< bool > CCSDS::Validator::getReport ( ) const
inline

Returns a report of performed validation checks.

  • Packet Coherence:
    • index [0]: Data Field Length Header declared equals actual data field length
    • index [1]: CRC15 value declared equals calculated CRC16 of the data field
    • index [2]: Sequence Control flags and count coherence
    • index [3]: Sequence Control count coherence (incremental start from 1)
  • Compare Against Template:
    • index [4]: Identification and Version in packet matches template
    • index [5]: Template Sequence Control match
Returns
A vector of boolean results for each performed check.

Definition at line 64 of file CCSDSValidator.h.

64{ return m_report; }

◆ setTemplatePacket()

void CCSDS::Validator::setTemplatePacket ( const Packet templatePacket)
inline

Sets the template packet for validation.

Parameters
templatePacketThe new template packet.

Definition at line 33 of file CCSDSValidator.h.

33{ m_templatePacket = templatePacket; }
Here is the caller graph for this function:

◆ validate()

bool CCSDS::Validator::validate ( const Packet packet)

Validates a given packet.

Parameters
packetThe packet to validate.
Returns
True if the packet passes validation, otherwise false.

Definition at line 9 of file CCSDSValidator.cpp.

9 {
10 m_report.clear();
11 m_report.reserve(m_reportSize);
12 m_report.assign({true, true, true, true, true, true});
13 bool result{true};
14 auto toValidate = packet;
15 toValidate.setUpdatePacketEnable(false);
16 auto toValidateHeader = toValidate.getPrimaryHeader();
17 const auto toValidateHeaderData = toValidateHeader.serialize();
18 // auto coherence checks
19 const auto dataFieldBytes = toValidate.getFullDataFieldBytes();
20 const auto dataFieldBytesSize = dataFieldBytes.size();
21
22 // test CRC therefore full data field coherence
24 m_report[0] = toValidateHeader.getDataLength() == dataFieldBytesSize;
25 result &= m_report[0];
26 const auto calcCRC = crc16(dataFieldBytes);
27 m_report[1] = calcCRC == toValidate.getCRC();
28 result &= m_report[1];
29 if (toValidateHeader.getSequenceFlags() == UNSEGMENTED) {
30 m_report[2] = toValidateHeader.getSequenceCount() == 0;
31 } else {
32 m_report[2] = toValidateHeader.getSequenceCount() > 0;
34 if (toValidateHeader.getSequenceFlags() == FIRST_SEGMENT) {
35 m_report[3] = toValidateHeader.getSequenceCount() == 1;
36 }else {
37 m_report[3] = toValidateHeader.getSequenceCount() == m_sequenceCounter;
38 }
40 }
41 }
42 result &= m_report[2];
43 result &= m_report[3];
44 }
45
48 auto templateHeader = m_templatePacket.getPrimaryHeader();
49 const auto templateHeaderData = templateHeader.serialize();
50 m_report[4] = templateHeaderData[0] == toValidateHeaderData[0] && templateHeaderData[1] == toValidateHeaderData[1];
51 result &= m_report[4];
52 if (templateHeader.getSequenceFlags() == UNSEGMENTED) {
53 m_report[5] = toValidateHeader.getSequenceFlags() == UNSEGMENTED;
54 } else {
55 m_report[5] = toValidateHeader.getSequenceFlags() != UNSEGMENTED;
56 }
57 result &= m_report[5];
58 }
59 return result;
60}
uint16_t crc16(const std::vector< uint8_t > &data, uint16_t polynomial=0x1021, uint16_t initialValue=0xFFFF, uint16_t finalXorValue=0x0000)
Computes the CRC-16 checksum for a given data vector with configurable parameters.
std::vector< uint8_t > serialize()
decomposes the Primary header class and returns it as a vector of bytes.
CCSDS::Header & getPrimaryHeader()
returns the CCSDS packet's Primary Header.
size_t m_reportSize
Expected size of the validation report.
bool m_validateSegmentedCount
Whether to validate the count of segmented packets.
@ UNSEGMENTED
11 Complete packet in a single frame.
Definition CCSDSHeader.h:23
@ FIRST_SEGMENT
01 First segment of a new packet.
Definition CCSDSHeader.h:21
Here is the call graph for this function:

Member Data Documentation

◆ m_CRCConfig

CRC16Config CCSDS::Validator::m_CRCConfig
private

Definition at line 80 of file CCSDSValidator.h.

◆ m_report

std::vector<bool> CCSDS::Validator::m_report {}
private

List of boolean results representing performed checks.

Definition at line 78 of file CCSDSValidator.h.

78{};

◆ m_reportSize

size_t CCSDS::Validator::m_reportSize {6}
private

Expected size of the validation report.

Definition at line 79 of file CCSDSValidator.h.

79{6};

◆ m_sequenceCounter

uint16_t CCSDS::Validator::m_sequenceCounter {1}
private

Counter for segmented Packets.

Definition at line 77 of file CCSDSValidator.h.

77{1};

◆ m_templatePacket

Packet CCSDS::Validator::m_templatePacket
private

Template packet used for validation.

Definition at line 73 of file CCSDSValidator.h.

◆ m_validateAgainstTemplate

bool CCSDS::Validator::m_validateAgainstTemplate {false}
private

Whether to validate against the template packet (default is false).

Definition at line 75 of file CCSDSValidator.h.

75{false};

◆ m_validatePacketCoherence

bool CCSDS::Validator::m_validatePacketCoherence {true}
private

Whether to validate packet length and CRC (default is true).

Definition at line 74 of file CCSDSValidator.h.

74{true};

◆ m_validateSegmentedCount

bool CCSDS::Validator::m_validateSegmentedCount {true}
private

Whether to validate the count of segmented packets.

Definition at line 76 of file CCSDSValidator.h.

76{true};

The documentation for this class was generated from the following files: