From e305cd38f90c63c64a7a7e2c597fbf9bfb8f8e34 Mon Sep 17 00:00:00 2001 From: Anh Date: Thu, 30 May 2024 08:46:36 -0400 Subject: [PATCH] Fix #445, update to meet standard Fix #445, update CF_DoSuspRes to increment command counter and issue info event instead of error event. Update Enable_engine command to increment cmd counter when state stays the same. Update Disable engine command to increment cmd counter when stat stays the same. --- fsw/inc/cf_events.h | 12 ++++++------ fsw/src/cf_cmd.c | 14 +++++++------- unit-test/cf_cmd_tests.c | 37 +++++++++++++++++-------------------- 3 files changed, 30 insertions(+), 33 deletions(-) diff --git a/fsw/inc/cf_events.h b/fsw/inc/cf_events.h index 28c1ff72..fae2bc38 100644 --- a/fsw/inc/cf_events.h +++ b/fsw/inc/cf_events.h @@ -1157,13 +1157,13 @@ /** * \brief CF Suspend/Resume Command For Single Transaction State Unchanged Event ID * - * \par Type: ERROR + * \par Type: INFORMATION * * \par Cause: * * Suspend/resume command received affecting single transaction already set to that state */ -#define CF_EID_ERR_CMD_SUSPRES_SAME (133) +#define CF_EID_INF_CMD_SUSPRES_SAME (133) /** * \brief CF Suspend/Resume Command No Matching Transaction Event ID @@ -1333,24 +1333,24 @@ /** * \brief CF Enable Engine Command Engine Already Enabled Event ID * - * \par Type: ERROR + * \par Type: INFORMATION * * \par Cause: * * Enable engine command received while engine is already enabled */ -#define CF_EID_ERR_CMD_ENG_ALREADY_ENA (149) +#define CF_EID_INF_CMD_ENG_ALREADY_ENA (149) /** * \brief CF Disable Engine Command Engine Already Disabled Event ID * - * \par Type: ERROR + * \par Type: INFORMATION * * \par Cause: * * Disable engine command received while engine is already disabled */ -#define CF_EID_ERR_CMD_ENG_ALREADY_DIS (150) +#define CF_EID_INF_CMD_ENG_ALREADY_DIS (150) /** * \brief CF Command Length Verification Failed Event ID diff --git a/fsw/src/cf_cmd.c b/fsw/src/cf_cmd.c index f7fe592b..e55c7fe7 100644 --- a/fsw/src/cf_cmd.c +++ b/fsw/src/cf_cmd.c @@ -439,9 +439,9 @@ void CF_DoSuspRes(const CF_Transaction_Payload_t *payload, uint8 action) if (ret == 1 && args.same) { /* A single transaction was mached, and it was already set the same way */ - CFE_EVS_SendEvent(CF_EID_ERR_CMD_SUSPRES_SAME, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(CF_EID_INF_CMD_SUSPRES_SAME, CFE_EVS_EventType_INFORMATION, "CF: %s cmd: setting suspend flag to current value of %d", msgstr[action], action); - ++CF_AppData.hk.Payload.counters.err; + ++CF_AppData.hk.Payload.counters.cmd; } else if (ret <= 0) { @@ -1184,9 +1184,9 @@ CFE_Status_t CF_EnableEngineCmd(const CF_EnableEngineCmd_t *msg) } else { - CFE_EVS_SendEvent(CF_EID_ERR_CMD_ENG_ALREADY_ENA, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(CF_EID_INF_CMD_ENG_ALREADY_ENA, CFE_EVS_EventType_INFORMATION, "CF: received enable engine command while engine already enabled"); - ++CF_AppData.hk.Payload.counters.err; + ++CF_AppData.hk.Payload.counters.cmd; } return CFE_SUCCESS; @@ -1204,15 +1204,15 @@ CFE_Status_t CF_DisableEngineCmd(const CF_DisableEngineCmd_t *msg) { CF_CFDP_DisableEngine(); CFE_EVS_SendEvent(CF_EID_INF_CMD_DISABLE_ENGINE, CFE_EVS_EventType_INFORMATION, "CF: disabled CFDP engine"); - ++CF_AppData.hk.Payload.counters.cmd; } else { - CFE_EVS_SendEvent(CF_EID_ERR_CMD_ENG_ALREADY_DIS, CFE_EVS_EventType_ERROR, + CFE_EVS_SendEvent(CF_EID_INF_CMD_ENG_ALREADY_DIS, CFE_EVS_EventType_INFORMATION, "CF: received disable engine command while engine already disabled"); - ++CF_AppData.hk.Payload.counters.err; } + ++CF_AppData.hk.Payload.counters.cmd; + return CFE_SUCCESS; } diff --git a/unit-test/cf_cmd_tests.c b/unit-test/cf_cmd_tests.c index c04f5b13..131a7803 100644 --- a/unit-test/cf_cmd_tests.c +++ b/unit-test/cf_cmd_tests.c @@ -1295,8 +1295,8 @@ void Test_CF_DoSuspRes(void) UT_SetHandlerFunction(UT_KEY(CF_TraverseAllTransactions), UT_AltHandler_CF_TraverseAllTransactions_SetSuspResArg, &utargs); UtAssert_VOIDCALL(CF_DoSuspRes(cmd, 0)); - UT_CF_AssertEventID(CF_EID_ERR_CMD_SUSPRES_SAME); - UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, 2); + UT_CF_AssertEventID(CF_EID_INF_CMD_SUSPRES_SAME); + UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 2); /* Output the CF_ChanAction_SuspResArg_t back to the caller, to set the "same" flag to 1 */ /* however this time CF_TraverseAllTransactions reports it matched multiple transactions, so it should NOT reject it @@ -1306,7 +1306,7 @@ void Test_CF_DoSuspRes(void) UtAssert_VOIDCALL(CF_DoSuspRes(cmd, 1)); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_INF_CMD_SUSPRES); - UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 2); + UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 3); } /******************************************************************************* @@ -3609,17 +3609,17 @@ void Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementEr UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); } -void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter(void) +void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter(void) { /* Arrange */ CF_EnableEngineCmd_t utbuf; - uint16 initial_hk_err_counter = Any_uint16(); + uint16 initial_hk_cmd_counter = Any_uint16(); memset(&utbuf, 0, sizeof(utbuf)); CF_AppData.engine.enabled = 1; /* 1 is enabled */ - CF_AppData.hk.Payload.counters.err = initial_hk_err_counter; + CF_AppData.hk.Payload.counters.cmd = initial_hk_cmd_counter; /* Act */ CF_EnableEngineCmd(&utbuf); @@ -3629,9 +3629,9 @@ void Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounte /* Assert */ UtAssert_STUB_COUNT(CF_CFDP_InitEngine, 0); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UT_CF_AssertEventID(CF_EID_ERR_CMD_ENG_ALREADY_ENA); + UT_CF_AssertEventID(CF_EID_INF_CMD_ENG_ALREADY_ENA); /* Assert for incremented counter */ - UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); + UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF); } /******************************************************************************* @@ -3664,17 +3664,17 @@ void Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter(voi UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_cmd_counter + 1) & 0xFFFF); } -void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail(void) +void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter(void) { /* Arrange */ CF_DisableEngineCmd_t utbuf; - uint16 initial_hk_err_counter = Any_uint16(); + uint16 initial_hk_counter = Any_uint16(); memset(&utbuf, 0, sizeof(utbuf)); CF_AppData.engine.enabled = 0; /* 0 is not enabled */ - CF_AppData.hk.Payload.counters.err = initial_hk_err_counter; + CF_AppData.hk.Payload.counters.cmd = initial_hk_counter; /* Act */ CF_DisableEngineCmd(&utbuf); @@ -3682,12 +3682,9 @@ void Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail(v /* Assert */ UtAssert_STUB_COUNT(CF_CFDP_DisableEngine, 0); UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); - UT_CF_AssertEventID(CF_EID_ERR_CMD_ENG_ALREADY_DIS); + UT_CF_AssertEventID(CF_EID_INF_CMD_ENG_ALREADY_DIS); /* Assert for incremented counter */ - UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, (initial_hk_err_counter + 1) & 0xFFFF); - UtAssert_True(CF_AppData.hk.Payload.counters.err == (uint16)(initial_hk_err_counter + 1), - "CF_AppData.hk.Payload.counters.err is %d and should be 1 more than %d", - CF_AppData.hk.Payload.counters.err, initial_hk_err_counter); + UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, (initial_hk_counter + 1) & 0xFFFF); } /******************************************************************************* @@ -4103,16 +4100,16 @@ void add_CF_CmdEnableEngine_tests(void) UtTest_Add(Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementErrCounter, cf_cmd_tests_Setup, cf_cmd_tests_Teardown, "Test_CF_CmdEnableEngine_WithEngineNotEnableFailsInitSendEventAndIncrementErrCounter"); - UtTest_Add(Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter, cf_cmd_tests_Setup, - cf_cmd_tests_Teardown, "Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementErrCounter"); + UtTest_Add(Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter, cf_cmd_tests_Setup, + cf_cmd_tests_Teardown, "Test_CF_CmdEnableEngine_WithEngineEnableFailsSendEventAndIncrementCmdCounter"); } void add_CF_CmdDisableEngine_tests(void) { UtTest_Add(Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter, cf_cmd_tests_Setup, cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_SuccessWhenEngineEnabledAndIncrementCmdCounter"); - UtTest_Add(Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail, cf_cmd_tests_Setup, - cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementErrCounterThenFail"); + UtTest_Add(Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter, cf_cmd_tests_Setup, + cf_cmd_tests_Teardown, "Test_CF_CmdDisableEngine_WhenEngineDisabledAndIncrementCmdCounter"); } void add_CF_SendHkCmd_tests(void)