Skip to content

Commit 0b1fe43

Browse files
committed
Fix #1447, Fix #1438: Event type bitmask derivation and handling improvements
1 parent 78b8fd7 commit 0b1fe43

File tree

4 files changed

+49
-50
lines changed

4 files changed

+49
-50
lines changed

modules/evs/config/default_cfe_evs_msgdefs.h

+11-8
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@
3333
#include "cfe_evs_fcncodes.h"
3434

3535
/* Event Type bit masks */
36-
#define CFE_EVS_DEBUG_BIT 0x0001
37-
#define CFE_EVS_INFORMATION_BIT 0x0002
38-
#define CFE_EVS_ERROR_BIT 0x0004
39-
#define CFE_EVS_CRITICAL_BIT 0x0008
36+
#define CFE_EVS_DEBUG_BIT (1 << (CFE_EVS_EventType_DEBUG - 1)) // 0x0001
37+
#define CFE_EVS_INFORMATION_BIT (1 << (CFE_EVS_EventType_INFORMATION - 1)) // 0x0002
38+
#define CFE_EVS_ERROR_BIT (1 << (CFE_EVS_EventType_ERROR - 1)) // 0x0004
39+
#define CFE_EVS_CRITICAL_BIT (1 << (CFE_EVS_EventType_CRITICAL - 1)) // 0x0008
40+
41+
/* Macro representing all event types turned on */
42+
#define CFE_EVS_ALL_EVENT_TYPES_MASK (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT)
4043

4144
/* Output Port bit masks */
42-
#define CFE_EVS_PORT1_BIT 0x0001
43-
#define CFE_EVS_PORT2_BIT 0x0002
44-
#define CFE_EVS_PORT3_BIT 0x0004
45-
#define CFE_EVS_PORT4_BIT 0x0008
45+
#define CFE_EVS_PORT1_BIT (1 << (CFE_EVS_EventOutput_PORT1 - 1)) // 0x0001
46+
#define CFE_EVS_PORT2_BIT (1 << (CFE_EVS_EventOutput_PORT2 - 1)) // 0x0002
47+
#define CFE_EVS_PORT3_BIT (1 << (CFE_EVS_EventOutput_PORT3 - 1)) // 0x0004
48+
#define CFE_EVS_PORT4_BIT (1 << (CFE_EVS_EventOutput_PORT4 - 1)) // 0x0008
4649

4750
/***********************************/
4851
/* Command Message Data Payloads */

modules/evs/fsw/src/cfe_evs_task.c

+10-36
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,11 @@ int32 CFE_EVS_SetFilterCmd(const CFE_EVS_SetFilterCmd_t *data)
479479
int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
480480
{
481481
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
482-
int32 ReturnCode;
482+
int32 ReturnCode = CFE_SUCCESS;
483483

484484
/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
485-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
485+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_PORTS_CC))
486486
{
487-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
488-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
489-
(long unsigned int)CFE_EVS_ENABLE_PORTS_CC);
490487
ReturnCode = CFE_EVS_INVALID_PARAMETER;
491488
}
492489
else
@@ -496,7 +493,6 @@ int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
496493

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

502498
return ReturnCode;
@@ -511,14 +507,11 @@ int32 CFE_EVS_EnablePortsCmd(const CFE_EVS_EnablePortsCmd_t *data)
511507
int32 CFE_EVS_DisablePortsCmd(const CFE_EVS_DisablePortsCmd_t *data)
512508
{
513509
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
514-
int32 ReturnCode;
510+
int32 ReturnCode = CFE_SUCCESS;
515511

516512
/* Need to check for an out of range bitmask, since oue bit masks are only 4 bits */
517-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
513+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_PORTS_CC))
518514
{
519-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
520-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
521-
(long unsigned int)CFE_EVS_DISABLE_PORTS_CC);
522515
ReturnCode = CFE_EVS_INVALID_PARAMETER;
523516
}
524517
else
@@ -528,8 +521,6 @@ int32 CFE_EVS_DisablePortsCmd(const CFE_EVS_DisablePortsCmd_t *data)
528521

