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 "FpConfig.hpp"
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, Fw::Buffer& contextBuffer) {
27  // Read the packet type from the packet buffer
30  {
31  Fw::SerializeBufferBase& serial = packetBuffer.getSerializeRepr();
32  status = serial.setBuffLen(packetBuffer.getSize());
33  FW_ASSERT(status == Fw::FW_SERIALIZE_OK);
34  status = serial.deserialize(packetType);
35  }
36 
37  // Whether to deallocate the packet buffer
38  bool deallocate = true;
39 
40  // Process the packet
41  if (status == Fw::FW_SERIALIZE_OK) {
42  U8* const packetData = packetBuffer.getData();
43  const FwSizeType packetSize = packetBuffer.getSize();
44  switch (packetType) {
45  // Handle a command packet
47  // Allocate a com buffer on the stack
48  Fw::ComBuffer com;
49  // Copy the contents of the packet buffer into the com buffer
50  status = com.setBuff(packetData, packetSize);
51  if (status == Fw::FW_SERIALIZE_OK) {
52  // Send the com buffer - critical functionality so it is considered an error not to
53  // have the port connected. This is why we don't check isConnected() before sending.
54  this->commandOut_out(0, com, 0);
55  } else {
57  }
58  break;
59  }
60  // Handle a file packet
62  // If the file uplink output port is connected,
63  // send the file packet. Otherwise take no action.
64  if (this->isConnected_fileOut_OutputPort(0)) {
65  // Make sure we can cast down to U32 without overflow
66  FW_ASSERT((packetSize - sizeof(packetType)) < std::numeric_limits<U32>::max(),
67  static_cast<FwAssertArgType>(packetSize - sizeof(packetType)));
68  // Shift the packet buffer to skip the packet type
69  // The FileUplink component does not expect the packet
70  // type to be there.
71  packetBuffer.setData(packetData + sizeof(packetType));
72  packetBuffer.setSize(static_cast<U32>(packetSize - sizeof(packetType)));
73  // Send the packet buffer
74  this->fileOut_out(0, packetBuffer);
75  // Transfer ownership of the packetBuffer to the receiver
76  deallocate = false;
77  }
78  break;
79  }
80  default: {
81  // Packet type is not known to the F Prime protocol. If the unknownDataOut port is
82  // connected, forward packet and context for further processing
84  this->unknownDataOut_out(0, packetBuffer, contextBuffer);
85  // Transfer ownership of the packetBuffer to the receiver
86  deallocate = false;
87  }
88  }
89  }
90  } else {
92  }
93 
94  if (deallocate) {
95  // Deallocate the packet buffer
96  this->bufferDeallocate_out(0, packetBuffer);
97  }
98 }
99 
100 void FprimeRouter ::cmdResponseIn_handler(FwIndexType portNum,
101  FwOpcodeType opcode,
102  U32 cmdSeq,
103  const Fw::CmdResponse& response) {
104  // Nothing to do
105 }
106 } // namespace Svc
void commandOut_out(FwIndexType portNum, Fw::ComBuffer &data, U32 context)
Invoke output port commandOut.
Serialization/Deserialization operation was successful.
SerializeBufferBase & getSerializeRepr()
Definition: Buffer.cpp:107
void setData(U8 *data)
Definition: Buffer.cpp:80
void setSize(SizeType size)
Definition: Buffer.cpp:87
PlatformSizeType FwSizeType
Definition: FpConfig.h:35
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)
PlatformIndexType FwIndexType
Definition: FpConfig.h:25
void bufferDeallocate_out(FwIndexType portNum, Fw::Buffer &fwBuffer)
Invoke output port bufferDeallocate.
SerializeStatus
forward declaration for string
U32 FwPacketDescriptorType
Definition: FpConfig.h:87
FprimeRouter(const char *const compName)
Construct FprimeRouter object.
U32 FwOpcodeType
Definition: FpConfig.h:91
~FprimeRouter()
Destroy FprimeRouter object.
Auto-generated base for FprimeRouter component.
C++-compatible configuration header for fprime configuration.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:32
void unknownDataOut_out(FwIndexType portNum, Fw::Buffer &data, Fw::Buffer &context)
Invoke output port unknownDataOut.
SerializeStatus deserialize(U8 &val)
deserialize 8-bit unsigned int
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
SizeType getSize() const
Definition: Buffer.cpp:72
bool isConnected_unknownDataOut_OutputPort(FwIndexType portNum)
#define FW_ASSERT(...)
Definition: Assert.hpp:14
SerializeStatus setBuffLen(Serializable::SizeType length)
sets buffer length manually after filling with data