F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SendBuffComponentImpl.cpp
Go to the documentation of this file.
2 #include <Fw/Types/Assert.hpp>
3 #include <Os/Console.hpp>
5 #include <cstring>
6 
7 #include <cstdio>
8 
9 #define DEBUG_LEVEL 1
10 
11 namespace Ref {
12 
13 SendBuffImpl::SendBuffImpl(const char* compName) : SendBuffComponentBase(compName) {
14  this->m_currPacketId = 0;
15  this->m_invocations = 0;
16  this->m_buffsSent = 0;
17  this->m_errorsInjected = 0;
18  this->m_injectError = false;
19  this->m_sendPackets = false;
20  this->m_currPacketId = 0;
21  this->m_firstPacketSent = false;
22  this->m_state = SendBuff_ActiveState::SEND_IDLE;
23 }
24 
26 
27 void SendBuffImpl::SchedIn_handler(FwIndexType portNum, U32 context) {
28  // first, dequeue any messages
29 
30  MsgDispatchStatus stat = MSG_DISPATCH_OK;
31 
32  while (MSG_DISPATCH_OK == stat) {
33  stat = this->doDispatch();
34  FW_ASSERT(stat != MSG_DISPATCH_ERROR);
35  }
36 
37  if (this->m_sendPackets) {
38  // check to see if first
39  if (this->m_firstPacketSent) {
40  this->m_firstPacketSent = false;
41  this->log_ACTIVITY_HI_FirstPacketSent(this->m_currPacketId);
42  this->tlmWrite_NumErrorsInjected(this->m_errorsInjected);
43  }
44  // reset buffer
45  this->m_testBuff.resetSer();
46  // serialize packet id
47  Fw::SerializeStatus serStat = this->m_testBuff.serializeFrom(this->m_currPacketId);
48  FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK);
49  // increment packet id
50  this->m_currPacketId++;
51  this->m_buffsSent++;
52  // set telemetry
53  this->tlmWrite_PacketsSent(this->m_buffsSent);
54  // write data
55  U8 testData[24];
56  FwSizeType dataSize = static_cast<FwSizeType>(sizeof(testData));
57  memset(testData, 0xFF, static_cast<size_t>(dataSize));
58  // compute checksum
59  U32 csum = 0;
60  for (U32 byte = 0; byte < dataSize; byte++) {
61  csum += testData[byte];
62  }
63  // inject error, if requested
64  if (this->m_injectError) {
65  this->m_injectError = false;
66  this->m_errorsInjected++;
67  testData[5] = 0;
68  this->log_WARNING_HI_PacketErrorInserted(this->m_currPacketId - 1);
69  }
70  // serialize data
71  serStat = this->m_testBuff.serializeFrom(testData, dataSize);
72  FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK);
73  // serialize checksum
74  serStat = this->m_testBuff.serializeFrom(csum);
75  FW_ASSERT(serStat == Fw::FW_SERIALIZE_OK);
76  // send data
77  this->Data_out(0, this->m_testBuff);
78  }
79 
80  this->m_invocations++;
81 
82  this->tlmWrite_SendState(this->m_state);
83 }
84 
85 void SendBuffImpl::SB_START_PKTS_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
86  this->m_sendPackets = true;
87  this->m_state = SendBuff_ActiveState::SEND_ACTIVE;
88  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
89 }
90 
91 void SendBuffImpl::SB_INJECT_PKT_ERROR_cmdHandler(FwOpcodeType opCode, U32 cmdSeq) {
92  this->m_injectError = true;
93  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
94 }
95 
96 void SendBuffImpl::SB_GEN_FATAL_cmdHandler(FwOpcodeType opCode,
97  U32 cmdSeq,
98  U32 arg1,
99  U32 arg2,
100  U32 arg3
101 ) {
102  this->log_FATAL_SendBuffFatal(arg1, arg2, arg3);
103  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
104 }
105 
107 /* Generate an ASSERT */
108 void SendBuffImpl::SB_GEN_ASSERT_cmdHandler(FwOpcodeType opCode,
109  U32 cmdSeq,
110  U32 arg1,
111  U32 arg2,
112  U32 arg3,
113  U32 arg4,
114  U32 arg5,
115  U32 arg6
116 ) {
117  FW_ASSERT(0, arg1, arg2, arg3, arg4, arg5, arg6);
118  this->cmdResponse_out(opCode, cmdSeq, Fw::CmdResponse::OK);
119 }
120 
121 void SendBuffImpl::parameterUpdated(FwPrmIdType id) {
122  this->log_ACTIVITY_LO_BuffSendParameterUpdated(id);
123  Fw::ParamValid valid;
124  switch (id) {
125  case PARAMID_PARAMETER3: {
126  U8 val = this->paramGet_parameter3(valid);
127  this->tlmWrite_Parameter3(val);
128  break;
129  }
130  case PARAMID_PARAMETER4: {
131  F32 val = this->paramGet_parameter4(valid);
132  this->tlmWrite_Parameter4(val);
133  break;
134  }
135  default:
136  FW_ASSERT(0, id);
137  break;
138  }
139 }
140 } // namespace Ref
Serialization/Deserialization operation was successful.
FwIdType FwOpcodeType
The type of a command opcode.
SerializeStatus serializeFrom(U8 val, Endianness mode=Endianness::BIG) override
Serialize an 8-bit unsigned integer value.
PlatformSizeType FwSizeType
SendBuffImpl(const char *compName)
constructor
FwIdType FwPrmIdType
The type of a parameter identifier.
SerializeStatus
forward declaration for string
float F32
32-bit floating point
Definition: BasicTypes.h:84
void resetSer() override
Reset serialization pointer to beginning of buffer.
Command successfully executed.
uint8_t U8
8-bit unsigned integer
Definition: BasicTypes.h:54
PlatformIndexType FwIndexType
Enum representing parameter validity.
#define FW_ASSERT(...)
Definition: Assert.hpp:14