529522
EVS_SendEvent(CFE_EVS_DISPORT_EID, CFE_EVS_EventType_DEBUG,
530523
"Disable Ports Command Received with Port Bit Mask = 0x%02x", (unsigned int)CmdPtr->BitMask);
531-
532-
ReturnCode = CFE_SUCCESS;
533524
}
534525

535526
return ReturnCode;
@@ -545,15 +536,12 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventTypeCmd_t *data)
545536
{
546537
uint32 i;
547538
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
548-
int32 ReturnCode;
539+
int32 ReturnCode = CFE_SUCCESS;
549540
EVS_AppData_t * AppDataPtr;
550541

551542
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
552-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
543+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_EVENT_TYPE_CC))
553544
{
554-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
555-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
556-
(long unsigned int)CFE_EVS_ENABLE_EVENT_TYPE_CC);
557545
ReturnCode = CFE_EVS_INVALID_PARAMETER;
558546
}
559547
else
@@ -572,8 +560,6 @@ int32 CFE_EVS_EnableEventTypeCmd(const CFE_EVS_EnableEventTypeCmd_t *data)
572560
EVS_SendEvent(CFE_EVS_ENAEVTTYPE_EID, CFE_EVS_EventType_DEBUG,
573561
"Enable Event Type Command Received with Event Type Bit Mask = 0x%02x",
574562
(unsigned int)CmdPtr->BitMask);
575-
576-
ReturnCode = CFE_SUCCESS;
577563
}
578564

579565
return ReturnCode;
@@ -590,17 +576,13 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventTypeCmd_t *data)
590576
uint32 i;
591577
const CFE_EVS_BitMaskCmd_Payload_t *CmdPtr = &data->Payload;
592578
int32 ReturnCode;
593-
EVS_AppData_t * AppDataPtr;
579+
EVS_AppData_t *AppDataPtr = CFE_SUCCESS;
594580

595581
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
596-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
582+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_EVENT_TYPE_CC))
597583
{
598-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
599-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
600-
(long unsigned int)CFE_EVS_DISABLE_EVENT_TYPE_CC);
601584
ReturnCode = CFE_EVS_INVALID_PARAMETER;
602585
}
603-
604586
else
605587
{
606588
AppDataPtr = CFE_EVS_Global.AppData;
@@ -617,8 +599,6 @@ int32 CFE_EVS_DisableEventTypeCmd(const CFE_EVS_DisableEventTypeCmd_t *data)
617599
EVS_SendEvent(CFE_EVS_DISEVTTYPE_EID, CFE_EVS_EventType_DEBUG,
618600
"Disable Event Type Command Received with Event Type Bit Mask = 0x%02x",
619601
(unsigned int)CmdPtr->BitMask);
620-
621-
ReturnCode = CFE_SUCCESS;
622602
}
623603

