diff --git a/docs/cFE Application Developers Guide.md b/docs/cFE Application Developers Guide.md index 7c7ea3adb..188ab473c 100644 --- a/docs/cFE Application Developers Guide.md +++ b/docs/cFE Application Developers Guide.md @@ -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 diff --git a/fsw/cfe-core/src/es/cfe_es_task.c b/fsw/cfe-core/src/es/cfe_es_task.c index d74d45b3b..1b2c3e9fb 100644 --- a/fsw/cfe-core/src/es/cfe_es_task.c +++ b/fsw/cfe-core/src/es/cfe_es_task.c @@ -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)) { /* @@ -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: @@ -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++; } diff --git a/fsw/cfe-core/src/es/cfe_es_task.h b/fsw/cfe-core/src/es/cfe_es_task.h index 6d89397d8..e687db466 100644 --- a/fsw/cfe-core/src/es/cfe_es_task.h +++ b/fsw/cfe-core/src/es/cfe_es_task.h @@ -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); /*************************************************************************/ diff --git a/fsw/cfe-core/src/evs/cfe_evs_task.c b/fsw/cfe-core/src/evs/cfe_evs_task.c index 7a134e8a9..d9cd5f31b 100644 --- a/fsw/cfe-core/src/evs/cfe_evs_task.c +++ b/fsw/cfe-core/src/evs/cfe_evs_task.c @@ -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 */ @@ -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: @@ -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: @@ -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; @@ -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; } diff --git a/fsw/cfe-core/src/inc/cfe_sb.h b/fsw/cfe-core/src/inc/cfe_sb.h index 3ac881b8b..e28dc443b 100644 --- a/fsw/cfe-core/src/inc/cfe_sb.h +++ b/fsw/cfe-core/src/inc/cfe_sb.h @@ -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. @@ -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. @@ -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); @@ -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); @@ -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); @@ -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. @@ -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. @@ -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); @@ -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); @@ -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 **/ diff --git a/fsw/cfe-core/src/inc/cfe_sb_events.h b/fsw/cfe-core/src/inc/cfe_sb_events.h index c99e55eed..464d4a519 100644 --- a/fsw/cfe-core/src/inc/cfe_sb_events.h +++ b/fsw/cfe-core/src/inc/cfe_sb_events.h @@ -713,8 +713,8 @@ **/ #define CFE_SB_BAD_CMD_CODE_EID 42 -/** \brief 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' -** \event 'Invalid Cmd, Unexpected Msg Id: 0x\%04x' +/** \brief 'Invalid Cmd, Unexpected Msg Id: 0x\%x' +** \event 'Invalid Cmd, Unexpected Msg Id: 0x\%x' ** ** \par Type: ERROR ** diff --git a/fsw/cfe-core/src/sb/cfe_sb_api.c b/fsw/cfe-core/src/sb/cfe_sb_api.c index 7ece355d7..9c5f0c70c 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_api.c +++ b/fsw/cfe-core/src/sb/cfe_sb_api.c @@ -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; @@ -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){ @@ -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 */ diff --git a/fsw/cfe-core/src/sb/cfe_sb_priv.h b/fsw/cfe-core/src/sb/cfe_sb_priv.h index 447b6823e..e3a2faefc 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_priv.h +++ b/fsw/cfe-core/src/sb/cfe_sb_priv.h @@ -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); diff --git a/fsw/cfe-core/src/sb/cfe_sb_task.c b/fsw/cfe-core/src/sb/cfe_sb_task.c index 3b87094b4..4e421dbcc 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_task.c +++ b/fsw/cfe-core/src/sb/cfe_sb_task.c @@ -320,23 +320,27 @@ int32 CFE_SB_AppInit(void){ ** Return: ** true if length is acceptable */ -bool CFE_SB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength) +bool CFE_SB_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_SB_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_SB.HKTlmMsg.Payload.CommandErrorCounter; } @@ -361,6 +365,7 @@ bool CFE_SB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength) */ void CFE_SB_ProcessCmdPipePkt(void) { CFE_SB_MsgId_t MessageID; + CFE_MSG_FcnCode_t FcnCode = 0; MessageID = CFE_SB_GetMsgId(CFE_SB.CmdPipePktPtr); @@ -373,7 +378,8 @@ void CFE_SB_ProcessCmdPipePkt(void) { case CFE_SB_SUB_RPT_CTRL_MID: /* Note: Command counter not incremented for this command */ - switch (CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)) { + CFE_MSG_GetFcnCode(CFE_SB.CmdPipePktPtr, &FcnCode); + switch (FcnCode) { case CFE_SB_SEND_PREV_SUBS_CC: if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_SendPrevSubs_t))) { @@ -397,15 +403,15 @@ void CFE_SB_ProcessCmdPipePkt(void) { default: CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID,CFE_EVS_EventType_ERROR, - "Invalid Cmd, Unexpected Command Code %d", - (int)CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)); + "Invalid Cmd, Unexpected Command Code %u", (unsigned int)FcnCode); CFE_SB.HKTlmMsg.Payload.CommandErrorCounter++; break; } /* end switch on cmd code */ break; case CFE_SB_CMD_MID: - switch (CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)) { + CFE_MSG_GetFcnCode(CFE_SB.CmdPipePktPtr, &FcnCode); + switch (FcnCode) { case CFE_SB_NOOP_CC: if (CFE_SB_VerifyCmdLength(CFE_SB.CmdPipePktPtr, sizeof(CFE_SB_Noop_t))) { @@ -465,8 +471,7 @@ void CFE_SB_ProcessCmdPipePkt(void) { default: CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID,CFE_EVS_EventType_ERROR, - "Invalid Cmd, Unexpected Command Code %d", - (int)CFE_SB_GetCmdCode(CFE_SB.CmdPipePktPtr)); + "Invalid Cmd, Unexpected Command Code %u", FcnCode); CFE_SB.HKTlmMsg.Payload.CommandErrorCounter++; break; } /* end switch on cmd code */ @@ -474,7 +479,7 @@ void CFE_SB_ProcessCmdPipePkt(void) { default: CFE_EVS_SendEvent(CFE_SB_BAD_MSGID_EID,CFE_EVS_EventType_ERROR, - "Invalid Cmd, Unexpected Msg Id: 0x%04x", + "Invalid Cmd, Unexpected Msg Id: 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MessageID)); CFE_SB.HKTlmMsg.Payload.CommandErrorCounter++; break; diff --git a/fsw/cfe-core/src/sb/cfe_sb_util.c b/fsw/cfe-core/src/sb/cfe_sb_util.c index aa7303b4a..582dc4b8b 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_util.c +++ b/fsw/cfe-core/src/sb/cfe_sb_util.c @@ -143,6 +143,7 @@ void CFE_SB_SetUserDataLength(CFE_MSG_Message_t *MsgPtr, uint16 DataLength) }/* end CFE_SB_SetUserDataLength */ +#ifndef CFE_OMIT_DEPRECATED_6_8 /* * Function: CFE_SB_GetTotalMsgLength - See API and header file for details */ @@ -157,7 +158,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr) return (uint16)size; }/* end CFE_SB_GetTotalMsgLength */ - +#endif /* CFE_OMIT_DEPRECATED_6_8 */ /* * Function: CFE_SB_SetTotalMsgLength - See API and header file for details diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_task.c b/fsw/cfe-core/src/tbl/cfe_tbl_task.c index 0c048c36e..828796f95 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_task.c +++ b/fsw/cfe-core/src/tbl/cfe_tbl_task.c @@ -260,12 +260,15 @@ void CFE_TBL_InitData(void) void CFE_TBL_TaskPipe(CFE_MSG_Message_t *MessagePtr) { - CFE_SB_MsgId_t MessageID = CFE_SB_GetMsgId(MessagePtr); - uint16 CommandCode = CFE_SB_GetCmdCode(MessagePtr); + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t CommandCode = 0; int16 CmdIndx; - uint32 ActualLength; + CFE_MSG_Size_t ActualLength = 0; CFE_TBL_CmdProcRet_t CmdStatus = CFE_TBL_INC_ERR_CTR; /* Assume a failed command */ + CFE_MSG_GetMsgId(MessagePtr, &MessageID); + CFE_MSG_GetFcnCode(MessagePtr, &CommandCode); + /* Search the Command Handler Table for a matching message */ CmdIndx = CFE_TBL_SearchCmdHndlrTbl(MessageID, CommandCode); @@ -273,7 +276,7 @@ void CFE_TBL_TaskPipe(CFE_MSG_Message_t *MessagePtr) if (CmdIndx >= 0) { /* Verify Message Length before processing */ - ActualLength = CFE_SB_GetTotalMsgLength(MessagePtr); + CFE_MSG_GetSize(MessagePtr, &ActualLength); if (ActualLength == CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength) { /* All checks have passed, call the appropriate message handler */ @@ -282,10 +285,10 @@ void CFE_TBL_TaskPipe(CFE_MSG_Message_t *MessagePtr) else /* Bad Message Length */ { CFE_EVS_SendEvent( CFE_TBL_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length -- ID = 0x%04X, CC = %d, Len = %d (!= %d)", + "Invalid msg length -- ID = 0x%X, CC = %u, Len = %u, Expected = %u", (unsigned int)CFE_SB_MsgIdToValue(MessageID), - (int)CommandCode, (int)ActualLength, - (int)CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength ); + (unsigned int)CommandCode, (unsigned int)ActualLength, + (unsigned int)CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength ); } /* Only update command counters when message has a command code */ @@ -308,9 +311,9 @@ void CFE_TBL_TaskPipe(CFE_MSG_Message_t *MessagePtr) if (CmdIndx == CFE_TBL_BAD_CMD_CODE) { CFE_EVS_SendEvent(CFE_TBL_CC1_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid command code -- ID = 0x%04X, CC = %d", + "Invalid command code -- ID = 0x%X, CC = %u", (unsigned int)CFE_SB_MsgIdToValue(MessageID), - (int)CommandCode); + (unsigned int)CommandCode); /* Update the command error counter */ CFE_TBL_TaskData.CommandErrorCounter++; @@ -318,7 +321,7 @@ void CFE_TBL_TaskPipe(CFE_MSG_Message_t *MessagePtr) else /* CmdIndx == CFE_TBL_BAD_MSG_ID */ { CFE_EVS_SendEvent(CFE_TBL_MID_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid message ID -- ID = 0x%04X", + "Invalid message ID -- ID = 0x%X", (unsigned int)CFE_SB_MsgIdToValue(MessageID)); /* ** Note: we only increment the command error counter when diff --git a/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.h b/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.h index c2f4f1aeb..dbbcb7c8d 100644 --- a/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.h +++ b/fsw/cfe-core/src/tbl/cfe_tbl_task_cmds.h @@ -72,8 +72,8 @@ typedef enum */ typedef struct { CFE_SB_MsgId_t MsgId; /**< \brief Acceptable Message ID */ - uint32 CmdCode; /**< \brief Acceptable Command Code (if necessary) */ - uint32 ExpectedLength; /**< \brief Expected Message Length (in bytes) including message header */ + CFE_MSG_FcnCode_t CmdCode; /**< \brief Acceptable Command Code (if necessary) */ + CFE_MSG_Size_t ExpectedLength; /**< \brief Expected Message Length (in bytes) including message header */ CFE_TBL_MsgProcFuncPtr_t MsgProcFuncPtr; /**< \brief Pointer to function to handle message */ CFE_TBL_MsgType_t MsgTypes; /**< \brief Message Type (i.e. - with/without Cmd Code) */ } CFE_TBL_CmdHandlerTblRec_t; diff --git a/fsw/cfe-core/src/time/cfe_time_task.c b/fsw/cfe-core/src/time/cfe_time_task.c index 18be17e47..bc047dce4 100644 --- a/fsw/cfe-core/src/time/cfe_time_task.c +++ b/fsw/cfe-core/src/time/cfe_time_task.c @@ -427,23 +427,27 @@ int32 CFE_TIME_TaskInit(void) ** Return: ** true if length is acceptable */ -bool CFE_TIME_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, uint16 ExpectedLength) +bool CFE_TIME_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_TIME_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_TIME_TaskData.CommandErrorCounter; } diff --git a/fsw/cfe-core/unit-test/es_UT.c b/fsw/cfe-core/unit-test/es_UT.c index f14abfdc6..d8f68ed04 100644 --- a/fsw/cfe-core/unit-test/es_UT.c +++ b/fsw/cfe-core/unit-test/es_UT.c @@ -2653,6 +2653,7 @@ void TestTask(void) CFE_ES_TaskRecord_t *UtTaskRecPtr; CFE_ES_CDS_RegRec_t *UtCDSRegRecPtr; CFE_ES_MemPoolRecord_t *UtPoolRecPtr; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; UtPrintf("Begin Test Task"); @@ -2668,6 +2669,9 @@ void TestTask(void) ES_ResetUnitTest(); /* this is needed so CFE_ES_GetAppId works */ ES_UT_SetupSingleAppId(CFE_ES_AppType_CORE, CFE_ES_AppState_RUNNING, NULL, NULL, NULL); + + /* Set up buffer for first cycle, pipe failure is on 2nd */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &MsgId, sizeof(MsgId), false); CFE_ES_TaskMain(); UT_Report(__FILE__, __LINE__, UT_PrintfIsInHistory(UT_OSP_MESSAGES[UT_OSP_COMMAND_PIPE]), diff --git a/fsw/cfe-core/unit-test/evs_UT.c b/fsw/cfe-core/unit-test/evs_UT.c index 91bd280a4..ba8e5a167 100644 --- a/fsw/cfe-core/unit-test/evs_UT.c +++ b/fsw/cfe-core/unit-test/evs_UT.c @@ -299,6 +299,7 @@ void Test_Init(void) { CFE_EVS_BitMaskCmd_t bitmaskcmd; CFE_EVS_AppNameBitMaskCmd_t appbitcmd; + CFE_SB_MsgId_t msgid = CFE_SB_INVALID_MSG_ID; UtPrintf("Begin Test Init"); @@ -323,7 +324,7 @@ void Test_Init(void) UT_InitData(); /* Set unexpected message ID */ - UT_SetDeferredRetcode(UT_KEY(CFE_SB_GetMsgId), 1, 0); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &msgid, sizeof(msgid), false); UT_EVS_DoGenericCheckEvents(CFE_EVS_TaskMain, &UT_EVS_EventBuf); ASSERT_TRUE(UT_SyslogIsInHistory(EVS_SYSLOG_MSGS[8])); diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 26de27841..11bca67a3 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -3589,7 +3589,6 @@ void Test_SB_Utils(void) SB_UT_ADD_SUBTEST(Test_CFE_SB_GetUserData); SB_UT_ADD_SUBTEST(Test_CFE_SB_SetGetMsgId); SB_UT_ADD_SUBTEST(Test_CFE_SB_SetGetUserDataLength); - SB_UT_ADD_SUBTEST(Test_CFE_SB_SetGetTotalMsgLength); SB_UT_ADD_SUBTEST(Test_CFE_SB_SetGetMsgTime); SB_UT_ADD_SUBTEST(Test_CFE_SB_SetGetCmdCode); SB_UT_ADD_SUBTEST(Test_CFE_SB_ChecksumUtils); @@ -3693,22 +3692,6 @@ void Test_CFE_SB_SetGetUserDataLength(void) } /* end Util_CFE_SB_SetGetUserDataLength */ -/* -** Test setting and getting the total message size -*/ -void Test_CFE_SB_SetGetTotalMsgLength(void) -{ - CFE_MSG_Message_t msg; - CFE_MSG_Size_t size = 6; - - UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &size, sizeof(size), false); - - /* Pass through functions */ - ASSERT_EQ(CFE_SB_GetTotalMsgLength(&msg), size); - CFE_SB_SetTotalMsgLength(&msg, 0); - -} /* end Test_CFE_SB_SetGetTotalMsgLength */ - void Test_CFE_SB_SetGetMsgTime(void) { CFE_MSG_Message_t msg; diff --git a/fsw/cfe-core/unit-test/sb_UT.h b/fsw/cfe-core/unit-test/sb_UT.h index 011bde253..50b272a7f 100644 --- a/fsw/cfe-core/unit-test/sb_UT.h +++ b/fsw/cfe-core/unit-test/sb_UT.h @@ -3016,7 +3016,7 @@ void Test_CleanupApp_API(void); ** ** \sa #Test_CFE_SB_MsgHdrSize, ** \sa #Test_CFE_SB_GetUserData, #Test_CFE_SB_SetGetMsgId, -** \sa #Test_CFE_SB_SetGetUserDataLength, #Test_CFE_SB_SetGetTotalMsgLength, +** \sa #Test_CFE_SB_SetGetUserDataLength, ** \sa #Test_CFE_SB_SetGetMsgTime, ** \sa #Test_CFE_SB_SetGetCmdCode, #Test_CFE_SB_ChecksumUtils ** diff --git a/fsw/cfe-core/unit-test/ut_support.c b/fsw/cfe-core/unit-test/ut_support.c index f2659b9ee..15e0681eb 100644 --- a/fsw/cfe-core/unit-test/ut_support.c +++ b/fsw/cfe-core/unit-test/ut_support.c @@ -218,15 +218,17 @@ void UT_Report(const char *file, uint32 line, bool test, const char *fun_name, void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_MSG_Message_t *), CFE_MSG_Message_t *MsgPtr, uint32 MsgSize, UT_TaskPipeDispatchId_t DispatchId) { - /* - * set the fields within the buffer itself. - * a lot of the CFE code requires this as it uses - * macros (not stubs) to read this info direct from - * the buffer. - */ - CFE_SB_SetTotalMsgLength(MsgPtr, MsgSize); - CFE_SB_SetMsgId(MsgPtr, DispatchId.MsgId); - CFE_SB_SetCmdCode(MsgPtr, DispatchId.CommandCode); + /* Set up for the typical task pipe related calls */ + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &DispatchId.MsgId, sizeof(DispatchId.MsgId), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &MsgSize, sizeof(MsgSize), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &DispatchId.CommandCode, sizeof(DispatchId.CommandCode), false); + + /* If 0 size passed in, set buffers for calls in the command length failure reporting */ + if (MsgSize == 0) + { + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetMsgId), &DispatchId.MsgId, sizeof(DispatchId.MsgId), false); + UT_SetDataBuffer(UT_KEY(CFE_MSG_GetFcnCode), &DispatchId.CommandCode, sizeof(DispatchId.CommandCode), false); + } /* * Finally, call the actual task pipe requested. diff --git a/fsw/cfe-core/unit-test/ut_support.h b/fsw/cfe-core/unit-test/ut_support.h index fca0130cc..176adf767 100644 --- a/fsw/cfe-core/unit-test/ut_support.h +++ b/fsw/cfe-core/unit-test/ut_support.h @@ -142,7 +142,7 @@ typedef struct * (ignored if the handler does not use command codes, * set to zero in this case). */ - uint16 CommandCode; + CFE_MSG_FcnCode_t CommandCode; } UT_TaskPipeDispatchId_t; diff --git a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c index 5c16fe9e1..41870c883 100644 --- a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c @@ -716,6 +716,7 @@ void CFE_SB_TimeStampMsg(CFE_MSG_Message_t *MsgPtr) UT_Stub_CopyFromLocal(UT_KEY(CFE_SB_TimeStampMsg), &MsgPtr, sizeof(MsgPtr)); } +#ifndef CFE_OMIT_DEPRECATED_6_8 /*****************************************************************************/ /** ** \brief CFE_SB_GetTotalMsgLength stub function @@ -751,6 +752,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_MSG_Message_t *MsgPtr) } return result; } +#endif /* CFE_OMIT_DEPRECATED_6_8 */ /*****************************************************************************/ /**