3838/*
3939** Global Data Section
4040*/
41- to_hk_tlm_t to_hk_status ;
42- CFE_SB_PipeId_t TO_Tlm_pipe ;
43- CFE_SB_PipeId_t TO_Cmd_pipe ;
41+ typedef union
42+ {
43+ CFE_SB_Msg_t MsgHdr ;
44+ to_hk_tlm_t HkTlm ;
45+ } TO_LAB_HkTlm_Buffer_t ;
4446
45- /*
46- ** Local Data Section
47- */
48- static uint32 TLMsockid ;
49- static to_data_types_fmt data_types_pkt ;
50- static boolean downlink_on ;
51- static char tlm_dest_IP [17 ];
52- static boolean suppress_sendto ;
47+ typedef union
48+ {
49+ CFE_SB_Msg_t MsgHdr ;
50+ to_data_types_fmt DataTypes ;
51+ } TO_LAB_DataTypes_Buffer_t ;
52+
53+ typedef struct
54+ {
55+ CFE_SB_PipeId_t Tlm_pipe ;
56+ CFE_SB_PipeId_t Cmd_pipe ;
57+ uint32 TLMsockid ;
58+ bool downlink_on ;
59+ char tlm_dest_IP [17 ];
60+ bool suppress_sendto ;
61+
62+ TO_LAB_HkTlm_Buffer_t HkBuf ;
63+ TO_LAB_DataTypes_Buffer_t DataTypesBuf ;
64+ } TO_LAB_GlobalData_t ;
65+
66+ TO_LAB_GlobalData_t TO_LAB_Global ;
5367
5468/*
5569** Include the TO subscription table
@@ -131,9 +145,9 @@ void TO_Lab_AppMain(void)
131145void TO_delete_callback (void )
132146{
133147 OS_printf ("TO delete callback -- Closing TO Network socket.\n" );
134- if ( downlink_on == TRUE )
148+ if ( TO_LAB_Global . downlink_on )
135149 {
136- OS_close (TLMsockid );
150+ OS_close (TO_LAB_Global . TLMsockid );
137151 }
138152}
139153
@@ -153,7 +167,7 @@ void TO_init(void)
153167 uint16 ToTlmPipeDepth ;
154168
155169 CFE_ES_RegisterApp ();
156- downlink_on = FALSE ;
170+ TO_LAB_Global . downlink_on = false ;
157171 PipeDepth = 8 ;
158172 strcpy (PipeName , "TO_LAB_CMD_PIPE" );
159173 ToTlmPipeDepth = 64 ;
@@ -168,23 +182,23 @@ void TO_init(void)
168182 /*
169183 ** Initialize housekeeping packet (clear user data area)...
170184 */
171- CFE_SB_InitMsg (& to_hk_status ,
185+ CFE_SB_InitMsg (& TO_LAB_Global . HkBuf . MsgHdr ,
172186 TO_LAB_HK_TLM_MID ,
173- sizeof (to_hk_status ), TRUE );
187+ sizeof (TO_LAB_Global . HkBuf . HkTlm ), true );
174188
175189 /* Subscribe to my commands */
176- status = CFE_SB_CreatePipe (& TO_Cmd_pipe , PipeDepth , PipeName );
190+ status = CFE_SB_CreatePipe (& TO_LAB_Global . Cmd_pipe , PipeDepth , PipeName );
177191 if (status == CFE_SUCCESS )
178192 {
179- CFE_SB_Subscribe (TO_LAB_CMD_MID , TO_Cmd_pipe );
180- CFE_SB_Subscribe (TO_LAB_SEND_HK_MID , TO_Cmd_pipe );
193+ CFE_SB_Subscribe (TO_LAB_CMD_MID , TO_LAB_Global . Cmd_pipe );
194+ CFE_SB_Subscribe (TO_LAB_SEND_HK_MID , TO_LAB_Global . Cmd_pipe );
181195 }
182196 else
183197 CFE_EVS_SendEvent (TO_CRCMDPIPE_ERR_EID ,CFE_EVS_EventType_ERROR ,
184198 "L%d TO Can't create cmd pipe status %i" ,__LINE__ ,(int )status );
185199
186200 /* Create TO TLM pipe */
187- status = CFE_SB_CreatePipe (& TO_Tlm_pipe , ToTlmPipeDepth , ToTlmPipeName );
201+ status = CFE_SB_CreatePipe (& TO_LAB_Global . Tlm_pipe , ToTlmPipeDepth , ToTlmPipeName );
188202 if (status != CFE_SUCCESS )
189203 {
190204 CFE_EVS_SendEvent (TO_TLMPIPE_ERR_EID ,CFE_EVS_EventType_ERROR ,
@@ -196,7 +210,7 @@ void TO_init(void)
196210 {
197211 if (TO_SubTable [i ].Stream != TO_UNUSED )
198212 status = CFE_SB_SubscribeEx (TO_SubTable [i ].Stream ,
199- TO_Tlm_pipe ,
213+ TO_LAB_Global . Tlm_pipe ,
200214 TO_SubTable [i ].Flags ,
201215 TO_SubTable [i ].BufLimit );
202216
@@ -227,17 +241,17 @@ void TO_init(void)
227241/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
228242void TO_StartSending ( TO_OUTPUT_ENABLE_PKT_t * pCmd )
229243{
230- (void ) CFE_SB_MessageStringGet (tlm_dest_IP , pCmd -> dest_IP , "" ,
231- sizeof (tlm_dest_IP ),
244+ (void ) CFE_SB_MessageStringGet (TO_LAB_Global . tlm_dest_IP , pCmd -> dest_IP , "" ,
245+ sizeof (TO_LAB_Global . tlm_dest_IP ),
232246 sizeof (pCmd -> dest_IP ));
233- suppress_sendto = FALSE ;
247+ TO_LAB_Global . suppress_sendto = false ;
234248 CFE_EVS_SendEvent (TO_TLMOUTENA_INF_EID ,CFE_EVS_EventType_INFORMATION ,
235- "TO telemetry output enabled for IP %s" , tlm_dest_IP );
249+ "TO telemetry output enabled for IP %s" , TO_LAB_Global . tlm_dest_IP );
236250
237- if (downlink_on == FALSE ) /* Then turn it on, otherwise we will just switch destination addresses*/
251+ if ( ! TO_LAB_Global . downlink_on ) /* Then turn it on, otherwise we will just switch destination addresses*/
238252 {
239253 TO_openTLM ();
240- downlink_on = TRUE ;
254+ TO_LAB_Global . downlink_on = true ;
241255 }
242256} /* End of TO_StartSending() */
243257
@@ -253,7 +267,7 @@ void TO_process_commands(void)
253267
254268 while (1 )
255269 {
256- switch (CFE_SB_RcvMsg (& MsgPtr , TO_Cmd_pipe , CFE_SB_POLL ))
270+ switch (CFE_SB_RcvMsg (& MsgPtr , TO_LAB_Global . Cmd_pipe , CFE_SB_POLL ))
257271 {
258272 case CFE_SUCCESS :
259273
@@ -302,7 +316,7 @@ void TO_exec_local_command(CFE_SB_MsgPtr_t cmd)
302316
303317 case TO_RESET_STATUS_CC :
304318 TO_reset_status ();
305- -- to_hk_status .command_counter ;
319+ -- TO_LAB_Global . HkBuf . HkTlm .command_counter ;
306320 break ;
307321
308322 case TO_SEND_DATA_TYPES_CC :
@@ -323,7 +337,7 @@ void TO_exec_local_command(CFE_SB_MsgPtr_t cmd)
323337
324338 case TO_OUTPUT_ENABLE_CC :
325339 TO_StartSending ( (TO_OUTPUT_ENABLE_PKT_t * )cmd );
326- downlink_on = TRUE;
340+ TO_LAB_Global . downlink_on = TRUE;
327341 break ;
328342
329343 default :
@@ -334,9 +348,9 @@ void TO_exec_local_command(CFE_SB_MsgPtr_t cmd)
334348 }
335349
336350 if (valid )
337- ++ to_hk_status .command_counter ;
351+ ++ TO_LAB_Global . HkBuf . HkTlm .command_counter ;
338352 else
339- ++ to_hk_status .command_error_counter ;
353+ ++ TO_LAB_Global . HkBuf . HkTlm .command_error_counter ;
340354} /* End of TO_exec_local_command() */
341355
342356/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -346,8 +360,8 @@ void TO_exec_local_command(CFE_SB_MsgPtr_t cmd)
346360/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
347361void TO_reset_status (void )
348362{
349- to_hk_status .command_error_counter = 0 ;
350- to_hk_status .command_counter = 0 ;
363+ TO_LAB_Global . HkBuf . HkTlm .command_error_counter = 0 ;
364+ TO_LAB_Global . HkBuf . HkTlm .command_counter = 0 ;
351365} /* End of TO_reset_status() */
352366
353367/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -361,41 +375,41 @@ void TO_output_data_types_packet(void)
361375 char string_variable [10 ] = "ABCDEFGHIJ" ;
362376
363377 /* initialize data types packet */
364- CFE_SB_InitMsg (& data_types_pkt ,
378+ CFE_SB_InitMsg (& TO_LAB_Global . DataTypesBuf . MsgHdr ,
365379 TO_LAB_DATA_TYPES_MID ,
366- sizeof (data_types_pkt ), TRUE );
380+ sizeof (TO_LAB_Global . DataTypesBuf . DataTypes ), true );
367381
368- CFE_SB_TimeStampMsg (( CFE_SB_MsgPtr_t ) & data_types_pkt );
382+ CFE_SB_TimeStampMsg (& TO_LAB_Global . DataTypesBuf . MsgHdr );
369383
370384 /* initialize the packet data */
371- data_types_pkt .synch = 0x6969 ;
385+ TO_LAB_Global . DataTypesBuf . DataTypes .synch = 0x6969 ;
372386#if 0
373- data_types_pkt .bit1 = 1 ;
374- data_types_pkt .bit2 = 0 ;
375- data_types_pkt .bit34 = 2 ;
376- data_types_pkt .bit56 = 3 ;
377- data_types_pkt .bit78 = 1 ;
378- data_types_pkt .nibble1 = 0xA ;
379- data_types_pkt .nibble2 = 0x4 ;
387+ TO_LAB_Global . DataTypesBuf . DataTypes .bit1 = 1 ;
388+ TO_LAB_Global . DataTypesBuf . DataTypes .bit2 = 0 ;
389+ TO_LAB_Global . DataTypesBuf . DataTypes .bit34 = 2 ;
390+ TO_LAB_Global . DataTypesBuf . DataTypes .bit56 = 3 ;
391+ TO_LAB_Global . DataTypesBuf . DataTypes .bit78 = 1 ;
392+ TO_LAB_Global . DataTypesBuf . DataTypes .nibble1 = 0xA ;
393+ TO_LAB_Global . DataTypesBuf . DataTypes .nibble2 = 0x4 ;
380394#endif
381- data_types_pkt . bl1 = FALSE ;
382- data_types_pkt . bl2 = TRUE ;
383- data_types_pkt .b1 = 16 ;
384- data_types_pkt .b2 = 127 ;
385- data_types_pkt .b3 = 0x7F ;
386- data_types_pkt .b4 = 0x45 ;
387- data_types_pkt .w1 = 0x2468 ;
388- data_types_pkt .w2 = 0x7FFF ;
389- data_types_pkt .dw1 = 0x12345678 ;
390- data_types_pkt .dw2 = 0x87654321 ;
391- data_types_pkt .f1 = 90.01 ;
392- data_types_pkt .f2 = .0000045 ;
393- data_types_pkt .df1 = 99.9 ;
394- data_types_pkt .df2 = .4444 ;
395-
396- for (i = 0 ; i < 10 ; i ++ ) data_types_pkt .str [i ] = string_variable [i ];
397-
398- CFE_SB_SendMsg (( CFE_SB_Msg_t * ) & data_types_pkt );
395+ TO_LAB_Global . DataTypesBuf . DataTypes . bl1 = false ;
396+ TO_LAB_Global . DataTypesBuf . DataTypes . bl2 = true ;
397+ TO_LAB_Global . DataTypesBuf . DataTypes .b1 = 16 ;
398+ TO_LAB_Global . DataTypesBuf . DataTypes .b2 = 127 ;
399+ TO_LAB_Global . DataTypesBuf . DataTypes .b3 = 0x7F ;
400+ TO_LAB_Global . DataTypesBuf . DataTypes .b4 = 0x45 ;
401+ TO_LAB_Global . DataTypesBuf . DataTypes .w1 = 0x2468 ;
402+ TO_LAB_Global . DataTypesBuf . DataTypes .w2 = 0x7FFF ;
403+ TO_LAB_Global . DataTypesBuf . DataTypes .dw1 = 0x12345678 ;
404+ TO_LAB_Global . DataTypesBuf . DataTypes .dw2 = 0x87654321 ;
405+ TO_LAB_Global . DataTypesBuf . DataTypes .f1 = 90.01 ;
406+ TO_LAB_Global . DataTypesBuf . DataTypes .f2 = .0000045 ;
407+ TO_LAB_Global . DataTypesBuf . DataTypes .df1 = 99.9 ;
408+ TO_LAB_Global . DataTypesBuf . DataTypes .df2 = .4444 ;
409+
410+ for (i = 0 ; i < 10 ; i ++ ) TO_LAB_Global . DataTypesBuf . DataTypes .str [i ] = string_variable [i ];
411+
412+ CFE_SB_SendMsg (& TO_LAB_Global . DataTypesBuf . MsgHdr );
399413} /* End of TO_output_data_types_packet() */
400414
401415/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -405,8 +419,8 @@ void TO_output_data_types_packet(void)
405419/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
406420void TO_output_status (void )
407421{
408- CFE_SB_TimeStampMsg (( CFE_SB_Msg_t * ) & to_hk_status );
409- CFE_SB_SendMsg (( CFE_SB_Msg_t * ) & to_hk_status );
422+ CFE_SB_TimeStampMsg (& TO_LAB_Global . HkBuf . MsgHdr );
423+ CFE_SB_SendMsg (& TO_LAB_Global . HkBuf . MsgHdr );
410424} /* End of TO_output_status() */
411425
412426/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -418,7 +432,7 @@ void TO_openTLM(void)
418432{
419433 int32 status ;
420434
421- status = OS_SocketOpen (& TLMsockid , OS_SocketDomain_INET , OS_SocketType_DATAGRAM );
435+ status = OS_SocketOpen (& TO_LAB_Global . TLMsockid , OS_SocketDomain_INET , OS_SocketType_DATAGRAM );
422436 if ( status != OS_SUCCESS )
423437 {
424438 CFE_EVS_SendEvent (TO_TLMOUTSOCKET_ERR_EID ,CFE_EVS_EventType_ERROR , "L%d, TO TLM socket error: %d" ,__LINE__ , (int )status );
@@ -438,7 +452,7 @@ void TO_AddPkt( TO_ADD_PKT_t * pCmd)
438452 int32 status ;
439453
440454 status = CFE_SB_SubscribeEx (pCmd -> Stream ,
441- TO_Tlm_pipe ,
455+ TO_LAB_Global . Tlm_pipe ,
442456 pCmd -> Flags ,
443457 pCmd -> BufLimit );
444458
@@ -464,11 +478,11 @@ void TO_RemovePkt(TO_REMOVE_PKT_t * pCmd)
464478{
465479 int32 status ;
466480
467- status = CFE_SB_Unsubscribe (pCmd -> Stream , TO_Tlm_pipe );
481+ status = CFE_SB_Unsubscribe (pCmd -> Stream , TO_LAB_Global . Tlm_pipe );
468482 if (status != CFE_SUCCESS )
469483 CFE_EVS_SendEvent (TO_REMOVEPKT_ERR_EID ,CFE_EVS_EventType_ERROR ,
470484 "L%d TO Can't Unsubscribe to Stream 0x%x on pipe %d, status %i" ,__LINE__ ,
471- pCmd -> Stream , TO_Tlm_pipe , (int )status );
485+ pCmd -> Stream , TO_LAB_Global . Tlm_pipe , (int )status );
472486 else
473487 CFE_EVS_SendEvent (TO_REMOVEPKT_INF_EID ,CFE_EVS_EventType_INFORMATION ,
474488 "L%d TO RemovePkt 0x%x" ,__LINE__ , pCmd -> Stream );
@@ -488,7 +502,7 @@ void TO_RemoveAllPkt(void)
488502 {
489503 if (TO_SubTable [i ].Stream != TO_UNUSED )
490504 {
491- status = CFE_SB_Unsubscribe (TO_SubTable [i ].Stream , TO_Tlm_pipe );
505+ status = CFE_SB_Unsubscribe (TO_SubTable [i ].Stream , TO_LAB_Global . Tlm_pipe );
492506
493507 if (status != CFE_SUCCESS )
494508 CFE_EVS_SendEvent (TO_REMOVEALLPTKS_ERR_EID ,CFE_EVS_EventType_ERROR ,
@@ -498,13 +512,13 @@ void TO_RemoveAllPkt(void)
498512 }
499513
500514 /* remove commands as well */
501- status = CFE_SB_Unsubscribe (TO_LAB_CMD_MID , TO_Cmd_pipe );
515+ status = CFE_SB_Unsubscribe (TO_LAB_CMD_MID , TO_LAB_Global . Cmd_pipe );
502516 if (status != CFE_SUCCESS )
503517 CFE_EVS_SendEvent (TO_REMOVECMDTO_ERR_EID ,CFE_EVS_EventType_ERROR ,
504518 "L%d TO Can't Unsubscribe to cmd stream 0x%x status %i" , __LINE__ ,
505519 TO_LAB_CMD_MID , (int )status );
506520
507- status = CFE_SB_Unsubscribe (TO_LAB_SEND_HK_MID , TO_Cmd_pipe );
521+ status = CFE_SB_Unsubscribe (TO_LAB_SEND_HK_MID , TO_LAB_Global . Cmd_pipe );
508522 if (status != CFE_SUCCESS )
509523 CFE_EVS_SendEvent (TO_REMOVEHKTO_ERR_EID ,CFE_EVS_EventType_ERROR ,
510524 "L%d TO Can't Unsubscribe to cmd stream 0x%x status %i" , __LINE__ ,
@@ -529,22 +543,22 @@ void TO_forward_telemetry(void)
529543
530544 OS_SocketAddrInit (& d_addr , OS_SocketDomain_INET );
531545 OS_SocketAddrSetPort (& d_addr , cfgTLM_PORT );
532- OS_SocketAddrFromString (& d_addr , tlm_dest_IP );
546+ OS_SocketAddrFromString (& d_addr , TO_LAB_Global . tlm_dest_IP );
533547 status = 0 ;
534548
535549 do
536550 {
537- CFE_SB_status = CFE_SB_RcvMsg (& PktPtr , TO_Tlm_pipe , CFE_SB_POLL );
551+ CFE_SB_status = CFE_SB_RcvMsg (& PktPtr , TO_LAB_Global . Tlm_pipe , CFE_SB_POLL );
538552
539- if ( (CFE_SB_status == CFE_SUCCESS ) && (suppress_sendto == FALSE ) )
553+ if ( (CFE_SB_status == CFE_SUCCESS ) && (TO_LAB_Global . suppress_sendto == false ) )
540554 {
541555 size = CFE_SB_GetTotalMsgLength (PktPtr );
542556
543- if (downlink_on == TRUE )
557+ if (TO_LAB_Global . downlink_on == true )
544558 {
545559 CFE_ES_PerfLogEntry (TO_SOCKET_SEND_PERF_ID );
546560
547- status = OS_SocketSendTo (TLMsockid , PktPtr , size , & d_addr );
561+ status = OS_SocketSendTo (TO_LAB_Global . TLMsockid , PktPtr , size , & d_addr );
548562
549563 CFE_ES_PerfLogExit (TO_SOCKET_SEND_PERF_ID );
550564 }
@@ -556,7 +570,7 @@ void TO_forward_telemetry(void)
556570 {
557571 CFE_EVS_SendEvent (TO_TLMOUTSTOP_ERR_EID ,CFE_EVS_EventType_ERROR ,
558572 "L%d TO sendto error %d. Tlm output supressed\n" , __LINE__ , (int )status );
559- suppress_sendto = TRUE ;
573+ TO_LAB_Global . suppress_sendto = true ;
560574 }
561575 }
562576 /* If CFE_SB_status != CFE_SUCCESS, then no packet was received from CFE_SB_RcvMsg() */
0 commit comments