Skip to content

Commit

Permalink
WIP nasa#777 - CFE_SB_GetTotalMsgLength and some CFE_SB_GetMsgId, CFE…
Browse files Browse the repository at this point in the history
…_SB_GetCmdCode
  • Loading branch information
skliper committed Nov 3, 2020
1 parent 9717fab commit fbc3925
Show file tree
Hide file tree
Showing 20 changed files with 149 additions and 126 deletions.
29 changes: 15 additions & 14 deletions docs/cFE Application Developers Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -1755,24 +1755,25 @@ Applications are portable to future missions. The following table
identifies the fields of the SB Message Header and the appropriate API
for extracting that field from the header:

| **SB Message Header Field** | **SB API for Reading the Header Field** | **Applicability** |
|:----------------------------|:----------------------------------------|:--------------------|
| Message ID | CFE_SB_GetMsgId | Command & Telemetry |
| Message Time | CFE_SB_GetMsgTime | Telemetry Only |
| Total Message Length | CFE_SB_GetTotalMsgLength | Command & Telemetry |
| User Data Message Length | CFE_SB_GetUserDataLength | Command & Telemetry |
| Command Code | CFE_SB_GetCmdCode | Command Only |
| Checksum | CFE_SB_GetChecksum | Command Only |

In addition to the function for reading the checksum field, there is
another API that automatically calculates the checksum for the packet
| **SB Message Header Field** | **API for Reading the Header Field** | **Applicability** |
|:----------------------------|:-------------------------------------|:--------------------|
| Message ID | CFE_MSG_GetMsgId | Command & Telemetry |
| Message Time | CFE_MSG_GetTime | Imp. Dependent |
| Total Message Length | CFE_MSG_GetSize | Command & Telemetry |
| Command Code | CFE_MSG_GetFcnCode | Command Only |

There are other APIs based on selected implementation, and the full list is
available in the user's guide.

There is another API that automatically calculates the checksum for the packet
and compares it to the checksum in the header. The API is called
CFE_SB_ValidateChecksum() and it simply returns a success or failure
indication.

If the Application's data structure definitions don't include the header
information, then the CFE_SB_GetUserData API could be used to obtain
the start address of the SB Message data.
Although CFE_SB_GetUserDataLength and CFE_SB_GetUserData APIs are available,
they are based on assumptions about the defintion of "User Data" and are
really just a best guess since the packet structure is dependent on implementation.
The preference is to use the actual packet structure when available.

#### 6.6 Sending Software Bus Messages

Expand Down
27 changes: 16 additions & 11 deletions fsw/cfe-core/src/es/cfe_es_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,10 @@ int32 CFE_ES_TaskInit(void)

void CFE_ES_TaskPipe(CFE_MSG_Message_t *MsgPtr)
{
CFE_SB_MsgId_t MessageID;
uint16 CommandCode;
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
CFE_MSG_FcnCode_t CommandCode = 0;

MessageID = CFE_SB_GetMsgId(MsgPtr);
CFE_MSG_GetMsgId(MsgPtr, &MessageID);
switch (CFE_SB_MsgIdToValue(MessageID))
{
/*
Expand All @@ -454,7 +454,7 @@ void CFE_ES_TaskPipe(CFE_MSG_Message_t *MsgPtr)
*/
case CFE_ES_CMD_MID:

CommandCode = CFE_SB_GetCmdCode(MsgPtr);
CFE_MSG_GetFcnCode(MsgPtr, &CommandCode);
switch (CommandCode)
{
case CFE_ES_NOOP_CC:
Expand Down Expand Up @@ -1641,22 +1641,27 @@ int32 CFE_ES_WriteERLogCmd(const CFE_ES_WriteERLog_t *data)
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength)
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
{
bool result = true;
uint16 ActualLength = CFE_SB_GetTotalMsgLength(MsgPtr);
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length
*/
if (ExpectedLength != ActualLength)
{
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(MsgPtr);
uint16 CommandCode = CFE_SB_GetCmdCode(MsgPtr);
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid cmd length: ID = 0x%X, CC = %d, Exp Len = %d, Len = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode, (int)ExpectedLength, (int)ActualLength);
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode,
(unsigned int)ActualLength, (unsigned int)ExpectedLength);
result = false;
CFE_ES_TaskData.CommandErrorCounter++;
}
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/es/cfe_es_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistry_t *data);
** Message Handler Helper Functions
*/
bool CFE_ES_ValidateHandle(CFE_ES_MemHandle_t Handle);
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength);
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);
void CFE_ES_FileWriteByteCntErr(const char *Filename,uint32 Requested,uint32 Actual);

