Skip to content

Commit

Permalink
Fix nasa#523, SB Subscription report control on separate MID
Browse files Browse the repository at this point in the history
  • Loading branch information
skliper committed Apr 28, 2020
1 parent 3c616f2 commit f211a06
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 32 deletions.
2 changes: 2 additions & 0 deletions cmake/sample_defs/cpu1_msgids.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
#define CFE_TBL_SEND_HK_MID CFE_MISSION_CMD_MID_BASE1 + CFE_MISSION_TBL_SEND_HK_MSG /* 0x180C */
#define CFE_TIME_SEND_HK_MID CFE_MISSION_CMD_MID_BASE1 + CFE_MISSION_TIME_SEND_HK_MSG /* 0x180D */

#define CFE_SB_SUB_RPT_CTRL_MID CFE_MISSION_CMD_MID_BASE1 + CFE_MISSION_SB_SUB_RPT_CTRL_MSG /* 0x180E */

#define CFE_TIME_TONE_CMD_MID CFE_MISSION_CMD_MID_BASE1 + CFE_MISSION_TIME_TONE_CMD_MSG /* 0x1810 */
#define CFE_TIME_1HZ_CMD_MID CFE_MISSION_CMD_MID_BASE1 + CFE_MISSION_TIME_1HZ_CMD_MSG /* 0x1811 */

Expand Down
2 changes: 2 additions & 0 deletions cmake/sample_defs/sample_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@
#define CFE_MISSION_TBL_SEND_HK_MSG 12
#define CFE_MISSION_TIME_SEND_HK_MSG 13

#define CFE_MISSION_SB_SUB_RPT_CTRL_MSG 14

#define CFE_MISSION_TIME_TONE_CMD_MSG 16
#define CFE_MISSION_TIME_1HZ_CMD_MSG 17

Expand Down
61 changes: 40 additions & 21 deletions fsw/cfe-core/src/sb/cfe_sb_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ int32 CFE_SB_AppInit(void){
CFE_ES_WriteToSysLog("SB:Subscribe to HK Request Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}/* end if */

Status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID),CFE_SB.CmdPipe);

if(Status != CFE_SUCCESS){
CFE_ES_WriteToSysLog("SB:Subscribe to Subscription Report Request Failed:RC=0x%08X\n",(unsigned int)Status);
return Status;
}/* end if */

/* Ensure a ground commanded reset does not get blocked if SB mem pool */
/* becomes fully configured (DCR6772) */
Expand Down Expand Up @@ -359,6 +366,39 @@ void CFE_SB_ProcessCmdPipePkt(void) {
CFE_SB_SendHKTlmCmd((CCSDS_CommandPacket_t *)CFE_SB.CmdPipePktPtr);
break;

case CFE_SB_SUB_RPT_CTRL_MID:
/* Note: Command counter not incremented for this command */
switch (CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)) {
case CFE_SB_SEND_PREV_SUBS_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_SendPrevSubs_t)))
{
CFE_SB_SendPrevSubsCmd((CFE_SB_SendPrevSubs_t *)CFE_SB.CmdPipePktPtr);
}
break;

case CFE_SB_ENABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_EnableSubReporting_t)))
{
CFE_SB_EnableSubReportingCmd((CFE_SB_EnableSubReporting_t *)CFE_SB.CmdPipePktPtr);
}
break;

case CFE_SB_DISABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_DisableSubReporting_t)))
{
CFE_SB_DisableSubReportingCmd((CFE_SB_DisableSubReporting_t *)CFE_SB.CmdPipePktPtr);
}
break;

default:
CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID,CFE_EVS_EventType_ERROR,
"Invalid Cmd, Unexpected Command Code %d",
(int)CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr));
CFE_SB.HKTlmMsg.Payload.CommandErrorCounter++;
break;
} /* end switch on cmd code */
break;

case CFE_SB_CMD_MID:
switch (CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)) {
case CFE_SB_NOOP_CC:
Expand Down Expand Up @@ -418,27 +458,6 @@ void CFE_SB_ProcessCmdPipePkt(void) {
}
break;

case CFE_SB_SEND_PREV_SUBS_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_SendPrevSubs_t)))
{
CFE_SB_SendPrevSubsCmd((CFE_SB_SendPrevSubs_t *)CFE_SB.CmdPipePktPtr);
}
break;

case CFE_SB_ENABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_EnableSubReporting_t)))
{
CFE_SB_EnableSubReportingCmd((CFE_SB_EnableSubReporting_t *)CFE_SB.CmdPipePktPtr);
}
break;

case CFE_SB_DISABLE_SUB_REPORTING_CC:
if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_DisableSubReporting_t)))
{
CFE_SB_DisableSubReportingCmd((CFE_SB_DisableSubReporting_t *)CFE_SB.CmdPipePktPtr);
}
break;

