Skip to content

Commit

Permalink
Fix nasa#288, Remove unnecessary CF_UnionArgs_Payload_t union
Browse files Browse the repository at this point in the history
  • Loading branch information
thnkslprpt committed Mar 12, 2023
1 parent cb2977c commit 7c1a590
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 71 deletions.
12 changes: 1 addition & 11 deletions fsw/inc/cf_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -870,16 +870,6 @@ 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
*
Expand All @@ -889,7 +879,7 @@ typedef union CF_UnionArgs_Payload
typedef struct
{
CFE_MSG_CommandHeader_t cmd_header; /**< \brief Command header */
CF_UnionArgs_Payload_t data; /**< \brief Generic command arguments */
uint8 byte[4]; /**< \brief Generic uint8 array of arguments */
} CF_UnionArgsCmd_t;

/**
Expand Down
22 changes: 11 additions & 11 deletions fsw/src/cf_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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->data.byte[0];
uint8 param = cmd->byte[0];
int i;
int acc = 1;

Expand Down Expand Up @@ -220,21 +220,21 @@ int CF_DoChanAction(CF_UnionArgsCmd_t *cmd, const char *errstr, CF_ChanActionFn_
/* 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->data.byte[0] == CF_ALL_CHANNELS)
if (cmd->byte[0] == CF_ALL_CHANNELS)
{
/* apply to all channels */
for (i = 0; i < CF_NUM_CHANNELS; ++i)
ret |= fn(i, context);
}
else if (cmd->data.byte[0] < CF_NUM_CHANNELS)
else if (cmd->byte[0] < CF_NUM_CHANNELS)
{
ret = fn(cmd->data.byte[0], context);
ret = fn(cmd->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->data.byte[0]);
"CF: %s: channel parameter out of range. received %d", errstr, cmd->byte[0]);
ret = -1;
}

Expand Down Expand Up @@ -591,20 +591,20 @@ int CF_DoEnableDisablePolldir(uint8 chan_num, const CF_ChanAction_BoolMsgArg_t *
int i;
int ret = 0;
/* no need to bounds check chan_num, done in caller */
if (context->msg->data.byte[1] == CF_ALL_POLLDIRS)
if (context->msg->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->data.byte[1] < CF_MAX_POLLING_DIR_PER_CHAN)
else if (context->msg->byte[1] < CF_MAX_POLLING_DIR_PER_CHAN)
{
CF_AppData.config_table->chan[chan_num].polldir[context->msg->data.byte[1]].enabled = context->barg;
CF_AppData.config_table->chan[chan_num].polldir[context->msg->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->data.byte[1],
"CF: enable/disable polldir: invalid polldir %d on channel %d", context->msg->byte[1],
chan_num);
ret = -1;
}
Expand Down Expand Up @@ -703,7 +703,7 @@ int CF_DoPurgeQueue(uint8 chan_num, CF_UnionArgsCmd_t *cmd)
int pend = 0;
int hist = 0;

switch (cmd->data.byte[1])
switch (cmd->byte[1])
{
case 0: /* pend */
pend = 1;
Expand All @@ -720,7 +720,7 @@ int 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->data.byte[1]);
cmd->byte[1]);
ret = -1;
break;
}
Expand Down
Loading

0 comments on commit 7c1a590

Please sign in to comment.