Skip to content

Commit

Permalink
Merge pull request #103 from jphickey/fix-96-use-dispatch
Browse files Browse the repository at this point in the history
Fix #96, use separate dispatcher for messages
  • Loading branch information
dzbaker authored Apr 6, 2023
2 parents 15035a8 + a5903c8 commit 625828e
Show file tree
Hide file tree
Showing 18 changed files with 2,088 additions and 3,983 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ set(APP_SRC_FILES
fsw/src/ds_cmds.c
fsw/src/ds_app.c
fsw/src/ds_file.c
fsw/src/ds_dispatch.c
)

# Create the app module
Expand Down
2 changes: 1 addition & 1 deletion fsw/inc/ds_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -846,7 +846,7 @@
* \par Cause:
*
* This event is issued when the filter table name is not successfully
* created (via snprintf) in the DS_AppProcessHK function.
* created (via snprintf) in the DS_AppSendHkCmd function.
*/
#define DS_APPHK_FILTER_TBL_PRINT_ERR_EID 70

Expand Down
12 changes: 10 additions & 2 deletions fsw/inc/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@
* \{
*/

/**
* \brief Send HK Request
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief cFE Software Bus command message header */
} DS_SendHkCmd_t;

/**
* \brief No-Operation Command
*
Expand All @@ -45,12 +53,12 @@ typedef struct
/**
* \brief Reset Housekeeping Telemetry Command
*
* For command details see #DS_RESET_CC
* For command details see #DS_RESET_COUNTERS_CC
*/
typedef struct
{
CFE_MSG_CommandHeader_t CommandHeader; /**< \brief cFE Software Bus command message header */
} DS_ResetCmd_t;
} DS_ResetCountersCmd_t;

/**
* \brief Payload containing Ena/Dis State
Expand Down
4 changes: 2 additions & 2 deletions fsw/inc/ds_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
* This command will set the housekeeping counters to zero
*
* \par Command Structure
* #DS_ResetCmd_t
* #DS_ResetCountersCmd_t
*
* \par Command Verification
* Evidence of success may be found in the following telemetry:
Expand All @@ -83,7 +83,7 @@
* \par Criticality
* None
*/
#define DS_RESET_CC 1
#define DS_RESET_COUNTERS_CC 1

