Skip to content

Commit

Permalink
Fix #28, Opaque CFE_SB_MsgId_t values
Browse files Browse the repository at this point in the history
Do not assume CFE_SB_MsgId_t is implicitly integral in nature.
When an integer value is required for printing or backward
compatibility, use the explicit conversion routine to
get this.
  • Loading branch information
jphickey committed Apr 6, 2020
1 parent 545710c commit 22d7857
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
43 changes: 25 additions & 18 deletions fsw/src/to_lab_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ void TO_LAB_init(void)
** Initialize housekeeping packet (clear user data area)...
*/
CFE_SB_InitMsg(&TO_LAB_Global.HkBuf.MsgHdr,
TO_LAB_HK_TLM_MID,
CFE_SB_ValueToMsgId(TO_LAB_HK_TLM_MID),
sizeof(TO_LAB_Global.HkBuf.HkTlm), true);

/* Subscribe to my commands */
status = CFE_SB_CreatePipe(&TO_LAB_Global.Cmd_pipe, PipeDepth, PipeName);
if (status == CFE_SUCCESS)
{
CFE_SB_Subscribe(TO_LAB_CMD_MID, TO_LAB_Global.Cmd_pipe);
CFE_SB_Subscribe(TO_LAB_SEND_HK_MID, TO_LAB_Global.Cmd_pipe);
CFE_SB_Subscribe(CFE_SB_ValueToMsgId(TO_LAB_CMD_MID), TO_LAB_Global.Cmd_pipe);
CFE_SB_Subscribe(CFE_SB_ValueToMsgId(TO_LAB_SEND_HK_MID), TO_LAB_Global.Cmd_pipe);
}
else
CFE_EVS_SendEvent(TO_CRCMDPIPE_ERR_EID,CFE_EVS_EventType_ERROR,
Expand All @@ -214,16 +214,16 @@ void TO_LAB_init(void)
/* Subscriptions for TLM pipe*/
for (i=0; (i < (sizeof(TO_SubTable)/sizeof(TO_subscription_t))); i++)
{
if(TO_SubTable[i].Stream != TO_UNUSED )
status = CFE_SB_SubscribeEx(TO_SubTable[i].Stream,
if(TO_SubTable[i].MsgIdVal != TO_UNUSED )
status = CFE_SB_SubscribeEx(CFE_SB_ValueToMsgId(TO_SubTable[i].MsgIdVal),
TO_LAB_Global.Tlm_pipe,
TO_SubTable[i].Flags,
TO_SubTable[i].BufLimit);

if (status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_SUBSCRIBE_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't subscribe to stream 0x%x status %i", __LINE__,
TO_SubTable[i].Stream,(int)status);
TO_SubTable[i].MsgIdVal,(int)status);
}

/*
Expand Down Expand Up @@ -286,7 +286,7 @@ void TO_LAB_process_commands(void)

MsgId = CFE_SB_GetMsgId(MsgPtr);
/* For SB return statuses that imply a message: process it. */
switch (MsgId)
switch (CFE_SB_MsgIdToValue(MsgId))
{
case TO_LAB_CMD_MID:
TO_LAB_exec_local_command(MsgPtr);
Expand All @@ -298,7 +298,8 @@ void TO_LAB_process_commands(void)

default:
CFE_EVS_SendEvent(TO_MSGID_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO: Invalid Msg ID Rcvd 0x%x",__LINE__,MsgId);
"L%d TO: Invalid Msg ID Rcvd 0x%x",__LINE__,
CFE_SB_MsgIdToValue(MsgId));
break;
}
break;
Expand Down Expand Up @@ -395,7 +396,7 @@ int32 TO_LAB_SendDataTypes(const TO_LAB_SendDataTypes_t *data)

/* initialize data types packet */
CFE_SB_InitMsg(&TO_LAB_Global.DataTypesBuf.MsgHdr,
TO_LAB_DATA_TYPES_MID,
CFE_SB_ValueToMsgId(TO_LAB_DATA_TYPES_MID),
sizeof(TO_LAB_Global.DataTypesBuf.DataTypes), true);

CFE_SB_TimeStampMsg(&TO_LAB_Global.DataTypesBuf.MsgHdr);
Expand Down Expand Up @@ -483,11 +484,12 @@ int32 TO_LAB_AddPacket(const TO_LAB_AddPacket_t *data)
if(status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_ADDPKT_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't subscribe 0x%x status %i",__LINE__,
pCmd->Stream, (int)status);
(unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream),
(int)status);
else
CFE_EVS_SendEvent(TO_ADDPKT_INF_EID,CFE_EVS_EventType_INFORMATION,
"L%d TO AddPkt 0x%x, QoS %d.%d, limit %d",__LINE__,
pCmd->Stream,
(unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream),
pCmd->Flags.Priority,
pCmd->Flags.Reliability,
pCmd->BufLimit);
Expand All @@ -510,10 +512,12 @@ int32 TO_LAB_RemovePacket(const TO_LAB_RemovePacket_t *data)
if(status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_REMOVEPKT_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't Unsubscribe to Stream 0x%x on pipe %d, status %i",__LINE__,
pCmd->Stream, TO_LAB_Global.Tlm_pipe, (int)status);
(unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream),
TO_LAB_Global.Tlm_pipe, (int)status);
else
CFE_EVS_SendEvent(TO_REMOVEPKT_INF_EID,CFE_EVS_EventType_INFORMATION,
"L%d TO RemovePkt 0x%x",__LINE__, pCmd->Stream);
"L%d TO RemovePkt 0x%x",__LINE__,
(unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream));
++TO_LAB_Global.HkBuf.HkTlm.Payload.CommandCounter;
return CFE_SUCCESS;
} /* End of TO_LAB_RemovePacket() */
Expand All @@ -530,25 +534,28 @@ int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAll_t *data)

