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