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  if (this->m_held.get_data().isValid()) {
72  // Fill the held data
73  this->Svc_AggregationMachine_action_doFill(smId, signal, this->m_held);
74  this->m_held = Svc::ComDataContextPair();
75  }
76 }
77 
78 void ComAggregator ::Svc_AggregationMachine_action_doFill(SmId smId,
80  const Svc::ComDataContextPair& value) {
81  Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom(
84  this->m_lastContext = value.get_context();
86  // Return port does not alter data and thus const-cast is safe
87  this->dataReturnOut_out(0, const_cast<Fw::Buffer&>(value.get_data()), value.get_context());
88  this->comStatusOut_out(0, good);
89 }
90 
91 void ComAggregator ::Svc_AggregationMachine_action_doSend(SmId smId, Svc_AggregationMachine::Signal signal) {
92  // Send only when the buffer will be valid
93  if (this->m_frameSerializer.getSize() > 0) {
94  this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
95  this->m_frameBuffer.setSize(this->m_frameSerializer.getSize());
96  this->m_allow_timeout = false; // Timeout messages should be discarded in WAIT_STATUS state
97  this->dataOut_out(0, this->m_frameBuffer, this->m_lastContext);
98  }
99 }
100 
101 void ComAggregator ::Svc_AggregationMachine_action_doHold(SmId smId,
103  const Svc::ComDataContextPair& value) {
104  FW_ASSERT(not this->m_held.get_data().isValid());
105  this->m_held = value;
106 }
107 
108 void ComAggregator ::Svc_AggregationMachine_action_assertNoStatus(SmId smId, Svc_AggregationMachine::Signal signal) {
109  // Status is not possible in this state, confirm by assertion
110  FW_ASSERT(0);
111 }
112 
113 // ----------------------------------------------------------------------
114 // Implementations for internal state machine guards
115 // ----------------------------------------------------------------------
116 
117 bool ComAggregator ::Svc_AggregationMachine_guard_isFull(SmId smId,
119  const Svc::ComDataContextPair& value) const {
121  const FwSizeType remaining = this->m_frameSerializer.getCapacity() - this->m_frameSerializer.getSize();
122  return (remaining < value.get_data().getSize());
123 }
124 
125 bool ComAggregator ::Svc_AggregationMachine_guard_willFill(SmId smId,
127  const Svc::ComDataContextPair& value) const {
129  const FwSizeType remaining = this->m_frameSerializer.getCapacity() - this->m_frameSerializer.getSize();
130  return (remaining == value.get_data().getSize());
131 }
132 
133 bool ComAggregator ::Svc_AggregationMachine_guard_isNotEmpty(SmId smId, Svc_AggregationMachine::Signal signal) const {
134  return this->m_frameSerializer.getSize() > 0;
135 }
136 
137 bool ComAggregator ::Svc_AggregationMachine_guard_isGood(SmId smId,
139  const Fw::Success& value) const {
140  return value == Fw::Success::SUCCESS;
141 }
142 
143 } // 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.