Skip to content

Commit

Permalink
Fix nasa#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 4090ed7
Show file tree
Hide file tree
Showing 33 changed files with 2,308 additions and 2,084 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
28 changes: 14 additions & 14 deletions fsw/inc/sc_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
* Implements the Noop command that insures the SC app is alive
*
* \par Command Structure
* #SC_NoArgsCmd_t
* #SC_NoopCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -132,7 +132,7 @@
* Resets the SC housekeeping counters
*
* \par Command Structure
* #SC_NoArgsCmd_t
* #SC_ResetCountersCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -195,7 +195,7 @@
* Stops the specified ATS
*
* \par Command Structure
* #SC_NoArgsCmd_t
* #SC_StopAtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -225,7 +225,7 @@
* Starts the specified RTS
*
* \par Command Structure
* #SC_RtsCmd_t
* #SC_StartRtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -261,7 +261,7 @@
* Stops the specified RTS
*
* \par Command Structure
* #SC_RtsCmd_t
* #SC_StopRtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -292,7 +292,7 @@
* Disables the specified RTS
*
* \par Command Structure
* #SC_RtsCmd_t
* #SC_DisableRtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -323,7 +323,7 @@
* Enables the specified RTS
*
* \par Command Structure
* #SC_RtsCmd_t
* #SC_EnableRtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -354,7 +354,7 @@
* Switches the running ATS and the ATS no running
*
* \par Command Structure
* #SC_NoArgsCmd_t
* #SC_SwitchAtsCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -416,7 +416,7 @@
* checksum validation before being sent out.
*
* \par Command Structure
* #SC_SetContinueAtsOnFailureCmd_t
* #SC_ContinueAtsOnFailureCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -485,7 +485,7 @@
* any source other than cFE Table Services.
*
* \par Command Structure
* #CFE_TBL_NotifyCmd_t
* #SC_ManageTableCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified via:
Expand Down Expand Up @@ -516,7 +516,7 @@
* currently LOADED, ENABLED and STOPPED.
*
* \par Command Structure
* #SC_RtsGrpCmd_t
* #SC_StartRtsGrpCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -556,7 +556,7 @@
* This command STOPS each RTS in the specified group that is currently STARTED.
*
* \par Command Structure
* #SC_RtsGrpCmd_t
* #SC_StopRtsGrpCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -594,7 +594,7 @@
* This command sets the enable state for the specified group of RTS to DISABLED.
*
* \par Command Structure
* #SC_RtsGrpCmd_t
* #SC_DisableRtsGrpCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
Expand Down Expand Up @@ -632,7 +632,7 @@
* This command sets the enable state for the specified group of RTS to ENABLED.
*
* \par Command Structure
* #SC_RtsGrpCmd_t
* #SC_EnableRtsGrpCmd_t
*
* \par Command Verification
* Successful execution of this command may be verified with
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 4090ed7

Please sign in to comment.