diff --git a/fsw/src/ds_app.c b/fsw/src/ds_app.c index 7e3a4ac..29f1361 100644 --- a/fsw/src/ds_app.c +++ b/fsw/src/ds_app.c @@ -467,6 +467,13 @@ void DS_AppProcessCmd(const CFE_SB_Buffer_t *BufPtr) 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)... */ diff --git a/fsw/src/ds_cmds.c b/fsw/src/ds_cmds.c index 0c15653..1eeb016 100644 --- a/fsw/src/ds_cmds.c +++ b/fsw/src/ds_cmds.c @@ -1441,3 +1441,113 @@ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr) (int)HashTableIndex); } } + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* DS_CmdRemoveMID() - remove message ID from packet filter table */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void DS_CmdRemoveMID(const CFE_SB_Buffer_t *BufPtr) +{ + DS_RemoveMidCmd_t *DS_RemoveMidCmd = (DS_RemoveMidCmd_t *)BufPtr; + size_t ActualLength = 0; + size_t ExpectedLength = sizeof(DS_RemoveMidCmd_t); + DS_PacketEntry_t * pPacketEntry = NULL; + DS_FilterParms_t * pFilterParms = NULL; + int32 FilterTableIndex = 0; + int32 HashTableIndex = 0; + int32 i = 0; + + CFE_MSG_GetSize(&BufPtr->Msg, &ActualLength); + FilterTableIndex = DS_TableFindMsgID(DS_RemoveMidCmd->MessageID); + + if (ExpectedLength != ActualLength) + { + /* + ** Invalid command packet length... + */ + DS_AppData.CmdRejectedCounter++; + + CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid REMOVE MID command length: expected = %d, actual = %d", (int)ExpectedLength, + (int)ActualLength); + } + else if (!CFE_SB_IsValidMsgId(DS_RemoveMidCmd->MessageID)) + { + /* + ** Invalid packet message ID - can be anything but unused... + */ + DS_AppData.CmdRejectedCounter++; + + CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid REMOVE MID command arg: invalid MID = 0x%08lX", + (unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID)); + } + else if (DS_AppData.FilterTblPtr == (DS_FilterTable_t *)NULL) + { + /* + ** Must have a valid packet filter table loaded... + */ + DS_AppData.CmdRejectedCounter++; + + CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid REMOVE MID command: filter table is not loaded"); + } + else if (FilterTableIndex == DS_INDEX_NONE) + { + /* + ** Message ID is not in packet filter table... + */ + DS_AppData.CmdRejectedCounter++; + + CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid REMOVE MID command: MID = 0x%08lX is not in filter table", + (unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID)); + } + else + { + /* Convert MID into hash table index */ + HashTableIndex = DS_TableHashFunction(DS_RemoveMidCmd->MessageID); + + /* + ** Reset used packet filter entry for used message ID... + */ + pPacketEntry = &DS_AppData.FilterTblPtr->Packet[FilterTableIndex]; + + pPacketEntry->MessageID = CFE_SB_INVALID_MSG_ID; + + /* Create new hash table as well */ + DS_TableCreateHash(); + + for (i = 0; i < DS_FILTERS_PER_PACKET; i++) + { + pFilterParms = &pPacketEntry->Filter[i]; + + pFilterParms->FileTableIndex = 0; + pFilterParms->FilterType = DS_BY_COUNT; + + pFilterParms->Algorithm_N = 0; + pFilterParms->Algorithm_X = 0; + pFilterParms->Algorithm_O = 0; + } + + CFE_SB_Unsubscribe(DS_RemoveMidCmd->MessageID, DS_AppData.InputPipe); + + /* + ** Notify cFE that we have modified the table data... + */ + CFE_TBL_Modified(DS_AppData.FilterTblHandle); + + DS_AppData.CmdAcceptedCounter++; + + CFE_EVS_SendEvent(DS_REMOVE_MID_CMD_EID, CFE_EVS_EventType_DEBUG, + "REMOVE MID command: MID = 0x%08lX, filter index = %d, hash index = %d", + (unsigned long)CFE_SB_MsgIdToValue(DS_RemoveMidCmd->MessageID), (int)FilterTableIndex, + (int)HashTableIndex); + } +} + +/************************/ +/* End of File Comment */ +/************************/ diff --git a/fsw/src/ds_cmds.h b/fsw/src/ds_cmds.h index 26f4e8c..08d45ef 100644 --- a/fsw/src/ds_cmds.h +++ b/fsw/src/ds_cmds.h @@ -444,4 +444,26 @@ void DS_CmdGetFileInfo(const CFE_SB_Buffer_t *BufPtr); */ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr); +/** + * \brief Remove Message ID from Packet Filter Table + * + * \par Description + * Remove used packet filter table entry + * Reject invalid commands + * - generate error event if invalid command packet length + * - generate error event if MID argument is invalid (cannot be zero) + * - generate error event if packet filter table is not loaded + * - generate error event if MID is not in packet filter table + * Accept valid commands + * - generate success event (event type = debug) + * + * \par Assumptions, External Events, and Notes: + * (none) + * + * \param[in] BufPtr Software Bus message pointer + * + * \sa #DS_REMOVE_MID_CC, #DS_RemoveMidCmd_t + */ +void DS_CmdRemoveMID(const CFE_SB_Buffer_t *BufPtr); + #endif diff --git a/fsw/src/ds_events.h b/fsw/src/ds_events.h index c41dbbf..121ae32 100644 --- a/fsw/src/ds_events.h +++ b/fsw/src/ds_events.h @@ -850,6 +850,39 @@ */ #define DS_APPHK_FILTER_TBL_PRINT_ERR_EID 70 +/** + * \brief DS Remove Message ID from Filter Table Command Event ID + * + * \par Type: DEBUG + * + * \par Cause: + * + * This event signals the successful execution of a command to remove + * a message ID from the Packet Filter Table. + * + * The Packet Filter Table must be loaded and have a used entry + * for removing the message ID. The message ID must not be zero + * be and must already exist in the table. + */ +#define DS_REMOVE_MID_CMD_EID 71 + +/** + * \brief DS Remove Message ID from Filter Table Command Invalid Event ID + * + * \par Type: ERROR + * + * \par Cause: + * + * This event signals the failed execution of a command to remove a + * message ID from the Packet Filter Table. The cause of the failure + * may be an invalid command packet length or an invalid message ID. + * + * The failure may also result from not having a Packet Filter Table + * loaded at the time the command was invoked. The loaded table + * must have an entry with the indicated message ID. + */ +#define DS_REMOVE_MID_CMD_ERR_EID 72 + /**@}*/ #endif diff --git a/fsw/src/ds_msg.h b/fsw/src/ds_msg.h index eac1f70..c97e593 100644 --- a/fsw/src/ds_msg.h +++ b/fsw/src/ds_msg.h @@ -269,6 +269,19 @@ typedef struct CFE_SB_MsgId_t MessageID; /**< \brief Message ID to add to Packet Filter Table */ } DS_AddMidCmd_t; +/** + * \brief Remove Message ID from Packet Filter Table + * + * For command details see #DS_REMOVE_MID_CC + */ +typedef struct +{ + CFE_MSG_CommandHeader_t CmdHeader; /**< \brief cFE Software Bus command message header */ + + CFE_SB_MsgId_t MessageID; /**< \brief Message ID to add to Packet Filter Table */ + +} DS_RemoveMidCmd_t; + /**\}*/ /** diff --git a/fsw/src/ds_msgdefs.h b/fsw/src/ds_msgdefs.h index a616fd4..00881b2 100644 --- a/fsw/src/ds_msgdefs.h +++ b/fsw/src/ds_msgdefs.h @@ -579,6 +579,37 @@ */ #define DS_CLOSE_ALL_CC 17 +/** + * \brief Remove Message ID from Packet Filter Table + * + * \par Description + * This command will change the Message ID selection for a + * used Packet Filter Table entry to unused (0). + * + * \par Command Structure + * #DS_RemoveMidCmd_t + * + * \par Command Verification + * Evidence of success may be found in the following telemetry: + * - #DS_HkPacket_t.CmdAcceptedCounter will increment + * - The #DS_REMOVE_MID_CMD_EID debug event message will be sent + * + * \par Error Conditions + * This command can fail for the following reasons: + * - Invalid command packet length + * - Message ID is invalid (can be anything but zero) + * - Packet filter table is not currently loaded + * - Message ID does not exist in packet filter table + * + * Evidence of failure may be found in the following telemetry: + * - #DS_HkPacket_t.CmdRejectedCounter will increment + * - The #DS_REMOVE_MID_CMD_ERR_EID error event message will be sent + * + * \par Criticality + * None + */ +#define DS_REMOVE_MID_CC 18 + /**\}*/ -#endif +#endif \ No newline at end of file diff --git a/fsw/src/ds_table.c b/fsw/src/ds_table.c index f81fa34..f838833 100644 --- a/fsw/src/ds_table.c +++ b/fsw/src/ds_table.c @@ -1095,7 +1095,7 @@ int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* Get filter table index for MID */ +/* DS_TableFindMsgID() - get filter table index for MID */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ diff --git a/unit-test/stubs/ds_cmds_stubs.c b/unit-test/stubs/ds_cmds_stubs.c index 002d2e1..65ea8e4 100644 --- a/unit-test/stubs/ds_cmds_stubs.c +++ b/unit-test/stubs/ds_cmds_stubs.c @@ -259,4 +259,21 @@ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr) { UT_Stub_RegisterContextGenericArg(UT_KEY(DS_CmdAddMID), BufPtr); UT_DEFAULT_IMPL(DS_CmdAddMID); -} +} /* End of DS_CmdAddMID() */ + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* DS_CmdRemoveMID() - remove message ID from packet filter table */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ + +void DS_CmdRemoveMID(const CFE_SB_Buffer_t *BufPtr) +{ + UT_Stub_RegisterContextGenericArg(UT_KEY(DS_CmdRemoveMID), BufPtr); + UT_DEFAULT_IMPL(DS_CmdRemoveMID); + +} /* End of DS_CmdRemoveMID() */ + +/************************/ +/* End of File Comment */ +/************************/ diff --git a/unit-test/stubs/ds_table_stubs.c b/unit-test/stubs/ds_table_stubs.c index 2bd4a3d..39b6773 100644 --- a/unit-test/stubs/ds_table_stubs.c +++ b/unit-test/stubs/ds_table_stubs.c @@ -296,7 +296,7 @@ void DS_TableCreateHash(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* Get filter table index for MID */ +/* DS_TableAddMsgID() - get filter table index for MID */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -309,7 +309,7 @@ int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ -/* Get filter table index for MID */ +/* DS_TableFindMsgID() - get filter table index for MID */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */