| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // ====================================================================== | ||
| 2 | // \title ComAggregator.cpp | ||
| 3 | // \author lestarch | ||
| 4 | // \brief cpp file for ComAggregator component implementation class | ||
| 5 | // ====================================================================== | ||
| 6 | |||
| 7 | #include "Svc/ComAggregator/ComAggregator.hpp" | ||
| 8 | #include <cstring> | ||
| 9 | #include "Fw/FPrimeBasicTypes.hpp" | ||
| 10 | #include "Svc/Ccsds/Utils/IdlePacket.hpp" | ||
| 11 | |||
| 12 | namespace Svc { | ||
| 13 | |||
| 14 | // Definition for ODR-use of static constexpr member (required until C++17) | ||
| 15 | constexpr U16 ComAggregator::FHP_UNSET; | ||
| 16 | constexpr FwSizeType ComAggregator::MIN_NON_SPANNING_AGGREGATION_SIZE; | ||
| 17 | |||
| 18 | // ---------------------------------------------------------------------- | ||
| 19 | // Component construction and destruction | ||
| 20 | // ---------------------------------------------------------------------- | ||
| 21 | |||
| 22 | 37 | ComAggregator ::ComAggregator(const char* const compName) | |
| 23 | : ComAggregatorComponentBase(compName), | ||
| 24 | 37 | m_allocator(nullptr), | |
| 25 | 37 | m_allocationId(static_cast<FwEnumStoreType>(-1)), | |
| 26 | 37 | m_allocation(nullptr), | |
| 27 | 37 | m_bufferState(Fw::Buffer::OwnershipState::OWNED), | |
| 28 |
1/1✓ Branch 5 taken 37 times.
|
37 | m_frameBuffer(), |
| 29 |
1/1✓ Branch 5 taken 37 times.
|
37 | m_frameSerializer(), |
| 30 | 37 | m_allow_timeout(false), | |
| 31 | 37 | m_spanning(false), | |
| 32 | 37 | m_aggregationSize(0), | |
| 33 | 37 | m_heldOffset(0), | |
| 34 | 37 | m_fhp(FHP_UNSET), | |
| 35 | 37 | m_pendingIdleCount(0), | |
| 36 | 37 | m_leadingIdleCount(0), | |
| 37 |
2/2✓ Branch 10 taken 37 times.
✓ Branch 16 taken 37 times.
|
148 | m_lastFrameLost(false) {} |
| 38 | |||
| 39 | 74 | ComAggregator ::~ComAggregator() {} | |
| 40 | |||
| 41 | 35 | void ComAggregator ::configure(FwSizeType aggregationSize, | |
| 42 | bool spanningEnabled, | ||
| 43 | FwEnumStoreType allocationId, | ||
| 44 | Fw::MemAllocator& allocator) { | ||
| 45 | // Storage is configured once, before any data is aggregated; cleanup() must run before reconfiguring | ||
| 46 | 35 | FW_ASSERT(this->m_allocation == nullptr); | |
| 47 | // An aggregate must have room for data beyond the minimum idle packet | ||
| 48 | 35 | FW_ASSERT(aggregationSize > Ccsds::Utils::IdlePacket::MIN_SIZE, static_cast<FwAssertArgType>(aggregationSize)); | |
| 49 |
2/2✓ Branch 0 taken 9 times.
✓ Branch 1 taken 26 times.
|
35 | if (spanningEnabled) { |
| 50 | // Every packet header offset in an aggregate must be representable as an 11-bit First Header Pointer | ||
| 51 | // and distinct from the reserved values (CCSDS 132.0-B-3 4.1.2.7.6) | ||
| 52 | 9 | const FwSizeType fhpRange = static_cast<FwSizeType>(Ccsds::TMSubfields::FHP_IDLE_DATA_ONLY); | |
| 53 | 9 | FW_ASSERT(aggregationSize <= fhpRange, static_cast<FwAssertArgType>(aggregationSize)); | |
| 54 | } else { | ||
| 55 | // Without spanning, a full com buffer or file buffer Space Packet must fit next to a minimum idle packet | ||
| 56 | 26 | FW_ASSERT(aggregationSize >= MIN_NON_SPANNING_AGGREGATION_SIZE, static_cast<FwAssertArgType>(aggregationSize)); | |
| 57 | // The residual idle packet, up to aggregationSize - 1 bytes, must have a representable SPP length field | ||
| 58 | 26 | FW_ASSERT((aggregationSize - 1) <= Ccsds::Utils::IdlePacket::MAX_SIZE, | |
| 59 | static_cast<FwAssertArgType>(aggregationSize)); | ||
| 60 | } | ||
| 61 | 35 | this->m_spanning = spanningEnabled; | |
| 62 | 35 | this->m_aggregationSize = aggregationSize; | |
| 63 | |||
| 64 | 35 | this->m_allocator = &allocator; | |
| 65 | 35 | this->m_allocationId = allocationId; | |
| 66 | 35 | FwSizeType allocatedSize = aggregationSize; | |
| 67 |
1/1✓ Branch 6 taken 35 times.
|
35 | this->m_allocation = allocator.checkedAllocate(allocationId, allocatedSize); |
| 68 |
1/1✓ Branch 10 taken 35 times.
|
35 | this->m_frameBuffer.set(static_cast<U8*>(this->m_allocation), aggregationSize); |
| 69 |
1/1✓ Branch 10 taken 35 times.
|
35 | this->m_frameSerializer.setExtBuffer(static_cast<U8*>(this->m_allocation), aggregationSize); |
| 70 | 35 | } | |
| 71 | |||
| 72 | 41 | void ComAggregator ::cleanup() { | |
| 73 |
3/4✓ Branch 4 taken 35 times.
✓ Branch 5 taken 6 times.
✓ Branch 10 taken 35 times.
✗ Branch 11 not taken.
|
41 | if ((this->m_allocator != nullptr) && (this->m_allocation != nullptr)) { |
| 74 | // The aggregate must not be held downstream when its storage is released | ||
| 75 | 35 | FW_ASSERT(this->m_bufferState == Fw::Buffer::OwnershipState::OWNED, | |
| 76 | static_cast<FwAssertArgType>(this->m_bufferState.load())); | ||
| 77 | // Drop the per-aggregate state so a later configure() starts clean | ||
| 78 |
2/2✓ Branch 2 taken 35 times.
✓ Branch 11 taken 35 times.
|
35 | this->m_held = Svc::ComDataContextPair(); |
| 79 | 35 | this->m_heldOffset = 0; | |
| 80 | 35 | this->m_fhp = FHP_UNSET; | |
| 81 | 35 | this->m_pendingIdleCount = 0; | |
| 82 | 35 | this->m_leadingIdleCount = 0; | |
| 83 | 35 | this->m_lastFrameLost = false; | |
| 84 | 35 | this->m_frameSerializer.setExtBuffer(nullptr, 0); | |
| 85 | 35 | this->m_frameBuffer.set(nullptr, 0); | |
| 86 | 35 | this->m_aggregationSize = 0; | |
| 87 | 35 | this->m_allocator->deallocate(this->m_allocationId, this->m_allocation); | |
| 88 | 35 | this->m_allocation = nullptr; | |
| 89 | 35 | this->m_allocator = nullptr; | |
| 90 | } | ||
| 91 | 41 | } | |
| 92 | |||
| 93 | 25 | void ComAggregator ::preamble() { | |
| 94 |
1/1✓ Branch 2 taken 25 times.
|
25 | Fw::Success good = Fw::Success::SUCCESS; |
| 95 |
1/1✓ Branch 5 taken 25 times.
|
25 | this->comStatusOut_out(0, good); |
| 96 | 50 | } | |
| 97 | |||
| 98 | // ---------------------------------------------------------------------- | ||
| 99 | // Handler implementations for typed input ports | ||
| 100 | // ---------------------------------------------------------------------- | ||
| 101 | |||
| 102 | 10992 | void ComAggregator ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) { | |
| 103 | 10992 | this->aggregationMachine_sendSignal_status(condition); | |
| 104 | 10992 | } | |
| 105 | |||
| 106 | 5025 | void ComAggregator ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) { | |
| 107 | 5025 | FW_ASSERT(this->m_allocation != nullptr); | |
| 108 | // Without spanning, any packet must fit in an empty aggregate next to a minimum idle packet | ||
| 109 | 5025 | FW_ASSERT(this->m_spanning || data.getSize() <= (this->m_aggregationSize - Ccsds::Utils::IdlePacket::MIN_SIZE), | |
| 110 | static_cast<FwAssertArgType>(data.getSize())); | ||
| 111 |
1/1✓ Branch 3 taken 5025 times.
|
5025 | Svc::ComDataContextPair pair(data, context); |
| 112 |
1/1✓ Branch 5 taken 5025 times.
|
5025 | this->aggregationMachine_sendSignal_fill(pair); |
| 113 | 10050 | } | |
| 114 | |||
| 115 | 5456 | void ComAggregator ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) { | |
| 116 | // This handler runs on the returning caller's thread: take ownership atomically | ||
| 117 | 5456 | const Fw::Buffer::OwnershipState previousState = this->m_bufferState.exchange(Fw::Buffer::OwnershipState::OWNED); | |
| 118 | 5456 | FW_ASSERT(previousState == Fw::Buffer::OwnershipState::NOT_OWNED, static_cast<FwAssertArgType>(previousState)); | |
| 119 | 5456 | } | |
| 120 | |||
| 121 | 4223 | void ComAggregator ::timeout_handler(FwIndexType portNum, U32 context) { | |
| 122 | // Timeout is ignored in WAIT_STATUS state. However, the queue may not process timeout messages until the wait | ||
| 123 | // status is returned because the port chain may be synchronous and downstream components (radio, retry, etc) may | ||
| 124 | // take a long time to complete the transmission of data. This can cause the queue to overflow with messages that | ||
| 125 | // will soon be discarded. | ||
| 126 | // | ||
| 127 | // Therefore, to fix the risk of queue overflow we only queue timeout messages when they would be processed by the | ||
| 128 | // state machine (i.e. in the FILL state). Otherwise, these messages are not queued. | ||
| 129 | // | ||
| 130 | // Behaviorally, this solution will work exactly like the naive implementation with an infinite queue depth, but | ||
| 131 | // prevents queue overflow when using finite queues. | ||
| 132 |
2/2✓ Branch 4 taken 4199 times.
✓ Branch 5 taken 24 times.
|
4223 | if (this->m_allow_timeout) { |
| 133 | 4199 | this->aggregationMachine_sendSignal_timeout(); | |
| 134 | } | ||
| 135 | 4223 | } | |
| 136 | |||
| 137 | // ---------------------------------------------------------------------- | ||
| 138 | // Implementations for internal state machine actions | ||
| 139 | // ---------------------------------------------------------------------- | ||
| 140 | |||
| 141 | 5476 | void ComAggregator ::Svc_AggregationMachine_action_doClear(SmId smId, Svc_AggregationMachine::Signal signal) { | |
| 142 | 5476 | this->m_allow_timeout = true; // Allow timeout messages in FILL state | |
| 143 | 5476 | this->m_frameSerializer.resetSer(); | |
| 144 | 5476 | this->m_frameBuffer.setSize(this->m_aggregationSize); | |
| 145 |
2/2✓ Branch 2 taken 5476 times.
✓ Branch 11 taken 5476 times.
|
5476 | this->m_lastContext = ComCfg::FrameContext(); |
| 146 | 5476 | this->m_fhp = FHP_UNSET; | |
| 147 | 5476 | this->dropLostFrameState(); | |
| 148 | 5476 | this->m_leadingIdleCount = this->m_pendingIdleCount; | |
| 149 | // Write out any idle packet bytes spanning over from the previous aggregate | ||
| 150 |
2/2✓ Branch 4 taken 34 times.
✓ Branch 5 taken 5442 times.
|
5476 | if (this->m_pendingIdleCount > 0) { |
| 151 | 68 | Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom( | |
| 152 | 68 | this->m_pendingIdle, this->m_pendingIdleCount, Fw::Serialization::OMIT_LENGTH); | |
| 153 | 34 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 154 | 34 | this->m_pendingIdleCount = 0; | |
| 155 | } | ||
| 156 | // Fill from the held buffer (whole packet, or remainder of a spanned packet) | ||
| 157 | 5476 | this->fillFromHeld(); | |
| 158 | 5476 | } | |
| 159 | |||
| 160 | 1435 | void ComAggregator ::Svc_AggregationMachine_action_doFill(SmId smId, | |
| 161 | Svc_AggregationMachine::Signal signal, | ||
| 162 | const Svc::ComDataContextPair& value) { | ||
| 163 | 1435 | this->markFirstHeaderIfUnset(); | |
| 164 | 2870 | Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom( | |
| 165 | 2870 | value.get_data().getData(), value.get_data().getSize(), Fw::Serialization::OMIT_LENGTH); | |
| 166 | 1435 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 167 | 1435 | this->m_lastContext = value.get_context(); | |
| 168 | 1435 | this->returnAndSignalReady(value); | |
| 169 | 1435 | } | |
| 170 | |||
| 171 | 5456 | void ComAggregator ::Svc_AggregationMachine_action_doSend(SmId smId, Svc_AggregationMachine::Signal signal) { | |
| 172 | // Send only when the buffer will be valid | ||
| 173 |
1/2✓ Branch 6 taken 5456 times.
✗ Branch 7 not taken.
|
5456 | if (this->m_frameSerializer.getSize() > 0) { |
| 174 | 5456 | this->fillResidualWithIdle(); | |
| 175 | 5456 | FW_ASSERT(this->m_frameSerializer.getSize() == this->m_aggregationSize, | |
| 176 | static_cast<FwAssertArgType>(this->m_frameSerializer.getSize())); | ||
| 177 |
3/4✗ Branch 3 not taken.
✓ Branch 4 taken 5456 times.
✓ Branch 5 taken 5432 times.
✓ Branch 6 taken 24 times.
|
5456 | if (this->m_spanning) { |
| 178 | 10864 | this->m_lastContext.set_firstHeaderPointer( | |
| 179 |
2/2✓ Branch 4 taken 4786 times.
✓ Branch 5 taken 646 times.
|
5432 | (this->m_fhp == FHP_UNSET) ? static_cast<U16>(Ccsds::TMSubfields::FHP_NO_PACKET_START) : this->m_fhp); |
| 180 | } else { | ||
| 181 | // Packets are never split: the first packet header is always at the start of the aggregate | ||
| 182 | 24 | this->m_lastContext.set_firstHeaderPointer(0); | |
| 183 | } | ||
| 184 | const Fw::Buffer::OwnershipState previousState = | ||
| 185 | 5456 | this->m_bufferState.exchange(Fw::Buffer::OwnershipState::NOT_OWNED); | |
| 186 | 5456 | FW_ASSERT(previousState == Fw::Buffer::OwnershipState::OWNED, static_cast<FwAssertArgType>(previousState)); | |
| 187 | 5456 | this->m_allow_timeout = false; // Timeout messages should be discarded in WAIT_STATUS state | |
| 188 | 5456 | this->dataOut_out(0, this->m_frameBuffer, this->m_lastContext); | |
| 189 | } | ||
| 190 | 5456 | } | |
| 191 | |||
| 192 | 3590 | void ComAggregator ::Svc_AggregationMachine_action_doHold(SmId smId, | |
| 193 | Svc_AggregationMachine::Signal signal, | ||
| 194 | const Svc::ComDataContextPair& value) { | ||
| 195 | 3590 | FW_ASSERT(not this->m_held.get_data().isValid()); | |
| 196 | 3590 | this->m_held = value; | |
| 197 | 3590 | this->m_heldOffset = 0; | |
| 198 | 3590 | } | |
| 199 | |||
| 200 | 2830 | void ComAggregator ::Svc_AggregationMachine_action_doSplitHold(SmId smId, | |
| 201 | Svc_AggregationMachine::Signal signal, | ||
| 202 | const Svc::ComDataContextPair& value) { | ||
| 203 | 2830 | this->Svc_AggregationMachine_action_doHold(smId, signal, value); | |
| 204 |
3/4✗ Branch 3 not taken.
✓ Branch 4 taken 2830 times.
✓ Branch 5 taken 2820 times.
✓ Branch 6 taken 10 times.
|
2830 | if (this->m_spanning) { |
| 205 | // Split the leading bytes of the held packet into the remaining aggregation space | ||
| 206 | 2820 | const FwSizeType remaining = this->remainingCapacity(); | |
| 207 |
1/2✓ Branch 0 taken 2820 times.
✗ Branch 1 not taken.
|
2820 | if (remaining > 0) { |
| 208 | // The held packet's header starts at the current fill offset of this aggregate | ||
| 209 | 2820 | this->markFirstHeaderIfUnset(); | |
| 210 | 2820 | Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom(value.get_data().getData(), remaining, | |
| 211 | Fw::Serialization::OMIT_LENGTH); | ||
| 212 | 2820 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 213 | 2820 | this->m_heldOffset = remaining; | |
| 214 | 2820 | this->m_lastContext = value.get_context(); | |
| 215 | } | ||
| 216 | } | ||
| 217 | 2830 | } | |
| 218 | |||
| 219 | 5516 | void ComAggregator ::Svc_AggregationMachine_action_doNoteFailure(SmId smId, Svc_AggregationMachine::Signal signal) { | |
| 220 | 5516 | this->m_lastFrameLost = true; | |
| 221 | 5516 | } | |
| 222 | |||
| 223 | ✗ | void ComAggregator ::Svc_AggregationMachine_action_assertNoStatus(SmId smId, Svc_AggregationMachine::Signal signal) { | |
| 224 | // Status is not possible in this state, confirm by assertion | ||
| 225 | ✗ | FW_ASSERT(false); | |
| 226 | ✗ | } | |
| 227 | |||
| 228 | // ---------------------------------------------------------------------- | ||
| 229 | // Implementations for internal state machine guards | ||
| 230 | // ---------------------------------------------------------------------- | ||
| 231 | |||
| 232 | 4265 | bool ComAggregator ::Svc_AggregationMachine_guard_isFull(SmId smId, | |
| 233 | Svc_AggregationMachine::Signal signal, | ||
| 234 | const Svc::ComDataContextPair& value) const { | ||
| 235 | 4265 | return not this->accepts(value.get_data().getSize()); | |
| 236 | } | ||
| 237 | |||
| 238 | 1435 | bool ComAggregator ::Svc_AggregationMachine_guard_willFill(SmId smId, | |
| 239 | Svc_AggregationMachine::Signal signal, | ||
| 240 | const Svc::ComDataContextPair& value) const { | ||
| 241 | 1435 | return (this->remainingCapacity() == value.get_data().getSize()); | |
| 242 | } | ||
| 243 | |||
| 244 | 4199 | bool ComAggregator ::Svc_AggregationMachine_guard_isNotEmpty(SmId smId, Svc_AggregationMachine::Signal signal) const { | |
| 245 | // Carried-over idle bytes are not payload: an aggregate holding only those is empty for timeout purposes | ||
| 246 | 4199 | return this->m_frameSerializer.getSize() > this->m_leadingIdleCount; | |
| 247 | } | ||
| 248 | |||
| 249 | 10992 | bool ComAggregator ::Svc_AggregationMachine_guard_isGood(SmId smId, | |
| 250 | Svc_AggregationMachine::Signal signal, | ||
| 251 | const Fw::Success& value) const { | ||
| 252 | 10992 | return value == Fw::Success::SUCCESS; | |
| 253 | } | ||
| 254 | |||
| 255 | 5476 | bool ComAggregator ::Svc_AggregationMachine_guard_isSpanFull(SmId smId, Svc_AggregationMachine::Signal signal) const { | |
| 256 |
5/6✗ Branch 3 not taken.
✓ Branch 4 taken 5476 times.
✓ Branch 5 taken 5437 times.
✓ Branch 6 taken 39 times.
✓ Branch 22 taken 1102 times.
✓ Branch 23 taken 4335 times.
|
5476 | return this->m_spanning && (this->m_frameSerializer.getSize() == this->m_aggregationSize); |
| 257 | } | ||
| 258 | |||
| 259 | // ---------------------------------------------------------------------- | ||
| 260 | // Helper functions | ||
| 261 | // ---------------------------------------------------------------------- | ||
| 262 | |||
| 263 | 17828 | FwSizeType ComAggregator ::remainingCapacity() const { | |
| 264 | 17828 | FW_ASSERT(this->m_frameSerializer.getSize() <= this->m_aggregationSize, | |
| 265 | static_cast<FwAssertArgType>(this->m_frameSerializer.getSize())); | ||
| 266 | 17828 | return this->m_aggregationSize - this->m_frameSerializer.getSize(); | |
| 267 | } | ||
| 268 | |||
| 269 | 4265 | bool ComAggregator ::accepts(FwSizeType size) const { | |
| 270 | 4265 | const FwSizeType remaining = this->remainingCapacity(); | |
| 271 |
2/2✓ Branch 0 taken 2826 times.
✓ Branch 1 taken 1439 times.
|
4265 | if (size > remaining) { |
| 272 | 2826 | return false; | |
| 273 | } | ||
| 274 | // Without spanning, an idle packet cannot continue into the next aggregate: the packet must either complete | ||
| 275 | // the aggregate or leave room for a whole minimum idle packet | ||
| 276 | 1439 | const FwSizeType residual = remaining - size; | |
| 277 |
7/8✗ Branch 3 not taken.
✓ Branch 4 taken 1439 times.
✓ Branch 5 taken 74 times.
✓ Branch 6 taken 1365 times.
✓ Branch 7 taken 71 times.
✓ Branch 8 taken 3 times.
✓ Branch 9 taken 67 times.
✓ Branch 10 taken 4 times.
|
1439 | return this->m_spanning || (residual == 0) || (residual >= Ccsds::Utils::IdlePacket::MIN_SIZE); |
| 278 | } | ||
| 279 | |||
| 280 | 6547 | void ComAggregator ::markFirstHeaderIfUnset() { | |
| 281 |
5/6✗ Branch 3 not taken.
✓ Branch 4 taken 6547 times.
✓ Branch 5 taken 6446 times.
✓ Branch 6 taken 101 times.
✓ Branch 11 taken 4786 times.
✓ Branch 12 taken 1660 times.
|
6547 | if (this->m_spanning && this->m_fhp == FHP_UNSET) { |
| 282 | 4786 | this->m_fhp = static_cast<U16>(this->m_frameSerializer.getSize()); | |
| 283 | } | ||
| 284 | 6547 | } | |
| 285 | |||
| 286 | 5476 | void ComAggregator ::fillFromHeld() { | |
| 287 |
2/2✓ Branch 10 taken 2763 times.
✓ Branch 11 taken 2713 times.
|
5476 | if (this->m_held.get_data().isValid()) { |
| 288 | 2763 | const Fw::Buffer& held = this->m_held.get_data(); | |
| 289 | 2763 | const FwSizeType heldRemaining = held.getSize() - this->m_heldOffset; | |
| 290 |
2/2✓ Branch 4 taken 1089 times.
✓ Branch 5 taken 1674 times.
|
2763 | const FwSizeType fillSize = FW_MIN(this->remainingCapacity(), heldRemaining); |
| 291 |
2/2✓ Branch 4 taken 768 times.
✓ Branch 5 taken 1995 times.
|
2763 | if (this->m_heldOffset == 0) { |
| 292 | // The held packet's header starts at the current fill offset of this aggregate | ||
| 293 | 768 | this->markFirstHeaderIfUnset(); | |
| 294 | } | ||
| 295 | 2763 | Fw::SerializeStatus status = this->m_frameSerializer.serializeFrom(held.getData() + this->m_heldOffset, | |
| 296 | fillSize, Fw::Serialization::OMIT_LENGTH); | ||
| 297 | 2763 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 298 | 2763 | this->m_lastContext = this->m_held.get_context(); | |
| 299 | 2763 | this->m_heldOffset += fillSize; | |
| 300 |
2/2✓ Branch 8 taken 1674 times.
✓ Branch 9 taken 1089 times.
|
2763 | if (this->m_heldOffset == held.getSize()) { |
| 301 | // Held buffer fully consumed: return it and request more data | ||
| 302 | 1674 | this->returnAndSignalReady(this->m_held); | |
| 303 |
2/2✓ Branch 2 taken 1674 times.
✓ Branch 11 taken 1674 times.
|
1674 | this->m_held = Svc::ComDataContextPair(); |
| 304 | 1674 | this->m_heldOffset = 0; | |
| 305 | } | ||
| 306 | } | ||
| 307 | 5476 | } | |
| 308 | |||
| 309 | 5456 | void ComAggregator ::fillResidualWithIdle() { | |
| 310 | 5456 | const FwSizeType residual = this->remainingCapacity(); | |
| 311 |
2/2✓ Branch 0 taken 3932 times.
✓ Branch 1 taken 1524 times.
|
5456 | if (residual == 0) { |
| 312 | 3932 | return; | |
| 313 | } | ||
| 314 | // The idle packet's header starts at the current fill offset of this aggregate | ||
| 315 | 1524 | this->markFirstHeaderIfUnset(); | |
| 316 | // Idle packet size: fill the residual space exactly, spanning a minimum-size idle packet | ||
| 317 | // into the next aggregate when the residual space is too small (CCSDS 132.0-B-3 4.1.4) | ||
| 318 | 1524 | Fw::SerializeStatus status = Fw::SerializeStatus::FW_SERIALIZE_OK; | |
| 319 |
2/2✓ Branch 0 taken 1449 times.
✓ Branch 1 taken 75 times.
|
1524 | if (residual >= Ccsds::Utils::IdlePacket::MIN_SIZE) { |
| 320 | // Idle packet fits entirely within this aggregate | ||
| 321 | 1449 | status = Ccsds::Utils::IdlePacket::serialize(this->m_frameSerializer, residual); | |
| 322 | 1449 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 323 | } else { | ||
| 324 | // Without spanning, accepts() keeps the residual at zero or at least a minimum idle packet | ||
| 325 | 75 | FW_ASSERT(this->m_spanning); | |
| 326 | // Stage a minimum-size idle packet, emit the leading bytes now and span the rest | ||
| 327 | 75 | U8 staging[Ccsds::Utils::IdlePacket::MIN_SIZE] = {}; | |
| 328 |
1/1✓ Branch 2 taken 75 times.
|
75 | Fw::ExternalSerializeBuffer stager(staging, sizeof(staging)); |
| 329 |
1/1✓ Branch 1 taken 75 times.
|
75 | status = Ccsds::Utils::IdlePacket::serialize(stager, Ccsds::Utils::IdlePacket::MIN_SIZE); |
| 330 | 75 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 331 |
1/1✓ Branch 6 taken 75 times.
|
75 | status = this->m_frameSerializer.serializeFrom(staging, residual, Fw::Serialization::OMIT_LENGTH); |
| 332 | 75 | FW_ASSERT(status == Fw::SerializeStatus::FW_SERIALIZE_OK); | |
| 333 | 75 | this->m_pendingIdleCount = Ccsds::Utils::IdlePacket::MIN_SIZE - residual; | |
| 334 |
2/4✗ Branch 8 not taken.
✓ Branch 9 taken 75 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 75 times.
|
75 | (void)memcpy(this->m_pendingIdle, &staging[residual], this->m_pendingIdleCount); |
| 335 | 75 | } | |
| 336 | } | ||
| 337 | |||
| 338 | 5476 | void ComAggregator ::dropLostFrameState() { | |
| 339 |
3/4✗ Branch 3 not taken.
✓ Branch 4 taken 5476 times.
✓ Branch 5 taken 2705 times.
✓ Branch 6 taken 2771 times.
|
5476 | if (this->m_lastFrameLost) { |
| 340 | 2705 | this->m_pendingIdleCount = 0; | |
| 341 |
6/6✓ Branch 10 taken 2416 times.
✓ Branch 11 taken 289 times.
✓ Branch 16 taken 1913 times.
✓ Branch 17 taken 503 times.
✓ Branch 18 taken 1913 times.
✓ Branch 19 taken 792 times.
|
2705 | if (this->m_held.get_data().isValid() && this->m_heldOffset > 0) { |
| 342 | 1913 | this->returnAndSignalReady(this->m_held); | |
| 343 |
2/2✓ Branch 2 taken 1913 times.
✓ Branch 11 taken 1913 times.
|
1913 | this->m_held = Svc::ComDataContextPair(); |
| 344 | 1913 | this->m_heldOffset = 0; | |
| 345 | } | ||
| 346 | 2705 | this->m_lastFrameLost = false; | |
| 347 | } | ||
| 348 | 5476 | } | |
| 349 | |||
| 350 | 5022 | void ComAggregator ::returnAndSignalReady(const Svc::ComDataContextPair& pair) { | |
| 351 | // Return port does not alter data and thus const-cast is safe | ||
| 352 |
1/1✓ Branch 14 taken 5022 times.
|
5022 | this->dataReturnOut_out(0, const_cast<Fw::Buffer&>(pair.get_data()), pair.get_context()); |
| 353 |
1/1✓ Branch 2 taken 5022 times.
|
5022 | Fw::Success good = Fw::Success::SUCCESS; |
| 354 |
1/1✓ Branch 5 taken 5022 times.
|
5022 | this->comStatusOut_out(0, good); |
| 355 | 10044 | } | |
| 356 | |||
| 357 | } // namespace Svc | ||
| 358 |