diff --git a/fsw/inc/cf_msg.h b/fsw/inc/cf_msg.h index 4c5ab8e7..a7114785 100644 --- a/fsw/inc/cf_msg.h +++ b/fsw/inc/cf_msg.h @@ -862,6 +862,16 @@ typedef struct CF_NoArgsCmd CFE_MSG_CommandHeader_t cmd_header; /**< \brief Command header */ } CF_NoArgsCmd_t; +/** + * \brief Command payload argument union to support 4 uint8's, 2 uint16's or 1 uint32 + */ +typedef union CF_UnionArgs_Payload +{ + uint32 dword; /**< \brief Generic uint32 argument */ + uint16 hword[2]; /**< \brief Generic uint16 array of arguments */ + uint8 byte[4]; /**< \brief Generic uint8 array of arguments */ +} CF_UnionArgs_Payload_t; + /** * \brief Generic command structure with arguments supports common handling on multiple command types * @@ -871,7 +881,7 @@ typedef struct CF_NoArgsCmd typedef struct { CFE_MSG_CommandHeader_t cmd_header; /**< \brief Command header */ - uint8 byte[4]; /**< \brief Generic uint8 array of arguments */ + CF_UnionArgs_Payload_t data; /**< \brief Generic command arguments */ } CF_UnionArgsCmd_t; /** diff --git a/fsw/src/cf_cmd.c b/fsw/src/cf_cmd.c index da09e0d1..c15035d2 100644 --- a/fsw/src/cf_cmd.c +++ b/fsw/src/cf_cmd.c @@ -62,7 +62,7 @@ void CF_CmdReset(CFE_SB_Buffer_t *msg) CF_UnionArgsCmd_t *cmd = (CF_UnionArgsCmd_t *)msg; static const char *names[5] = {"all", "cmd", "fault", "up", "down"}; /* 0=all, 1=cmd, 2=fault 3=up 4=down */ - uint8 param = cmd->byte[0]; + uint8 param = cmd->data.byte[0]; int i; int acc = 1; @@ -221,22 +221,22 @@ CFE_Status_t CF_DoChanAction(CF_UnionArgsCmd_t *cmd, const char *errstr, CF_Chan /* this function is generic for any ground command that takes a single channel * argument which must be less than CF_NUM_CHANNELS or 255 which is a special * value that means apply command to all channels */ - if (cmd->byte[0] == CF_ALL_CHANNELS) + if (cmd->data.byte[0] == CF_ALL_CHANNELS) { /* apply to all channels */ for (i = 0; i < CF_NUM_CHANNELS; ++i) ret |= fn(i, context); } - else if (cmd->byte[0] < CF_NUM_CHANNELS) + else if (cmd->data.byte[0] < CF_NUM_CHANNELS) { - ret = fn(cmd->byte[0], context); + ret = fn(cmd->data.byte[0], context); } else { /* bad parameter */ CFE_EVS_SendEvent(CF_EID_ERR_CMD_CHAN_PARAM, CFE_EVS_EventType_ERROR, - "CF: %s: channel parameter out of range. received %d", errstr, cmd->byte[0]); - ret = CF_ERROR; + "CF: %s: channel parameter out of range. received %d", errstr, cmd->data.byte[0]); + ret = -1; } return ret; @@ -592,20 +592,20 @@ CFE_Status_t CF_DoEnableDisablePolldir(uint8 chan_num, const CF_ChanAction_BoolM int i; CFE_Status_t ret = CFE_SUCCESS; /* no need to bounds check chan_num, done in caller */ - if (context->msg->byte[1] == CF_ALL_POLLDIRS) + if (context->msg->data.byte[1] == CF_ALL_POLLDIRS) { /* all polldirs in channel */ for (i = 0; i < CF_MAX_POLLING_DIR_PER_CHAN; ++i) CF_AppData.config_table->chan[chan_num].polldir[i].enabled = context->barg; } - else if (context->msg->byte[1] < CF_MAX_POLLING_DIR_PER_CHAN) + else if (context->msg->data.byte[1] < CF_MAX_POLLING_DIR_PER_CHAN) { - CF_AppData.config_table->chan[chan_num].polldir[context->msg->byte[1]].enabled = context->barg; + CF_AppData.config_table->chan[chan_num].polldir[context->msg->data.byte[1]].enabled = context->barg; } else { CFE_EVS_SendEvent(CF_EID_ERR_CMD_POLLDIR_INVALID, CFE_EVS_EventType_ERROR, - "CF: enable/disable polldir: invalid polldir %d on channel %d", context->msg->byte[1], + "CF: enable/disable polldir: invalid polldir %d on channel %d", context->msg->data.byte[1], chan_num); ret = CF_ERROR; } @@ -704,7 +704,7 @@ CFE_Status_t CF_DoPurgeQueue(uint8 chan_num, CF_UnionArgsCmd_t *cmd) int pend = 0; int hist = 0; - switch (cmd->byte[1]) + switch (cmd->data.byte[1]) { case 0: /* pend */ pend = 1; @@ -721,8 +721,8 @@ CFE_Status_t CF_DoPurgeQueue(uint8 chan_num, CF_UnionArgsCmd_t *cmd) default: CFE_EVS_SendEvent(CF_EID_ERR_CMD_PURGE_ARG, CFE_EVS_EventType_ERROR, "CF: purge queue invalid arg %d", - cmd->byte[1]); - ret = CF_ERROR; + cmd->data.byte[1]); + ret = -1; break; } diff --git a/unit-test/cf_cmd_tests.c b/unit-test/cf_cmd_tests.c index f3d2e81f..5e4fe86e 100644 --- a/unit-test/cf_cmd_tests.c +++ b/unit-test/cf_cmd_tests.c @@ -205,7 +205,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIsEqTo_5_SendEventAndRejectCommand(vo memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = 5; /* 5 is size of 'names' */ + msg->data.byte[0] = 5; /* 5 is size of 'names' */ CF_AppData.HkPacket.CommandErrorCounter = initial_hk_err_counter; @@ -229,7 +229,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIsGreaterThan_5_SendEventAndRejectCom memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = Any_uint8_GreaterThan(5); /* 5 is size of 'names' */ + msg->data.byte[0] = Any_uint8_GreaterThan(5); /* 5 is size of 'names' */ CF_AppData.HkPacket.CommandErrorCounter = initial_hk_err_counter; @@ -252,8 +252,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIs_command_AndResetHkCmdAndErrCountSe memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = CF_Reset_command; - + msg->data.byte[0] = CF_Reset_command; CF_AppData.HkPacket.CommandCounter = Any_uint16_Except(0); CF_AppData.HkPacket.CommandErrorCounter = Any_uint16_Except(0); @@ -278,7 +277,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIs_fault_ResetAllHkFaultCountSendEven memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = CF_Reset_fault; + msg->data.byte[0] = CF_Reset_fault; for (i = 0; i < CF_NUM_CHANNELS; ++i) { @@ -338,7 +337,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIs_up_AndResetAllHkRecvCountSendEvent memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = CF_Reset_up; + msg->data.byte[0] = CF_Reset_up; for (i = 0; i < CF_NUM_CHANNELS; ++i) { @@ -386,7 +385,7 @@ void Test_CF_CmdReset_tests_SWhenCommandByteIs_down_AndResetAllHkSentCountendEve memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = CF_Reset_down; + msg->data.byte[0] = CF_Reset_down; for (i = 0; i < CF_NUM_CHANNELS; ++i) { @@ -427,7 +426,7 @@ void Test_CF_CmdReset_tests_WhenCommandByteIs_all_AndResetAllMemValuesSendEvent( memset(&utbuf, 0, sizeof(utbuf)); - msg->byte[0] = CF_Reset_all; + msg->data.byte[0] = CF_Reset_all; CF_AppData.HkPacket.CommandCounter = Any_uint16_Except(0); CF_AppData.HkPacket.CommandErrorCounter = Any_uint16_Except(0); @@ -654,7 +653,7 @@ void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenAny_fn_returns_1_Return_1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = CF_ALL_CHANNELS; + arg_cmd->data.byte[0] = CF_ALL_CHANNELS; UT_SetDeferredRetcode(UT_KEY(Chan_action_fn_t), random_fn_call, 1); @@ -683,7 +682,7 @@ void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenAll_fn_return_1_Return_1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = CF_ALL_CHANNELS; + arg_cmd->data.byte[0] = CF_ALL_CHANNELS; UT_SetDefaultReturnValue(UT_KEY(Chan_action_fn_t), 1); @@ -712,7 +711,7 @@ void Test_CF_DoChanAction_CF_ALL_CHANNELS_WhenNo_fn_returns_0_Return_0(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = CF_ALL_CHANNELS; + arg_cmd->data.byte[0] = CF_ALL_CHANNELS; UT_SetDefaultReturnValue(UT_KEY(Chan_action_fn_t), 0); @@ -741,7 +740,7 @@ void Test_CF_DoChanAction_WhenChannel_fn_ActionReturns_1_Return_1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = Any_cf_channel(); + arg_cmd->data.byte[0] = Any_cf_channel(); UT_SetDefaultReturnValue(UT_KEY(Chan_action_fn_t), 1); @@ -770,7 +769,7 @@ void Test_CF_DoChanAction_WhenChannel_fn_ActionReturns_0_Return_1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = Any_cf_channel(); + arg_cmd->data.byte[0] = Any_cf_channel(); UT_SetDefaultReturnValue(UT_KEY(Chan_action_fn_t), 0); @@ -799,7 +798,7 @@ void Test_CF_DoChanAction_WhenChanNumberEq_CF_NUM_CHANNELS_Return_neg1_And_SendE memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[0] = CF_NUM_CHANNELS; + arg_cmd->data.byte[0] = CF_NUM_CHANNELS; /* Act */ local_result = CF_DoChanAction(arg_cmd, arg_errstr, arg_fn, arg_context); @@ -812,9 +811,8 @@ void Test_CF_DoChanAction_WhenChanNumberEq_CF_NUM_CHANNELS_Return_neg1_And_SendE UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_CMD_CHAN_PARAM); - UtAssert_True(local_result == CF_ERROR, - "CF_DoChanAction returned %d and should be -1 (CF_ERROR) (cmd->byte[0] >= CF_NUM_CHANNELS)", - local_result); + UtAssert_True(local_result == -1, + "CF_DoChanAction returned %d and should be -1 (cmd->data.byte[0] >= CF_NUM_CHANNELS)", local_result); } void Test_CF_DoChanAction_WhenBadChannelNumber_Return_neg1_And_SendEvent(void) @@ -832,16 +830,16 @@ void Test_CF_DoChanAction_WhenBadChannelNumber_Return_neg1_And_SendEvent(void) memset(&utbuf, 0, sizeof(utbuf)); /* force CF_ALL_CHANNELS to not be a selection possibility */ - arg_cmd->byte[0] = CF_ALL_CHANNELS; - while (arg_cmd->byte[0] == CF_ALL_CHANNELS) + arg_cmd->data.byte[0] = CF_ALL_CHANNELS; + while (arg_cmd->data.byte[0] == CF_ALL_CHANNELS) { if (catastrophe_count == 10) /* 10 is arbitrary */ { UtAssert_Message(UTASSERT_CASETYPE_ABORT, __FILE__, __LINE__, - "CANNOT make arg_cmd->byte[0] != CF_ALL_CHANNELS in 10 tries"); + "CANNOT make arg_cmd->data.byte[0] != CF_ALL_CHANNELS in 10 tries"); } - arg_cmd->byte[0] = Any_uint8_GreaterThan_or_EqualTo(CF_NUM_CHANNELS); + arg_cmd->data.byte[0] = Any_uint8_GreaterThan_or_EqualTo(CF_NUM_CHANNELS); ++catastrophe_count; } @@ -856,9 +854,8 @@ void Test_CF_DoChanAction_WhenBadChannelNumber_Return_neg1_And_SendEvent(void) UtAssert_STUB_COUNT(CFE_EVS_SendEvent, 1); UT_CF_AssertEventID(CF_EID_ERR_CMD_CHAN_PARAM); - UtAssert_True(local_result == CF_ERROR, - "CF_DoChanAction returned %d and should be -1 (CF_ERROR) (cmd->byte[0] >= CF_NUM_CHANNELS)", - local_result); + UtAssert_True(local_result == -1, + "CF_DoChanAction returned %d and should be -1 (cmd->data.byte[0] >= CF_NUM_CHANNELS)", local_result); } /******************************************************************************* @@ -914,7 +911,7 @@ void Test_CF_CmdFreeze_Set_frozen_To_1_AndAcceptCommand(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = chan_num; + msg->data.byte[0] = chan_num; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -944,7 +941,7 @@ void Test_CF_CmdFreeze_Set_frozen_To_1_AndRejectCommand(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = CF_NUM_CHANNELS + 1; + msg->data.byte[0] = CF_NUM_CHANNELS + 1; CF_AppData.HkPacket.CommandCounter = 0; @@ -977,7 +974,7 @@ void Test_CF_CmdThaw_Set_frozen_To_0_AndAcceptCommand(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = chan_num; + msg->data.byte[0] = chan_num; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -1007,7 +1004,7 @@ void Test_CF_CmdThaw_Set_frozen_To_0_AndRejectCommand(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = CF_NUM_CHANNELS + 1; + msg->data.byte[0] = CF_NUM_CHANNELS + 1; CF_AppData.HkPacket.CommandCounter = 0; @@ -1633,7 +1630,7 @@ void Test_CF_CmdEnableDequeue_Success(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = chan_num; + msg->data.byte[0] = chan_num; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -1671,7 +1668,7 @@ void Test_CF_CmdEnableDequeue_Failure(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = CF_NUM_CHANNELS + 1; + msg->data.byte[0] = CF_NUM_CHANNELS + 1; CF_AppData.HkPacket.CommandErrorCounter = 0; @@ -1708,7 +1705,7 @@ void Test_CF_CmdDisableDequeue_Success(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = chan_num; + msg->data.byte[0] = chan_num; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -1744,7 +1741,7 @@ void Test_CF_CmdDisableDequeue_Failure(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = CF_NUM_CHANNELS + 1; + msg->data.byte[0] = CF_NUM_CHANNELS + 1; CF_AppData.HkPacket.CommandErrorCounter = 0; @@ -1781,7 +1778,7 @@ void Test_CF_DoEnableDisablePolldir_When_CF_ALL_CHANNELS_SetAllPolldirsInChannel CF_AppData.config_table = &config_table; - msg->byte[1] = CF_ALL_CHANNELS; + msg->data.byte[1] = CF_ALL_CHANNELS; context.msg = msg; context.barg = Any_bool_arg_t_barg(); @@ -1820,7 +1817,7 @@ void Test_CF_DoEnableDisablePolldir_WhenSetToSpecificPolldirSetPolldirFrom_conte CF_AppData.config_table = &config_table; - msg->byte[1] = polldir; + msg->data.byte[1] = polldir; context.msg = msg; context.barg = Any_bool_arg_t_barg(); @@ -1852,7 +1849,7 @@ void Test_CF_DoEnableDisablePolldir_FailPolldirEq_CF_MAX_POLLING_DIR_PER_CHAN_An CF_AppData.config_table = &config_table; - msg->byte[1] = CF_MAX_POLLING_DIR_PER_CHAN; + msg->data.byte[1] = CF_MAX_POLLING_DIR_PER_CHAN; context.msg = msg; context.barg = Any_bool_arg_t_barg(); @@ -1882,7 +1879,7 @@ void Test_CF_DoEnableDisablePolldir_FailAnyBadPolldirSendEvent(void) CF_AppData.config_table = &config_table; - msg->byte[1] = CF_MAX_POLLING_DIR_PER_CHAN; + msg->data.byte[1] = CF_MAX_POLLING_DIR_PER_CHAN; context.msg = msg; context.barg = Any_bool_arg_t_barg(); @@ -1920,10 +1917,10 @@ void Test_CF_CmdEnablePolldir_SuccessWhenActionSuccess(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; /* Arrange unstubbable: CF_DoEnableDisablePolldir */ - msg->byte[1] = polldir; + msg->data.byte[1] = polldir; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -1955,11 +1952,10 @@ void Test_CF_CmdEnablePolldir_FailWhenActionFail(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; /* Arrange unstubbable: CF_DoEnableDisablePolldir */ - msg->byte[1] = error_polldir; - + msg->data.byte[1] = error_polldir; CF_AppData.HkPacket.CommandErrorCounter = initial_hk_err_counter; /* Act */ @@ -1997,10 +1993,10 @@ void Test_CF_CmdDisablePolldir_SuccessWhenActionSuccess(void) CF_AppData.config_table = &config_table; /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; /* Arrange unstubbable: CF_DoEnableDisablePolldir */ - msg->byte[1] = polldir; + msg->data.byte[1] = polldir; CF_AppData.HkPacket.CommandCounter = initial_hk_cmd_counter; @@ -2032,10 +2028,10 @@ void Test_CF_CmdDisablePolldir_FailWhenActionFail(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; /* Arrange unstubbable: CF_DoEnableDisablePolldir */ - msg->byte[1] = error_polldir; + msg->data.byte[1] = error_polldir; CF_AppData.HkPacket.CommandErrorCounter = initial_hk_err_counter; @@ -2131,7 +2127,7 @@ void Test_CF_DoPurgeQueue_PendOnly(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[1] = 0; /* pend */ + arg_cmd->data.byte[1] = 0; /* pend */ UT_SetHandlerFunction(UT_KEY(CF_CList_Traverse), UT_AltHandler_CF_CList_Traverse_POINTER, &context_CF_CList_Traverse); @@ -2167,7 +2163,7 @@ void Test_CF_DoPurgeQueue_HistoryOnly(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[1] = 1; /* history */ + arg_cmd->data.byte[1] = 1; /* history */ /* set correct context type for CF_CList_Traverse stub */ UT_SetHandlerFunction(UT_KEY(CF_CList_Traverse), UT_AltHandler_CF_CList_Traverse_POINTER, @@ -2207,7 +2203,7 @@ void Test_CF_DoPurgeQueue_Both(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[1] = 2; /* both */ + arg_cmd->data.byte[1] = 2; /* both */ /* set correct context type for CF_CList_Traverse stub */ /* this must use data buffer hack to pass multiple contexts */ @@ -2247,7 +2243,7 @@ void Test_CF_DoPurgeQueue_GivenBad_data_byte_1_SendEventAndReturn_neg1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[1] = 3; /* 3 is first default value */ + arg_cmd->data.byte[1] = 3; /* 3 is first default value */ /* Act */ local_result = CF_DoPurgeQueue(arg_chan_num, arg_cmd); @@ -2271,7 +2267,7 @@ void Test_CF_DoPurgeQueue_AnyGivenBad_data_byte_1_SendEventAndReturn_neg1(void) memset(&utbuf, 0, sizeof(utbuf)); - arg_cmd->byte[1] = Any_uint8_GreaterThan_or_EqualTo(3); + arg_cmd->data.byte[1] = Any_uint8_GreaterThan_or_EqualTo(3); /* Act */ local_result = CF_DoPurgeQueue(arg_chan_num, arg_cmd); @@ -2304,10 +2300,10 @@ void Test_CF_CmdPurgeQueue_FailWhenActionFail(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; /* Arrange unstubbable: CF_DoPurgeQueue */ - msg->byte[1] = error_purge; + msg->data.byte[1] = error_purge; CF_AppData.HkPacket.CommandErrorCounter = initial_hk_err_counter; @@ -2334,7 +2330,7 @@ void Test_CF_CmdPurgeQueue_SuccessWhenActionSuccess(void) memset(&utbuf, 0, sizeof(utbuf)); /* Arrange unstubbable: CF_DoChanAction */ - msg->byte[0] = channel; + msg->data.byte[0] = channel; CF_AppData.HkPacket.CommandCounter = 0; @@ -4404,4 +4400,4 @@ void UtTest_Setup(void) add_CF_CmdDisableEngine_tests(); add_CF_ProcessGroundCommand_tests(); -} \ No newline at end of file +}