F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ApidManager.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ApidManager.cpp
3 // \author thomas-bc
4 // \brief cpp file for ApidManager component implementation class
5 // ======================================================================
6 
9 
10 namespace Svc {
11 
12 namespace CCSDS {
13 
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17 
18 ApidManager ::ApidManager(const char* const compName) : ApidManagerComponentBase(compName) {}
19 
20 // ----------------------------------------------------------------------
21 // Handler implementations for typed input ports
22 // ----------------------------------------------------------------------
23 
24 U16 ApidManager ::validateApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::APID& apid, U16 receivedSeqCount) {
25  U16 expectedSequenceCount = this->getAndIncrementSeqCount(apid);
26  if (receivedSeqCount != expectedSequenceCount && receivedSeqCount != SEQUENCE_COUNT_ERROR) {
27  // Likely a packet was dropped or out of order
28  this->log_WARNING_LO_UnexpectedSequenceCount(receivedSeqCount, expectedSequenceCount);
29  // Synchronize onboard count with received number so that count can keep going
30  this->setNextSeqCount(apid, static_cast<U16>(receivedSeqCount + 1));
31  }
32  return receivedSeqCount;
33 }
34 
35 U16 ApidManager ::getApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::APID& apid, U16 unused) {
36  return this->getAndIncrementSeqCount(apid);
37 }
38 
39 // ----------------------------------------------------------------------
40 // Helpers
41 // ----------------------------------------------------------------------
42 
43 U16 ApidManager ::getAndIncrementSeqCount(ComCfg::APID::T apid) {
44  U16 seqCount = SEQUENCE_COUNT_ERROR; // Default to error value
45  // Search the APID in the sequence table
46  for (U16 i = 0; i < MAX_TRACKED_APIDS; i++) {
47  if (this->m_apidSequences[i].apid == apid) {
48  seqCount = this->m_apidSequences[i].sequenceCount;
49  // Increment entry for next call
50  this->m_apidSequences[i].sequenceCount =
51  static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth));
52  return seqCount; // Return the current sequence count
53  }
54  }
55  // If not found, search for an uninitialized entry to track this APID
56  for (U16 i = 0; i < MAX_TRACKED_APIDS; i++) {
57  if (this->m_apidSequences[i].apid == ComCfg::APID::INVALID_UNINITIALIZED) {
58  this->m_apidSequences[i].apid = apid; // Initialize this entry with the new APID
59  seqCount = this->m_apidSequences[i].sequenceCount; // Entries default to 0 unless otherwise specified
60  // Increment entry for next call
61  this->m_apidSequences[i].sequenceCount =
62  static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth));
63  return seqCount; // Return the initialized sequence count
64  }
65  }
66  this->log_WARNING_HI_ApidTableFull(apid);
67  return SEQUENCE_COUNT_ERROR;
68 }
69 
70 void ApidManager::setNextSeqCount(ComCfg::APID::T apid, U16 seqCount) {
71  for (U16 i = 0; i < MAX_TRACKED_APIDS; i++) {
72  if (this->m_apidSequences[i].apid == apid) {
73  this->m_apidSequences[i].sequenceCount = seqCount;
74  return;
75  }
76  }
77  // This code should not be reachable with the if statement in validateApidSeqCountIn_handler
78  FW_ASSERT(false, static_cast<FwAssertArgType>(apid));
79 }
80 
81 } // namespace CCSDS
82 } // namespace Svc
void log_WARNING_LO_UnexpectedSequenceCount(U16 transmitted, U16 expected) const
void log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
ApidManager(const char *const compName)
Construct ApidManager object.
Definition: ApidManager.cpp:18
T
The raw enum type.
Definition: APIDEnumAc.hpp:31
static constexpr U16 MAX_TRACKED_APIDS
Definition: ApidManager.hpp:38
Auto-generated base for ApidManager component.
PlatformIndexType FwIndexType
APIDs are 11 bits in the Space Packet protocol, so we use U16. Max value 7FF.
Definition: APIDEnumAc.hpp:17
static constexpr U16 SEQUENCE_COUNT_ERROR
Definition: ApidManager.hpp:39
RateGroupDivider component implementation.
Anything equal or higher value is invalid and should not be used.
Definition: APIDEnumAc.hpp:53
#define FW_ASSERT(...)
Definition: Assert.hpp:14