From f211a064bf24839f45e0ef25f1f4b8cae16c3bf6 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Tue, 28 Apr 2020 10:38:43 -0400 Subject: [PATCH] Fix #523, SB Subscription report control on separate MID --- cmake/sample_defs/cpu1_msgids.h | 2 + cmake/sample_defs/sample_mission_cfg.h | 2 + fsw/cfe-core/src/sb/cfe_sb_task.c | 61 +++++++++++++++++--------- fsw/cfe-core/unit-test/sb_UT.c | 48 +++++++++++++++----- 4 files changed, 81 insertions(+), 32 deletions(-) diff --git a/cmake/sample_defs/cpu1_msgids.h b/cmake/sample_defs/cpu1_msgids.h index 9a2c6c4fe..eddd60824 100644 --- a/cmake/sample_defs/cpu1_msgids.h +++ b/cmake/sample_defs/cpu1_msgids.h @@ -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 */ diff --git a/cmake/sample_defs/sample_mission_cfg.h b/cmake/sample_defs/sample_mission_cfg.h index 979da27a7..6043ecb32 100644 --- a/cmake/sample_defs/sample_mission_cfg.h +++ b/cmake/sample_defs/sample_mission_cfg.h @@ -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 diff --git a/fsw/cfe-core/src/sb/cfe_sb_task.c b/fsw/cfe-core/src/sb/cfe_sb_task.c index 88e4cece2..b368c3c88 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_task.c +++ b/fsw/cfe-core/src/sb/cfe_sb_task.c @@ -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) */ @@ -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: @@ -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", diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index b6d4a3917..20f7e1645 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -657,7 +657,7 @@ void Test_SB_AppInit_EVSSendEvtFail(void) TestStat = CFE_FAIL; } - ExpRtn = 5; + ExpRtn = 7; ActRtn = UT_GetNumEventsSent(); if (ActRtn != ExpRtn) @@ -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(); @@ -863,7 +863,7 @@ void Test_SB_AppInit_GetPoolFail(void) TestStat = CFE_FAIL; } - ExpRtn = 5; + ExpRtn = 7; ActRtn = UT_GetNumEventsSent(); if (ActRtn != ExpRtn) @@ -910,7 +910,7 @@ void Test_SB_AppInit_PutPoolFail(void) TestStat = CFE_FAIL; } - ExpRtn = 5; + ExpRtn = 7; ActRtn = UT_GetNumEventsSent(); if (ActRtn != ExpRtn) @@ -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) @@ -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) @@ -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) @@ -1475,7 +1475,7 @@ void Test_SB_Cmds_RoutingInfoWriteFail(void) TestStat = CFE_FAIL; } - ExpRtn = 9; + ExpRtn = 11; ActRtn = UT_GetNumEventsSent(); if (ActRtn != ExpRtn) @@ -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"); @@ -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); @@ -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); @@ -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");