F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SpacePacketDeframer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SpacePacketDeframer.cpp
3 // \author thomas-bc
4 // \brief cpp file for SpacePacketDeframer component implementation class
5 // ======================================================================
6 
10 
11 namespace Svc {
12 
13 namespace Ccsds {
14 
15 // ----------------------------------------------------------------------
16 // Component construction and destruction
17 // ----------------------------------------------------------------------
18 
20 
22 
23 // ----------------------------------------------------------------------
24 // Handler implementations for typed input ports
25 // ----------------------------------------------------------------------
26 
27 void SpacePacketDeframer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28  // ################################
29  // CCSDS SpacePacket Format:
30  // 6 octets - Primary Header
31  // 0-65536 octets - Data Field (with optional secondary header)
32 
33  // CCSDS SpacePacket Primary Header:
34  // 3b - 000 - (PVN) Packet Version Number
35  // 1b - 0/1 - (PT) Packet Type
36  // 1b - 0/1 - (SHF) Secondary Header Flag
37  // 11b - n/a - (APID) Application Process ID
38  // 2b - 00 - Sequence Flag
39  // 14b - n/a - Sequence Count
40  // 16b - n/a - Packet Data Length
41  // ################################
42 
43  // Check size and drop packets that are too-small
48  }
49  this->dataReturnOut_out(0, data, context); // Drop the packet
50  return;
51  }
52 
53  SpacePacketHeader header;
54  Fw::SerializeStatus status = data.getDeserializer().deserializeTo(header);
55  // Length is valid, so deserialization here should succeed
56  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
57 
58  // Space Packet protocol defines the Data Length as number of bytes minus 1
59  // so we need to add 1 to the length to get the actual data size
60  U16 pkt_length = static_cast<U16>(header.get_packetDataLength() + 1);
61  if (pkt_length > data.getSize() - SpacePacketHeader::SERIALIZED_SIZE) {
62  FwSizeType maxDataAvailable = data.getSize() - SpacePacketHeader::SERIALIZED_SIZE;
63  this->log_WARNING_HI_InvalidLength(pkt_length, maxDataAvailable);
66  }
67  this->dataReturnOut_out(0, data, context); // Drop the packet
68  return;
69  }
70 
71  U16 apidValue = header.get_packetIdentification() & SpacePacketSubfields::ApidMask;
72  ComCfg::Apid::T apid = static_cast<ComCfg::Apid::T>(apidValue);
73  ComCfg::FrameContext contextCopy = context;
74  contextCopy.set_apid(apid);
75 
76  // Validate with the ApidManager that the sequence count is correct
77  U16 receivedSequenceCount = header.get_packetSequenceControl() & SpacePacketSubfields::SeqCountMask;
78  (void)this->validateApidSeqCount_out(0, apid, receivedSequenceCount);
79  contextCopy.set_sequenceCount(receivedSequenceCount);
80 
81  // Set data buffer to be of the encapsulated data: HEADER (6 bytes) | PACKET DATA
83  data.setSize(pkt_length);
84 
85  this->dataOut_out(0, data, contextCopy);
86 }
87 
88 void SpacePacketDeframer ::dataReturnIn_handler(FwIndexType portNum,
89  Fw::Buffer& data,
90  const ComCfg::FrameContext& context) {
91  this->dataReturnOut_out(0, data, context);
92 }
93 
94 } // namespace Ccsds
95 } // namespace Svc
Serialization/Deserialization operation was successful.
void setData(U8 *data)
Definition: Buffer.cpp:68
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Definition: Buffer.cpp:75
void set_apid(ComCfg::Apid::T apid)
Set member apid.
U8 * getData() const
Definition: Buffer.cpp:56
void log_WARNING_HI_InvalidLength(U16 transmitted, FwSizeType actual) const
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
SerializeStatus
forward declaration for string
SpacePacketDeframer(const char *const compName)
Construct SpacePacketDeframer object.
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:105
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
T
The raw enum type.
Definition: ApidEnumAc.hpp:31
void set_sequenceCount(U16 sequenceCount)
Set member sequenceCount.
void errorNotify_out(FwIndexType portNum, const Svc::Ccsds::FrameError &errorCode)
Invoke output port errorNotify.
FwSizeType getSize() const
Definition: Buffer.cpp:60
~SpacePacketDeframer()
Destroy SpacePacketDeframer object.
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
Auto-generated base for SpacePacketDeframer component.
SerializeStatus deserializeTo(U8 &val, Endianness mode=Endianness::BIG) override
Deserialize an 8-bit unsigned integer value.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
U16 validateApidSeqCount_out(FwIndexType portNum, const ComCfg::Apid &apid, U16 sequenceCount)
Invoke output port validateApidSeqCount.