F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComAggregator.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComAggregator.cpp
3 // \author lestarch
4 // \brief cpp file for ComAggregator component implementation class
5 // ======================================================================
6 
8 
9 namespace Svc {
10 
11 // ----------------------------------------------------------------------
12 // Component construction and destruction
13 // ----------------------------------------------------------------------
14 
15 ComAggregator ::ComAggregator(const char* const compName)
16  : ComAggregatorComponentBase(compName),
17  m_bufferState(Fw::Buffer::OwnershipState::OWNED),
18  m_frameBuffer(m_frameBufferStore, sizeof(m_frameBufferStore)),
19  m_frameSerializer(m_frameBuffer.getSerializer()),
20  m_allow_timeout(false) {}
21 
23 
26  this->comStatusOut_out(0, good);
27 }
28 
29 // ----------------------------------------------------------------------
30 // Handler implementations for typed input ports
31 // ----------------------------------------------------------------------
32 
33 void ComAggregator ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
34  this->aggregationMachine_sendSignal_status(condition);
35 }
36 
37 void ComAggregator ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
38  Svc::ComDataContextPair pair(data, context);
40 }
41 
42 void ComAggregator ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
43  FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
44  this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
45 }
46 
47 void ComAggregator ::timeout_handler(FwIndexType portNum, U32 context) {
48  // Timeout is ignored in WAIT_STATUS state. However, the queue may not process timeout messages until the wait
49  // status is returned because the port chain may be synchronous and downstream components (radio, retry, etc) may
50  // take a long time to complete the transmission of data. This can cause the queue to overflow with messages that
51  // will soon be discarded.
52  //
53  // Therefore, to fix the risk of queue overflow we only queue timeout messages when they would be processed by the
54  // state machine (i.e. in the FILL state). Otherwise, these messages are not queued.
55  //
56  // Behaviorally, this solution will work exactly like the naive implementation with an infinite queue depth, but
57  // prevents queue overflow when using finite queues.
58  if (this->m_allow_timeout) {
60  }
61 }
62 
63 // ----------------------------------------------------------------------
64 // Implementations for internal state machine actions
65 // ----------------------------------------------------------------------
66 
67 void ComAggregator ::Svc_AggregationMachine_action_doClear(SmId smId, Svc_AggregationMachine::Signal signal) {
68  this->m_allow_timeout = true; // Allow timeout messages in FILL state
69  this->m_frameSerializer.resetSer();
70  this->m_frameBuffer.setSize(sizeof(this->m_frameBufferStore));
71  this->m_lastContext = ComCfg::FrameContext();
72  if (this->m_held.get_data().isValid()) {
73  // Fill the held data
74  this->Svc_AggregationMachine_action_doFill(smId, signal, this->m_held);
75  this->m_held = Svc::ComDataContextPair();
76  }
77 }
78 
79 void ComAggregator ::Svc_AggregationMachine_action_doFill(SmId smId,
81  const Svc::ComDataContextPair& value) {
82  Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom(
85  this->m_lastContext = value.get_context();
87  // Return port does not alter data and thus const-cast is safe
88  this->dataReturnOut_out(0, const_cast<Fw::Buffer&>(value.get_data()), value.get_context());
89  this->comStatusOut_out(0, good);
90 }
91 
92 void ComAggregator ::Svc_AggregationMachine_action_doSend(SmId smId, Svc_AggregationMachine::Signal signal) {
93  // Send only when the buffer will be valid
94  if (this->m_frameSerializer.getSize() > 0) {
95  this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
96  this->m_frameBuffer.setSize(this->m_frameSerializer.getSize());
97  this->m_allow_timeout = false; // Timeout messages should be discarded in WAIT_STATUS state
98  this->dataOut_out(0, this->m_frameBuffer, this->m_lastContext);
99  }
100 }
101 
102 void ComAggregator ::Svc_AggregationMachine_action_doHold(SmId smId,
104  const Svc::ComDataContextPair& value) {
105  FW_ASSERT(not this->m_held.get_data().isValid());
106  this->m_held = value;
107 }
108 
109 void ComAggregator ::Svc_AggregationMachine_action_assertNoStatus(SmId smId, Svc_AggregationMachine::Signal signal) {
110  // Status is not possible in this state, confirm by assertion
111  FW_ASSERT(0);
112 }
113 
114 // ----------------------------------------------------------------------
115 // Implementations for internal state machine guards
116 // ----------------------------------------------------------------------
117 
118 bool ComAggregator ::Svc_AggregationMachine_guard_isFull(SmId smId,
120  const Svc::ComDataContextPair& value) const {
122  const FwSizeType remaining = this->m_frameSerializer.getCapacity() - this->m_frameSerializer.getSize();
123  return (remaining < value.get_data().getSize());
124 }
125 
126 bool ComAggregator ::Svc_AggregationMachine_guard_willFill(SmId smId,
128  const Svc::ComDataContextPair& value) const {
130  const FwSizeType remaining = this->m_frameSerializer.getCapacity() - this->m_frameSerializer.getSize();
131  return (remaining == value.get_data().getSize());
132 }
133 
134 bool ComAggregator ::Svc_AggregationMachine_guard_isNotEmpty(SmId smId, Svc_AggregationMachine::Signal signal) const {
135  return this->m_frameSerializer.getSize() > 0;
136 }
137 
138 bool ComAggregator ::Svc_AggregationMachine_guard_isGood(SmId smId,
140  const Fw::Success& value) const {
141  return value == Fw::Success::SUCCESS;
142 }
143 
144 } // namespace Svc
Serialization/Deserialization operation was successful.
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatusOut.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
Representing success.
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Definition: Buffer.cpp:75
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
Serializable::SizeType getSize() const override
Get current buffer size.
void aggregationMachine_sendSignal_status(const Fw::Success &value)
Send signal status to state machine aggregationMachine.
U8 * getData() const
Definition: Buffer.cpp:56
The buffer is currently not owned.
SerializeStatus
forward declaration for string
~ComAggregator()
Destroy ComAggregator object.
void preamble() override
A function that will be called before the event loop is entered.
Serializable::SizeType getCapacity() const
Get buffer capacity.
Omit length from serialization.
bool isValid() const
Definition: Buffer.cpp:52
void resetSer() override
Reset serialization pointer to beginning of buffer.
ComCfg::FrameContext & get_context()
Get member context.
FwSizeType getSize() const
Definition: Buffer.cpp:60
Auto-generated base for ComAggregator component.
void aggregationMachine_sendSignal_timeout()
Send signal timeout to state machine aggregationMachine.
Fw::Buffer & get_data()
Get member data.
ComAggregator(const char *const compName)
Construct ComAggregator object.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
The buffer is currently owned.
Implementation of malloc based allocator.
FpySequencer_SequencerStateMachineStateMachineBase::Signal Signal
#define FW_ASSERT(...)
Definition: Assert.hpp:14
void aggregationMachine_sendSignal_fill(const Svc::ComDataContextPair &value)
Send signal fill to state machine aggregationMachine.
Success/Failure.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.