/*************************************************************************/
Expand Down
45 changes: 26 additions & 19 deletions fsw/cfe-core/src/evs/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ CFE_EVS_GlobalData_t CFE_EVS_GlobalData;
/*
** Local function prototypes.
*/
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr);
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength);
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId);
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);

/* Function Definitions */

Expand Down Expand Up @@ -354,16 +354,16 @@ int32 CFE_EVS_TaskInit ( void )
*/
void CFE_EVS_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
{
CFE_SB_MsgId_t MessageID;
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;

MessageID = CFE_SB_GetMsgId(MsgPtr);
CFE_MSG_GetMsgId(MsgPtr, &MessageID);

/* Process all SB messages */
switch (CFE_SB_MsgIdToValue(MessageID))
{
case CFE_EVS_CMD_MID:
/* EVS task specific command */
CFE_EVS_ProcessGroundCommand(MsgPtr);
CFE_EVS_ProcessGroundCommand(MsgPtr, MessageID);
break;

case CFE_EVS_SEND_HK_MID:
Expand Down Expand Up @@ -396,13 +396,16 @@ void CFE_EVS_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
** Assumptions and Notes:
**
*/
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId)
{
/* status will get reset if it passes length check */
int32 Status = CFE_STATUS_WRONG_MSG_LENGTH;
int32 Status = CFE_STATUS_WRONG_MSG_LENGTH;
CFE_MSG_FcnCode_t FcnCode = 0;

CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

/* Process "known" EVS task ground commands */
switch (CFE_SB_GetCmdCode(MsgPtr))
switch (FcnCode)
{
case CFE_EVS_NOOP_CC:

Expand Down Expand Up @@ -576,9 +579,9 @@ void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
default:

EVS_SendEvent(CFE_EVS_ERR_CC_EID, CFE_EVS_EventType_ERROR,
"Invalid command code -- ID = 0x%08x, CC = %d",
(unsigned int)CFE_SB_MsgIdToValue(CFE_SB_GetMsgId(MsgPtr)),
(int)CFE_SB_GetCmdCode(MsgPtr));
"Invalid command code -- ID = 0x%08x, CC = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId),
(unsigned int)FcnCode);
Status = CFE_STATUS_BAD_COMMAND_CODE;

break;
Expand Down Expand Up @@ -608,23 +611,27 @@ void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
** Assumptions and Notes:
**
*/
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength)
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
{
bool result = true;
uint16 ActualLength = CFE_SB_GetTotalMsgLength(MsgPtr);
bool result = true;
CFE_MSG_Size_t ActualLength = 0;
CFE_MSG_FcnCode_t FcnCode = 0;
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetSize(MsgPtr, &ActualLength);

/*
** Verify the command packet length
*/
if (ExpectedLength != ActualLength)
{
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(MsgPtr);
uint16 CommandCode = CFE_SB_GetCmdCode(MsgPtr);
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);

EVS_SendEvent(CFE_EVS_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid cmd length: ID = 0x%X, CC = %d, Exp Len = %d, Len = %d",
(unsigned int)CFE_SB_MsgIdToValue(MessageID),
(int)CommandCode, (int)ExpectedLength, (int)ActualLength);
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode,
(unsigned int)ActualLength, (unsigned int)ExpectedLength);
result = false;
}

Expand Down
25 changes: 15 additions & 10 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ void CFE_SB_InitMsg(void *MsgPtr,
uint16 Length,
bool Clear );

#endif /* CFE_OMIT_DEPRECATED_6_8 */

/*****************************************************************************/
/**
** \brief DEPRECATED - Sets the message ID of a software bus message.
Expand All @@ -856,8 +858,6 @@ void CFE_SB_InitMsg(void *MsgPtr,
void CFE_SB_SetMsgId(CFE_MSG_Message_t *MsgPtr,
CFE_SB_MsgId_t MsgId);

#endif /* CFE_OMIT_DEPRECATED_6_8 */

/*****************************************************************************/
/**
** \brief Sets the length of user data in a software bus message.
Expand Down Expand Up @@ -903,7 +903,7 @@ void CFE_SB_SetUserDataLength(CFE_MSG_Message_t *MsgPtr,uint16 DataLength);
** \param[in] TotalLength The length to set (total size of the message, in bytes,
** including headers).
**
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength,
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode,
**/
void CFE_SB_SetTotalMsgLength(CFE_MSG_Message_t *MsgPtr,uint16 TotalLength);
Expand Down Expand Up @@ -1044,7 +1044,7 @@ int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr,
**
** \return A pointer to the first byte of user data within the software bus message.
**
** \sa #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
void *CFE_SB_GetUserData(CFE_MSG_Message_t *MsgPtr);
Expand All @@ -1063,7 +1063,7 @@ void *CFE_SB_GetUserData(CFE_MSG_Message_t *MsgPtr);
**
** \return The software bus Message ID from the message header.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_MSG_Message_t *MsgPtr);
Expand All @@ -1083,14 +1083,17 @@ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_MSG_Message_t *MsgPtr);
**
** \return The size (in bytes) of the user data in the software bus message.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetUserDataLength(const CFE_MSG_Message_t *MsgPtr);