for (i=0; (i < (sizeof(TO_SubTable)/sizeof(TO_subscription_t))); i++)
{
if (TO_SubTable[i].Stream != TO_UNUSED )
if (TO_SubTable[i].MsgIdVal != TO_UNUSED )
{
status = CFE_SB_Unsubscribe(TO_SubTable[i].Stream, TO_LAB_Global.Tlm_pipe);
status = CFE_SB_Unsubscribe(CFE_SB_ValueToMsgId(TO_SubTable[i].MsgIdVal),
TO_LAB_Global.Tlm_pipe);

if(status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_REMOVEALLPTKS_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't Unsubscribe to stream 0x%x status %i", __LINE__,
TO_SubTable[i].Stream, (int)status);
TO_SubTable[i].MsgIdVal, (int)status);
}
}

/* remove commands as well */
status = CFE_SB_Unsubscribe(TO_LAB_CMD_MID, TO_LAB_Global.Cmd_pipe);
status = CFE_SB_Unsubscribe(CFE_SB_ValueToMsgId(TO_LAB_CMD_MID),
TO_LAB_Global.Cmd_pipe);
if(status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_REMOVECMDTO_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't Unsubscribe to cmd stream 0x%x status %i", __LINE__,
TO_LAB_CMD_MID, (int)status);

status = CFE_SB_Unsubscribe(TO_LAB_SEND_HK_MID, TO_LAB_Global.Cmd_pipe);
status = CFE_SB_Unsubscribe(CFE_SB_ValueToMsgId(TO_LAB_SEND_HK_MID),
TO_LAB_Global.Cmd_pipe);
if (status != CFE_SUCCESS)
CFE_EVS_SendEvent(TO_REMOVEHKTO_ERR_EID,CFE_EVS_EventType_ERROR,
"L%d TO Can't Unsubscribe to cmd stream 0x%x status %i", __LINE__,
Expand Down
9 changes: 6 additions & 3 deletions fsw/src/to_lab_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,12 @@ typedef struct
/*****************************************************************************/

typedef struct {
CFE_SB_MsgId_t Stream;
CFE_SB_Qos_t Flags;
uint16 BufLimit;
/* Note - this currently needs to be a MsgId "value" (integer) due to the way
this table is currently initialized at compile-time. This should change back
to a CFE_SB_MsgId_t value in a future revision */
CFE_SB_MsgId_Atom_t MsgIdVal;
CFE_SB_Qos_t Flags;
uint16 BufLimit;
} TO_subscription_t;

/******************************************************************************/
Expand Down

0 comments on commit 22d7857

Please sign in to comment.