From c050163929ab79b5a3cae589806b703be068964c Mon Sep 17 00:00:00 2001 From: Jacob Hageman <jacob.hageman@nasa.gov> Date: Tue, 7 Jun 2022 12:30:22 -0600 Subject: [PATCH] Part #17, Use real message types in tables --- fsw/tables/sc_rts001.c | 94 ++++++++++++++---------------------------- 1 file changed, 30 insertions(+), 64 deletions(-) diff --git a/fsw/tables/sc_rts001.c b/fsw/tables/sc_rts001.c index 3fe981c..94eb24e 100644 --- a/fsw/tables/sc_rts001.c +++ b/fsw/tables/sc_rts001.c @@ -47,78 +47,44 @@ #include "cfe.h" #include "cfe_tbl_filedef.h" -#include "cfe_endian.h" +#include "sc_app.h" /* defines SC table headers */ #include "sc_platform_cfg.h" /* defines table buffer size */ #include "sc_msgdefs.h" /* defines SC command code values */ #include "sc_msgids.h" /* defines SC packet msg ID's */ /* -** Execution time for each sample command -*/ -#define CMD1_TIME 0 -#define CMD2_TIME 5 -#define CMD3_TIME 5 - -/* -** Calculate checksum for each sample command -*/ -#define CMD1_XSUM 0x008F -#define CMD2_XSUM 0x0088 -#define CMD3_XSUM 0x008B + * Checksum for each sample command + */ +#ifndef SC_NOOP_CKSUM +#define SC_NOOP_CKSUM 0x8F +#endif -/* -** Optional command data values -*/ -#define CMD2_ARG 0x0200 -#define CMD3_ARG 0x0200 +/* Custom table structure, modify as needed to add desired commands */ +typedef struct +{ + SC_RtsEntryHeader_t hdr1; + SC_NoArgsCmd_t cmd1; + SC_RtsEntryHeader_t hdr2; + SC_NoArgsCmd_t cmd2; +} SC_RtsStruct001_t; -/* -** Command packet segment flags and sequence counter -** - 2 bits of segment flags (0xC000 = start and end of packet) -** - 14 bits of sequence count (unused for command packets) -*/ -#define PKT_FLAGS 0xC000 +/* Define the union to size the table correctly */ +typedef union +{ + SC_RtsStruct001_t rts; + uint16 buf[SC_RTS_BUFF_SIZE]; +} SC_RtsTable001_t; -/* -** Length of cmd pkt data (in bytes minus one) that follows primary header (thus, 0xFFFF = 64k) -*/ -#define CMD1_LENGTH 1 -#define CMD2_LENGTH 5 -#define CMD3_LENGTH 5 +/* Helper macro to get size of structure elements */ +#define SC_RTS_MEMBER_SIZE(member) sizeof(((SC_RtsStruct001_t *)0)->member) -/* -** Sample cFE Table Header -*/ -static CFE_TBL_FileDef_t CFE_TBL_FileDef __attribute__((__used__)) = { - "RTS_Table001", "SC.RTS_TBL001", "SC Sample RTS_TBL001", "sc_rts001.tbl", (SC_RTS_BUFF_SIZE * sizeof(uint16))}; +/* Used designated intializers to be verbose, modify as needed/desired */ +SC_RtsTable001_t SC_Rts001 = { + .rts.hdr1.TimeTag = 5, + .rts.cmd1.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_RTS_MEMBER_SIZE(cmd1), SC_NOOP_CC, SC_NOOP_CKSUM), + .rts.hdr2.TimeTag = 3, + .rts.cmd2.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_RTS_MEMBER_SIZE(cmd2), SC_NOOP_CC, SC_NOOP_CKSUM)}; -/* -** Sample RTS Table Data -*/ -uint16 RTS_Table001[SC_RTS_BUFF_SIZE] = { - /* cmd time, <---------------------------- cmd pkt primary header ----------------------------> <----- cmd pkt - 2nd header ----> <-- opt data ---> */ - 0x0000, - CMD1_TIME, - CFE_MAKE_BIG16(SC_CMD_MID), - CFE_MAKE_BIG16(PKT_FLAGS), - CFE_MAKE_BIG16(CMD1_LENGTH), - CFE_MAKE_BIG16((SC_NOOP_CC << 8) | CMD1_XSUM), - 0x0000, - CMD2_TIME, - CFE_MAKE_BIG16(SC_CMD_MID), - CFE_MAKE_BIG16(PKT_FLAGS), - CFE_MAKE_BIG16(CMD2_LENGTH), - CFE_MAKE_BIG16((SC_ENABLE_RTS_CC << 8) | CMD2_XSUM), - CMD2_ARG, - 0x0000, - 0x0000, - CMD3_TIME, - CFE_MAKE_BIG16(SC_CMD_MID), - CFE_MAKE_BIG16(PKT_FLAGS), - CFE_MAKE_BIG16(CMD3_LENGTH), - CFE_MAKE_BIG16((SC_START_RTS_CC << 8) | CMD3_XSUM), - CMD3_ARG, - 0x0000, -}; +/* Macro for table structure */ +CFE_TBL_FILEDEF(SC_Rts001, SC.RTS_TBL001, SC Example RTS_TBL001, sc_rts001.tbl)