Skip to content

Commit

Permalink
Fix nasa#422, implement dispatcher pattern for CF
Browse files Browse the repository at this point in the history
Move message identification, validation, and routing to a separate
source file per the recommended CFS app patterns.
  • Loading branch information
jphickey committed Dec 13, 2023
1 parent 515e3a8 commit a844bf3
Show file tree
Hide file tree
Showing 23 changed files with 1,030 additions and 698 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ set(APP_SRC_FILES
fsw/src/cf_codec.c
fsw/src/cf_cmd.c
fsw/src/cf_crc.c
fsw/src/cf_dispatch.c
fsw/src/cf_timer.c
fsw/src/cf_utils.c
)
Expand Down
45 changes: 44 additions & 1 deletion config/default_cf_extern_typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
#ifndef CF_EXTERN_TYPEDEFS_H
#define CF_EXTERN_TYPEDEFS_H

#include "cf_platform_cfg.h"
/* constants such as CF_FILENAME_MAX_LEN are in mission_cfg.h */
#include "cf_mission_cfg.h"

/**
* @brief Values for CFDP file transfer class
Expand Down Expand Up @@ -70,4 +71,46 @@ typedef struct CF_TxnFilenames
char dst_filename[CF_FILENAME_MAX_LEN];
} CF_TxnFilenames_t;

/**
* @brief Entity id size
*
* @par Description:
* The maximum size of the entity id as expected for all CFDP packets.
* CF supports the spec's variable size of EID, where the actual size is
* selected at runtime, and therefore the size in CFDP PDUs may be smaller
* than the size specified here. This type only establishes the maximum
* size (and therefore maximum value) that an EID may be.
*
* @note This type is used in several CF commands, and so changing the size
* of this type will affect the following structs:
* CF_ConfigTable_t, configuration table - will change size of file
* CF_ConfigPacket_t, set config params command
* CF_TxFileCmd_t, transmit file command
* CF_PlaybackDirCmd_t, equivalent to above
* CF_Transaction_Payload_t, any command that selects a transaction based on EID
*
* @par Limits
* Must be one of uint8, uint16, uint32, uint64.
*/
typedef uint32 CF_EntityId_t;

/**
* @brief transaction sequence number size
*
* @par Description:
* The max size of the transaction sequence number as expected for all CFDP packets.
* CF supports the spec's variable size of TSN, where the actual size is
* selected at runtime, and therefore the size in CFDP PDUs may be smaller
* than the size specified here. This type only establishes the maximum
* size (and therefore maximum value) that a TSN may be.
*
* @note This type is used in several CF commands, and so changing the size
* of this type will affect the following structure:
* CF_Transaction_Payload_t, any command that selects a transaction based on TSN
*
* @par Limits
* Must be one of uint8, uint16, uint32, uint64.
*/
typedef uint32 CF_TransactionSeq_t;

#endif /* CF_EXTERN_TYPEDEFS_H */
8 changes: 4 additions & 4 deletions config/default_cf_fcncodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -400,9 +400,9 @@ typedef enum
* \par Criticality
* None
*
* \sa #CF_GET_MIB_PARAM_CC
* \sa #CF_GET_PARAM_CC
*/
CF_SET_MIB_PARAM_CC = 10,
CF_SET_PARAM_CC = 10,

/**
* \brief Get parameter
Expand Down Expand Up @@ -431,9 +431,9 @@ typedef enum
* \par Criticality
* None
*
* \sa #CF_SET_MIB_PARAM_CC
* \sa #CF_SET_PARAM_CC
*/
CF_GET_MIB_PARAM_CC = 11,
CF_GET_PARAM_CC = 11,

/**
* \brief Write queue
Expand Down
80 changes: 0 additions & 80 deletions config/default_cf_interface_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,48 +41,6 @@
* \{
*/

/**
* @brief Entity id size
*
* @par Description:
* The maximum size of the entity id as expected for all CFDP packets.
* CF supports the spec's variable size of EID, where the actual size is
* selected at runtime, and therefore the size in CFDP PDUs may be smaller
* than the size specified here. This type only establishes the maximum
* size (and therefore maximum value) that an EID may be.
*
* @note This type is used in several CF commands, and so changing the size
* of this type will affect the following structs:
* CF_ConfigTable_t, configuration table - will change size of file
* CF_ConfigPacket_t, set config params command
* CF_TxFileCmd_t, transmit file command
* CF_PlaybackDirCmd_t, equivalent to above
* CF_Transaction_Payload_t, any command that selects a transaction based on EID
*
* @par Limits
* Must be one of uint8, uint16, uint32, uint64.
*/
typedef uint32 CF_EntityId_t;

