diff --git a/modules/evs/config/default_cfe_evs_msgdefs.h b/modules/evs/config/default_cfe_evs_msgdefs.h index ec295e80a..2f9ad6fd0 100644 --- a/modules/evs/config/default_cfe_evs_msgdefs.h +++ b/modules/evs/config/default_cfe_evs_msgdefs.h @@ -33,16 +33,18 @@ #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 + +#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 */ diff --git a/modules/evs/fsw/src/cfe_evs_task.c b/modules/evs/fsw/src/cfe_evs_task.c index 61f1b901b..d75224722 100644 --- a/modules/evs/fsw/src/cfe_evs_task.c +++ b/modules/evs/fsw/src/cfe_evs_task.c @@ -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 @@ -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; @@ -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 @@ -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; @@ -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 @@ -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; @@ -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; @@ -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; @@ -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 @@ -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 diff --git a/modules/evs/fsw/src/cfe_evs_utils.c b/modules/evs/fsw/src/cfe_evs_utils.c index db3afd915..987889992 100644 --- a/modules/evs/fsw/src/cfe_evs_utils.c +++ b/modules/evs/fsw/src/cfe_evs_utils.c @@ -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); } /*---------------------------------------------------------------- @@ -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); } /*---------------------------------------------------------------- @@ -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; +} \ No newline at end of file diff --git a/modules/evs/fsw/src/cfe_evs_utils.h b/modules/evs/fsw/src/cfe_evs_utils.h index 866b51e79..eb39f7aa7 100644 --- a/modules/evs/fsw/src/cfe_evs_utils.h +++ b/modules/evs/fsw/src/cfe_evs_utils.h @@ -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. 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 */