Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1449, Factor out common code for bitmask check #2248

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 32 additions & 43 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,22 +481,15 @@
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;

/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
(long unsigned int)CFE_EVS_ENABLE_PORTS_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
ReturnCode = CFE_EVS_CheckBitmaskInRange(CmdPtr, CFE_EVS_ENABLE_PORTS_CC);

if (ReturnCode == CFE_SUCCESS)
{
/* Process command data */
CFE_EVS_Global.EVS_TlmPkt.Payload.OutputPort |= CmdPtr->BitMask;

EVS_SendEvent(CFE_EVS_ENAPORT_EID, CFE_EVS_EventType_DEBUG,
"Enable Ports Command Received with Port Bit Mask = 0x%02x", (unsigned int)CmdPtr->BitMask);
ReturnCode = CFE_SUCCESS;
}

return ReturnCode;
Expand All @@ -513,23 +506,15 @@
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;

/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
(long unsigned int)CFE_EVS_DISABLE_PORTS_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
ReturnCode = CFE_EVS_CheckBitmaskInRange(CmdPtr, CFE_EVS_DISABLE_PORTS_CC);

if (ReturnCode == CFE_SUCCESS)
{
/* Process command data */
CFE_EVS_Global.EVS_TlmPkt.Payload.OutputPort &= ~CmdPtr->BitMask;

EVS_SendEvent(CFE_EVS_DISPORT_EID, CFE_EVS_EventType_DEBUG,
"Disable Ports Command Received with Port Bit Mask = 0x%02x", (unsigned int)CmdPtr->BitMask);

ReturnCode = CFE_SUCCESS;
}

return ReturnCode;
Expand All @@ -548,15 +533,9 @@
int32 ReturnCode;
EVS_AppData_t * AppDataPtr;

/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
(long unsigned int)CFE_EVS_ENABLE_EVENT_TYPE_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
else
ReturnCode = CFE_EVS_CheckBitmaskInRange(CmdPtr, CFE_EVS_ENABLE_EVENT_TYPE_CC);

if (ReturnCode == CFE_SUCCESS)
{
AppDataPtr = CFE_EVS_Global.AppData;
for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++)
Expand All @@ -572,8 +551,6 @@
EVS_SendEvent(CFE_EVS_ENAEVTTYPE_EID, CFE_EVS_EventType_DEBUG,
"Enable Event Type Command Received with Event Type Bit Mask = 0x%02x",
(unsigned int)CmdPtr->BitMask);

ReturnCode = CFE_SUCCESS;
}

return ReturnCode;
Expand All @@ -592,16 +569,9 @@
int32 ReturnCode;
EVS_AppData_t * AppDataPtr;

/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
(long unsigned int)CFE_EVS_DISABLE_EVENT_TYPE_CC);
ReturnCode = CFE_EVS_INVALID_PARAMETER;
}
ReturnCode = CFE_EVS_CheckBitmaskInRange(CmdPtr, CFE_EVS_DISABLE_EVENT_TYPE_CC);

else
if (ReturnCode == CFE_SUCCESS)
{
AppDataPtr = CFE_EVS_Global.AppData;
for (i = 0; i < CFE_PLATFORM_ES_MAX_APPLICATIONS; i++)
Expand All @@ -617,8 +587,6 @@
EVS_SendEvent(CFE_EVS_DISEVTTYPE_EID, CFE_EVS_EventType_DEBUG,
"Disable Event Type Command Received with Event Type Bit Mask = 0x%02x",
(unsigned int)CmdPtr->BitMask);

ReturnCode = CFE_SUCCESS;
}

return ReturnCode;
Expand Down Expand Up @@ -1292,3 +1260,24 @@

return Result;
}

/*----------------------------------------------------------------
*
* Application-scope internal function
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_EVS_CheckBitmaskInRange(const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr, uint16 CommandCode)

Check notice

Code scanning / CodeQL-coding-standard

Long function without assertion Note

All functions of more than 10 lines should have at least one assertion.
{
CFE_Status_t status = CFE_SUCCESS;

if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
(long unsigned int)CommandCode);
status = CFE_EVS_INVALID_PARAMETER;
}

return status;
}
10 changes: 10 additions & 0 deletions modules/evs/fsw/src/cfe_evs_task.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,4 +323,14 @@ int32 CFE_EVS_WriteAppDataFileCmd(const CFE_EVS_WriteAppDataFileCmd_t *data);
*/
int32 CFE_EVS_ResetAllFiltersCmd(const CFE_EVS_ResetAllFiltersCmd_t *data);

/*---------------------------------------------------------------------------------------*/
/**
* @brief Internal helper function to check if command bitmask is in range
*
* This routine checks if the given command bitmask is zero, or out of range (> 4 bits).
*
* @returns CFE_EVS_INVALID_PARAMETER if out of range, CFE_SUCCESS if within valid range
*/
CFE_Status_t CFE_EVS_CheckBitmaskInRange(const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr, uint16 CommandCode);

#endif /* CFE_EVS_TASK_H */
Loading