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  const U16 expectedSequenceCount = this->getAndIncrementSeqCount(apid);
26  if (expectedSequenceCount == SEQUENCE_COUNT_ERROR) {
27  // APID could not be tracked (table full); nothing to validate or sync against
28  return receivedSeqCount;
29  }
30  if (receivedSeqCount != expectedSequenceCount) {
31  // Likely a packet was dropped or out of order
32  this->log_WARNING_LO_UnexpectedSequenceCount(receivedSeqCount, expectedSequenceCount);
33  // Sync onboard count to what was received so counting can keep going. Insert cannot fail:
34  // getAndIncrementSeqCount above inserted the APID already, we would have returned early
35  // due to SEQUENCE_COUNT_ERROR
36  const Fw::Success insertStatus = m_apidSequences.insert(apid, this->calculateNextSeqCount(receivedSeqCount));
37  FW_ASSERT(insertStatus == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(apid));
38  }
39  return receivedSeqCount;
40 }
41 
42 U16 ApidManager ::getApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::Apid& apid, U16 unused) {
43  return this->getAndIncrementSeqCount(apid);
44 }
45 
46 // ----------------------------------------------------------------------
47 // Helpers
48 // ----------------------------------------------------------------------
49 
50 U16 ApidManager ::getAndIncrementSeqCount(ComCfg::Apid::T apid) {
51  U16 seqCount = 0;
52  // Find current sequence count if APID is tracked; otherwise default to 0 (first count for a new APID)
53  (void)m_apidSequences.find(apid, seqCount);
54  // Store the next sequence count for this APID. If the APID is not yet tracked, this
55  // also registers it; insert can only fail when registering a new APID into a full table.
56  const Fw::Success insertStatus = m_apidSequences.insert(apid, this->calculateNextSeqCount(seqCount));
57  if (insertStatus != Fw::Success::SUCCESS) {
58  this->log_WARNING_HI_ApidTableFull(apid);
59  return SEQUENCE_COUNT_ERROR;
60  }
61  return seqCount;
62 }
63 
64 U16 ApidManager::calculateNextSeqCount(const U16 seqCount) const {
65  return static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth));
66 }
67 
68 } // namespace Ccsds
69 } // namespace Svc
static constexpr U16 SEQUENCE_COUNT_ERROR
Definition: ApidManager.hpp:40
Representing success.
Success insert(const K &key, const V &value) override
Definition: ArrayMap.hpp:97
T
The raw enum type.
Definition: ApidEnumAc.hpp:31
ApidManager(const char *const compName)
Construct ApidManager object.
Definition: ApidManager.cpp:18
void log_WARNING_HI_ApidTableFull(U16 invalidApidValue) const
void log_WARNING_LO_UnexpectedSequenceCount(U16 transmitted, U16 expected) const
Success find(const K &key, V &value) const override
Definition: ArrayMap.hpp:81
PlatformIndexType FwIndexType
RateGroupDivider component implementation.
Auto-generated base for ApidManager component.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
APIDs are 11 bits in the Space Packet protocol, so we use U16. Max value 7FF.
Definition: ApidEnumAc.hpp:17
Success/Failure.