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, this->calculateNextSeqCount(receivedSeqCount));
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 = 0;
45  // Find sequence count if exists, otherwise use 0
46  (void)m_apidSequences.find(apid, seqCount);
47  // Increment sequence count for next call
48  U16 updatedSeqCount = this->calculateNextSeqCount(seqCount);
49 
50  Fw::Success insertStatus = m_apidSequences.insert(apid, updatedSeqCount);
51  if (insertStatus == Fw::Success::SUCCESS) {
52  return seqCount; // Return the current sequence count
53  }
54 
55  this->log_WARNING_HI_ApidTableFull(apid);
56  return SEQUENCE_COUNT_ERROR;
57 }
58 
59 void ApidManager::setNextSeqCount(ComCfg::Apid::T apid, U16 seqCount) {
60  Fw::Success insertStatus = m_apidSequences.insert(apid, seqCount);
61  FW_ASSERT(insertStatus == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(apid));
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.