Skip to content

Commit

Permalink
Merge pull request #395 from nasa/fix-393
Browse files Browse the repository at this point in the history
Fix #393, revert merge of PR #341.
  • Loading branch information
dzbaker authored Jul 11, 2023
2 parents 0f18ae4 + 98b4694 commit f5c3cb3
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 68 deletions.
12 changes: 11 additions & 1 deletion fsw/inc/cf_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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;

/**
Expand Down
26 changes: 13 additions & 13 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->byte[0];
uint8 param = cmd->data.byte[0];
int i;
int acc = 1;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
Loading

0 comments on commit f5c3cb3

Please sign in to comment.