Skip to content

Commit fbc3925

Browse files
author
Jacob Hageman
committed
WIP #777 - CFE_SB_GetTotalMsgLength and some CFE_SB_GetMsgId, CFE_SB_GetCmdCode
1 parent 9717fab commit fbc3925

20 files changed

+149
-126
lines changed

docs/cFE Application Developers Guide.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1755,24 +1755,25 @@ Applications are portable to future missions. The following table
17551755
identifies the fields of the SB Message Header and the appropriate API
17561756
for extracting that field from the header:
17571757

1758-
| **SB Message Header Field** | **SB API for Reading the Header Field** | **Applicability** |
1759-
|:----------------------------|:----------------------------------------|:--------------------|
1760-
| Message ID | CFE_SB_GetMsgId | Command & Telemetry |
1761-
| Message Time | CFE_SB_GetMsgTime | Telemetry Only |
1762-
| Total Message Length | CFE_SB_GetTotalMsgLength | Command & Telemetry |
1763-
| User Data Message Length | CFE_SB_GetUserDataLength | Command & Telemetry |
1764-
| Command Code | CFE_SB_GetCmdCode | Command Only |
1765-
| Checksum | CFE_SB_GetChecksum | Command Only |
1766-
1767-
In addition to the function for reading the checksum field, there is
1768-
another API that automatically calculates the checksum for the packet
1758+
| **SB Message Header Field** | **API for Reading the Header Field** | **Applicability** |
1759+
|:----------------------------|:-------------------------------------|:--------------------|
1760+
| Message ID | CFE_MSG_GetMsgId | Command & Telemetry |
1761+
| Message Time | CFE_MSG_GetTime | Imp. Dependent |
1762+
| Total Message Length | CFE_MSG_GetSize | Command & Telemetry |
1763+
| Command Code | CFE_MSG_GetFcnCode | Command Only |
1764+
1765+
There are other APIs based on selected implementation, and the full list is
1766+
available in the user's guide.
1767+
1768+
There is another API that automatically calculates the checksum for the packet
17691769
and compares it to the checksum in the header. The API is called
17701770
CFE_SB_ValidateChecksum() and it simply returns a success or failure
17711771
indication.
17721772

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

17771778
#### 6.6 Sending Software Bus Messages
17781779

fsw/cfe-core/src/es/cfe_es_task.c

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -436,10 +436,10 @@ int32 CFE_ES_TaskInit(void)
436436

437437
void CFE_ES_TaskPipe(CFE_MSG_Message_t *MsgPtr)
438438
{
439-
CFE_SB_MsgId_t MessageID;
440-
uint16 CommandCode;
439+
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
440+
CFE_MSG_FcnCode_t CommandCode = 0;
441441

442-
MessageID = CFE_SB_GetMsgId(MsgPtr);
442+
CFE_MSG_GetMsgId(MsgPtr, &MessageID);
443443
switch (CFE_SB_MsgIdToValue(MessageID))
444444
{
445445
/*
@@ -454,7 +454,7 @@ void CFE_ES_TaskPipe(CFE_MSG_Message_t *MsgPtr)
454454
*/
455455
case CFE_ES_CMD_MID:
456456

457-
CommandCode = CFE_SB_GetCmdCode(MsgPtr);
457+
CFE_MSG_GetFcnCode(MsgPtr, &CommandCode);
458458
switch (CommandCode)
459459
{
460460
case CFE_ES_NOOP_CC:
@@ -1641,22 +1641,27 @@ int32 CFE_ES_WriteERLogCmd(const CFE_ES_WriteERLog_t *data)
16411641
/* */
16421642
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
16431643

1644-
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength)
1644+
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
16451645
{
1646-
bool result = true;
1647-
uint16 ActualLength = CFE_SB_GetTotalMsgLength(MsgPtr);
1646+
bool result = true;
1647+
CFE_MSG_Size_t ActualLength = 0;
1648+
CFE_MSG_FcnCode_t FcnCode = 0;
1649+
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
1650+
1651+
CFE_MSG_GetSize(MsgPtr, &ActualLength);
16481652

16491653
/*
16501654
** Verify the command packet length
16511655
*/
16521656
if (ExpectedLength != ActualLength)
16531657
{
1654-
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(MsgPtr);
1655-
uint16 CommandCode = CFE_SB_GetCmdCode(MsgPtr);
1658+
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
1659+
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);
16561660

16571661
CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
1658-
"Invalid cmd length: ID = 0x%X, CC = %d, Exp Len = %d, Len = %d",
1659-
(unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode, (int)ExpectedLength, (int)ActualLength);
1662+
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
1663+
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode,
1664+
(unsigned int)ActualLength, (unsigned int)ExpectedLength);
16601665
result = false;
16611666
CFE_ES_TaskData.CommandErrorCounter++;
16621667
}

fsw/cfe-core/src/es/cfe_es_task.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistry_t *data);
204204
** Message Handler Helper Functions
205205
*/
206206
bool CFE_ES_ValidateHandle(CFE_ES_MemHandle_t Handle);
207-
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength);
207+
bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);
208208
void CFE_ES_FileWriteByteCntErr(const char *Filename,uint32 Requested,uint32 Actual);
209209

