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 
22 
25  this->comStatusOut_out(0, good);
26 }
27 
28 // ----------------------------------------------------------------------
29 // Handler implementations for typed input ports
30 // ----------------------------------------------------------------------
31 
32 void ComAggregator ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
33  this->aggregationMachine_sendSignal_status(condition);
34 }
35 
36 void ComAggregator ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
37  Svc::ComDataContextPair pair(data, context);
39 }
40 
41 void ComAggregator ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
42  FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::NOT_OWNED);
43  this->m_bufferState = Fw::Buffer::OwnershipState::OWNED;
44 }
45 
46 void ComAggregator ::timeout_handler(FwIndexType portNum, U32 context) {
48 }
49 
50 // ----------------------------------------------------------------------
51 // Implementations for internal state machine actions
52 // ----------------------------------------------------------------------
53 
54 void ComAggregator ::Svc_AggregationMachine_action_doClear(SmId smId, Svc_AggregationMachine::Signal signal) {
55  this->m_frameSerializer.resetSer();
56  this->m_frameBuffer.setSize(sizeof(this->m_frameBufferStore));
57  if (this->m_held.get_data().isValid()) {
58  // Fill the held data
59  this->Svc_AggregationMachine_action_doFill(smId, signal, this->m_held);
60  this->m_held = Svc::ComDataContextPair();
61  }
62 }
63 
64 void ComAggregator ::Svc_AggregationMachine_action_doFill(SmId smId,
66  const Svc::ComDataContextPair& value) {
67  Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom(
70  this->m_lastContext = value.get_context();
72  // Return port does not alter data and thus const-cast is safe
73  this->dataReturnOut_out(0, const_cast<Fw::Buffer&>(value.get_data()), value.get_context());
74  this->comStatusOut_out(0, good);
75 }
76 
77 void ComAggregator ::Svc_AggregationMachine_action_doSend(SmId smId, Svc_AggregationMachine::Signal signal) {
78  // Send only when the buffer will be valid
79  if (this->m_frameSerializer.getSize() > 0) {
80  this->m_bufferState = Fw::Buffer::OwnershipState::NOT_OWNED;
81  this->m_frameBuffer.setSize(this->m_frameSerializer.getSize());
82  this->dataOut_out(0, this->m_frameBuffer, this->m_lastContext);
83  }
84 }
85 
86 void ComAggregator ::Svc_AggregationMachine_action_doHold(SmId smId,
88  const Svc::ComDataContextPair& value) {
89  FW_ASSERT(not this->m_held.get_data().isValid());
90  this->m_held = value;
91 }
92 
93 void ComAggregator ::Svc_AggregationMachine_action_assertNoStatus(SmId smId, Svc_AggregationMachine::Signal signal) {
94  // Status is not possible in this state, confirm by assertion
95  FW_ASSERT(0);
96 }
97 
98 // ----------------------------------------------------------------------
99 // Implementations for internal state machine guards
100 // ----------------------------------------------------------------------
101 
102 bool ComAggregator ::Svc_AggregationMachine_guard_isFull(SmId smId,
104  const Svc::ComDataContextPair& value) const {
106  const FwSizeType remaining = this->m_frameSerializer.getCapacity() - this->m_frameSerializer.getSize();
107  return (remaining <= value.get_data().getSize());
108 }
109 
110 bool ComAggregator ::Svc_AggregationMachine_guard_isNotEmpty(SmId smId, Svc_AggregationMachine::Signal signal) const {
111  return this->m_frameSerializer.getSize() > 0;
112 }
113 
114 bool ComAggregator ::Svc_AggregationMachine_guard_isGood(SmId smId,
116  const Fw::Success& value) const {
117  return value == Fw::Success::SUCCESS;
118 }
119 
120 } // 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.