#ifndef CFE_OMIT_DEPRECATED_6_8

/*****************************************************************************/
/**
** \brief Gets the total length of a software bus message.
** \brief DEPRECATED: Gets the total length of a software bus message.
** \deprecated
**
** \par Description
** This routine returns the total size of the software bus message.
Expand All @@ -1109,6 +1112,8 @@ uint16 CFE_SB_GetUserDataLength(const CFE_MSG_Message_t *MsgPtr);
**/
uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr);

#endif /* CFE_OMIT_DEPRECATED_6_8 */

/*****************************************************************************/
/**
** \brief Gets the command code field from a software bus message.
Expand All @@ -1128,7 +1133,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr);
** \return The command code included in the software bus message header (if present).
** Otherwise, returns a command code value of zero.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_SetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetCmdCode(CFE_MSG_Message_t *MsgPtr);
Expand All @@ -1151,7 +1156,7 @@ uint16 CFE_SB_GetCmdCode(CFE_MSG_Message_t *MsgPtr);
** \return The system time included in the software bus message header (if present),
** otherwise, returns a time value of zero.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_SetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_MSG_Message_t *MsgPtr);
Expand Down Expand Up @@ -1224,7 +1229,7 @@ int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr,
** \return The checksum included in the software bus message header (if present), otherwise,
** returns a checksum value of zero.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
** #CFE_SB_ValidateChecksum, #CFE_SB_GenerateChecksum
**/
Expand Down
4 changes: 2 additions & 2 deletions fsw/cfe-core/src/inc/cfe_sb_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -713,8 +713,8 @@
**/
#define CFE_SB_BAD_CMD_CODE_EID 42

/** \brief <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' </tt>
** \event <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' </tt>
/** \brief <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%x' </tt>
** \event <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%x' </tt>
**
** \par Type: ERROR
**
Expand Down
6 changes: 3 additions & 3 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1164,7 +1164,7 @@ int32 CFE_SB_SendMsgFull(CFE_MSG_Message_t *MsgPtr,
CFE_SB_PipeD_t *PipeDscPtr;
CFE_SBR_RouteId_t RouteId;
CFE_SB_BufferD_t *BufDscPtr;
uint16 TotalMsgSize;
CFE_MSG_Size_t TotalMsgSize = 0;
CFE_ES_ResourceID_t AppId;
CFE_ES_ResourceID_t TskId;
uint32 i;
Expand Down Expand Up @@ -1212,7 +1212,7 @@ int32 CFE_SB_SendMsgFull(CFE_MSG_Message_t *MsgPtr,
return CFE_SB_BAD_ARGUMENT;
}/* end if */

TotalMsgSize = CFE_SB_GetTotalMsgLength(MsgPtr);
CFE_MSG_GetSize(MsgPtr, &TotalMsgSize);

/* Verify the size of the pkt is < or = the mission defined max */
if(TotalMsgSize > CFE_MISSION_SB_MAX_SB_MSG_SIZE){
Expand Down Expand Up @@ -1294,7 +1294,7 @@ int32 CFE_SB_SendMsgFull(CFE_MSG_Message_t *MsgPtr,
/* Copy the packet into the SB memory space */
if (CopyMode != CFE_SB_SEND_ZEROCOPY){
/* Copy the packet into the SB memory space */
memcpy( BufDscPtr->Buffer, MsgPtr, (uint16)TotalMsgSize );
memcpy(BufDscPtr->Buffer, MsgPtr, TotalMsgSize);
}

/* For Tlm packets, increment the seq count if requested */
Expand Down
2 changes: 1 addition & 1 deletion fsw/cfe-core/src/sb/cfe_sb_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ CFE_SB_DestinationD_t *CFE_SB_GetDestPtr(CFE_SBR_RouteId_t RouteId, CFE_SB_PipeI
** \returns The number of bytes in the software bus message header for
** messages with the given \c MsgId.
**
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_MsgHdrSize(const CFE_MSG_Message_t *MsgPtr);
Expand Down
Loading

0 comments on commit fbc3925

Please sign in to comment.