Skip to content

Commit

Permalink
Fix nasa#1447, Fix nasa#1438: Event type bitmask derivation and handl…
Browse files Browse the repository at this point in the history
…ing improvements
  • Loading branch information
thnkslprpt committed Oct 13, 2024
1 parent 78b8fd7 commit 0b1fe43
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 50 deletions.
19 changes: 11 additions & 8 deletions modules/evs/config/default_cfe_evs_msgdefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,19 @@
#include "cfe_evs_fcncodes.h"

/* Event Type bit masks */
#define CFE_EVS_DEBUG_BIT 0x0001
#define CFE_EVS_INFORMATION_BIT 0x0002
#define CFE_EVS_ERROR_BIT 0x0004
#define CFE_EVS_CRITICAL_BIT 0x0008
#define CFE_EVS_DEBUG_BIT (1 << (CFE_EVS_EventType_DEBUG - 1)) // 0x0001
#define CFE_EVS_INFORMATION_BIT (1 << (CFE_EVS_EventType_INFORMATION - 1)) // 0x0002
#define CFE_EVS_ERROR_BIT (1 << (CFE_EVS_EventType_ERROR - 1)) // 0x0004
#define CFE_EVS_CRITICAL_BIT (1 << (CFE_EVS_EventType_CRITICAL - 1)) // 0x0008

/* Macro representing all event types turned on */
#define CFE_EVS_ALL_EVENT_TYPES_MASK (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT)

/* Output Port bit masks */
#define CFE_EVS_PORT1_BIT 0x0001
#define CFE_EVS_PORT2_BIT 0x0002
#define CFE_EVS_PORT3_BIT 0x0004
#define CFE_EVS_PORT4_BIT 0x0008
#define CFE_EVS_PORT1_BIT (1 << (CFE_EVS_EventOutput_PORT1 - 1)) // 0x0001
#define CFE_EVS_PORT2_BIT (1 << (CFE_EVS_EventOutput_PORT2 - 1)) // 0x0002
#define CFE_EVS_PORT3_BIT (1 << (CFE_EVS_EventOutput_PORT3 - 1)) // 0x0004
#define CFE_EVS_PORT4_BIT (1 << (CFE_EVS_EventOutput_PORT4 - 1)) // 0x0008

/***********************************/
/* Command Message Data Payloads */
Expand Down
46 changes: 10 additions & 36 deletions modules/evs/fsw/src/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,11 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilterCmd_t *data)
int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
{
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
int32 ReturnCode = CFE_SUCCESS;

/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_PORTS_CC))
{
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
Expand All @@ -496,7 +493,6 @@ int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)

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 @@ -511,14 +507,11 @@ int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
int32 CFE_EVS_DisablePortsCmd(const CFE_EVS_DisablePortsCmd_t *data)
{
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
int32 ReturnCode = CFE_SUCCESS;

/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_PORTS_CC))
{
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
Expand All @@ -528,8 +521,6 @@ int32 CFE_EVS_DisablePortsCmd(const CFE_EVS_DisablePortsCmd_t *data)

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 @@ -545,15 +536,12 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventTypeCmd_t *data)
{
uint32 i;
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
int32 ReturnCode = CFE_SUCCESS;
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)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_EVENT_TYPE_CC))
{
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
Expand All @@ -572,8 +560,6 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventTypeCmd_t *data)
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 @@ -590,17 +576,13 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventTypeCmd_t *data)
uint32 i;
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
int32 ReturnCode;
EVS_AppData_t * AppDataPtr;
EVS_AppData_t *AppDataPtr = CFE_SUCCESS;

/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_EVENT_TYPE_CC))
{
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;
}

else
{
AppDataPtr = CFE_EVS_Global.AppData;
Expand All @@ -617,8 +599,6 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventTypeCmd_t *data)
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 @@ -676,11 +656,8 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventTypeCmd_t *data)
if (Status == CFE_SUCCESS)
{
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_APP_EVENT_TYPE_CC))
{
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_APP_EVENT_TYPE_CC);
Status = CFE_EVS_INVALID_PARAMETER;
}
else
Expand Down Expand Up @@ -738,11 +715,8 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventTypeCmd_t *dat
if (Status == CFE_SUCCESS)
{
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_APP_EVENT_TYPE_CC))
{
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_APP_EVENT_TYPE_CC);
Status = CFE_EVS_INVALID_PARAMETER;
}
else
Expand Down
20 changes: 14 additions & 6 deletions modules/evs/fsw/src/cfe_evs_utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,8 @@ EVS_BinFilter_t *EVS_FindEventID(uint16 EventID, EVS_BinFilter_t *FilterArray)
*-----------------------------------------------------------------*/
void EVS_EnableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
{
uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT);

/* Enable selected event type bits from bitmask */
AppDataPtr->EventTypesActiveFlag |= (BitMask & EventTypeBits);
AppDataPtr->EventTypesActiveFlag |= (BitMask & CFE_EVS_ALL_EVENT_TYPES_MASK);
}

/*----------------------------------------------------------------
Expand All @@ -437,10 +435,8 @@ void EVS_EnableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
*-----------------------------------------------------------------*/
void EVS_DisableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
{
uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT);

/* Disable selected event type bits from bitmask */
AppDataPtr->EventTypesActiveFlag &= ~(BitMask & EventTypeBits);
AppDataPtr->EventTypesActiveFlag &= ~(BitMask & CFE_EVS_ALL_EVENT_TYPES_MASK);
}

/*----------------------------------------------------------------
Expand Down Expand Up @@ -621,3 +617,15 @@ int32 EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...)

return CFE_SUCCESS;
}

bool EVS_IsInvalidBitMask(uint32 BitMask, uint16 CommandCode)
{
if ((BitMask) == 0x0 || (BitMask) > CFE_EVS_ALL_EVENT_TYPES_MASK)
{
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
"Bit Mask = 0x%08x out of range: CC = %u", (unsigned int)BitMask, (unsigned int)CommandCode);
return true;
}

return false;
}
14 changes: 14 additions & 0 deletions modules/evs/fsw/src/cfe_evs_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,18 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
*/
int32 EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...);

/**
* @brief Checks if the provided BitMask is invalid.
*
* This function evaluates whether the given BitMask is either zero or exceeds the maximum allowed
* value defined by CFE_EVS_ALL_EVENT_TYPES_MASK (which represents all events types turned on).
* If the BitMask is invalid, an error event is sent and the function returns true.
*
* @param BitMask The bitmask to be checked.
* @param CommandCode The command code associated with the bitmask.
*
* @return true if the BitMask is invalid, false otherwise.
*/
bool EVS_IsInvalidBitMask(uint32 BitMask, uint16 CommandCode);

#endif /* CFE_EVS_UTILS_H */

0 comments on commit 0b1fe43

Please sign in to comment.