Skip to content

Commit

Permalink
Fix #51, remove mid
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfig committed Oct 31, 2022
1 parent 49d6a09 commit f9c2910
Show file tree
Hide file tree
Showing 9 changed files with 238 additions and 5 deletions.
7 changes: 7 additions & 0 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)...
*/
Expand Down
110 changes: 110 additions & 0 deletions fsw/src/ds_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/************************/
22 changes: 22 additions & 0 deletions fsw/src/ds_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
33 changes: 33 additions & 0 deletions fsw/src/ds_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions fsw/src/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**\}*/

/**
Expand Down
33 changes: 32 additions & 1 deletion fsw/src/ds_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Expand Down
19 changes: 18 additions & 1 deletion unit-test/stubs/ds_cmds_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
/************************/
4 changes: 2 additions & 2 deletions unit-test/stubs/ds_table_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ void DS_TableCreateHash(void)

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* Get filter table index for MID */
/* DS_TableAddMsgID() - get filter table index for MID */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Expand All @@ -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 */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Expand Down

0 comments on commit f9c2910

Please sign in to comment.