Skip to content

Commit

Permalink
Merge pull request #35 from skliper/fix17-tbl_msg_struct
Browse files Browse the repository at this point in the history
Fix #17, Use real message types in tables
  • Loading branch information
dzbaker authored Jan 5, 2023
2 parents e2f2124 + 1edd226 commit c65b280
Show file tree
Hide file tree
Showing 3 changed files with 184 additions and 298 deletions.
212 changes: 82 additions & 130 deletions fsw/tables/sc_ats1.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,154 +21,106 @@
* @file
* CFS Stored Command (SC) sample ATS table 1
*
* @note
* Note 1: The following source code demonstrates how to create a sample
* Stored Command ATS table. The preferred method for creating
* flight versions of ATS tables is to use custom ground system
* tools that output the binary table files, skipping this step
* altogether.
* The following source code demonstrates how to create a sample
* Stored Command ATS table using the software defined command structures.
* It's also possible to create this table via alternative tools
* (ground system) and or system agnostic data definitions (XTCE/EDS/JSON).
*
* Note 2: This source file creates a sample ATS table that contains the
* following commands that are scheduled as follows:
* This source file creates a sample ATS table that contains only
* the following commands that are scheduled as follows:
*
* SC NOOP command, execution time = SC_TEST_TIME + 30
* SC Enable RTS #1 command, execution time = SC_TEST_TIME + 35
* SC Start RTS #1 command, execution time = SC_TEST_TIME + 40
* SC Reset Counters command, execution time = SC_TEST_TIME + 100
* SC NOOP command, execution time = SC_TEST_TIME + 30
* SC Enable RTS #1 command, execution time = SC_TEST_TIME + 35
* SC Start RTS #1 command, execution time = SC_TEST_TIME + 40
* SC Reset Counters command, execution time = SC_TEST_TIME + 100
*
* Note 3: Before starting the sample ATS, set time = SC_TEST_TIME. The
* user will then have 30 seconds to start the ATS before the
* first command in the sample ATS is scheduled to execute.
*
* Note 4: The byte following the command code in each command packet
* secondary header must contain an 8 bit checksum. Refer to
* the SC Users Guide for information on how to calculate this
* checksum.
*
* Note 5: If the command length (in bytes) is odd, a pad byte must be added
* to the ATS command structure (opt data portion) to ensure the next
* command starts on a word (uint16) boundary.
*
* Note 6: There is a crucial safety measure that is required of all ATS tables.
* The ATP relies on a sentinel word of zeroes at the end of an ATS table
* to signal the end of the ATS table (end of data marker).
* Before starting the sample ATS, set time = SC_TEST_TIME. The
* user will then have 30 seconds to start the ATS before the
* first command in the sample ATS is scheduled to execute.
*/

#include "cfe.h"
#include "cfe_endian.h"
#include "cfe_tbl_filedef.h"

#include "sc_tbldefs.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 */
#include "sc_msg.h" /* defines SC message structures */

/*
** Arbitrary spacecraft time for start of sample ATS
*/
#define TEST_TIME 1000000
/* Spacecraft sample ATS time offsets */
#define SC_TEST_TIME (1000000)
#define SC_CMD1_TIME (SC_TEST_TIME + 30)
#define SC_CMD2_TIME (SC_TEST_TIME + 35)
#define SC_CMD3_TIME (SC_TEST_TIME + 40)
#define SC_CMD4_TIME (SC_TEST_TIME + 100)

/*
** Execution time for each sample command
*/
#define CMD1_TIME (TEST_TIME + 30)
#define CMD2_TIME (TEST_TIME + 35)
#define CMD3_TIME (TEST_TIME + 40)
#define CMD4_TIME (TEST_TIME + 100)
/* Checksum for each sample command */
#ifndef SC_NOOP_CKSUM
#define SC_NOOP_CKSUM (0x8F)
#endif
#ifndef SC_ENABLE_RTS1_CKSUM
#define SC_ENABLE_RTS1_CKSUM (0x8D)
#endif
#ifndef SC_START_RTS1_CKSUM
#define SC_START_RTS1_CKSUM (0x8E)
#endif
#ifndef SC_RESET_COUNTERS_CKSUM
#define SC_RESET_COUNTERS_CKSUM (0x8E)
#endif