210210
/*************************************************************************/

fsw/cfe-core/src/evs/cfe_evs_task.c

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ CFE_EVS_GlobalData_t CFE_EVS_GlobalData;
5353
/*
5454
** Local function prototypes.
5555
*/
56-
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr);
57-
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength);
56+
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId);
57+
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength);
5858

5959
/* Function Definitions */
6060

@@ -354,16 +354,16 @@ int32 CFE_EVS_TaskInit ( void )
354354
*/
355355
void CFE_EVS_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
356356
{
357-
CFE_SB_MsgId_t MessageID;
357+
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
358358

359-
MessageID = CFE_SB_GetMsgId(MsgPtr);
359+
CFE_MSG_GetMsgId(MsgPtr, &MessageID);
360360

361361
/* Process all SB messages */
362362
switch (CFE_SB_MsgIdToValue(MessageID))
363363
{
364364
case CFE_EVS_CMD_MID:
365365
/* EVS task specific command */
366-
CFE_EVS_ProcessGroundCommand(MsgPtr);
366+
CFE_EVS_ProcessGroundCommand(MsgPtr, MessageID);
367367
break;
368368

369369
case CFE_EVS_SEND_HK_MID:
@@ -396,13 +396,16 @@ void CFE_EVS_ProcessCommandPacket(CFE_MSG_Message_t *MsgPtr)
396396
** Assumptions and Notes:
397397
**
398398
*/
399-
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
399+
void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId)
400400
{
401401
/* status will get reset if it passes length check */
402-
int32 Status = CFE_STATUS_WRONG_MSG_LENGTH;
402+
int32 Status = CFE_STATUS_WRONG_MSG_LENGTH;
403+
CFE_MSG_FcnCode_t FcnCode = 0;
404+
405+
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);
403406

404407
/* Process "known" EVS task ground commands */
405-
switch (CFE_SB_GetCmdCode(MsgPtr))
408+
switch (FcnCode)
406409
{
407410
case CFE_EVS_NOOP_CC:
408411

@@ -576,9 +579,9 @@ void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
576579
default:
577580

578581
EVS_SendEvent(CFE_EVS_ERR_CC_EID, CFE_EVS_EventType_ERROR,
579-
"Invalid command code -- ID = 0x%08x, CC = %d",
580-
(unsigned int)CFE_SB_MsgIdToValue(CFE_SB_GetMsgId(MsgPtr)),
581-
(int)CFE_SB_GetCmdCode(MsgPtr));
582+
"Invalid command code -- ID = 0x%08x, CC = %u",
583+
(unsigned int)CFE_SB_MsgIdToValue(MsgId),
584+
(unsigned int)FcnCode);
582585
Status = CFE_STATUS_BAD_COMMAND_CODE;
583586

584587
break;
@@ -608,23 +611,27 @@ void CFE_EVS_ProcessGroundCommand(CFE_MSG_Message_t *MsgPtr)
608611
** Assumptions and Notes:
609612
**
610613
*/
611-
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength)
614+
bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t ExpectedLength)
612615
{
613-
bool result = true;
614-
uint16 ActualLength = CFE_SB_GetTotalMsgLength(MsgPtr);
616+
bool result = true;
617+
CFE_MSG_Size_t ActualLength = 0;
618+
CFE_MSG_FcnCode_t FcnCode = 0;
619+
CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID;
620+
621+
CFE_MSG_GetSize(MsgPtr, &ActualLength);
615622

616623
/*
617624
** Verify the command packet length
618625
*/
619626
if (ExpectedLength != ActualLength)
620627
{
621-
CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(MsgPtr);
622-
uint16 CommandCode = CFE_SB_GetCmdCode(MsgPtr);
628+
CFE_MSG_GetMsgId(MsgPtr, &MsgId);
629+
CFE_MSG_GetFcnCode(MsgPtr, &FcnCode);
623630

624631
EVS_SendEvent(CFE_EVS_LEN_ERR_EID, CFE_EVS_EventType_ERROR,
625-
"Invalid cmd length: ID = 0x%X, CC = %d, Exp Len = %d, Len = %d",
626-
(unsigned int)CFE_SB_MsgIdToValue(MessageID),
627-
(int)CommandCode, (int)ExpectedLength, (int)ActualLength);
632+
"Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u",
633+
(unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode,
634+
(unsigned int)ActualLength, (unsigned int)ExpectedLength);
628635
result = false;
629636
}
630637

fsw/cfe-core/src/inc/cfe_sb.h

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ void CFE_SB_InitMsg(void *MsgPtr,
833833
uint16 Length,
834834
bool Clear );
835835

836+
#endif /* CFE_OMIT_DEPRECATED_6_8 */
837+
836838
/*****************************************************************************/
837839
/**
838840
** \brief DEPRECATED - Sets the message ID of a software bus message.
@@ -856,8 +858,6 @@ void CFE_SB_InitMsg(void *MsgPtr,
856858
void CFE_SB_SetMsgId(CFE_MSG_Message_t *MsgPtr,
857859
CFE_SB_MsgId_t MsgId);
858860

859-
#endif /* CFE_OMIT_DEPRECATED_6_8 */
860-
861861
/*****************************************************************************/
862862
/**
863863
** \brief Sets the length of user data in a software bus message.
@@ -903,7 +903,7 @@ void CFE_SB_SetUserDataLength(CFE_MSG_Message_t *MsgPtr,uint16 DataLength);
903903
** \param[in] TotalLength The length to set (total size of the message, in bytes,
904904
** including headers).
905905
**
906-
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
906+
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength,
907907
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode,
908908
**/
909909
void CFE_SB_SetTotalMsgLength(CFE_MSG_Message_t *MsgPtr,uint16 TotalLength);
@@ -1044,7 +1044,7 @@ int32 CFE_SB_MessageStringSet(char *DestStringPtr, const char *SourceStringPtr,
10441044
**
10451045
** \return A pointer to the first byte of user data within the software bus message.
10461046
**
1047-
** \sa #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
1047+
** \sa #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
10481048
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
10491049
**/
10501050
void *CFE_SB_GetUserData(CFE_MSG_Message_t *MsgPtr);
@@ -1063,7 +1063,7 @@ void *CFE_SB_GetUserData(CFE_MSG_Message_t *MsgPtr);
10631063
**
10641064
** \return The software bus Message ID from the message header.
10651065
**
1066-
** \sa #CFE_SB_GetUserData, #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
1066+
** \sa #CFE_SB_GetUserData, #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength,
10671067
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
10681068
**/
10691069
CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_MSG_Message_t *MsgPtr);
@@ -1083,14 +1083,17 @@ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_MSG_Message_t *MsgPtr);
10831083
**
10841084
** \return The size (in bytes) of the user data in the software bus message.
10851085
**
1086-
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
1086+
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength,
10871087
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
10881088
**/
10891089
uint16 CFE_SB_GetUserDataLength(const CFE_MSG_Message_t *MsgPtr);
10901090

