Skip to content

Commit

Permalink
Fix #108, dispatch pattern for SC
Browse files Browse the repository at this point in the history
Move switch statements to a separate dispatch source file, and update
all unit tests accordingly.

All business logic of commands is put into separate command handler
functions in sc_cmds.c.  No logic is inside the switch statement,
outside of message validation.
  • Loading branch information
jphickey committed Sep 29, 2023
1 parent 67c885c commit 5aec544
Show file tree
Hide file tree
Showing 32 changed files with 2,294 additions and 2,070 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(APP_SRC_FILES
fsw/src/sc_state.c
fsw/src/sc_loads.c
fsw/src/sc_cmds.c
fsw/src/sc_dispatch.c
)

# Create the app module
Expand Down
187 changes: 163 additions & 24 deletions fsw/inc/sc_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
#include <sc_platform_cfg.h>
#include <sc_msgdefs.h>

#include "cfe_tbl_msg.h"

/************************************************************************
* Macro Definitions
************************************************************************/
Expand Down Expand Up @@ -171,17 +173,6 @@ typedef struct
uint16 LastRtsId; /**< \brief ID of the last RTS to act on, 1 through #SC_NUMBER_OF_RTS */
} SC_RtsGrpCmd_Payload_t;

/**
* \brief No Arguments Command
*
* For command details see #SC_NOOP_CC, #SC_RESET_COUNTERS_CC, #SC_STOP_ATS_CC, #SC_SWITCH_ATS_CC
* Also see #SC_SEND_HK_MID
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_NoArgsCmd_t;

/**
* \brief ATS Id Command
*
Expand All @@ -193,17 +184,6 @@ typedef struct
SC_StartAtsCmd_Payload_t Payload;
} SC_StartAtsCmd_t;

/**
* \brief RTS Id Command
*
* For command details see #SC_START_RTS_CC, #SC_STOP_RTS_CC, #SC_DISABLE_RTS_CC, #SC_ENABLE_RTS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsCmd_Payload_t Payload;
} SC_RtsCmd_t;

/**
* \brief Jump running ATS to a new time Command
*
Expand Down Expand Up @@ -237,16 +217,175 @@ typedef struct
SC_AppendAtsCmd_Payload_t Payload;
} SC_AppendAtsCmd_t;

/**
* \brief Send HK Command
*
* For command details see #SC_SEND_HK_MID
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_SendHkCmd_t;

/**
* \brief 1Hz Wakeup Command
*
* For command details see #SC_1HZ_WAKEUP_MID
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_OneHzWakeupCmd_t;

/**
* \brief No operation Command
*
* For command details see #SC_NOOP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_NoopCmd_t;

/**
* \brief Reset Counters Command
*
* For command details see #SC_RESET_COUNTERS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_ResetCountersCmd_t;

/**
* \brief Stop ATS Command
*
* For command details see #SC_STOP_ATS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_StopAtsCmd_t;

/**
* \brief Switch ATS Command
*
* For command details see #SC_SWITCH_ATS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
} SC_SwitchAtsCmd_t;

/**
* \brief Start RTS Command
*
* For command details see #SC_START_RTS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsCmd_Payload_t Payload;
} SC_StartRtsCmd_t;

/**
* \brief Stop RTS Command
*
* For command details see #SC_STOP_RTS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsCmd_Payload_t Payload;
} SC_StopRtsCmd_t;

/**
* \brief Disable RTS Command
*
* For command details see #SC_DISABLE_RTS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsCmd_Payload_t Payload;
} SC_DisableRtsCmd_t;

/**
* \brief Enable RTS Command
*
* For command details see #SC_ENABLE_RTS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsCmd_Payload_t Payload;
} SC_EnableRtsCmd_t;

/**
* \brief Continue ATS on failure command
*
* For command details see #SC_CONTINUE_ATS_ON_FAILURE_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_SetContinueAtsOnFailureCmd_Payload_t Payload;
} SC_ContinueAtsOnFailureCmd_t;

/**
* \brief Manage Table Command
*
* For command details see #SC_MANAGE_TABLE_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
CFE_TBL_NotifyCmd_Payload_t Payload;
} SC_ManageTableCmd_t;

/**
* \brief RTS Group Command
*
* For command details see #SC_START_RTS_GRP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsGrpCmd_Payload_t Payload;
} SC_StartRtsGrpCmd_t;

/**
* \brief RTS Group Command
*
* For command details see #SC_STOP_RTS_GRP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsGrpCmd_Payload_t Payload;
} SC_StopRtsGrpCmd_t;

/**
* \brief RTS Group Command
*
* For command details see #SC_DISABLE_RTS_GRP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsGrpCmd_Payload_t Payload;
} SC_DisableRtsGrpCmd_t;

/**
* \brief RTS Group Command
*
* For command details see #SC_START_RTS_GRP_CC, #SC_STOP_RTS_GRP_CC, #SC_DISABLE_RTS_GRP_CC, #SC_ENABLE_RTS_GRP_CC
* For command details see #SC_ENABLE_RTS_GRP_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command Header */
SC_RtsGrpCmd_Payload_t Payload;
} SC_RtsGrpCmd_t;
} SC_EnableRtsGrpCmd_t;

/**\}*/

Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sc_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include "cfe.h"
#include "sc_app.h"
#include "sc_rts.h"
#include "sc_cmds.h"
#include "sc_dispatch.h"
#include "sc_loads.h"
#include "sc_events.h"
#include "sc_msgids.h"
Expand Down
2 changes: 1 addition & 1 deletion fsw/src/sc_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void SC_LoadDefaultTables(void);
* \par Assumptions, External Events, and Notes:
* None
*
* \sa #SC_TableManageCmd
* \sa #SC_ManageTableCmd
*/
void SC_RegisterManageCmds(void);

Expand Down
Loading

0 comments on commit 5aec544

Please sign in to comment.