F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
TmFramer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title TmFramer.cpp
3 // \author thomas-bc
4 // \brief cpp file for TmFramer component implementation class
5 // ======================================================================
6 
10 
11 namespace Svc {
12 
13 namespace Ccsds {
14 
15 // ----------------------------------------------------------------------
16 // Component construction and destruction
17 // ----------------------------------------------------------------------
18 
19 TmFramer ::TmFramer(const char* const compName)
20  : TmFramerComponentBase(compName), m_masterFrameCount(0), m_virtualFrameCount(0) {}
21 
23 
24 // ----------------------------------------------------------------------
25 // Handler implementations for typed input ports
26 // ----------------------------------------------------------------------
27 
28 void TmFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
29  // The data must fill the data field exactly: idle filling (Standard 4.2.2.5) is done upstream by Svc::ComAggregator
30  FW_ASSERT(data.getSize() == TmPayloadCapacity, static_cast<FwAssertArgType>(data.getSize()));
32  static_cast<FwAssertArgType>(context.get_firstHeaderPointer()));
33  FW_ASSERT(this->m_bufferState == BufferOwnershipState::OWNED, static_cast<FwAssertArgType>(this->m_bufferState));
34 
35  // -----------------------------------------------
36  // Header
37  // -----------------------------------------------
38  TMHeader header;
39 
40  // GVCID (Global Virtual Channel ID) (Standard 4.1.2.2 and 4.1.2.3)
41  U16 globalVcId = static_cast<U16>(context.get_vcId() << TMSubfields::virtualChannelIdOffset);
42  globalVcId |= static_cast<U16>(ComCfg::SpacecraftId << TMSubfields::spacecraftIdOffset);
43  globalVcId |= 0x0; // Operational Control Field: Flag set to 0 (Standard 4.1.2.4)
44 
45  // Data Field Status (Standard 4.1.2.7):
46  // - all flags to 0 except Segment Length Id 0b11 (Standard 4.1.2.7.5)
47  // - First Header Pointer from context (Standard 4.1.2.7.6): set by an upstream aggregator when packets
48  // span frames; the default of 0 indicates a packet header at offset 0 of the data field
49  const U16 dataFieldStatus =
50  static_cast<U16>((0x3 << TMSubfields::segLengthOffset) | context.get_firstHeaderPointer());
51 
52  header.set_globalVcId(globalVcId);
53  header.set_masterFrameCount(this->m_masterFrameCount);
54  header.set_virtualFrameCount(this->m_virtualFrameCount);
55  header.set_dataFieldStatus(dataFieldStatus);
56 
57  // We use only a single Virtual Channel for now, so master and virtual frame counts are the same
58  this->m_masterFrameCount++; // U8 intended to wrap around (modulo 256)
59  this->m_virtualFrameCount++; // U8 intended to wrap around (modulo 256)
60 
61  // -------------------------------------------------
62  // Data field
63  // -------------------------------------------------
64  // Payload packet
65  Fw::SerializeStatus status;
66  // Create frame Fw::Buffer using member data field
67  Fw::Buffer frameBuffer = Fw::Buffer(this->m_frameBuffer, sizeof(this->m_frameBuffer));
68  auto frameSerializer = frameBuffer.getSerializer();
69  status = frameSerializer.serializeFrom(header);
70  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
71  status = frameSerializer.serializeFrom(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
72  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
73 
74  // -------------------------------------------------
75  // Trailer (CRC)
76  // -------------------------------------------------
77  TMTrailer trailer;
78  // Compute CRC over the entire frame buffer minus the FECF trailer (Standard 4.1.6)
79  U16 crc =
80  Ccsds::Utils::CRC16::compute(frameBuffer.getData(), sizeof(this->m_frameBuffer) - TMTrailer::SERIALIZED_SIZE);
81  // Set the Frame Error Control Field (FECF)
82  trailer.set_fecf(crc);
83  // Move the serializer pointer to the end of the location where the trailer will be serialized
84  status = frameSerializer.moveSerToOffset(ComCfg::TmFrameFixedSize - TMTrailer::SERIALIZED_SIZE);
85  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
86  status = frameSerializer.serializeFrom(trailer);
87  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
88 
89  this->m_bufferState = BufferOwnershipState::NOT_OWNED;
90  this->dataOut_out(0, frameBuffer, context);
91  this->dataReturnOut_out(0, data, context); // return ownership of the original data buffer
92 }
93 
94 void TmFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
95  if (this->isConnected_comStatusOut_OutputPort(portNum)) {
96  this->comStatusOut_out(portNum, condition);
97  }
98 }
99 
100 void TmFramer ::dataReturnIn_handler(FwIndexType portNum,
101  Fw::Buffer& frameBuffer,
102  const ComCfg::FrameContext& context) {
103  // Assert that the returned buffer is the member, and set ownership state
104  FW_ASSERT(frameBuffer.getData() >= &this->m_frameBuffer[0]);
105  FW_ASSERT(frameBuffer.getData() < &this->m_frameBuffer[0] + sizeof(this->m_frameBuffer));
106  this->m_bufferState = BufferOwnershipState::OWNED;
107 }
108 } // namespace Ccsds
109 } // namespace Svc
Serialization/Deserialization operation was successful.
static U16 compute(const U8 *buffer, U32 length)
compute CRC16 for a buffer
Definition: CRC16.hpp:44
void set_globalVcId(U16 globalVcId)
Set member globalVcId.
~TmFramer()
Destroy TmFramer object.
Definition: TmFramer.cpp:22
U8 * getData() const
Definition: Buffer.cpp:82
Describes the frame trailer format for a Telemetry (TM) Transfer Frame.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
void set_fecf(U16 fecf)
Set member fecf.
SerializeStatus
forward declaration for string
Describes the frame header format for a Telemetry (TM) Transfer Frame.
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition) const
Invoke output port comStatusOut.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataOut.
Omit length from serialization.
U8 get_vcId() const
Get member vcId.
void set_dataFieldStatus(U16 dataFieldStatus)
Set member dataFieldStatus.
bool isConnected_comStatusOut_OutputPort(FwIndexType portNum) const
U16 get_firstHeaderPointer() const
Get member firstHeaderPointer.
FwSizeType getSize() const
Definition: Buffer.cpp:90
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataReturnOut.
void set_virtualFrameCount(U8 virtualFrameCount)
Set member virtualFrameCount.
Auto-generated base for TmFramer component.
TmFramer(const char *const compName)
Construct TmFramer object.
Definition: TmFramer.cpp:19
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
The size of the serial representation.
void set_masterFrameCount(U8 masterFrameCount)
Set member masterFrameCount.
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:155
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.