F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
ComAggregator.hpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title ComAggregator.hpp
3 // \author lestarch
4 // \brief hpp file for ComAggregator component implementation class
5 // ======================================================================
6 
7 #ifndef Svc_ComAggregator_HPP
8 #define Svc_ComAggregator_HPP
9 
10 #include <algorithm>
11 #include <atomic>
13 #include "Os/Mutex.hpp"
18 
19 namespace Svc {
20 
22  friend class ComAggregatorTester; // Allow unit test access to private members
23  public:
24  // ----------------------------------------------------------------------
25  // Component construction and destruction
26  // ----------------------------------------------------------------------
27 
29  ComAggregator(const char* const compName
30  );
31 
34 
46  void configure(FwSizeType aggregationSize,
47  bool spanningEnabled,
48  FwEnumStoreType allocationId,
49  Fw::MemAllocator& allocator
50  );
51 
59  void cleanup();
60 
61  void preamble() override;
62 
65  std::max(static_cast<FwSizeType>(FW_COM_BUFFER_MAX_SIZE), static_cast<FwSizeType>(FW_FILE_BUFFER_MAX_SIZE)) +
67 
68  private:
69  // ----------------------------------------------------------------------
70  // Handler implementations for typed input ports
71  // ----------------------------------------------------------------------
72 
77  void comStatusIn_handler(FwIndexType portNum,
78  Fw::Success& condition
79  ) override;
80 
84  void dataIn_handler(FwIndexType portNum,
85  Fw::Buffer& data,
86  const ComCfg::FrameContext& context) override;
87 
91  void dataReturnIn_handler(FwIndexType portNum,
92  Fw::Buffer& data,
93  const ComCfg::FrameContext& context) override;
94 
96  void timeout_handler(FwIndexType portNum,
97  U32 context
98  ) override;
99 
100  private:
101  // ----------------------------------------------------------------------
102  // Implementations for internal state machine actions
103  // ----------------------------------------------------------------------
104 
108  void Svc_AggregationMachine_action_doClear(SmId smId,
110  ) override;
111 
115  void Svc_AggregationMachine_action_doFill(SmId smId,
117  const Svc::ComDataContextPair& value
118  ) override;
119 
123  void Svc_AggregationMachine_action_doSend(SmId smId,
125  ) override;
126 
130  void Svc_AggregationMachine_action_doHold(SmId smId,
132  const Svc::ComDataContextPair& value
133  ) override;
134 
138  void Svc_AggregationMachine_action_doSplitHold(SmId smId,
140  const Svc::ComDataContextPair& value
141  ) override;
142 
146  void Svc_AggregationMachine_action_doNoteFailure(SmId smId,
148  ) override;
149 
153  void Svc_AggregationMachine_action_assertNoStatus(SmId smId,
155  ) override;
156 
157  private:
158  // ----------------------------------------------------------------------
159  // Implementations for internal state machine guards
160  // ----------------------------------------------------------------------
161 
165  bool Svc_AggregationMachine_guard_isFull(SmId smId,
167  const Svc::ComDataContextPair& value
168  ) const override;
169 
173  bool Svc_AggregationMachine_guard_willFill(SmId smId,
175  const Svc::ComDataContextPair& value
176  ) const override;
177 
181  bool Svc_AggregationMachine_guard_isNotEmpty(SmId smId,
183  ) const override;
184 
188  bool Svc_AggregationMachine_guard_isGood(SmId smId,
190  const Fw::Success& value
191  ) const override;
192 
196  bool Svc_AggregationMachine_guard_isSpanFull(SmId smId,
198  ) const override;
199 
200  private:
201  // ----------------------------------------------------------------------
202  // Helper functions
203  // ----------------------------------------------------------------------
204 
206  FwSizeType remainingCapacity() const;
207 
211  bool accepts(FwSizeType size) const;
212 
214  void markFirstHeaderIfUnset();
215 
217  void fillFromHeld();
218 
221  void fillResidualWithIdle();
222 
224  void returnAndSignalReady(const Svc::ComDataContextPair& pair);
225 
229  void dropLostFrameState();
230 
231  private:
232  static constexpr U16 FHP_UNSET = 0xFFFF;
233 
234  Fw::MemAllocator* m_allocator;
235  FwEnumStoreType m_allocationId;
236  void* m_allocation;
237  std::atomic<Fw::Buffer::OwnershipState> m_bufferState{
239  Fw::Buffer m_frameBuffer;
242  ComCfg::FrameContext m_lastContext;
243 
244  Svc::ComDataContextPair m_held;
245  std::atomic<bool> m_allow_timeout;
246 
247  bool m_spanning;
248  FwSizeType m_aggregationSize;
249  FwSizeType m_heldOffset;
250  U16 m_fhp;
251  U8 m_pendingIdle[Ccsds::Utils::IdlePacket::MIN_SIZE] = {};
252  FwSizeType m_pendingIdleCount;
253  FwSizeType m_leadingIdleCount;
254  bool m_lastFrameLost;
255 };
256 
257 } // namespace Svc
258 
259 #endif
PlatformSizeType FwSizeType
I32 FwEnumStoreType
friend class ComAggregatorTester
static constexpr FwSizeType MIN_NON_SPANNING_AGGREGATION_SIZE
Smallest aggregate that holds a full com buffer and a full file buffer Space Packet without spanning...
~ComAggregator()
Destroy ComAggregator object.
void preamble() override
A function that will be called before the event loop is entered.
constexpr FwSizeType MIN_SIZE
Minimum idle packet size: header plus one byte of idle data.
Definition: IdlePacket.hpp:24
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
Auto-generated base for ComAggregator component.
Memory Allocation base class.
ComAggregator(const char *const compName)
Construct ComAggregator object.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
External serialize buffer with member copy semantics.
RateGroupDivider component implementation.
Defines a base class for a memory allocator for classes.
The buffer is currently owned.
void configure(FwSizeType aggregationSize, bool spanningEnabled, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
Success/Failure.