F´ Flight Software - C/C++ Documentation NASA-v1.6.0
A framework for building embedded system applications to NASA flight quality standards.
Loading...
Searching...
No Matches
Framer.cpp
Go to the documentation of this file.
1// ======================================================================
2// \title Framer.cpp
3// \author mstarch
4// \brief cpp file for Framer component implementation class
5//
6// \copyright
7// Copyright 2009-2022, by the California Institute of Technology.
8// ALL RIGHTS RESERVED. United States Government Sponsorship
9// acknowledged.
10//
11// ======================================================================
12
13#include <FpConfig.hpp>
14#include <Svc/Framer/Framer.hpp>
15#include "Fw/Logger/Logger.hpp"
16#include "Utils/Hash/Hash.hpp"
17
18namespace Svc {
19
20// ----------------------------------------------------------------------
21// Construction, initialization, and destruction
22// ----------------------------------------------------------------------
23
24Framer ::Framer(const char* const compName)
25 : FramerComponentBase(compName), FramingProtocolInterface(), m_protocol(nullptr), m_frame_sent(false) {}
26
27void Framer ::init(const NATIVE_INT_TYPE instance) {
28 FramerComponentBase::init(instance);
29}
30
31Framer ::~Framer() {}
32
33void Framer ::setup(FramingProtocol& protocol) {
34 FW_ASSERT(this->m_protocol == nullptr);
35 this->m_protocol = &protocol;
36 protocol.setup(*this);
37}
38
39void Framer ::handle_framing(const U8* const data, const U32 size, Fw::ComPacket::ComPacketType packet_type) {
40 FW_ASSERT(this->m_protocol != nullptr);
41 this->m_frame_sent = false; // Clear the flag to detect if frame was sent
42 this->m_protocol->frame(data, size, packet_type);
43 // If no frame was sent, Framer has the obligation to report success
44 if (this->isConnected_comStatusOut_OutputPort(0) && (!this->m_frame_sent)) {
45 Fw::Success status = Fw::Success::SUCCESS;
46 this->comStatusOut_out(0, status);
47 }
48}
49
50// ----------------------------------------------------------------------
51// Handler implementations for user-defined typed input ports
52// ----------------------------------------------------------------------
53
54void Framer ::comIn_handler(const NATIVE_INT_TYPE portNum, Fw::ComBuffer& data, U32 context) {
55 this->handle_framing(data.getBuffAddr(), data.getBuffLength(), Fw::ComPacket::FW_PACKET_UNKNOWN);
56}
57
58void Framer ::bufferIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& fwBuffer) {
59 this->handle_framing(fwBuffer.getData(), fwBuffer.getSize(), Fw::ComPacket::FW_PACKET_FILE);
60 // Deallocate the buffer after it was processed by the framing protocol
61 this->bufferDeallocate_out(0, fwBuffer);
62}
63
64void Framer ::comStatusIn_handler(const NATIVE_INT_TYPE portNum, Fw::Success& condition) {
65 if (this->isConnected_comStatusOut_OutputPort(portNum)) {
66 this->comStatusOut_out(portNum, condition);
67 }
68}
69
70// ----------------------------------------------------------------------
71// Framing protocol implementations
72// ----------------------------------------------------------------------
73
74void Framer ::send(Fw::Buffer& outgoing) {
75 FW_ASSERT(!this->m_frame_sent); // Prevent multiple sends per-packet
76 const Drv::SendStatus sendStatus = this->framedOut_out(0, outgoing);
77 if (sendStatus.e != Drv::SendStatus::SEND_OK) {
78 // Note: if there is a data sending problem, an EVR likely wouldn't
79 // make it down. Log the issue in hopes that
80 // someone will see it.
81 Fw::Logger::logMsg("[ERROR] Failed to send framed data: %d\n", sendStatus.e);
82 }
83 this->m_frame_sent = true; // A frame was sent
84}
85
86Fw::Buffer Framer ::allocate(const U32 size) {
87 return this->framedAllocate_out(0, size);
88}
89
90} // end namespace Svc
#define FW_ASSERT(...)
Definition Assert.hpp:7
PlatformIntType NATIVE_INT_TYPE
Definition BasicTypes.h:51
uint8_t U8
8-bit unsigned integer
Definition BasicTypes.h:26
C++-compatible configuration header for fprime configuration.
U8 * getData() const
Definition Buffer.cpp:60
U32 getSize() const
Definition Buffer.cpp:64
U8 * getBuffAddr()
gets buffer address for data filling
Definition ComBuffer.cpp:40
static void logMsg(const char *fmt, POINTER_CAST a0=0, POINTER_CAST a1=0, POINTER_CAST a2=0, POINTER_CAST a3=0, POINTER_CAST a4=0, POINTER_CAST a5=0, POINTER_CAST a6=0, POINTER_CAST a7=0, POINTER_CAST a8=0, POINTER_CAST a9=0)
Definition Logger.cpp:18
NATIVE_UINT_TYPE getBuffLength() const
returns current buffer size
abstract class representing a framing protocol
void setup(FramingProtocolInterface &interface)
setup function called to supply the interface used for allocation and sending
interface supplied to the framing protocol