1091+
#ifndef CFE_OMIT_DEPRECATED_6_8
1092+
10911093
/*****************************************************************************/
10921094
/**
1093-
** \brief Gets the total length of a software bus message.
1095+
** \brief DEPRECATED: Gets the total length of a software bus message.
1096+
** \deprecated
10941097
**
10951098
** \par Description
10961099
** This routine returns the total size of the software bus message.
@@ -1109,6 +1112,8 @@ uint16 CFE_SB_GetUserDataLength(const CFE_MSG_Message_t *MsgPtr);
11091112
**/
11101113
uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr);
11111114

1115+
#endif /* CFE_OMIT_DEPRECATED_6_8 */
1116+
11121117
/*****************************************************************************/
11131118
/**
11141119
** \brief Gets the command code field from a software bus message.
@@ -1128,7 +1133,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr);
11281133
** \return The command code included in the software bus message header (if present).
11291134
** Otherwise, returns a command code value of zero.
11301135
**
1131-
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
1136+
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
11321137
** #CFE_SB_GetMsgTime, #CFE_SB_SetCmdCode, #CFE_SB_GetChecksum
11331138
**/
11341139
uint16 CFE_SB_GetCmdCode(CFE_MSG_Message_t *MsgPtr);
@@ -1151,7 +1156,7 @@ uint16 CFE_SB_GetCmdCode(CFE_MSG_Message_t *MsgPtr);
11511156
** \return The system time included in the software bus message header (if present),
11521157
** otherwise, returns a time value of zero.
11531158
**
1154-
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
1159+
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
11551160
** #CFE_SB_SetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
11561161
**/
11571162
CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_MSG_Message_t *MsgPtr);
@@ -1224,7 +1229,7 @@ int32 CFE_SB_MessageStringGet(char *DestStringPtr, const char *SourceStringPtr,
12241229
** \return The checksum included in the software bus message header (if present), otherwise,
12251230
** returns a checksum value of zero.
12261231
**
1227-
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
1232+
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
12281233
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
12291234
** #CFE_SB_ValidateChecksum, #CFE_SB_GenerateChecksum
12301235
**/

fsw/cfe-core/src/inc/cfe_sb_events.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -713,8 +713,8 @@
713713
**/
714714
#define CFE_SB_BAD_CMD_CODE_EID 42
715715

716-
/** \brief <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' </tt>
717-
** \event <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' </tt>
716+
/** \brief <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%x' </tt>
717+
** \event <tt> 'Invalid Cmd, Unexpected Msg Id: 0x\%x' </tt>
718718
**
719719
** \par Type: ERROR
720720
**

fsw/cfe-core/src/sb/cfe_sb_api.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1164,7 +1164,7 @@ int32 CFE_SB_SendMsgFull(CFE_MSG_Message_t *MsgPtr,
11641164
CFE_SB_PipeD_t *PipeDscPtr;
11651165
CFE_SBR_RouteId_t RouteId;
11661166
CFE_SB_BufferD_t *BufDscPtr;
1167-
uint16 TotalMsgSize;
1167+
CFE_MSG_Size_t TotalMsgSize = 0;
11681168
CFE_ES_ResourceID_t AppId;
11691169
CFE_ES_ResourceID_t TskId;
11701170
uint32 i;
@@ -1212,7 +1212,7 @@ int32 CFE_SB_SendMsgFull(CFE_MSG_Message_t *MsgPtr,
12121212
return CFE_SB_BAD_ARGUMENT;
12131213
}/* end if */
12141214

1215-
TotalMsgSize = CFE_SB_GetTotalMsgLength(MsgPtr);
1215+
CFE_MSG_GetSize(MsgPtr, &TotalMsgSize);
12161216

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

13001300
/* For Tlm packets, increment the seq count if requested */

fsw/cfe-core/src/sb/cfe_sb_priv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ CFE_SB_DestinationD_t *CFE_SB_GetDestPtr(CFE_SBR_RouteId_t RouteId, CFE_SB_PipeI
357357
** \returns The number of bytes in the software bus message header for
358358
** messages with the given \c MsgId.
359359
**
360-
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength,
360+
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength,
361361
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
362362
**/
363363
uint16 CFE_SB_MsgHdrSize(const CFE_MSG_Message_t *MsgPtr);

0 commit comments

Comments
 (0)