/*
** Create execution time as Most Signficant (MS) and Least Signficant (LS) 16 bit values
*/
#define CMD1_TIME_MS ((CMD1_TIME >> 16) & 0xFFFF)
#define CMD2_TIME_MS ((CMD2_TIME >> 16) & 0xFFFF)
#define CMD3_TIME_MS ((CMD3_TIME >> 16) & 0xFFFF)
#define CMD4_TIME_MS ((CMD4_TIME >> 16) & 0xFFFF)
/* Custom table structure, modify as needed to add desired commands */
typedef struct
{
SC_AtsEntryHeader_t hdr1;
SC_NoArgsCmd_t cmd1;
SC_AtsEntryHeader_t hdr2;
SC_RtsCmd_t cmd2;
SC_AtsEntryHeader_t hdr3;
SC_RtsCmd_t cmd3;
SC_AtsEntryHeader_t hdr4;
SC_NoArgsCmd_t cmd4;
} SC_AtsStruct1_t;

#define CMD1_TIME_LS (CMD1_TIME & 0xFFFF)
#define CMD2_TIME_LS (CMD2_TIME & 0xFFFF)
#define CMD3_TIME_LS (CMD3_TIME & 0xFFFF)
#define CMD4_TIME_LS (CMD4_TIME & 0xFFFF)
/* Define the union to size the table correctly */
typedef union
{
SC_AtsStruct1_t ats;
uint16 buf[SC_ATS_BUFF_SIZE];
} SC_AtsTable1_t;

/*
** Calculate checksum for each sample command
*/
#define CMD1_XSUM 0x008F
#define CMD2_XSUM 0x008D
#define CMD3_XSUM 0x008E
#define CMD4_XSUM 0x008E
/* Helper macro to get size of structure elements */
#define SC_MEMBER_SIZE(member) (sizeof(((SC_AtsStruct1_t *)0)->member))

/*
** Optional command data values
*/
#define CMD2_ARG 1
#define CMD3_ARG 1
/* Used designated intializers to be verbose, modify as needed/desired */
SC_AtsTable1_t SC_Ats1 = {
/* 1 */
.ats.hdr1.CmdNumber = 1,
.ats.hdr1.TimeTag_MS = SC_CMD1_TIME >> 16,
.ats.hdr1.TimeTag_LS = SC_CMD1_TIME & 0xFFFF,
.ats.cmd1.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd1), SC_NOOP_CC, SC_NOOP_CKSUM),

/*
** 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
/* 2 */
.ats.hdr2.CmdNumber = 2,
.ats.hdr2.TimeTag_MS = SC_CMD2_TIME >> 16,
.ats.hdr2.TimeTag_LS = SC_CMD2_TIME & 0xFFFF,
.ats.cmd2.CmdHeader =
CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd2), SC_ENABLE_RTS_CC, SC_ENABLE_RTS1_CKSUM),
.ats.cmd2.RtsId = 1,

/*
** 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
#define CMD4_LENGTH 1
/* 3 */
.ats.hdr3.CmdNumber = 3,
.ats.hdr3.TimeTag_MS = SC_CMD3_TIME >> 16,
.ats.hdr3.TimeTag_LS = SC_CMD3_TIME & 0xFFFF,
.ats.cmd3.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_START_RTS_CC, SC_START_RTS1_CKSUM),
.ats.cmd3.RtsId = 1,

/*
** Sample ATS_TBL1 Table Header
*/
static CFE_TBL_FileDef_t CFE_TBL_FileDef __attribute__((__used__)) = {
"ATS_Table1", "SC.ATS_TBL1", "SC Sample ATS_TBL1", "sc_ats1.tbl", (SC_ATS_BUFF_SIZE * sizeof(uint16))};
/* 4 */
.ats.hdr4.CmdNumber = 4,
.ats.hdr4.TimeTag_MS = SC_CMD4_TIME >> 16,
.ats.hdr4.TimeTag_LS = SC_CMD4_TIME & 0xFFFF,
.ats.cmd4.CmdHeader =
CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd4), SC_RESET_COUNTERS_CC, SC_RESET_COUNTERS_CKSUM)};

