Skip to content

Commit

Permalink
Fix #51, remove mid draft
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfig committed Oct 24, 2022
1 parent 49d6a09 commit 13484db
Show file tree
Hide file tree
Showing 10 changed files with 309 additions and 6 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
92 changes: 91 additions & 1 deletion fsw/src/ds_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1440,4 +1440,94 @@ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr)
(unsigned long)CFE_SB_MsgIdToValue(DS_AddMidCmd->MessageID), (int)FilterTableIndex,
(int)HashTableIndex);
}
}
} /* End of DS_CmdAddMID() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* 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;
int32 FilterTableIndex = 0;
int32 HashTableIndex = 0;

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_TableFindMsgID(DS_RemoveMidCmd->MessageID)) == 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
{
/*
** Free used packet filter entry for used message ID...
*/
pPacketEntry = &DS_AppData.FilterTblPtr->Packet[FilterTableIndex];

free(pPacketEntry);

/* Remove the message ID from the hash table as well */
HashTableIndex = DS_TableRemoveMsgID(DS_RemoveMidCmd->MessageID, FilterTableIndex);

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 DS_CmdRemoveMID() */

/************************/
/* End of File Comment */
/************************/
23 changes: 23 additions & 0 deletions fsw/src/ds_cmds.h
Original file line number Diff line number Diff line change
Expand Up @@ -444,4 +444,27 @@ 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 already in packet filter table
* - generate error event if no unused packet filter table entries
* 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
34 changes: 34 additions & 0 deletions fsw/src/ds_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -850,6 +850,40 @@
*/
#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 unused entry available for the new message ID and
* must not already contain the new 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
34 changes: 33 additions & 1 deletion fsw/src/ds_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,38 @@
*/
#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 an
* unused Packet Filter Table entry to the indicated value.
*
* \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_ADD_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 already exists in packet filter table
* - All packet filter table entries are already in use
*
* Evidence of failure may be found in the following telemetry:
* - #DS_HkPacket_t.CmdRejectedCounter will increment
* - The #DS_ADD_MID_CMD_ERR_EID error event message will be sent
*
* \par Criticality
* None
*/
#define DS_REMOVE_MID_CC 18

/**\}*/

#endif
#endif
54 changes: 53 additions & 1 deletion fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1095,7 +1095,59 @@ int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex)

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

int32 DS_TableRemoveMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex)
{
int32 HashIndex = 0;
DS_HashLink_t *RemoveLink = NULL;
DS_HashLink_t *LinkList = NULL;
DS_HashLink_t *PrevLink = NULL;

/* Get used linked list entry (one link entry per filter table entry) */
RemoveLink = &DS_AppData.HashLinks[FilterIndex];

/* Hash table function converts MID into hash table index */
HashIndex = DS_TableHashFunction(RemoveLink->MessageID);

if (DS_AppData.HashTable[HashIndex]->Index == RemoveLink->Index)
{
/* Remove first link in this hash table entry linked list */
free(RemoveLink);
}
else
{
/*
** Get start of linked list (all MID's with same hash result)
** Keep track of previous link as we need need to change 'PrevLink->Next'
*/
/* Get start of linked list (all MID's with same hash result) */
PrevLink = DS_AppData.HashTable[HashIndex];

LinkList = DS_AppData.HashTable[HashIndex]->Next;

/* Find link to remove */
while (LinkList->Index != RemoveLink->Index)
{
PrevLink = LinkList;
LinkList = LinkList->Next;
}

/* Remove link */
PrevLink->Next = LinkList->Next;

free(LinkList);
}

return (HashIndex);

} /* End of DS_TableRemoveMsgID() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* DS_TableFindMsgID() - get filter table index for MID */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Expand Down
21 changes: 21 additions & 0 deletions fsw/src/ds_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,6 +607,27 @@ void DS_TableCreateHash(void);
*/
int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex);

/**
* \brief Removes a message ID from the hash table
*
* \par Description
* This function removes a message ID from the hash table
*
* \par Called From:
* - Command to remove a MID
*
* \par Assumptions, External Events, and Notes:
* (none)
*
* \param[in] MessageID Message ID
* \param[in] FilterIndex Filter table index for message ID
*
* \return Hash table index for message ID
*
* \sa #DS_HashLink_t, #DS_TableHashFunction, #DS_TableFindMsgID
*/
int32 DS_TableRemoveMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex);

/**
* \brief Search packet filter table for message ID
*
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 */
/************************/
18 changes: 16 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,21 @@ int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex)

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

int32 DS_TableRemoveMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex)
{
UT_Stub_RegisterContextGenericArg(UT_KEY(DS_TableAddMsgID), MessageID);
UT_Stub_RegisterContextGenericArg(UT_KEY(DS_TableAddMsgID), FilterIndex);
return UT_DEFAULT_IMPL(DS_TableAddMsgID);

} /* End of DS_TableRemoveMsgID() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* DS_TableFindMsgID() - get filter table index for MID */
/* */
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

Expand Down

0 comments on commit 13484db

Please sign in to comment.