15 constexpr U16 ComAggregator::FHP_UNSET;
26 m_allocation(nullptr),
27 m_bufferState(
Fw::Buffer::OwnershipState::OWNED),
30 m_allow_timeout(false),
35 m_pendingIdleCount(0),
36 m_leadingIdleCount(0),
37 m_lastFrameLost(false) {}
49 if (spanningEnabled) {
53 FW_ASSERT(aggregationSize <= fhpRange, static_cast<FwAssertArgType>(aggregationSize));
59 static_cast<FwAssertArgType>(aggregationSize));
61 this->m_spanning = spanningEnabled;
62 this->m_aggregationSize = aggregationSize;
64 this->m_allocator = &allocator;
65 this->m_allocationId = allocationId;
67 this->m_allocation = allocator.
checkedAllocate(allocationId, allocatedSize);
68 this->m_frameBuffer.
set(static_cast<U8*>(this->m_allocation), aggregationSize);
69 this->m_frameSerializer.
setExtBuffer(static_cast<U8*>(this->m_allocation), aggregationSize);
73 if ((this->m_allocator !=
nullptr) && (this->m_allocation !=
nullptr)) {
76 static_cast<FwAssertArgType>(this->m_bufferState.load()));
79 this->m_heldOffset = 0;
80 this->m_fhp = FHP_UNSET;
81 this->m_pendingIdleCount = 0;
82 this->m_leadingIdleCount = 0;
83 this->m_lastFrameLost =
false;
85 this->m_frameBuffer.
set(
nullptr, 0);
86 this->m_aggregationSize = 0;
87 this->m_allocator->
deallocate(this->m_allocationId, this->m_allocation);
88 this->m_allocation =
nullptr;
89 this->m_allocator =
nullptr;
107 FW_ASSERT(this->m_allocation !=
nullptr);
110 static_cast<FwAssertArgType>(data.
getSize()));
121 void ComAggregator ::timeout_handler(
FwIndexType portNum, U32 context) {
132 if (this->m_allow_timeout) {
142 this->m_allow_timeout =
true;
144 this->m_frameBuffer.
setSize(this->m_aggregationSize);
146 this->m_fhp = FHP_UNSET;
147 this->dropLostFrameState();
148 this->m_leadingIdleCount = this->m_pendingIdleCount;
150 if (this->m_pendingIdleCount > 0) {
154 this->m_pendingIdleCount = 0;
157 this->fillFromHeld();
160 void ComAggregator ::Svc_AggregationMachine_action_doFill(SmId smId,
163 this->markFirstHeaderIfUnset();
168 this->returnAndSignalReady(value);
173 if (this->m_frameSerializer.
getSize() > 0) {
174 this->fillResidualWithIdle();
177 if (this->m_spanning) {
187 this->m_allow_timeout =
false;
188 this->
dataOut_out(0, this->m_frameBuffer, this->m_lastContext);
192 void ComAggregator ::Svc_AggregationMachine_action_doHold(SmId smId,
196 this->m_held = value;
197 this->m_heldOffset = 0;
200 void ComAggregator ::Svc_AggregationMachine_action_doSplitHold(SmId smId,
203 this->Svc_AggregationMachine_action_doHold(smId, signal, value);
204 if (this->m_spanning) {
206 const FwSizeType remaining = this->remainingCapacity();
209 this->markFirstHeaderIfUnset();
213 this->m_heldOffset = remaining;
220 this->m_lastFrameLost =
true;
232 bool ComAggregator ::Svc_AggregationMachine_guard_isFull(SmId smId,
238 bool ComAggregator ::Svc_AggregationMachine_guard_willFill(SmId smId,
246 return this->m_frameSerializer.
getSize() > this->m_leadingIdleCount;
249 bool ComAggregator ::Svc_AggregationMachine_guard_isGood(SmId smId,
256 return this->m_spanning && (this->m_frameSerializer.
getSize() == this->m_aggregationSize);
263 FwSizeType ComAggregator ::remainingCapacity()
const {
266 return this->m_aggregationSize - this->m_frameSerializer.
getSize();
269 bool ComAggregator ::accepts(
FwSizeType size)
const {
270 const FwSizeType remaining = this->remainingCapacity();
271 if (size > remaining) {
280 void ComAggregator ::markFirstHeaderIfUnset() {
281 if (this->m_spanning && this->m_fhp == FHP_UNSET) {
282 this->m_fhp =
static_cast<U16
>(this->m_frameSerializer.
getSize());
286 void ComAggregator ::fillFromHeld() {
290 const FwSizeType fillSize =
FW_MIN(this->remainingCapacity(), heldRemaining);
291 if (this->m_heldOffset == 0) {
293 this->markFirstHeaderIfUnset();
299 this->m_heldOffset += fillSize;
300 if (this->m_heldOffset == held.
getSize()) {
302 this->returnAndSignalReady(this->m_held);
304 this->m_heldOffset = 0;
309 void ComAggregator ::fillResidualWithIdle() {
310 const FwSizeType residual = this->remainingCapacity();
315 this->markFirstHeaderIfUnset();
334 (void)memcpy(this->m_pendingIdle, &staging[residual], this->m_pendingIdleCount);
338 void ComAggregator ::dropLostFrameState() {
339 if (this->m_lastFrameLost) {
340 this->m_pendingIdleCount = 0;
342 this->returnAndSignalReady(this->m_held);
344 this->m_heldOffset = 0;
346 this->m_lastFrameLost =
false;
Serialization/Deserialization operation was successful.
void set(U8 *data, FwSizeType size, U32 context=NO_CONTEXT)
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Serializable::SizeType getSize() const override
Get current buffer size.
Fw::SerializeStatus serialize(Fw::SerialBufferBase &serializer, FwSizeType size)
Serialize an idle packet of exactly size bytes (header and idle data) into serializer ...
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataReturnOut.
void aggregationMachine_sendSignal_status(const Fw::Success &value)
Send signal status to state machine aggregationMachine.
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...
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
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.
#define FW_MIN(a, b)
MIN macro (deprecated in C++, use std::min)
Omit length from serialization.
External serialize buffer with no copy semantics.
void * checkedAllocate(const FwEnumStoreType identifier, FwSizeType &size, bool &recoverable, FwSizeType alignment=alignof(std::max_align_t))
void resetSer() override
Reset serialization pointer to beginning of buffer.
ComCfg::FrameContext & get_context()
Get member context.
constexpr FwSizeType MIN_SIZE
Minimum idle packet size: header plus one byte of idle data.
uint8_t U8
8-bit unsigned integer
FwSizeType getSize() const
Auto-generated base for ComAggregator component.
void aggregationMachine_sendSignal_timeout()
Send signal timeout to state machine aggregationMachine.
Fw::Buffer & get_data()
Get member data.
void setExtBuffer(U8 *buffPtr, Serializable::SizeType size)
Set the external buffer.
Memory Allocation base class.
ComAggregator(const char *const compName)
Construct ComAggregator object.
PlatformIndexType FwIndexType
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition) const
Invoke output port comStatusOut.
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
constexpr FwSizeType MAX_SIZE
Maximum idle packet size: header plus the largest data length the SPP length field can express...
virtual void deallocate(const FwEnumStoreType identifier, void *ptr)=0
The buffer is currently owned.
Implementation of malloc based allocator.
void set_firstHeaderPointer(U16 firstHeaderPointer)
Set member firstHeaderPointer.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataOut.
void configure(FwSizeType aggregationSize, bool spanningEnabled, FwEnumStoreType allocationId, Fw::MemAllocator &allocator)
FpySequencer_SequencerStateMachineStateMachineBase::Signal Signal
void aggregationMachine_sendSignal_fill(const Svc::ComDataContextPair &value)
Send signal fill to state machine aggregationMachine.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.