From 856367951848fdf00a3985144765edb6b13b0e61 Mon Sep 17 00:00:00 2001 From: Jacob Hageman Date: Fri, 14 Aug 2020 10:48:52 -0400 Subject: [PATCH] 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 */