Skip to content

Commit

Permalink
Fix nasa#51, remove mid draft
Browse files Browse the repository at this point in the history
  • Loading branch information
chillfig committed Oct 11, 2022
1 parent 7e5bcb8 commit b3fbe1a
Show file tree
Hide file tree
Showing 10 changed files with 302 additions and 7 deletions.
7 changes: 7 additions & 0 deletions fsw/src/ds_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,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
86 changes: 86 additions & 0 deletions fsw/src/ds_cmds.c
Original file line number Diff line number Diff line change
Expand Up @@ -1442,6 +1442,92 @@ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr)
}
} /* 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
44 changes: 39 additions & 5 deletions fsw/src/ds_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,40 @@
*/
#define DS_ADD_MID_CMD_ERR_EID 65

/**
* \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 66

/**
* \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 67

/**
* \brief DS Close All Destination Files Command Event ID
*
Expand All @@ -799,7 +833,7 @@
*
* This command will succeed regardless of whether there was an open file.
*/
#define DS_CLOSE_ALL_CMD_EID 66
#define DS_CLOSE_ALL_CMD_EID 68

/**
* \brief DS Close All Destination Files Command Invalid Event ID
Expand All @@ -812,7 +846,7 @@
* all open Destination Files. The cause of the failure can only
* be an invalid command packet length.
*/
#define DS_CLOSE_ALL_CMD_ERR_EID 67
#define DS_CLOSE_ALL_CMD_ERR_EID 69

/**
* \brief DS File Create Invalid Name Event ID
Expand All @@ -824,7 +858,7 @@
* This event is generated when DS_FileCreateName is invoked with an
* empty path name.
*/
#define DS_FILE_CREATE_EMPTY_PATH_ERR_EID 68
#define DS_FILE_CREATE_EMPTY_PATH_ERR_EID 70

/**
* \brief DS Filter Table Name Invalid Event ID
Expand All @@ -836,7 +870,7 @@
* This event is issued when an invalid filter table name is passed to
* the CFE_TBL_GetInfo.
*/
#define DS_APPHK_FILTER_TBL_ERR_EID 69
#define DS_APPHK_FILTER_TBL_ERR_EID 71

/**
* \brief DS Filter Table Name Create Failed Event ID
Expand All @@ -848,7 +882,7 @@
* This event is issued when the filter table name is not successfully
* created (via snprintf) in the DS_AppProcessHK function.
*/
#define DS_APPHK_FILTER_TBL_PRINT_ERR_EID 70
#define DS_APPHK_FILTER_TBL_PRINT_ERR_EID 72

/**@}*/

Expand Down
13 changes: 13 additions & 0 deletions fsw/src/ds_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,19 @@ typedef struct

} 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 @@ -549,6 +549,38 @@
*/
#define DS_ADD_MID_CC 16

/**
* \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 17

/**
* \brief Close All Destination Files
*
Expand Down Expand Up @@ -577,7 +609,7 @@
* \par Criticality
* None
*/
#define DS_CLOSE_ALL_CC 17
#define DS_CLOSE_ALL_CC 18

/**\}*/

Expand Down
52 changes: 52 additions & 0 deletions fsw/src/ds_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -1109,6 +1109,58 @@ int32 DS_TableAddMsgID(CFE_SB_MsgId_t MessageID, int32 FilterIndex)

} /* End of DS_TableAddMsgID() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
/* 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.HashTable[FilterIndex];

/* Hash table function converts MID into hash table index */
HashIndex = DS_TableHashFunction(NewLink->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 @@ -613,6 +613,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
13 changes: 13 additions & 0 deletions unit-test/stubs/ds_cmds_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,19 @@ void DS_CmdAddMID(const CFE_SB_Buffer_t *BufPtr)

} /* 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 */
/************************/
Loading

0 comments on commit b3fbe1a

Please sign in to comment.