default:
CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID,CFE_EVS_EventType_ERROR,
"Invalid Cmd, Unexpected Command Code %d",
Expand Down
48 changes: 37 additions & 11 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -657,7 +657,7 @@ void Test_SB_AppInit_EVSSendEvtFail(void)
TestStat = CFE_FAIL;
}

ExpRtn = 5;
ExpRtn = 7;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -849,7 +849,7 @@ void Test_SB_AppInit_GetPoolFail(void)
#endif

SB_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 3, ForcedRtnVal);
UT_SetDeferredRetcode(UT_KEY(CFE_ES_GetPoolBuf), 4, ForcedRtnVal);
ExpRtn = ForcedRtnVal;
ActRtn = CFE_SB_AppInit();

Expand All @@ -863,7 +863,7 @@ void Test_SB_AppInit_GetPoolFail(void)
TestStat = CFE_FAIL;
}

ExpRtn = 5;
ExpRtn = 7;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -910,7 +910,7 @@ void Test_SB_AppInit_PutPoolFail(void)
TestStat = CFE_FAIL;
}

ExpRtn = 5;
ExpRtn = 7;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -961,7 +961,7 @@ void Test_SB_Main_RcvErr(void)
SB_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(OS_QueueGet), 1, -1);
CFE_SB_TaskMain();
ExpRtn = 8;
ExpRtn = 10;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -1007,7 +1007,7 @@ void Test_SB_Main_InitErr(void)
SB_ResetUnitTest();
UT_SetDeferredRetcode(UT_KEY(CFE_ES_PutPoolBuf), 1, -1);
CFE_SB_TaskMain();
ExpRtn = 5;
ExpRtn = 7;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -1244,7 +1244,7 @@ void Test_SB_Cmds_RoutingInfoDef(void)
CFE_SB.CmdPipePktPtr = (CFE_SB_MsgPtr_t) &WriteFileCmd;
CFE_SB_ProcessCmdPipePkt();

ExpRtn = 9;
ExpRtn = 12;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -1475,7 +1475,7 @@ void Test_SB_Cmds_RoutingInfoWriteFail(void)
TestStat = CFE_FAIL;
}

ExpRtn = 9;
ExpRtn = 11;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -2718,7 +2718,7 @@ void Test_SB_Cmds_SendPrevSubs(void)
#endif

SB_ResetUnitTest();
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_CMD_MID), sizeof(CFE_SB_SendPrevSubs_t), true);
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID), sizeof(CFE_SB_SendPrevSubs_t), true);
CFE_SB_SetCmdCode((CFE_SB_MsgPtr_t) &NoParamCmd, CFE_SB_SEND_PREV_SUBS_CC);
CFE_SB.CmdPipePktPtr = (CFE_SB_MsgPtr_t) &NoParamCmd;
CFE_SB_CreatePipe(&PipeId1, PipeDepth, "TestPipe1");
Expand Down Expand Up @@ -2852,7 +2852,7 @@ void Test_SB_Cmds_SubRptOn(void)
#endif

SB_ResetUnitTest();
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_CMD_MID),
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID),
sizeof(NoParamCmd), true);
CFE_SB_SetCmdCode((CFE_SB_MsgPtr_t) &NoParamCmd,
CFE_SB_ENABLE_SUB_REPORTING_CC);
Expand Down Expand Up @@ -2890,7 +2890,7 @@ void Test_SB_Cmds_SubRptOff(void)
#endif

SB_ResetUnitTest();
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_CMD_MID),
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID),
sizeof(NoParamCmd), true);
CFE_SB_SetCmdCode((CFE_SB_MsgPtr_t) &NoParamCmd,
CFE_SB_DISABLE_SUB_REPORTING_CC);
Expand Down Expand Up @@ -2952,6 +2952,32 @@ void Test_SB_Cmds_UnexpCmdCode(void)
TestStat = CFE_FAIL;
}

/* Same test for subscription reporting control MID */
SB_ResetUnitTest();
CFE_SB_InitMsg(&NoParamCmd, CFE_SB_ValueToMsgId(CFE_SB_SUB_RPT_CTRL_MID), sizeof(NoParamCmd), true);

/* Use a command code known to be invalid */
CFE_SB_SetCmdCode((CFE_SB_MsgPtr_t) &NoParamCmd, 99);
CFE_SB.CmdPipePktPtr = (CFE_SB_MsgPtr_t) &NoParamCmd;
CFE_SB_ProcessCmdPipePkt();
ExpRtn = 1;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected rtn from UT_GetNumEventsSent, exp=%ld, act=%ld",
(long) ExpRtn, (long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}

if (UT_EventIsInHistory(CFE_SB_BAD_CMD_CODE_EID) == false)
{
UT_Text("CFE_SB_BAD_CMD_CODE_EID not sent");
TestStat = CFE_FAIL;
}

UT_Report(__FILE__, __LINE__,
TestStat, "CFE_SB_ProcessCmdPipePkt",
"Unexpected command code test");
Expand Down

0 comments on commit f211a06

Please sign in to comment.