Skip to content

Commit 262dddf

Browse files
committed
Fix #229, Check return values for CFE_SB_Subscribe for TO_LAB_CMD_MID and TO_LAB_SEND_HK_MID in TO_LAB_init() in fsw/src/to_lab_app.c
1 parent f99581e commit 262dddf

1 file changed

Lines changed: 48 additions & 10 deletions

File tree

fsw/src/to_lab_app.c

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838
*/
3939
TO_LAB_GlobalData_t TO_LAB_Global;
4040

41+
/*
42+
** TO Local Function Prototypes
43+
*/
44+
CFE_Status_t TO_LAB_CmdSubscribe(CFE_SB_MsgId_Atom_t MsgIdValue);
45+
4146
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
4247
/* */
4348
/* TO_LAB_AppMain() -- Application entry point and main process loop */
@@ -111,6 +116,8 @@ void TO_LAB_delete_callback(void)
111116
CFE_Status_t TO_LAB_init(void)
112117
{
113118
CFE_Status_t status;
119+
CFE_Status_t status_cmd_subscribe;
120+
CFE_Status_t status_send_hk_subscribe;
114121
char PipeName[16];
115122
uint16 PipeDepth;
116123
char ToTlmPipeName[16];
@@ -208,18 +215,25 @@ CFE_Status_t TO_LAB_init(void)
208215

209216
if (status == CFE_SUCCESS)
210217
{
211-
CFE_SB_Subscribe(CFE_SB_ValueToMsgId(TO_LAB_CMD_MID), TO_LAB_Global.Cmd_pipe);
212-
CFE_SB_Subscribe(CFE_SB_ValueToMsgId(TO_LAB_SEND_HK_MID), TO_LAB_Global.Cmd_pipe);
218+
status_cmd_subscribe = TO_LAB_CmdSubscribe(TO_LAB_CMD_MID);
219+
status_send_hk_subscribe = TO_LAB_CmdSubscribe(TO_LAB_SEND_HK_MID);
213220

214-
/* Create TO TLM pipe */
215-
status = CFE_SB_CreatePipe(&TO_LAB_Global.Tlm_pipe, ToTlmPipeDepth, ToTlmPipeName);
216-
if (status != CFE_SUCCESS)
221+
if (status_cmd_subscribe >= CFE_SUCCESS && status_send_hk_subscribe >= CFE_SUCCESS)
217222
{
218-
CFE_EVS_SendEvent(TO_LAB_TLMPIPE_ERR_EID,
219-
CFE_EVS_EventType_ERROR,
220-
"L%d TO Can't create Tlm pipe status %i",
221-
__LINE__,
222-
(int)status);
223+
/* Create TO TLM pipe */
224+
status = CFE_SB_CreatePipe(&TO_LAB_Global.Tlm_pipe, ToTlmPipeDepth, ToTlmPipeName);
225+
if (status != CFE_SUCCESS)
226+
{
227+
CFE_EVS_SendEvent(TO_LAB_TLMPIPE_ERR_EID,
228+
CFE_EVS_EventType_ERROR,
229+
"L%d TO Can't create Tlm pipe status %i",
230+
__LINE__,
231+
(int)status);
232+
}
233+
}
234+
else
235+
{
236+
status = (CFE_SUCCESS - 1);
223237
}
224238
}
225239

@@ -246,6 +260,30 @@ CFE_Status_t TO_LAB_init(void)
246260
return status;
247261
}
248262

263+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
264+
/* */
265+
/* TO_LAB_CmdSubscribe() -- Subscribes to command message */
266+
/* */
267+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
268+
CFE_Status_t TO_LAB_CmdSubscribe(CFE_SB_MsgId_Atom_t MsgIdValue)
269+
{
270+
CFE_Status_t status;
271+
status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(MsgIdValue), TO_LAB_Global.Cmd_pipe);
272+
273+
if (status != CFE_SUCCESS)
274+
{
275+
(void)CFE_EVS_SendEvent(TO_LAB_SUBSCRIBE_ERR_EID,
276+
CFE_EVS_EventType_ERROR,
277+
"L%d TO Can't subscribe to stream 0x%x status %i",
278+
__LINE__,
279+
(unsigned int)MsgIdValue,
280+
(int)status);
281+
}
282+
283+
return status;
284+
}
285+
286+
249287
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
250288
/* */
251289
/* TO_LAB_process_commands() -- Process command pipe message */

0 commit comments

Comments
 (0)