Skip to content

Commit

Permalink
Merge pull request #446 from avan989/fix-445-standardization-cmd-respond
Browse files Browse the repository at this point in the history
fix #445, update to meet standard
  • Loading branch information
dzbaker authored Aug 8, 2024
2 parents 5e1cfcf + 9b07112 commit cc22558
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 37 deletions.
8 changes: 4 additions & 4 deletions config/default_cf_fcncodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,13 +249,13 @@ typedef enum
* the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.cmd will increment
* - #CF_CMD_SUSPRES_INF_EID
* - #CF_CMD_SUSPRES_SAME_INF_EID
*
* \par Error Conditions
* This command may fail for the following reason(s):
* - Command packet length not as expected, #CF_CMD_LEN_ERR_EID
* - Transaction not found using compound key, #CF_CMD_TRANS_NOT_FOUND_ERR_EID
* - Invalid channel number, #CF_CMD_TSN_CHAN_INVALID_ERR_EID
* - Already in requested state, #CF_CMD_SUSPRES_SAME_ERR_EID
* - No matching transaction, #CF_CMD_SUSPRES_CHAN_ERR_EID
*
* \par Evidence of failure may be found in the following telemetry:
Expand Down Expand Up @@ -285,13 +285,13 @@ typedef enum
* the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.cmd will increment
* - #CF_CMD_SUSPRES_INF_EID
* - #CF_CMD_SUSPRES_SAME_INF_EID
*
* \par Error Conditions
* This command may fail for the following reason(s):
* - Command packet length not as expected, #CF_CMD_LEN_ERR_EID
* - Transaction not found using compound key, #CF_CMD_TRANS_NOT_FOUND_ERR_EID
* - Invalid channel number, #CF_CMD_TSN_CHAN_INVALID_ERR_EID
* - Already in requested state, #CF_CMD_SUSPRES_SAME_ERR_EID
* - No matching transaction, #CF_CMD_SUSPRES_CHAN_ERR_EID
*
* \par Evidence of failure may be found in the following telemetry:
Expand Down Expand Up @@ -673,12 +673,12 @@ typedef enum
* the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.cmd will increment
* - #CF_CMD_ENABLE_ENGINE_INF_EID
* - #CF_CMD_ENG_ALREADY_ENA_INF_EID
*
* \par Error Conditions
* This command may fail for the following reason(s):
* - Command packet length not as expected, #CF_CMD_LEN_ERR_EID
* - Engine initialization failed, #CF_CMD_ENABLE_ENGINE_ERR_EID
* - Engine already enabled, #CF_CMD_ENG_ALREADY_ENA_ERR_EID
*
* \par Evidence of failure may be found in the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.err will increment
Expand Down Expand Up @@ -706,11 +706,11 @@ typedef enum
* the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.cmd will increment
* - #CF_CMD_DISABLE_ENGINE_INF_EID
* - #CF_CMD_ENG_ALREADY_DIS_INF_EID
*
* \par Error Conditions
* This command may fail for the following reason(s):
* - Command packet length not as expected, #CF_CMD_LEN_ERR_EID
* - Engine already disabled, #CF_CMD_ENG_ALREADY_DIS_ERR_EID
*
* \par Evidence of failure may be found in the following telemetry:
* - #CF_HkPacket_Payload_t.counters #CF_HkCmdCounters_t.err will increment
Expand Down
12 changes: 6 additions & 6 deletions fsw/inc/cf_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_CMD_SUSPRES_SAME_ERR_EID (133)
#define CF_CMD_SUSPRES_SAME_INF_EID (133)

/**
* \brief CF Suspend/Resume Command No Matching Transaction Event ID
Expand Down Expand Up @@ -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_CMD_ENG_ALREADY_ENA_ERR_EID (149)
#define CF_CMD_ENG_ALREADY_ENA_INF_EID (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_CMD_ENG_ALREADY_DIS_ERR_EID (150)
#define CF_CMD_ENG_ALREADY_DIS_INF_EID (150)

/**
* \brief CF Command Length Verification Failed Event ID
Expand Down
14 changes: 7 additions & 7 deletions fsw/src/cf_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_CMD_SUSPRES_SAME_ERR_EID, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_CMD_SUSPRES_SAME_INF_EID, 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)
{
Expand Down Expand Up @@ -1184,9 +1184,9 @@ CFE_Status_t CF_EnableEngineCmd(const CF_EnableEngineCmd_t *msg)
}
else
{
CFE_EVS_SendEvent(CF_CMD_ENG_ALREADY_ENA_ERR_EID, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_CMD_ENG_ALREADY_ENA_INF_EID, 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;
Expand All @@ -1204,15 +1204,15 @@ CFE_Status_t CF_DisableEngineCmd(const CF_DisableEngineCmd_t *msg)
{
CF_CFDP_DisableEngine();
CFE_EVS_SendEvent(CF_CMD_DISABLE_ENGINE_INF_EID, CFE_EVS_EventType_INFORMATION, "CF: disabled CFDP engine");
++CF_AppData.hk.Payload.counters.cmd;
}
else
{
CFE_EVS_SendEvent(CF_CMD_ENG_ALREADY_DIS_ERR_EID, CFE_EVS_EventType_ERROR,
CFE_EVS_SendEvent(CF_CMD_ENG_ALREADY_DIS_INF_EID, 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;
}

Expand Down
37 changes: 17 additions & 20 deletions unit-test/cf_cmd_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -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_CMD_SUSPRES_SAME_ERR_EID);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.err, 2);
UT_CF_AssertEventID(CF_CMD_SUSPRES_SAME_INF_EID);
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
Expand All @@ -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_CMD_SUSPRES_INF_EID);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 2);
UtAssert_UINT32_EQ(CF_AppData.hk.Payload.counters.cmd, 3);
}

/*******************************************************************************
Expand Down Expand Up @@ -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);
Expand All @@ -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_CMD_ENG_ALREADY_ENA_ERR_EID);
UT_CF_AssertEventID(CF_CMD_ENG_ALREADY_ENA_INF_EID);
/* 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);
}

/*******************************************************************************
Expand Down Expand Up @@ -3664,30 +3664,27 @@ 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);

/* Assert */
UtAssert_STUB_COUNT(CF_CFDP_DisableEngine, 0);
UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1);
UT_CF_AssertEventID(CF_CMD_ENG_ALREADY_DIS_ERR_EID);
UT_CF_AssertEventID(CF_CMD_ENG_ALREADY_DIS_INF_EID);
/* 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);
}

/*******************************************************************************
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit cc22558

Please sign in to comment.