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 
44 
45  SpacePacketHeader header;
46  Fw::SerializeStatus status = data.getDeserializer().deserialize(header);
47  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
48 
49  // Space Packet protocol defines the Data Length as number of bytes minus 1
50  // so we need to add 1 to the length to get the actual data size
51  U16 pkt_length = static_cast<U16>(header.get_packetDataLength() + 1);
52  if (pkt_length > data.getSize() - SpacePacketHeader::SERIALIZED_SIZE) {
53  FwSizeType maxDataAvailable = data.getSize() - SpacePacketHeader::SERIALIZED_SIZE;
54  this->log_WARNING_HI_InvalidLength(pkt_length, maxDataAvailable);
55  this->dataReturnOut_out(0, data, context); // Drop the packet
56  return;
57  }
58 
60  ComCfg::APID::T apid = static_cast<ComCfg::APID::T>(apidValue);
61  ComCfg::FrameContext contextCopy = context;
62  contextCopy.set_apid(apid);
63 
64  // Validate with the ApidManager that the sequence count is correct
65  U16 receivedSequenceCount = header.get_packetSequenceControl() & SpacePacketSubfields::SeqCountMask;
66  (void)this->validateApidSeqCount_out(0, apid, receivedSequenceCount);
67  contextCopy.set_sequenceCount(receivedSequenceCount);
68 
69  // Set data buffer to be of the encapsulated data: HEADER (6 bytes) | PACKET DATA
71  data.setSize(pkt_length);
72 
73  this->dataOut_out(0, data, contextCopy);
74 }
75 
76 void SpacePacketDeframer ::dataReturnIn_handler(FwIndexType portNum,
77  Fw::Buffer& data,
78  const ComCfg::FrameContext& context) {
79  this->dataReturnOut_out(0, data, context);
80 }
81 
82 } // namespace Ccsds
83 } // namespace Svc
Serialization/Deserialization operation was successful.
void setData(U8 *data)
Definition: Buffer.cpp:68
U16 get_packetSequenceControl() const
Get member packetSequenceControl.
PlatformSizeType FwSizeType
void setSize(FwSizeType size)
Definition: Buffer.cpp:75
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.
T
The raw enum type.
Definition: APIDEnumAc.hpp:31
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:105
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
void set_sequenceCount(U16 sequenceCount)
Set member sequenceCount.
Describes the frame header format for the SpacePacket communications protocol.
U16 validateApidSeqCount_out(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)
Invoke output port validateApidSeqCount.
U16 get_packetDataLength() const
Get member packetDataLength.
U16 get_packetIdentification() const
Get member packetIdentification.
FwSizeType getSize() const
Definition: Buffer.cpp:60
~SpacePacketDeframer()
Destroy SpacePacketDeframer object.
SerializeStatus deserialize(U8 &val)
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
void set_apid(ComCfg::APID::T apid)
Set member apid.
RateGroupDivider component implementation.
Auto-generated base for SpacePacketDeframer component.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.