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.getpacketDataLength() + 1);
52  if (pkt_length > data.getSize() - SpacePacketHeader::SERIALIZED_SIZE) {
53  U32 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.setapid(apid);
63 
64  // Validate with the ApidManager that the sequence count is correct
65  U16 receivedSequenceCount = header.getpacketSequenceControl() & SpacePacketSubfields::SeqCountMask;
66  (void)this->validateApidSeqCount_out(0, apid, receivedSequenceCount);
67  contextCopy.setsequenceCount(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:80
void setapid(ComCfg::APID::T apid)
Set member apid.
void setsequenceCount(U16 sequenceCount)
Set member sequenceCount.
U16 getpacketIdentification() const
Get member packetIdentification.
Auto-generated base for SpacePacketDeframer component.
void setSize(SizeType size)
Definition: Buffer.cpp:87
U8 * getData() const
Definition: Buffer.cpp:68
SpacePacketDeframer(const char *const compName)
Construct SpacePacketDeframer object.
U16 validateApidSeqCount_out(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)
Invoke output port validateApidSeqCount.
SerializeStatus
forward declaration for string
T
The raw enum type.
Definition: APIDEnumAc.hpp:31
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:117
void log_WARNING_HI_InvalidLength(U16 transmitted, U32 actual) const
U16 getpacketSequenceControl() const
Get member packetSequenceControl.
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
U16 getpacketDataLength() const
Get member packetDataLength.
~SpacePacketDeframer()
Destroy SpacePacketDeframer object.
Describes the frame header format for the SpacePacket communications protocol.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
SizeType getSize() const
Definition: Buffer.cpp:72
#define FW_ASSERT(...)
Definition: Assert.hpp:14
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.