F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
FprimeRouter.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title FprimeRouter.cpp
3 // \author thomas-bc
4 // \brief cpp file for FprimeRouter component implementation class
5 // ======================================================================
6 
8 #include "Fw/Com/ComPacket.hpp"
10 #include "Fw/Logger/Logger.hpp"
11 #include "config/ApidEnumAc.hpp"
12 
13 namespace Svc {
14 
15 // ----------------------------------------------------------------------
16 // Component construction and destruction
17 // ----------------------------------------------------------------------
18 
19 FprimeRouter ::FprimeRouter(const char* const compName) : FprimeRouterComponentBase(compName) {}
20 
22 
23 // ----------------------------------------------------------------------
24 // Handler implementations for user-defined typed input ports
25 // ----------------------------------------------------------------------
26 
27 void FprimeRouter ::dataIn_handler(FwIndexType portNum, Fw::Buffer& packetBuffer, const ComCfg::FrameContext& context) {
28  Fw::SerializeStatus status;
29  Fw::ComPacketType packetType = context.get_apid();
30  // Route based on received APID (packet type)
31  switch (packetType) {
32  // Handle a command packet
33  case Fw::ComPacketType::FW_PACKET_COMMAND: {
34  // Allocate a com buffer on the stack
35  Fw::ComBuffer com;
36  // Copy the contents of the packet buffer into the com buffer
37  status = com.setBuff(packetBuffer.getData(), packetBuffer.getSize());
38  if (status == Fw::FW_SERIALIZE_OK) {
39  // Send the com buffer - critical functionality so it is considered an error not to
40  // have the port connected. This is why we don't check isConnected() before sending.
41  this->commandOut_out(0, com, 0);
42  } else {
44  }
45  // Return ownership of the incoming packetBuffer with an empty context
46  ComCfg::FrameContext emptyContext;
47  this->dataReturnOut_out(0, packetBuffer, emptyContext);
48  break;
49  }
50  // Handle a file packet
51  case Fw::ComPacketType::FW_PACKET_FILE: {
52  // If the file uplink output port is connected, send the file packet directly.
53  // Ownership is passed to the receiver and will come back on fileBufferReturnIn,
54  // at which point we return it to the deframer via dataReturnOut.
55  if (this->isConnected_fileOut_OutputPort(0)) {
56  this->fileOut_out(0, packetBuffer);
57  } else {
58  // Port not connected, return the buffer immediately with an empty context
59  ComCfg::FrameContext emptyContext;
60  this->dataReturnOut_out(0, packetBuffer, emptyContext);
61  }
62  break;
63  }
64  default: {
65  // Packet type is not known to the F Prime protocol. If the unknownDataOut port is
66  // connected, forward packet and context for further processing.
67  // Ownership is passed to the receiver and will come back on fileBufferReturnIn,
68  // at which point we return it to the deframer via dataReturnOut.
70  this->unknownDataOut_out(0, packetBuffer, context);
71  } else {
72  // Port not connected, return the buffer immediately with an empty context
73  ComCfg::FrameContext emptyContext;
74  this->dataReturnOut_out(0, packetBuffer, emptyContext);
75  }
76  break;
77  }
78  }
79 }
80 
81 void FprimeRouter ::cmdResponseIn_handler(FwIndexType portNum,
82  FwOpcodeType opcode,
83  U32 cmdSeq,
84  const Fw::CmdResponse& response) {
85  // Nothing to do
86 }
87 
88 void FprimeRouter ::fileBufferReturnIn_handler(FwIndexType portNum, Fw::Buffer& fwBuffer) {
89  // Return ownership of the buffer to the deframer with an empty context
90  ComCfg::FrameContext context;
91  this->dataReturnOut_out(0, fwBuffer, context);
92 }
93 
94 } // namespace Svc
Serialization/Deserialization operation was successful.
FwIdType FwOpcodeType
The type of a command opcode.
void unknownDataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port unknownDataOut.
ComCfg::Apid::T get_apid() const
Get member apid.
U8 * getData() const
Definition: Buffer.cpp:56
void fileOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer) const
Invoke output port fileOut.
Enum representing a command response.
void commandOut_out(FwIndexType portNum, Fw::ComBuffer &data, U32 context) const
Invoke output port commandOut.
SerializeStatus
forward declaration for string
FprimeRouter(const char *const compName)
Construct FprimeRouter object.
T
The raw enum type.
Definition: ApidEnumAc.hpp:31
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length) override
Set buffer contents from external source.
~FprimeRouter()
Destroy FprimeRouter object.
Auto-generated base for FprimeRouter component.
FwSizeType getSize() const
Definition: Buffer.cpp:60
void dataReturnOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context) const
Invoke output port dataReturnOut.
bool isConnected_unknownDataOut_OutputPort(FwIndexType portNum) const
PlatformIndexType FwIndexType
void log_WARNING_HI_SerializationError(U32 status) const
Type used to pass context info between components during framing/deframing.
bool isConnected_fileOut_OutputPort(FwIndexType portNum) const
RateGroupDivider component implementation.