diff --git a/CMakeLists.txt b/CMakeLists.txt index b8459230..832b351a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(APP_SRC_FILES fsw/custom/bp_semcfg.c fsw/custom/bp_storecfg.c fsw/custom/bp_tlmcfg.c + fsw/custom/bpnode_evp_cfs.c ) if (CFE_EDS_ENABLED_BUILD) diff --git a/fsw/custom/bpnode_evp_cfs.c b/fsw/custom/bpnode_evp_cfs.c new file mode 100644 index 00000000..d34ce83f --- /dev/null +++ b/fsw/custom/bpnode_evp_cfs.c @@ -0,0 +1,147 @@ +/* + * TODO: Fill in file header, if necessary. + */ + +/************************************************ + * Includes + ************************************************/ + +#include +#include "cfe.h" +#include "bp_eventids.h" +#include "bpl_evm_api.h" +#include "bpnode_evp_cfs.h" + +/************************************************ + * Local Data + ************************************************/ + +/* +** Limits: +** - Must contain less than or equal to CFE_PLATFORM_EVS_MAX_EVENT_FILTERS entries +*/ +static const CFE_EVS_BinFilter_t BPNODE_EVP_CFS_EVENT_FILTER[] = { + {BP_IO_SEND_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_IO_RECEIVE_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_LIB_PROC_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_LIB_LOAD_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_LIB_STORE_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_LIB_ACCEPT_ERR_EID, CFE_EVS_FIRST_8_STOP}, + {BP_FILE_ERR_EID, CFE_EVS_FIRST_8_STOP}, +}; + +const size_t BPNODE_EVP_CFS_NUM_EVENT_FILTERS = sizeof(BPNODE_EVP_CFS_EVENT_FILTER) / + sizeof(BPNODE_EVP_CFS_EVENT_FILTER[0]); + +/************************************************ + * Exported Functions + ************************************************/ + +/*----------------------------------------------- + * BPNODE_EVP_Initialize_Impl + *-----------------------------------------------*/ +BPL_Status_t BPNODE_EVP_Initialize_Impl(void) +{ + BPL_Status_t ReturnStatus; + CFE_Status_t CfeEvsRegisterStatus; + + CfeEvsRegisterStatus = CFE_EVS_Register(BPNODE_EVP_CFS_EVENT_FILTER, + BPNODE_EVP_CFS_NUM_EVENT_FILTERS, + CFE_EVS_EventFilter_BINARY); + + if (CfeEvsRegisterStatus != CFE_SUCCESS) + { + OS_printf("BPNODE_EVP_Initialize_Impl call to CFE_EVS_Register returned error: %u!\n", + CfeEvsRegisterStatus); + ReturnStatus.ReturnValue = BPL_STATUS_ERROR_PROXY_INIT; + } + else + { + ReturnStatus.ReturnValue = BPL_STATUS_SUCCESS; + } + + return ReturnStatus; +} + +/*----------------------------------------------- + * BPNODE_EVP_TranslateTypeToHost + *-----------------------------------------------*/ +uint16_t BPNODE_EVP_TranslateTypeToHost(BPL_EVM_EventType_t EventType) +{ + uint16_t HostEventType; + switch (EventType) + { + case BPL_EVM_EventType_DEBUG: + HostEventType = CFE_EVS_EventType_DEBUG; + break; + case BPL_EVM_EventType_INFO: + HostEventType = CFE_EVS_EventType_INFORMATION; + break; + case BPL_EVM_EventType_WARNING: + HostEventType = CFE_EVS_EventType_ERROR; + break; + case BPL_EVM_EventType_ERROR: + HostEventType = CFE_EVS_EventType_ERROR; + break; + case BPL_EVM_EventType_CRITICAL: + HostEventType = CFE_EVS_EventType_CRITICAL; + break; + default: + /* This default case also captures the BPL_EVM_EventType_UNKNOWN case. */ + HostEventType = CFE_EVS_EventType_ERROR; + break; + } + return HostEventType; +} + +/*----------------------------------------------- + * BPNODE_EVP_SendEvent_Impl + *-----------------------------------------------*/ +BPL_Status_t BPNODE_EVP_SendEvent_Impl(uint16_t EventID, BPL_EVM_EventType_t EventType, + char const * EventText, va_list EventTextArgPtr) +{ + BPL_Status_t ReturnStatus; + CFE_Status_t ProxyStatus; + uint16_t HostEventType = BPNODE_EVP_TranslateTypeToHost(EventType); + char ExpandedEventText[BPNODE_EVP_MAX_MESSAGE_LENGTH]; + int ExpandedLength; + + /* + ** Due to how we truncate the message if its too long (as seen in code, below), + ** we need to ensure that this buffer is at least 2 characters long. + */ + assert(BPNODE_EVP_MAX_MESSAGE_LENGTH >= 2); + assert(BPNODE_EVP_MAX_MESSAGE_LENGTH <= CFE_MISSION_EVS_MAX_MESSAGE_LENGTH); + + memset(&ExpandedEventText, 0, sizeof(ExpandedEventText)); + ExpandedLength = vsnprintf((char *)ExpandedEventText, sizeof(ExpandedEventText), + EventText, EventTextArgPtr); + if (ExpandedLength >= (int)sizeof(ExpandedEventText)) + { + /* Mark character before zero terminator to indicate truncation */ + ExpandedEventText[sizeof(ExpandedEventText) - 2u] = BPNODE_EVP_MSG_TRUNCATED; + /* + ** TODO: should we return an error here? + ** Note: In the cFE implementation, they don't treat message truncation as an error. + */ + } + + /* TODO: We'll probably want to remove this, or wrap it behind an "if debug" compiler flag. */ + OS_printf("BPNODE_EVP_SendEvent_Impl(%u, %s, %s)\n", + EventID, BPL_EVM_EventTypeToString(EventType), ExpandedEventText); + + ProxyStatus = CFE_EVS_SendEvent(EventID, HostEventType, "%s", ExpandedEventText); + + if (ProxyStatus != CFE_SUCCESS) + { + OS_printf("BPNODE_EVP_SendEvent_Impl CFE_EVS_SendEvent returned error status: 0x%08X!\n", + ProxyStatus); + ReturnStatus.ReturnValue = BPL_STATUS_ERROR_GENERAL; + } + else + { + ReturnStatus.ReturnValue = BPL_STATUS_SUCCESS; + } + + return ReturnStatus; +} diff --git a/fsw/custom/bpnode_evp_cfs.h b/fsw/custom/bpnode_evp_cfs.h new file mode 100644 index 00000000..d3737729 --- /dev/null +++ b/fsw/custom/bpnode_evp_cfs.h @@ -0,0 +1,42 @@ +/* + * TODO: Fill in file header, if necessary. + */ + +#ifndef BPNODE_EVP_CFS_H +#define BPNODE_EVP_CFS_H + +/************************************************ + * Includes + ************************************************/ + +#include "cfe.h" +#include "bpl_evm_api.h" + +/************************************************ + * Typedefs + ************************************************/ + +/* +** Defines the character used when truncating event strings that are too long +** Match what cFE uses (CFE_EVS_MSG_TRUNCATED) +*/ +#define BPNODE_EVP_MSG_TRUNCATED ('$') + +/* +** Defines the max length of the expanded event string +** +** Limits: +** - must be greater than or equal to 2 +** - must be less than or equal to host limit (CFE_MISSION_EVS_MAX_MESSAGE_LENGTH) +*/ +#define BPNODE_EVP_MAX_MESSAGE_LENGTH (CFE_MISSION_EVS_MAX_MESSAGE_LENGTH) + +/************************************************ + * Exported Functions + ************************************************/ + +BPL_Status_t BPNODE_EVP_Initialize_Impl(void); +BPL_Status_t BPNODE_EVP_SendEvent_Impl(uint16_t EventID, BPL_EVM_EventType_t EventType, + char const * EventText, va_list EventTextArgPtr); + +#endif /* BPNODE_EVP_CFS_H */ diff --git a/fsw/inc/bp_eventids.h b/fsw/inc/bp_eventids.h index 457f5cab..48d1ab28 100644 --- a/fsw/inc/bp_eventids.h +++ b/fsw/inc/bp_eventids.h @@ -59,9 +59,6 @@ #define BP_LIB_CONFIG_ERR_EID 36 #define BP_FILE_ERR_EID 37 #define BP_FILE_POLLING_NOT_ACTIVE_ERR_EID 38 -#define BP_STORE_INFO_EID 39 - -#define BP_BPLIB_INFO_EID 40 /* placeholder for CLA/Bundle flow events */ #define BP_CLA_INIT_INF_EID 50 diff --git a/fsw/src/bp_app.c b/fsw/src/bp_app.c index 1c22a2ed..69fe22c8 100644 --- a/fsw/src/bp_app.c +++ b/fsw/src/bp_app.c @@ -39,6 +39,8 @@ #include "bp_dispatch.h" #include "bp_cla_bundle_io.h" #include "bplib_routing.h" +#include "bpl_evm_api.h" +#include "bpnode_evp_cfs.h" /************************************************ * File Data @@ -65,6 +67,19 @@ static CFE_Status_t BP_SetupLibrary(void) return CFE_STATUS_EXTERNAL_RESOURCE_FAIL; } + BPL_EVM_ProxyCallbacks_t EventProxyCallbacks = { + .Initialize_Impl = BPNODE_EVP_Initialize_Impl, + .SendEvent_Impl = BPNODE_EVP_SendEvent_Impl, + }; + + BPL_Status_t BPL_EVM_Status; + BPL_EVM_Status = BPL_EVM_Initialize(EventProxyCallbacks); + if (BPL_EVM_Status.ReturnValue != BPL_STATUS_SUCCESS) + { + fprintf(stderr, "%s(): BPL_EVM_Initialize failed\n", __func__); + return CFE_STATUS_EXTERNAL_RESOURCE_FAIL; + } + return CFE_SUCCESS; } @@ -73,28 +88,12 @@ static CFE_Status_t BP_SetupLibrary(void) *-----------------------------------------------*/ static CFE_Status_t AppInit(void) { - static const CFE_EVS_BinFilter_t BP_EVENT_FILTER_INIT[] = { - {BP_IO_SEND_ERR_EID, CFE_EVS_FIRST_8_STOP}, {BP_IO_RECEIVE_ERR_EID, CFE_EVS_FIRST_8_STOP}, - {BP_LIB_PROC_ERR_EID, CFE_EVS_FIRST_8_STOP}, {BP_LIB_LOAD_ERR_EID, CFE_EVS_FIRST_8_STOP}, - {BP_LIB_STORE_ERR_EID, CFE_EVS_FIRST_8_STOP}, {BP_LIB_ACCEPT_ERR_EID, CFE_EVS_FIRST_8_STOP}, - {BP_FILE_ERR_EID, CFE_EVS_FIRST_8_STOP}, {BP_STORE_INFO_EID, CFE_EVS_FIRST_8_STOP}, - {BP_BPLIB_INFO_EID, CFE_EVS_FIRST_8_STOP}}; - - const size_t num_event_filters = sizeof(BP_EVENT_FILTER_INIT) / sizeof(BP_EVENT_FILTER_INIT[0]); CFE_Status_t status = CFE_SUCCESS; CFE_ES_AppId_t app_id; - assert(num_event_filters <= BP_MAX_EVENT_FILTERS); memset(&BP_GlobalData, 0, sizeof(BP_GlobalData)); BP_GlobalData.Throttles = BP_Throttles; - memcpy(BP_GlobalData.EventFilters, BP_EVENT_FILTER_INIT, sizeof(BP_EVENT_FILTER_INIT)); - - /* Register Application with Event Services */ - status = CFE_EVS_Register(BP_GlobalData.EventFilters, num_event_filters, CFE_EVS_EventFilter_BINARY); - if (status != CFE_SUCCESS) - return status; - /* Get Application ID */ status = CFE_ES_GetAppID(&app_id); if (status != CFE_SUCCESS) @@ -165,7 +164,7 @@ static CFE_Status_t AppInit(void) BP_DoRebuildFlowBitmask(); /* Application startup event message */ - CFE_EVS_SendEvent(BP_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "BP App Version %d.%d.%d.%d: Initialized", + (void) BPL_EVM_SendEvent(BP_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "BP App Version %d.%d.%d.%d: Initialized", BP_MAJOR_VERSION, BP_MINOR_VERSION, BP_REVISION, BP_MISSION_REV); return CFE_SUCCESS; @@ -213,6 +212,7 @@ void BP_AppMain(void) } /* Exit Application */ + BPL_EVM_Deinitialize(); CFE_EVS_SendEvent(BP_EXIT_ERR_EID, CFE_EVS_EventType_ERROR, "BP application terminating: result = 0x%08X", (unsigned int)run_status); CFE_ES_WriteToSysLog("BP application terminating: result = 0x%08X\n", diff --git a/fsw/src/bp_global.h b/fsw/src/bp_global.h index e779a5aa..79158c9e 100644 --- a/fsw/src/bp_global.h +++ b/fsw/src/bp_global.h @@ -44,7 +44,6 @@ typedef struct CFE_SB_PipeId_t AppPipe; BP_HkPkt_t HkPkt; BP_FlowHkPkt_t FlowHkPkt; - CFE_EVS_BinFilter_t EventFilters[BP_MAX_EVENT_FILTERS]; char AppName[CFE_MISSION_MAX_API_LEN]; char ConfigTableName[CFE_TBL_MAX_FULL_NAME_LEN];