Skip to content
Draft
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
a03bc50
WIP: Add prototype Event Management calls and Event Proxy impl files
keegan-moore Mar 19, 2024
bf38ef7
Migrate proxy api to return BPL_Status_t to match EVM
keegan-moore Mar 19, 2024
879f086
Add BPL_EVM_Initialize error check to BP_SetupLibrary
keegan-moore Mar 19, 2024
7531529
Add call to CFE_EVS_SendEvent from BPNODE_EVT_SendEvent_Impl
keegan-moore Mar 19, 2024
f1f9aea
Destruct BPL_EVM_EventInfo_t and update refs
keegan-moore Mar 19, 2024
9dbb7c5
Change event id to uint16_t
keegan-moore Mar 19, 2024
7e4f1c6
Add EventType to proxy send event impl
keegan-moore Mar 19, 2024
722c064
Add basic function header comment to BPNODE_EVT_TranslateTypeToHost
keegan-moore Mar 19, 2024
1637329
Remove ReturnStatus default val as it gets set later
keegan-moore Mar 19, 2024
25f8a55
Add BPL_EVM_Deinitialize call at app exit
keegan-moore Mar 19, 2024
e131d61
WIP: Add EventText and variable arg list to BPNODE_EVT_SendEvent_Impl
keegan-moore Mar 19, 2024
4ef6160
Fix event text arg expansion in BPNODE_EVT_SendEvent_Impl
keegan-moore Mar 19, 2024
6b836c4
Swap BP app init event message to use BPL_EVM_SendEvent
keegan-moore Mar 19, 2024
8030756
Clean up some of the old debug prints
keegan-moore Mar 19, 2024
26f2acb
Rename namespace from bpnode_evt_ to bpnode_evp_
keegan-moore Mar 20, 2024
29701c3
Move CFE_EVS_Register call and filter decl into EVP
keegan-moore Mar 20, 2024
3828a50
Remove unused Event IDs from default EVS filter to fix error
keegan-moore Mar 20, 2024
3017405
Remove newly unreferenced Event IDs
keegan-moore Mar 20, 2024
f5173ee
Update debug prints in BPNODE_EVP_Initialize_Impl and SendEvent_Impl
keegan-moore Mar 20, 2024
278c7d8
Remove redundant ReturnStatus assignment in BPNODE_EVP_Initialize_Impl
keegan-moore Mar 20, 2024
d6b3f0a
Remove EVP Init from callback functions in EVM
keegan-moore Mar 25, 2024
2483add
Remove TODO comment
keegan-moore Mar 25, 2024
ffcd02f
Revert "Remove EVP Init from callback functions in EVM"
keegan-moore Mar 25, 2024
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
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
147 changes: 147 additions & 0 deletions fsw/custom/bpnode_evp_cfs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* TODO: Fill in file header, if necessary.
*/

/************************************************
* Includes
************************************************/

#include <assert.h>
#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 = { .ReturnValue = BPL_STATUS_SUCCESS };
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.
*/
}
Comment on lines +109 to +127
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error handling response should be reviewed by the group.


/* 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);
Comment on lines +129 to +131
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I simply remove this, or are there debug print flags in BP that we should use?


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);
Comment on lines +137 to +138
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and other places, I've put OS_printf debug print calls in to help catch errors. Is there a better strategy for this?

ReturnStatus.ReturnValue = BPL_STATUS_ERROR_GENERAL;
}
else
{
ReturnStatus.ReturnValue = BPL_STATUS_SUCCESS;
}

return ReturnStatus;
}
42 changes: 42 additions & 0 deletions fsw/custom/bpnode_evp_cfs.h
Original file line number Diff line number Diff line change
@@ -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 */
3 changes: 0 additions & 3 deletions fsw/inc/bp_eventids.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 18 additions & 17 deletions fsw/src/bp_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -65,6 +67,20 @@ static CFE_Status_t BP_SetupLibrary(void)
return CFE_STATUS_EXTERNAL_RESOURCE_FAIL;
}

/* TODO: Is this the right spot? */
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;
}

Expand All @@ -73,28 +89,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)
Expand Down Expand Up @@ -165,7 +165,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);
Comment on lines 166 to 168
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The previous call to CFE_EVS_SendEvent ignored its CFE_Status_t return status, so I kept that going here.

However, if we wanted to check the return status, it would look something like this:

    /* Application startup event message */
    BPL_Status_t BPL_EVM_SendEventStatus;
    (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);
    if (BPL_EVM_SendEventStatus.ReturnValue != BPL_STATUS_SUCCESS)
    {
        fprintf(stderr, "%s(): First BPL_EVM_SendEvent call failed\n", __func__);
        return BPL_EVM_SendEventStatus.ReturnValue;
    }

I find this to be a little too distracting for such a benign activity, but I'm happy to go with the group's decision on whether to continue ignoring the status return from Send Event calls.


return CFE_SUCCESS;
Expand Down Expand Up @@ -213,6 +213,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",
Expand Down
1 change: 0 additions & 1 deletion fsw/src/bp_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand Down