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..ba6c6bf9d --- /dev/null +++ b/fsw/cfe-core/src/inc/cfe_msg.h @@ -0,0 +1,168 @@ +/* +** 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 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. +** +** \sa #CFE_SB_ValidateChecksum, #CFE_SB_GetChecksum +**/ +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. +** +** \sa #CFE_SB_GenerateChecksum, #CFE_SB_GetChecksum +**/ +bool CFE_MSG_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr); +/**@}*/ + +/** @defgropu CFEAPIMSGCmdCode cFE 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. +** +** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_GetTotalMsgLength, +** #CFE_SB_GetMsgTime, #CFE_SB_SetCmdCode, #CFE_SB_GetChecksum +**/ +uint16 CFE_MSG_GetCmdCode(CFE_SB_MsgPtr_t MsgPtr); + +/**@}*/ + +#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..7cabd7b2e --- /dev/null +++ b/fsw/cfe-core/src/msg/CMakeLists.txt @@ -0,0 +1,21 @@ +################################################################## +# +# 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 + 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..ea234a874 --- /dev/null +++ b/fsw/cfe-core/src/msg/cfe_msg_time.c @@ -0,0 +1,23 @@ +//TODO add header +#include "cfe_sb.h" + +/* + * Function: CFE_SB_SetMsgTime - See API and header file for details + */ +int32 CFE_SB_SetMsgTime(CFE_SB_MsgPtr_t MsgPtr, CFE_TIME_SysTime_t NewTime) +{ + //TODO implement + return CFE_SUCCESS; +} + +/* + * Function: CFE_SB_GetMsgTime - See API and header file for details + */ +CFE_TIME_SysTime_t CFE_SB_GetMsgTime(CFE_SB_MsgPtr_t MsgPtr) +{ + CFE_TIME_SysTime_t TimeFromMsg; + + //TODO implement + return TimeFromMsg; +} + diff --git a/fsw/cfe-core/src/sb/cfe_sb_util.c b/fsw/cfe-core/src/sb/cfe_sb_util.c index abef9d505..719d3dde1 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 @@ -309,17 +310,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 */ + return CFE_MSG_GetCmdCode(MsgPtr); - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; - - return CCSDS_RD_FC(CmdHdrPtr->Cmd.Sec); }/* end CFE_SB_GetCmdCode */ @@ -329,19 +322,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 +334,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 +345,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 +356,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 */