/*
** Sample ATS_TBL1 Table Data
*/
uint16 ATS_Table1[SC_ATS_BUFF_SIZE] = {
/* cmd num, <---- cmd exe time ----> <---------------------------- cmd pkt primary header
----------------------------> <----- cmd pkt 2nd header ----> <-- opt data ---> */
0,
1,
CMD1_TIME_MS,
CMD1_TIME_LS,
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),
0,
2,
CMD2_TIME_MS,
CMD2_TIME_LS,
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,
0,
3,
CMD3_TIME_MS,
CMD3_TIME_LS,
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,
0,
4,
CMD4_TIME_MS,
CMD4_TIME_LS,
CFE_MAKE_BIG16(SC_CMD_MID),
CFE_MAKE_BIG16(PKT_FLAGS),
CFE_MAKE_BIG16(CMD4_LENGTH),
CFE_MAKE_BIG16((SC_RESET_COUNTERS_CC << 8) | CMD4_XSUM),
0,
0,
0,
0,
0,
0,
0};
/* Macro for table structure */
CFE_TBL_FILEDEF(SC_Ats1, SC.ATS_TBL1, SC Example ATS_TBL1, sc_ats1.tbl)
140 changes: 56 additions & 84 deletions fsw/tables/sc_rts001.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,104 +21,76 @@
* @file
* CFS Stored Command (SC) sample RTS table 1
*
* @note
* Note 1: The following source code demonstrates how to create a sample
* Stored Command RTS table. The preferred method for creating
* flight versions of RTS tables is to use custom ground system
* tools that output the binary table files, skipping this step
* altogether.
* The following source code demonstrates how to create a sample
* Stored Command RTS table using the software defined command structures.
* It's also possible to create this table via alternative tools
* (ground system) and or system agnostic data definitions (XTCE/EDS/JSON).
*
* Note 2: This source file creates a sample RTS table that contains only
* the following commands that are scheduled as follows:
* This source file creates a sample RTS table that contains only
* the following commands that are scheduled as follows:
*
* SC NOOP command, execution time relative to start of RTS = 0
* SC Enable RTS #2 command, execution time relative to prev cmd = 5
* SC Start RTS #2 command, execution time relative to prev cmd = 5
*
* Note 3: The byte following the command code in each command packet
* secondary header must contain an 8 bit checksum. Refer to
* the SC Users Guide for information on how to calculate this
* checksum.
*
* Note 4: If the command length (in bytes) is odd, a pad byte must be added
* to the RTS command structure (opt data portion) to ensure the next
* command starts on a word (uint16) boundary.
* SC NOOP command, execution time relative to start of RTS = 0
* SC Enable RTS #2 command, execution time relative to prev cmd = 5
* SC Start RTS #2 command, execution time relative to prev cmd = 5
*/

#include "cfe.h"
#include "cfe_tbl_filedef.h"
#include "cfe_endian.h"

#include "sc_tbldefs.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 */
#include "sc_msg.h" /* defines SC message structures */

/* Checksum for each sample command */
#ifndef SC_NOOP_CKSUM
#define SC_NOOP_CKSUM (0x8F)
#endif
#ifndef SC_ENABLE_RTS2_CKSUM
#define SC_ENABLE_RTS2_CKSUM (0x8E)
#endif
#ifndef SC_START_RTS2_CKSUM
#define SC_START_RTS2_CKSUM (0x8D)
#endif

/*
** Execution time for each sample command
*/
#define CMD1_TIME 0
#define CMD2_TIME 5
#define CMD3_TIME 5
/* 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_RtsCmd_t cmd2;
SC_RtsEntryHeader_t hdr3;
SC_RtsCmd_t cmd3;
} SC_RtsStruct001_t;

/*
** Calculate checksum for each sample command
*/
#define CMD1_XSUM 0x008F
#define CMD2_XSUM 0x0088
#define CMD3_XSUM 0x008B
/* Define the union to size the table correctly */
typedef union
{
SC_RtsStruct001_t rts;
uint16 buf[SC_RTS_BUFF_SIZE];
} SC_RtsTable001_t;

/*
** Optional command data values
*/
#define CMD2_ARG 0x0200
#define CMD3_ARG 0x0200
/* Helper macro to get size of structure elements */
#define SC_MEMBER_SIZE(member) (sizeof(((SC_RtsStruct001_t *)0)->member))

/*
** 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
/* Used designated intializers to be verbose, modify as needed/desired */
SC_RtsTable001_t SC_Rts001 = {
/* 1 */
.rts.hdr1.TimeTag = 0,
.rts.cmd1.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd1), SC_NOOP_CC, SC_NOOP_CKSUM),

/*
** 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
/* 2 */
.rts.hdr2.TimeTag = 5,
.rts.cmd2.CmdHeader =
CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd2), SC_ENABLE_RTS_CC, SC_ENABLE_RTS2_CKSUM),
.rts.cmd2.RtsId = 2,

/*
** 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))};
/* 3 */
.rts.hdr3.TimeTag = 5,
.rts.cmd3.CmdHeader = CFE_MSG_CMD_HDR_INIT(SC_CMD_MID, SC_MEMBER_SIZE(cmd3), SC_START_RTS_CC, SC_START_RTS2_CKSUM),
.rts.cmd3.RtsId = 2};

/*
** 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)
Loading

0 comments on commit c65b280

Please sign in to comment.