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 
9 #include "Fw/Com/ComPacket.hpp"
10 #include "Fw/Logger/Logger.hpp"
11 
12 namespace Svc {
13 
14 // ----------------------------------------------------------------------
15 // Component construction and destruction
16 // ----------------------------------------------------------------------
17 
18 FprimeRouter ::FprimeRouter(const char* const compName) : FprimeRouterComponentBase(compName) {}
19 
21 
22 // ----------------------------------------------------------------------
23 // Handler implementations for user-defined typed input ports
24 // ----------------------------------------------------------------------
25 
26 void FprimeRouter ::dataIn_handler(FwIndexType portNum, Fw::Buffer& packetBuffer, const ComCfg::FrameContext& context) {
27  // Read the packet type from the packet buffer
30  {
31  auto esb = packetBuffer.getDeserializer();
32  status = esb.deserialize(packetType);
33  }
34 
35  // Whether to deallocate the packet buffer
36  bool deallocate = true;
37 
38  // Process the packet
39  if (status == Fw::FW_SERIALIZE_OK) {
40  U8* const packetData = packetBuffer.getData();
41  const FwSizeType packetSize = packetBuffer.getSize();
42  switch (packetType) {
43  // Handle a command packet
45  // Allocate a com buffer on the stack
46  Fw::ComBuffer com;
47  // Copy the contents of the packet buffer into the com buffer
48  status = com.setBuff(packetData, packetSize);
49  if (status == Fw::FW_SERIALIZE_OK) {
50  // Send the com buffer - critical functionality so it is considered an error not to
51  // have the port connected. This is why we don't check isConnected() before sending.
52  this->commandOut_out(0, com, 0);
53  } else {
55  }
56  break;
57  }
58  // Handle a file packet
60  // If the file uplink output port is connected,
61  // send the file packet. Otherwise take no action.
62  if (this->isConnected_fileOut_OutputPort(0)) {
63  // Send the packet buffer
64  this->fileOut_out(0, packetBuffer);
65  // Transfer ownership of the packetBuffer to the receiver
66  deallocate = false;
67  }
68  break;
69  }
70  default: {
71  // Packet type is not known to the F Prime protocol. If the unknownDataOut port is
72  // connected, forward packet and context for further processing
74  this->unknownDataOut_out(0, packetBuffer, context);
75  // Transfer ownership of the packetBuffer to the receiver
76  deallocate = false;
77  }
78  }
79  }
80  } else {
82  }
83 
84  if (deallocate) {
85  // Deallocate the packet buffer
86  this->bufferDeallocate_out(0, packetBuffer);
87  }
88 }
89 
90 void FprimeRouter ::cmdResponseIn_handler(FwIndexType portNum,
91  FwOpcodeType opcode,
92  U32 cmdSeq,
93  const Fw::CmdResponse& response) {
94  // Nothing to do
95 }
96 } // namespace Svc
void commandOut_out(FwIndexType portNum, Fw::ComBuffer &data, U32 context)
Invoke output port commandOut.
Serialization/Deserialization operation was successful.
PlatformSizeType FwSizeType
U8 * getData() const
Definition: Buffer.cpp:68
void fileOut_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port fileOut.
Enum representing a command response.
bool isConnected_fileOut_OutputPort(FwIndexType portNum)
void bufferDeallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferDeallocate.
SerializeStatus
forward declaration for string
ExternalSerializeBufferWithMemberCopy getDeserializer()
Definition: Buffer.cpp:117
FprimeRouter(const char *const compName)
Construct FprimeRouter object.
U32 FwOpcodeType
The type of a command opcode.
~FprimeRouter()
Destroy FprimeRouter object.
Auto-generated base for FprimeRouter component.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:56
void unknownDataOut_out(FwIndexType portNum, Fw::Buffer &data, const ComCfg::FrameContext &context)
Invoke output port unknownDataOut.
U32 FwPacketDescriptorType
The type of a com packet descriptor.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
PlatformIndexType FwIndexType
void log_WARNING_HI_DeserializationError(U32 status) const
SerializeStatus setBuff(const U8 *src, Serializable::SizeType length)
sets buffer contents and size
void log_WARNING_HI_SerializationError(U32 status) const
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
SizeType getSize() const
Definition: Buffer.cpp:72
bool isConnected_unknownDataOut_OutputPort(FwIndexType portNum)