47
47
*/
48
48
typedef union
49
49
{
50
- CFE_MSG_Message_t MsgHdr ;
50
+ CFE_MSG_Message_t Msg ;
51
51
uint8 bytes [CI_LAB_MAX_INGEST ];
52
52
uint16 hwords [2 ];
53
53
} CI_LAB_IngestBuffer_t ;
54
54
55
- typedef union
56
- {
57
- CFE_MSG_Message_t MsgHdr ;
58
- CI_LAB_HkTlm_t HkTlm ;
59
- } CI_LAB_HkTlm_Buffer_t ;
60
-
61
55
typedef struct
62
56
{
63
57
bool SocketConnected ;
64
58
CFE_SB_PipeId_t CommandPipe ;
65
- CFE_MSG_Message_t * MsgPtr ;
66
59
osal_id_t SocketID ;
67
60
OS_SockAddr_t SocketAddress ;
68
61
69
- CI_LAB_HkTlm_Buffer_t HkBuffer ;
62
+ CI_LAB_HkTlm_t HkTlm ;
70
63
CI_LAB_IngestBuffer_t IngestBuffer ;
71
64
} CI_LAB_GlobalData_t ;
72
65
@@ -87,7 +80,9 @@ static CFE_EVS_BinFilter_t CI_LAB_EventFilters[] =
87
80
*/
88
81
int32 CI_LAB_Noop (const CI_LAB_Noop_t * data );
89
82
int32 CI_LAB_ResetCounters (const CI_LAB_ResetCounters_t * data );
90
- int32 CI_LAB_ReportHousekeeping (const CFE_SB_CmdHdr_t * data );
83
+
84
+ /* Housekeeping message handler */
85
+ int32 CI_LAB_ReportHousekeeping (const CFE_MSG_CommandHeader_t * data );
91
86
92
87
/** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
93
88
/* CI_Lab_AppMain() -- Application entry point and main process loop */
@@ -101,8 +96,9 @@ int32 CI_LAB_ReportHousekeeping(const CFE_SB_CmdHdr_t *data);
101
96
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
102
97
void CI_Lab_AppMain (void )
103
98
{
104
- int32 status ;
105
- uint32 RunStatus = CFE_ES_RunStatus_APP_RUN ;
99
+ int32 status ;
100
+ uint32 RunStatus = CFE_ES_RunStatus_APP_RUN ;
101
+ CFE_SB_Buffer_t * SBBufPtr ;
106
102
107
103
CFE_ES_PerfLogEntry (CI_LAB_MAIN_TASK_PERF_ID );
108
104
@@ -116,13 +112,13 @@ void CI_Lab_AppMain(void)
116
112
CFE_ES_PerfLogExit (CI_LAB_MAIN_TASK_PERF_ID );
117
113
118
114
/* Pend on receipt of command packet -- timeout set to 500 millisecs */
119
- status = CFE_SB_RcvMsg (& CI_LAB_Global . MsgPtr , CI_LAB_Global .CommandPipe , 500 );
115
+ status = CFE_SB_RcvMsg (& SBBufPtr , CI_LAB_Global .CommandPipe , 500 );
120
116
121
117
CFE_ES_PerfLogEntry (CI_LAB_MAIN_TASK_PERF_ID );
122
118
123
119
if (status == CFE_SUCCESS )
124
120
{
125
- CI_LAB_ProcessCommandPacket ();
121
+ CI_LAB_ProcessCommandPacket (SBBufPtr );
126
122
}
127
123
128
124
/* Regardless of packet vs timeout, always process uplink queue */
@@ -201,7 +197,7 @@ void CI_LAB_TaskInit(void)
201
197
*/
202
198
OS_TaskInstallDeleteHandler (& CI_LAB_delete_callback );
203
199
204
- CFE_MSG_Init (& CI_LAB_Global .HkBuffer . HkTlm .TlmHeader .BaseMsg , CI_LAB_HK_TLM_MID , CI_LAB_HK_TLM_LNGTH );
200
+ CFE_MSG_Init (& CI_LAB_Global .HkTlm .TlmHeader .Msg , CI_LAB_HK_TLM_MID , sizeof ( CI_LAB_Global . HkTlm ) );
205
201
206
202
CFE_EVS_SendEvent (CI_LAB_STARTUP_INF_EID , CFE_EVS_EventType_INFORMATION , "CI Lab Initialized.%s" ,
207
203
CI_LAB_VERSION_STRING );
@@ -220,24 +216,24 @@ void CI_LAB_TaskInit(void)
220
216
/* 3. Request for housekeeping telemetry packet (from HS task) */
221
217
/* */
222
218
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
223
- void CI_LAB_ProcessCommandPacket (void )
219
+ void CI_LAB_ProcessCommandPacket (CFE_SB_Buffer_t * SBBufPtr )
224
220
{
225
221
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID ;
226
222
227
- CFE_MSG_GetMsgId (CI_LAB_Global . MsgPtr , & MsgId );
223
+ CFE_MSG_GetMsgId (& SBBufPtr -> Msg , & MsgId );
228
224
229
225
switch (CFE_SB_MsgIdToValue (MsgId ))
230
226
{
231
227
case CI_LAB_CMD_MID :
232
- CI_LAB_ProcessGroundCommand ();
228
+ CI_LAB_ProcessGroundCommand (SBBufPtr );
233
229
break ;
234
230
235
231
case CI_LAB_SEND_HK_MID :
236
- CI_LAB_ReportHousekeeping ((const CFE_SB_CmdHdr_t * )CI_LAB_Global . MsgPtr );
232
+ CI_LAB_ReportHousekeeping ((const CFE_MSG_CommandHeader_t * )SBBufPtr );
237
233
break ;
238
234
239
235
default :
240
- CI_LAB_Global .HkBuffer . HkTlm .Payload .CommandErrorCounter ++ ;
236
+ CI_LAB_Global .HkTlm .Payload .CommandErrorCounter ++ ;
241
237
CFE_EVS_SendEvent (CI_LAB_COMMAND_ERR_EID , CFE_EVS_EventType_ERROR , "CI: invalid command packet,MID = 0x%x" ,
242
238
(unsigned int )CFE_SB_MsgIdToValue (MsgId ));
243
239
break ;
@@ -253,21 +249,27 @@ void CI_LAB_ProcessCommandPacket(void)
253
249
/* */
254
250
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/
255
251
256
- void CI_LAB_ProcessGroundCommand (void )
252
+ void CI_LAB_ProcessGroundCommand (CFE_SB_Buffer_t * SBBufPtr )
257
253
{
258
254
CFE_MSG_FcnCode_t CommandCode = 0 ;
259
255
260
- CFE_MSG_GetFcnCode (CI_LAB_Global . MsgPtr , & CommandCode );
256
+ CFE_MSG_GetFcnCode (& SBBufPtr -> Msg , & CommandCode );
261
257
262
258
/* Process "known" CI task ground commands */
263
259
switch (CommandCode )
264
260
{
265
261
case CI_LAB_NOOP_CC :
266
- CI_LAB_Noop ((const CI_LAB_Noop_t * )CI_LAB_Global .MsgPtr );
262
+ if (CI_LAB_VerifyCmdLength (& SBBufPtr -> Msg , sizeof (CI_LAB_Noop_t )))
263
+ {
264
+ CI_LAB_Noop ((const CI_LAB_Noop_t * )SBBufPtr );
265
+ }
267
266
break ;
268
267
269
268
case CI_LAB_RESET_COUNTERS_CC :
270
- CI_LAB_ResetCounters ((const CI_LAB_ResetCounters_t * )CI_LAB_Global .MsgPtr );
269
+ if (CI_LAB_VerifyCmdLength (& SBBufPtr -> Msg , sizeof (CI_LAB_ResetCounters_t )))
270
+ {
271
+ CI_LAB_ResetCounters ((const CI_LAB_ResetCounters_t * )SBBufPtr );
272
+ }
271
273
break ;
272
274
273
275
/* default case already found during FC vs length test */
@@ -289,7 +291,7 @@ void CI_LAB_ProcessGroundCommand(void)
289
291
int32 CI_LAB_Noop (const CI_LAB_Noop_t * data )
290
292
{
291
293
/* Does everything the name implies */
292
- CI_LAB_Global .HkBuffer . HkTlm .Payload .CommandCounter ++ ;
294
+ CI_LAB_Global .HkTlm .Payload .CommandCounter ++ ;
293
295
294
296
CFE_EVS_SendEvent (CI_LAB_COMMANDNOP_INF_EID , CFE_EVS_EventType_INFORMATION , "CI: NOOP command" );
295
297
@@ -319,11 +321,11 @@ int32 CI_LAB_ResetCounters(const CI_LAB_ResetCounters_t *data)
319
321
/* telemetry, packetize it and send it to the housekeeping task via */
320
322
/* the software bus */
321
323
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
322
- int32 CI_LAB_ReportHousekeeping (const CFE_SB_CmdHdr_t * data )
324
+ int32 CI_LAB_ReportHousekeeping (const CFE_MSG_CommandHeader_t * data )
323
325
{
324
- CI_LAB_Global .HkBuffer . HkTlm .Payload .SocketConnected = CI_LAB_Global .SocketConnected ;
325
- CFE_SB_TimeStampMsg (& CI_LAB_Global .HkBuffer . MsgHdr );
326
- CFE_SB_SendMsg (& CI_LAB_Global .HkBuffer . MsgHdr );
326
+ CI_LAB_Global .HkTlm .Payload .SocketConnected = CI_LAB_Global .SocketConnected ;
327
+ CFE_SB_TimeStampMsg (& CI_LAB_Global .HkTlm . TlmHeader . Msg );
328
+ CFE_SB_TransmitMsg (& CI_LAB_Global .HkTlm . TlmHeader . Msg , true );
327
329
return CFE_SUCCESS ;
328
330
329
331
} /* End of CI_LAB_ReportHousekeeping() */
@@ -339,12 +341,12 @@ int32 CI_LAB_ReportHousekeeping(const CFE_SB_CmdHdr_t *data)
339
341
void CI_LAB_ResetCounters_Internal (void )
340
342
{
341
343
/* Status of commands processed by CI task */
342
- CI_LAB_Global .HkBuffer . HkTlm .Payload .CommandCounter = 0 ;
343
- CI_LAB_Global .HkBuffer . HkTlm .Payload .CommandErrorCounter = 0 ;
344
+ CI_LAB_Global .HkTlm .Payload .CommandCounter = 0 ;
345
+ CI_LAB_Global .HkTlm .Payload .CommandErrorCounter = 0 ;
344
346
345
347
/* Status of packets ingested by CI task */
346
- CI_LAB_Global .HkBuffer . HkTlm .Payload .IngestPackets = 0 ;
347
- CI_LAB_Global .HkBuffer . HkTlm .Payload .IngestErrors = 0 ;
348
+ CI_LAB_Global .HkTlm .Payload .IngestPackets = 0 ;
349
+ CI_LAB_Global .HkTlm .Payload .IngestErrors = 0 ;
348
350
349
351
return ;
350
352
@@ -367,14 +369,14 @@ void CI_LAB_ReadUpLink(void)
367
369
if (status >= ((int32 )CFE_SB_CMD_HDR_SIZE ) && status <= ((int32 )CI_LAB_MAX_INGEST ))
368
370
{
369
371
CFE_ES_PerfLogEntry (CI_LAB_SOCKET_RCV_PERF_ID );
370
- CI_LAB_Global .HkBuffer . HkTlm .Payload .IngestPackets ++ ;
371
- status = CFE_SB_SendMsg (& CI_LAB_Global .IngestBuffer .MsgHdr );
372
+ CI_LAB_Global .HkTlm .Payload .IngestPackets ++ ;
373
+ status = CFE_SB_TransmitMsg (& CI_LAB_Global .IngestBuffer .Msg , false );
372
374
CFE_ES_PerfLogExit (CI_LAB_SOCKET_RCV_PERF_ID );
373
375
}
374
376
else if (status > 0 )
375
377
{
376
378
/* bad size, report as ingest error */
377
- CI_LAB_Global .HkBuffer . HkTlm .Payload .IngestErrors ++ ;
379
+ CI_LAB_Global .HkTlm .Payload .IngestErrors ++ ;
378
380
CFE_EVS_SendEvent (CI_LAB_INGEST_ERR_EID , CFE_EVS_EventType_ERROR ,
379
381
"CI: L%d, cmd %0x %0x dropped, bad length=%d\n" , __LINE__ ,
380
382
CI_LAB_Global .IngestBuffer .hwords [0 ], CI_LAB_Global .IngestBuffer .hwords [1 ], (int )status );
@@ -416,7 +418,7 @@ bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLe
416
418
(unsigned int )CFE_SB_MsgIdToValue (MsgId ), (unsigned int )FcnCode , (unsigned int )ActualLength ,
417
419
(unsigned int )ExpectedLength );
418
420
result = false;
419
- CI_LAB_Global .HkBuffer . HkTlm .Payload .CommandErrorCounter ++ ;
421
+ CI_LAB_Global .HkTlm .Payload .CommandErrorCounter ++ ;
420
422
}
421
423
422
424
return (result );
0 commit comments