624604
return ReturnCode;
@@ -676,11 +656,8 @@ int32 CFE_EVS_EnableAppEventTypeCmd(const CFE_EVS_EnableAppEventTypeCmd_t *data)
676656
if (Status == CFE_SUCCESS)
677657
{
678658
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
679-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
659+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_ENABLE_APP_EVENT_TYPE_CC))
680660
{
681-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
682-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
683-
(long unsigned int)CFE_EVS_ENABLE_APP_EVENT_TYPE_CC);
684661
Status = CFE_EVS_INVALID_PARAMETER;
685662
}
686663
else
@@ -738,11 +715,8 @@ int32 CFE_EVS_DisableAppEventTypeCmd(const CFE_EVS_DisableAppEventTypeCmd_t *dat
738715
if (Status == CFE_SUCCESS)
739716
{
740717
/* Need to check for an out of range bitmask, since our bit masks are only 4 bits */
741-
if (CmdPtr->BitMask == 0x0 || CmdPtr->BitMask > 0x0F)
718+
if (EVS_IsInvalidBitMask(CmdPtr->BitMask, CFE_EVS_DISABLE_APP_EVENT_TYPE_CC))
742719
{
743-
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
744-
"Bit Mask = 0x%08x out of range: CC = %lu", (unsigned int)CmdPtr->BitMask,
745-
(long unsigned int)CFE_EVS_DISABLE_APP_EVENT_TYPE_CC);
746720
Status = CFE_EVS_INVALID_PARAMETER;
747721
}
748722
else

modules/evs/fsw/src/cfe_evs_utils.c

+14-6
Original file line numberDiff line numberDiff line change
@@ -423,10 +423,8 @@ EVS_BinFilter_t *EVS_FindEventID(uint16 EventID, EVS_BinFilter_t *FilterArray)
423423
*-----------------------------------------------------------------*/
424424
void EVS_EnableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
425425
{
426-
uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT);
427-
428426
/* Enable selected event type bits from bitmask */
429-
AppDataPtr->EventTypesActiveFlag |= (BitMask & EventTypeBits);
427+
AppDataPtr->EventTypesActiveFlag |= (BitMask & CFE_EVS_ALL_EVENT_TYPES_MASK);
430428
}
431429

432430
/*----------------------------------------------------------------
@@ -437,10 +435,8 @@ void EVS_EnableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
437435
*-----------------------------------------------------------------*/
438436
void EVS_DisableTypes(EVS_AppData_t *AppDataPtr, uint8 BitMask)
439437
{
440-
uint8 EventTypeBits = (CFE_EVS_DEBUG_BIT | CFE_EVS_INFORMATION_BIT | CFE_EVS_ERROR_BIT | CFE_EVS_CRITICAL_BIT);
441-
442438
/* Disable selected event type bits from bitmask */
443-
AppDataPtr->EventTypesActiveFlag &= ~(BitMask & EventTypeBits);
439+
AppDataPtr->EventTypesActiveFlag &= ~(BitMask & CFE_EVS_ALL_EVENT_TYPES_MASK);
444440
}
445441

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

622618
return CFE_SUCCESS;
623619
}
620+
621+
bool EVS_IsInvalidBitMask(uint32 BitMask, uint16 CommandCode)
622+
{
623+
if ((BitMask) == 0x0 || (BitMask) > CFE_EVS_ALL_EVENT_TYPES_MASK)
624+
{
625+
EVS_SendEvent(CFE_EVS_ERR_INVALID_BITMASK_EID, CFE_EVS_EventType_ERROR,
626+
"Bit Mask = 0x%08x out of range: CC = %u", (unsigned int)BitMask, (unsigned int)CommandCode);
627+
return true;
628+
}
629+
630+
return false;
631+
}

modules/evs/fsw/src/cfe_evs_utils.h

+14
Original file line numberDiff line numberDiff line change
@@ -252,4 +252,18 @@ void EVS_GenerateEventTelemetry(EVS_AppData_t *AppDataPtr, uint16 EventID, uint1
252252
*/
253253
int32 EVS_SendEvent(uint16 EventID, uint16 EventType, const char *Spec, ...);
254254

255+
/**
256+
* @brief Checks if the provided BitMask is invalid.
257+
*
258+
* This function evaluates whether the given BitMask is either zero or exceeds the maximum allowed
259+
* value defined by CFE_EVS_ALL_EVENT_TYPES_MASK (which represents all events types turned on).
260+
* If the BitMask is invalid, an error event is sent and the function returns true.
261+
*
262+
* @param BitMask The bitmask to be checked.
263+
* @param CommandCode The command code associated with the bitmask.
264+
*
265+
* @return true if the BitMask is invalid, false otherwise.
266+
*/
267+
bool EVS_IsInvalidBitMask(uint32 BitMask, uint16 CommandCode);
268+
255269
#endif /* CFE_EVS_UTILS_H */

0 commit comments

Comments
 (0)