Skip to content

Commit

Permalink
Merge pull request nasa#568 from skliper/fix297-cmd-sec-hdr
Browse files Browse the repository at this point in the history
Fix nasa#297, CCSDS Command Secondary Header Endian Agnostic
  • Loading branch information
astrogeco committed Apr 6, 2020
2 parents 02bab72 + 2d48787 commit ff3aa94
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
22 changes: 12 additions & 10 deletions fsw/cfe-core/src/inc/ccsds.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,12 @@ typedef struct {

typedef struct {

uint16 Command; /* command secondary header */
/* bits shift ------------ description ---------------- */
/* 0x00FF 0 : checksum, calculated by ground system */
/* 0x7F00 8 : command function code */
/* 0x8000 15 : reserved, set to 0 */
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;

Expand Down Expand Up @@ -326,14 +327,14 @@ typedef CCSDS_TelemetryPacket_t CCSDS_TlmPkt_t;
(((phdr).Length[1] = ((value) - 7) & 0xff)) )

/* Read function code from command secondary header. */
#define CCSDS_RD_FC(shdr) CCSDS_RD_BITS((shdr).Command, 0x7F00, 8)
#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).Command, 0x7F00, 8, value)
#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) CCSDS_RD_BITS((shdr).Command, 0x00FF, 0)
#define CCSDS_RD_CHECKSUM(shdr) ((shdr).Checksum)
/* Write checksum to command secondary header. */
#define CCSDS_WR_CHECKSUM(shdr,val) CCSDS_WR_BITS((shdr).Command, 0x00FF, 0, val)
#define CCSDS_WR_CHECKSUM(shdr,val) ((shdr).Checksum = (val))

/* Define additional APID Qualifier macros. */

Expand Down Expand Up @@ -378,7 +379,8 @@ typedef CCSDS_TelemetryPacket_t CCSDS_TlmPkt_t;

/* Clear command secondary header. */
#define CCSDS_CLR_CMDSEC_HDR(shdr) \
( (shdr).Command = (CCSDS_INIT_CHECKSUM << 0) | (CCSDS_INIT_FC << 8) )
( (shdr).FunctionCode = CCSDS_INIT_FC,\
(shdr).Checksum = CCSDS_INIT_CHECKSUM )


#define CCSDS_WR_SEC_HDR_SEC(shdr, value) shdr.Time[0] = ((value>>24) & 0xFF), \
Expand Down
22 changes: 10 additions & 12 deletions fsw/cfe-core/unit-test/ut_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,30 +481,28 @@ int16 UT_GetActualPktLenField(CFE_SB_MsgPtr_t MsgPtr)
uint8 UT_GetActualCmdCodeField(CFE_SB_MsgPtr_t MsgPtr)
{
/*
* CFE 6.4.0 tried to make all headers big-endian.
* CFE 6.4.1 made secondary headers native-endian again.
*
* This function is used to "go around" the structure field
* definitions and access macro definitions, to look for the
* bits of the function code in the exact spot where we are
* expecting to find them.
*
* The CCSDS Command Function Code is defined as living in
* bits 8 through 14 (mask 0x7F00) of the 16-bit unsigned
* value encoded in NATIVE endianness in the two bytes
* stored at offsets 6 and 7 in the packet for CCSDS version 1
* and offsets 10 and 11 for CCSDS Version 2
* the first byte of the command secondary header (mask 0x7F)
* NOTE: this definition is endian agnostic
*
* CCSDS version 1 - cmd sec header is offset 6 bytes
* CCSDS Version 2 - cmd sec header is offset 10 bytes
*/

uint8 CmdCodeWordFieldIndex; /* Field index (in WORDS) */
uint16 *w = (uint16 *)MsgPtr;
uint8 Index; /* Field index (in BYTES) */
uint8 *w = (uint8 *)MsgPtr;

#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
CmdCodeWordFieldIndex = 3;
Index = 6;
#else
CmdCodeWordFieldIndex = 5;
Index = 10;
#endif
return (w[CmdCodeWordFieldIndex] & 0x7F00) >> 8;
return (w[Index] & 0x7F);
}


Expand Down

0 comments on commit ff3aa94

Please sign in to comment.