F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SpacePacketFramer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SpacePacketFramer.cpp
3 // \author thomas-bc
4 // \brief cpp file for SpacePacketFramer 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 SpacePacketFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
28  SpacePacketHeader header;
29  Fw::SerializeStatus status;
31  FW_ASSERT(data.getSize() <= std::numeric_limits<Fw::Buffer::SizeType>::max() - SpacePacketHeader::SERIALIZED_SIZE,
32  static_cast<FwAssertArgType>(data.getSize()));
33  FW_ASSERT(
34  data.getSize() > 0,
35  static_cast<FwAssertArgType>(data.getSize())); // Protocol specifies at least 1 byte of data for a valid packet
36 
37  // Allocate frame buffer
38  Fw::Buffer frameBuffer = this->bufferAllocate_out(0, static_cast<Fw::Buffer::SizeType>(frameSize));
39  auto frameSerializer = frameBuffer.getSerializer();
40 
41  // -----------------------------------------------
42  // Header
43  // -----------------------------------------------
44  // PVN is always 0 per Standard - Packet Type is 0 for Telemetry (downlink) - SecHdr flag is 0 for no secondary
45  // header
46  U16 packetIdentification = 0;
47  ComCfg::APID::T apid = context.get_apid();
49  static_cast<FwAssertArgType>(apid)); // apid must fit in 11 bits
50  packetIdentification |= static_cast<U16>(apid) & static_cast<U16>(SpacePacketSubfields::ApidMask); // 11 bit APID
51 
52  U16 sequenceCount = this->getApidSeqCount_out(0, apid, 0); // retrieve the sequence count for this APID
53  U16 packetSequenceControl = 0;
54  packetSequenceControl |=
55  0x3 << SpacePacketSubfields::SeqFlagsOffset; // Sequence Flags 0b11 = unsegmented User Data
56  packetSequenceControl |=
57  sequenceCount & static_cast<U16>(SpacePacketSubfields::SeqCountMask); // 14 bit sequence count
58 
59  FW_ASSERT(data.getSize() <= std::numeric_limits<U16>::max(), static_cast<FwAssertArgType>(data.getSize()));
60  U16 packetDataLength =
61  static_cast<U16>(data.getSize() - 1); // Standard specifies length is number of bytes minus 1
62 
63  header.set_packetIdentification(packetIdentification);
64  header.set_packetSequenceControl(packetSequenceControl);
65  header.set_packetDataLength(packetDataLength);
66 
67  // -----------------------------------------------
68  // Serialize the packet
69  // -----------------------------------------------
70  status = frameSerializer.serialize(header);
71  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
72  status = frameSerializer.serialize(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
73  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
74 
75  this->dataOut_out(0, frameBuffer, context);
76  this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
77 }
78 
79 void SpacePacketFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
80  if (this->isConnected_comStatusOut_OutputPort(portNum)) {
81  this->comStatusOut_out(portNum, condition);
82  }
83 }
84 
85 void SpacePacketFramer ::dataReturnIn_handler(FwIndexType portNum,
86  Fw::Buffer& frameBuffer,
87  const ComCfg::FrameContext& context) {
88  // dataReturnIn is the allocated buffer coming back from the dataOut port
89  this->bufferDeallocate_out(0, frameBuffer);
90 }
91 
92 } // namespace Ccsds
93 } // namespace Svc
Serialization/Deserialization operation was successful.
ComCfg::APID::T get_apid() const
Get member apid.
~SpacePacketFramer()
Destroy SpacePacketFramer object.
PlatformSizeType FwSizeType
U8 * getData() const
Definition: Buffer.cpp:56
SpacePacketFramer(const char *const compName)
Construct SpacePacketFramer object.
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatusOut.
SerializeStatus
forward declaration for string
T
The raw enum type.
Definition: APIDEnumAc.hpp:31
U16 getApidSeqCount_out(FwIndexType portNum, const ComCfg::APID &apid, U16 sequenceCount)
Invoke output port getApidSeqCount.
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.
void bufferDeallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferDeallocate.
Auto-generated base for SpacePacketFramer component.
void set_packetDataLength(U16 packetDataLength)
Set member packetDataLength.
FwSizeType getSize() const
Definition: Buffer.cpp:60
void set_packetIdentification(U16 packetIdentification)
Set member packetIdentification.
Omit length from serialization.
PlatformIndexType FwIndexType
void set_packetSequenceControl(U16 packetSequenceControl)
Set member packetSequenceControl.
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:95
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.
Fw::Buffer bufferAllocate_out(FwIndexType portNum, FwSizeType size)
Invoke output port bufferAllocate.