/**
* @brief transaction sequence number size
*
* @par Description:
* The max size of the transaction sequence number as expected for all CFDP packets.
* CF supports the spec's variable size of TSN, where the actual size is
* selected at runtime, and therefore the size in CFDP PDUs may be smaller
* than the size specified here. This type only establishes the maximum
* size (and therefore maximum value) that a TSN may be.
*
* @note This type is used in several CF commands, and so changing the size
* of this type will affect the following structure:
* CF_Transaction_Payload_t, any command that selects a transaction based on TSN
*
* @par Limits
* Must be one of uint8, uint16, uint32, uint64.
*/
typedef uint32 CF_TransactionSeq_t;

/**
* @brief Number of channels
*
Expand All @@ -108,20 +66,6 @@ typedef uint32 CF_TransactionSeq_t;
*/
#define CF_NAK_MAX_SEGMENTS (58)

/**
* @brief Total number of chunks (tx, rx, all channels)
*
* @par Description:
* Must be equal to the sum of all values input in CF_CHANNEL_NUM_RX_CHUNKS_PER_TRANSACTION
* and CF_CHANNEL_NUM_TX_CHUNKS_PER_TRANSACTION.
*
* @par Limits:
*
*/
/* CF_TOTAL_CHUNKS must be equal to the total number of chunks per rx/tx transactions per channel */
/* (in other words, the summation of all elements in CF_CHANNEL_NUM_R/TX_CHUNKS_PER_TRANSACTION */
#define CF_TOTAL_CHUNKS (CF_NAK_MAX_SEGMENTS * 4)

/**
* @brief Max number of polling directories per channel.
*
Expand Down Expand Up @@ -158,14 +102,6 @@ typedef uint32 CF_TransactionSeq_t;
*/
#define CF_FILENAME_MAX_NAME CFE_MISSION_MAX_FILE_LEN

/**
* @brief Maximum file path (not including file name)
*
* @par Limits:
*
*/
#define CF_FILENAME_MAX_PATH (CFE_MISSION_MAX_PATH_LEN - CFE_MISSION_MAX_FILE_LEN)

/**
* @brief Max filename and path length.
*
Expand Down Expand Up @@ -196,22 +132,6 @@ typedef uint32 CF_TransactionSeq_t;
*/
#define CF_PDU_ENCAPSULATION_EXTRA_TRAILING_BYTES 0

/**
* \brief Mission specific version number
*
* \par Description:
* An application version number consists of four parts:
* major version number, minor version number, revision
* number and mission specific revision number. The mission
* specific revision number is defined here such
* that missions can manage as a configuration definition
*
* \par Limits:
* Must be defined as a numeric value that is greater than
* or equal to zero.
*/
#define CF_MISSION_REV 0

/**\}*/

#endif
8 changes: 8 additions & 0 deletions config/default_cf_mission_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@

#include "cf_interface_cfg.h"

/**
* @brief Maximum file path (not including file name)
*
* @par Limits:
*
*/
#define CF_FILENAME_MAX_PATH (CFE_MISSION_MAX_PATH_LEN - CFE_MISSION_MAX_FILE_LEN)

#endif
20 changes: 20 additions & 0 deletions config/default_cf_msgstruct.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ typedef struct CF_AbandonCmd
CF_Transaction_Payload_t Payload;
} CF_AbandonCmd_t;

/**
* \brief Send Housekeeping Command
*
* Internal notification from SCH with no payload
*/
typedef struct CF_SendHkCmd
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */
} CF_SendHkCmd_t;

/**
* \brief Wake Up Command
*
* Internal notification from SCH with no payload
*/
typedef struct CF_WakeupCmd
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */
} CF_WakeupCmd_t;

/**\}*/

#endif
30 changes: 30 additions & 0 deletions config/default_cf_platform_cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,34 @@
#include "cf_mission_cfg.h"
#include "cf_internal_cfg.h"

/**
* @brief Total number of chunks (tx, rx, all channels)
*
* @par Description:
* Must be equal to the sum of all values input in CF_CHANNEL_NUM_RX_CHUNKS_PER_TRANSACTION
* and CF_CHANNEL_NUM_TX_CHUNKS_PER_TRANSACTION.
*
* @par Limits:
*
*/
/* CF_TOTAL_CHUNKS must be equal to the total number of chunks per rx/tx transactions per channel */
/* (in other words, the summation of all elements in CF_CHANNEL_NUM_R/TX_CHUNKS_PER_TRANSACTION */
#define CF_TOTAL_CHUNKS (CF_NAK_MAX_SEGMENTS * 4)

