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 (receivedSeqCount != expectedSequenceCount) {
27  // Likely a packet was dropped or out of order
28  this->log_WARNING_LO_UnexpectedSequenceCount(receivedSeqCount, expectedSequenceCount);
29  // Sync onboard count to what was received so counting can keep going. Insert cannot fail:
30  // getAndIncrementSeqCount above inserted the APID already (asserting on failure)
31  const Fw::Success insertStatus = m_apidSequences.insert(apid, this->calculateNextSeqCount(receivedSeqCount));
32  FW_ASSERT(insertStatus == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(apid));
33  }
34  return receivedSeqCount;
35 }
36 
37 U16 ApidManager ::getApidSeqCountIn_handler(FwIndexType portNum, const ComCfg::Apid& apid, U16 unused) {
38  return this->getAndIncrementSeqCount(apid);
39 }
40 
41 // ----------------------------------------------------------------------
42 // Helpers
43 // ----------------------------------------------------------------------
44 
45 U16 ApidManager ::getAndIncrementSeqCount(ComCfg::Apid::T apid) {
46  U16 seqCount = 0;
47  // Find current sequence count if APID is tracked; otherwise default to 0 (first count for a new APID)
48  (void)m_apidSequences.find(apid, seqCount);
49  // Store the next sequence count for this APID. If the APID is not yet tracked, this
50  // also registers it.
51  // Insert should never fail because the apid should be a valid enum value and
52  // the table should be large enough to hold all the enum values
53  const Fw::Success insertStatus = m_apidSequences.insert(apid, this->calculateNextSeqCount(seqCount));
54  FW_ASSERT(insertStatus == Fw::Success::SUCCESS);
55  return seqCount;
56 }
57 
58 U16 ApidManager::calculateNextSeqCount(const U16 seqCount) const {
59  return static_cast<U16>((seqCount + 1) % (1 << SpacePacketSubfields::SeqCountWidth));
60 }
61 
62 } // namespace Ccsds
63 } // namespace Svc
Representing success.
Success insert(const K &key, const V &value) override
Definition: ArrayMap.hpp:97
T
The raw enum type.
Definition: ApidEnumAc.hpp:32
ApidManager(const char *const compName)
Construct ApidManager object.
Definition: ApidManager.cpp:18
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:18
Success/Failure.