From 4ec714b16e0892d308c7a5c9ca6f1301d3c78f29 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Sat, 8 Jun 2024 09:12:54 +0200 Subject: [PATCH] Add statuses in to manage table functions --- fsw/inc/sc_events.h | 23 +++++++++++ fsw/src/sc_cmds.c | 96 ++++++++++++++++++++++++++------------------- fsw/src/sc_cmds.h | 12 ++++-- 3 files changed, 87 insertions(+), 44 deletions(-) diff --git a/fsw/inc/sc_events.h b/fsw/inc/sc_events.h index e0905bf..fbb5464 100644 --- a/fsw/inc/sc_events.h +++ b/fsw/inc/sc_events.h @@ -1354,6 +1354,29 @@ */ #define SC_AUTOSTART_RTS_INV_ID_ERR_EID 138 +/** + * \brief SC Manage Table Command Event ID + * + * \par Type: INFORMATION + * + * \par Cause: + * This event message is issued when the #SC_MANAGE_TABLE_CC command + * was received and processed successfully. + */ +#define SC_TABLE_MANAGE_INF_EID 139 + +/** + * \brief SC Manage Table Command Error Event ID + * + * \par Type: ERROR + * + * \par Cause: + * This event message is issued when the #SC_MANAGE_TABLE_CC command + * encountered an error during execution. There may also be an additional + * error event issues by one of the sub-routines. + */ +#define SC_TABLE_MANAGE_ERR_EID 140 + /**\}*/ #endif diff --git a/fsw/src/sc_cmds.c b/fsw/src/sc_cmds.c index 53170f5..36faceb 100644 --- a/fsw/src/sc_cmds.c +++ b/fsw/src/sc_cmds.c @@ -59,12 +59,12 @@ void SC_ProcessAtpCmd(void) SC_CommandIndex_t CmdIndex; /* ATS command index */ CFE_Status_t Result; bool AbortATS = false; - SC_AtsEntry_t * EntryPtr; + SC_AtsEntry_t *EntryPtr; CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; CFE_MSG_FcnCode_t CommandCode = 0; bool ChecksumValid; SC_AtsCmdEntryOffsetRecord_t *CmdOffsetRec; /* ATS entry location in table */ - SC_AtsCmdStatusEntry_t * StatusEntryPtr; + SC_AtsCmdStatusEntry_t *StatusEntryPtr; /* ** The following conditions must be met before the ATS command will be @@ -289,7 +289,7 @@ void SC_ProcessAtpCmd(void) void SC_ProcessRtpCommand(void) { - SC_RtsEntry_t * EntryPtr; /* a pointer to an RTS entry header */ + SC_RtsEntry_t *EntryPtr; /* a pointer to an RTS entry header */ SC_RtsIndex_t RtsIndex; /* the RTS index for the cmd */ SC_EntryOffset_t CmdOffset; /* the location of the cmd */ CFE_Status_t Result; @@ -606,56 +606,67 @@ void SC_NoopCmd(const SC_NoopCmd_t *Cmd) void SC_ManageTableCmd(const SC_ManageTableCmd_t *Cmd) { - int32 ArrayIndex; - int32 TableID = Cmd->Payload.Parameter; + int32 ArrayIndex; + int32 TableID = Cmd->Payload.Parameter; + CFE_Status_t Status = SC_ERROR; /* Manage selected table as appropriate for each table type */ if ((TableID >= SC_TBL_ID_ATS_0) && (TableID < (SC_TBL_ID_ATS_0 + SC_NUMBER_OF_ATS))) { ArrayIndex = TableID - SC_TBL_ID_ATS_0; - SC_ManageAtsTable(ArrayIndex); + Status = SC_ManageAtsTable(ArrayIndex); } else if (TableID == SC_TBL_ID_APPEND) { - SC_ManageTable(APPEND, -1); + Status = SC_ManageTable(APPEND, -1); } else if ((TableID >= SC_TBL_ID_RTS_0) && (TableID < (SC_TBL_ID_RTS_0 + SC_NUMBER_OF_RTS))) { ArrayIndex = TableID - SC_TBL_ID_RTS_0; - SC_ManageRtsTable(ArrayIndex); + Status = SC_ManageRtsTable(ArrayIndex); } else if (TableID == SC_TBL_ID_RTS_INFO) { /* No need to release dump only table pointer */ - CFE_TBL_Manage(SC_OperData.RtsInfoHandle); + Status = CFE_TBL_Manage(SC_OperData.RtsInfoHandle); } else if (TableID == SC_TBL_ID_RTP_CTRL) { /* No need to release dump only table pointer */ - CFE_TBL_Manage(SC_OperData.RtsCtrlBlckHandle); + Status = CFE_TBL_Manage(SC_OperData.RtsCtrlBlckHandle); } else if (TableID == SC_TBL_ID_ATS_INFO) { /* No need to release dump only table pointer */ - CFE_TBL_Manage(SC_OperData.AtsInfoHandle); + Status = CFE_TBL_Manage(SC_OperData.AtsInfoHandle); } else if (TableID == SC_TBL_ID_ATP_CTRL) { /* No need to release dump only table pointer */ - CFE_TBL_Manage(SC_OperData.AtsCtrlBlckHandle); + Status = CFE_TBL_Manage(SC_OperData.AtsCtrlBlckHandle); } else if ((TableID >= SC_TBL_ID_ATS_CMD_0) && (TableID < (SC_TBL_ID_ATS_CMD_0 + SC_NUMBER_OF_ATS))) { /* No need to release dump only table pointer */ ArrayIndex = TableID - SC_TBL_ID_ATS_CMD_0; - CFE_TBL_Manage(SC_OperData.AtsCmdStatusHandle[ArrayIndex]); + Status = CFE_TBL_Manage(SC_OperData.AtsCmdStatusHandle[ArrayIndex]); } else { - /* Invalid table ID */ - CFE_EVS_SendEvent(SC_TABLE_MANAGE_ID_ERR_EID, CFE_EVS_EventType_ERROR, - "Table manage command packet error: table ID = %d", - (int)TableID); + /* Invalid table ID */ + CFE_EVS_SendEvent(SC_TABLE_MANAGE_ID_ERR_EID, CFE_EVS_EventType_ERROR, + "Table manage command packet error: table ID = %d", (int)TableID); + } + + /* Issue error event for any negative (error) return codes that originated above. */ + if (Status < CFE_SUCCESS) + { + CFE_EVS_SendEvent(SC_TABLE_MANAGE_ERR_EID, CFE_EVS_EventType_ERROR, "Table manage command error: 0x%08X", + (unsigned int)Status); + } + else + { + CFE_EVS_SendEvent(SC_TABLE_MANAGE_INF_EID, CFE_EVS_EventType_INFORMATION, "Table manage command."); } } @@ -665,17 +676,22 @@ void SC_ManageTableCmd(const SC_ManageTableCmd_t *Cmd) /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_ManageRtsTable(int32 ArrayIndex) +CFE_Status_t SC_ManageRtsTable(int32 ArrayIndex) { + CFE_Status_t Status = SC_ERROR; + /* validate array index */ if (ArrayIndex >= SC_NUMBER_OF_RTS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_RTS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "RTS table manage error: invalid RTS index %d", (int)ArrayIndex); - return; + } + else + { + Status = SC_ManageTable(RTS, ArrayIndex); } - SC_ManageTable(RTS, ArrayIndex); + return Status; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -684,17 +700,22 @@ void SC_ManageRtsTable(int32 ArrayIndex) /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_ManageAtsTable(int32 ArrayIndex) +CFE_Status_t SC_ManageAtsTable(int32 ArrayIndex) { + CFE_Status_t Status = SC_ERROR; + /* validate array index */ if (ArrayIndex >= SC_NUMBER_OF_ATS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_ATS_INV_INDEX_ERR_EID, CFE_EVS_EventType_ERROR, "ATS table manage error: invalid ATS index %d", (int)ArrayIndex); - return; + } + else + { + Status = SC_ManageTable(ATS, ArrayIndex); } - SC_ManageTable(ATS, ArrayIndex); + return Status; } /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ @@ -703,12 +724,12 @@ void SC_ManageAtsTable(int32 ArrayIndex) /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void SC_ManageTable(SC_TableType type, int32 ArrayIndex) +CFE_Status_t SC_ManageTable(SC_TableType type, int32 ArrayIndex) { - CFE_Status_t Result; + CFE_Status_t Status; CFE_TBL_Handle_t TblHandle; - uint32 ** TblAddr; - void * TblPtrNew; + uint32 **TblAddr; + void *TblPtrNew; switch (type) { @@ -734,9 +755,9 @@ void SC_ManageTable(SC_TableType type, int32 ArrayIndex) CFE_TBL_Manage(TblHandle); /* Re-acquire table data pointer */ - Result = CFE_TBL_GetAddress(&TblPtrNew, TblHandle); + Status = CFE_TBL_GetAddress(&TblPtrNew, TblHandle); *TblAddr = TblPtrNew; /* Note that CFE_TBL_GetAddress() sets this to NULL if it fails */ - if (Result == CFE_TBL_INFO_UPDATED) + if (Status == CFE_TBL_INFO_UPDATED) { /* Process new table data */ if (type == ATS) @@ -751,35 +772,28 @@ void SC_ManageTable(SC_TableType type, int32 ArrayIndex) { SC_UpdateAppend(); } - - Result = CFE_SUCCESS; } - else if ((Result != CFE_SUCCESS) && (Result != CFE_TBL_ERR_NEVER_LOADED)) + else if ((Status != CFE_SUCCESS) && (Status != CFE_TBL_ERR_NEVER_LOADED)) { /* Ignore successful dump or validate and cmds before first activate. */ if (type == ATS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_ATS_ERR_EID, CFE_EVS_EventType_ERROR, "ATS table manage process error: ATS = %u, Result = 0x%X", - SC_IDNUM_AS_UINT(SC_AtsIndexToNum(SC_ATS_IDX_C(ArrayIndex))), (unsigned int)Result); + SC_IDNUM_AS_UINT(SC_AtsIndexToNum(SC_ATS_IDX_C(ArrayIndex))), (unsigned int)Status); } else if (type == RTS) { CFE_EVS_SendEvent(SC_TABLE_MANAGE_RTS_ERR_EID, CFE_EVS_EventType_ERROR, "RTS table manage process error: RTS = %u, Result = 0x%X", - SC_IDNUM_AS_UINT(SC_RtsIndexToNum(SC_RTS_IDX_C(ArrayIndex))), (unsigned int)Result); + SC_IDNUM_AS_UINT(SC_RtsIndexToNum(SC_RTS_IDX_C(ArrayIndex))), (unsigned int)Status); } else { CFE_EVS_SendEvent(SC_TABLE_MANAGE_APPEND_ERR_EID, CFE_EVS_EventType_ERROR, - "ATS Append table manage process error: Result = 0x%X", (unsigned int)Result); + "ATS Append table manage process error: Result = 0x%X", (unsigned int)Status); } } - if ((Result == CFE_SUCCESS) || (Result == CFE_TBL_INFO_UPDATED)) - { - CFE_EVS_SendEvent(SC_TABLE_MANAGE_INF_EID, CFE_EVS_EventType_INFORMATION, - "Table manage command."); - } - + return Status; } /* End SC_ManageTable() */ diff --git a/fsw/src/sc_cmds.h b/fsw/src/sc_cmds.h index 2d35a08..343f861 100644 --- a/fsw/src/sc_cmds.h +++ b/fsw/src/sc_cmds.h @@ -69,9 +69,11 @@ void SC_ManageTableCmd(const SC_ManageTableCmd_t *Cmd); * * \param [in] ArrayIndex index into array of RTS tables * + * \return CFE_SUCCESS on success, or appropriate error code + * * \sa #SC_ManageTableCmd */ -void SC_ManageRtsTable(int32 ArrayIndex); +CFE_Status_t SC_ManageRtsTable(int32 ArrayIndex); /** * \brief Manage pending update to an ATS table @@ -88,9 +90,11 @@ void SC_ManageRtsTable(int32 ArrayIndex); * * \param [in] ArrayIndex index into array of ATS tables * + * \return CFE_SUCCESS on success, or appropriate error code + * * \sa #SC_ManageTableCmd */ -void SC_ManageAtsTable(int32 ArrayIndex); +CFE_Status_t SC_ManageAtsTable(int32 ArrayIndex); /** * \brief Manage pending update to a table @@ -105,9 +109,11 @@ void SC_ManageAtsTable(int32 ArrayIndex); * \par Assumptions, External Events, and Notes: * None * + * \return CFE_SUCCESS on success, or appropriate error code + * * \sa #SC_ManageTableCmd */ -void SC_ManageTable(SC_TableType type, int32 ArrayIndex); +CFE_Status_t SC_ManageTable(SC_TableType type, int32 ArrayIndex); /** * \brief Sends out an Event message