diff --git a/fsw/cfe-core/CMakeLists.txt b/fsw/cfe-core/CMakeLists.txt index d7337425e..83975b547 100644 --- a/fsw/cfe-core/CMakeLists.txt +++ b/fsw/cfe-core/CMakeLists.txt @@ -31,10 +31,18 @@ add_definitions(-D_CFE_CORE_) set(CFE_CORE_MODULES es sb evs tbl time fs) set(CFE_ALL_MODULE_SRCS) +if (NOT MISSION_CORE_MODULES) + set(MISSION_CORE_MODULES ${cfe-core_MISSION_DIR}/src/msg) +endif (NOT MISSION_CORE_MODULES) + foreach(MODULE ${CFE_CORE_MODULES} config shared) aux_source_directory(src/${MODULE} CFE_ALL_MODULE_SRCS) endforeach(MODULE ${CFE_CORE_MODULES}) +foreach(MODULE ${MISSION_CORE_MODULES}) + add_subdirectory(${MODULE} ${CFE_CORE_TARGET}) +endforeach(MODULE ${MISSION_CORE_MODULES}) + add_library(${CFE_CORE_TARGET} STATIC ${CFE_ALL_MODULE_SRCS}) if (ENABLE_UNIT_TESTS) diff --git a/fsw/cfe-core/src/inc/cfe_msg.h b/fsw/cfe-core/src/inc/cfe_msg.h new file mode 100644 index 000000000..965d68380 --- /dev/null +++ b/fsw/cfe-core/src/inc/cfe_msg.h @@ -0,0 +1,220 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/****************************************************************************** + * Message access APIs + */ + +#ifndef _cfe_msg_ +#define _cfe_msg_ + +/* + * Includes + */ +#include "common_types.h" +#include "cfe_mission_cfg.h" +#include "cfe_sb.h" + +/** @defgroup CFEAPIMSGChecksum cFE Message Checksum Control APIs + * @{ + */ + +/*****************************************************************************/ +/** +** \brief Gets the checksum field from a software bus message. +** +** \par Description +** This routine gets the checksum (or other message integrity check +** value) from a software bus message. The contents and location of +** this field will depend on the underlying implementation of software +** bus messages. It may be a checksum, a CRC, or some other algorithm. +** Users should not call this function as part of a message integrity +** check (call #CFE_SB_ValidateChecksum instead). +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a checksum field, then this routine will return a zero. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** +** \return The checksum included in the software bus message header (if present), otherwise, +** returns a checksum value of zero. +**/ +uint16 CFE_MSG_GetChecksum(CFE_SB_MsgPtr_t MsgPtr); + +/*****************************************************************************/ +/** +** \brief Calculates and sets the checksum of a software bus message +** +** \par Description +** This routine calculates the checksum of a software bus message according +** to an implementation-defined algorithm. Then, it sets the checksum field +** in the message with the calculated value. The contents and location of +** this field will depend on the underlying implementation of software bus +** messages. It may be a checksum, a CRC, or some other algorithm. +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a checksum field, then this routine will do nothing. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +**/ +void CFE_MSG_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr); + +/*****************************************************************************/ +/** +** \brief Validates the checksum of a software bus message. +** +** \par Description +** This routine calculates the expected checksum of a software bus message +** according to an implementation-defined algorithm. Then, it checks the +** calculated value against the value in the message's checksum. If the +** checksums do not match, this routine will generate an event message +** reporting the error. +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a checksum field, then this routine will always return \c true. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** +** \return Boolean checksum result +** \retval true The checksum field in the packet is valid. +** \retval false The checksum field in the packet is not valid or the message type is wrong. +**/ +bool CFE_MSG_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr); +/**@}*/ + +/** @defgropu CFEAPIMSGCmdCode cFE Message Command Code APIs + * @{ + */ + +/*****************************************************************************/ +/** +** \brief Sets the command code field in a software bus message. +** +** \par Description +** This routine sets the command code of a software bus message (if SB +** messages are implemented as CCSDS packets, this will be the function code). +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a command code field, then this routine will do nothing to +** the message contents and will return #CFE_SB_WRONG_MSG_TYPE. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** +** \param[in] CmdCode The command code to include in the message. +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_SB_WRONG_MSG_TYPE \copybrief CFE_SB_WRONG_MSG_TYPE +** +**/ +int32 CFE_MSG_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, + uint16 CmdCode); + +/*****************************************************************************/ +/** +** \brief Gets the command code field from a software bus message. +** +** \par Description +** This routine gets the command code from a software bus message (if +** SB messages are implemented as CCSDS packets, this will be the function +** code). +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a command code field, then this routine will return a zero. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** +** \return The command code included in the software bus message header (if present). +** Otherwise, returns a command code value of zero. +**/ +uint16 CFE_MSG_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr); + +/**@}*/ + +/** @defgropu CFEAPIMSGTime cFE Message Time APIs + * @{ + */ + +/*****************************************************************************/ +/** +** \brief Gets the time field from a software bus message. +** +** \par Description +** This routine gets the time from a software bus message. +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not +** include a time field, then this routine will return a zero time. +** - Note default implementation of command messages do not have a time field. +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** \param[out] Time Time from the message +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_SB_WRONG_MSG_TYPE \copybrief CFE_SB_WRONG_MSG_TYPE +**/ +int32 CFE_MSG_GetMsgTime(CFE_TIME_SysTime_t *Time, CFE_SB_MsgPtr_t MsgPtr); + +/*****************************************************************************/ +/** +** \brief Sets the time field in a software bus message. +** +** \par Description +** This routine sets the time of a software bus message. Most applications +** will want to use #CFE_SB_TimeStampMsg instead of this function. But, +** when needed, #CFE_SB_SetMsgTime can be used to send a group of SB messages +** with identical time stamps. +** +** \par Assumptions, External Events, and Notes: +** - If the underlying implementation of software bus messages does not include +** a time field, then this routine will do nothing to the message contents +** and will return #CFE_SB_WRONG_MSG_TYPE. +** - Note default implementation of command messages do not have a time field +** and will trigger the #CFE_SB_WRONG_MSG_TYPE error +** +** \param[in] MsgPtr A pointer to the buffer that contains the software bus message. +** This must point to the first byte of the message header. +** +** \param[in] Time The time to include in the message. This will usually be a time +** returned by the function #CFE_TIME_GetTime. +** +** \return Execution status, see \ref CFEReturnCodes +** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS +** \retval #CFE_SB_WRONG_MSG_TYPE \copybrief CFE_SB_WRONG_MSG_TYPE +**/ +int32 CFE_MSG_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, + CFE_TIME_SysTime_t Time); + +/**@}*/ + + +#endif /* _cfe_msg_ */ diff --git a/fsw/cfe-core/src/msg/CMakeLists.txt b/fsw/cfe-core/src/msg/CMakeLists.txt new file mode 100644 index 000000000..dbb801f28 --- /dev/null +++ b/fsw/cfe-core/src/msg/CMakeLists.txt @@ -0,0 +1,22 @@ +################################################################## +# +# cFE message module CMake build recipe +# +# This CMakeLists.txt adds source files for +# message module included in the cFE distribution. Selected +# files are built into a static library that in turn +# is linked into the final executable. +# +# Note this is different than applications which are dynamically +# linked to support runtime loading. The core applications all +# use static linkage. +# +################################################################## + +# Add the basic set of files which are always built +set(CFE_ALL_MODULE_SRCS ${CFE_ALL_MODULE_SRCS} + ${CMAKE_CURRENT_SOURCE_DIR}/cfe_msg_checksum.c + ${CMAKE_CURRENT_SOURCE_DIR}/cfe_msg_fc.c + ${CMAKE_CURRENT_SOURCE_DIR}/cfe_msg_time.c + PARENT_SCOPE +) diff --git a/fsw/cfe-core/src/msg/cfe_msg_checksum.c b/fsw/cfe-core/src/msg/cfe_msg_checksum.c new file mode 100644 index 000000000..847cb1bce --- /dev/null +++ b/fsw/cfe-core/src/msg/cfe_msg_checksum.c @@ -0,0 +1,77 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/****************************************************************************** + * Checksum field access functions + */ +#include "cfe_msg.h" +#include "cfe_sb.h" + +/****************************************************************************** + * Get checksum - See API and header file for details + */ +uint16 CFE_MSG_GetChecksum(CFE_SB_MsgPtr_t MsgPtr) +{ + CFE_SB_CmdHdr_t *CmdHdrPtr; + + /* if msg type is telemetry or there is no secondary hdr... */ + if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ + return 0; + }/* end if */ + + /* cast the input pointer to a Cmd Msg pointer */ + CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; + + return CCSDS_RD_CHECKSUM(CmdHdrPtr->Cmd.Sec); +} + +/****************************************************************************** + * Calculate and set checksum field - See API and header file for details + */ +void CFE_MSG_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr) +{ + CCSDS_CommandPacket_t *CmdPktPtr; + + /* if msg type is telemetry or there is no secondary hdr... */ + if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ + return; + }/* end if */ + + CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr; + + CCSDS_LoadCheckSum(CmdPktPtr); +} + +/****************************************************************************** + * Validate checksum - See API and header file for details + */ +bool CFE_MSG_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr) +{ + CCSDS_CommandPacket_t *CmdPktPtr; + + /* if msg type is telemetry or there is no secondary hdr... */ + if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ + return false; + }/* end if */ + + CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr; + + return CCSDS_ValidCheckSum (CmdPktPtr); +} diff --git a/fsw/cfe-core/src/msg/cfe_msg_fc.c b/fsw/cfe-core/src/msg/cfe_msg_fc.c new file mode 100644 index 000000000..88cc0795c --- /dev/null +++ b/fsw/cfe-core/src/msg/cfe_msg_fc.c @@ -0,0 +1,65 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/****************************************************************************** + * Command function code field access functions + */ +#include "cfe_msg.h" +#include "cfe_sb.h" +#include "cfe_error.h" + +/****************************************************************************** + * Get Command function code - See API and header file for details + */ +uint16 CFE_MSG_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr) +{ + CFE_SB_CmdHdr_t *CmdHdrPtr; + + /* if msg type is telemetry or there is no secondary hdr, return 0 */ + if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ + return 0; + }/* end if */ + + /* Cast the input pointer to a Cmd Msg pointer */ + CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; + + return CCSDS_RD_FC(CmdHdrPtr->Cmd.Sec); +} + +/****************************************************************************** + * Set Command function code - See API and header file for details + */ +int32 CFE_MSG_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, + uint16 CmdCode) +{ + CFE_SB_CmdHdr_t *CmdHdrPtr; + + /* if msg type is telemetry or there is no secondary hdr... */ + if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ + return CFE_SB_WRONG_MSG_TYPE; + }/* end if */ + + /* Cast the input pointer to a Cmd Msg pointer */ + CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; + + CCSDS_WR_FC(CmdHdrPtr->Cmd.Sec,CmdCode); + + return CFE_SUCCESS; +} diff --git a/fsw/cfe-core/src/msg/cfe_msg_time.c b/fsw/cfe-core/src/msg/cfe_msg_time.c new file mode 100644 index 000000000..17987c198 --- /dev/null +++ b/fsw/cfe-core/src/msg/cfe_msg_time.c @@ -0,0 +1,134 @@ +/* +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2019 United States Government as represented by +** the Administrator of the National Aeronautics and Space Administration. +** All Rights Reserved. +** +** Licensed under the Apache License, Version 2.0 (the "License"); +** you may not use this file except in compliance with the License. +** You may obtain a copy of the License at +** +** http://www.apache.org/licenses/LICENSE-2.0 +** +** Unless required by applicable law or agreed to in writing, software +** distributed under the License is distributed on an "AS IS" BASIS, +** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +** See the License for the specific language governing permissions and +** limitations under the License. +*/ + +/****************************************************************************** + * Time field access functions + */ +#include "cfe_sb.h" +#include "cfe_msg.h" +#include "cfe_error.h" +#include + +/****************************************************************************** + * Set message time - See API and header file for details + */ +int32 CFE_MSG_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t NewTime) +{ + + int32 Result = CFE_SB_WRONG_MSG_TYPE; + + CFE_SB_TlmHdr_t *TlmHdrPtr; + + /* declare format specific vars */ + #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + uint16 LocalSubs16; + #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) + uint32 LocalSubs32; + #endif + + /* cannot set time if msg type is a command or msg has no secondary hdr */ + if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) { + + /* copy time data to/from packets to eliminate alignment issues */ + TlmHdrPtr = (CFE_SB_TlmHdr_t *) MsgPtr; + + #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + + /* convert time from CFE_TIME_SysTime_t format to packet format */ + LocalSubs16 = (uint16) (NewTime.Subseconds >> 16); + memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); + memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &LocalSubs16, 2); + Result = CFE_SUCCESS; + + #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) + + /* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */ + memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); + memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &NewTime.Subseconds, 4); + Result = CFE_SUCCESS; + + #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) + + /* convert time from CFE_TIME_SysTime_t format to packet format */ + LocalSubs32 = CFE_TIME_Sub2MicroSecs(NewTime.Subseconds) << 12; + memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); + memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &LocalSubs32, 4); + Result = CFE_SUCCESS; + + #endif + } + + return Result; +} + +/****************************************************************************** + * Get message time - See API and header file for details + */ +int32 CFE_MSG_GetMsgTime(CFE_TIME_SysTime_t *Time, CFE_SB_MsgPtr_t MsgPtr) +{ + + int32 status = CFE_SB_WRONG_MSG_TYPE; + uint32 LocalSecs32 = 0; + uint32 LocalSubs32 = 0; + + #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + uint16 LocalSubs16; + #endif + + CFE_SB_TlmHdr_t *TlmHdrPtr; + + /* if msg type is a command or msg has no secondary hdr, time = 0 */ + if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) { + + /* copy time data to/from packets to eliminate alignment issues */ + TlmHdrPtr = (CFE_SB_TlmHdr_t *)MsgPtr; + + #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + + memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); + memcpy(&LocalSubs16, &TlmHdrPtr->Tlm.Sec.Time[4], 2); + /* convert packet data into CFE_TIME_SysTime_t format */ + LocalSubs32 = ((uint32) LocalSubs16) << 16; + + #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) + + memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); + memcpy(&LocalSubs32, &TlmHdrPtr->Tlm.Sec.Time[4], 4); + /* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */ + + #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) + + memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); + memcpy(&LocalSubs32, &TlmHdrPtr->Tlm.Sec.Time[4], 4); + /* convert packet data into CFE_TIME_SysTime_t format */ + LocalSubs32 = CFE_TIME_Micro2SubSecs((LocalSubs32 >> 12)); + + #endif + + status = CFE_SUCCESS; + } + + /* return the packet time converted to CFE_TIME_SysTime_t format */ + Time->Seconds = LocalSecs32; + Time->Subseconds = LocalSubs32; + + return status; + +} diff --git a/fsw/cfe-core/src/sb/cfe_sb_util.c b/fsw/cfe-core/src/sb/cfe_sb_util.c index abef9d505..8ec1d1dc1 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_util.c +++ b/fsw/cfe-core/src/sb/cfe_sb_util.c @@ -38,6 +38,7 @@ #include "ccsds.h" #include "osapi.h" #include "cfe_error.h" +#include "cfe_msg.h" #include @@ -194,47 +195,8 @@ void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength) CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr) { CFE_TIME_SysTime_t TimeFromMsg; - uint32 LocalSecs32 = 0; - uint32 LocalSubs32 = 0; - #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - uint16 LocalSubs16; - #endif - - CFE_SB_TlmHdr_t *TlmHdrPtr; - - /* if msg type is a command or msg has no secondary hdr, time = 0 */ - if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) { - - /* copy time data to/from packets to eliminate alignment issues */ - TlmHdrPtr = (CFE_SB_TlmHdr_t *)MsgPtr; - - #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - - memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); - memcpy(&LocalSubs16, &TlmHdrPtr->Tlm.Sec.Time[4], 2); - /* convert packet data into CFE_TIME_SysTime_t format */ - LocalSubs32 = ((uint32) LocalSubs16) << 16; - - #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) - - memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); - memcpy(&LocalSubs32, &TlmHdrPtr->Tlm.Sec.Time[4], 4); - /* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */ - - #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) - - memcpy(&LocalSecs32, &TlmHdrPtr->Tlm.Sec.Time[0], 4); - memcpy(&LocalSubs32, &TlmHdrPtr->Tlm.Sec.Time[4], 4); - /* convert packet data into CFE_TIME_SysTime_t format */ - LocalSubs32 = CFE_TIME_Micro2SubSecs((LocalSubs32 >> 12)); - - #endif - } - - /* return the packet time converted to CFE_TIME_SysTime_t format */ - TimeFromMsg.Seconds = LocalSecs32; - TimeFromMsg.Subseconds = LocalSubs32; + CFE_MSG_GetMsgTime(&TimeFromMsg, MsgPtr); return TimeFromMsg; @@ -246,50 +208,8 @@ CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr) */ int32 CFE_SB_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t NewTime) { - int32 Result = CFE_SB_WRONG_MSG_TYPE; - - CFE_SB_TlmHdr_t *TlmHdrPtr; - - /* declare format specific vars */ - #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - uint16 LocalSubs16; - #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) - uint32 LocalSubs32; - #endif - - /* cannot set time if msg type is a command or msg has no secondary hdr */ - if ((CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_CMD) && (CCSDS_RD_SHDR(MsgPtr->Hdr) != 0)) { - - /* copy time data to/from packets to eliminate alignment issues */ - TlmHdrPtr = (CFE_SB_TlmHdr_t *) MsgPtr; - - #if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - - /* convert time from CFE_TIME_SysTime_t format to packet format */ - LocalSubs16 = (uint16) (NewTime.Subseconds >> 16); - memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); - memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &LocalSubs16, 2); - Result = CFE_SUCCESS; - - #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) - /* no conversion necessary -- packet format = CFE_TIME_SysTime_t format */ - memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); - memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &NewTime.Subseconds, 4); - Result = CFE_SUCCESS; - - #elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) - - /* convert time from CFE_TIME_SysTime_t format to packet format */ - LocalSubs32 = CFE_TIME_Sub2MicroSecs(NewTime.Subseconds) << 12; - memcpy(&TlmHdrPtr->Tlm.Sec.Time[0], &NewTime.Seconds, 4); - memcpy(&TlmHdrPtr->Tlm.Sec.Time[4], &LocalSubs32, 4); - Result = CFE_SUCCESS; - - #endif - } - - return Result; + return CFE_MSG_SetMsgTime(MsgPtr, NewTime); }/* end CFE_SB_SetMsgTime */ @@ -309,17 +229,9 @@ void CFE_SB_TimeStampMsg(CFE_SB_MsgPtr_t MsgPtr) */ uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr) { - CFE_SB_CmdHdr_t *CmdHdrPtr; - - /* if msg type is telemetry or there is no secondary hdr, return 0 */ - if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ - return 0; - }/* end if */ - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; + return CFE_MSG_GetCmdCode(MsgPtr); - return CCSDS_RD_FC(CmdHdrPtr->Cmd.Sec); }/* end CFE_SB_GetCmdCode */ @@ -329,19 +241,8 @@ uint16 CFE_SB_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr) int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CmdCode) { - CFE_SB_CmdHdr_t *CmdHdrPtr; - - /* if msg type is telemetry or there is no secondary hdr... */ - if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ - return CFE_SB_WRONG_MSG_TYPE; - }/* end if */ - - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; - - CCSDS_WR_FC(CmdHdrPtr->Cmd.Sec,CmdCode); - return CFE_SUCCESS; + return CFE_MSG_SetCmdCode(MsgPtr, CmdCode); }/* end CFE_SB_SetCmdCode */ @@ -352,17 +253,7 @@ int32 CFE_SB_SetCmdCode(CFE_SB_MsgPtr_t MsgPtr, uint16 CFE_SB_GetChecksum(CFE_SB_MsgPtr_t MsgPtr) { - CFE_SB_CmdHdr_t *CmdHdrPtr; - - /* if msg type is telemetry or there is no secondary hdr... */ - if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ - return 0; - }/* end if */ - - /* cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; - - return CCSDS_RD_CHECKSUM(CmdHdrPtr->Cmd.Sec); + return CFE_MSG_GetChecksum(MsgPtr); }/* end CFE_SB_GetChecksum */ @@ -373,16 +264,7 @@ uint16 CFE_SB_GetChecksum(CFE_SB_MsgPtr_t MsgPtr) void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr) { - CCSDS_CommandPacket_t *CmdPktPtr; - - /* if msg type is telemetry or there is no secondary hdr... */ - if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ - return; - }/* end if */ - - CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr; - - CCSDS_LoadCheckSum(CmdPktPtr); + CFE_MSG_GenerateChecksum(MsgPtr); }/* end CFE_SB_GenerateChecksum */ @@ -393,16 +275,7 @@ void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr) bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr) { - CCSDS_CommandPacket_t *CmdPktPtr; - - /* if msg type is telemetry or there is no secondary hdr... */ - if((CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_TLM)||(CCSDS_RD_SHDR(MsgPtr->Hdr) == 0)){ - return false; - }/* end if */ - - CmdPktPtr = (CCSDS_CommandPacket_t *)MsgPtr; - - return CCSDS_ValidCheckSum (CmdPktPtr); + return CFE_MSG_ValidateChecksum(MsgPtr); }/* end CFE_SB_ValidateChecksum */