F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FprimeFramer.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FprimeFramer.cpp
3 // \author thomas-bc
4 // \brief cpp file for FprimeFramer component implementation class
5 // ======================================================================
6 
10 #include "Utils/Hash/Hash.hpp"
11 
12 namespace Svc {
13 
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17 
18 FprimeFramer ::FprimeFramer(const char* const compName) : FprimeFramerComponentBase(compName) {}
19 
21 
22 // ----------------------------------------------------------------------
23 // Handler implementations for typed input ports
24 // ----------------------------------------------------------------------
25 
26 void FprimeFramer ::dataIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
29 
30  // Full size of the frame will be size of header + data + trailer
31  FwSizeType frameSize =
33  FW_ASSERT(data.getSize() <= std::numeric_limits<FprimeProtocol::TokenType>::max(), static_cast<FwAssertArgType>(frameSize));
34  FW_ASSERT(frameSize <= std::numeric_limits<Fw::Buffer::SizeType>::max(), static_cast<FwAssertArgType>(frameSize));
35 
36  // Allocate frame buffer
37  Fw::Buffer frameBuffer = this->bufferAllocate_out(0, static_cast<Fw::Buffer::SizeType>(frameSize));
38  auto frameSerializer = frameBuffer.getSerializer();
39  Fw::SerializeStatus status;
40 
41  // Serialize the header
42  // 0xDEADBEEF is already set as the default value for the header startWord field in the FPP type definition
43  header.setlengthField(data.getSize());
44  status = frameSerializer.serialize(header);
45  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
46 
47  // Serialize the data
48  status = frameSerializer.serialize(data.getData(), data.getSize(), Fw::Serialization::OMIT_LENGTH);
49  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
50 
51  // Serialize the trailer (with CRC computation)
52  Utils::HashBuffer hashBuffer;
53  Utils::Hash::hash(frameBuffer.getData(), frameSize - HASH_DIGEST_LENGTH, hashBuffer);
54  trailer.setcrcField(hashBuffer.asBigEndianU32());
55  status = frameSerializer.serialize(trailer);
56  FW_ASSERT(status == Fw::FW_SERIALIZE_OK, status);
57 
58  // Send the full frame out - this port shall always be connected
59  this->dataOut_out(0, frameBuffer, context);
60  // Return original (unframed) data buffer ownership back to its sender - always connected
61  this->dataReturnOut_out(0, data, context);
62 }
63 
64 void FprimeFramer ::comStatusIn_handler(FwIndexType portNum, Fw::Success& condition) {
65  if (this->isConnected_comStatusOut_OutputPort(portNum)) {
66  this->comStatusOut_out(portNum, condition);
67  }
68 }
69 
70 void FprimeFramer ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& frameBuffer, const ComCfg::FrameContext& context) {
71  // dataReturnIn is the allocated buffer coming back from the ComManager (e.g. ComStub) component
72  this->bufferDeallocate_out(0, frameBuffer);
73 }
74 
75 } // namespace Svc
Serialization/Deserialization operation was successful.
#define HASH_DIGEST_LENGTH
Definition: CRC32.hpp:18
PlatformSizeType FwSizeType
void setcrcField(U32 crcField)
Set member crcField.
Auto-generated base for FprimeFramer component.
U8 * getData() const
Definition: Buffer.cpp:68
Describes the frame header format for the F Prime communications protocol.
SerializeStatus
forward declaration for string
void setlengthField(Svc::FprimeProtocol::TokenType lengthField)
Set member lengthField.
void dataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataOut.
bool isConnected_comStatusOut_OutputPort(FwIndexType portNum)
Describes the frame trailer format for the F Prime communications protocol.
~FprimeFramer()
Destroy FprimeFramer object.
static void hash(const void *data, const FwSizeType len, HashBuffer &buffer)
Definition: CRC32.cpp:32
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port dataReturnOut.
Omit length from serialization.
PlatformIndexType FwIndexType
U32 asBigEndianU32() const
Convert bytes 0 through 3 of the hash data to a big-Endian U32 value.
A container class for holding a hash buffer.
Definition: HashBuffer.hpp:26
Fw::Buffer bufferAllocate_out(FwIndexType portNum, U32 size)
Invoke output port bufferAllocate.
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
void bufferDeallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferDeallocate.
SizeType getSize() const
Definition: Buffer.cpp:72
void comStatusOut_out(FwIndexType portNum, Fw::Success &condition)
Invoke output port comStatusOut.
FprimeFramer(const char *const compName)
Construct FprimeFramer object.
ExternalSerializeBufferWithMemberCopy getSerializer()
Definition: Buffer.cpp:107
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.
PlatformAssertArgType FwAssertArgType
The type of arguments to assert functions.