/**
* \brief Set Enable/Disable State For DS Application
Expand Down
225 changes: 4 additions & 221 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

#include "ds_msg.h"
#include "ds_app.h"
#include "ds_dispatch.h"
#include "ds_cmds.h"
#include "ds_file.h"
#include "ds_table.h"
Expand Down Expand Up @@ -273,231 +274,13 @@ int32 DS_AppInitialize(void)
return Result;
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process Software Bus messages */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void DS_AppProcessMsg(const CFE_SB_Buffer_t *BufPtr)
{
CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID;
size_t ActualLength = 0;
size_t ExpectedLength = 0;

CFE_MSG_GetMsgId(&BufPtr->Msg, &MessageID);

switch (CFE_SB_MsgIdToValue(MessageID))
{
/*
** DS application commands...
*/
case DS_CMD_MID:
DS_AppProcessCmd(BufPtr);
if (DS_TableFindMsgID(MessageID) != DS_INDEX_NONE)
{
DS_AppStorePacket(MessageID, BufPtr);
}
break;

/*
** DS housekeeping request command...
*/
case DS_SEND_HK_MID:

CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength);
ExpectedLength = sizeof(DS_NoopCmd_t);
if (ExpectedLength != ActualLength)
{
CFE_EVS_SendEvent(DS_HK_REQUEST_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid HK request length: expected = %d, actual = %d", (int)ExpectedLength,
(int)ActualLength);
}
else
{
DS_AppProcessHK();
if (DS_TableFindMsgID(MessageID) != DS_INDEX_NONE)
{
DS_AppStorePacket(MessageID, BufPtr);
}
}
break;

/*
** Unknown message ID's (must be something to store)...
*/
default:
DS_AppStorePacket(MessageID, BufPtr);
break;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process application commands */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void DS_AppProcessCmd(const CFE_SB_Buffer_t *BufPtr)
{
CFE_MSG_FcnCode_t CommandCode = 0;

CFE_MSG_GetFcnCode(&BufPtr->Msg, &CommandCode);

switch (CommandCode)
{
/*
** Do nothing command (aliveness test)...
*/
case DS_NOOP_CC:
DS_CmdNoop(BufPtr);
break;

/*
** Set housekeeping telemetry counters to zero...
*/
case DS_RESET_CC:
DS_CmdReset(BufPtr);
break;

/*
** Set DS application enable/disable state...
*/
case DS_SET_APP_STATE_CC:
DS_CmdSetAppState(BufPtr);
break;

/*
** Set packet filter file index...
*/
case DS_SET_FILTER_FILE_CC:
DS_CmdSetFilterFile(BufPtr);
break;

/*
** Set packet filter type (time vs count)...
*/
case DS_SET_FILTER_TYPE_CC:
DS_CmdSetFilterType(BufPtr);
break;

/*
** Set packet filter algorithm parameters...
*/
case DS_SET_FILTER_PARMS_CC:
DS_CmdSetFilterParms(BufPtr);
break;

/*
** Set destination file filename type (time vs count)...
*/
case DS_SET_DEST_TYPE_CC:
DS_CmdSetDestType(BufPtr);
break;

/*
** Set destination file enable/disable state...
*/
case DS_SET_DEST_STATE_CC:
DS_CmdSetDestState(BufPtr);
break;

/*
** Set destination file path portion of filename...
*/
case DS_SET_DEST_PATH_CC:
DS_CmdSetDestPath(BufPtr);
break;

/*
** Set destination file base portion of filename...
*/
case DS_SET_DEST_BASE_CC:
DS_CmdSetDestBase(BufPtr);
break;

/*
** Set destination file extension portion of filename...
*/
case DS_SET_DEST_EXT_CC:
DS_CmdSetDestExt(BufPtr);
break;

/*
** Set destination file maximum size limit...
*/
case DS_SET_DEST_SIZE_CC:
DS_CmdSetDestSize(BufPtr);
break;

/*
** Set destination file maximum age limit...
*/
case DS_SET_DEST_AGE_CC:
DS_CmdSetDestAge(BufPtr);
break;

/*
** Set destination file sequence count portion of filename...
*/
case DS_SET_DEST_COUNT_CC:
DS_CmdSetDestCount(BufPtr);
break;

/*
** Close destination file (next packet will re-open)...
*/
case DS_CLOSE_FILE_CC:
DS_CmdCloseFile(BufPtr);
break;

/*
** Get file info telemetry packet...
*/
case DS_GET_FILE_INFO_CC:
DS_CmdGetFileInfo(BufPtr);
break;

/*
** Add message ID to filter table...
*/
case DS_ADD_MID_CC:
DS_CmdAddMID(BufPtr);
break;

/*
** Remove message ID from filter table...
*/
case DS_REMOVE_MID_CC:
DS_CmdRemoveMID(BufPtr);
break;

/*
** Close all destination files (next packet will re-open)...
*/
case DS_CLOSE_ALL_CC:
DS_CmdCloseAll(BufPtr);
break;

/*
** DS application command with unknown command code...
*/
default:
CFE_EVS_SendEvent(DS_CMD_CODE_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid command code: MID = 0x%08X, CC = %d", DS_CMD_MID, CommandCode);

DS_AppData.CmdRejectedCounter++;
break;
}
}

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Process hk request command */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

void DS_AppProcessHK(void)
void DS_AppSendHkCmd(void)
{
DS_HkPacket_t HkPacket;
int32 i = 0;
Expand Down Expand Up @@ -588,7 +371,7 @@ void DS_AppProcessHK(void)
/* If the filter table name is invalid, send an event and erase any
* stale/misleading filename from the HK packet */
CFE_EVS_SendEvent(DS_APPHK_FILTER_TBL_ERR_EID, CFE_EVS_EventType_ERROR,
"Invalid filter tbl name in DS_AppProcessHK. Name=%s, Err=0x%08X", FilterTblName, Status);
"Invalid filter tbl name in DS_AppSendHkCmd. Name=%s, Err=0x%08X", FilterTblName, Status);

memset(PayloadPtr->FilterTblFilename, 0, sizeof(PayloadPtr->FilterTblFilename));
}
Expand All @@ -598,7 +381,7 @@ void DS_AppProcessHK(void)
/* If the filter table name couldn't be copied, send an event and erase
* any stale/misleading filename from the HK packet */
CFE_EVS_SendEvent(DS_APPHK_FILTER_TBL_PRINT_ERR_EID, CFE_EVS_EventType_ERROR,
"Filter tbl name copy fail in DS_AppProcessHK. Err=%d", (int)Status);
"Filter tbl name copy fail in DS_AppSendHkCmd. Err=%d", (int)Status);

memset(PayloadPtr->FilterTblFilename, 0, sizeof(PayloadPtr->FilterTblFilename));
}
Expand Down
33 changes: 1 addition & 32 deletions fsw/src/ds_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,37 +147,6 @@ void DS_AppMain(void);
*/
int32 DS_AppInitialize(void);

/**
* \brief Software Bus message handler
*
* \par Description
* Process packets received via Software Bus message pipe
* - may call application housekeeping request command handler
* - may call 1Hz wakeup command handler (if enabled)
* - may call application ground command handler
* All packets are processed for possible data storage
*
* \par Assumptions, External Events, and Notes:
* (none)
*
* \param[in] BufPtr Software Bus message pointer
*/
void DS_AppProcessMsg(const CFE_SB_Buffer_t *BufPtr);

/**
* \brief Application ground command handler
*
* \par Description
* Call command code specific DS command handler function
* Generate command error event for unknown command codes
*
* \par Assumptions, External Events, and Notes:
* (none)
*
* \param[in] BufPtr Software Bus message pointer
*/
void DS_AppProcessCmd(const CFE_SB_Buffer_t *BufPtr);

/**
* \brief Application housekeeping request command handler
*
Expand All @@ -190,7 +159,7 @@ void DS_AppProcessCmd(const CFE_SB_Buffer_t *BufPtr);
*
* \sa #DS_HkPacket_t
*/
void DS_AppProcessHK(void);
void DS_AppSendHkCmd(void);

/**
* \brief Application packet storage pre-processor
Expand Down
Loading

0 comments on commit 625828e

Please sign in to comment.