From d3a073e90cbb6f8529f468c751b144138973bb26 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:31:40 -0400 Subject: [PATCH 1/4] Fix #711, Add message header module Implements message header module such that users can customize or extend as needed. - Separates code for easier selection - Implements consistent getter/setter APIs - Fix #736/#781: MsgId logic no longer overrides bits in init - Fix #529: Get size supports max size - Adds single big endian time implementation, but not selected - Adds msg module to module list - Adds msg module to cppcheck --- .travis.yml | 4 +- cmake/mission_defaults.cmake | 1 + fsw/cfe-core/src/inc/cfe_msg_api.h | 665 ++++++++++++++++++ fsw/cfe-core/src/inc/cfe_msg_typedefs.h | 90 +++ modules/msg/CMakeLists.txt | 62 ++ modules/msg/mission_build.cmake | 27 + .../msg/mission_inc/default_cfe_msg_hdr_pri.h | 89 +++ .../mission_inc/default_cfe_msg_hdr_priext.h | 90 +++ .../msg/mission_inc/default_cfe_msg_sechdr.h | 93 +++ modules/msg/private_inc/cfe_msg_defaults.h | 84 +++ modules/msg/private_inc/cfe_msg_priv.h | 81 +++ modules/msg/src/cfe_msg_ccsdsext.c | 250 +++++++ modules/msg/src/cfe_msg_ccsdspri.c | 352 +++++++++ modules/msg/src/cfe_msg_init.c | 57 ++ modules/msg/src/cfe_msg_initdefaulthdr_pri.c | 34 + .../msg/src/cfe_msg_initdefaulthdr_priext.c | 35 + modules/msg/src/cfe_msg_msgid_shared.c | 46 ++ modules/msg/src/cfe_msg_msgid_v1.c | 71 ++ modules/msg/src/cfe_msg_msgid_v2.c | 111 +++ modules/msg/src/cfe_msg_sechdr_checksum.c | 116 +++ modules/msg/src/cfe_msg_sechdr_fc.c | 88 +++ modules/msg/src/cfe_msg_sechdr_time.c | 97 +++ modules/msg/src/cfe_msg_sechdr_time_old.c | 137 ++++ 23 files changed, 2678 insertions(+), 2 deletions(-) create mode 100644 fsw/cfe-core/src/inc/cfe_msg_api.h create mode 100644 fsw/cfe-core/src/inc/cfe_msg_typedefs.h create mode 100644 modules/msg/CMakeLists.txt create mode 100644 modules/msg/mission_build.cmake create mode 100644 modules/msg/mission_inc/default_cfe_msg_hdr_pri.h create mode 100644 modules/msg/mission_inc/default_cfe_msg_hdr_priext.h create mode 100644 modules/msg/mission_inc/default_cfe_msg_sechdr.h create mode 100644 modules/msg/private_inc/cfe_msg_defaults.h create mode 100644 modules/msg/private_inc/cfe_msg_priv.h create mode 100644 modules/msg/src/cfe_msg_ccsdsext.c create mode 100644 modules/msg/src/cfe_msg_ccsdspri.c create mode 100644 modules/msg/src/cfe_msg_init.c create mode 100644 modules/msg/src/cfe_msg_initdefaulthdr_pri.c create mode 100644 modules/msg/src/cfe_msg_initdefaulthdr_priext.c create mode 100644 modules/msg/src/cfe_msg_msgid_shared.c create mode 100644 modules/msg/src/cfe_msg_msgid_v1.c create mode 100644 modules/msg/src/cfe_msg_msgid_v2.c create mode 100644 modules/msg/src/cfe_msg_sechdr_checksum.c create mode 100644 modules/msg/src/cfe_msg_sechdr_fc.c create mode 100644 modules/msg/src/cfe_msg_sechdr_time.c create mode 100644 modules/msg/src/cfe_msg_sechdr_time_old.c diff --git a/.travis.yml b/.travis.yml index 0616343b8..8b098f179 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,8 +17,8 @@ script: # Check versions - cppcheck --version - #cppcheck flight software cfe/fsw/cfe-core/src - - cppcheck --force --inline-suppr --std=c99 --language=c --error-exitcode=1 --enable=warning,performance,portability,style --suppress=variableScope --inconclusive fsw/cfe-core/src 2>cppcheck_flight_cfe.txt + #cppcheck flight software fsw/cfe-core/src and modules + - cppcheck --force --inline-suppr --std=c99 --language=c --error-exitcode=1 --enable=warning,performance,portability,style --suppress=variableScope --inconclusive fsw/cfe-core/src modules 2>cppcheck_flight_cfe.txt - | if [[ -s cppcheck_flight_cfe.txt ]]; then echo "You must fix cppcheck errors before submitting a pull request" diff --git a/cmake/mission_defaults.cmake b/cmake/mission_defaults.cmake index 8f49d54d5..79d1fb1bd 100644 --- a/cmake/mission_defaults.cmake +++ b/cmake/mission_defaults.cmake @@ -14,6 +14,7 @@ set(MISSION_CORE_MODULES "cfe-core" "osal" "psp" + "msg" ) # The "MISSION_GLOBAL_APPLIST" is a set of apps/libs that will be built diff --git a/fsw/cfe-core/src/inc/cfe_msg_api.h b/fsw/cfe-core/src/inc/cfe_msg_api.h new file mode 100644 index 000000000..7584b1f76 --- /dev/null +++ b/fsw/cfe-core/src/inc/cfe_msg_api.h @@ -0,0 +1,665 @@ +/* +** 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_api_ +#define _cfe_msg_api_ + +/* + * Includes + */ +#include "common_types.h" +#include "cfe_msg_hdr.h" +#include "cfe_msg_typedefs.h" +#include "cfe_time.h" +#include "cfe_sb.h" + +/** \defgroup CFEAPIMSGHeader cFE Message header APIs + * \{ + */ + +/*****************************************************************************/ +/** + * \brief Initialize a message + * + * \par Description + * This routine initialize a message. If Clear is true the + * message is cleard and constant header defaults are set. + * The bits from MsgId and message size are always set. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] MsgId MsgId that corresponds to message + * \param[in] Size Total size of the mesage (used to set length field) + * \param[in] Clear Boolean to clear and set defaults + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_Init(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_MSG_Size_t Size, bool Clear); + +/*****************************************************************************/ +/** + * \brief Gets the total size of a message. + * + * \par Description + * This routine gets the total size of the message. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Size Total message size + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetSize(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t *Size); + +/*****************************************************************************/ +/** + * \brief Sets the total size of a message. + * + * \par Description + * This routine sets the total size of the message. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Size Total message size + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetSize(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size); + +/*****************************************************************************/ +/** + * \brief Gets the message type. + * + * \par Description + * This routine gets the message type. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Type Message type + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetType(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t *Type); + +/*****************************************************************************/ +/** + * \brief Sets the message type. + * + * \par Description + * This routine sets the message type. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Type Message type + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetType(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t Type); + +/*****************************************************************************/ +/** + * \brief Gets the message header version. + * + * \par Description + * This routine gets the message header version. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Version Header version + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetHeaderVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_HeaderVersion_t *Version); + +/*****************************************************************************/ +/** + * \brief Sets the message header version. + * + * \par Description + * This routine sets the message header version. Typically only + * set within message initialization and not used by APPs. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Version Header version + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetHeaderVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_HeaderVersion_t Version); + +/*****************************************************************************/ +/** + * \brief Gets the message secondary header boolean + * + * \par Description + * This routine gets the message secondary header boolean. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] HasSecondary Has secondary header flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetHasSecondaryHeader(const CFE_MSG_Message_t *MsgPtr, bool *HasSecondary); + +/*****************************************************************************/ +/** + * \brief Sets the message secondary header boolean + * + * \par Description + * This routine sets the message has secondary header boolean. Typically only + * set within message initialization and not used by APPs. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] HasSecondary Has secondary header flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetHasSecondaryHeader(CFE_MSG_Message_t *MsgPtr, bool HasSecondary); + +/*****************************************************************************/ +/** + * \brief Gets the message application ID + * + * \par Description + * This routine gets the message application ID. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] ApId Application ID + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetApId(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_ApId_t *ApId); + +/*****************************************************************************/ +/** + * \brief Sets the message application ID + * + * \par Description + * This routine sets the message application ID. Typically set + * at initialization using the MsgId, but API available to set + * bits that may not be included in MsgId. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] ApId Application ID + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetApId(CFE_MSG_Message_t *MsgPtr, CFE_MSG_ApId_t ApId); + +/*****************************************************************************/ +/** + * \brief Gets the message segmentation flag + * + * \par Description + * This routine gets the message segmentation flag + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] SegFlag Segmentation flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetSegmentationFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_SegmentationFlag_t *SegFlag); + +/*****************************************************************************/ +/** + * \brief Sets the message segmentation flag + * + * \par Description + * This routine sets the message segmentation flag. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] SegFlag Segmentation flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetSegmentationFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SegmentationFlag_t SegFlag); + +/*****************************************************************************/ +/** + * \brief Gets the message sequence count + * + * \par Description + * This routine gets the message sequence count. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] SeqCnt Sequence count + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetSequenceCount(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t *SeqCnt); + +/*****************************************************************************/ +/** + * \brief Sets the message sequence count + * + * \par Description + * This routine sets the message sequence count. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] SeqCnt Sequence count + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetSequenceCount(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t SeqCnt); + +/*****************************************************************************/ +/** + * \brief Gets the message EDS version + * + * \par Description + * This routine gets the message EDS version. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Version EDS Version + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetEDSVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *Version); + +/*****************************************************************************/ +/** + * \brief Sets the message EDS version + * + * \par Description + * This routine sets the message EDS version. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Version EDS Version + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetEDSVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t Version); + +/*****************************************************************************/ +/** + * \brief Gets the message endian + * + * \par Description + * This routine gets the message endian. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Endian Endian + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetEndian(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t *Endian); + +/*****************************************************************************/ +/** + * \brief Sets the message endian + * + * \par Description + * This routine sets the message endian. Invalid endian selection + * will set big endian. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Endian Endian + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetEndian(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t Endian); + +/*****************************************************************************/ +/** + * \brief Gets the message playback flag + * + * \par Description + * This routine gets the message playback flag. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] PlayFlag Playback Flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetPlaybackFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t *PlayFlag); + +/*****************************************************************************/ +/** + * \brief Sets the message playback flag + * + * \par Description + * This routine sets the message playback flag. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] PlayFlag Playback Flag + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetPlaybackFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t PlayFlag); + +/*****************************************************************************/ +/** + * \brief Gets the message subsystem + * + * \par Description + * This routine gets the message subsystem + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Subsystem Subsystem + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetSubsystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t *Subsystem); + +/*****************************************************************************/ +/** + * \brief Sets the message subsystem + * + * \par Description + * This routine sets the message subsystem. Some bits may + * be set at initialization using the MsgId, but API available to set + * bits that may not be included in MsgId. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] Subsystem Subsystem + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetSubsystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t Subsystem); + +/*****************************************************************************/ +/** + * \brief Gets the message system + * + * \par Description + * This routine gets the message system id + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] System System + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetSystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t *System); + +/*****************************************************************************/ +/** + * \brief Sets the message system + * + * \par Description + * This routine sets the message system id. Some bits may + * be set at initialization using the MsgId, but API available to set + * bits that may not be included in MsgId. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] System System + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetSystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t System); + +/*****************************************************************************/ +/** + * \brief Calculates and sets the checksum of a message + * + * \par Description + * This routine calculates the checksum of a 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 + * messages. It may be a checksum, a CRC, or some other algorithm. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not + * include a checksum field, then this routine will return + * #CFE_MSG_WRONG_MSG_TYPE + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + */ +int32 CFE_MSG_GenerateChecksum(CFE_MSG_Message_t *MsgPtr); + +/*****************************************************************************/ +/** + * \brief Validates the checksum of a message. + * + * \par Description + * This routine validates the checksum of a message + * according to an implementation-defined algorithm. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not + * include a checksum field, then this routine will return + * #CFE_MSG_WRONG_MSG_TYPE and set the IsValid parameter false. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * This must point to the first byte of the message header. + * \param[out] IsValid Checksum validation result + * \arg true - valid + * \arg false - invalid or not supported/implemented + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + */ +int32 CFE_MSG_ValidateChecksum(const CFE_MSG_Message_t *MsgPtr, bool *IsValid); + +/*****************************************************************************/ +/** + * \brief Sets the function code field in a message. + * + * \par Description + * This routine sets the function code of a message. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not + * include a function code field, then this routine will do nothing to + * the message contents and will return #CFE_MSG_WRONG_MSG_TYPE. + * + * \param[in, out] MsgPtr A pointer to the buffer that contains the message. + * \param[in] FcnCode The function code to include in the message. + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + * + */ +int32 CFE_MSG_SetFcnCode(CFE_MSG_Message_t *MsgPtr, CFE_MSG_FcnCode_t FcnCode); + +/*****************************************************************************/ +/** + * \brief Gets the function code field from a message. + * + * \par Description + * This routine gets the function code from a message. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not + * include a function code field, then this routine will + * set FcnCode to zero and return #CFE_MSG_WRONG_MSG_TYPE + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] FcnCode The function code from the message + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + */ +int32 CFE_MSG_GetFcnCode(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_FcnCode_t *FcnCode); + +/*****************************************************************************/ +/** + * \brief Gets the time field from a message. + * + * \par Description + * This routine gets the time from a message. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not + * include a time field, then this routine will set Time + * to zero and return #CFE_MSG_WRONG_MSG_TYPE + * - Note default implementation of command messages do not have a time field. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] Time Time from the message + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + */ +int32 CFE_MSG_GetMsgTime(const CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t *Time); + +/*****************************************************************************/ +/** + * \brief Sets the time field in a message. + * + * \par Description + * This routine sets the time of a message. Most applications + * will want to use #CFE_SB_TimeStampMsg instead of this function. But, + * when needed, this API can be used to set multiple messages + * with identical time stamps. + * + * \par Assumptions, External Events, and Notes: + * - If the underlying implementation of messages does not include + * a time field, then this routine will do nothing to the message contents + * and will return #CFE_MSG_WRONG_MSG_TYPE. + * - Note default implementation of command messages do not have a time field. + * + * \param[in, out] MsgPtr A pointer to the message. + * \param[in] Time The time to include in the message. This will usually be a time + * from #CFE_TIME_GetTime. + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + * \retval #CFE_MSG_WRONG_MSG_TYPE \copybrief CFE_MSG_WRONG_MSG_TYPE + */ +int32 CFE_MSG_SetMsgTime(CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t Time); + +/**\}*/ + +/** \defgroup CFEAPIMSGMsgId cFE Message Id APIs + * \{ + */ + +/*****************************************************************************/ +/** + * \brief Gets the message id from a message. + * + * \par Description + * This routine gets the message id from a message. The message id + * is a hash of bits in the message header, used by the software bus for + * routing. Message id needs to be unique for each endpoint + * in the system. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] MsgId Message id + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetMsgId(const CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t *MsgId); + +/*****************************************************************************/ +/** + * \brief Sets the message id bits in a message. + * + * \par Description + * This routine sets the message id bits in a message. The message id + * is a hash of bits in the message header, used by the software bus for + * routing. Message id needs to be unique for each endpoint + * in the system. + * \par Note + * This API only sets the bits in the header that make up the message ID. + * No other values in the header are modified. + * + * \param[in] MsgPtr A pointer to the buffer that contains the message. + * \param[out] MsgId Message id + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_SetMsgId(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId); + +/*****************************************************************************/ +/** + * \brief Gets message type using message ID + * + * \par Description + * This routine gets the message type using the message ID + * + * \param[in] MsgId Message id + * \param[out] Type Message type + * + * \return Execution status, see \ref CFEReturnCodes + * \retval #CFE_SUCCESS \copybrief CFE_SUCCESS + * \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT + */ +int32 CFE_MSG_GetTypeFromMsgId(CFE_SB_MsgId_t MsgId, CFE_MSG_Type_t *Type); + +/**\}*/ + +#endif /* _cfe_msg_api_ */ diff --git a/fsw/cfe-core/src/inc/cfe_msg_typedefs.h b/fsw/cfe-core/src/inc/cfe_msg_typedefs.h new file mode 100644 index 000000000..0397d0fd7 --- /dev/null +++ b/fsw/cfe-core/src/inc/cfe_msg_typedefs.h @@ -0,0 +1,90 @@ +/* +** 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 type defines + * - Separate from API so these can be adjusted for custom implementations + */ + +#ifndef _cfe_msg_typedefs_ +#define _cfe_msg_typedefs_ + +/* + * Includes + */ +#include "common_types.h" +#include "cfe_error.h" + +/* + * Defines + */ +/* Error bits won't fit a new module so reuse SB error codes */ +#define CFE_MSG_BAD_ARGUMENT CFE_SB_BAD_ARGUMENT /**< \brief Error - bad argument */ +#define CFE_MSG_NOT_IMPLEMENTED CFE_SB_NOT_IMPLEMENTED /**< \brief Error - not implemented */ +#define CFE_MSG_WRONG_MSG_TYPE CFE_SB_WRONG_MSG_TYPE /**< \brief Error - wrong type */ + +/* + * Types + */ +typedef uint32 CFE_MSG_Size_t; /**< \brief Message size (CCSDS needs uint32 for max size) */ +typedef uint32 CFE_MSG_Checksum_t; /**< \brief Message checksum (Oversized to avoid redefine) */ +typedef uint16 CFE_MSG_FcnCode_t; /**< \brief Message function code */ +typedef uint16 CFE_MSG_HeaderVersion_t; /**< \brief Message header version */ +typedef uint16 CFE_MSG_ApId_t; /**< \brief Message application ID */ +typedef uint16 CFE_MSG_SequenceCount_t; /**< \brief Message sequence count */ +typedef uint16 CFE_MSG_EDSVersion_t; /**< \brief Message EDS version */ +typedef uint16 CFE_MSG_Subsystem_t; /**< \brief Message subsystem */ +typedef uint16 CFE_MSG_System_t; /**< \brief Message system */ + +/** \brief Message type */ +typedef enum +{ + CFE_MSG_Type_Invalid, /**< \brief Message type invalid, undefined, not implemented */ + CFE_MSG_Type_Cmd, /**< \brief Command message type */ + CFE_MSG_Type_Tlm /**< \brief Telemetry message type */ +} CFE_MSG_Type_t; + +/** \brief Segmentation flags */ +typedef enum +{ + CFE_MSG_SegFlag_Invalid, /**< \brief Invalid segmentation flag */ + CFE_MSG_SegFlag_Continue, /**< \brief Continuation segment of User Data */ + CFE_MSG_SegFlag_First, /**< \brief First segment of User Data */ + CFE_MSG_SegFlag_Last, /**< \brief Last segment of User Data */ + CFE_MSG_SegFlag_Unsegmented /**< \brief Unsegemented data */ +} CFE_MSG_SegmentationFlag_t; + +/** \brief Endian flag */ +typedef enum +{ + CFE_MSG_Endian_Invalid, /**< \brief Invalid endian setting */ + CFE_MSG_Endian_Big, /**< \brief Big endian */ + CFE_MSG_Endian_Little /**< \brief Little endian */ +} CFE_MSG_Endian_t; + +/** \brief Playback flag */ +typedef enum +{ + CFE_MSG_PlayFlag_Invalid, /**< \brief Invalid playback setting */ + CFE_MSG_PlayFlag_Original, /**< \brief Original */ + CFE_MSG_PlayFlag_Playback /**< \brief Playback */ +} CFE_MSG_PlaybackFlag_t; + +#endif /* _cfe_msg_typedefs_ */ diff --git a/modules/msg/CMakeLists.txt b/modules/msg/CMakeLists.txt new file mode 100644 index 000000000..1d6f2e04c --- /dev/null +++ b/modules/msg/CMakeLists.txt @@ -0,0 +1,62 @@ +################################################################## +# +# 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 +# Defined as absolute so this list can also be used to build unit tests +set(${DEP}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_ccsdspri.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_init.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_msgid_shared.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_sechdr_checksum.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_sechdr_fc.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_sechdr_time_old.c +) + +# Source selection for if CCSDS extended header is included, and MsgId version use +if (MISSION_INCLUDE_CCSDSEXT_HEADER) + message(STATUS "CCSDS primary and extended header included in message header") + list(APPEND ${DEP}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_ccsdsext.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_initdefaulthdr_priext.c) + if (MISSION_MSGID_V2) # MsgId v2 or v1 can be used with extended headers + message(STATUS "Message Id version 2 in use (MsgId V2)") + list(APPEND ${DEP}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_msgid_v2.c) + else (MISSION_MSGID_V2) + message(STATUS "Message Id version 1 in use (MsgId V1)") + list(APPEND ${DEP}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_msgid_v1.c) + endif (MISSION_MSGID_V2) +else (MISSION_INCLUDE_CCSDSEXT_HEADER) + message(STATUS "CCSDS primary header included in message header (not including CCSDS extended header)") + message(STATUS "Message Id version 1 in use (MsgId V1)") + list(APPEND ${DEP}_SRC + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_initdefaulthdr_pri.c + ${CMAKE_CURRENT_SOURCE_DIR}/src/cfe_msg_msgid_v1.c) + if (MISSION_MSGID_V2) + message(FATAL_ERROR "Message Id (MsgId) version 2 can only be used if MISSION_INCLUDE_CCSDSEXT_HEADER is set") + endif (MISSION_MSGID_V2) +endif (MISSION_INCLUDE_CCSDSEXT_HEADER) + +# Module library +add_library(${DEP} STATIC ${${DEP}_SRC}) + +# Add private include +target_include_directories(${DEP} PRIVATE private_inc) + +# Add unit test coverage subdirectory +if(ENABLE_UNIT_TESTS) + add_subdirectory(unit-test-coverage) +endif(ENABLE_UNIT_TESTS) diff --git a/modules/msg/mission_build.cmake b/modules/msg/mission_build.cmake new file mode 100644 index 000000000..b34a3f6e5 --- /dev/null +++ b/modules/msg/mission_build.cmake @@ -0,0 +1,27 @@ +########################################################### +# +# MSG mission build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# Extended header inclusion selection +if (MISSION_INCLUDE_CCSDSEXT_HEADER) + set(MSG_HDR_FILE "default_cfe_msg_hdr_priext.h") +else (MISSION_INCLUDE_CCSDSEXT_HEADER) + set(MSG_HDR_FILE "default_cfe_msg_hdr_pri.h") +endif (MISSION_INCLUDE_CCSDSEXT_HEADER) + +# Generate the header definition files, use local default for this module) +generate_config_includefile( + FILE_NAME "cfe_msg_hdr.h" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/mission_inc/${MSG_HDR_FILE}" +) + +generate_config_includefile( + FILE_NAME "cfe_msg_sechdr.h" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/mission_inc/default_cfe_msg_sechdr.h" +) diff --git a/modules/msg/mission_inc/default_cfe_msg_hdr_pri.h b/modules/msg/mission_inc/default_cfe_msg_hdr_pri.h new file mode 100644 index 000000000..d422106db --- /dev/null +++ b/modules/msg/mission_inc/default_cfe_msg_hdr_pri.h @@ -0,0 +1,89 @@ +/* +** 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. +*/ + +/****************************************************************************** + * Define cFS standard full header + * - Avoid direct access for portability, use APIs + * - Used to construct message structures + */ + +#ifndef _cfe_msg_hdr_ +#define _cfe_msg_hdr_ + +/* + * Include Files + */ + +#include "common_types.h" +#include "ccsds_hdr.h" +#include "cfe_msg_sechdr.h" + +/* + * Type Definitions + */ + +/********************************************************************** + * Structure definitions for full header + * + * These are based on historically supported definitions and not + * an open source standard. + */ + +/** + * \brief Full CCSDS header + */ +typedef struct +{ + CCSDS_PrimaryHeader_t Pri; /**< \brief CCSDS Primary Header */ +} CCSDS_SpacePacket_t; + +/** + * \brief cFS command header + */ +typedef struct +{ + + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */ + CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */ + +} CFE_MSG_CommandHeader_t; + +/** + * \brief cFS telemetry header + */ +typedef struct +{ + + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */ + CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */ + +} CFE_MSG_TelemetryHeader_t; + +/** + * \brief cFS Generic packet header + */ +typedef union +{ + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */ + uint32 Align; /**< \brief Force 32-bit alignment */ + uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */ +} CFE_MSG_Message_t; + +#endif /* _cfe_msg_hdr_ */ diff --git a/modules/msg/mission_inc/default_cfe_msg_hdr_priext.h b/modules/msg/mission_inc/default_cfe_msg_hdr_priext.h new file mode 100644 index 000000000..652925269 --- /dev/null +++ b/modules/msg/mission_inc/default_cfe_msg_hdr_priext.h @@ -0,0 +1,90 @@ +/* +** 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. +*/ + +/****************************************************************************** + * Define cFS standard full header + * - Avoid direct access for portability, use APIs + * - Used to construct message structures + */ + +#ifndef _cfe_msg_hdr_ +#define _cfe_msg_hdr_ + +/* + * Include Files + */ + +#include "common_types.h" +#include "ccsds_hdr.h" +#include "cfe_msg_sechdr.h" + +/* + * Type Definitions + */ + +/********************************************************************** + * Structure definitions for full header + * + * These are based on historically supported definitions and not + * an open source standard. + */ + +/** + * \brief Full CCSDS header + */ +typedef struct +{ + CCSDS_PrimaryHeader_t Pri; /**< \brief CCSDS Primary Header */ + CCSDS_ExtendedHeader_t Ext; /**< \brief CCSDS Extended Header */ +} CCSDS_SpacePacket_t; + +/** + * \brief cFS command header + */ +typedef struct +{ + + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */ + CFE_MSG_CommandSecondaryHeader_t Sec; /**< \brief Secondary header */ + +} CFE_MSG_CommandHeader_t; + +/** + * \brief cFS telemetry header + */ +typedef struct +{ + + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS header */ + CFE_MSG_TelemetrySecondaryHeader_t Sec; /**< \brief Secondary header */ + +} CFE_MSG_TelemetryHeader_t; + +/** + * \brief cFS Generic packet header + */ +typedef union +{ + CCSDS_SpacePacket_t CCSDS; /**< \brief CCSDS Header (Pri or Pri + Ext) */ + uint32 Align; /**< \brief Force 32-bit alignment */ + uint8 Byte[sizeof(CCSDS_SpacePacket_t)]; /**< \brief Byte level access */ +} CFE_MSG_Message_t; + +#endif /* _cfe_msg_hdr_ */ diff --git a/modules/msg/mission_inc/default_cfe_msg_sechdr.h b/modules/msg/mission_inc/default_cfe_msg_sechdr.h new file mode 100644 index 000000000..d4d7a678a --- /dev/null +++ b/modules/msg/mission_inc/default_cfe_msg_sechdr.h @@ -0,0 +1,93 @@ +/* +** 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. +*/ + +/****************************************************************************** + * Define cFS standard secondary header + * - Avoid direct access for portability, use APIs + * - Used to construct message structures + */ + +#ifndef _cfe_msg_sechdr_ +#define _cfe_msg_sechdr_ + +/* + * Include Files + */ + +#include "common_types.h" +#include "cfe_mission_cfg.h" + +/* + * Defines + */ + +/* These go away w/ single framework implementation */ +/* CCSDS_TIME_SIZE is specific to the selected CFE_SB time format */ +#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) +/* 32 bits seconds + 16 bits subseconds */ +#define CCSDS_TIME_SIZE 6 +#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) +/* 32 bits seconds + 32 bits subseconds */ +#define CCSDS_TIME_SIZE 8 +#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) +/* 32 bits seconds + 20 bits microsecs + 12 bits reserved */ +#define CCSDS_TIME_SIZE 8 +#else +/* unknown format */ +#error unable to define CCSDS_TIME_SIZE! +#endif + +/* + * Type Definitions + */ + +/********************************************************************** + * Structure definitions for secondary headers + * + * These are based on historically supported definitions and not + * an open source standard. + */ + +/** + * \brief cFS command secondary header + */ +typedef struct +{ + + uint8 FunctionCode; /**< \brief Command Function Code */ + /* bits shift ---------description-------- */ + /* 0x7F 0 Command function code */ + /* 0x80 7 Reserved */ + + uint8 Checksum; /**< \brief Command checksum (all bits, 0xFF) */ + +} CFE_MSG_CommandSecondaryHeader_t; + +/** + * \brief cFS telemetry secondary header + */ +typedef struct +{ + + uint8 Time[CCSDS_TIME_SIZE]; /**< \brief Time sized for selected format */ + +} CFE_MSG_TelemetrySecondaryHeader_t; + +#endif /* _cfe_msg_sechdr_ */ diff --git a/modules/msg/private_inc/cfe_msg_defaults.h b/modules/msg/private_inc/cfe_msg_defaults.h new file mode 100644 index 000000000..ab1541672 --- /dev/null +++ b/modules/msg/private_inc/cfe_msg_defaults.h @@ -0,0 +1,84 @@ +/* +** 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 header defaults, used to initialize messages + * - Avoid including outside this module + */ + +#ifndef _cfe_msg_defaults_ +#define _cfe_msg_defaults_ + +/* + * Includes + */ +#include "cfe_platform_cfg.h" +#include "cfe_mission_cfg.h" + +/* + * Defines + */ + +/* Backwards compatibility */ +#ifndef CFE_PLATFORM_DEFAULT_APID +#define CFE_PLATFORM_DEFAULT_APID 0 /**< \brief Default APID, for bits not in MsgId */ +#endif + +#ifndef CFE_MISSION_CCSDSVER +#ifdef MESSAGE_FORMAT_IS_CCSDS_VER_2 +#define CFE_MISSION_CCSDSVER 1 /**< \brief Default CCSDS Version, cFS Ver 2 historically = 1 */ +#else +#define CFE_MISSION_CCSDSVER 0 /**< \brief Default CCSDS Version, cFS Ver 1 historically = 0 */ +#endif +#endif + +#ifndef CFE_PLATFORM_DEFAULT_SUBSYS +#define CFE_PLATFORM_DEFAULT_SUBSYS 0 /**< \brief Default SubSystem, for bits not in MsgId */ +#endif + +#ifndef CFE_PLATFORM_EDSVER +#define CFE_PLATFORM_EDSVER 1 /**< \brief Default EDS version, cFS historically = 1 */ +#endif + +/*****************************************************************************/ +/** + * \brief Set CCSDS Primary header defaults + * + * \par DESCRIPTION + * Only sets the constant defaults. Internal function assumes + * pointer is valid. + * + * \param[out] MsgPtr Message to set + */ +void CFE_MSG_SetDefaultCCSDSPri(CFE_MSG_Message_t *MsgPtr); + +/*****************************************************************************/ +/** + * \brief Set CCSDS Extended header defaults + * + * \par DESCRIPTION + * Only sets the constant defaults. Internal function assumes + * pointer is valid. + * + * \param[out] MsgPtr Message to set + */ +void CFE_MSG_SetDefaultCCSDSExt(CFE_MSG_Message_t *MsgPtr); + +#endif /* _cfe_msg_default_ */ diff --git a/modules/msg/private_inc/cfe_msg_priv.h b/modules/msg/private_inc/cfe_msg_priv.h new file mode 100644 index 000000000..32d785715 --- /dev/null +++ b/modules/msg/private_inc/cfe_msg_priv.h @@ -0,0 +1,81 @@ +/* +** 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 private header + * - Avoid including outside this module + */ + +#ifndef _cfe_msg_priv_ +#define _cfe_msg_priv_ + +/* + * Includes + */ +#include "common_types.h" + +/*****************************************************************************/ +/** + * \brief get generic header field (uint8 array[2]) + * + * \par DESCRIPTION + * Big endian get of header field given mask. Only sets bits + * in value that are part of mask. + * + * \param[in] Word Header value to set + * \param[out] Val Value to set + * \param[in] Mask Mask used for set + */ +static inline void CFE_MSG_GetHeaderField(const uint8 *Word, uint16 *Val, uint16 Mask) +{ + *Val = (Word[0] << 8 | Word[1]) & Mask; +} + +/*****************************************************************************/ +/** + * \brief Set generic header field (uint8 array[2]) + * + * \par DESCRIPTION + * Big endian set of header field given value and mask. Only sets bits + * from value that are part of mask. + * + * \param[in, out] Word Header value to set + * \param[in] Val Value to set + * \param[in] Mask Mask used for set + */ +static inline void CFE_MSG_SetHeaderField(uint8 *Word, uint16 Val, uint16 Mask) +{ + Word[0] = (Word[0] & ~(Mask >> 8)) | ((Val & Mask) >> 8); + Word[1] = ((Word[1] & ~Mask) | (Val & Mask)) & 0xFF; +} + +/*****************************************************************************/ +/** + * \brief Initialize default header - implemented based on selected header format + * + * \par DESCRIPTION + * Sets the constant defaults for the entire header. Internal function + * assumes pointer is valid. + * + * \param[out] MsgPtr Message to set + */ +void CFE_MSG_InitDefaultHdr(CFE_MSG_Message_t *MsgPtr); + +#endif /* _cfe_msg_priv_ */ diff --git a/modules/msg/src/cfe_msg_ccsdsext.c b/modules/msg/src/cfe_msg_ccsdsext.c new file mode 100644 index 000000000..6c7587c3b --- /dev/null +++ b/modules/msg/src/cfe_msg_ccsdsext.c @@ -0,0 +1,250 @@ +/* +** 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 CCSDS extended header implementations + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_msg_defaults.h" +#include "cfe_error.h" + +/* CCSDS Extended definitions */ +#define CFE_MSG_EDSVER_SHIFT 11 /**< \brief CCSDS EDS version shift */ +#define CFE_MSG_EDSVER_MASK 0xF800 /**< \brief CCSDS EDS version mask */ +#define CFE_MSG_ENDIAN_MASK 0x0400 /**< \brief CCSDS endiam mask, little endian when set */ +#define CFE_MSG_PLAYBACK_MASK 0x0200 /**< \brief CCSDS playback flag, playback when set */ +#define CFE_MSG_SUBSYS_MASK 0x01FF /**< \brief CCSDS Subsystem mask */ + +/****************************************************************************** + * CCSDS extended header initialization - See header file for details + */ +void CFE_MSG_SetDefaultCCSDSExt(CFE_MSG_Message_t *MsgPtr) +{ + + CFE_MSG_SetEDSVersion(MsgPtr, (CFE_MSG_EDSVersion_t)CFE_PLATFORM_EDSVER); + +#if (CFE_PLATFORM_ENDIAN == CCSDS_LITTLE_ENDIAN) + CFE_MSG_SetEndian(MsgPtr, CFE_MSG_Endian_Little); +#else + CFE_MSG_SetEndian(MsgPtr, CFE_MSG_Endian_Big); +#endif + + /* Default bits of the subsystem, for whatever isn't set by MsgId */ + CFE_MSG_SetSubsystem(MsgPtr, (CFE_MSG_Subsystem_t)CFE_PLATFORM_DEFAULT_SUBSYS); + CFE_MSG_SetSystem(MsgPtr, (CFE_MSG_System_t)CFE_MISSION_SPACECRAFT_ID); +} + +/****************************************************************************** + * Get message EDS version - See API and header file for details + */ +int32 CFE_MSG_GetEDSVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t *Version) +{ + + if (MsgPtr == NULL || Version == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Version, CFE_MSG_EDSVER_MASK); + *Version >>= CFE_MSG_EDSVER_SHIFT; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message EDS version - See API and header file for details + */ +int32 CFE_MSG_SetEDSVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_EDSVersion_t Version) +{ + if (MsgPtr == NULL || (Version > (CFE_MSG_EDSVER_MASK >> CFE_MSG_EDSVER_SHIFT))) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Version << CFE_MSG_EDSVER_SHIFT, CFE_MSG_EDSVER_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message endian - See API and header file for details + */ +int32 CFE_MSG_GetEndian(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t *Endian) +{ + + if (MsgPtr == NULL || Endian == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if ((MsgPtr->CCSDS.Ext.Subsystem[0] & (CFE_MSG_ENDIAN_MASK >> 8)) != 0) + { + *Endian = CFE_MSG_Endian_Little; + } + else + { + *Endian = CFE_MSG_Endian_Big; + } + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message endian - See API and header file for details + */ +int32 CFE_MSG_SetEndian(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Endian_t Endian) +{ + int32 status = CFE_SUCCESS; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if (Endian == CFE_MSG_Endian_Little) + { + MsgPtr->CCSDS.Ext.Subsystem[0] |= CFE_MSG_ENDIAN_MASK >> 8; + } + else if (Endian == CFE_MSG_Endian_Big) + { + MsgPtr->CCSDS.Ext.Subsystem[0] &= ~(CFE_MSG_ENDIAN_MASK >> 8); + } + else + { + status = CFE_MSG_BAD_ARGUMENT; + } + + return status; +} + +/****************************************************************************** + * Get message playback flag - See API and header file for details + */ +int32 CFE_MSG_GetPlaybackFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t *PlayFlag) +{ + + if (MsgPtr == NULL || PlayFlag == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if ((MsgPtr->CCSDS.Ext.Subsystem[0] & (CFE_MSG_PLAYBACK_MASK >> 8)) != 0) + { + *PlayFlag = CFE_MSG_PlayFlag_Playback; + } + else + { + *PlayFlag = CFE_MSG_PlayFlag_Original; + } + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message playback flag - See API and header file for details + */ +int32 CFE_MSG_SetPlaybackFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_PlaybackFlag_t PlayFlag) +{ + int32 status = CFE_SUCCESS; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if (PlayFlag == CFE_MSG_PlayFlag_Playback) + { + MsgPtr->CCSDS.Ext.Subsystem[0] |= CFE_MSG_PLAYBACK_MASK >> 8; + } + else if (PlayFlag == CFE_MSG_PlayFlag_Original) + { + MsgPtr->CCSDS.Ext.Subsystem[0] &= ~(CFE_MSG_PLAYBACK_MASK >> 8); + } + else + { + status = CFE_MSG_BAD_ARGUMENT; + } + + return status; +} + +/****************************************************************************** + * Get message subsystem - See API and header file for details + */ +int32 CFE_MSG_GetSubsystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t *Subsystem) +{ + + if (MsgPtr == NULL || Subsystem == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Subsystem, CFE_MSG_SUBSYS_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message subsystem - See API and header file for details + */ +int32 CFE_MSG_SetSubsystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Subsystem_t Subsystem) +{ + if (MsgPtr == NULL || ((Subsystem & ~CFE_MSG_SUBSYS_MASK) != 0)) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Ext.Subsystem, Subsystem, CFE_MSG_SUBSYS_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message system - See API and header file for details + */ +int32 CFE_MSG_GetSystem(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t *System) +{ + + if (MsgPtr == NULL || System == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + *System = (MsgPtr->CCSDS.Ext.SystemId[0] << 8) + MsgPtr->CCSDS.Ext.SystemId[1]; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message system - See API and header file for details + */ +int32 CFE_MSG_SetSystem(CFE_MSG_Message_t *MsgPtr, CFE_MSG_System_t System) +{ + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + MsgPtr->CCSDS.Ext.SystemId[0] = (System >> 8) & 0xFF; + MsgPtr->CCSDS.Ext.SystemId[1] = System & 0xFF; + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_ccsdspri.c b/modules/msg/src/cfe_msg_ccsdspri.c new file mode 100644 index 000000000..b7d73679d --- /dev/null +++ b/modules/msg/src/cfe_msg_ccsdspri.c @@ -0,0 +1,352 @@ +/* +** 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 CCSDS Primary header implementations + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_msg_defaults.h" +#include "cfe_error.h" + +/* CCSDS Primary Standard definitions */ +#define CFE_MSG_SIZE_OFFSET 7 /**< \brief CCSDS size offset */ +#define CFE_MSG_CCSDSVER_MASK 0xE000 /**< \brief CCSDS version mask */ +#define CFE_MSG_CCSDSVER_SHIFT 13 /**< \brief CCSDS version shift */ +#define CFE_MSG_TYPE_MASK 0x1000 /**< \brief CCSDS type mask, command when set */ +#define CFE_MSG_SHDR_MASK 0x0800 /**< \brief CCSDS secondary header mask, exists when set*/ +#define CFE_MSG_APID_MASK 0x07FF /**< \brief CCSDS ApID mask */ +#define CFE_MSG_SEGFLG_MASK 0xC000 /**< \brief CCSDS segmentation flag mask, all set = complete packet */ +#define CFE_MSG_SEGFLG_CNT 0x0000 /**< \brief CCSDS Segment continuation flag */ +#define CFE_MSG_SEGFLG_FIRST 0x4000 /**< \brief CCSDS Segment first flag */ +#define CFE_MSG_SEGFLG_LAST 0x8000 /**< \brief CCSDS Segment last flag */ +#define CFE_MSG_SEGFLG_UNSEG 0xC000 /**< \brief CCSDS Unsegmented flag */ +#define CFE_MSG_SEQCNT_MASK 0x3FFF /**< \brief CCSDS Sequence count mask */ + +/****************************************************************************** + * CCSDS Primary header initialization - See header file for details + */ +void CFE_MSG_SetDefaultCCSDSPri(CFE_MSG_Message_t *MsgPtr) +{ + + /* cFS standard is for secondary header to be present */ + CFE_MSG_SetHasSecondaryHeader(MsgPtr, true); + + /* cFS standard for CCSDS Version is Ver 1 = 0, Ver 2 = 1, but mission may redefine */ + CFE_MSG_SetHeaderVersion(MsgPtr, CFE_MISSION_CCSDSVER); + + /* Default bits of the APID, for whatever isn't set by MsgId */ + CFE_MSG_SetApId(MsgPtr, CFE_PLATFORM_DEFAULT_APID); + + /* Default to complete packets */ + CFE_MSG_SetSegmentationFlag(MsgPtr, CFE_MSG_SegFlag_Unsegmented); +} + +/****************************************************************************** + * Get message header version - See API and header file for details + */ +int32 CFE_MSG_GetHeaderVersion(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_HeaderVersion_t *Version) +{ + + if (MsgPtr == NULL || Version == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Pri.StreamId, Version, CFE_MSG_CCSDSVER_MASK); + *Version >>= CFE_MSG_CCSDSVER_SHIFT; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message header version - See API and header file for details + */ +int32 CFE_MSG_SetHeaderVersion(CFE_MSG_Message_t *MsgPtr, CFE_MSG_HeaderVersion_t Version) +{ + if (MsgPtr == NULL || (Version > (CFE_MSG_CCSDSVER_MASK >> CFE_MSG_CCSDSVER_SHIFT))) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.StreamId, Version << CFE_MSG_CCSDSVER_SHIFT, CFE_MSG_CCSDSVER_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message type - See API and header file for details + */ +int32 CFE_MSG_GetType(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t *Type) +{ + + if (MsgPtr == NULL || Type == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if ((MsgPtr->CCSDS.Pri.StreamId[0] & (CFE_MSG_TYPE_MASK >> 8)) != 0) + { + *Type = CFE_MSG_Type_Cmd; + } + else + { + *Type = CFE_MSG_Type_Tlm; + } + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message type - See API and header file for details + */ +int32 CFE_MSG_SetType(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t Type) +{ + int32 status = CFE_SUCCESS; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if (Type == CFE_MSG_Type_Cmd) + { + MsgPtr->CCSDS.Pri.StreamId[0] |= CFE_MSG_TYPE_MASK >> 8; + } + else if (Type == CFE_MSG_Type_Tlm) + { + MsgPtr->CCSDS.Pri.StreamId[0] &= ~(CFE_MSG_TYPE_MASK >> 8); + } + else + { + status = CFE_MSG_BAD_ARGUMENT; + } + + return status; +} + +/****************************************************************************** + * Get message has secondary header flag - See API and header file for details + */ +int32 CFE_MSG_GetHasSecondaryHeader(const CFE_MSG_Message_t *MsgPtr, bool *HasSecondary) +{ + + if (MsgPtr == NULL || HasSecondary == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + *HasSecondary = (MsgPtr->CCSDS.Pri.StreamId[0] & (CFE_MSG_SHDR_MASK >> 8)) != 0; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message has secondary header flag - See API and header file for details + */ +int32 CFE_MSG_SetHasSecondaryHeader(CFE_MSG_Message_t *MsgPtr, bool HasSecondary) +{ + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + if (HasSecondary) + { + MsgPtr->CCSDS.Pri.StreamId[0] |= CFE_MSG_SHDR_MASK >> 8; + } + else + { + MsgPtr->CCSDS.Pri.StreamId[0] &= ~(CFE_MSG_SHDR_MASK >> 8); + } + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message application ID - See API and header file for details + */ +int32 CFE_MSG_GetApId(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_ApId_t *ApId) +{ + + if (MsgPtr == NULL || ApId == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Pri.StreamId, ApId, CFE_MSG_APID_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message application ID - See API and header file for details + */ +int32 CFE_MSG_SetApId(CFE_MSG_Message_t *MsgPtr, CFE_MSG_ApId_t ApId) +{ + if (MsgPtr == NULL || ((ApId & ~CFE_MSG_APID_MASK) != 0)) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.StreamId, ApId, CFE_MSG_APID_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message segmentation flag - See API and header file for details + */ +int32 CFE_MSG_GetSegmentationFlag(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_SegmentationFlag_t *SegFlag) +{ + + uint16 rawval; + + if (MsgPtr == NULL || SegFlag == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Pri.Sequence, &rawval, CFE_MSG_SEGFLG_MASK); + + switch (rawval) + { + case CFE_MSG_SEGFLG_CNT: + *SegFlag = CFE_MSG_SegFlag_Continue; + break; + case CFE_MSG_SEGFLG_FIRST: + *SegFlag = CFE_MSG_SegFlag_First; + break; + case CFE_MSG_SEGFLG_LAST: + *SegFlag = CFE_MSG_SegFlag_Last; + break; + case CFE_MSG_SEGFLG_UNSEG: + default: + *SegFlag = CFE_MSG_SegFlag_Unsegmented; + } + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message segmentation flag - See API and header file for details + */ +int32 CFE_MSG_SetSegmentationFlag(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SegmentationFlag_t SegFlag) +{ + uint16 rawval = 0; + int32 status = CFE_SUCCESS; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + switch (SegFlag) + { + case CFE_MSG_SegFlag_Continue: + rawval = CFE_MSG_SEGFLG_CNT; + break; + case CFE_MSG_SegFlag_First: + rawval = CFE_MSG_SEGFLG_FIRST; + break; + case CFE_MSG_SegFlag_Last: + rawval = CFE_MSG_SEGFLG_LAST; + break; + case CFE_MSG_SegFlag_Unsegmented: + rawval = CFE_MSG_SEGFLG_UNSEG; + break; + case CFE_MSG_SegFlag_Invalid: + default: + status = CFE_MSG_BAD_ARGUMENT; + } + + if (status == CFE_SUCCESS) + { + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.Sequence, rawval, CFE_MSG_SEGFLG_MASK); + } + + return status; +} + +/****************************************************************************** + * Get message sequence count - See API and header file for details + */ +int32 CFE_MSG_GetSequenceCount(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t *SeqCnt) +{ + + if (MsgPtr == NULL || SeqCnt == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_GetHeaderField(MsgPtr->CCSDS.Pri.Sequence, SeqCnt, CFE_MSG_SEQCNT_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message sequence count - See API and header file for details + */ +int32 CFE_MSG_SetSequenceCount(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t SeqCnt) +{ + if (MsgPtr == NULL || ((SeqCnt & ~CFE_MSG_SEQCNT_MASK) != 0)) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetHeaderField(MsgPtr->CCSDS.Pri.Sequence, SeqCnt, CFE_MSG_SEQCNT_MASK); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message size - See API and header file for details + */ +int32 CFE_MSG_GetSize(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t *Size) +{ + + if (MsgPtr == NULL || Size == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + *Size = (MsgPtr->CCSDS.Pri.Length[0] << 8) + MsgPtr->CCSDS.Pri.Length[1] + CFE_MSG_SIZE_OFFSET; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message size - See API and header file for details + */ +int32 CFE_MSG_SetSize(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size) +{ + if (MsgPtr == NULL || Size < CFE_MSG_SIZE_OFFSET || Size > (0xFFFF + CFE_MSG_SIZE_OFFSET)) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Size is CCSDS header is total packet size - CFE_MSG_SIZE_OFFSET (7) */ + Size -= CFE_MSG_SIZE_OFFSET; + + MsgPtr->CCSDS.Pri.Length[0] = (Size >> 8) & 0xFF; + MsgPtr->CCSDS.Pri.Length[1] = Size & 0xFF; + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_init.c b/modules/msg/src/cfe_msg_init.c new file mode 100644 index 000000000..b64e2d0f6 --- /dev/null +++ b/modules/msg/src/cfe_msg_init.c @@ -0,0 +1,57 @@ +/* +** 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 initialization + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_msg_defaults.h" +#include "string.h" + +/****************************************************************************** + * Top level message initialization - See API and header file for details + */ +int32 CFE_MSG_Init(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_MSG_Size_t Size, bool Clear) +{ + + int32 status; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Clear and set defaults if request */ + if (Clear) + { + memset(MsgPtr, 0, Size); + CFE_MSG_InitDefaultHdr(MsgPtr); + } + + /* Set values input */ + status = CFE_MSG_SetMsgId(MsgPtr, MsgId); + if (status == CFE_SUCCESS) + { + status = CFE_MSG_SetSize(MsgPtr, Size); + } + + return status; +} diff --git a/modules/msg/src/cfe_msg_initdefaulthdr_pri.c b/modules/msg/src/cfe_msg_initdefaulthdr_pri.c new file mode 100644 index 000000000..2904ab1ef --- /dev/null +++ b/modules/msg/src/cfe_msg_initdefaulthdr_pri.c @@ -0,0 +1,34 @@ +/* +** 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 default header initialization - implementation without CCSDS + * extended header + */ +#include "cfe_msg_hdr.h" +#include "cfe_msg_defaults.h" + +/****************************************************************************** + * Top level message initialization - See header file for details + */ +void CFE_MSG_InitDefaultHdr(CFE_MSG_Message_t *MsgPtr) +{ + CFE_MSG_SetDefaultCCSDSPri(MsgPtr); +} diff --git a/modules/msg/src/cfe_msg_initdefaulthdr_priext.c b/modules/msg/src/cfe_msg_initdefaulthdr_priext.c new file mode 100644 index 000000000..c11f15347 --- /dev/null +++ b/modules/msg/src/cfe_msg_initdefaulthdr_priext.c @@ -0,0 +1,35 @@ +/* +** 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 default header initialization - implementation without CCSDS + * extended header + */ +#include "cfe_msg_hdr.h" +#include "cfe_msg_defaults.h" + +/****************************************************************************** + * Top level message initialization - See header file for details + */ +void CFE_MSG_InitDefaultHdr(CFE_MSG_Message_t *MsgPtr) +{ + CFE_MSG_SetDefaultCCSDSPri(MsgPtr); + CFE_MSG_SetDefaultCCSDSExt(MsgPtr); +} diff --git a/modules/msg/src/cfe_msg_msgid_shared.c b/modules/msg/src/cfe_msg_msgid_shared.c new file mode 100644 index 000000000..79caaac7f --- /dev/null +++ b/modules/msg/src/cfe_msg_msgid_shared.c @@ -0,0 +1,46 @@ +/* +** 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 id access functions, shared cFS implementation + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_error.h" + +/****************************************************************************** + * Get type from message id - See API and header file for details + * cFS default implementation + */ +int32 CFE_MSG_GetTypeFromMsgId(CFE_SB_MsgId_t MsgId, CFE_MSG_Type_t *Type) +{ + + CFE_MSG_Message_t msg; + + if (Type == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + CFE_MSG_SetMsgId(&msg, MsgId); + CFE_MSG_GetType(&msg, Type); + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_msgid_v1.c b/modules/msg/src/cfe_msg_msgid_v1.c new file mode 100644 index 000000000..8b79ec3d3 --- /dev/null +++ b/modules/msg/src/cfe_msg_msgid_v1.c @@ -0,0 +1,71 @@ +/* +** 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 id access functions, cFS version 1 implementation + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_error.h" +#include "cfe_platform_cfg.h" + +/****************************************************************************** + * Get message id - See API and header file for details + * cFS default version 1 implementation using CCSDS headers + * + * Message Id = CCSDS Stream ID (in local endian) + */ +int32 CFE_MSG_GetMsgId(const CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t *MsgId) +{ + + CFE_SB_MsgId_Atom_t msgidval; + + if (MsgPtr == NULL || MsgId == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + msgidval = (MsgPtr->CCSDS.Pri.StreamId[0] << 8) + MsgPtr->CCSDS.Pri.StreamId[1]; + *MsgId = CFE_SB_ValueToMsgId(msgidval); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message id - See API and header file for details + * cFS default version 1 implementations using CCSDS headers + * + * CCSDS Stream ID = Message Id converted to big endian + */ +int32 CFE_MSG_SetMsgId(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId) +{ + + CFE_SB_MsgId_Atom_t msgidval = CFE_SB_MsgIdToValue(MsgId); + + if (MsgPtr == NULL || msgidval > CFE_PLATFORM_SB_HIGHEST_VALID_MSGID) + { + return CFE_MSG_BAD_ARGUMENT; + } + + MsgPtr->CCSDS.Pri.StreamId[0] = (uint8)(msgidval >> 8); + MsgPtr->CCSDS.Pri.StreamId[1] = (uint8)(msgidval); + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_msgid_v2.c b/modules/msg/src/cfe_msg_msgid_v2.c new file mode 100644 index 000000000..6845f9755 --- /dev/null +++ b/modules/msg/src/cfe_msg_msgid_v2.c @@ -0,0 +1,111 @@ +/* +** 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 id access functions + * + * cFS default version 2 implementation using CCSDS headers + * + * Message Id: + * 7 bits from the primary header APID (0x7F of 0x7FF) + * 1 bit for the command/telemetry flag + * 0 bits from the Playback flag + * 8 bits from the secondary header APID qualifier (Subsystem) (0xFF of 0x01FF) + * 0 bits from the secondary header APID qualifier as the System + * = 16 bits total + * + * Byte 1 Byte 0 + * 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 + * +-+-+-+-+-+-+-+-+|--------|+-+-+-+-+-+-+-+ + * | APID Qualifier |C/T flg | Pri Hdr APID | + * +-+-+-+-+-+-+-+-+|--------|+-+-+-+-+-+-+-+ + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_error.h" +#include "cfe_platform_cfg.h" + +/* cFS MsgId definitions */ +#define CFE_MSG_MSGID_APID_MASK 0x007F /**< \brief CCSDS ApId mask for MsgId */ +#define CFE_MSG_MSGID_TYPE_MASK 0x0080 /**< \brief Message type mask for MsgId, set = cmd */ +#define CFE_MSG_MSGID_SUBSYS_MASK 0xFF00 /**< \brief Subsystem mask for MsgId */ + +/****************************************************************************** + * Get message id - See API and header file for details + */ +int32 CFE_MSG_GetMsgId(const CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t *MsgId) +{ + + CFE_SB_MsgId_Atom_t msgidval; + CFE_MSG_Type_t type; + + if (MsgPtr == NULL || MsgId == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, assumes tlm if invalid */ + CFE_MSG_GetType(MsgPtr, &type); + + /* Set message ID bits from CCSDS header fields */ + msgidval = MsgPtr->CCSDS.Pri.StreamId[1] & CFE_MSG_MSGID_APID_MASK; + if (type == CFE_MSG_Type_Cmd) + { + msgidval |= CFE_MSG_MSGID_TYPE_MASK; + } + msgidval |= (MsgPtr->CCSDS.Ext.Subsystem[1] << 8) & CFE_MSG_MSGID_SUBSYS_MASK; + + *MsgId = CFE_SB_ValueToMsgId(msgidval); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set message id - See API and header file for details + */ +int32 CFE_MSG_SetMsgId(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId) +{ + + CFE_SB_MsgId_Atom_t msgidval = CFE_SB_MsgIdToValue(MsgId); + + if (MsgPtr == NULL || msgidval > CFE_PLATFORM_SB_HIGHEST_VALID_MSGID) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Clear and set PID_MSGID_MASK bits */ + MsgPtr->CCSDS.Pri.StreamId[1] = + (MsgPtr->CCSDS.Pri.StreamId[1] & ~CFE_MSG_MSGID_APID_MASK) | (msgidval & CFE_MSG_MSGID_APID_MASK); + + /* Set APIDQ Subsystem bits */ + MsgPtr->CCSDS.Ext.Subsystem[1] = ((msgidval & CFE_MSG_MSGID_SUBSYS_MASK) >> 8); + + /* Set type, ignores return since no failure action */ + if ((msgidval & CFE_MSG_MSGID_TYPE_MASK) != 0) + { + CFE_MSG_SetType(MsgPtr, CFE_MSG_Type_Cmd); + } + else + { + CFE_MSG_SetType(MsgPtr, CFE_MSG_Type_Tlm); + } + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_sechdr_checksum.c b/modules/msg/src/cfe_msg_sechdr_checksum.c new file mode 100644 index 000000000..aa645c864 --- /dev/null +++ b/modules/msg/src/cfe_msg_sechdr_checksum.c @@ -0,0 +1,116 @@ +/* +** 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_api.h" +#include "cfe_msg_priv.h" + +/******************************************************************************/ +/** + * \brief Compute checksum - internal utility + * + * \param[in] MsgPtr Message pointer to checksum + * + * \return Calculated checksum + */ +CFE_MSG_Checksum_t CFE_MSG_ComputeCheckSum(const CFE_MSG_Message_t *MsgPtr) +{ + + uint32 PktLen = 0; + const uint8 * BytePtr = MsgPtr->Byte; + CFE_MSG_Checksum_t chksum = 0xFF; + + /* Message already checked, no error case reachable */ + CFE_MSG_GetSize(MsgPtr, &PktLen); + + while (PktLen--) + { + chksum ^= *(BytePtr++); + } + + return chksum; +} + +/****************************************************************************** + * Calculate and set checksum field - See API and header file for details + * Implementation supports cFS secondary definition or no secodary header + */ +int32 CFE_MSG_GenerateChecksum(CFE_MSG_Message_t *MsgPtr) +{ + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_CommandHeader_t *cmd = (CFE_MSG_CommandHeader_t *)MsgPtr; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Cmd || !hassechdr) + { + return CFE_MSG_WRONG_MSG_TYPE; + } + + /* Zero checksum so new checksum will be correct */ + cmd->Sec.Checksum = 0; + + /* Compute and set */ + cmd->Sec.Checksum = CFE_MSG_ComputeCheckSum((CFE_MSG_Message_t *)cmd); + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Validate checksum - See API and header file for details + * Implementation supports cFS secondary definition or no secondary header + */ +int32 CFE_MSG_ValidateChecksum(const CFE_MSG_Message_t *MsgPtr, bool *IsValid) +{ + + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + + if (MsgPtr == NULL || IsValid == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Cmd || !hassechdr) + { + return CFE_MSG_WRONG_MSG_TYPE; + } + + /* Compute, valid if == 0 */ + *IsValid = (CFE_MSG_ComputeCheckSum(MsgPtr) == 0); + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_sechdr_fc.c b/modules/msg/src/cfe_msg_sechdr_fc.c new file mode 100644 index 000000000..aa1c5abc9 --- /dev/null +++ b/modules/msg/src/cfe_msg_sechdr_fc.c @@ -0,0 +1,88 @@ +/* +** 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. +*/ + +/****************************************************************************** + * Function code field access functions + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" + +#define CFE_MSG_FC_MASK 0x7F /**< \brief Function code mask */ + +/****************************************************************************** + * Get function code - See API and header file for details + * cFS default secondary header implementation + */ +int32 CFE_MSG_GetFcnCode(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_FcnCode_t *FcnCode) +{ + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_CommandHeader_t *cmd = (CFE_MSG_CommandHeader_t *)MsgPtr; + + if (MsgPtr == NULL || FcnCode == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Cmd || !hassechdr) + { + *FcnCode = 0; + return CFE_MSG_WRONG_MSG_TYPE; + } + + *FcnCode = cmd->Sec.FunctionCode & CFE_MSG_FC_MASK; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Set function code - See API and header file for details + * cFS default secondary header implementation + */ +int32 CFE_MSG_SetFcnCode(CFE_MSG_Message_t *MsgPtr, CFE_MSG_FcnCode_t FcnCode) +{ + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_CommandHeader_t *cmd = (CFE_MSG_CommandHeader_t *)MsgPtr; + + if (MsgPtr == NULL || (FcnCode > CFE_MSG_FC_MASK)) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Cmd || !hassechdr) + { + return CFE_MSG_WRONG_MSG_TYPE; + } + + cmd->Sec.FunctionCode = FcnCode; + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_sechdr_time.c b/modules/msg/src/cfe_msg_sechdr_time.c new file mode 100644 index 000000000..71d8d7a84 --- /dev/null +++ b/modules/msg/src/cfe_msg_sechdr_time.c @@ -0,0 +1,97 @@ +/* +** 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 - cFS default 32 bit seconds, 16 bit subseconds + * in big endian format + */ +#include "cfe_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_error.h" +#include + +/****************************************************************************** + * Set message time - See API and header file for details + */ +int32 CFE_MSG_SetMsgTime(CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t NewTime) +{ + + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_TelemetryHeader_t *tlm = (CFE_MSG_TelemetryHeader_t *)MsgPtr; + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Tlm || !hassechdr) + { + return CFE_MSG_WRONG_MSG_TYPE; + } + + /* Set big endian time field with default 32/16 layout */ + tlm->Sec.Time[0] = (NewTime.Seconds >> 24) & 0xFF; + tlm->Sec.Time[1] = (NewTime.Seconds >> 16) & 0xFF; + tlm->Sec.Time[2] = (NewTime.Seconds >> 8) & 0xFF; + tlm->Sec.Time[3] = NewTime.Seconds & 0xFF; + tlm->Sec.Time[4] = (NewTime.Subseconds >> 24) & 0xFF; + tlm->Sec.Time[5] = (NewTime.Subseconds >> 16) & 0xFF; + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message time - See API and header file for details + */ +int32 CFE_MSG_GetMsgTime(const CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t *Time) +{ + + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_TelemetryHeader_t *tlm = (CFE_MSG_TelemetryHeader_t *)MsgPtr; + + if (MsgPtr == NULL || Time == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Tlm || !hassechdr) + { + memset(Time, 0, sizeof(*Time)); + return CFE_MSG_WRONG_MSG_TYPE; + } + + /* Get big endian time fields with default 32/16 layout */ + Time->Subseconds = (tlm->Sec.Time[4] << 24) + (tlm->Sec.Time[5] << 16); + Time->Seconds = (tlm->Sec.Time[0] << 24) + (tlm->Sec.Time[1] << 16) + (tlm->Sec.Time[2] << 8) + tlm->Sec.Time[3]; + + return CFE_SUCCESS; +} diff --git a/modules/msg/src/cfe_msg_sechdr_time_old.c b/modules/msg/src/cfe_msg_sechdr_time_old.c new file mode 100644 index 000000000..7b1a5b16b --- /dev/null +++ b/modules/msg/src/cfe_msg_sechdr_time_old.c @@ -0,0 +1,137 @@ +/* +** 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_msg_api.h" +#include "cfe_msg_priv.h" +#include "cfe_error.h" +#include + +/****************************************************************************** + * Set message time - See API and header file for details + */ +int32 CFE_MSG_SetMsgTime(CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t NewTime) +{ + + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_TelemetryHeader_t *tlm = (CFE_MSG_TelemetryHeader_t *)MsgPtr; + +/* 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 + + if (MsgPtr == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Tlm || !hassechdr) + { + return CFE_MSG_WRONG_MSG_TYPE; + } + + memcpy(&tlm->Sec.Time[0], &NewTime.Seconds, 4); + +#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(&tlm->Sec.Time[4], &LocalSubs16, 2); + +#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(&tlm->Sec.Time[4], &NewTime.Subseconds, 4); + +#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(&tlm->Sec.Time[4], &LocalSubs32, 4); + +#endif + + return CFE_SUCCESS; +} + +/****************************************************************************** + * Get message time - See API and header file for details + */ +int32 CFE_MSG_GetMsgTime(const CFE_MSG_Message_t *MsgPtr, CFE_TIME_SysTime_t *Time) +{ + + uint32 status; + CFE_MSG_Type_t type; + bool hassechdr = false; + CFE_MSG_TelemetryHeader_t *tlm = (CFE_MSG_TelemetryHeader_t *)MsgPtr; + +#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + uint16 LocalSubs16; +#endif + + if (MsgPtr == NULL || Time == NULL) + { + return CFE_MSG_BAD_ARGUMENT; + } + + /* Ignore return, pointer already checked */ + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + + status = CFE_MSG_GetType(MsgPtr, &type); + if (status != CFE_SUCCESS || type != CFE_MSG_Type_Tlm || !hassechdr) + { + memset(Time, 0, sizeof(*Time)); + return CFE_MSG_WRONG_MSG_TYPE; + } + + memcpy(&Time->Seconds, &tlm->Sec.Time[0], 4); + +#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) + + memcpy(&LocalSubs16, &tlm->Sec.Time[4], 2); + /* convert packet data into CFE_TIME_SysTime_t format */ + Time->Subseconds = ((uint32)LocalSubs16) << 16; + +#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) + + memcpy(&Time->Subseconds, &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(&LocalSubs32, &tlm->Sec.Time[4], 4); + /* convert packet data into CFE_TIME_SysTime_t format */ + Time->Subseconds = CFE_TIME_Micro2SubSecs((LocalSubs32 >> 12)); + +#endif + + return CFE_SUCCESS; +} From 856367951848fdf00a3985144765edb6b13b0e61 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:48:52 -0400 Subject: [PATCH 2/4] Fix #711, Update SB/CCSDS FSW for msg module - Fix #733: Validate checksum description update - Fix #597: Remove local endian SID macros - Updates SB to use msg module - General cleanup --- fsw/cfe-core/src/inc/ccsds.h | 505 ++--------------------- fsw/cfe-core/src/inc/ccsds_hdr.h | 89 ++++ fsw/cfe-core/src/inc/cfe.h | 2 + fsw/cfe-core/src/inc/cfe_sb.h | 24 +- fsw/cfe-core/src/sb/ccsds.c | 122 ------ fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c | 93 +---- fsw/cfe-core/src/sb/cfe_sb_msg_id_util.h | 78 ---- fsw/cfe-core/src/sb/cfe_sb_priv.c | 5 +- fsw/cfe-core/src/sb/cfe_sb_task.c | 1 - fsw/cfe-core/src/sb/cfe_sb_util.c | 235 +++-------- 10 files changed, 193 insertions(+), 961 deletions(-) create mode 100644 fsw/cfe-core/src/inc/ccsds_hdr.h delete mode 100644 fsw/cfe-core/src/sb/ccsds.c delete mode 100644 fsw/cfe-core/src/sb/cfe_sb_msg_id_util.h diff --git a/fsw/cfe-core/src/inc/ccsds.h b/fsw/cfe-core/src/inc/ccsds.h index f86e550c1..04575866f 100644 --- a/fsw/cfe-core/src/inc/ccsds.h +++ b/fsw/cfe-core/src/inc/ccsds.h @@ -32,503 +32,44 @@ /* ** Include Files */ - #include "common_types.h" #include "cfe_mission_cfg.h" - - -/* Macro to convert 16/32 bit types from platform "endianness" to Big Endian */ -#ifdef SOFTWARE_BIG_BIT_ORDER - #define CFE_MAKE_BIG16(n) (n) - #define CFE_MAKE_BIG32(n) (n) -#else - #define CFE_MAKE_BIG16(n) ( (((n) << 8) & 0xFF00) | (((n) >> 8) & 0x00FF) ) - #define CFE_MAKE_BIG32(n) ( (((n) << 24) & 0xFF000000) | (((n) << 8) & 0x00FF0000) | (((n) >> 8) & 0x0000FF00) | (((n) >> 24) & 0x000000FF) ) -#endif - - -/* CCSDS_TIME_SIZE is specific to the selected CFE_SB time format */ -#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - /* 32 bits seconds + 16 bits subseconds */ - #define CCSDS_TIME_SIZE 6 -#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) - /* 32 bits seconds + 32 bits subseconds */ - #define CCSDS_TIME_SIZE 8 -#elif (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20) - /* 32 bits seconds + 20 bits microsecs + 12 bits reserved */ - #define CCSDS_TIME_SIZE 8 -#else - /* unknown format */ - #error unable to define CCSDS_TIME_SIZE! -#endif - - -/* -** Type Definitions -*/ - -/********************************************************************** -** Structure definitions for CCSDS headers. All items in the structure -** must be aligned on 16-bit words. Bitfields must be avoided since -** some compilers (such as gcc) force them into 32-bit alignment. -** -** CCSDS headers must always be in network byte order per the standard. -** MSB at the lowest address which is commonly refered to as "BIG Endian" -** -** CCSDS Space Packets can be version 1 or version 2. Version 2 has -** an additional 32 bits for APID Qualifier fields in the secondary -** header. The primary header is unchanged. -** -**********************************************************************/ - -/*----- CCSDS packet primary header. -----*/ - -typedef struct { - - uint8 StreamId[2]; /* packet identifier word (stream ID) */ - /* bits shift ------------ description ---------------- */ - /* 0x07FF 0 : application ID */ - /* 0x0800 11 : secondary header: 0 = absent, 1 = present */ - /* 0x1000 12 : packet type: 0 = TLM, 1 = CMD */ - /* 0xE000 13 : CCSDS version: 0 = ver 1, 1 = ver 2 */ - - uint8 Sequence[2]; /* packet sequence word */ - /* bits shift ------------ description ---------------- */ - /* 0x3FFF 0 : sequence count */ - /* 0xC000 14 : segmentation flags: 3 = complete packet */ - - uint8 Length[2]; /* packet length word */ - /* bits shift ------------ description ---------------- */ - /* 0xFFFF 0 : (total packet length) - 7 */ - -} CCSDS_PriHdr_t; - -/*----- CCSDS command secondary header. -----*/ - -typedef struct { - - uint8 FunctionCode; /* Command Function Code */ - /* bits shift ---------description-------- */ - /* 0x7F 0 Command function code */ - /* 0x80 7 Reserved */ - - uint8 Checksum; /* Command checksum (all bits, 0xFF) */ - -} CCSDS_CmdSecHdr_t; - -/*----- CCSDS telemetry secondary header. -----*/ - -typedef struct { - - uint8 Time[CCSDS_TIME_SIZE]; - -} CCSDS_TlmSecHdr_t; - -/*----- CCSDS Endian Flag in the APID Qualifier Field. -----*/ -#define CCSDS_BIG_ENDIAN 0 -#define CCSDS_LITTLE_ENDIAN 1 -#define CCSDS_ENDIAN_MASK 0x0400 - -/*------ CCSDS packet playback Flag in the APID Qualifier Field. -------*/ -/* This field denotes that this packet is a playback of a stored packet */ -#define CCSDS_NON_PLAYBACK_PKT 0 -#define CCSDS_PLAYBACK_PKT 1 -#define CCSDS_PLAYBACK_PKT_MASK 0x0200 - -/*------ CCSDS packet Electronic Data Sheet version in the APID Qualifier Field. -------*/ -/* This is the verion of the data sheet that defines the packet payload format and other */ -/* metadata like unit conversions */ -#define CCSDS_EDS_MASK 0xF800 - -/*----- CCSDS Secondary Header APID Qualifers ----*/ -typedef struct { - - uint8 APIDQSubsystem[2]; - - /* bits shift ------------ description ---------------- */ - /* 0x01FF 0 : Subsystem Id mission defined */ - /* 0x0200 9 : Playback flag 0 = original, 1 = playback */ - /* 0x0400 10 : Endian: Big = 0, Little (Intel) = 1 */ - /* 0xF800 11 : EDS Version for packet definition used */ - - uint8 APIDQSystemId[2]; - /* 0xFFFF 0 : System Id mission defined */ - -} CCSDS_APIDqualifiers_t; - -/** - * \brief CCSDS Primary with APID Qualifier Header Type Definition - */ -typedef struct{ - CCSDS_PriHdr_t Pri;/**< \brief CCSDS Primary Header #CCSDS_PriHdr_t */ - CCSDS_APIDqualifiers_t ApidQ;/**< \brief CCSDS APID Qualifier Secondary Header #CCSDS_APIDqualifiers_t */ -}CCSDS_APIDQHdr_t; - -typedef struct -{ - /* - * In Version 1 mode, the standard / non-APID qualified header is used for all packets - */ - CCSDS_PriHdr_t Hdr; /**< Complete "version 1" (standard) header */ - -#ifdef MESSAGE_FORMAT_IS_CCSDS_VER_2 - - /* - * In Version 2 mode, the extended / APID qualified header is used for all packets - */ - CCSDS_APIDqualifiers_t ApidQ;/**< \brief CCSDS APID Qualifier Secondary Header #CCSDS_APIDqualifiers_t */ -#endif /* MESSAGE_FORMAT_IS_CCSDS_VER_2 */ - -} CCSDS_SpacePacket_t; - - - - -/*----- Generic combined command header. -----*/ - -typedef struct -{ - CCSDS_SpacePacket_t SpacePacket; /**< \brief Standard Header on all packets */ - CCSDS_CmdSecHdr_t Sec; -} CCSDS_CommandPacket_t; - -/*----- Generic combined telemetry header. -----*/ - -typedef struct -{ - CCSDS_SpacePacket_t SpacePacket; /**< \brief Standard Header on all packets */ - CCSDS_TlmSecHdr_t Sec; -} CCSDS_TelemetryPacket_t; +#include "cfe_msg_hdr.h" /* * COMPATIBILITY TYPEDEFS: - * These types were defined by CFE 6.5 and below and applications may still use them. * These typdefs provide compatibility for existing code. These should be * removed in the next CFE release. */ #ifndef CFE_OMIT_DEPRECATED_6_6 -typedef CCSDS_CommandPacket_t CCSDS_CmdPkt_t; -typedef CCSDS_TelemetryPacket_t CCSDS_TlmPkt_t; +typedef CFE_MSG_CommandHeader_t CCSDS_CmdPkt_t; +typedef CFE_MSG_TelemetryHeader_t CCSDS_TlmPkt_t; #endif /* CFE_OMIT_DEPRECATED_6_6 */ -/* -** Macro Definitions -*/ - -/********************************************************************** -** Constant values. -**********************************************************************/ - -/* Value of packet type for a telemetry packet. */ -#define CCSDS_TLM 0 -/* Value of packet type for a command packet. */ -#define CCSDS_CMD 1 - -/* Value of secondary header flag if secondary header not present. */ -#define CCSDS_NO_SEC_HDR 0 -/* Value of secondary header flag if secondary header exists. */ -#define CCSDS_HAS_SEC_HDR 1 - -#define NUM_CCSDS_APIDS 2048 -#define NUM_CCSDS_PKT_TYPES 2 - - -/********************************************************************** -** Initial values for CCSDS header fields. -**********************************************************************/ +#ifndef CFE_OMIT_DEPRECATED_6_8 -/* Initial value of the sequence count. */ -#define CCSDS_INIT_SEQ 0 -/* Initial value of the sequence flags. */ -#define CCSDS_INIT_SEQFLG 3 -/* Initial value of the command function code. */ -#define CCSDS_INIT_FC 0 -/* Initial value of the command checksum. */ -#define CCSDS_INIT_CHECKSUM 0 - -/* Note: the stream ID and length are always explicitly set for a packet, -** so default values are not required. */ - - -/********************************************************************** -** Macros for reading and writing bit fields in a 16-bit integer. -** These are used to implement the read and write macros below. -**********************************************************************/ - -/* Read bits specified by 'mask' from 'word' and shift down by 'shift'. */ -#define CCSDS_RD_BITS(word,mask,shift) \ - (((word) & mask) >> shift) - -/* Shift 'value' up by 'shift' and write to those bits in 'word' that -** are specified by 'mask'. Other bits in 'word' are unchanged. */ -#define CCSDS_WR_BITS(word,mask,shift,value) \ - ((word) = (uint16)(((word) & ~mask) | (((value) & (mask >> shift)) << shift))) - - -/********************************************************************** -** Macros for reading and writing the fields in a CCSDS header. All -** of the macros are used in a similar way: -** -** CCSDS_RD_xxx(header) -- Read field xxx from header. -** CCSDS_WR_xxx(header,value) -- Write value to field xxx of header. -** -** Note that 'header' is a reference to the actual header structure, -** not to a pointer to the structure. If using a pointer, one must -** refer to the structure as *pointer. -** -** The CCSDS_WR_xxx macros may refer to 'header' more than once; thus -** the expression for 'header' must NOT contain any side effects. -**********************************************************************/ - -/* Read entire stream ID from primary header. */ -#define CCSDS_RD_SID(phdr) (((phdr).StreamId[0] << 8) + ((phdr).StreamId[1])) -/* Write entire stream ID to primary header. */ -#define CCSDS_WR_SID(phdr,value) ( ((phdr).StreamId[0] = (value >> 8) ) ,\ - ((phdr).StreamId[1] = (value & 0xff) ) ) - -/* Read application ID from primary header. */ -#define CCSDS_RD_APID(phdr) (CCSDS_RD_SID(phdr) & 0x07FF) -/* Write application ID to primary header. */ -#define CCSDS_WR_APID(phdr,value) ((((phdr).StreamId[0] = ((phdr).StreamId[0] & 0xF8) | ((value >> 8) & 0x07))) ,\ - (((phdr).StreamId[1] = ((value)) & 0xff)) ) - -/* Read secondary header flag from primary header. */ -#define CCSDS_RD_SHDR(phdr) (((phdr).StreamId[0] & 0x08) >> 3) -/* Write secondary header flag to primary header. */ -#define CCSDS_WR_SHDR(phdr,value) ((phdr).StreamId[0] = ((phdr).StreamId[0] & 0xf7) | ((value << 3) & 0x08)) - -/* Read packet type (0=TLM,1=CMD) from primary header. */ -#define CCSDS_RD_TYPE(phdr) (((phdr).StreamId[0] & 0x10) >> 4) -/* Write packet type (0=TLM,1=CMD) to primary header. */ -#define CCSDS_WR_TYPE(phdr,value) ((phdr).StreamId[0] = ((phdr).StreamId[0] & 0xEF) | ((value << 4) & 0x10)) - -/* Read CCSDS version from primary header. */ -#define CCSDS_RD_VERS(phdr) (((phdr).StreamId[0] & 0xE0) >> 5) -/* Write CCSDS version to primary header. */ -#define CCSDS_WR_VERS(phdr,value) ((phdr).StreamId[0] = ((phdr).StreamId[0] & 0x1F) | ((value << 5) & 0xE0)) - -/* Read sequence count from primary header. */ -#define CCSDS_RD_SEQ(phdr) ((((phdr).Sequence[0] & 0x3F) << 8) + ((phdr).Sequence[1])) -/* Write sequence count to primary header. */ -#define CCSDS_WR_SEQ(phdr,value) ((((phdr).Sequence[0] = ((phdr).Sequence[0] & 0xC0) | ((value >> 8) & 0x3f))) ,\ - (((phdr).Sequence[1] = ((value)) & 0xff)) ) - -/* Read sequence flags from primary header. */ -#define CCSDS_RD_SEQFLG(phdr) (((phdr).Sequence[0] & 0xC0) >> 6) -/* Write sequence flags to primary header. */ -#define CCSDS_WR_SEQFLG(phdr,value) ((phdr).Sequence[0] = ((phdr).Sequence[0] & 0x3F) | ((value << 6) & 0xC0) ) - -/* Read total packet length from primary header. */ -#define CCSDS_RD_LEN(phdr) ( ( (phdr).Length[0] << 8) + (phdr).Length[1] + 7) -/* Write total packet length to primary header. */ -#define CCSDS_WR_LEN(phdr,value) ((((phdr).Length[0] = ((value) - 7) >> 8)) ,\ - (((phdr).Length[1] = ((value) - 7) & 0xff)) ) - -/* Read function code from command secondary header. */ -#define CCSDS_RD_FC(shdr) CCSDS_RD_BITS((shdr).FunctionCode, 0x7F, 0) -/* Write function code to command secondary header. */ -#define CCSDS_WR_FC(shdr,value) CCSDS_WR_BITS((shdr).FunctionCode, 0x7F, 0, value) - -/* Read checksum from command secondary header. */ -#define CCSDS_RD_CHECKSUM(shdr) ((shdr).Checksum) -/* Write checksum to command secondary header. */ -#define CCSDS_WR_CHECKSUM(shdr,val) ((shdr).Checksum = (val)) - -/* Define additional APID Qualifier macros. */ - -/* These macros will convert between local endianness and network endianness */ -/* The packet headers are always in network byte order */ -#define CCSDS_RD_EDS_VER(shdr) ( ((shdr).APIDQSubsystem[0] & 0xF8) >> 3) -#define CCSDS_RD_ENDIAN(shdr) ( ((shdr).APIDQSubsystem[0] & 0x04) >> 2) -#define CCSDS_RD_PLAYBACK(shdr) ( ((shdr).APIDQSubsystem[0] & 0x02) >> 1) -#define CCSDS_RD_SUBSYSTEM_ID(shdr) ( (((shdr).APIDQSubsystem[0] & 0x01) << 8) + ((shdr).APIDQSubsystem[1])) -#define CCSDS_RD_SYSTEM_ID(shdr) ( ((shdr).APIDQSystemId[0] << 8) + ((shdr).APIDQSystemId[1])) - -#define CCSDS_WR_EDS_VER(shdr,val) ( (shdr).APIDQSubsystem[0] = ((shdr).APIDQSubsystem[0] & 0x07) | (((val) & 0x1f) << 3) ) -#define CCSDS_WR_ENDIAN(shdr,val) ( (shdr).APIDQSubsystem[0] = ((shdr).APIDQSubsystem[0] & 0xFB) | (((val) & 0x01) << 2) ) -#define CCSDS_WR_PLAYBACK(shdr,val) ( (shdr).APIDQSubsystem[0] = ((shdr).APIDQSubsystem[0] & 0xFD) | (((val) & 0x01) << 1) ) - -#define CCSDS_WR_SUBSYSTEM_ID(shdr,val) (((shdr).APIDQSubsystem[0] = ((shdr).APIDQSubsystem[0] & 0xFE) | ((val & 0x0100) >> 8)) ,\ - ( (shdr).APIDQSubsystem[1] = (val & 0x00ff)) ) - -#define CCSDS_WR_SYSTEM_ID(shdr,val) (((shdr).APIDQSystemId[0] = ((val & 0xff00) >> 8)),\ - ( (shdr).APIDQSystemId[1] = (val & 0x00ff)) ) - -/********************************************************************** -** Macros for clearing a CCSDS header to a standard initial state. All -** of the macros are used in a similar way: -** CCSDS_CLR_xxx_HDR(header) -- Clear header of type xxx. -**********************************************************************/ - -/* Clear primary header. */ -#define CCSDS_CLR_PRI_HDR(phdr) \ - ( (phdr).StreamId[0] = 0,\ - (phdr).StreamId[1] = 0,\ - (phdr).Sequence[0] = (CCSDS_INIT_SEQFLG << 6),\ - (phdr).Sequence[1] = 0,\ - (phdr).Length[0] = 0, \ - (phdr).Length[1] = 0 ) - -#define CCSDS_CLR_SEC_APIDQ(shdr) \ - ( (shdr).APIDQSubsystem[0] = 0,\ - (shdr).APIDQSubsystem[1] = 0,\ - (shdr).APIDQSystemId[0] = 0,\ - (shdr).APIDQSystemId[1] = 0 ) - -/* Clear command secondary header. */ -#define CCSDS_CLR_CMDSEC_HDR(shdr) \ - ( (shdr).FunctionCode = CCSDS_INIT_FC,\ - (shdr).Checksum = CCSDS_INIT_CHECKSUM ) - - -#define CCSDS_WR_SEC_HDR_SEC(shdr, value) shdr.Time[0] = ((value>>24) & 0xFF), \ - shdr.Time[1] = ((value>>16) & 0xFF), \ - shdr.Time[2] = ((value>>8) & 0xFF), \ - shdr.Time[3] = ((value) & 0xFF) - -#define CCSDS_RD_SEC_HDR_SEC(shdr) (((uint32)shdr.Time[0]) << 24) | \ - (((uint32)shdr.Time[1]) << 16) | \ - (((uint32)shdr.Time[2]) << 8) | \ - ((uint32)shdr.Time[3]) - -/* Clear telemetry secondary header. */ -#if (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_16_SUBS) - /* 32 bits seconds + 16 bits subseconds */ - #define CCSDS_CLR_TLMSEC_HDR(shdr) \ - ( (shdr).Time[0] = 0,\ - (shdr).Time[1] = 0,\ - (shdr).Time[2] = 0,\ - (shdr).Time[3] = 0,\ - (shdr).Time[4] = 0,\ - (shdr).Time[5] = 0 ) - - -#define CCSDS_WR_SEC_HDR_SUBSEC(shdr, value) shdr.Time[4] = ((value>>8) & 0xFF), \ - shdr.Time[5] = ((value) & 0xFF) - -#define CCSDS_RD_SEC_HDR_SUBSEC(shdr) (((uint32)shdr.Time[4]) << 8) | \ - ((uint32)shdr.Time[5]) -#elif ((CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_SUBS) ||\ - (CFE_MISSION_SB_PACKET_TIME_FORMAT == CFE_MISSION_SB_TIME_32_32_M_20)) - /* 32 bits seconds + 32 bits subseconds */ - #define CCSDS_CLR_TLMSEC_HDR(shdr) \ - ( (shdr).Time[0] = 0,\ - (shdr).Time[1] = 0,\ - (shdr).Time[2] = 0,\ - (shdr).Time[3] = 0,\ - (shdr).Time[4] = 0,\ - (shdr).Time[5] = 0,\ - (shdr).Time[6] = 0,\ - (shdr).Time[7] = 0 ) - -#define CCSDS_WR_SEC_HDR_SUBSEC(shdr, value) shdr.Time[4] = ((value>>24) & 0xFF), \ - shdr.Time[5] = ((value>>16) & 0xFF), \ - shdr.Time[6] = ((value>>8) & 0xFF), \ - shdr.Time[7] = ((value) & 0xFF) +typedef struct{ + CCSDS_PrimaryHeader_t Pri; + CCSDS_ExtendedHeader_t ApidQ; +} CCSDS_APIDQHdr_t; +typedef CCSDS_ExtendedHeader_t CCSDS_APIDqualifiers_t; +typedef CCSDS_PrimaryHeader_t CCSDS_PriHdr_t; +typedef CFE_MSG_CommandSecondaryHeader_t CCSDS_CmdSecHdr_t; +typedef CFE_MSG_TelemetrySecondaryHeader_t CCSDS_TlmSecHdr_t; +typedef CFE_MSG_CommandHeader_t CCSDS_CommandPacket_t; /* Element names changed, direct access will break */ +typedef CFE_MSG_TelemetryHeader_t CCSDS_TelemetryPacket_t; /* Element names changed, direct access will break */ + +#endif /* CFE_OMIT_DEPRECATED_6_8 */ -#define CCSDS_RD_SEC_HDR_SUBSEC(shdr) (((uint32)shdr.Time[4]) << 24) | \ - (((uint32)shdr.Time[5]) << 16) | \ - (((uint32)shdr.Time[6]) << 8) | \ - ((uint32)shdr.Time[7]) +/* Macro to convert 16/32 bit types from platform "endianness" to Big Endian */ +#ifdef SOFTWARE_BIG_BIT_ORDER + #define CFE_MAKE_BIG16(n) (n) + #define CFE_MAKE_BIG32(n) (n) +#else + #define CFE_MAKE_BIG16(n) ( (((n) << 8) & 0xFF00) | (((n) >> 8) & 0x00FF) ) + #define CFE_MAKE_BIG32(n) ( (((n) << 24) & 0xFF000000) | (((n) << 8) & 0x00FF0000) | (((n) >> 8) & 0x0000FF00) | (((n) >> 24) & 0x000000FF) ) #endif - - -/********************************************************************** -** Macros for extracting fields from a stream ID. All of the macros -** are used in a similar way: -** -** CCSDS_SID_xxx(sid) -- Extract field xxx from sid. -**********************************************************************/ - -/* Extract application ID from stream ID. */ -#define CCSDS_SID_APID(sid) CCSDS_RD_BITS(sid, 0x07FF, 0) - -/* Extract secondary header flag from stream ID. */ -#define CCSDS_SID_SHDR(sid) CCSDS_RD_BITS(sid, 0x0800, 11) - -/* Extract packet type (0=TLM,1=CMD) from stream ID. */ -#define CCSDS_SID_TYPE(sid) CCSDS_RD_BITS(sid, 0x1000, 12) - -/* Extract CCSDS version from stream ID. */ -#define CCSDS_SID_VERS(sid) CCSDS_RD_BITS(sid, 0xE000, 13) - - -/********************************************************************** -** Macros for frequently used combinations of operations. -** -** CCSDS_INC_SEQ(phdr) -- Increment sequence count. -**********************************************************************/ - -/* Increment sequence count in primary header by 1. */ -#define CCSDS_INC_SEQ(phdr) \ - CCSDS_WR_SEQ(phdr, (CCSDS_RD_SEQ(phdr)+1)) - - -/*********************************************************************/ - -/* -** Exported Functions -*/ - - -/****************************************************************************** -** Function: CCSDS_LoadCheckSum() -** -** Purpose: -** Compute and load a checksum for a CCSDS command packet that has a -** secondary header. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. The checksum field in the packet -** will be modified. -** -** Return: -** (none) -*/ - -void CCSDS_LoadCheckSum (CCSDS_CommandPacket_t *PktPtr); - -/****************************************************************************** -** Function: CCSDS_ValidCheckSum() -** -** Purpose: -** Determine whether a checksum in a command packet is valid. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. -** -** Return: -** true if checksum of packet is valid; false if not. -** A valid checksum is 0. -*/ - -bool CCSDS_ValidCheckSum (CCSDS_CommandPacket_t *PktPtr); - -/****************************************************************************** -** Function: CCSDS_ComputeCheckSum() -** -** Purpose: -** Compute the checksum for a command packet. The checksum is the XOR of -** all bytes in the packet; a valid checksum is zero. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. -** -** Return: -** true if checksum of packet is valid; false if not. -*/ - -uint8 CCSDS_ComputeCheckSum (CCSDS_CommandPacket_t *PktPtr); - - #endif /* _ccsds_ */ -/*****************************************************************************/ diff --git a/fsw/cfe-core/src/inc/ccsds_hdr.h b/fsw/cfe-core/src/inc/ccsds_hdr.h new file mode 100644 index 000000000..c4d509d42 --- /dev/null +++ b/fsw/cfe-core/src/inc/ccsds_hdr.h @@ -0,0 +1,89 @@ +/* +** 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. +*/ + +/****************************************************************************** + * Define CCSDS packet header types + * - Avoid direct access for portability, use APIs + * - Used to construct message structures + */ + +#ifndef _ccsds_hdr_ +#define _ccsds_hdr_ + +/* + * Include Files + */ + +#include "common_types.h" +#include "cfe_mission_cfg.h" + +/* + * Type Definitions + */ + +/********************************************************************** + * Structure definitions for CCSDS headers. + * + * CCSDS headers must always be in network byte order per the standard. + * MSB at the lowest address which is commonly refered to as "BIG Endian" + * + */ + +/** + * \brief CCSDS packet primary header + */ +typedef struct { + + uint8 StreamId[2]; /**< \brief packet identifier word (stream ID) */ + /* bits shift ------------ description ---------------- */ + /* 0x07FF 0 : application ID */ + /* 0x0800 11 : secondary header: 0 = absent, 1 = present */ + /* 0x1000 12 : packet type: 0 = TLM, 1 = CMD */ + /* 0xE000 13 : CCSDS version: 0 = ver 1, 1 = ver 2 */ + + uint8 Sequence[2]; /**< \brief packet sequence word */ + /* bits shift ------------ description ---------------- */ + /* 0x3FFF 0 : sequence count */ + /* 0xC000 14 : segmentation flags: 3 = complete packet */ + + uint8 Length[2]; /**< \brief packet length word */ + /* bits shift ------------ description ---------------- */ + /* 0xFFFF 0 : (total packet length) - 7 */ + +} CCSDS_PrimaryHeader_t; + +/** + * \brief CCSDS packet extended header + */ +typedef struct { + + uint8 Subsystem[2]; /**< \brief subsystem qualifier */ + /* bits shift ------------ description ---------------- */ + /* 0x01FF 0 : Subsystem Id mission defined */ + /* 0x0200 9 : Playback flag 0 = original, 1 = playback */ + /* 0x0400 10 : Endian: Big = 0, Little (Intel) = 1 */ + /* 0xF800 11 : EDS Version for packet definition used */ + + uint8 SystemId[2]; /**< \brief system qualifier */ + /* 0xFFFF 0 : System Id mission defined */ + +} CCSDS_ExtendedHeader_t; + +#endif /* _ccsds_hdr_ */ diff --git a/fsw/cfe-core/src/inc/cfe.h b/fsw/cfe-core/src/inc/cfe.h index 530e7e52b..b58931d00 100644 --- a/fsw/cfe-core/src/inc/cfe.h +++ b/fsw/cfe-core/src/inc/cfe.h @@ -54,6 +54,8 @@ #include "cfe_time.h" /* Define Time Service API */ #include "cfe_tbl.h" /* Define Table Service API */ +#include "cfe_msg_api.h" /* Define Message API */ + #include "cfe_psp.h" /* Define Platform Support Package API */ #endif /* _cfe_ */ diff --git a/fsw/cfe-core/src/inc/cfe_sb.h b/fsw/cfe-core/src/inc/cfe_sb.h index 7f92c3794..54ccd2dab 100644 --- a/fsw/cfe-core/src/inc/cfe_sb.h +++ b/fsw/cfe-core/src/inc/cfe_sb.h @@ -146,24 +146,19 @@ ** Type Definitions */ -/** \brief Generic Software Bus Message Type Definition */ -typedef union { - CCSDS_PriHdr_t Hdr; /**< \brief CCSDS Primary Header #CCSDS_PriHdr_t */ - CCSDS_SpacePacket_t SpacePacket; - uint32 Dword; /**< \brief Forces minimum of 32-bit alignment for this object */ - uint8 Byte[sizeof(CCSDS_PriHdr_t)]; /**< \brief Allows byte-level access */ -}CFE_SB_Msg_t; +/** \brief Software Bus generic message */ +typedef CFE_MSG_Message_t CFE_SB_Msg_t; -/** \brief Generic Software Bus Command Header Type Definition */ +/** \brief Aligned Software Bus command header */ typedef union { - CCSDS_CommandPacket_t Cmd; - CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */ + CFE_MSG_CommandHeader_t Cmd; + CFE_SB_Msg_t BaseMsg; } CFE_SB_CmdHdr_t; -/** \brief Generic Software Bus Telemetry Header Type Definition */ +/** \brief Aligned Software Bus telemetry header */ typedef union { - CCSDS_TelemetryPacket_t Tlm; - CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */ + CFE_MSG_TelemetryHeader_t Tlm; + CFE_SB_Msg_t BaseMsg; } CFE_SB_TlmHdr_t; #define CFE_SB_CMD_HDR_SIZE (sizeof(CFE_SB_CmdHdr_t))/**< \brief Size of #CFE_SB_CmdHdr_t in bytes */ @@ -1313,7 +1308,7 @@ void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr); ** ** \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. +** include a checksum field this routine will always return false. ** ** \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. @@ -1432,6 +1427,7 @@ static inline CFE_SB_MsgId_t CFE_SB_ValueToMsgId(CFE_SB_MsgId_Atom_t MsgIdValue) /*****************************************************************************/ /** * \brief Identifies packet type given message ID + * * Provides the packet type associated with the given message ID * diff --git a/fsw/cfe-core/src/sb/ccsds.c b/fsw/cfe-core/src/sb/ccsds.c deleted file mode 100644 index 02317f71d..000000000 --- a/fsw/cfe-core/src/sb/ccsds.c +++ /dev/null @@ -1,122 +0,0 @@ -/* -** 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. -*/ - -/****************************************************************************** -** File: ccsds.c -** -** Purpose: -** Functions for working with CCSDS headers. -** -******************************************************************************/ - -/* -** Include Files -*/ - -#include "common_types.h" -#include "ccsds.h" -#include "osapi.h" -#include "cfe_psp.h" - -/****************************************************************************** -** Function: CCSDS_LoadCheckSum() -** -** Purpose: -** Compute and load a checksum for a CCSDS command packet that has a -** secondary header. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. The checksum field in the packet -** will be modified. -** -** Return: -** (none) -*/ - -void CCSDS_LoadCheckSum (CCSDS_CommandPacket_t *PktPtr) -{ - uint8 CheckSum; - - /* Clear the checksum field so the new checksum is correct. */ - CCSDS_WR_CHECKSUM(PktPtr->Sec, 0); - - /* Compute and load new checksum. */ - CheckSum = CCSDS_ComputeCheckSum(PktPtr); - CCSDS_WR_CHECKSUM(PktPtr->Sec, CheckSum); - -} /* END CCSDS_LoadCheckSum() */ - - -/****************************************************************************** -** Function: CCSDS_ValidCheckSum() -** -** Purpose: -** Determine whether a checksum in a command packet is valid. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. -** -** Return: -** true if checksum of packet is valid; false if not. -** A valid checksum is 0. -*/ - -bool CCSDS_ValidCheckSum (CCSDS_CommandPacket_t *PktPtr) -{ - - return (CCSDS_ComputeCheckSum(PktPtr) == 0); - -} /* END CCSDS_ValidCheckSum() */ - - -/****************************************************************************** -** Function: CCSDS_ComputeCheckSum() -** -** Purpose: -** Compute the checksum for a command packet. The checksum is the XOR of -** all bytes in the packet; a valid checksum is zero. -** -** Arguments: -** PktPtr : Pointer to header of command packet. The packet must -** have a secondary header and the length in the primary -** header must be correct. -** -** Return: -** true if checksum of packet is valid; false if not. -*/ - -uint8 CCSDS_ComputeCheckSum (CCSDS_CommandPacket_t *PktPtr) -{ - uint16 PktLen = CCSDS_RD_LEN(PktPtr->SpacePacket.Hdr); - uint8 *BytePtr = (uint8 *)PktPtr; - uint8 CheckSum; - - CheckSum = 0xFF; - while (PktLen--) CheckSum ^= *(BytePtr++); - - return CheckSum; - -} /* END CCSDS_ComputeCheckSum() */ - -/*****************************************************************************/ diff --git a/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c b/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c index 59fdb72f1..25595d7ea 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c +++ b/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c @@ -90,7 +90,7 @@ #include "osapi.h" #include "cfe_error.h" #include "cfe_sb_priv.h" -#include "cfe_sb_msg_id_util.h" +#include "cfe_msg_api.h" /****************************************************************************** @@ -120,34 +120,12 @@ CFE_SB_MsgKey_t CFE_SB_ConvertMsgIdtoMsgKey( CFE_SB_MsgId_t MsgId) */ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr) { - CFE_SB_MsgId_Atom_t MsgIdVal = 0; + CFE_SB_MsgId_t MsgId; -#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 - MsgIdVal = CCSDS_RD_SID(MsgPtr->Hdr); -#else + /* Ignore return since no alternative action */ + CFE_MSG_GetMsgId(MsgPtr, &MsgId); - uint32 SubSystemId; - - MsgIdVal = CCSDS_RD_APID(MsgPtr->Hdr); /* Primary header APID */ - - if ( CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_CMD) - MsgIdVal = MsgIdVal | CFE_SB_CMD_MESSAGE_TYPE; - - /* Add in the SubSystem ID as needed */ - SubSystemId = CCSDS_RD_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ); - MsgIdVal = (MsgIdVal | (SubSystemId << 8)); - -/* Example code to add in the System ID as needed. */ -/* The default is to init this field to the Spacecraft ID but ignore for routing. */ -/* To fully implement this field would require significant SB optimization to avoid */ -/* prohibitively large routing and index tables. */ -/* uint16 SystemId; */ -/* SystemId = CCSDS_RD_SYSTEM_ID(HdrPtr->ApidQ); */ -/* MsgIdVal = (MsgIdVal | (SystemId << 16)); */ - -#endif - -return CFE_SB_ValueToMsgId(MsgIdVal); + return MsgId; }/* end CFE_SB_GetMsgId */ @@ -158,32 +136,10 @@ return CFE_SB_ValueToMsgId(MsgIdVal); void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr, CFE_SB_MsgId_t MsgId) { - CFE_SB_MsgId_Atom_t MsgIdVal = CFE_SB_MsgIdToValue(MsgId); - -#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 - CCSDS_WR_SID(MsgPtr->Hdr, MsgIdVal); -#else - CCSDS_WR_VERS(MsgPtr->SpacePacket.Hdr, 1); - - /* Set the stream ID APID in the primary header. */ - CCSDS_WR_APID(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_APID_FROM_MSGID(MsgIdVal) ); - - CCSDS_WR_TYPE(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_TYPE_FROM_MSGID(MsgIdVal) ); - - - CCSDS_CLR_SEC_APIDQ(MsgPtr->SpacePacket.ApidQ); - - CCSDS_WR_EDS_VER(MsgPtr->SpacePacket.ApidQ, 1); - - CCSDS_WR_ENDIAN(MsgPtr->SpacePacket.ApidQ, CFE_PLATFORM_ENDIAN); - - CCSDS_WR_PLAYBACK(MsgPtr->SpacePacket.ApidQ, false); - - CCSDS_WR_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_SB_RD_SUBSYS_ID_FROM_MSGID(MsgIdVal)); - - CCSDS_WR_SYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_MISSION_SPACECRAFT_ID); - -#endif + + /* Ignore return, no alternate action */ + CFE_MSG_SetMsgId(MsgPtr, MsgId); + }/* end CFE_SB_SetMsgId */ /* @@ -192,31 +148,12 @@ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr, uint32 CFE_SB_GetPktType(CFE_SB_MsgId_t MsgId) { - CFE_SB_MsgId_Atom_t Val = CFE_SB_MsgIdToValue(MsgId); - uint8 PktType; - - if (CFE_SB_IsValidMsgId(MsgId)) - { -#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 - if (CFE_TST(Val,12)) - { - PktType = CFE_SB_PKTTYPE_CMD; - } else { - PktType = CFE_SB_PKTTYPE_TLM; - } -#else - if (CFE_SB_RD_TYPE_FROM_MSGID(Val) == 1) - { - PktType = CFE_SB_PKTTYPE_CMD; - } else { - PktType = CFE_SB_PKTTYPE_TLM; - } -#endif /* MESSAGE_FORMAT_IS_CCSDS_VER_2 */ - } else { - PktType = CFE_SB_PKTTYPE_INVALID; - } - - return PktType; + CFE_MSG_Type_t type; + + /* Ignores return, no alternate action */ + CFE_MSG_GetTypeFromMsgId(MsgId, &type); + + return type; }/* end CFE_SB_GetPktType */ diff --git a/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.h b/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.h deleted file mode 100644 index 29b94ba9e..000000000 --- a/fsw/cfe-core/src/sb/cfe_sb_msg_id_util.h +++ /dev/null @@ -1,78 +0,0 @@ -/* -** 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. -*/ - -/****************************************************************************** -** File: cfe_sb_msg_id_util.h -** -** Purpose: -** This header file contains prototypes for private functions and type -** definitions for SB internal use. -** -** Author: J. Wilmot/NASA -** -******************************************************************************/ - -#ifndef _cfe_sb_msg_id_util_ -#define _cfe_sb_msg_id_util_ - -/* -** Includes -*/ -#include "common_types.h" - -/** -** For MESSAGE_FORMAT_IS_CCSDS_VER_2 the default layout of the message id is: -** 7 bits from the primary header APID -** 1 bit for the command/telemetry flag -** 0 bits from the Playback flag -** 8 bits from the secondary header APID qualifier (Subsystem) -** 0 bits from the secondary header APID qualifier as the System -** = 16 bits total -** -** Byte 1 Byte 0 -** 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 -** +-+-+-+-+-+-+-+-+|--------|+-+-+-+-+-+-+-+ -** | APID Qualifier |C/T flg | Pri Hdr APID | -** +-+-+-+-+-+-+-+-+|--------|+-+-+-+-+-+-+-+ -** This layout may be modified via the 4 macros -** CFE_SB_CMD_MESSAGE_TYPE, CFE_SB_RD_APID_FROM_MSGID -** CFE_SB_RD_SUBSYS_ID_FROM_MSGID and CFE_SB_RD_TYPE_FROM_MSGID -** -*/ - -/* -** Macro Definitions -*/ - -/* - * Mission defined bit used to indicate message is a command type. A 0 in this bit position indicates - * a telemetry message type. This bit is included in the message id. - */ -#define CFE_SB_CMD_MESSAGE_TYPE 0x00000080 /* 1 bit (position 7) for Cmd/Tlm */ - -/* - * Mission defined macros to extract message id fields from the primary and secondary headers -*/ -#define CFE_SB_RD_APID_FROM_MSGID(MsgId) (MsgId & 0x0000007F) /* 0-6(7) bits for Pri Hdr APID */ -#define CFE_SB_RD_SUBSYS_ID_FROM_MSGID(MsgId) ( (MsgId & 0x0000FF00) >> 8) /* bits 8-15(8) bits for APID Subsystem ID */ -#define CFE_SB_RD_TYPE_FROM_MSGID(MsgId) ( (MsgId & CFE_SB_CMD_MESSAGE_TYPE) >> 7) /* 1 Cmd/Tlm Bit (bit #7) */ - -#endif /* _cfe_sb_msg_id_util_ */ -/*****************************************************************************/ diff --git a/fsw/cfe-core/src/sb/cfe_sb_priv.c b/fsw/cfe-core/src/sb/cfe_sb_priv.c index f1b4a3724..1ae509dce 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_priv.c +++ b/fsw/cfe-core/src/sb/cfe_sb_priv.c @@ -80,12 +80,11 @@ #include "osapi.h" #include "private/cfe_private.h" #include "cfe_sb_priv.h" -#include "cfe_sb_msg_id_util.h" #include "cfe_sb.h" #include "ccsds.h" #include "cfe_error.h" #include "cfe_es.h" -#include "cfe_sb_msg_id_util.h" +#include "cfe_msg_api.h" #include /****************************************************************************** @@ -551,7 +550,7 @@ int32 CFE_SB_DuplicateSubscribeCheck(CFE_SB_MsgKey_t MsgKey, */ void CFE_SB_SetMsgSeqCnt(CFE_SB_MsgPtr_t MsgPtr,uint32 Count){ - CCSDS_WR_SEQ(MsgPtr->Hdr,Count); + CFE_MSG_SetSequenceCount(MsgPtr, Count); }/* end CFE_SB_SetMsgSeqCnt */ diff --git a/fsw/cfe-core/src/sb/cfe_sb_task.c b/fsw/cfe-core/src/sb/cfe_sb_task.c index b36d2f173..b9a85cccd 100644 --- a/fsw/cfe-core/src/sb/cfe_sb_task.c +++ b/fsw/cfe-core/src/sb/cfe_sb_task.c @@ -42,7 +42,6 @@ #include "cfe_psp.h" #include "cfe_es_msg.h" #include "cfe_sb_verify.h" -#include "cfe_sb_msg_id_util.h" #include /* Task Globals */ diff --git a/fsw/cfe-core/src/sb/cfe_sb_util.c b/fsw/cfe-core/src/sb/cfe_sb_util.c index abef9d505..1cc61fbc5 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_api.h" #include @@ -49,38 +50,10 @@ void CFE_SB_InitMsg(void *MsgPtr, uint16 Length, bool Clear ) { - uint16 SeqCount; - CCSDS_PriHdr_t *PktPtr; - - PktPtr = (CCSDS_PriHdr_t *) MsgPtr; - - /* Save the sequence count in case it must be preserved. */ - SeqCount = CCSDS_RD_SEQ(*PktPtr); - - /* Zero the entire packet if needed. */ - if (Clear) - { memset(MsgPtr, 0, Length); } - else /* Clear only the primary header. */ - { - CCSDS_CLR_PRI_HDR(*PktPtr); - } - - /* Set the length fields in the primary header. */ - CCSDS_WR_LEN(*PktPtr, Length); - - /* Always set the secondary header flag as CFS applications are required use it */ - CCSDS_WR_SHDR(*PktPtr, 1); - - CFE_SB_SetMsgId(MsgPtr, MsgId); - - /* Restore the sequence count if needed. */ - if (!Clear) - CCSDS_WR_SEQ(*PktPtr, SeqCount); - else - CCSDS_WR_SEQFLG(*PktPtr, CCSDS_INIT_SEQFLG); -} /* end CFE_SB_InitMsg */ + CFE_MSG_Init((CFE_MSG_Message_t *)MsgPtr, MsgId, Length, Clear); +} /* end CFE_SB_InitMsg */ /****************************************************************************** ** Function: CFE_SB_MsgHdrSize() @@ -97,27 +70,29 @@ void CFE_SB_InitMsg(void *MsgPtr, uint16 CFE_SB_MsgHdrSize(const CFE_SB_Msg_t *MsgPtr) { - uint16 size; - const CCSDS_PriHdr_t *HdrPtr; + uint16 size = 0; + bool hassechdr = false; + CFE_MSG_Type_t type = CFE_MSG_Type_Invalid; - HdrPtr = (const CCSDS_PriHdr_t *) MsgPtr; + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + CFE_MSG_GetType(MsgPtr, &type); /* if secondary hdr is not present... */ /* Since all cFE messages must have a secondary hdr this check is not needed */ - if(CCSDS_RD_SHDR(*HdrPtr) == 0){ - size = sizeof(CCSDS_PriHdr_t); - - }else if(CCSDS_RD_TYPE(*HdrPtr) == CCSDS_CMD){ - - size = CFE_SB_CMD_HDR_SIZE; - - }else{ - - size = CFE_SB_TLM_HDR_SIZE; - + if(!hassechdr) + { + size = sizeof(CCSDS_SpacePacket_t); + } + else if(type == CFE_MSG_Type_Cmd) + { + size = sizeof(CFE_SB_CmdHdr_t); + } + else if(type == CFE_MSG_Type_Tlm) + { + size = sizeof(CFE_SB_TlmHdr_t); } - return size; + return size; }/* end CFE_SB_MsgHdrSize */ @@ -142,10 +117,10 @@ void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr) */ uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr) { - uint16 TotalMsgSize; + uint32 TotalMsgSize; uint16 HdrSize; - TotalMsgSize = CFE_SB_GetTotalMsgLength(MsgPtr); + CFE_MSG_GetSize(MsgPtr, &TotalMsgSize); HdrSize = CFE_SB_MsgHdrSize(MsgPtr); return (TotalMsgSize - HdrSize); @@ -161,18 +136,23 @@ void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr, uint16 DataLength) HdrSize = CFE_SB_MsgHdrSize(MsgPtr); TotalMsgSize = HdrSize + DataLength; - CCSDS_WR_LEN(MsgPtr->Hdr,TotalMsgSize); + + CFE_MSG_SetSize(MsgPtr, TotalMsgSize); }/* end CFE_SB_SetUserDataLength */ - /* * Function: CFE_SB_GetTotalMsgLength - See API and header file for details */ uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr) { - return CCSDS_RD_LEN(MsgPtr->Hdr); + CFE_MSG_Size_t size; + + CFE_MSG_GetSize(MsgPtr, &size); + + /* Known bug that this API can't return maximum ccsds size */ + return (uint16)size; }/* end CFE_SB_GetTotalMsgLength */ @@ -183,7 +163,7 @@ uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr) void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength) { - CCSDS_WR_LEN(MsgPtr->Hdr,TotalLength); + CFE_MSG_SetSize(MsgPtr, TotalLength); }/* end CFE_SB_SetTotalMsgLength */ @@ -193,48 +173,9 @@ 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; + CFE_TIME_SysTime_t TimeFromMsg = {0}; - /* 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(MsgPtr, &TimeFromMsg); return TimeFromMsg; @@ -246,50 +187,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 +208,13 @@ 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 */ + CFE_MSG_FcnCode_t fc; - /* Cast the input pointer to a Cmd Msg pointer */ - CmdHdrPtr = (CFE_SB_CmdHdr_t *)MsgPtr; + CFE_MSG_GetFcnCode(MsgPtr, &fc); + + return fc; - return CCSDS_RD_FC(CmdHdrPtr->Cmd.Sec); }/* end CFE_SB_GetCmdCode */ @@ -329,60 +224,41 @@ 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_SetFcnCode(MsgPtr, CmdCode); }/* end CFE_SB_SetCmdCode */ - /* * Function: CFE_SB_GetChecksum - See API and header file for details */ uint16 CFE_SB_GetChecksum(CFE_SB_MsgPtr_t MsgPtr) { - CFE_SB_CmdHdr_t *CmdHdrPtr; + CFE_MSG_Type_t type = CFE_MSG_Type_Invalid; + bool hassechdr = false; + + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassechdr); + CFE_MSG_GetType(MsgPtr, &type); /* 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)){ + if((type == CFE_MSG_Type_Tlm)||(!hassechdr)) + { 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); + /* Byte access for now to avoid error if secondary doesn't contain checksum */ + return MsgPtr->Byte[sizeof(CCSDS_SpacePacket_t) + 1]; }/* end CFE_SB_GetChecksum */ - /* * Function: CFE_SB_GenerateChecksum - See API and header file for details */ 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 */ @@ -392,21 +268,14 @@ void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr) */ bool CFE_SB_ValidateChecksum(CFE_SB_MsgPtr_t MsgPtr) { + bool isvalid = false; - CCSDS_CommandPacket_t *CmdPktPtr; + CFE_MSG_ValidateChecksum(MsgPtr, &isvalid); - /* 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 isvalid; }/* end CFE_SB_ValidateChecksum */ - /* * Function: CFE_SB_MessageStringGet - See API and header file for details */ From 97682b8d0a671b035402dd419f6927d2db26c53f Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:51:57 -0400 Subject: [PATCH 3/4] Fix #711, SB unit test updates for msg module - Removes dependencies on old macros - Simplifies unit tests - Treats msg module as internal code for now (temporary) --- fsw/cfe-core/unit-test/CMakeLists.txt | 9 + fsw/cfe-core/unit-test/sb_UT.c | 534 ++++++++------------------ fsw/cfe-core/unit-test/ut_support.c | 2 +- fsw/cfe-core/ut-stubs/ut_sb_stubs.c | 2 +- 4 files changed, 176 insertions(+), 371 deletions(-) diff --git a/fsw/cfe-core/unit-test/CMakeLists.txt b/fsw/cfe-core/unit-test/CMakeLists.txt index 3c90521c4..ee10db8c4 100644 --- a/fsw/cfe-core/unit-test/CMakeLists.txt +++ b/fsw/cfe-core/unit-test/CMakeLists.txt @@ -26,6 +26,11 @@ add_library(ut_cfe-core_support STATIC ut_support.c ut_osprintf_stubs.c ) +target_include_directories(ut_cfe-core_support PUBLIC + ${cfe-core_MISSION_DIR}/src/es + ${cfe-core_MISSION_DIR}/src/evs + ${cfe-core_MISSION_DIR}/src/time + ${CMAKE_CURRENT_SOURCE_DIR}) # For each core module, generate the associated unit test # This is done by linking the stubs of every OTHER module with the @@ -67,6 +72,10 @@ foreach(MODULE ${CFE_CORE_MODULES}) ut_cfe-core_support ut_cfe-core_stubs ut_assert) + + # TODO short term hack for testing with new code + target_link_libraries(${UT_TARGET_NAME}_UT msg) + #target_link_libraries(${UT_TARGET_NAME}_UT mission_msg) add_test(${UT_TARGET_NAME}_UT ${UT_TARGET_NAME}_UT) install(TARGETS ${UT_TARGET_NAME}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) diff --git a/fsw/cfe-core/unit-test/sb_UT.c b/fsw/cfe-core/unit-test/sb_UT.c index 2f2ffcf1a..c93b3e8d5 100644 --- a/fsw/cfe-core/unit-test/sb_UT.c +++ b/fsw/cfe-core/unit-test/sb_UT.c @@ -39,6 +39,7 @@ ** Includes */ #include "sb_UT.h" +#include "cfe_msg_api.h" /* * A method to add an SB "Subtest" @@ -136,122 +137,9 @@ void UtTest_Setup(void) UT_ADD_TEST(Test_SB_Utils); Test_SB_SpecialCases(); - Test_SB_Macros(); } /* end main */ -/* -** Function for calling SB and CCSDS Macros -** test functions -*/ -void Test_SB_Macros(void) -{ - SB_UT_ADD_SUBTEST(Test_SB_CCSDSPriHdr_Macros); - SB_UT_ADD_SUBTEST(Test_SB_CCSDSSecHdr_Macros); -} /* end Test_SB_Macros */ - -/* -**Test_SB_CCSDSSecHdr_Macros -*/ -void Test_SB_CCSDSSecHdr_Macros(void) -{ - CFE_SB_CmdHdr_t NoParamPkt; - - CCSDS_CLR_CMDSEC_HDR(NoParamPkt.Cmd.Sec); - CCSDS_WR_FC(NoParamPkt.Cmd.Sec, 1); - - ASSERT_TRUE(CCSDS_RD_FC(NoParamPkt.Cmd.Sec) == 0x01); - - CCSDS_CLR_CMDSEC_HDR(NoParamPkt.Cmd.Sec); - CCSDS_WR_CHECKSUM(NoParamPkt.Cmd.Sec, 0xFF); - - ASSERT_TRUE(CCSDS_RD_CHECKSUM(NoParamPkt.Cmd.Sec) == 0xFF); - - -#ifdef MESSAGE_FORMAT_IS_CCSDS_VER_2 - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_EDS_VER(NoParamPkt.Cmd.SpacePacket.ApidQ, 0x01); - - ASSERT_TRUE(CCSDS_RD_EDS_VER(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0x01); - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_ENDIAN(NoParamPkt.Cmd.SpacePacket.ApidQ, 0x01); - - ASSERT_TRUE(CCSDS_RD_ENDIAN(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0x01); - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_PLAYBACK(NoParamPkt.Cmd.SpacePacket.ApidQ, 0x01); - - ASSERT_TRUE(CCSDS_RD_PLAYBACK(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0x01); - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_SUBSYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ, 0xFF); - - ASSERT_TRUE(CCSDS_RD_SUBSYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0xFF); - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_SUBSYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ, 0xFF); - - ASSERT_TRUE(CCSDS_RD_SUBSYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0xFF); - - CCSDS_CLR_SEC_APIDQ(NoParamPkt.Cmd.SpacePacket.ApidQ); - CCSDS_WR_SYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ, 0xFFFF); - - ASSERT_TRUE(CCSDS_RD_SYSTEM_ID(NoParamPkt.Cmd.SpacePacket.ApidQ) == 0xFFFF); - -#endif -} /* end Test_SB_CCSDSSecHdr_Macros */ - -/* -**Test_SB_CCSDSPriHdr_Macros -*/ -void Test_SB_CCSDSPriHdr_Macros(void) -{ - CFE_SB_Msg_t Msg; - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_SID(Msg.Hdr, 0x1899); - - ASSERT_TRUE(CCSDS_RD_SID(Msg.Hdr) == 0x1899); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_APID(Msg.Hdr, 0x07FF); - - ASSERT_TRUE(CCSDS_RD_APID(Msg.Hdr) == 0x07FF); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_SHDR(Msg.Hdr, 1); - - ASSERT_TRUE(CCSDS_RD_SHDR(Msg.Hdr) == 1); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_TYPE(Msg.Hdr, 1); - - ASSERT_TRUE(CCSDS_RD_TYPE(Msg.Hdr) == 1); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_VERS(Msg.Hdr, 1); - - ASSERT_TRUE(CCSDS_RD_VERS(Msg.Hdr) == 1); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_SEQ(Msg.Hdr, 0x3FFF); - - ASSERT_TRUE(CCSDS_RD_SEQ(Msg.Hdr) == 0x3FFF); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_SEQFLG(Msg.Hdr, 0x03); - - ASSERT_TRUE(CCSDS_RD_SEQFLG(Msg.Hdr) == 0x03); - - CCSDS_CLR_PRI_HDR(Msg.Hdr); - CCSDS_WR_LEN(Msg.Hdr, 0xFFFF); - - ASSERT_TRUE(CCSDS_RD_LEN(Msg.Hdr) == 0xFFFF); - -} /* end Test_SB_CCSDSPriHdr_Macros */ - /* ** Reset variable values and sockets prior to a test */ @@ -2658,7 +2546,6 @@ void Test_Unsubscribe_GetDestPtr(void) void Test_SendMsg_API(void) { SB_UT_ADD_SUBTEST(Test_SendMsg_NullPtr); - SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId); SB_UT_ADD_SUBTEST(Test_SendMsg_NoSubscribers); SB_UT_ADD_SUBTEST(Test_SendMsg_MaxMsgSizePlusOne); SB_UT_ADD_SUBTEST(Test_SendMsg_BasicSend); @@ -2673,7 +2560,6 @@ void Test_SendMsg_API(void) SB_UT_ADD_SUBTEST(Test_SendMsg_ZeroCopyReleasePtr); SB_UT_ADD_SUBTEST(Test_SendMsg_DisabledDestination); SB_UT_ADD_SUBTEST(Test_SendMsg_SendWithMetadata); - SB_UT_ADD_SUBTEST(Test_SendMsg_InvalidMsgId_ZeroCopy); SB_UT_ADD_SUBTEST(Test_SendMsg_MaxMsgSizePlusOne_ZeroCopy); SB_UT_ADD_SUBTEST(Test_SendMsg_NoSubscribers_ZeroCopy); } /* end Test_SendMsg_API */ @@ -2691,34 +2577,6 @@ void Test_SendMsg_NullPtr(void) } /* end Test_SendMsg_NullPtr */ -/* -** Test response to sending a message with an invalid ID -*/ -void Test_SendMsg_InvalidMsgId(void) -{ - SB_UT_Test_Tlm_t TlmPkt; - CFE_SB_MsgPtr_t TlmPktPtr = (CFE_SB_MsgPtr_t) &TlmPkt; - - CFE_SB_InitMsg(&TlmPkt, SB_UT_ALTERNATE_INVALID_MID, - sizeof(TlmPkt), true); - CFE_SB_SetMsgId(TlmPktPtr, CFE_SB_INVALID_MSG_ID); - - CCSDS_WR_APID(TlmPktPtr->Hdr, 0x7FF ); - -#ifdef MESSAGE_FORMAT_IS_CCSDS_VER_2 - - CCSDS_WR_SUBSYSTEM_ID(TlmPktPtr->SpacePacket.ApidQ, 0x7E ); - -#endif - - ASSERT_EQ(CFE_SB_SendMsg(TlmPktPtr), CFE_SB_BAD_ARGUMENT); - - EVTCNT(1); - - EVTSENT(CFE_SB_SEND_INV_MSGID_EID); - -} /* end Test_SendMsg_InvalidMsgId */ - /* ** Test response to sending a message which has no subscribers */ @@ -2784,24 +2642,26 @@ void Test_SendMsg_BasicSend(void) */ void Test_SendMsg_SequenceCount(void) { - CFE_SB_PipeId_t PipeId; - CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID; - CFE_SB_MsgPtr_t PtrToMsg; - SB_UT_Test_Tlm_t TlmPkt; - CFE_SB_MsgPtr_t TlmPktPtr = (CFE_SB_MsgPtr_t) &TlmPkt; - uint32 PipeDepth = 10; + CFE_SB_PipeId_t PipeId; + CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID; + CFE_SB_MsgPtr_t PtrToMsg; + SB_UT_Test_Tlm_t TlmPkt; + CFE_SB_MsgPtr_t TlmPktPtr = (CFE_SB_MsgPtr_t) &TlmPkt; + uint32 PipeDepth = 10; + CFE_MSG_SequenceCount_t SeqCnt; SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "SeqCntTestPipe")); CFE_SB_InitMsg(&TlmPkt, MsgId, sizeof(TlmPkt), true); SETUP(CFE_SB_Subscribe(MsgId, PipeId)); - CCSDS_WR_SEQ(TlmPktPtr->Hdr, 22); + CFE_MSG_SetSequenceCount(TlmPktPtr, 22); SETUP(CFE_SB_SendMsg(TlmPktPtr)); ASSERT(CFE_SB_RcvMsg(&PtrToMsg, PipeId, CFE_SB_PEND_FOREVER)); ASSERT_TRUE(PtrToMsg != NULL); - ASSERT_TRUE(CCSDS_RD_SEQ(PtrToMsg->Hdr) == 1); + CFE_MSG_GetSequenceCount(PtrToMsg, &SeqCnt); + ASSERT_EQ(SeqCnt, 1); ASSERT(CFE_SB_PassMsg(TlmPktPtr)); @@ -2809,7 +2669,8 @@ void Test_SendMsg_SequenceCount(void) ASSERT_TRUE(PtrToMsg != NULL); - ASSERT_TRUE(CCSDS_RD_SEQ(PtrToMsg->Hdr) == 22); + CFE_MSG_GetSequenceCount(PtrToMsg, &SeqCnt); + ASSERT_EQ(SeqCnt, 22); ASSERT(CFE_SB_SendMsg(TlmPktPtr)); @@ -2817,7 +2678,8 @@ void Test_SendMsg_SequenceCount(void) ASSERT_TRUE(PtrToMsg != NULL); - ASSERT_TRUE(CCSDS_RD_SEQ(PtrToMsg->Hdr) == 2); + CFE_MSG_GetSequenceCount(PtrToMsg, &SeqCnt); + ASSERT_EQ(SeqCnt, 2); EVTCNT(3); @@ -2833,7 +2695,8 @@ void Test_SendMsg_SequenceCount(void) SETUP(CFE_SB_RcvMsg(&PtrToMsg, PipeId, CFE_SB_PEND_FOREVER)); - ASSERT_EQ(CCSDS_RD_SEQ(PtrToMsg->Hdr), 4); + CFE_MSG_GetSequenceCount(PtrToMsg, &SeqCnt); + ASSERT_EQ(SeqCnt, 4); TEARDOWN(CFE_SB_DeletePipe(PipeId)); @@ -3020,6 +2883,7 @@ void Test_SendMsg_ZeroCopySend(void) CFE_SB_MsgPtr_t ZeroCpyMsgPtr = NULL; uint32 PipeDepth = 10; CFE_SB_ZeroCopyHandle_t ZeroCpyBufHndl = 0; + CFE_MSG_SequenceCount_t SeqCnt; SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "ZeroCpyTestPipe")); @@ -3033,7 +2897,7 @@ void Test_SendMsg_ZeroCopySend(void) else { CFE_SB_InitMsg(ZeroCpyMsgPtr, MsgId, sizeof(SB_UT_Test_Tlm_t), true); - CCSDS_WR_SEQ(ZeroCpyMsgPtr->Hdr, 22); + CFE_MSG_SetSequenceCount(ZeroCpyMsgPtr, 22); } /* Test response to a get pool information error */ @@ -3047,7 +2911,8 @@ void Test_SendMsg_ZeroCopySend(void) ASSERT_TRUE(PtrToMsg != NULL); - ASSERT_EQ(CCSDS_RD_SEQ(PtrToMsg->Hdr), 1); + CFE_MSG_GetSequenceCount(PtrToMsg, &SeqCnt); + ASSERT_EQ(SeqCnt, 1); EVTCNT(3); @@ -3069,7 +2934,8 @@ void Test_SendMsg_ZeroCopyPass(void) CFE_SB_MsgPtr_t ZeroCpyMsgPtr = NULL; uint32 PipeDepth = 10; CFE_SB_ZeroCopyHandle_t ZeroCpyBufHndl = 0; - uint16 Seq = 22; + CFE_MSG_SequenceCount_t ExpectedSeqCnt = 22; + CFE_MSG_SequenceCount_t ActualSeqCnt; SETUP(CFE_SB_CreatePipe(&PipeId, PipeDepth, "ZeroCpyPassTestPipe")); SETUP(CFE_SB_Subscribe(MsgId, PipeId)); @@ -3084,7 +2950,7 @@ void Test_SendMsg_ZeroCopyPass(void) else { CFE_SB_InitMsg(ZeroCpyMsgPtr, MsgId, sizeof(SB_UT_Test_Tlm_t), true); - CCSDS_WR_SEQ(ZeroCpyMsgPtr->Hdr, Seq); + CFE_MSG_SetSequenceCount(ZeroCpyMsgPtr, ExpectedSeqCnt); } /* Test response to a get pool information error */ @@ -3105,8 +2971,8 @@ void Test_SendMsg_ZeroCopyPass(void) } else { - UtAssert_True(CCSDS_RD_SEQ(PtrToMsg->Hdr) == Seq, "sequence count for send in sequence count test, exp=%d, act=%d", - Seq, CCSDS_RD_SEQ(PtrToMsg->Hdr)); + CFE_MSG_GetSequenceCount(PtrToMsg, &ActualSeqCnt); + ASSERT_EQ(ExpectedSeqCnt, ActualSeqCnt); } EVTCNT(3); @@ -3235,36 +3101,6 @@ void Test_SendMsg_SendWithMetadata(void) } /* end Test_SendMsg_SendWithMetadata */ -/* -** Test response to sending a message with an invalid ID and ZeroCopy is set -*/ -void Test_SendMsg_InvalidMsgId_ZeroCopy(void) -{ - SB_UT_Test_Tlm_t TlmPkt; - CFE_SB_MsgPtr_t TlmPktPtr; - - TlmPktPtr = CFE_SB_ZeroCopyGetPtr(sizeof(SB_UT_Test_Tlm_t), - (CFE_SB_ZeroCopyHandle_t *) &TlmPkt); - - if (TlmPktPtr == NULL) - { - UtAssert_Failed("Unexpected NULL pointer returned from ZeroCopyGetPtr"); - } - else - { - CFE_SB_InitMsg(TlmPktPtr, SB_UT_ALTERNATE_INVALID_MID, - sizeof(SB_UT_Test_Tlm_t), true); - ASSERT_EQ(CFE_SB_SendMsgFull(TlmPktPtr, CFE_SB_INCREMENT_TLM, - CFE_SB_SEND_ZEROCOPY), CFE_SB_BAD_ARGUMENT); - - } - - EVTCNT(1); - - EVTSENT(CFE_SB_SEND_INV_MSGID_EID); - -} /* end Test_SendMsg_InvalidMsgId_ZeroCopy */ - /* ** Test response to sending a message with the message size larger than allowed ** and ZeroCopy is set @@ -3741,66 +3577,31 @@ void Test_CFE_SB_InitMsg_False(void) */ void Test_CFE_SB_MsgHdrSize_Cmd(void) { - CCSDS_PriHdr_t * PktPtr; SB_UT_Test_Cmd_t testCmd; - CFE_SB_MsgPtr_t MsgPtr; - - MsgPtr = (CFE_SB_MsgPtr_t)&testCmd; - PktPtr = (CCSDS_PriHdr_t*)MsgPtr; + CFE_SB_MsgPtr_t MsgPtr = (CFE_SB_MsgPtr_t)&testCmd; /* Test for cmds w/sec hdr */ - - CFE_SB_InitMsg(MsgPtr, - SB_UT_CMD_MID, - sizeof(testCmd), - 0); - - - /* Set this to Command Type */ - CCSDS_WR_TYPE(*PktPtr, 1); - /* No sec hdr */ - CCSDS_WR_SHDR(*PktPtr, 1); - + CFE_SB_InitMsg(MsgPtr, SB_UT_CMD_MID, sizeof(testCmd), true); ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CFE_SB_CmdHdr_t)); /* Test for cmds wo/sec hdr */ - - /* Set this to Command Type */ - CCSDS_WR_TYPE(*PktPtr, 1); - /* No sec hdr */ - CCSDS_WR_SHDR(*PktPtr, 0); - - ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CCSDS_PriHdr_t)); + CFE_MSG_SetHasSecondaryHeader(MsgPtr, false); + ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CCSDS_SpacePacket_t)); } /* end Test_CFE_SB_MsgHdrSize */ void Test_CFE_SB_MsgHdrSize_Tlm(void) { - CCSDS_PriHdr_t * PktPtr; SB_UT_Test_Tlm_t testTlm; - CFE_SB_MsgPtr_t MsgPtr; + CFE_SB_MsgPtr_t MsgPtr = (CFE_SB_MsgPtr_t)&testTlm; /* Test for tlm w/sec hdr */ - MsgPtr = (CFE_SB_MsgPtr_t)&testTlm; - PktPtr = (CCSDS_PriHdr_t*)MsgPtr; - - CFE_SB_SetMsgId(MsgPtr, SB_UT_TLM_MID); - - /* Set this to Tlm Type */ - CCSDS_WR_TYPE(*PktPtr, 0); - CCSDS_WR_SHDR(*PktPtr, 1); - + CFE_SB_InitMsg(MsgPtr, SB_UT_TLM_MID, sizeof(testTlm), true); ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CFE_SB_TlmHdr_t)); - /* Test for tlm wo/sec hdr */ - CFE_SB_SetMsgId(MsgPtr, SB_UT_TLM_MID); - - /* Set this to Telemetry Type */ - CCSDS_WR_TYPE(*PktPtr, 0); - CCSDS_WR_SHDR(*PktPtr, 0); - - ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CCSDS_PriHdr_t)); + CFE_MSG_SetHasSecondaryHeader(MsgPtr, false); + ASSERT_EQ(CFE_SB_MsgHdrSize(MsgPtr), sizeof(CCSDS_SpacePacket_t)); } /* end Test_CFE_SB_MsgHdrSize_Tlm */ @@ -3831,19 +3632,20 @@ void Test_CFE_SB_GetUserData_Cmd(void) void Test_CFE_SB_GetUserData_CmdNoSecHdr(void) { SB_UT_TstPktWoSecHdr_t SBNoSecHdrPkt; - CFE_SB_MsgPtr_t SBNoSecHdrPktPtr = (CFE_SB_MsgPtr_t) &SBNoSecHdrPkt; + CFE_SB_MsgPtr_t SBNoSecHdrPktPtr = (CFE_SB_MsgPtr_t)&SBNoSecHdrPkt; uint8 *ActualAdrReturned; uint8 *ExpAdrReturned; /* Test address returned for cmd pkts wo/sec hdr */ - CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_CMD_MID); - CCSDS_WR_SHDR(*(CCSDS_PriHdr_t*)SBNoSecHdrPktPtr, 0); + CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_CMD_MID, sizeof(SBNoSecHdrPkt), true); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); + ActualAdrReturned = CFE_SB_GetUserData(SBNoSecHdrPktPtr); - ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + 6; + ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + sizeof(CCSDS_SpacePacket_t); UtAssert_True(ActualAdrReturned == ExpAdrReturned, "Address of data for commands without secondary header is " - "packet address + 6\n PktAddr %p, Rtn %p, Exp %p", + "packet address + CCSDS header(s)\n PktAddr %p, Rtn %p, Exp %p", (void *) SBNoSecHdrPktPtr, ActualAdrReturned, ExpAdrReturned); } /* end Test_CFE_SB_GetUserData */ @@ -3876,10 +3678,11 @@ void Test_CFE_SB_GetUserData_TlmNoSecHdr(void) uint8 *ExpAdrReturned; /* Test address returned for tlm pkts wo/sec hdr */ - CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_TLM_MID); - CCSDS_WR_SHDR(*(CCSDS_PriHdr_t*)SBNoSecHdrPktPtr, 0); + CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_TLM_MID, sizeof(SBNoSecHdrPkt), true); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); + ActualAdrReturned = CFE_SB_GetUserData(SBNoSecHdrPktPtr); - ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + sizeof(CCSDS_PriHdr_t); + ExpAdrReturned = (uint8 *) SBNoSecHdrPktPtr + sizeof(CCSDS_SpacePacket_t); UtAssert_True(ActualAdrReturned == ExpAdrReturned, "Address of data for telemetry packets without secondary " @@ -3897,7 +3700,8 @@ void Test_CFE_SB_SetGetMsgId(void) CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; CFE_SB_MsgId_t MsgIdReturned; CFE_SB_MsgId_t MsgIdSet; - uint32 i; + uint16 Value[] = {0, 0x700, 0x7FF /* Max */, 0x800 /* Invalid */, 0xFFFF /* Invalid */}; + int i; /* Test setting and getting the message ID of a message */ @@ -3917,21 +3721,70 @@ void Test_CFE_SB_SetGetMsgId(void) * all values */ - /* Looping through every value from 0 to 0xffff */ - for (i = 0; i <= 0xFFFF; i++) + /* Looping through values */ + for (i = 0; i < sizeof(Value)/sizeof(Value[0]); i++) { - MsgIdSet = CFE_SB_ValueToMsgId(i); + MsgIdSet = CFE_SB_ValueToMsgId(Value[i]); CFE_SB_SetMsgId(SBCmdPtr, MsgIdSet); MsgIdReturned = CFE_SB_GetMsgId(SBCmdPtr); - if (!CFE_SB_MsgId_Equal(MsgIdReturned, MsgIdSet)) + if (Value[i] < 0x800) { - break; + ASSERT_TRUE(CFE_SB_MsgId_Equal(MsgIdReturned, MsgIdSet)); } } } /* end Test_CFE_SB_SetGetMsgId */ +/* Local helper function for user data length tests */ +/* Runs standard tests given an initialized message */ +void Util_CFE_SB_SetGetUserDataLength(CFE_SB_Msg_t *MsgPtr, uint16 SecHdrSize) +{ + uint16 SetSize[] = {0, 1, 0x8000, 0 /* Max calculated */, 0xFFFF}; + uint16 SizeReturned; + uint16 ActualPktLenField; + uint16 ExpPktLenField; + int i; + bool checkrtn; + + /* Max valid value */ + if (SecHdrSize == 0) + { + SetSize[3] = 0xFFFF; + } + else + { + SetSize[3] = 0xFFFF - SecHdrSize + 1; + } + + for (i = 0; i < sizeof(SetSize)/sizeof(SetSize[0]); i++) + { + /* CCSDS requires >= 1 byte payload, less won't update size */ + /* Over max possible also won't update size */ + if ((SecHdrSize + SetSize[i] < 1) || (SetSize[i] + SecHdrSize > 0x10000)) + { + ExpPktLenField = UT_GetActualPktLenField(MsgPtr); + checkrtn = false; + } + else + { + ExpPktLenField = SecHdrSize + SetSize[i] - 1; + checkrtn = true; + } + + CFE_SB_SetUserDataLength(MsgPtr, SetSize[i]); + SizeReturned = CFE_SB_GetUserDataLength(MsgPtr); + ActualPktLenField = UT_GetActualPktLenField(MsgPtr); + + if (checkrtn) + { + ASSERT_EQ (SizeReturned, SetSize[i]); + } + ASSERT_EQ (ActualPktLenField, ExpPktLenField); + } + +} /* end Util_CFE_SB_SetGetUserDataLength */ + /* ** Test setting and getting the user data size of a message */ @@ -3939,55 +3792,25 @@ void Test_CFE_SB_SetGetUserDataLength_Cmd(void) { SB_UT_Test_Cmd_t SBCmd; CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; - int32 SetSize; - uint16 SizeReturned; - int16 ActualPktLenField; - int16 ExpPktLenField; - - /* CCSDS pkt length field = SecHdrSize + data - 1 */ - /* Loop through all pkt length values for cmd pkts w/sec hdr */ + /* Init cmd pkt w/ sec hdr */ CFE_SB_InitMsg(SBCmdPtr, SB_UT_CMD_MID, sizeof(SB_UT_Test_Cmd_t), true); - for (SetSize = 0; SetSize < 0x10000; SetSize++) - { - CFE_SB_SetUserDataLength(SBCmdPtr, SetSize); - SizeReturned = CFE_SB_GetUserDataLength(SBCmdPtr); - ActualPktLenField = UT_GetActualPktLenField(SBCmdPtr); - - ExpPktLenField = sizeof(CFE_SB_CmdHdr_t) + SetSize - sizeof(CCSDS_PriHdr_t) - 1; /* SecHdrSize + data - 1 */ - - ASSERT_EQ (SizeReturned, SetSize); - ASSERT_EQ (ActualPktLenField, ExpPktLenField); - } + /* Calculation for secondary header accounts for possible padding */ + Util_CFE_SB_SetGetUserDataLength(SBCmdPtr, sizeof(CFE_SB_CmdHdr_t) - sizeof(CCSDS_PrimaryHeader_t)); } /* end Test_CFE_SB_SetGetUserDataLength */ void Test_CFE_SB_SetGetUserDataLength_CmdNoSecHdr(void) { - SB_UT_TstPktWoSecHdr_t SBNoSecHdrPkt; + SB_UT_TstPktWoSecHdr_t SBNoSecHdrPkt = {0}; CFE_SB_MsgPtr_t SBNoSecHdrPktPtr = (CFE_SB_MsgPtr_t) &SBNoSecHdrPkt; - int32 SetSize; - uint16 SizeReturned; - int16 ActualPktLenField; - int16 ExpPktLenField; - /* Loop through all pkt length values for cmd pkts wo/sec hdr */ - memset(&SBNoSecHdrPkt, 0, sizeof(SBNoSecHdrPktPtr)); - CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_CMD_MID); - CCSDS_WR_SHDR(*(CCSDS_PriHdr_t*)SBNoSecHdrPktPtr, 0); - - for (SetSize = 0; SetSize < 0x10000; SetSize++) - { - CFE_SB_SetUserDataLength(SBNoSecHdrPktPtr, SetSize); - SizeReturned = CFE_SB_GetUserDataLength(SBNoSecHdrPktPtr); - ActualPktLenField = UT_GetActualPktLenField(SBNoSecHdrPktPtr); - ExpPktLenField = 0 + SetSize - 1; /* SecHdrSize + data - 1 */ - - ASSERT_EQ (SizeReturned, SetSize); - ASSERT_EQ (ActualPktLenField, ExpPktLenField); - } + /* Init cmd pkt w/o sec hdr */ + CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_CMD_MID, sizeof(SBNoSecHdrPkt), true); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); + Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, sizeof(CCSDS_SpacePacket_t) - sizeof(CCSDS_PrimaryHeader_t)); } /* end Test_CFE_SB_SetGetUserDataLength */ @@ -3995,25 +3818,12 @@ void Test_CFE_SB_SetGetUserDataLength_Tlm(void) { SB_UT_Test_Tlm_t SBTlm; CFE_SB_MsgPtr_t SBTlmPtr = (CFE_SB_MsgPtr_t) &SBTlm; - int32 SetSize; - uint16 SizeReturned; - int16 ActualPktLenField; - int16 ExpPktLenField; - /* Loop through all pkt length values for tlm pkts w/sec hdr */ + /* Init tlm pkts w/ sec hdr */ CFE_SB_InitMsg(SBTlmPtr, SB_UT_TLM_MID, sizeof(SB_UT_Test_Tlm_t), true); - for (SetSize = 0; SetSize < 0x10000; SetSize++) - { - CFE_SB_SetUserDataLength(SBTlmPtr, SetSize); - SizeReturned = CFE_SB_GetUserDataLength(SBTlmPtr); - ActualPktLenField = UT_GetActualPktLenField(SBTlmPtr); - - ExpPktLenField = sizeof(CCSDS_TelemetryPacket_t) + SetSize - sizeof(CCSDS_PriHdr_t) - 1; /* SecHdrSize + data - 1 */ - - ASSERT_EQ (SizeReturned, SetSize); - ASSERT_EQ (ActualPktLenField, ExpPktLenField); - } + /* Calculation for secondary header accounts for possible padding */ + Util_CFE_SB_SetGetUserDataLength(SBTlmPtr, sizeof(CFE_SB_TlmHdr_t) - sizeof(CCSDS_PrimaryHeader_t)); } /* end Test_CFE_SB_SetGetUserDataLength */ @@ -4021,27 +3831,12 @@ void Test_CFE_SB_SetGetUserDataLength_TlmNoSecHdr(void) { SB_UT_TstPktWoSecHdr_t SBNoSecHdrPkt; CFE_SB_MsgPtr_t SBNoSecHdrPktPtr = (CFE_SB_MsgPtr_t) &SBNoSecHdrPkt; - int32 SetSize; - uint16 SizeReturned; - int16 ActualPktLenField; - int16 ExpPktLenField; - - /* Loop through all pkt length values for tlm pkts wo/sec hdr */ - memset(&SBNoSecHdrPkt, 0, sizeof(SBNoSecHdrPktPtr)); - CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_TLM_MID); - - CCSDS_WR_SHDR(*(CCSDS_PriHdr_t*)SBNoSecHdrPktPtr, 0); - for (SetSize = 0; SetSize < 0x10000; SetSize++) - { - CFE_SB_SetUserDataLength(SBNoSecHdrPktPtr, SetSize); - SizeReturned = CFE_SB_GetUserDataLength(SBNoSecHdrPktPtr); - ActualPktLenField = UT_GetActualPktLenField(SBNoSecHdrPktPtr); - ExpPktLenField = 0 + SetSize - 1; /* SecHdrSize + data - 1 */ + /* Set up tlm pkts wo/sec hdr */ + CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_TLM_MID, sizeof(SBNoSecHdrPkt), true); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); - ASSERT_EQ (SizeReturned, SetSize); - ASSERT_EQ (ActualPktLenField, ExpPktLenField); - } + Util_CFE_SB_SetGetUserDataLength(SBNoSecHdrPktPtr, sizeof(CCSDS_SpacePacket_t) - sizeof(CCSDS_PrimaryHeader_t)); } /* end Test_CFE_SB_SetGetUserDataLength */ @@ -4050,29 +3845,38 @@ void Test_CFE_SB_SetGetUserDataLength_TlmNoSecHdr(void) */ void Test_CFE_SB_SetGetTotalMsgLength(void) { - SB_UT_Test_Cmd_t SBCmd; - CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; - int32 SetSize; - uint16 TotalMsgSizeReturned; - int16 ActualPktLenField; - int16 ExpPktLenField; + SB_UT_Test_Cmd_t SBCmd; + CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; - /* CCSDS pkt length field = TotalPktSize - 7 */ + /* Known bug CFE_SB_GetTotalMsgLength won't do max CCSDS size */ + uint32 SetSize[] = {0 /* Invalid */, 1 /* Invalid */, 7 /* Min */, 8000, 0xFFFF}; + uint16 TotalMsgSizeReturned; + uint16 ActualPktLenField; + uint16 ExpPktLenField; + int i; /* * Note this is no different for commands vs. telemetry vs. secondary header... * This consolidates all the separate test cases - testing for different header types is redundant. */ - CFE_SB_SetMsgId(SBCmdPtr, SB_UT_CMD_MID); + CFE_SB_InitMsg(SBCmdPtr, SB_UT_CMD_MID, sizeof(SBCmd), true); - for (SetSize = 0; SetSize < 0x10000; SetSize++) + for (i = 0; i < sizeof(SetSize)/sizeof(SetSize[0]); i++) { - CFE_SB_SetTotalMsgLength(SBCmdPtr, SetSize); + if (SetSize[i] < 7) /* Invalid size won't change packet value */ + { + ExpPktLenField = UT_GetActualPktLenField(SBCmdPtr); + } + else + { + ExpPktLenField = SetSize[i] - 7; /* TotalPktSize - 7 */ + } + + CFE_SB_SetTotalMsgLength(SBCmdPtr, SetSize[i]); TotalMsgSizeReturned = CFE_SB_GetTotalMsgLength(SBCmdPtr); ActualPktLenField = UT_GetActualPktLenField(SBCmdPtr); - ExpPktLenField = SetSize - 7; /* TotalPktSize - 7 */ - ASSERT_EQ (TotalMsgSizeReturned, SetSize); + ASSERT_EQ (TotalMsgSizeReturned, ExpPktLenField + 7); ASSERT_EQ (ActualPktLenField, ExpPktLenField); } @@ -4120,8 +3924,7 @@ void Test_CFE_SB_SetGetMsgTime_CmdNoSecHdr(void) /* Set MsgId */ CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_TLM_MID); - CCSDS_WR_SHDR(*(CCSDS_PriHdr_t*)SBNoSecHdrPktPtr, 0); - + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); SetTime.Seconds = 0x4321; SetTime.Subseconds = 0x8765; @@ -4180,7 +3983,7 @@ void Test_CFE_SB_SetGetMsgTime_TlmNoSecHdr(void) /* Set MsgId to 0x0005 */ CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_TLM_MID); - CCSDS_WR_SHDR(*((CCSDS_PriHdr_t*)SBNoSecHdrPktPtr), 0); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); SetTime.Seconds = 0x01234567; SetTime.Subseconds = 0x89abcdef; ASSERT_EQ(CFE_SB_SetMsgTime(SBNoSecHdrPktPtr, SetTime), CFE_SB_WRONG_MSG_TYPE); @@ -4239,38 +4042,35 @@ void Test_CFE_SB_TimeStampMsg(void) */ void Test_CFE_SB_SetGetCmdCode_Cmd(void) { - SB_UT_Test_Cmd_t SBCmd; - CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; - uint16 CmdCodeSet; - uint16 ExpCmdCode; - CCSDS_PriHdr_t *PktPtr; - - /* Loop through all cmd code values(plus a few invalid) for cmd - * pkts w/sec hdr - */ + SB_UT_Test_Cmd_t SBCmd; + CFE_SB_MsgPtr_t SBCmdPtr = (CFE_SB_MsgPtr_t) &SBCmd; + uint16 CmdCodeSet[] = {0, 1, 0x70, 0x7f /* Max */, 0x80 /* Invalid */, 0xFFFF /* Invalid */}; + uint16 ExpCmdCode; + int i; /* Set MsgId to all f's */ memset(SBCmdPtr, 0xff, sizeof(SBCmd)); + CFE_SB_InitMsg(SBCmdPtr, SB_UT_CMD_MID, sizeof(SB_UT_Test_Cmd_t), false); + CFE_MSG_SetHasSecondaryHeader(SBCmdPtr, true); - CFE_SB_InitMsg(SBCmdPtr, SB_UT_CMD_MID, sizeof(SB_UT_Test_Cmd_t), true); - - PktPtr = (CCSDS_PriHdr_t*)SBCmdPtr; - - CCSDS_WR_SHDR(*PktPtr,1); - - for (CmdCodeSet = 0; CmdCodeSet < 0x100; CmdCodeSet++) + for (i = 0; i < sizeof(CmdCodeSet)/sizeof(CmdCodeSet[0]); i++) { - ASSERT_EQ(CFE_SB_SetCmdCode(SBCmdPtr, CmdCodeSet), CFE_SUCCESS); - - /* GSFC CmdCode is the 7 LSBs of the 1st byte of cmd sec hdr */ - ExpCmdCode = CmdCodeSet & 0x007f; - - ASSERT_EQ(CFE_SB_GetCmdCode(SBCmdPtr), ExpCmdCode); - ASSERT_EQ(UT_GetActualCmdCodeField(SBCmdPtr), ExpCmdCode); + if (CmdCodeSet[i] <= 0x7f) /* Valid */ + { + ASSERT_EQ(CFE_SB_SetCmdCode(SBCmdPtr, CmdCodeSet[i]), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_GetCmdCode(SBCmdPtr), CmdCodeSet[i]); + ASSERT_EQ(UT_GetActualCmdCodeField(SBCmdPtr), CmdCodeSet[i]); + } + else /* Invalid */ + { + /* When invalid command code shouldn't change */ + ExpCmdCode = UT_GetActualCmdCodeField(SBCmdPtr); + ASSERT_EQ(CFE_SB_SetCmdCode(SBCmdPtr, CmdCodeSet[i]), CFE_SB_BAD_ARGUMENT); + ASSERT_EQ(CFE_SB_GetCmdCode(SBCmdPtr), ExpCmdCode); + ASSERT_EQ(UT_GetActualCmdCodeField(SBCmdPtr), ExpCmdCode); + } } - - } /* end Test_CFE_SB_SetGetCmdCode */ void Test_CFE_SB_SetGetCmdCode_NonCmd(void) @@ -4279,7 +4079,6 @@ void Test_CFE_SB_SetGetCmdCode_NonCmd(void) CFE_SB_MsgPtr_t SBTlmPtr = (CFE_SB_MsgPtr_t) &SBTlm; SB_UT_TstPktWoSecHdr_t SBNoSecHdrPkt; CFE_SB_MsgPtr_t SBNoSecHdrPktPtr = (CFE_SB_MsgPtr_t) &SBNoSecHdrPkt; - CCSDS_PriHdr_t *PktPtr; /* Loop through all cmd code values (plus a few invalid) for cmd * pkts wo/sec hdr @@ -4291,16 +4090,14 @@ void Test_CFE_SB_SetGetCmdCode_NonCmd(void) /* Set MsgId */ CFE_SB_SetMsgId(SBNoSecHdrPktPtr, SB_UT_CMD_MID); - PktPtr = (CCSDS_PriHdr_t*)SBNoSecHdrPktPtr; - CCSDS_WR_SHDR(*PktPtr,0); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); ASSERT_EQ(CFE_SB_SetCmdCode(SBNoSecHdrPktPtr, 11), CFE_SB_WRONG_MSG_TYPE); ASSERT_EQ(CFE_SB_GetCmdCode(SBNoSecHdrPktPtr), 0); CFE_SB_SetMsgId(SBTlmPtr, SB_UT_TLM_MID); - PktPtr = (CCSDS_PriHdr_t*)SBTlmPtr; - CCSDS_WR_SHDR(*PktPtr,1); + CFE_SB_SetMsgId(SBTlmPtr, true); ASSERT_EQ(CFE_SB_SetCmdCode(SBTlmPtr, 22), CFE_SB_WRONG_MSG_TYPE); ASSERT_EQ(CFE_SB_GetCmdCode(SBTlmPtr), 0); @@ -4326,7 +4123,7 @@ void Test_CFE_SB_ChecksumUtils_Cmd(void) #ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2 ExpRtnFrmGet = 0x2f; #else - ExpRtnFrmGet = 0x65; + ExpRtnFrmGet = 0x5D; #endif ASSERT_EQ(CFE_SB_GetChecksum(SBCmdPtr), ExpRtnFrmGet); @@ -4353,8 +4150,7 @@ void Test_CFE_SB_ChecksumUtils_CmdNoSecHdr(void) CFE_SB_InitMsg(SBNoSecHdrPktPtr, SB_UT_BARE_CMD_MID3, sizeof(SBNoSecHdrPkt), true); - - CCSDS_WR_SHDR( SBNoSecHdrPktPtr->Hdr, 0 ); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); /* Set checksum field */ CFE_SB_GenerateChecksum(SBNoSecHdrPktPtr); @@ -4368,7 +4164,7 @@ void Test_CFE_SB_ChecksumUtils_CmdNoSecHdr(void) */ SBNoSecHdrPktPtr->Byte[0] ^= 0x02; - CCSDS_WR_SHDR( SBNoSecHdrPktPtr->Hdr, 0 ); + CFE_MSG_SetHasSecondaryHeader(SBNoSecHdrPktPtr, false); ASSERT_TRUE(!CFE_SB_ValidateChecksum(SBNoSecHdrPktPtr)); } /* end 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 19c208306..7daac8d34 100644 --- a/fsw/cfe-core/unit-test/ut_support.c +++ b/fsw/cfe-core/unit-test/ut_support.c @@ -472,7 +472,7 @@ void UT_DisplayPkt(CFE_SB_MsgPtr_t ptr, uint32 size) */ int16 UT_GetActualPktLenField(CFE_SB_MsgPtr_t MsgPtr) { - return ( ( MsgPtr->Hdr.Length[0] << 8) + MsgPtr->Hdr.Length[1] ); + return ( ( MsgPtr->CCSDS.Pri.Length[0] << 8) + MsgPtr->CCSDS.Pri.Length[1] ); } /* diff --git a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c index 304d835c8..bfa2bdf89 100644 --- a/fsw/cfe-core/ut-stubs/ut_sb_stubs.c +++ b/fsw/cfe-core/ut-stubs/ut_sb_stubs.c @@ -928,7 +928,7 @@ void *CFE_SB_GetUserData(CFE_SB_MsgPtr_t MsgPtr) if (UT_Stub_CopyToLocal(UT_KEY(CFE_SB_GetUserData), &Result, sizeof(Result)) != sizeof(Result)) { BytePtr = (uint8 *)MsgPtr; - if (CCSDS_RD_TYPE(MsgPtr->Hdr) != CCSDS_TLM) + if ((MsgPtr->Byte[0] & 0x10) != 0) { HdrSize = CFE_SB_CMD_HDR_SIZE; } From 164c75e3e1c67175f1df43611e7cdd22b1a4746e Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:53:52 -0400 Subject: [PATCH 4/4] Fix #711, Add msg module unit test --- modules/msg/unit-test-coverage/CMakeLists.txt | 63 +++ modules/msg/unit-test-coverage/msg_UT.c | 55 ++ .../test_cfe_msg_ccsdsext.c | 424 ++++++++++++++++ .../test_cfe_msg_ccsdsext.h | 37 ++ .../test_cfe_msg_ccsdspri.c | 469 ++++++++++++++++++ .../test_cfe_msg_ccsdspri.h | 39 ++ .../test_cfe_msg_checksum.c | 90 ++++ .../test_cfe_msg_checksum.h | 33 ++ .../msg/unit-test-coverage/test_cfe_msg_fc.c | 105 ++++ .../msg/unit-test-coverage/test_cfe_msg_fc.h | 33 ++ .../unit-test-coverage/test_cfe_msg_init.c | 147 ++++++ .../unit-test-coverage/test_cfe_msg_init.h | 37 ++ .../unit-test-coverage/test_cfe_msg_msgid.h | 33 ++ .../test_cfe_msg_msgid_shared.c | 79 +++ .../test_cfe_msg_msgid_shared.h | 33 ++ .../test_cfe_msg_msgid_v1.c | 104 ++++ .../test_cfe_msg_msgid_v2.c | 116 +++++ .../unit-test-coverage/test_cfe_msg_time.c | 98 ++++ .../unit-test-coverage/test_cfe_msg_time.h | 33 ++ .../msg/unit-test-coverage/test_msg_ext_not.c | 85 ++++ modules/msg/unit-test-coverage/test_msg_not.c | 55 ++ modules/msg/unit-test-coverage/test_msg_not.h | 67 +++ .../msg/unit-test-coverage/test_msg_pri_not.c | 102 ++++ .../msg/unit-test-coverage/test_msg_prionly.c | 42 ++ .../msg/unit-test-coverage/test_msg_utils.c | 72 +++ .../msg/unit-test-coverage/test_msg_utils.h | 45 ++ 26 files changed, 2496 insertions(+) create mode 100644 modules/msg/unit-test-coverage/CMakeLists.txt create mode 100644 modules/msg/unit-test-coverage/msg_UT.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_checksum.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_checksum.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_fc.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_fc.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_init.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_init.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_time.c create mode 100644 modules/msg/unit-test-coverage/test_cfe_msg_time.h create mode 100644 modules/msg/unit-test-coverage/test_msg_ext_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_not.h create mode 100644 modules/msg/unit-test-coverage/test_msg_pri_not.c create mode 100644 modules/msg/unit-test-coverage/test_msg_prionly.c create mode 100644 modules/msg/unit-test-coverage/test_msg_utils.c create mode 100644 modules/msg/unit-test-coverage/test_msg_utils.h diff --git a/modules/msg/unit-test-coverage/CMakeLists.txt b/modules/msg/unit-test-coverage/CMakeLists.txt new file mode 100644 index 000000000..5449769c4 --- /dev/null +++ b/modules/msg/unit-test-coverage/CMakeLists.txt @@ -0,0 +1,63 @@ +################################################################## +# +# cFE unit test build recipe +# +# This CMake file contains the recipe for building the cFE unit tests. +# It is invoked from the parent directory when unit tests are enabled. +# +################################################################## + +# Unit test object library sources, options, and includes +add_library(ut_${DEP}_objs OBJECT ${${DEP}_SRC}) +target_compile_options(ut_${DEP}_objs PRIVATE ${UT_COVERAGE_COMPILE_FLAGS}) +target_include_directories(ut_${DEP}_objs PRIVATE + $) + +set (ut_${DEP}_tests + msg_UT.c + test_msg_utils.c + test_msg_not.c + test_msg_pri_not.c + test_cfe_msg_init.c + test_cfe_msg_ccsdspri.c + test_cfe_msg_msgid_shared.c + test_cfe_msg_checksum.c + test_cfe_msg_fc.c + test_cfe_msg_time.c + $) + +# Add extended header tests if appropriate +if (MISSION_INCLUDE_CCSDSEXT_HEADER) + list(APPEND ut_${DEP}_tests + test_msg_ext_not.c + test_cfe_msg_ccsdsext.c) +else (MISSION_INCLUDE_CCSDSEXT_HEADER) + list(APPEND ut_${DEP}_tests + test_msg_prionly.c) +endif (MISSION_INCLUDE_CCSDSEXT_HEADER) + +# Add the correct message id test +if (MISSION_MSGID_V2) + list(APPEND ut_${DEP}_tests + test_cfe_msg_msgid_v2.c) +else (MISSION_MSGID_V2) + list(APPEND ut_${DEP}_tests + test_cfe_msg_msgid_v1.c) +endif (MISSION_MSGID_V2) + +# Add executable +add_executable(${DEP}_UT ${ut_${DEP}_tests}) + +# Add include to get private defaults +target_include_directories(${DEP}_UT PRIVATE ../private_inc) + +# Also add the UT_COVERAGE_LINK_FLAGS to the link command +# This should enable coverage analysis on platforms that support this +target_link_libraries(${DEP}_UT + ${UT_COVERAGE_LINK_FLAGS} + ut_cfe-core_support + ut_cfe-core_stubs + ut_assert) + +add_test(${DEP}_UT ${DEP}_UT) +install(TARGETS ${DEP}_UT DESTINATION ${TGTNAME}/${UT_INSTALL_SUBDIR}) diff --git a/modules/msg/unit-test-coverage/msg_UT.c b/modules/msg/unit-test-coverage/msg_UT.c new file mode 100644 index 000000000..3b0359276 --- /dev/null +++ b/modules/msg/unit-test-coverage/msg_UT.c @@ -0,0 +1,55 @@ +/* +** 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 header unit tests + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_cfe_msg_init.h" +#include "test_cfe_msg_ccsdspri.h" +#include "test_cfe_msg_ccsdsext.h" +#include "test_cfe_msg_msgid_shared.h" +#include "test_cfe_msg_msgid.h" +#include "test_cfe_msg_fc.h" +#include "test_cfe_msg_checksum.h" +#include "test_cfe_msg_time.h" + +/* + * Functions + */ +void UtTest_Setup(void) +{ + UT_Init("msg"); + UT_Text("Message header coverage test..."); + + UT_ADD_TEST(Test_MSG_Init); + UT_ADD_TEST(Test_MSG_CCSDSPri); + UT_ADD_TEST(Test_MSG_CCSDSExt); + UT_ADD_TEST(Test_MSG_MsgId_Shared); + UT_ADD_TEST(Test_MSG_MsgId); + UT_ADD_TEST(Test_MSG_Checksum); + UT_ADD_TEST(Test_MSG_FcnCode); + UT_ADD_TEST(Test_MSG_Time); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c new file mode 100644 index 000000000..63b897f26 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.c @@ -0,0 +1,424 @@ +/* +** 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. +*/ + +/* + * Test CCSDS Extended header accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_ccsdsext.h" +#include "cfe_error.h" +#include "cfe_mission_cfg.h" +#include "cfe_platform_cfg.h" +#include "cfe_msg_defaults.h" +#include + +/* + * Defines + */ +#define TEST_EDSVER_MAX 0x1F /* Maximum value for EDS Version field */ +#define TEST_SUBSYS_MAX 0x1FF /* Maximum value for Subsystem field */ +#define TEST_SYSTEM_MAX 0xFFFF /* Maximum value for System field */ + +#define TEST_DEFAULT_SUBSYS_MASK 0x100 /* Bits that can be set by default subsys if msgid V2 */ + +/* Extended header initialization specific coverage */ +void Test_MSG_Init_Ext(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_Atom_t msgidval_exp; + CFE_MSG_HeaderVersion_t hdrver; + CFE_MSG_Subsystem_t subsys; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_System_t system; + CFE_MSG_Endian_t endian; + bool is_v1; + + /* Get msgid version by checking if msgid sets header version */ + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + is_v1 = (hdrver == 0); + + UT_Text("Set to all F's, msgid value = 0, and run with clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Default EDS version check */ + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &edsver), CFE_SUCCESS); + ASSERT_EQ(edsver, CFE_PLATFORM_EDSVER); + + /* Default subsystem check */ + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &subsys), CFE_SUCCESS); + if (is_v1) + ASSERT_EQ(subsys, CFE_PLATFORM_DEFAULT_SUBSYS); + else + ASSERT_EQ(subsys, CFE_PLATFORM_DEFAULT_SUBSYS & TEST_DEFAULT_SUBSYS_MASK); + + /* Default system check */ + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &system), CFE_SUCCESS); + ASSERT_EQ(system, CFE_MISSION_SPACECRAFT_ID); + + /* Default endian check */ + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &endian), CFE_SUCCESS); +#if (CFE_PLATFORM_ENDIAN == CCSDS_LITTLE_ENDIAN) + ASSERT_EQ(endian, CFE_MSG_Endian_Little); +#else + ASSERT_EQ(endian, CFE_MSG_Endian_Big); +#endif + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Ext_NotZero(&msg) & ~(MSG_EDSVER_FLAG | MSG_ENDIAN_FLAG | MSG_SUBSYS_FLAG | MSG_SYSTEM_FLAG), 0); + + UT_Text("Set to all 0, max msgid value, and run without clearing"); + memset(&msg, 0, sizeof(msg)); + msgidval_exp = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Default subsystem check */ + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &subsys), CFE_SUCCESS); + if (is_v1) + ASSERT_EQ(subsys, 0); + else + ASSERT_EQ(subsys, 0xFF); + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Ext_NotZero(&msg) & ~MSG_SUBSYS_FLAG, 0); +} + +void Test_MSG_EDSVersion(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_EDSVersion_t input[] = {0, TEST_EDSVER_MAX / 2, TEST_EDSVER_MAX}; + CFE_MSG_EDSVersion_t actual = TEST_EDSVER_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_EDSVER_MAX); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, TEST_EDSVER_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_EDSVER_MAX); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_EDSVER_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_EDSVER_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetEDSVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEDSVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_EDSVER_FLAG); + } + } +} + +void Test_MSG_Endian(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Endian_t input[] = {CFE_MSG_Endian_Big, CFE_MSG_Endian_Little}; + CFE_MSG_Endian_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_Endian_Invalid, CFE_MSG_Endian_Little + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEndian(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, CFE_MSG_Endian_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, CFE_MSG_Endian_Little + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Endian_Little); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Endian_Little) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_ENDIAN_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Endian_Big); + ASSERT_EQ(CFE_MSG_SetEndian(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetEndian(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Endian_Big) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_ENDIAN_FLAG); + } + } +} + +void Test_MSG_PlaybackFlag(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_PlaybackFlag_t input[] = {CFE_MSG_PlayFlag_Original, CFE_MSG_PlayFlag_Playback}; + CFE_MSG_PlaybackFlag_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_PlayFlag_Invalid, CFE_MSG_PlayFlag_Playback + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, CFE_MSG_PlayFlag_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, CFE_MSG_PlayFlag_Playback + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_PlayFlag_Playback); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_PlayFlag_Playback) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_PBACK_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_PlayFlag_Original); + ASSERT_EQ(CFE_MSG_SetPlaybackFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetPlaybackFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_PlayFlag_Original) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_PBACK_FLAG); + } + } +} + +void Test_MSG_Subsystem(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Subsystem_t input[] = {0, TEST_SUBSYS_MAX / 2, TEST_SUBSYS_MAX}; + CFE_MSG_Subsystem_t actual = TEST_SUBSYS_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SUBSYS_MAX); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, TEST_SUBSYS_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SUBSYS_MAX); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SUBSYS_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SUBSYS_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSubsystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSubsystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SUBSYS_FLAG); + } + } +} + +void Test_MSG_System(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_SYSTEM_MAX / 2, TEST_SYSTEM_MAX}; + CFE_MSG_ApId_t actual = TEST_SYSTEM_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SYSTEM_MAX); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSystem(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SYSTEM_MAX); + ASSERT_EQ(CFE_MSG_SetSystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SYSTEM_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SYSTEM_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSystem(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSystem(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SYSTEM_FLAG); + } + } +} + +/* + * Test MSG ccsdsext + */ +void Test_MSG_CCSDSExt(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_Init_Ext); + MSG_UT_ADD_SUBTEST(Test_MSG_EDSVersion); + MSG_UT_ADD_SUBTEST(Test_MSG_Endian); + MSG_UT_ADD_SUBTEST(Test_MSG_PlaybackFlag); + MSG_UT_ADD_SUBTEST(Test_MSG_Subsystem); + MSG_UT_ADD_SUBTEST(Test_MSG_System); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h new file mode 100644 index 000000000..d1c416432 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdsext.h @@ -0,0 +1,37 @@ +/* +** 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. +*/ + +/* + * cfe_msg_ccsdsext test header + */ +#ifndef test_cfe_msg_ccsdsext_ +#define test_cfe_msg_ccsdsext_ + +/* + * Defines + */ + +/* + * Functions + */ +/* Test CCSDS Extended header accessor functions */ +void Test_MSG_CCSDSExt(void); + +#endif /* test_cfe_msg_ccsdsext_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c new file mode 100644 index 000000000..104c2955c --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.c @@ -0,0 +1,469 @@ +/* +** 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. +*/ + +/* + * Test CCSDS Primary header accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_ccsdspri.h" +#include "cfe_error.h" +#include + +/* + * Defines + */ +#define TEST_CCSDSVER_MAX 7 /* Maximum value for CCSDS Version field */ +#define TEST_APID_MAX 0x7FF /* Maximum value for CCSDS ApId field */ +#define TEST_SEQUENCE_MAX 0x3FFF /* Maximum value for CCSDS Sequence field */ + +void Test_MSG_Size(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Size_t input[] = {TEST_MSG_SIZE_OFFSET, 0x8000, 0xFFFF, 0xFFFF + TEST_MSG_SIZE_OFFSET}; + CFE_MSG_Size_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (0, min valid - 1, max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetSize(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, TEST_MSG_SIZE_OFFSET - 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0xFFFF + TEST_MSG_SIZE_OFFSET + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSize(&msg, 0xFFFFFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0xFFFF + TEST_MSG_SIZE_OFFSET); + ASSERT_EQ(CFE_MSG_SetSize(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0xFFFF + TEST_MSG_SIZE_OFFSET) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_LENGTH_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_MSG_SIZE_OFFSET); + ASSERT_EQ(CFE_MSG_SetSize(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_MSG_SIZE_OFFSET) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_LENGTH_FLAG); + } + } +} + +void Test_MSG_Type(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_Type_t input[] = {CFE_MSG_Type_Cmd, CFE_MSG_Type_Tlm}; + CFE_MSG_Type_t actual = 0; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (CFE_MSG_Type_Invalid, CFE_MSG_Type_Tlm + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_GetType(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetType(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + ASSERT_EQ(CFE_MSG_SetType(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Type_Cmd) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_TYPE_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); + ASSERT_EQ(CFE_MSG_SetType(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetType(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_Type_Tlm) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + } + } +} + +void Test_MSG_HeaderVersion(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_HeaderVersion_t input[] = {0, TEST_CCSDSVER_MAX / 2, TEST_CCSDSVER_MAX}; + CFE_MSG_HeaderVersion_t actual = TEST_CCSDSVER_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_CCSDSVER_MAX); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, TEST_CCSDSVER_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_CCSDSVER_MAX); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_CCSDSVER_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HDRVER_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetHeaderVersion(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HDRVER_FLAG); + } + } +} + +void Test_MSG_HasSecondaryHeader(void) +{ + CFE_MSG_Message_t msg; + bool actual = true; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(NULL, false), CFE_MSG_BAD_ARGUMENT); + + UT_Text("Set to all F's, true and false inputs"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HASSEC_FLAG); + + UT_Text("Set to all 0, true and false inputs"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(&msg, true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HASSEC_FLAG); +} + +void Test_MSG_ApId(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_APID_MAX / 2, TEST_APID_MAX}; + CFE_MSG_ApId_t actual = TEST_APID_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_APID_MAX); + ASSERT_EQ(CFE_MSG_GetApId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetApId(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetApId(&msg, TEST_APID_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetApId(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_APID_MAX); + ASSERT_EQ(CFE_MSG_SetApId(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_APID_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_APID_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetApId(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + } + } +} + +void Test_MSG_SegmentationFlag(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_SegmentationFlag_t input[] = {CFE_MSG_SegFlag_Continue, CFE_MSG_SegFlag_First, CFE_MSG_SegFlag_Last, + CFE_MSG_SegFlag_Unsegmented}; + CFE_MSG_SegmentationFlag_t actual = CFE_MSG_SegFlag_Invalid; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (*_Invalid, max valid + 1"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Invalid); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, CFE_MSG_SegFlag_Invalid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, CFE_MSG_SegFlag_Unsegmented + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Unsegmented); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_SegFlag_Unsegmented) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SEGMENT_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_SegFlag_Continue); + ASSERT_EQ(CFE_MSG_SetSegmentationFlag(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == CFE_MSG_SegFlag_Continue) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SEGMENT_FLAG); + } + } +} + +void Test_MSG_SequenceCount(void) +{ + CFE_MSG_Message_t msg; + CFE_MSG_ApId_t input[] = {0, TEST_SEQUENCE_MAX / 2, TEST_SEQUENCE_MAX}; + CFE_MSG_ApId_t actual = TEST_SEQUENCE_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1, max)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_SEQUENCE_MAX); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, TEST_SEQUENCE_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_SEQUENCE_MAX); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == TEST_SEQUENCE_MAX) + { + ASSERT_EQ(Test_MSG_NotF(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_SEQUENCE_FLAG); + } + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetSequenceCount(&msg, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSequenceCount(&msg, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + if (input[i] == 0) + { + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + } + else + { + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_SEQUENCE_FLAG); + } + } +} + +/* + * Test MSG ccsdspri + */ +void Test_MSG_CCSDSPri(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_Size); + MSG_UT_ADD_SUBTEST(Test_MSG_Type); + MSG_UT_ADD_SUBTEST(Test_MSG_HeaderVersion); + MSG_UT_ADD_SUBTEST(Test_MSG_HasSecondaryHeader); + MSG_UT_ADD_SUBTEST(Test_MSG_ApId); + MSG_UT_ADD_SUBTEST(Test_MSG_SegmentationFlag); + MSG_UT_ADD_SUBTEST(Test_MSG_SequenceCount); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h new file mode 100644 index 000000000..c85e21961 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_ccsdspri.h @@ -0,0 +1,39 @@ +/* +** 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. +*/ + +/* + * cfe_msg_ccsdspri test header + */ +#ifndef test_cfe_msg_ccsdspri_ +#define test_cfe_msg_ccsdspri_ + +/* + * Defines + */ + +#define TEST_MSG_SIZE_OFFSET 7 /* CCSDS Message length offset */ + +/* + * Functions + */ +/* Test CCSDS Primary header accessor functions */ +void Test_MSG_CCSDSPri(void); + +#endif /* test_cfe_msg_ccsdspri_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c new file mode 100644 index 000000000..5b3b433c5 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.c @@ -0,0 +1,90 @@ +/* +** 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. +*/ + +/* + * Test checksum accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_checksum.h" +#include "cfe_error.h" +#include + +void Test_MSG_Checksum(void) +{ + CFE_SB_CmdHdr_t cmd; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd; + bool actual; + + UT_Text("Bad parameter tests, Null pointers"); + memset(&cmd, 0, sizeof(cmd)); + actual = true; + ASSERT_EQ(CFE_MSG_GenerateChecksum(NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_ValidateChecksum(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + + UT_Text("Bad message, no secondary header"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + + UT_Text("Bad message, wrong type (telemetry)"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, true); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + + UT_Text("Set to all F's, validate/generate/validate"); + memset(&cmd, 0xFF, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetSize(msgptr, sizeof(cmd)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotF(msgptr), MSG_LENGTH_FLAG); + + UT_Text("Set to all 0 except secheader and type, validate/generate/validate"); + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetSize(msgptr, sizeof(cmd)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, false); + ASSERT_EQ(CFE_MSG_GenerateChecksum(msgptr), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_ValidateChecksum(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, true); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_LENGTH_FLAG | MSG_HASSEC_FLAG | MSG_TYPE_FLAG); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h new file mode 100644 index 000000000..5b521fe7f --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_checksum.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_checksum test header + */ +#ifndef test_cfe_msg_checksum_ +#define test_cfe_msg_checksum_ + +/* + * Functions + */ +/* Test checksum accessor functions */ +void Test_MSG_Checksum(void); + +#endif /* test_cfe_msg_checksum_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_fc.c b/modules/msg/unit-test-coverage/test_cfe_msg_fc.c new file mode 100644 index 000000000..062a1d908 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_fc.c @@ -0,0 +1,105 @@ +/* +** 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. +*/ + +/* + * Test function code accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_fc.h" +#include "cfe_error.h" +#include + +/* + * Defines + */ +#define TEST_FCNCODE_MAX 0x7F /* Maximum value for fc field */ + +void Test_MSG_FcnCode(void) +{ + CFE_SB_CmdHdr_t cmd; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&cmd; + CFE_MSG_FcnCode_t input[] = {0, TEST_FCNCODE_MAX / 2, TEST_FCNCODE_MAX}; + CFE_MSG_FcnCode_t actual = TEST_FCNCODE_MAX; + int i; + + UT_Text("Bad parameter tests, Null pointers, invalid (max valid + 1, max)"); + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual, TEST_FCNCODE_MAX); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, TEST_FCNCODE_MAX + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + + UT_Text("Bad message, no secondary header"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + + UT_Text("Bad message, wrong type (telemetry)"); + memset(&cmd, 0, sizeof(cmd)); + actual = TEST_FCNCODE_MAX; + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, 0), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&cmd, 0xFF, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, TEST_FCNCODE_MAX); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + ASSERT_EQ(Test_MSG_NotF(msgptr), 0); + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&cmd, 0, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, 0); + ASSERT_EQ(CFE_MSG_SetFcnCode(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(cmd)); + ASSERT_EQ(CFE_MSG_GetFcnCode(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, input[i]); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG | MSG_TYPE_FLAG); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_fc.h b/modules/msg/unit-test-coverage/test_cfe_msg_fc.h new file mode 100644 index 000000000..1dbff0fca --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_fc.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_fc test header + */ +#ifndef test_cfe_msg_fc_ +#define test_cfe_msg_fc_ + +/* + * Functions + */ +/* Test function code accessor functions */ +void Test_MSG_FcnCode(void); + +#endif /* test_cfe_msg_fc_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_init.c b/modules/msg/unit-test-coverage/test_cfe_msg_init.c new file mode 100644 index 000000000..d49924493 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_init.c @@ -0,0 +1,147 @@ +/* +** 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. +*/ + +/* + * Test message init + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_init.h" +#include "cfe_error.h" +#include "cfe_msg_defaults.h" +#include + +#define TEST_DEFAULT_APID_MASK 0x780 /* Bits that can be set by default apid if msgid V2 */ + +/* + * Test MSG Init + */ +void Test_MSG_Init(void) +{ + + CFE_MSG_Message_t msg; + CFE_MSG_Size_t size; + CFE_SB_MsgId_Atom_t msgidval_exp; + CFE_SB_MsgId_t msgid_act; + CFE_MSG_HeaderVersion_t hdrver; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + unsigned int flag_exp; + bool hassec; + bool is_v1; + + UT_Text("Bad parameter tests, Null pointer, invalid size, invalid msgid"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_Init(NULL, CFE_SB_ValueToMsgId(0), sizeof(msg), false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(0), 0, false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), sizeof(msg), false), + CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(-1), sizeof(msg), false), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, msgid value = 0, and run without clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + + /* Get msgid version by checking if header version was set */ + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + is_v1 = (hdrver == 0); + + flag_exp = MSG_TYPE_FLAG | MSG_LENGTH_FLAG | MSG_APID_FLAG; + if (is_v1) + flag_exp |= MSG_HDRVER_FLAG | MSG_HASSEC_FLAG; + + ASSERT_EQ(Test_MSG_Pri_NotF(&msg), flag_exp); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + + UT_Text("Set to all F's, msgid value = 0, and run with clearing"); + memset(&msg, 0xFF, sizeof(msg)); + msgidval_exp = 0; + + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), true), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetSegmentationFlag(&msg, &segflag), CFE_SUCCESS); + ASSERT_EQ(segflag, CFE_MSG_SegFlag_Unsegmented); + + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + if (!is_v1) + { + ASSERT_EQ(apid, CFE_PLATFORM_DEFAULT_APID & TEST_DEFAULT_APID_MASK); + ASSERT_EQ(hdrver, CFE_MISSION_CCSDSVER); + ASSERT_EQ(hassec, true); + } + else + { + ASSERT_EQ(apid, 0); + ASSERT_EQ(hdrver, 0); + ASSERT_EQ(hassec, false); + } + + /* Confirm the rest of the fields not already explicitly checked */ + ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~(MSG_APID_FLAG | MSG_HDRVER_FLAG | MSG_HASSEC_FLAG), + MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG); + + UT_Text("Set to all 0, max msgid value, and run without clearing"); + memset(&msg, 0, sizeof(msg)); + msgidval_exp = CFE_PLATFORM_SB_HIGHEST_VALID_MSGID; + ASSERT_EQ(CFE_MSG_Init(&msg, CFE_SB_ValueToMsgId(msgidval_exp), sizeof(msg), false), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, 0); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid_act), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid_act), msgidval_exp); + ASSERT_EQ(CFE_MSG_GetSize(&msg, &size), CFE_SUCCESS); + ASSERT_EQ(size, sizeof(msg)); + + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + if (!is_v1) + { + ASSERT_EQ(apid & TEST_DEFAULT_APID_MASK, CFE_PLATFORM_DEFAULT_APID & TEST_DEFAULT_APID_MASK); + ASSERT_EQ(hassec, false); + } + else + { + ASSERT_EQ(apid, 0x7FF); + ASSERT_EQ(hassec, true); + } + + ASSERT_EQ(Test_MSG_Pri_NotZero(&msg) & ~(MSG_APID_FLAG | MSG_HASSEC_FLAG), MSG_TYPE_FLAG | MSG_LENGTH_FLAG); + + /* Zero (no default) header version check */ + ASSERT_EQ(CFE_MSG_GetHeaderVersion(&msg, &hdrver), CFE_SUCCESS); + ASSERT_EQ(hdrver, 0); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_init.h b/modules/msg/unit-test-coverage/test_cfe_msg_init.h new file mode 100644 index 000000000..0ee75f86c --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_init.h @@ -0,0 +1,37 @@ +/* +** 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. +*/ + +/* + * cfe_msg_init test header + */ +#ifndef test_cfe_msg_init_ +#define test_cfe_msg_init_ + +/* + * Includes + */ + +/* + * Functions + */ +/* Test extended header mission functionality */ +void Test_MSG_Init(void); + +#endif /* test_cfe_msg_init_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h b/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h new file mode 100644 index 000000000..8a3a467e9 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid.h @@ -0,0 +1,33 @@ +/* +** 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 ID V2 accessor function test header + */ +#ifndef test_cfe_msg_msgid_ +#define test_cfe_msg_msgid_ + +/* + * Functions + */ +/* Test msgid accessor functions */ +void Test_MSG_MsgId(void); + +#endif /* test_cfe_msg_msgid_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c new file mode 100644 index 000000000..4cec04552 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.c @@ -0,0 +1,79 @@ +/* +** 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. +*/ + +/* + * Test MsgId shared accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid_shared.h" +#include "cfe_error.h" +#include + +void Test_MSG_GetTypeFromMsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(0); + CFE_MSG_Type_t actual = CFE_MSG_Type_Invalid; + + UT_Text("Bad parameter tests, Null pointer"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set to all F's, test cmd and tlm"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(CFE_PLATFORM_SB_HIGHEST_VALID_MSGID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); + + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + + UT_Text("Set to all 0, test cmd and tlm"); + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Cmd); + + ASSERT_EQ(CFE_MSG_SetType(&msg, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetTypeFromMsgId(msgid, &actual), CFE_SUCCESS); + ASSERT_EQ(actual, CFE_MSG_Type_Tlm); +} + +/* + * Test MSG MsgId Shared + */ +void Test_MSG_MsgId_Shared(void) +{ + MSG_UT_ADD_SUBTEST(Test_MSG_GetTypeFromMsgId); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h new file mode 100644 index 000000000..469f65408 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_shared.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_msgid_shared test header + */ +#ifndef test_cfe_msg_msgid_shared_ +#define test_cfe_msg_msgid_shared_ + +/* + * Functions + */ +/* Test msgid shared accessor functions */ +void Test_MSG_MsgId_Shared(void); + +#endif /* test_cfe_msg_msgid_shared_ */ diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c new file mode 100644 index 000000000..f0e51a2aa --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v1.c @@ -0,0 +1,104 @@ +/* +** 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. +*/ + +/* + * Test MsgId V1 accessors + */ + +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid.h" +#include "cfe_error.h" +#include + +#define TEST_MAX_APID 0x7FF + +void Test_MSG_MsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(1); + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + bool hassec; + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(NULL, &msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 1); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(NULL, msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_INVALID_MSG_ID), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0xFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set msg to all F's, set msgid to 0 and verify"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0xFFFF); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_HDRVER_FLAG | MSG_APID_FLAG | MSG_TYPE_FLAG | MSG_HASSEC_FLAG); + + UT_Text("Set msg to all 0, set msgid to max and verify"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | MSG_HASSEC_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, TEST_MAX_APID); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + ASSERT_EQ(hassec, true); + + UT_Text("Set ApId msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(TEST_MAX_APID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, TEST_MAX_APID); + + UT_Text("Set has secondary header bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x0800)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_HASSEC_FLAG); + ASSERT_EQ(CFE_MSG_GetHasSecondaryHeader(&msg, &hassec), CFE_SUCCESS); + ASSERT_EQ(hassec, true); + + UT_Text("Set type msgid bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x1000)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c new file mode 100644 index 000000000..cca35be7a --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_msgid_v2.c @@ -0,0 +1,116 @@ +/* +** 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. +*/ + +/* + * Test MsgId V2 accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "test_cfe_msg_msgid.h" +#include "cfe_error.h" +#include + +void Test_MSG_MsgId(void) +{ + CFE_MSG_Message_t msg; + CFE_SB_MsgId_t msgid = CFE_SB_ValueToMsgId(1); + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_Subsystem_t subsystem; + int local_subsys_flag = 0; + + /* Check if subsystem accessor functions are implemented */ + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + local_subsys_flag = MSG_SUBSYS_FLAG; + } + + UT_Text("Bad parameter tests, Null pointers and invalid (max valid + 1)"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(NULL, &msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 1); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(NULL, msgid), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_INVALID_MSG_ID), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID + 1), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0xFFFFFFFF), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(&msg), 0); + + UT_Text("Set msg to all F's, set msgid to 0 and verify"); + memset(&msg, 0xFF, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0xFFFF); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, 0), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(Test_MSG_NotF(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | local_subsys_flag); + + UT_Text("Set msg to all 0, set msgid to max and verify"); + memset(&msg, 0, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), 0); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID), CFE_SUCCESS); + Test_MSG_PrintMsg(&msg, sizeof(msg)); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(CFE_SB_MsgIdToValue(msgid), CFE_PLATFORM_SB_HIGHEST_VALID_MSGID); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG | MSG_TYPE_FLAG | local_subsys_flag); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, 0x7F); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + ASSERT_EQ(subsystem, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID >> 8); + } + + UT_Text("Set ApId msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x007F)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_APID_FLAG); + ASSERT_EQ(CFE_MSG_GetApId(&msg, &apid), CFE_SUCCESS); + ASSERT_EQ(apid, 0x007F); + + UT_Text("Set type msgid bit only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0x0080)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetType(&msg, &type), CFE_SUCCESS); + ASSERT_EQ(type, CFE_MSG_Type_Cmd); + + UT_Text("Set subsystem msgid bits only and verify"); + ASSERT_EQ(CFE_MSG_SetMsgId(&msg, CFE_SB_ValueToMsgId(0xFF00 & CFE_PLATFORM_SB_HIGHEST_VALID_MSGID)), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgId(&msg, &msgid), CFE_SUCCESS); + ASSERT_EQ(Test_MSG_NotZero(&msg), local_subsys_flag); + if (CFE_MSG_GetSubsystem(&msg, &subsystem) != CFE_MSG_NOT_IMPLEMENTED) + { + ASSERT_EQ(subsystem, CFE_PLATFORM_SB_HIGHEST_VALID_MSGID >> 8); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_time.c b/modules/msg/unit-test-coverage/test_cfe_msg_time.c new file mode 100644 index 000000000..6e6977d52 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_time.c @@ -0,0 +1,98 @@ +/* +** 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. +*/ + +/* + * Test time accessors + */ + +/* + * Includes + */ +#include "utassert.h" +#include "ut_support.h" +#include "test_msg_not.h" +#include "test_msg_utils.h" +#include "cfe_msg_api.h" +#include "test_cfe_msg_time.h" +#include "cfe_error.h" +#include + +void Test_MSG_Time(void) +{ + CFE_SB_TlmHdr_t tlm; + CFE_MSG_Message_t *msgptr = (CFE_MSG_Message_t *)&tlm; + CFE_TIME_SysTime_t input[] = {{0, 0}, {0x12345678, 0xABCDEF12}, {0xFFFFFFFF, 0xFFFFFFFF}}; + CFE_TIME_SysTime_t actual = {0xFFFFFFFF, 0xFFFFFFFF}; + int i; + + UT_Text("Bad parameter tests, Null pointers, no secondary header"); + memset(&tlm, 0, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(NULL, &actual), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(actual.Seconds, 0xFFFFFFFF); + ASSERT_EQ(actual.Subseconds, 0xFFFFFFFF); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, NULL), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_SetMsgTime(NULL, input[0]), CFE_MSG_BAD_ARGUMENT); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), 0); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + + UT_Text("Bad message, wrong type (command)"); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Cmd), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_TYPE_FLAG); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_MSG_WRONG_MSG_TYPE); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + + UT_Text("Set to all F's, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&tlm, 0xFF, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_SetType(msgptr, CFE_MSG_Type_Tlm), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, 0xFFFFFFFF); + ASSERT_EQ(actual.Subseconds, 0xFFFF0000); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, input[i].Seconds); + ASSERT_EQ(actual.Subseconds, input[i].Subseconds & 0xFFFF0000); + ASSERT_EQ(Test_MSG_NotF(msgptr), MSG_TYPE_FLAG); + } + + UT_Text("Set to all 0, various valid inputs"); + for (i = 0; i < sizeof(input) / sizeof(input[0]); i++) + { + memset(&tlm, 0, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_SetHasSecondaryHeader(msgptr, true), CFE_SUCCESS); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, 0); + ASSERT_EQ(actual.Subseconds, 0); + ASSERT_EQ(CFE_MSG_SetMsgTime(msgptr, input[i]), CFE_SUCCESS); + Test_MSG_PrintMsg(msgptr, sizeof(tlm)); + ASSERT_EQ(CFE_MSG_GetMsgTime(msgptr, &actual), CFE_SUCCESS); + ASSERT_EQ(actual.Seconds, input[i].Seconds); + ASSERT_EQ(actual.Subseconds, input[i].Subseconds & 0xFFFF0000); + ASSERT_EQ(Test_MSG_NotZero(msgptr), MSG_HASSEC_FLAG); + } +} diff --git a/modules/msg/unit-test-coverage/test_cfe_msg_time.h b/modules/msg/unit-test-coverage/test_cfe_msg_time.h new file mode 100644 index 000000000..2981d8ee5 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_cfe_msg_time.h @@ -0,0 +1,33 @@ +/* +** 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. +*/ + +/* + * cfe_msg_time test header + */ +#ifndef test_cfe_msg_time_ +#define test_cfe_msg_time_ + +/* + * Functions + */ +/* Test time accessor functions */ +void Test_MSG_Time(void); + +#endif /* test_cfe_msg_time_ */ diff --git a/modules/msg/unit-test-coverage/test_msg_ext_not.c b/modules/msg/unit-test-coverage/test_msg_ext_not.c new file mode 100644 index 000000000..d764bfabd --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_ext_not.c @@ -0,0 +1,85 @@ +/* +** 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. +*/ + +/* + * Extended message header field not Zero or F + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_Endian_t endian; + CFE_MSG_PlaybackFlag_t playflag; + CFE_MSG_Subsystem_t subsystem; + CFE_MSG_System_t system; + + CFE_MSG_GetEDSVersion(MsgPtr, &edsver); + if (edsver != 0) + bits |= MSG_EDSVER_FLAG; + CFE_MSG_GetEndian(MsgPtr, &endian); + if (endian != CFE_MSG_Endian_Big) + bits |= MSG_ENDIAN_FLAG; + CFE_MSG_GetPlaybackFlag(MsgPtr, &playflag); + if (playflag != CFE_MSG_PlayFlag_Original) + bits |= MSG_PBACK_FLAG; + CFE_MSG_GetSubsystem(MsgPtr, &subsystem); + if (subsystem != 0) + bits |= MSG_SUBSYS_FLAG; + CFE_MSG_GetSystem(MsgPtr, &system); + if (system != 0) + bits |= MSG_SYSTEM_FLAG; + + return bits; +} + +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_EDSVersion_t edsver; + CFE_MSG_Endian_t endian; + CFE_MSG_PlaybackFlag_t playflag; + CFE_MSG_Subsystem_t subsystem; + CFE_MSG_System_t system; + + CFE_MSG_GetEDSVersion(MsgPtr, &edsver); + if (edsver != 0x1F) + bits |= MSG_EDSVER_FLAG; + CFE_MSG_GetEndian(MsgPtr, &endian); + if (endian != CFE_MSG_Endian_Little) + bits |= MSG_ENDIAN_FLAG; + CFE_MSG_GetPlaybackFlag(MsgPtr, &playflag); + if (playflag != CFE_MSG_PlayFlag_Playback) + bits |= MSG_PBACK_FLAG; + CFE_MSG_GetSubsystem(MsgPtr, &subsystem); + if (subsystem != 0x1FF) + bits |= MSG_SUBSYS_FLAG; + CFE_MSG_GetSystem(MsgPtr, &system); + if (system != 0xFFFF) + bits |= MSG_SYSTEM_FLAG; + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_not.c b/modules/msg/unit-test-coverage/test_msg_not.c new file mode 100644 index 000000000..8d7d60e86 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_not.c @@ -0,0 +1,55 @@ +/* +** 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 header field not Zero or F + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + + /* Primary */ + bits |= Test_MSG_Pri_NotZero(MsgPtr); + + /* Extended */ + bits |= Test_MSG_Ext_NotZero(MsgPtr); + + return bits; +} + +unsigned int Test_MSG_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + + /* Primary */ + bits |= Test_MSG_Pri_NotF(MsgPtr); + + /* Extended */ + bits |= Test_MSG_Ext_NotF(MsgPtr); + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_not.h b/modules/msg/unit-test-coverage/test_msg_not.h new file mode 100644 index 000000000..10bb706ba --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_not.h @@ -0,0 +1,67 @@ +/* +** 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 header fields not (Zero or F's) + */ +#ifndef test_msg_not_ +#define test_msg_not_ + +/* + * Defines + */ + +/* Field flags */ +/* CCSDS Primary */ +#define MSG_HDRVER_FLAG 0x00001 +#define MSG_TYPE_FLAG 0x00002 +#define MSG_HASSEC_FLAG 0x00004 +#define MSG_APID_FLAG 0x00008 +#define MSG_SEGMENT_FLAG 0x00010 +#define MSG_SEQUENCE_FLAG 0x00020 +#define MSG_LENGTH_FLAG 0x00040 + +/* Extended */ +#define MSG_EDSVER_FLAG 0x00080 +#define MSG_ENDIAN_FLAG 0x00100 +#define MSG_PBACK_FLAG 0x00200 +#define MSG_SUBSYS_FLAG 0x00400 +#define MSG_SYSTEM_FLAG 0x00800 + +/* Secondary */ +#define MSG_CKSUM_FLAG 0x01000 +#define MSG_FCNCODE_FLAG 0x02000 +#define MSG_TIME_FLAG 0x04000 + +/* + * Prototypes + */ + +/* Returns flags for fields that are 0 */ +unsigned int Test_MSG_NotZero(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Pri_NotZero(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr); + +/* Returns flags for fields that are fully set (aka all F's */ +unsigned int Test_MSG_NotF(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Pri_NotF(const CFE_MSG_Message_t *MsgPtr); +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr); + +#endif /* test_msg_not_ */ diff --git a/modules/msg/unit-test-coverage/test_msg_pri_not.c b/modules/msg/unit-test-coverage/test_msg_pri_not.c new file mode 100644 index 000000000..3f35cf3b0 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_pri_not.c @@ -0,0 +1,102 @@ +/* +** 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. +*/ + +/* + * Primary message header field not Zero or F + */ + +/* + * Includes + */ +#include "test_cfe_msg_ccsdspri.h" /* For TEST_MSG_SIZE_OFFSET */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" + +unsigned int Test_MSG_Pri_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_HeaderVersion_t hdrver; + bool hassec; + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + CFE_MSG_SequenceCount_t seqcnt; + CFE_MSG_Size_t size; + + CFE_MSG_GetHeaderVersion(MsgPtr, &hdrver); + if (hdrver != 0) + bits |= MSG_HDRVER_FLAG; + CFE_MSG_GetType(MsgPtr, &type); + if (type != CFE_MSG_Type_Tlm) + bits |= MSG_TYPE_FLAG; + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassec); + if (hassec) + bits |= MSG_HASSEC_FLAG; + CFE_MSG_GetApId(MsgPtr, &apid); + if (apid != 0) + bits |= MSG_APID_FLAG; + CFE_MSG_GetSegmentationFlag(MsgPtr, &segflag); + if (segflag != CFE_MSG_SegFlag_Continue) + bits |= MSG_SEGMENT_FLAG; + CFE_MSG_GetSequenceCount(MsgPtr, &seqcnt); + if (seqcnt != 0) + bits |= MSG_SEQUENCE_FLAG; + CFE_MSG_GetSize(MsgPtr, &size); + if (size != TEST_MSG_SIZE_OFFSET) + bits |= MSG_LENGTH_FLAG; + + return bits; +} + +unsigned int Test_MSG_Pri_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + unsigned int bits = 0; + CFE_MSG_HeaderVersion_t hdrver; + bool hassec; + CFE_MSG_Type_t type; + CFE_MSG_ApId_t apid; + CFE_MSG_SegmentationFlag_t segflag; + CFE_MSG_SequenceCount_t seqcnt; + CFE_MSG_Size_t size; + + CFE_MSG_GetHeaderVersion(MsgPtr, &hdrver); + if (hdrver != 0x7) + bits |= MSG_HDRVER_FLAG; + CFE_MSG_GetType(MsgPtr, &type); + if (type != CFE_MSG_Type_Cmd) + bits |= MSG_TYPE_FLAG; + CFE_MSG_GetHasSecondaryHeader(MsgPtr, &hassec); + if (!hassec) + bits |= MSG_HASSEC_FLAG; + CFE_MSG_GetApId(MsgPtr, &apid); + if (apid != 0x7FF) + bits |= MSG_APID_FLAG; + CFE_MSG_GetSegmentationFlag(MsgPtr, &segflag); + if (segflag != CFE_MSG_SegFlag_Unsegmented) + bits |= MSG_SEGMENT_FLAG; + CFE_MSG_GetSequenceCount(MsgPtr, &seqcnt); + if (seqcnt != 0x3FFF) + bits |= MSG_SEQUENCE_FLAG; + CFE_MSG_GetSize(MsgPtr, &size); + if (size != 0xFFFF + TEST_MSG_SIZE_OFFSET) + bits |= MSG_LENGTH_FLAG; + + return bits; +} diff --git a/modules/msg/unit-test-coverage/test_msg_prionly.c b/modules/msg/unit-test-coverage/test_msg_prionly.c new file mode 100644 index 000000000..6df77d970 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_prionly.c @@ -0,0 +1,42 @@ +/* +** 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. +*/ + +/* + * Extended header stubbed out, use when no extended header is defined + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_not.h" +#include "test_cfe_msg_ccsdsext.h" + +unsigned int Test_MSG_Ext_NotZero(const CFE_MSG_Message_t *MsgPtr) +{ + return 0; +} + +unsigned int Test_MSG_Ext_NotF(const CFE_MSG_Message_t *MsgPtr) +{ + return 0; +} + +void Test_MSG_CCSDSExt(void) {} diff --git a/modules/msg/unit-test-coverage/test_msg_utils.c b/modules/msg/unit-test-coverage/test_msg_utils.c new file mode 100644 index 000000000..1b715076e --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_utils.c @@ -0,0 +1,72 @@ +/* +** 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 header test utilities + */ + +/* + * Includes + */ +#include "cfe_msg_api.h" +#include "test_msg_utils.h" +#include "utassert.h" + +void Test_MSG_PrintMsg(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size) +{ + + int i; + char sbuf[121] = {0}; + char wbuf[6] = {0}; + + if (Size == 0) + { + CFE_MSG_GetSize(MsgPtr, &Size); + } + + for (i = 0; i < Size / 2; i++) + { + sprintf(wbuf, "%02X%02X ", MsgPtr->Byte[i * 2], MsgPtr->Byte[(i * 2) + 1]); + strcat(sbuf, wbuf); + + /* Make sure string buffer doesn't overflow */ + if (sizeof(sbuf) < (strlen(sbuf) + 6)) + break; + } + + UtAssert_Message(UTASSERT_CASETYPE_INFO, __FILE__, __LINE__, "Message: %s", sbuf); +} + +unsigned long long int Test_MSG_Sum(const CFE_MSG_Message_t *MsgPtr) +{ + + CFE_MSG_Size_t length; + unsigned long long int sum = 0; + int i; + + CFE_MSG_GetSize(MsgPtr, &length); + + for (i = 0; i < length; i++) + { + sum += MsgPtr->Byte[i]; + } + + return sum; +} diff --git a/modules/msg/unit-test-coverage/test_msg_utils.h b/modules/msg/unit-test-coverage/test_msg_utils.h new file mode 100644 index 000000000..8ff2c6ef8 --- /dev/null +++ b/modules/msg/unit-test-coverage/test_msg_utils.h @@ -0,0 +1,45 @@ +/* +** 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 header test utilities + */ +#ifndef test_msg_utils_ +#define test_msg_utils_ + +/* + * Includes + */ +#include "cfe_msg_typedefs.h" + +/* + * Defines + */ + +/* Subtest macro */ +#define MSG_UT_ADD_SUBTEST(Func) UT_AddSubTest(Func, NULL, NULL, __func__, #Func) + +/* Prints the message, 0 length uses length from message */ +void Test_MSG_PrintMsg(const CFE_MSG_Message_t *MsgPtr, CFE_MSG_Size_t Size); + +/* Sums the message for checking, generically check the entire message */ +unsigned long long int Test_MSG_Sum(const CFE_MSG_Message_t *MsgPtr); + +#endif /* test_msg_utils_ */