/**
* \brief Mission specific version number
*
* \par Description:
* An application version number consists of four parts:
* major version number, minor version number, revision
* number and mission specific revision number. The mission
* specific revision number is defined here such
* that missions can manage as a configuration definition
*
* \par Limits:
* Must be defined as a numeric value that is greater than
* or equal to zero.
*/
#define CF_MISSION_REV 0

#endif
4 changes: 2 additions & 2 deletions fsw/inc/cf_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@
*
* Invalid message ID received on the software bus pipe
*/
#define CF_EID_ERR_INIT_CMD_LENGTH (28)
#define CF_EID_ERR_INVALID_MID (28)

/**
* \brief CF SB Receive Buffer Failed Event ID
Expand Down Expand Up @@ -372,7 +372,7 @@
*
* Can be induced via various off-nominal conditions - such as sending a META-data PDU
* with an invalid file destination.
*
*
*/
#define CF_EID_DBG_RESET_FREED_XACT (59)

Expand Down
71 changes: 6 additions & 65 deletions fsw/src/cf_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,13 @@
#include "cf_perfids.h"
#include "cf_cfdp.h"
#include "cf_version.h"
#include "cf_cmd.h"
#include "cf_dispatch.h"
#include "cf_tbl.h"

#include <string.h>

CF_AppData_t CF_AppData;

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in cf_app.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_HkCmd(void)
{
CFE_MSG_SetMsgTime(&CF_AppData.hk.TelemetryHeader.Msg, CFE_TIME_GetTime());
/* return value ignored */ CFE_SB_TransmitMsg(&CF_AppData.hk.TelemetryHeader.Msg, true);
}

/*----------------------------------------------------------------
*
* Application-scope internal function
Expand Down Expand Up @@ -199,9 +188,9 @@ CFE_Status_t CF_TableInit(void)
*-----------------------------------------------------------------*/
CFE_Status_t CF_Init(void)
{
CFE_Status_t status;
static const CFE_SB_MsgId_Atom_t MID_VALUES[] = {CF_CMD_MID, CF_SEND_HK_MID, CF_WAKE_UP_MID};
uint32 i;
CFE_Status_t status;
const CFE_SB_MsgId_Atom_t MID_VALUES[] = {CF_CMD_MID, CF_SEND_HK_MID, CF_WAKE_UP_MID};
uint32 i;

CF_AppData.run_status = CFE_ES_RunStatus_APP_RUN;

Expand Down Expand Up @@ -260,54 +249,6 @@ CFE_Status_t CF_Init(void)
return status;
}

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in cf_app.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_WakeUp(void)
{
CFE_ES_PerfLogEntry(CF_PERF_ID_CYCLE_ENG);
CF_CFDP_CycleEngine();
CFE_ES_PerfLogExit(CF_PERF_ID_CYCLE_ENG);
}

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in cf_app.h for argument/return detail
*
*-----------------------------------------------------------------*/
void CF_ProcessMsg(CFE_SB_Buffer_t *msg)
{
CFE_SB_MsgId_t msg_id = CFE_SB_INVALID_MSG_ID;

CFE_MSG_GetMsgId(&msg->Msg, &msg_id);

switch (CFE_SB_MsgIdToValue(msg_id))
{
case CF_CMD_MID:
CF_ProcessGroundCommand(msg);
break;

case CF_WAKE_UP_MID:
CF_WakeUp();
break;

case CF_SEND_HK_MID:
CF_HkCmd();
CF_CheckTables();
break;

default:
++CF_AppData.hk.Payload.counters.err;
CFE_EVS_SendEvent(CF_EID_ERR_INIT_CMD_LENGTH, CFE_EVS_EventType_ERROR,
"CF: invalid command packet id=0x%lx", (unsigned long)CFE_SB_MsgIdToValue(msg_id));
break;
}
}

/*----------------------------------------------------------------
*
* Entry point function
Expand Down Expand Up @@ -342,7 +283,7 @@ void CF_AppMain(void)
*/
if (status == CFE_SUCCESS && msg != NULL)
{
CF_ProcessMsg(msg);
CF_AppPipe(msg);
}
else if (status != CFE_SB_TIME_OUT && status != CFE_SB_NO_MESSAGE)
{
Expand Down
Loading

0 comments on commit a844bf3

Please sign in to comment.