diff --git a/CHANGELOG.md b/CHANGELOG.md index ae4d6c98a..5fe316a04 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## Development Build: v7.0.0-rc4+dev260 +- add more generic status codes +- separate dispatcher for messages +- See and + ## Development Build: v7.0.0-rc4+dev254 - improve 64-bit memory address handling in CMD/TLM - See diff --git a/modules/core_api/fsw/inc/cfe_error.h b/modules/core_api/fsw/inc/cfe_error.h index 90c69d56b..bd7138478 100644 --- a/modules/core_api/fsw/inc/cfe_error.h +++ b/modules/core_api/fsw/inc/cfe_error.h @@ -202,6 +202,30 @@ char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_stri */ #define CFE_STATUS_REQUEST_ALREADY_PENDING ((int32)0xc8000006) +/** + * @brief Request or input value failed basic structural validation + * + * A message or table input was not in the proper format to be understood + * and processed by an application, and was rejected. + */ +#define CFE_STATUS_VALIDATION_FAILURE ((int32)0xc8000007) + +/** + * @brief Request or input value is out of range + * + * A message, table, or function call input contained a value that was outside + * the acceptable range, and the request was rejected. + */ +#define CFE_STATUS_RANGE_ERROR ((int32)0xc8000008) + +/** + * @brief Cannot process request at this time + * + * The system is not currently in the correct state to accept the request at + * this time. + */ +#define CFE_STATUS_INCORRECT_STATE ((int32)0xc8000009) + /** * @brief Not Implemented * diff --git a/modules/core_api/fsw/inc/cfe_version.h b/modules/core_api/fsw/inc/cfe_version.h index db5077422..a15334cdb 100644 --- a/modules/core_api/fsw/inc/cfe_version.h +++ b/modules/core_api/fsw/inc/cfe_version.h @@ -26,7 +26,7 @@ #define CFE_VERSION_H /* Development Build Macro Definitions */ -#define CFE_BUILD_NUMBER 254 /**< @brief Development: Number of development git commits since CFE_BUILD_BASELINE */ +#define CFE_BUILD_NUMBER 260 /**< @brief Development: Number of development git commits since CFE_BUILD_BASELINE */ #define CFE_BUILD_BASELINE "v7.0.0-rc4" /**< @brief Development: Reference git tag for build number */ /* See \ref cfsversions for definitions */ diff --git a/modules/core_private/ut-stubs/inc/ut_support.h b/modules/core_private/ut-stubs/inc/ut_support.h index 4bd7d9a86..cfd13cc8c 100644 --- a/modules/core_private/ut-stubs/inc/ut_support.h +++ b/modules/core_private/ut-stubs/inc/ut_support.h @@ -252,7 +252,7 @@ void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MS ** \returns ** This function does not return a value. ******************************************************************************/ -void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_Buffer_t *), CFE_MSG_Message_t *MsgPtr, size_t MsgSize, +void UT_CallTaskPipe(void (*TaskPipeFunc)(const CFE_SB_Buffer_t *), const CFE_MSG_Message_t *MsgPtr, size_t MsgSize, UT_TaskPipeDispatchId_t DispatchId); /*****************************************************************************/ diff --git a/modules/core_private/ut-stubs/src/ut_support.c b/modules/core_private/ut-stubs/src/ut_support.c index 639b607c8..887ce1125 100644 --- a/modules/core_private/ut-stubs/src/ut_support.c +++ b/modules/core_private/ut-stubs/src/ut_support.c @@ -236,7 +236,7 @@ void UT_SetupBasicMsgDispatch(const UT_TaskPipeDispatchId_t *DispatchReq, CFE_MS ** This first sets up the various stubs according to the test case, ** then invokes the pipe function. */ -void UT_CallTaskPipe(void (*TaskPipeFunc)(CFE_SB_Buffer_t *), CFE_MSG_Message_t *MsgPtr, size_t MsgSize, +void UT_CallTaskPipe(void (*TaskPipeFunc)(const CFE_SB_Buffer_t *), const CFE_MSG_Message_t *MsgPtr, size_t MsgSize, UT_TaskPipeDispatchId_t DispatchId) { union diff --git a/modules/es/CMakeLists.txt b/modules/es/CMakeLists.txt index 0e8ebe701..772166537 100644 --- a/modules/es/CMakeLists.txt +++ b/modules/es/CMakeLists.txt @@ -13,6 +13,7 @@ set(es_SOURCES fsw/src/cfe_es_backgroundtask.c fsw/src/cfe_es_cds.c fsw/src/cfe_es_cds_mempool.c + fsw/src/cfe_es_dispatch.c fsw/src/cfe_es_erlog.c fsw/src/cfe_es_generic_pool.c fsw/src/cfe_es_mempool.c diff --git a/modules/es/fsw/src/cfe_es_dispatch.c b/modules/es/fsw/src/cfe_es_dispatch.c new file mode 100644 index 000000000..2d0df7172 --- /dev/null +++ b/modules/es/fsw/src/cfe_es_dispatch.c @@ -0,0 +1,285 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Msg pipe dispatcher routines for CFE ES + */ + +/* + * Includes + */ +#include "cfe_es_module_all.h" + +#include "cfe_version.h" +#include "target_config.h" +#include "cfe_es_verify.h" + +#include "cfe_config.h" + +#include + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +bool CFE_ES_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + CFE_MSG_Size_t ActualLength = 0; + CFE_MSG_FcnCode_t FcnCode = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + result = false; + CFE_ES_Global.TaskData.CommandErrorCounter++; + } + + return result; +} + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t CommandCode = 0; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); + switch (CFE_SB_MsgIdToValue(MessageID)) + { + /* + ** Housekeeping telemetry request + */ + case CFE_ES_SEND_HK_MID: + CFE_ES_HousekeepingCmd((const CFE_ES_SendHkCmd_t *)SBBufPtr); + break; + + /* + ** ES task ground commands + */ + case CFE_ES_CMD_MID: + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + switch (CommandCode) + { + case CFE_ES_NOOP_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t))) + { + CFE_ES_NoopCmd((const CFE_ES_NoopCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_RESET_COUNTERS_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t))) + { + CFE_ES_ResetCountersCmd((const CFE_ES_ResetCountersCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_RESTART_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t))) + { + CFE_ES_RestartCmd((const CFE_ES_RestartCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_START_APP_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t))) + { + CFE_ES_StartAppCmd((const CFE_ES_StartAppCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_STOP_APP_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t))) + { + CFE_ES_StopAppCmd((const CFE_ES_StopAppCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_RESTART_APP_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t))) + { + CFE_ES_RestartAppCmd((const CFE_ES_RestartAppCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_RELOAD_APP_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t))) + { + CFE_ES_ReloadAppCmd((const CFE_ES_ReloadAppCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_QUERY_ONE_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t))) + { + CFE_ES_QueryOneCmd((const CFE_ES_QueryOneCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_QUERY_ALL_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t))) + { + CFE_ES_QueryAllCmd((const CFE_ES_QueryAllCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_QUERY_ALL_TASKS_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t))) + { + CFE_ES_QueryAllTasksCmd((const CFE_ES_QueryAllTasksCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_CLEAR_SYSLOG_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t))) + { + CFE_ES_ClearSysLogCmd((const CFE_ES_ClearSysLogCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_WRITE_SYSLOG_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t))) + { + CFE_ES_WriteSysLogCmd((const CFE_ES_WriteSysLogCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_OVER_WRITE_SYSLOG_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t))) + { + CFE_ES_OverWriteSysLogCmd((const CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_CLEAR_ER_LOG_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t))) + { + CFE_ES_ClearERLogCmd((const CFE_ES_ClearERLogCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_WRITE_ER_LOG_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t))) + { + CFE_ES_WriteERLogCmd((const CFE_ES_WriteERLogCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_START_PERF_DATA_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t))) + { + CFE_ES_StartPerfDataCmd((const CFE_ES_StartPerfDataCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_STOP_PERF_DATA_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t))) + { + CFE_ES_StopPerfDataCmd((const CFE_ES_StopPerfDataCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_SET_PERF_FILTER_MASK_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t))) + { + CFE_ES_SetPerfFilterMaskCmd((const CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_SET_PERF_TRIGGER_MASK_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t))) + { + CFE_ES_SetPerfTriggerMaskCmd((const CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_RESET_PR_COUNT_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t))) + { + CFE_ES_ResetPRCountCmd((const CFE_ES_ResetPRCountCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_SET_MAX_PR_COUNT_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t))) + { + CFE_ES_SetMaxPRCountCmd((const CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_DELETE_CDS_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t))) + { + CFE_ES_DeleteCDSCmd((const CFE_ES_DeleteCDSCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_SEND_MEM_POOL_STATS_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t))) + { + CFE_ES_SendMemPoolStatsCmd((const CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr); + } + break; + + case CFE_ES_DUMP_CDS_REGISTRY_CC: + if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t))) + { + CFE_ES_DumpCDSRegistryCmd((const CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr); + } + break; + + default: + CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid ground command code: ID = 0x%X, CC = %d", + (unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode); + CFE_ES_Global.TaskData.CommandErrorCounter++; + break; + } + break; + + default: + + CFE_EVS_SendEvent(CFE_ES_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%X", + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); + CFE_ES_Global.TaskData.CommandErrorCounter++; + break; + } +} diff --git a/modules/es/fsw/src/cfe_es_dispatch.h b/modules/es/fsw/src/cfe_es_dispatch.h new file mode 100644 index 000000000..35b157ff0 --- /dev/null +++ b/modules/es/fsw/src/cfe_es_dispatch.h @@ -0,0 +1,44 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * cFE Executive Services (ES) dispatch header file + * + */ + +#ifndef CFE_ES_DISPATCH_H +#define CFE_ES_DISPATCH_H + +/* +** Includes +*/ +#include "common_types.h" + +#include "cfe_es_api_typedefs.h" +#include "cfe_sb_api_typedefs.h" +#include "cfe_msg_api_typedefs.h" + +/*---------------------------------------------------------------------------------------*/ +/** + * Reads and processes messages from the executive services command pipe + */ +void CFE_ES_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); + +#endif /* CFE_ES_DISPATCH_H */ diff --git a/modules/es/fsw/src/cfe_es_module_all.h b/modules/es/fsw/src/cfe_es_module_all.h index 4127dc483..e21006b26 100644 --- a/modules/es/fsw/src/cfe_es_module_all.h +++ b/modules/es/fsw/src/cfe_es_module_all.h @@ -49,6 +49,7 @@ #include "cfe_es_events.h" #include "cfe_es_start.h" #include "cfe_es_task.h" +#include "cfe_es_dispatch.h" #include "cfe_es_resource.h" #include "cfe_es_log.h" diff --git a/modules/es/fsw/src/cfe_es_task.c b/modules/es/fsw/src/cfe_es_task.c index 0219f7c25..a862ffabf 100644 --- a/modules/es/fsw/src/cfe_es_task.c +++ b/modules/es/fsw/src/cfe_es_task.c @@ -434,221 +434,6 @@ int32 CFE_ES_TaskInit(void) return CFE_SUCCESS; } -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -void CFE_ES_TaskPipe(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t CommandCode = 0; - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); - switch (CFE_SB_MsgIdToValue(MessageID)) - { - /* - ** Housekeeping telemetry request - */ - case CFE_ES_SEND_HK_MID: - CFE_ES_HousekeepingCmd((CFE_ES_SendHkCmd_t *)SBBufPtr); - break; - - /* - ** ES task ground commands - */ - case CFE_ES_CMD_MID: - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - switch (CommandCode) - { - case CFE_ES_NOOP_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_NoopCmd_t))) - { - CFE_ES_NoopCmd((CFE_ES_NoopCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_RESET_COUNTERS_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetCountersCmd_t))) - { - CFE_ES_ResetCountersCmd((CFE_ES_ResetCountersCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_RESTART_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartCmd_t))) - { - CFE_ES_RestartCmd((CFE_ES_RestartCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_START_APP_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartAppCmd_t))) - { - CFE_ES_StartAppCmd((CFE_ES_StartAppCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_STOP_APP_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopAppCmd_t))) - { - CFE_ES_StopAppCmd((CFE_ES_StopAppCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_RESTART_APP_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_RestartAppCmd_t))) - { - CFE_ES_RestartAppCmd((CFE_ES_RestartAppCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_RELOAD_APP_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ReloadAppCmd_t))) - { - CFE_ES_ReloadAppCmd((CFE_ES_ReloadAppCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_QUERY_ONE_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryOneCmd_t))) - { - CFE_ES_QueryOneCmd((CFE_ES_QueryOneCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_QUERY_ALL_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllCmd_t))) - { - CFE_ES_QueryAllCmd((CFE_ES_QueryAllCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_QUERY_ALL_TASKS_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_QueryAllTasksCmd_t))) - { - CFE_ES_QueryAllTasksCmd((CFE_ES_QueryAllTasksCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_CLEAR_SYSLOG_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearSysLogCmd_t))) - { - CFE_ES_ClearSysLogCmd((CFE_ES_ClearSysLogCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_WRITE_SYSLOG_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteSysLogCmd_t))) - { - CFE_ES_WriteSysLogCmd((CFE_ES_WriteSysLogCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_OVER_WRITE_SYSLOG_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_OverWriteSysLogCmd_t))) - { - CFE_ES_OverWriteSysLogCmd((CFE_ES_OverWriteSysLogCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_CLEAR_ER_LOG_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ClearERLogCmd_t))) - { - CFE_ES_ClearERLogCmd((CFE_ES_ClearERLogCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_WRITE_ER_LOG_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_WriteERLogCmd_t))) - { - CFE_ES_WriteERLogCmd((CFE_ES_WriteERLogCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_START_PERF_DATA_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StartPerfDataCmd_t))) - { - CFE_ES_StartPerfDataCmd((CFE_ES_StartPerfDataCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_STOP_PERF_DATA_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_StopPerfDataCmd_t))) - { - CFE_ES_StopPerfDataCmd((CFE_ES_StopPerfDataCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_SET_PERF_FILTER_MASK_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfFilterMaskCmd_t))) - { - CFE_ES_SetPerfFilterMaskCmd((CFE_ES_SetPerfFilterMaskCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_SET_PERF_TRIGGER_MASK_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetPerfTriggerMaskCmd_t))) - { - CFE_ES_SetPerfTriggerMaskCmd((CFE_ES_SetPerfTriggerMaskCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_RESET_PR_COUNT_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_ResetPRCountCmd_t))) - { - CFE_ES_ResetPRCountCmd((CFE_ES_ResetPRCountCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_SET_MAX_PR_COUNT_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SetMaxPRCountCmd_t))) - { - CFE_ES_SetMaxPRCountCmd((CFE_ES_SetMaxPRCountCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_DELETE_CDS_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DeleteCDSCmd_t))) - { - CFE_ES_DeleteCDSCmd((CFE_ES_DeleteCDSCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_SEND_MEM_POOL_STATS_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_SendMemPoolStatsCmd_t))) - { - CFE_ES_SendMemPoolStatsCmd((CFE_ES_SendMemPoolStatsCmd_t *)SBBufPtr); - } - break; - - case CFE_ES_DUMP_CDS_REGISTRY_CC: - if (CFE_ES_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_ES_DumpCDSRegistryCmd_t))) - { - CFE_ES_DumpCDSRegistryCmd((CFE_ES_DumpCDSRegistryCmd_t *)SBBufPtr); - } - break; - - default: - CFE_EVS_SendEvent(CFE_ES_CC1_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid ground command code: ID = 0x%X, CC = %d", - (unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode); - CFE_ES_Global.TaskData.CommandErrorCounter++; - break; - } - break; - - default: - - CFE_EVS_SendEvent(CFE_ES_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid command pipe message ID: 0x%X", - (unsigned int)CFE_SB_MsgIdToValue(MessageID)); - CFE_ES_Global.TaskData.CommandErrorCounter++; - break; - } -} - /*---------------------------------------------------------------- * * Application-scope internal function @@ -1676,40 +1461,6 @@ int32 CFE_ES_WriteERLogCmd(const CFE_ES_WriteERLogCmd_t *data) return CFE_SUCCESS; } -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - CFE_MSG_Size_t ActualLength = 0; - CFE_MSG_FcnCode_t FcnCode = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - CFE_EVS_SendEvent(CFE_ES_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - result = false; - CFE_ES_Global.TaskData.CommandErrorCounter++; - } - - return result; -} - /*---------------------------------------------------------------- * * Application-scope internal function diff --git a/modules/es/fsw/src/cfe_es_task.h b/modules/es/fsw/src/cfe_es_task.h index 04bb495fd..54bf57a0a 100644 --- a/modules/es/fsw/src/cfe_es_task.h +++ b/modules/es/fsw/src/cfe_es_task.h @@ -89,12 +89,6 @@ void CFE_ES_TaskMain(void); */ int32 CFE_ES_TaskInit(void); -/*---------------------------------------------------------------------------------------*/ -/** - * Reads and processes messages from the executive services command pipe - */ -void CFE_ES_TaskPipe(CFE_SB_Buffer_t *SBBufPtr); - /* * Functions related to the ES background helper task for low-priority tasks */ @@ -283,12 +277,6 @@ int32 CFE_ES_DumpCDSRegistryCmd(const CFE_ES_DumpCDSRegistryCmd_t *data); */ bool CFE_ES_ValidateHandle(CFE_ES_MemHandle_t Handle); -/*---------------------------------------------------------------------------------------*/ -/** - * \brief Verify command packet length - */ -bool CFE_ES_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); - /*---------------------------------------------------------------------------------------*/ /** * \brief Notify of file write inconsistency diff --git a/modules/evs/CMakeLists.txt b/modules/evs/CMakeLists.txt index a406d1651..66cb966c8 100644 --- a/modules/evs/CMakeLists.txt +++ b/modules/evs/CMakeLists.txt @@ -12,10 +12,7 @@ set(evs_SOURCES fsw/src/cfe_evs_log.c fsw/src/cfe_evs_task.c fsw/src/cfe_evs_utils.c - fsw/src/cfe_evs.c - fsw/src/cfe_evs_log.c - fsw/src/cfe_evs_task.c - fsw/src/cfe_evs_utils.c + fsw/src/cfe_evs_dispatch.c ) add_library(evs STATIC ${evs_SOURCES}) diff --git a/modules/evs/fsw/src/cfe_evs_dispatch.c b/modules/evs/fsw/src/cfe_evs_dispatch.c new file mode 100644 index 000000000..53ee28f71 --- /dev/null +++ b/modules/evs/fsw/src/cfe_evs_dispatch.c @@ -0,0 +1,310 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Event services message dispatcher + */ + +/* Include Files */ +#include "cfe_evs_module_all.h" /* All EVS internal definitions and API */ + +#include + +/* +** Local function prototypes. +*/ +void CFE_EVS_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId); +bool CFE_EVS_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_EVS_ProcessCommandPacket(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); + + /* Process all SB messages */ + switch (CFE_SB_MsgIdToValue(MessageID)) + { + case CFE_EVS_CMD_MID: + /* EVS task specific command */ + CFE_EVS_ProcessGroundCommand(SBBufPtr, MessageID); + break; + + case CFE_EVS_SEND_HK_MID: + /* Housekeeping request */ + CFE_EVS_ReportHousekeepingCmd((const CFE_EVS_SendHkCmd_t *)SBBufPtr); + break; + + default: + /* Unknown command -- should never occur */ + CFE_EVS_Global.EVS_TlmPkt.Payload.CommandErrorCounter++; + EVS_SendEvent(CFE_EVS_ERR_MSGID_EID, CFE_EVS_EventType_ERROR, "Invalid command packet, Message ID = 0x%08X", + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); + break; + } +} + +/*---------------------------------------------------------------- + * + * Internal helper routine only, not part of API. + * + * This function processes a command, verifying that it is valid and of + * proper length. + * + *-----------------------------------------------------------------*/ +void CFE_EVS_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId) +{ + /* status will get reset if it passes length check */ + int32 Status = CFE_STATUS_WRONG_MSG_LENGTH; + CFE_MSG_FcnCode_t FcnCode = 0; + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); + + /* Process "known" EVS task ground commands */ + switch (FcnCode) + { + case CFE_EVS_NOOP_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_NoopCmd_t))) + { + Status = CFE_EVS_NoopCmd((const CFE_EVS_NoopCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_RESET_COUNTERS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetCountersCmd_t))) + { + Status = CFE_EVS_ResetCountersCmd((const CFE_EVS_ResetCountersCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_ENABLE_EVENT_TYPE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableEventTypeCmd_t))) + { + Status = CFE_EVS_EnableEventTypeCmd((const CFE_EVS_EnableEventTypeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_DISABLE_EVENT_TYPE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableEventTypeCmd_t))) + { + Status = CFE_EVS_DisableEventTypeCmd((const CFE_EVS_DisableEventTypeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_SET_EVENT_FORMAT_MODE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetEventFormatModeCmd_t))) + { + Status = CFE_EVS_SetEventFormatModeCmd((const CFE_EVS_SetEventFormatModeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_ENABLE_APP_EVENT_TYPE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventTypeCmd_t))) + { + Status = CFE_EVS_EnableAppEventTypeCmd((const CFE_EVS_EnableAppEventTypeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_DISABLE_APP_EVENT_TYPE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventTypeCmd_t))) + { + Status = CFE_EVS_DisableAppEventTypeCmd((const CFE_EVS_DisableAppEventTypeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_ENABLE_APP_EVENTS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventsCmd_t))) + { + Status = CFE_EVS_EnableAppEventsCmd((const CFE_EVS_EnableAppEventsCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_DISABLE_APP_EVENTS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventsCmd_t))) + { + Status = CFE_EVS_DisableAppEventsCmd((const CFE_EVS_DisableAppEventsCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_RESET_APP_COUNTER_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAppCounterCmd_t))) + { + Status = CFE_EVS_ResetAppCounterCmd((const CFE_EVS_ResetAppCounterCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_SET_FILTER_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetFilterCmd_t))) + { + Status = CFE_EVS_SetFilterCmd((const CFE_EVS_SetFilterCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_ENABLE_PORTS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnablePortsCmd_t))) + { + Status = CFE_EVS_EnablePortsCmd((const CFE_EVS_EnablePortsCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_DISABLE_PORTS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisablePortsCmd_t))) + { + Status = CFE_EVS_DisablePortsCmd((const CFE_EVS_DisablePortsCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_RESET_FILTER_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetFilterCmd_t))) + { + Status = CFE_EVS_ResetFilterCmd((const CFE_EVS_ResetFilterCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_RESET_ALL_FILTERS_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAllFiltersCmd_t))) + { + Status = CFE_EVS_ResetAllFiltersCmd((const CFE_EVS_ResetAllFiltersCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_ADD_EVENT_FILTER_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_AddEventFilterCmd_t))) + { + Status = CFE_EVS_AddEventFilterCmd((const CFE_EVS_AddEventFilterCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_DELETE_EVENT_FILTER_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DeleteEventFilterCmd_t))) + { + Status = CFE_EVS_DeleteEventFilterCmd((const CFE_EVS_DeleteEventFilterCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_WRITE_APP_DATA_FILE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteAppDataFileCmd_t))) + { + Status = CFE_EVS_WriteAppDataFileCmd((const CFE_EVS_WriteAppDataFileCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_SET_LOG_MODE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetLogModeCmd_t))) + { + Status = CFE_EVS_SetLogModeCmd((const CFE_EVS_SetLogModeCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_CLEAR_LOG_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ClearLogCmd_t))) + { + Status = CFE_EVS_ClearLogCmd((const CFE_EVS_ClearLogCmd_t *)SBBufPtr); + } + break; + + case CFE_EVS_WRITE_LOG_DATA_FILE_CC: + + if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteLogDataFileCmd_t))) + { + Status = CFE_EVS_WriteLogDataFileCmd((const CFE_EVS_WriteLogDataFileCmd_t *)SBBufPtr); + } + break; + + /* default is a bad command code as it was not found above */ + default: + + EVS_SendEvent(CFE_EVS_ERR_CC_EID, CFE_EVS_EventType_ERROR, "Invalid command code -- ID = 0x%08x, CC = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode); + Status = CFE_STATUS_BAD_COMMAND_CODE; + + break; + } + + if (Status == CFE_SUCCESS) + { + CFE_EVS_Global.EVS_TlmPkt.Payload.CommandCounter++; + } + else if (Status < 0) /* Negative values indicate errors */ + { + CFE_EVS_Global.EVS_TlmPkt.Payload.CommandErrorCounter++; + } +} + +/*---------------------------------------------------------------- + * + * Internal helper routine only, not part of API. + * + * This function validates the length of a command structure, and + * generates an error event if is not the expected length. + * + *-----------------------------------------------------------------*/ +bool CFE_EVS_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + CFE_MSG_Size_t ActualLength = 0; + CFE_MSG_FcnCode_t FcnCode = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + EVS_SendEvent(CFE_EVS_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + result = false; + } + + return result; +} diff --git a/modules/evs/fsw/src/cfe_evs_dispatch.h b/modules/evs/fsw/src/cfe_evs_dispatch.h new file mode 100644 index 000000000..6cd50eba0 --- /dev/null +++ b/modules/evs/fsw/src/cfe_evs_dispatch.h @@ -0,0 +1,42 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Event Services API - Dispatch API + */ + +#ifndef CFE_EVS_DISPATCH_H +#define CFE_EVS_DISPATCH_H + +/********************************** Include Files ************************************/ +#include "common_types.h" +#include "cfe_evs_api_typedefs.h" +#include "cfe_sb_api_typedefs.h" +#include "cfe_msg_api_typedefs.h" + +/*---------------------------------------------------------------------------------------*/ +/** + * @brief Command Pipe Processing + * + * This function processes packets received on the EVS command pipe. + */ +void CFE_EVS_ProcessCommandPacket(const CFE_SB_Buffer_t *SBBufPtr); + +#endif /* CFE_EVS_DISPATCH_H */ diff --git a/modules/evs/fsw/src/cfe_evs_module_all.h b/modules/evs/fsw/src/cfe_evs_module_all.h index 6009b03dc..312d60789 100644 --- a/modules/evs/fsw/src/cfe_evs_module_all.h +++ b/modules/evs/fsw/src/cfe_evs_module_all.h @@ -43,5 +43,6 @@ #include "cfe_evs_task.h" /* EVS internal definitions */ #include "cfe_evs_log.h" /* EVS log file definitions */ #include "cfe_evs_utils.h" /* EVS utility function definitions */ +#include "cfe_evs_dispatch.h" #endif /* CFE_EVS_MODULE_ALL_H */ diff --git a/modules/evs/fsw/src/cfe_evs_task.c b/modules/evs/fsw/src/cfe_evs_task.c index 1dd39ca09..782a297c5 100644 --- a/modules/evs/fsw/src/cfe_evs_task.c +++ b/modules/evs/fsw/src/cfe_evs_task.c @@ -307,282 +307,6 @@ int32 CFE_EVS_TaskInit(void) return CFE_SUCCESS; } -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -void CFE_EVS_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); - - /* Process all SB messages */ - switch (CFE_SB_MsgIdToValue(MessageID)) - { - case CFE_EVS_CMD_MID: - /* EVS task specific command */ - CFE_EVS_ProcessGroundCommand(SBBufPtr, MessageID); - break; - - case CFE_EVS_SEND_HK_MID: - /* Housekeeping request */ - CFE_EVS_ReportHousekeepingCmd((CFE_EVS_SendHkCmd_t *)SBBufPtr); - break; - - default: - /* Unknown command -- should never occur */ - CFE_EVS_Global.EVS_TlmPkt.Payload.CommandErrorCounter++; - EVS_SendEvent(CFE_EVS_ERR_MSGID_EID, CFE_EVS_EventType_ERROR, "Invalid command packet, Message ID = 0x%08X", - (unsigned int)CFE_SB_MsgIdToValue(MessageID)); - break; - } -} - -/*---------------------------------------------------------------- - * - * Internal helper routine only, not part of API. - * - * This function processes a command, verifying that it is valid and of - * proper length. - * - *-----------------------------------------------------------------*/ -void CFE_EVS_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr, CFE_SB_MsgId_t MsgId) -{ - /* status will get reset if it passes length check */ - int32 Status = CFE_STATUS_WRONG_MSG_LENGTH; - CFE_MSG_FcnCode_t FcnCode = 0; - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); - - /* Process "known" EVS task ground commands */ - switch (FcnCode) - { - case CFE_EVS_NOOP_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_NoopCmd_t))) - { - Status = CFE_EVS_NoopCmd((CFE_EVS_NoopCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_RESET_COUNTERS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetCountersCmd_t))) - { - Status = CFE_EVS_ResetCountersCmd((CFE_EVS_ResetCountersCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_ENABLE_EVENT_TYPE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableEventTypeCmd_t))) - { - Status = CFE_EVS_EnableEventTypeCmd((CFE_EVS_EnableEventTypeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_DISABLE_EVENT_TYPE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableEventTypeCmd_t))) - { - Status = CFE_EVS_DisableEventTypeCmd((CFE_EVS_DisableEventTypeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_SET_EVENT_FORMAT_MODE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetEventFormatModeCmd_t))) - { - Status = CFE_EVS_SetEventFormatModeCmd((CFE_EVS_SetEventFormatModeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_ENABLE_APP_EVENT_TYPE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventTypeCmd_t))) - { - Status = CFE_EVS_EnableAppEventTypeCmd((CFE_EVS_EnableAppEventTypeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_DISABLE_APP_EVENT_TYPE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventTypeCmd_t))) - { - Status = CFE_EVS_DisableAppEventTypeCmd((CFE_EVS_DisableAppEventTypeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_ENABLE_APP_EVENTS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnableAppEventsCmd_t))) - { - Status = CFE_EVS_EnableAppEventsCmd((CFE_EVS_EnableAppEventsCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_DISABLE_APP_EVENTS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisableAppEventsCmd_t))) - { - Status = CFE_EVS_DisableAppEventsCmd((CFE_EVS_DisableAppEventsCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_RESET_APP_COUNTER_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAppCounterCmd_t))) - { - Status = CFE_EVS_ResetAppCounterCmd((CFE_EVS_ResetAppCounterCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_SET_FILTER_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetFilterCmd_t))) - { - Status = CFE_EVS_SetFilterCmd((CFE_EVS_SetFilterCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_ENABLE_PORTS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_EnablePortsCmd_t))) - { - Status = CFE_EVS_EnablePortsCmd((CFE_EVS_EnablePortsCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_DISABLE_PORTS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DisablePortsCmd_t))) - { - Status = CFE_EVS_DisablePortsCmd((CFE_EVS_DisablePortsCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_RESET_FILTER_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetFilterCmd_t))) - { - Status = CFE_EVS_ResetFilterCmd((CFE_EVS_ResetFilterCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_RESET_ALL_FILTERS_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ResetAllFiltersCmd_t))) - { - Status = CFE_EVS_ResetAllFiltersCmd((CFE_EVS_ResetAllFiltersCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_ADD_EVENT_FILTER_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_AddEventFilterCmd_t))) - { - Status = CFE_EVS_AddEventFilterCmd((CFE_EVS_AddEventFilterCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_DELETE_EVENT_FILTER_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_DeleteEventFilterCmd_t))) - { - Status = CFE_EVS_DeleteEventFilterCmd((CFE_EVS_DeleteEventFilterCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_WRITE_APP_DATA_FILE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteAppDataFileCmd_t))) - { - Status = CFE_EVS_WriteAppDataFileCmd((CFE_EVS_WriteAppDataFileCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_SET_LOG_MODE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_SetLogModeCmd_t))) - { - Status = CFE_EVS_SetLogModeCmd((CFE_EVS_SetLogModeCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_CLEAR_LOG_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_ClearLogCmd_t))) - { - Status = CFE_EVS_ClearLogCmd((CFE_EVS_ClearLogCmd_t *)SBBufPtr); - } - break; - - case CFE_EVS_WRITE_LOG_DATA_FILE_CC: - - if (CFE_EVS_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_EVS_WriteLogDataFileCmd_t))) - { - Status = CFE_EVS_WriteLogDataFileCmd((CFE_EVS_WriteLogDataFileCmd_t *)SBBufPtr); - } - break; - - /* default is a bad command code as it was not found above */ - default: - - EVS_SendEvent(CFE_EVS_ERR_CC_EID, CFE_EVS_EventType_ERROR, "Invalid command code -- ID = 0x%08x, CC = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode); - Status = CFE_STATUS_BAD_COMMAND_CODE; - - break; - } - - if (Status == CFE_SUCCESS) - { - CFE_EVS_Global.EVS_TlmPkt.Payload.CommandCounter++; - } - else if (Status < 0) /* Negative values indicate errors */ - { - CFE_EVS_Global.EVS_TlmPkt.Payload.CommandErrorCounter++; - } -} - -/*---------------------------------------------------------------- - * - * Internal helper routine only, not part of API. - * - * This function validates the length of a command structure, and - * generates an error event if is not the expected length. - * - *-----------------------------------------------------------------*/ -bool CFE_EVS_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - CFE_MSG_Size_t ActualLength = 0; - CFE_MSG_FcnCode_t FcnCode = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - EVS_SendEvent(CFE_EVS_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - result = false; - } - - return result; -} - /*---------------------------------------------------------------- * * Application-scope internal function diff --git a/modules/evs/fsw/src/cfe_evs_task.h b/modules/evs/fsw/src/cfe_evs_task.h index e22c498ad..f8274057e 100644 --- a/modules/evs/fsw/src/cfe_evs_task.h +++ b/modules/evs/fsw/src/cfe_evs_task.h @@ -143,14 +143,6 @@ extern CFE_EVS_Global_t CFE_EVS_Global; */ int32 CFE_EVS_TaskInit(void); -/*---------------------------------------------------------------------------------------*/ -/** - * @brief Command Pipe Processing - * - * This function processes packets received on the EVS command pipe. - */ -void CFE_EVS_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr); - /* * EVS Message Handler Functions */ diff --git a/modules/sb/CMakeLists.txt b/modules/sb/CMakeLists.txt index 4362a2774..d7b9ecac7 100644 --- a/modules/sb/CMakeLists.txt +++ b/modules/sb/CMakeLists.txt @@ -13,13 +13,7 @@ set(sb_SOURCES fsw/src/cfe_sb_init.c fsw/src/cfe_sb_msg_id_util.c fsw/src/cfe_sb_priv.c - fsw/src/cfe_sb_task.c - fsw/src/cfe_sb_util.c - fsw/src/cfe_sb_api.c - fsw/src/cfe_sb_buf.c - fsw/src/cfe_sb_init.c - fsw/src/cfe_sb_msg_id_util.c - fsw/src/cfe_sb_priv.c + fsw/src/cfe_sb_dispatch.c fsw/src/cfe_sb_task.c fsw/src/cfe_sb_util.c ) diff --git a/modules/sb/fsw/src/cfe_sb_dispatch.c b/modules/sb/fsw/src/cfe_sb_dispatch.c new file mode 100644 index 000000000..9db5f9770 --- /dev/null +++ b/modules/sb/fsw/src/cfe_sb_dispatch.c @@ -0,0 +1,200 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/****************************************************************************** +** File: cfe_sb_task.c +** +** Purpose: +** This file contains the source code for the SB task. +** +** Author: R.McGraw/SSI +** +******************************************************************************/ + +/* Include Files */ + +#include "cfe_sb_module_all.h" + +#include + +/*---------------------------------------------------------------- + * + * Internal helper routine only, not part of API. + * + * Verifies the length of incoming SB command packets, returns true if acceptable + * + *-----------------------------------------------------------------*/ +bool CFE_SB_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + CFE_MSG_Size_t ActualLength = 0; + CFE_MSG_FcnCode_t FcnCode = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + CFE_EVS_SendEvent(CFE_SB_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + result = false; + ++CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter; + } + + return result; +} + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_SB_ProcessCmdPipePkt(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t FcnCode = 0; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); + + switch (CFE_SB_MsgIdToValue(MessageID)) + { + case CFE_SB_SEND_HK_MID: + /* Note: Command counter not incremented for this command */ + CFE_SB_SendHKTlmCmd((const CFE_MSG_CommandHeader_t *)SBBufPtr); + break; + + case CFE_SB_SUB_RPT_CTRL_MID: + /* Note: Command counter not incremented for this command */ + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); + switch (FcnCode) + { + case CFE_SB_SEND_PREV_SUBS_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendPrevSubsCmd_t))) + { + CFE_SB_SendPrevSubsCmd((const CFE_SB_SendPrevSubsCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_ENABLE_SUB_REPORTING_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableSubReportingCmd_t))) + { + CFE_SB_EnableSubReportingCmd((const CFE_SB_EnableSubReportingCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_DISABLE_SUB_REPORTING_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableSubReportingCmd_t))) + { + CFE_SB_DisableSubReportingCmd((const CFE_SB_DisableSubReportingCmd_t *)SBBufPtr); + } + break; + + default: + CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR, + "Invalid Cmd, Unexpected Command Code %u", (unsigned int)FcnCode); + CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; + break; + } /* end switch on cmd code */ + break; + + case CFE_SB_CMD_MID: + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); + switch (FcnCode) + { + case CFE_SB_NOOP_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_NoopCmd_t))) + { + CFE_SB_NoopCmd((const CFE_SB_NoopCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_RESET_COUNTERS_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_ResetCountersCmd_t))) + { + /* Note: Command counter not incremented for this command */ + CFE_SB_ResetCountersCmd((const CFE_SB_ResetCountersCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_SEND_SB_STATS_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendSbStatsCmd_t))) + { + CFE_SB_SendStatsCmd((const CFE_SB_SendSbStatsCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_WRITE_ROUTING_INFO_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteRoutingInfoCmd_t))) + { + CFE_SB_WriteRoutingInfoCmd((const CFE_SB_WriteRoutingInfoCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_ENABLE_ROUTE_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableRouteCmd_t))) + { + CFE_SB_EnableRouteCmd((const CFE_SB_EnableRouteCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_DISABLE_ROUTE_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableRouteCmd_t))) + { + CFE_SB_DisableRouteCmd((const CFE_SB_DisableRouteCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_WRITE_PIPE_INFO_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WritePipeInfoCmd_t))) + { + CFE_SB_WritePipeInfoCmd((const CFE_SB_WritePipeInfoCmd_t *)SBBufPtr); + } + break; + + case CFE_SB_WRITE_MAP_INFO_CC: + if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteMapInfoCmd_t))) + { + CFE_SB_WriteMapInfoCmd((const CFE_SB_WriteMapInfoCmd_t *)SBBufPtr); + } + break; + + default: + CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR, + "Invalid Cmd, Unexpected Command Code %u", FcnCode); + CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; + break; + } /* end switch on cmd code */ + break; + + default: + CFE_EVS_SendEvent(CFE_SB_BAD_MSGID_EID, CFE_EVS_EventType_ERROR, "Invalid Cmd, Unexpected Msg Id: 0x%x", + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); + CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; + break; + + } /* end switch on MsgId */ +} diff --git a/modules/sb/fsw/src/cfe_sb_dispatch.h b/modules/sb/fsw/src/cfe_sb_dispatch.h new file mode 100644 index 000000000..4857bda90 --- /dev/null +++ b/modules/sb/fsw/src/cfe_sb_dispatch.h @@ -0,0 +1,47 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Purpose: + * This header file contains prototypes for private functions and type + * definitions for SB internal use. + * + * Author: R.McGraw/SSI + * + */ + +#ifndef CFE_SB_DISPATCH_H +#define CFE_SB_DISPATCH_H + +/* +** Includes +*/ +#include "common_types.h" +#include "cfe_sb_api_typedefs.h" + +/*---------------------------------------------------------------------------------------*/ +/** + * Processes a single message buffer that has been received from the command pipe + * + * @param SBBufPtr Software bus buffer pointer + */ +void CFE_SB_ProcessCmdPipePkt(const CFE_SB_Buffer_t *SBBufPtr); + +#endif /* CFE_SB_DISPATCH_H */ diff --git a/modules/sb/fsw/src/cfe_sb_module_all.h b/modules/sb/fsw/src/cfe_sb_module_all.h index 8889993fc..fe3070205 100644 --- a/modules/sb/fsw/src/cfe_sb_module_all.h +++ b/modules/sb/fsw/src/cfe_sb_module_all.h @@ -43,6 +43,7 @@ #include "cfe_sb_events.h" #include "cfe_sb_destination_typedef.h" #include "cfe_sb_msg.h" +#include "cfe_sb_dispatch.h" #include "cfe_sbr.h" #include "cfe_core_resourceid_basevalues.h" diff --git a/modules/sb/fsw/src/cfe_sb_priv.h b/modules/sb/fsw/src/cfe_sb_priv.h index 76cbc93fd..9443c6094 100644 --- a/modules/sb/fsw/src/cfe_sb_priv.h +++ b/modules/sb/fsw/src/cfe_sb_priv.h @@ -331,14 +331,6 @@ void CFE_SB_LockSharedData(const char *FuncName, int32 LineNumber); */ void CFE_SB_UnlockSharedData(const char *FuncName, int32 LineNumber); -/*---------------------------------------------------------------------------------------*/ -/** - * Processes a single message buffer that has been received from the command pipe - * - * @param SBBufPtr Software bus buffer pointer - */ -void CFE_SB_ProcessCmdPipePkt(CFE_SB_Buffer_t *SBBufPtr); - /*---------------------------------------------------------------------------------------*/ /** * Function to reset the SB housekeeping counters. diff --git a/modules/sb/fsw/src/cfe_sb_task.c b/modules/sb/fsw/src/cfe_sb_task.c index c651056e8..2f99e48f0 100644 --- a/modules/sb/fsw/src/cfe_sb_task.c +++ b/modules/sb/fsw/src/cfe_sb_task.c @@ -277,173 +277,6 @@ int32 CFE_SB_AppInit(void) return CFE_SUCCESS; } -/*---------------------------------------------------------------- - * - * Internal helper routine only, not part of API. - * - * Verifies the length of incoming SB command packets, returns true if acceptable - * - *-----------------------------------------------------------------*/ -bool CFE_SB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - CFE_MSG_Size_t ActualLength = 0; - CFE_MSG_FcnCode_t FcnCode = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - CFE_EVS_SendEvent(CFE_SB_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - result = false; - ++CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter; - } - - return result; -} - -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -void CFE_SB_ProcessCmdPipePkt(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t FcnCode = 0; - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); - - switch (CFE_SB_MsgIdToValue(MessageID)) - { - case CFE_SB_SEND_HK_MID: - /* Note: Command counter not incremented for this command */ - CFE_SB_SendHKTlmCmd((CFE_MSG_CommandHeader_t *)SBBufPtr); - break; - - case CFE_SB_SUB_RPT_CTRL_MID: - /* Note: Command counter not incremented for this command */ - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); - switch (FcnCode) - { - case CFE_SB_SEND_PREV_SUBS_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendPrevSubsCmd_t))) - { - CFE_SB_SendPrevSubsCmd((CFE_SB_SendPrevSubsCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_ENABLE_SUB_REPORTING_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableSubReportingCmd_t))) - { - CFE_SB_EnableSubReportingCmd((CFE_SB_EnableSubReportingCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_DISABLE_SUB_REPORTING_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableSubReportingCmd_t))) - { - CFE_SB_DisableSubReportingCmd((CFE_SB_DisableSubReportingCmd_t *)SBBufPtr); - } - break; - - default: - CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR, - "Invalid Cmd, Unexpected Command Code %u", (unsigned int)FcnCode); - CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; - break; - } /* end switch on cmd code */ - break; - - case CFE_SB_CMD_MID: - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); - switch (FcnCode) - { - case CFE_SB_NOOP_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_NoopCmd_t))) - { - CFE_SB_NoopCmd((CFE_SB_NoopCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_RESET_COUNTERS_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_ResetCountersCmd_t))) - { - /* Note: Command counter not incremented for this command */ - CFE_SB_ResetCountersCmd((CFE_SB_ResetCountersCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_SEND_SB_STATS_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_SendSbStatsCmd_t))) - { - CFE_SB_SendStatsCmd((CFE_SB_SendSbStatsCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_WRITE_ROUTING_INFO_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteRoutingInfoCmd_t))) - { - CFE_SB_WriteRoutingInfoCmd((CFE_SB_WriteRoutingInfoCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_ENABLE_ROUTE_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_EnableRouteCmd_t))) - { - CFE_SB_EnableRouteCmd((CFE_SB_EnableRouteCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_DISABLE_ROUTE_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_DisableRouteCmd_t))) - { - CFE_SB_DisableRouteCmd((CFE_SB_DisableRouteCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_WRITE_PIPE_INFO_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WritePipeInfoCmd_t))) - { - CFE_SB_WritePipeInfoCmd((CFE_SB_WritePipeInfoCmd_t *)SBBufPtr); - } - break; - - case CFE_SB_WRITE_MAP_INFO_CC: - if (CFE_SB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_SB_WriteMapInfoCmd_t))) - { - CFE_SB_WriteMapInfoCmd((CFE_SB_WriteMapInfoCmd_t *)SBBufPtr); - } - break; - - default: - CFE_EVS_SendEvent(CFE_SB_BAD_CMD_CODE_EID, CFE_EVS_EventType_ERROR, - "Invalid Cmd, Unexpected Command Code %u", FcnCode); - CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; - break; - } /* end switch on cmd code */ - break; - - default: - CFE_EVS_SendEvent(CFE_SB_BAD_MSGID_EID, CFE_EVS_EventType_ERROR, "Invalid Cmd, Unexpected Msg Id: 0x%x", - (unsigned int)CFE_SB_MsgIdToValue(MessageID)); - CFE_SB_Global.HKTlmMsg.Payload.CommandErrorCounter++; - break; - - } /* end switch on MsgId */ -} - /*---------------------------------------------------------------- * * Application-scope internal function diff --git a/modules/tbl/CMakeLists.txt b/modules/tbl/CMakeLists.txt index 3a761a360..30d333245 100644 --- a/modules/tbl/CMakeLists.txt +++ b/modules/tbl/CMakeLists.txt @@ -12,10 +12,7 @@ set(tbl_SOURCES fsw/src/cfe_tbl_internal.c fsw/src/cfe_tbl_task.c fsw/src/cfe_tbl_task_cmds.c - fsw/src/cfe_tbl_api.c - fsw/src/cfe_tbl_internal.c - fsw/src/cfe_tbl_task.c - fsw/src/cfe_tbl_task_cmds.c + fsw/src/cfe_tbl_dispatch.c ) add_library(tbl STATIC ${tbl_SOURCES}) diff --git a/modules/tbl/fsw/src/cfe_tbl_dispatch.c b/modules/tbl/fsw/src/cfe_tbl_dispatch.c new file mode 100644 index 000000000..b9d8a2484 --- /dev/null +++ b/modules/tbl/fsw/src/cfe_tbl_dispatch.c @@ -0,0 +1,224 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** File: cfe_tbl_task.c +** +** Subsystem: cFE TBL Task +** +** Author: David Kobe (the Hammers Company, Inc.) +** +** Notes: +** +*/ + +/* +** Required header files +*/ +#include "cfe_tbl_module_all.h" + +#include + +/** +** Data structure of a single record in #CFE_TBL_CmdHandlerTbl +*/ +typedef struct +{ + CFE_SB_MsgId_t MsgId; /**< \brief Acceptable Message ID */ + CFE_MSG_FcnCode_t CmdCode; /**< \brief Acceptable Command Code (if necessary) */ + size_t ExpectedLength; /**< \brief Expected Message Length (in bytes) including message header */ + CFE_TBL_MsgProcFuncPtr_t MsgProcFuncPtr; /**< \brief Pointer to function to handle message */ + CFE_TBL_MsgType_t MsgTypes; /**< \brief Message Type (i.e. - with/without Cmd Code) */ +} CFE_TBL_CmdHandlerTblRec_t; + +/* + * Macros to assist in building the CFE_TBL_CmdHandlerTbl - + * For command handler entries, which have a command code, payload type, and a handler function + */ +#define CFE_TBL_ENTRY(mid, ccode, paramtype, handlerfunc, msgtype) \ + { \ + CFE_SB_MSGID_WRAP_VALUE(mid), ccode, sizeof(paramtype), (CFE_TBL_MsgProcFuncPtr_t)handlerfunc, msgtype \ + } + +/* Constant Data */ + +const CFE_TBL_CmdHandlerTblRec_t CFE_TBL_CmdHandlerTbl[] = { + /* SEND_HK Entry */ + CFE_TBL_ENTRY(CFE_TBL_SEND_HK_MID, 0, CFE_TBL_NoArgsCmd_t, CFE_TBL_HousekeepingCmd, CFE_TBL_MSG_MSGTYPE), + + /* Everything else */ + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_NOOP_CC, CFE_TBL_NoopCmd_t, CFE_TBL_NoopCmd, CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_RESET_COUNTERS_CC, CFE_TBL_ResetCountersCmd_t, CFE_TBL_ResetCountersCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_LOAD_CC, CFE_TBL_LoadCmd_t, CFE_TBL_LoadCmd, CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DUMP_CC, CFE_TBL_DumpCmd_t, CFE_TBL_DumpCmd, CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_VALIDATE_CC, CFE_TBL_ValidateCmd_t, CFE_TBL_ValidateCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_ACTIVATE_CC, CFE_TBL_ActivateCmd_t, CFE_TBL_ActivateCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DUMP_REGISTRY_CC, CFE_TBL_DumpRegistryCmd_t, CFE_TBL_DumpRegistryCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_SEND_REGISTRY_CC, CFE_TBL_SendRegistryCmd_t, CFE_TBL_SendRegistryCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DELETE_CDS_CC, CFE_TBL_DeleteCDSCmd_t, CFE_TBL_DeleteCDSCmd, + CFE_TBL_CMD_MSGTYPE), + CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_ABORT_LOAD_CC, CFE_TBL_AbortLoadCmd_t, CFE_TBL_AbortLoadCmd, + CFE_TBL_CMD_MSGTYPE), + + /* list terminator (keep last) */ + {CFE_SB_MSGID_RESERVED, 0, 0, NULL, CFE_TBL_TERM_MSGTYPE}}; + +/******************************************************************************/ + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_TBL_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t CommandCode = 0; + int16 CmdIndx; + CFE_MSG_Size_t ActualLength = 0; + CFE_TBL_CmdProcRet_t CmdStatus = CFE_TBL_INC_ERR_CTR; /* Assume a failed command */ + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + + /* Search the Command Handler Table for a matching message */ + CmdIndx = CFE_TBL_SearchCmdHndlrTbl(MessageID, CommandCode); + + /* Check to see if a matching command was found */ + if (CmdIndx >= 0) + { + /* Verify Message Length before processing */ + CFE_MSG_GetSize(&SBBufPtr->Msg, &ActualLength); + if (ActualLength == CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength) + { + /* All checks have passed, call the appropriate message handler */ + CmdStatus = (CFE_TBL_CmdHandlerTbl[CmdIndx].MsgProcFuncPtr)(SBBufPtr); + } + else /* Bad Message Length */ + { + CFE_EVS_SendEvent(CFE_TBL_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid msg length -- ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MessageID), (unsigned int)CommandCode, + (unsigned int)ActualLength, (unsigned int)CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength); + } + + /* Only update command counters when message has a command code */ + if (CFE_TBL_CmdHandlerTbl[CmdIndx].MsgTypes == CFE_TBL_CMD_MSGTYPE) + { + if (CmdStatus == CFE_TBL_INC_CMD_CTR) + { + CFE_TBL_Global.CommandCounter++; + } + else if (CmdStatus == CFE_TBL_INC_ERR_CTR) + { + CFE_TBL_Global.CommandErrorCounter++; + } + } + } + else + { + /* Determine whether event message should be */ + /* "Bad Command Code" or "Bad Message ID" */ + if (CmdIndx == CFE_TBL_BAD_CMD_CODE) + { + CFE_EVS_SendEvent(CFE_TBL_CC1_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid command code -- ID = 0x%X, CC = %u", + (unsigned int)CFE_SB_MsgIdToValue(MessageID), (unsigned int)CommandCode); + + /* Update the command error counter */ + CFE_TBL_Global.CommandErrorCounter++; + } + else /* CmdIndx == CFE_TBL_BAD_MSG_ID */ + { + CFE_EVS_SendEvent(CFE_TBL_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid message ID -- ID = 0x%X", + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); + /* + ** Note: we only increment the command error counter when + ** processing messages with command codes + */ + } + } +} + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +int16 CFE_TBL_SearchCmdHndlrTbl(CFE_SB_MsgId_t MessageID, uint16 CommandCode) +{ + int16 TblIndx = CFE_TBL_BAD_CMD_CODE; + bool FoundMsg = false; + bool FoundMatch = false; + + do + { + /* Point to next entry in Command Handler Table */ + TblIndx++; + + /* Check to see if we found a matching Message ID */ + if (CFE_SB_MsgId_Equal(CFE_TBL_CmdHandlerTbl[TblIndx].MsgId, MessageID) && + (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE)) + { + /* Flag any found message IDs so that if there is an error, */ + /* we can determine if it was a bad message ID or bad command code */ + FoundMsg = true; + + /* If entry in the Command Handler Table is a command entry, */ + /* then check for a matching command code */ + if (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes == CFE_TBL_CMD_MSGTYPE) + { + if (CFE_TBL_CmdHandlerTbl[TblIndx].CmdCode == CommandCode) + { + /* Found matching message ID and Command Code */ + FoundMatch = true; + } + } + else /* Message is not a command message with specific command code */ + { + /* Automatically assume a match when legit */ + /* Message ID is all that is required */ + FoundMatch = true; + } + } + } while ((!FoundMatch) && (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE)); + + /* If we failed to find a match, return a negative index */ + if (!FoundMatch) + { + /* Determine if the message ID was bad or the command code */ + if (FoundMsg) + { + /* A matching message ID was found, so the command code must be bad */ + TblIndx = CFE_TBL_BAD_CMD_CODE; + } + else /* No matching message ID was found */ + { + TblIndx = CFE_TBL_BAD_MSG_ID; + } + } + + return TblIndx; +} diff --git a/modules/tbl/fsw/src/cfe_tbl_dispatch.h b/modules/tbl/fsw/src/cfe_tbl_dispatch.h new file mode 100644 index 000000000..ae9a61f2d --- /dev/null +++ b/modules/tbl/fsw/src/cfe_tbl_dispatch.h @@ -0,0 +1,55 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @file + * + * Purpose: cFE Table Services (TBL) utility function interface file + * + * Author: D. Kobe/the Hammers Company, Inc. + * + * Notes: + * + */ + +#ifndef CFE_TBL_DISPATCH_H +#define CFE_TBL_DISPATCH_H + +/* +** Required header files... +*/ +#include "cfe_tbl_api_typedefs.h" +#include "cfe_sb_api_typedefs.h" +#include "cfe_msg_api_typedefs.h" + +/*---------------------------------------------------------------------------------------*/ +/** +** \brief Processes command pipe messages +** +** \par Description +** Processes messages obtained from the command pipe. +** +** \par Assumptions, External Events, and Notes: +** None +** +** \param[in] SBBufPtr Pointer to the message received from the command pipe +** +*/ +void CFE_TBL_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); + +#endif /* CFE_TBL_DISPATCH_H */ diff --git a/modules/tbl/fsw/src/cfe_tbl_module_all.h b/modules/tbl/fsw/src/cfe_tbl_module_all.h index 60e64152e..a4b4a304e 100644 --- a/modules/tbl/fsw/src/cfe_tbl_module_all.h +++ b/modules/tbl/fsw/src/cfe_tbl_module_all.h @@ -44,6 +44,7 @@ #include "cfe_tbl_internal.h" #include "cfe_tbl_task.h" #include "cfe_tbl_task_cmds.h" +#include "cfe_tbl_dispatch.h" /* * Additionally TBL needs to use special/extra CDS APIs that are not in the normal API diff --git a/modules/tbl/fsw/src/cfe_tbl_task.c b/modules/tbl/fsw/src/cfe_tbl_task.c index d49f7d48e..fa055b8f2 100644 --- a/modules/tbl/fsw/src/cfe_tbl_task.c +++ b/modules/tbl/fsw/src/cfe_tbl_task.c @@ -41,45 +41,6 @@ */ CFE_TBL_Global_t CFE_TBL_Global; -/* - * Macros to assist in building the CFE_TBL_CmdHandlerTbl - - * For command handler entries, which have a command code, payload type, and a handler function - */ -#define CFE_TBL_ENTRY(mid, ccode, paramtype, handlerfunc, msgtype) \ - { \ - CFE_SB_MSGID_WRAP_VALUE(mid), ccode, sizeof(paramtype), (CFE_TBL_MsgProcFuncPtr_t)handlerfunc, msgtype \ - } - -/* Constant Data */ - -const CFE_TBL_CmdHandlerTblRec_t CFE_TBL_CmdHandlerTbl[] = { - /* SEND_HK Entry */ - CFE_TBL_ENTRY(CFE_TBL_SEND_HK_MID, 0, CFE_TBL_NoArgsCmd_t, CFE_TBL_HousekeepingCmd, CFE_TBL_MSG_MSGTYPE), - - /* Everything else */ - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_NOOP_CC, CFE_TBL_NoopCmd_t, CFE_TBL_NoopCmd, CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_RESET_COUNTERS_CC, CFE_TBL_ResetCountersCmd_t, CFE_TBL_ResetCountersCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_LOAD_CC, CFE_TBL_LoadCmd_t, CFE_TBL_LoadCmd, CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DUMP_CC, CFE_TBL_DumpCmd_t, CFE_TBL_DumpCmd, CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_VALIDATE_CC, CFE_TBL_ValidateCmd_t, CFE_TBL_ValidateCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_ACTIVATE_CC, CFE_TBL_ActivateCmd_t, CFE_TBL_ActivateCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DUMP_REGISTRY_CC, CFE_TBL_DumpRegistryCmd_t, CFE_TBL_DumpRegistryCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_SEND_REGISTRY_CC, CFE_TBL_SendRegistryCmd_t, CFE_TBL_SendRegistryCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_DELETE_CDS_CC, CFE_TBL_DeleteCDSCmd_t, CFE_TBL_DeleteCDSCmd, - CFE_TBL_CMD_MSGTYPE), - CFE_TBL_ENTRY(CFE_TBL_CMD_MID, CFE_TBL_ABORT_LOAD_CC, CFE_TBL_AbortLoadCmd_t, CFE_TBL_AbortLoadCmd, - CFE_TBL_CMD_MSGTYPE), - - /* list terminator (keep last) */ - {CFE_SB_MSGID_RESERVED, 0, 0, NULL, CFE_TBL_TERM_MSGTYPE}}; - -/******************************************************************************/ - /*---------------------------------------------------------------- * * Implemented per public API @@ -235,141 +196,3 @@ void CFE_TBL_InitData(void) CFE_MSG_Init(CFE_MSG_PTR(CFE_TBL_Global.NotifyMsg.CommandHeader), CFE_SB_INVALID_MSG_ID, sizeof(CFE_TBL_Global.NotifyMsg)); } - -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -void CFE_TBL_TaskPipe(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t CommandCode = 0; - int16 CmdIndx; - CFE_MSG_Size_t ActualLength = 0; - CFE_TBL_CmdProcRet_t CmdStatus = CFE_TBL_INC_ERR_CTR; /* Assume a failed command */ - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - - /* Search the Command Handler Table for a matching message */ - CmdIndx = CFE_TBL_SearchCmdHndlrTbl(MessageID, CommandCode); - - /* Check to see if a matching command was found */ - if (CmdIndx >= 0) - { - /* Verify Message Length before processing */ - CFE_MSG_GetSize(&SBBufPtr->Msg, &ActualLength); - if (ActualLength == CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength) - { - /* All checks have passed, call the appropriate message handler */ - CmdStatus = (CFE_TBL_CmdHandlerTbl[CmdIndx].MsgProcFuncPtr)(SBBufPtr); - } - else /* Bad Message Length */ - { - CFE_EVS_SendEvent(CFE_TBL_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length -- ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MessageID), (unsigned int)CommandCode, - (unsigned int)ActualLength, (unsigned int)CFE_TBL_CmdHandlerTbl[CmdIndx].ExpectedLength); - } - - /* Only update command counters when message has a command code */ - if (CFE_TBL_CmdHandlerTbl[CmdIndx].MsgTypes == CFE_TBL_CMD_MSGTYPE) - { - if (CmdStatus == CFE_TBL_INC_CMD_CTR) - { - CFE_TBL_Global.CommandCounter++; - } - else if (CmdStatus == CFE_TBL_INC_ERR_CTR) - { - CFE_TBL_Global.CommandErrorCounter++; - } - } - } - else - { - /* Determine whether event message should be */ - /* "Bad Command Code" or "Bad Message ID" */ - if (CmdIndx == CFE_TBL_BAD_CMD_CODE) - { - CFE_EVS_SendEvent(CFE_TBL_CC1_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid command code -- ID = 0x%X, CC = %u", - (unsigned int)CFE_SB_MsgIdToValue(MessageID), (unsigned int)CommandCode); - - /* Update the command error counter */ - CFE_TBL_Global.CommandErrorCounter++; - } - else /* CmdIndx == CFE_TBL_BAD_MSG_ID */ - { - CFE_EVS_SendEvent(CFE_TBL_MID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid message ID -- ID = 0x%X", - (unsigned int)CFE_SB_MsgIdToValue(MessageID)); - /* - ** Note: we only increment the command error counter when - ** processing messages with command codes - */ - } - } -} - -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -int16 CFE_TBL_SearchCmdHndlrTbl(CFE_SB_MsgId_t MessageID, uint16 CommandCode) -{ - int16 TblIndx = CFE_TBL_BAD_CMD_CODE; - bool FoundMsg = false; - bool FoundMatch = false; - - do - { - /* Point to next entry in Command Handler Table */ - TblIndx++; - - /* Check to see if we found a matching Message ID */ - if (CFE_SB_MsgId_Equal(CFE_TBL_CmdHandlerTbl[TblIndx].MsgId, MessageID) && - (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE)) - { - /* Flag any found message IDs so that if there is an error, */ - /* we can determine if it was a bad message ID or bad command code */ - FoundMsg = true; - - /* If entry in the Command Handler Table is a command entry, */ - /* then check for a matching command code */ - if (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes == CFE_TBL_CMD_MSGTYPE) - { - if (CFE_TBL_CmdHandlerTbl[TblIndx].CmdCode == CommandCode) - { - /* Found matching message ID and Command Code */ - FoundMatch = true; - } - } - else /* Message is not a command message with specific command code */ - { - /* Automatically assume a match when legit */ - /* Message ID is all that is required */ - FoundMatch = true; - } - } - } while ((!FoundMatch) && (CFE_TBL_CmdHandlerTbl[TblIndx].MsgTypes != CFE_TBL_TERM_MSGTYPE)); - - /* If we failed to find a match, return a negative index */ - if (!FoundMatch) - { - /* Determine if the message ID was bad or the command code */ - if (FoundMsg) - { - /* A matching message ID was found, so the command code must be bad */ - TblIndx = CFE_TBL_BAD_CMD_CODE; - } - else /* No matching message ID was found */ - { - TblIndx = CFE_TBL_BAD_MSG_ID; - } - } - - return TblIndx; -} diff --git a/modules/tbl/fsw/src/cfe_tbl_task.h b/modules/tbl/fsw/src/cfe_tbl_task.h index 852b5aa91..f3274d230 100644 --- a/modules/tbl/fsw/src/cfe_tbl_task.h +++ b/modules/tbl/fsw/src/cfe_tbl_task.h @@ -389,21 +389,6 @@ int16 CFE_TBL_SearchCmdHndlrTbl(CFE_SB_MsgId_t MessageID, uint16 CommandCode); */ int32 CFE_TBL_TaskInit(void); -/*---------------------------------------------------------------------------------------*/ -/** -** \brief Processes command pipe messages -** -** \par Description -** Processes messages obtained from the command pipe. -** -** \par Assumptions, External Events, and Notes: -** None -** -** \param[in] SBBufPtr Pointer to the message received from the command pipe -** -*/ -void CFE_TBL_TaskPipe(CFE_SB_Buffer_t *SBBufPtr); - /*---------------------------------------------------------------------------------------*/ /** ** \brief Table Service Application Data Initialization diff --git a/modules/tbl/fsw/src/cfe_tbl_task_cmds.h b/modules/tbl/fsw/src/cfe_tbl_task_cmds.h index 33d2cd0a4..1dfd63a5a 100644 --- a/modules/tbl/fsw/src/cfe_tbl_task_cmds.h +++ b/modules/tbl/fsw/src/cfe_tbl_task_cmds.h @@ -72,18 +72,6 @@ typedef enum CFE_TBL_CMD_MSGTYPE /**< \brief Command Type (requires Message ID and Command Code match) */ } CFE_TBL_MsgType_t; -/** -** Data structure of a single record in #CFE_TBL_CmdHandlerTbl -*/ -typedef struct -{ - CFE_SB_MsgId_t MsgId; /**< \brief Acceptable Message ID */ - CFE_MSG_FcnCode_t CmdCode; /**< \brief Acceptable Command Code (if necessary) */ - size_t ExpectedLength; /**< \brief Expected Message Length (in bytes) including message header */ - CFE_TBL_MsgProcFuncPtr_t MsgProcFuncPtr; /**< \brief Pointer to function to handle message */ - CFE_TBL_MsgType_t MsgTypes; /**< \brief Message Type (i.e. - with/without Cmd Code) */ -} CFE_TBL_CmdHandlerTblRec_t; - /* Command Message Processing Functions */ /*****************************************************************************/ diff --git a/modules/time/CMakeLists.txt b/modules/time/CMakeLists.txt index 2168ed154..7c61c9236 100644 --- a/modules/time/CMakeLists.txt +++ b/modules/time/CMakeLists.txt @@ -12,10 +12,7 @@ set(time_SOURCES fsw/src/cfe_time_task.c fsw/src/cfe_time_tone.c fsw/src/cfe_time_utils.c - fsw/src/cfe_time_api.c - fsw/src/cfe_time_task.c - fsw/src/cfe_time_tone.c - fsw/src/cfe_time_utils.c + fsw/src/cfe_time_dispatch.c ) add_library(time STATIC ${time_SOURCES}) diff --git a/modules/time/fsw/src/cfe_time_dispatch.c b/modules/time/fsw/src/cfe_time_dispatch.c new file mode 100644 index 000000000..fcd6e08fd --- /dev/null +++ b/modules/time/fsw/src/cfe_time_dispatch.c @@ -0,0 +1,264 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/** + * @brief + * + * CFE TIME dispatch implementation + */ + +/* +** Required header files... +*/ +#include "cfe_time_module_all.h" + +/*---------------------------------------------------------------- + * + * Internal helper routine only, not part of API. + * + * Function to verify the length of incoming TIME command packets + * + *-----------------------------------------------------------------*/ +bool CFE_TIME_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + CFE_MSG_Size_t ActualLength = 0; + CFE_MSG_FcnCode_t FcnCode = 0; + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetSize(MsgPtr, &ActualLength); + + /* + ** Verify the command packet length + */ + if (ExpectedLength != ActualLength) + { + CFE_MSG_GetMsgId(MsgPtr, &MsgId); + CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); + + CFE_EVS_SendEvent(CFE_TIME_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", + (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, + (unsigned int)ExpectedLength); + result = false; + ++CFE_TIME_Global.CommandErrorCounter; + } + + return result; +} + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_TIME_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; + CFE_MSG_FcnCode_t CommandCode = 0; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); + + switch (CFE_SB_MsgIdToValue(MessageID)) + { + /* + ** Housekeeping telemetry request... + */ + case CFE_TIME_SEND_HK_MID: + CFE_TIME_HousekeepingCmd((const CFE_TIME_SendHkCmd_t *)SBBufPtr); + break; + + /* + ** Time at the tone "signal"... + */ + case CFE_TIME_TONE_CMD_MID: + CFE_TIME_ToneSignalCmd((const CFE_TIME_ToneSignalCmd_t *)SBBufPtr); + break; + + /* + ** Time at the tone "data"... + */ + case CFE_TIME_DATA_CMD_MID: + CFE_TIME_ToneDataCmd((const CFE_TIME_ToneDataCmd_t *)SBBufPtr); + break; + + /* + ** Run time state machine at 1Hz... + */ + case CFE_TIME_1HZ_CMD_MID: + CFE_TIME_OneHzCmd((const CFE_TIME_1HzCmd_t *)SBBufPtr); + break; + +/* +** Request for time at the tone "data"... +*/ +#if (CFE_PLATFORM_TIME_CFG_SERVER == true) + case CFE_TIME_SEND_CMD_MID: + CFE_TIME_ToneSendCmd((const CFE_TIME_FakeToneCmd_t *)SBBufPtr); + break; +#endif + + /* + ** Time task ground commands... + */ + case CFE_TIME_CMD_MID: + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + switch (CommandCode) + { + case CFE_TIME_NOOP_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_NoopCmd_t))) + { + CFE_TIME_NoopCmd((const CFE_TIME_NoopCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_RESET_COUNTERS_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_ResetCountersCmd_t))) + { + CFE_TIME_ResetCountersCmd((const CFE_TIME_ResetCountersCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SEND_DIAGNOSTIC_TLM_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SendDiagnosticCmd_t))) + { + CFE_TIME_SendDiagnosticTlm((const CFE_TIME_SendDiagnosticCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_STATE_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetStateCmd_t))) + { + CFE_TIME_SetStateCmd((const CFE_TIME_SetStateCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_SOURCE_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSourceCmd_t))) + { + CFE_TIME_SetSourceCmd((const CFE_TIME_SetSourceCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_SIGNAL_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSignalCmd_t))) + { + CFE_TIME_SetSignalCmd((const CFE_TIME_SetSignalCmd_t *)SBBufPtr); + } + break; + + /* + ** Time Clients process "tone delay" commands... + */ + case CFE_TIME_ADD_DELAY_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddDelayCmd_t))) + { + CFE_TIME_AddDelayCmd((const CFE_TIME_AddDelayCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SUB_DELAY_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubDelayCmd_t))) + { + CFE_TIME_SubDelayCmd((const CFE_TIME_SubDelayCmd_t *)SBBufPtr); + } + break; + + /* + ** Time Servers process "set time" commands... + */ + case CFE_TIME_SET_TIME_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetTimeCmd_t))) + { + CFE_TIME_SetTimeCmd((const CFE_TIME_SetTimeCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_MET_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetMETCmd_t))) + { + CFE_TIME_SetMETCmd((const CFE_TIME_SetMETCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_STCF_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSTCFCmd_t))) + { + CFE_TIME_SetSTCFCmd((const CFE_TIME_SetSTCFCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SET_LEAP_SECONDS_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetLeapSecondsCmd_t))) + { + CFE_TIME_SetLeapSecondsCmd((const CFE_TIME_SetLeapSecondsCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_ADD_ADJUST_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddAdjustCmd_t))) + { + CFE_TIME_AddAdjustCmd((const CFE_TIME_AddAdjustCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SUB_ADJUST_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubAdjustCmd_t))) + { + CFE_TIME_SubAdjustCmd((const CFE_TIME_SubAdjustCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_ADD_1HZ_ADJUSTMENT_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Add1HZAdjustmentCmd_t))) + { + CFE_TIME_Add1HZAdjustmentCmd((const CFE_TIME_Add1HZAdjustmentCmd_t *)SBBufPtr); + } + break; + + case CFE_TIME_SUB_1HZ_ADJUSTMENT_CC: + if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Sub1HZAdjustmentCmd_t))) + { + CFE_TIME_Sub1HZAdjustmentCmd((const CFE_TIME_Sub1HZAdjustmentCmd_t *)SBBufPtr); + } + break; + + default: + + CFE_TIME_Global.CommandErrorCounter++; + CFE_EVS_SendEvent(CFE_TIME_CC_ERR_EID, CFE_EVS_EventType_ERROR, + "Invalid command code -- ID = 0x%X, CC = %d", + (unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode); + break; + } /* switch (CFE_TIME_CMD_MID -- command code)*/ + break; + + default: + + /* + ** Note: we only increment the command error counter when + ** processing CFE_TIME_CMD_MID commands... + */ + CFE_EVS_SendEvent(CFE_TIME_ID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid message ID -- ID = 0x%X", + (unsigned int)CFE_SB_MsgIdToValue(MessageID)); + break; + + } /* switch (message ID) */ +} diff --git a/modules/time/fsw/src/cfe_time_dispatch.h b/modules/time/fsw/src/cfe_time_dispatch.h new file mode 100644 index 000000000..2604b865c --- /dev/null +++ b/modules/time/fsw/src/cfe_time_dispatch.h @@ -0,0 +1,47 @@ +/************************************************************************ + * NASA Docket No. GSC-18,719-1, and identified as “core Flight System: Bootes” + * + * Copyright (c) 2020 United States Government as represented by the + * Administrator of the National Aeronautics and Space Administration. + * All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. You may obtain + * a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ************************************************************************/ + +/* +** File: cfe_time_task.c +** +** Subsystem: cFE TIME Task +** +** Author: S. Walling (Microtel) +** +** Notes: +** +*/ +#ifndef CFE_TIME_DISPATCH_H +#define CFE_TIME_DISPATCH_H + +/* +** Required header files... +*/ +#include "cfe_time_api_typedefs.h" +#include "cfe_sb_api_typedefs.h" +#include "cfe_msg_api_typedefs.h" + +/*---------------------------------------------------------------- + * + * Application-scope internal function + * See description in header file for argument/return detail + * + *-----------------------------------------------------------------*/ +void CFE_TIME_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); + +#endif diff --git a/modules/time/fsw/src/cfe_time_module_all.h b/modules/time/fsw/src/cfe_time_module_all.h index 38675b228..8bd048ad6 100644 --- a/modules/time/fsw/src/cfe_time_module_all.h +++ b/modules/time/fsw/src/cfe_time_module_all.h @@ -42,5 +42,6 @@ #include "cfe_time_msg.h" #include "cfe_time_events.h" #include "cfe_time_utils.h" +#include "cfe_time_dispatch.h" #endif /* CFE_TIME_MODULE_ALL_H */ diff --git a/modules/time/fsw/src/cfe_time_task.c b/modules/time/fsw/src/cfe_time_task.c index aa316c7a6..f392e6627 100644 --- a/modules/time/fsw/src/cfe_time_task.c +++ b/modules/time/fsw/src/cfe_time_task.c @@ -305,242 +305,6 @@ int32 CFE_TIME_TaskInit(void) return CFE_SUCCESS; } -/*---------------------------------------------------------------- - * - * Internal helper routine only, not part of API. - * - * Function to verify the length of incoming TIME command packets - * - *-----------------------------------------------------------------*/ -bool CFE_TIME_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) -{ - bool result = true; - CFE_MSG_Size_t ActualLength = 0; - CFE_MSG_FcnCode_t FcnCode = 0; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; - - CFE_MSG_GetSize(MsgPtr, &ActualLength); - - /* - ** Verify the command packet length - */ - if (ExpectedLength != ActualLength) - { - CFE_MSG_GetMsgId(MsgPtr, &MsgId); - CFE_MSG_GetFcnCode(MsgPtr, &FcnCode); - - CFE_EVS_SendEvent(CFE_TIME_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid msg length: ID = 0x%X, CC = %u, Len = %u, Expected = %u", - (unsigned int)CFE_SB_MsgIdToValue(MsgId), (unsigned int)FcnCode, (unsigned int)ActualLength, - (unsigned int)ExpectedLength); - result = false; - ++CFE_TIME_Global.CommandErrorCounter; - } - - return result; -} - -/*---------------------------------------------------------------- - * - * Application-scope internal function - * See description in header file for argument/return detail - * - *-----------------------------------------------------------------*/ -void CFE_TIME_TaskPipe(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_SB_MsgId_t MessageID = CFE_SB_INVALID_MSG_ID; - CFE_MSG_FcnCode_t CommandCode = 0; - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MessageID); - - switch (CFE_SB_MsgIdToValue(MessageID)) - { - /* - ** Housekeeping telemetry request... - */ - case CFE_TIME_SEND_HK_MID: - CFE_TIME_HousekeepingCmd((CFE_TIME_SendHkCmd_t *)SBBufPtr); - break; - - /* - ** Time at the tone "signal"... - */ - case CFE_TIME_TONE_CMD_MID: - CFE_TIME_ToneSignalCmd((CFE_TIME_ToneSignalCmd_t *)SBBufPtr); - break; - - /* - ** Time at the tone "data"... - */ - case CFE_TIME_DATA_CMD_MID: - CFE_TIME_ToneDataCmd((CFE_TIME_ToneDataCmd_t *)SBBufPtr); - break; - - /* - ** Run time state machine at 1Hz... - */ - case CFE_TIME_1HZ_CMD_MID: - CFE_TIME_OneHzCmd((CFE_TIME_1HzCmd_t *)SBBufPtr); - break; - -/* -** Request for time at the tone "data"... -*/ -#if (CFE_PLATFORM_TIME_CFG_SERVER == true) - case CFE_TIME_SEND_CMD_MID: - CFE_TIME_ToneSendCmd((CFE_TIME_FakeToneCmd_t *)SBBufPtr); - break; -#endif - - /* - ** Time task ground commands... - */ - case CFE_TIME_CMD_MID: - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - switch (CommandCode) - { - case CFE_TIME_NOOP_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_NoopCmd_t))) - { - CFE_TIME_NoopCmd((CFE_TIME_NoopCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_RESET_COUNTERS_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_ResetCountersCmd_t))) - { - CFE_TIME_ResetCountersCmd((CFE_TIME_ResetCountersCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SEND_DIAGNOSTIC_TLM_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SendDiagnosticCmd_t))) - { - CFE_TIME_SendDiagnosticTlm((CFE_TIME_SendDiagnosticCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_STATE_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetStateCmd_t))) - { - CFE_TIME_SetStateCmd((CFE_TIME_SetStateCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_SOURCE_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSourceCmd_t))) - { - CFE_TIME_SetSourceCmd((CFE_TIME_SetSourceCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_SIGNAL_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSignalCmd_t))) - { - CFE_TIME_SetSignalCmd((CFE_TIME_SetSignalCmd_t *)SBBufPtr); - } - break; - - /* - ** Time Clients process "tone delay" commands... - */ - case CFE_TIME_ADD_DELAY_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddDelayCmd_t))) - { - CFE_TIME_AddDelayCmd((CFE_TIME_AddDelayCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SUB_DELAY_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubDelayCmd_t))) - { - CFE_TIME_SubDelayCmd((CFE_TIME_SubDelayCmd_t *)SBBufPtr); - } - break; - - /* - ** Time Servers process "set time" commands... - */ - case CFE_TIME_SET_TIME_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetTimeCmd_t))) - { - CFE_TIME_SetTimeCmd((CFE_TIME_SetTimeCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_MET_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetMETCmd_t))) - { - CFE_TIME_SetMETCmd((CFE_TIME_SetMETCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_STCF_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetSTCFCmd_t))) - { - CFE_TIME_SetSTCFCmd((CFE_TIME_SetSTCFCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SET_LEAP_SECONDS_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SetLeapSecondsCmd_t))) - { - CFE_TIME_SetLeapSecondsCmd((CFE_TIME_SetLeapSecondsCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_ADD_ADJUST_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_AddAdjustCmd_t))) - { - CFE_TIME_AddAdjustCmd((CFE_TIME_AddAdjustCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SUB_ADJUST_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_SubAdjustCmd_t))) - { - CFE_TIME_SubAdjustCmd((CFE_TIME_SubAdjustCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_ADD_1HZ_ADJUSTMENT_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Add1HZAdjustmentCmd_t))) - { - CFE_TIME_Add1HZAdjustmentCmd((CFE_TIME_Add1HZAdjustmentCmd_t *)SBBufPtr); - } - break; - - case CFE_TIME_SUB_1HZ_ADJUSTMENT_CC: - if (CFE_TIME_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CFE_TIME_Sub1HZAdjustmentCmd_t))) - { - CFE_TIME_Sub1HZAdjustmentCmd((CFE_TIME_Sub1HZAdjustmentCmd_t *)SBBufPtr); - } - break; - - default: - - CFE_TIME_Global.CommandErrorCounter++; - CFE_EVS_SendEvent(CFE_TIME_CC_ERR_EID, CFE_EVS_EventType_ERROR, - "Invalid command code -- ID = 0x%X, CC = %d", - (unsigned int)CFE_SB_MsgIdToValue(MessageID), (int)CommandCode); - break; - } /* switch (CFE_TIME_CMD_MID -- command code)*/ - break; - - default: - - /* - ** Note: we only increment the command error counter when - ** processing CFE_TIME_CMD_MID commands... - */ - CFE_EVS_SendEvent(CFE_TIME_ID_ERR_EID, CFE_EVS_EventType_ERROR, "Invalid message ID -- ID = 0x%X", - (unsigned int)CFE_SB_MsgIdToValue(MessageID)); - break; - - } /* switch (message ID) */ -} - /*---------------------------------------------------------------- * * Application-scope internal function diff --git a/modules/time/fsw/src/cfe_time_utils.h b/modules/time/fsw/src/cfe_time_utils.h index 7885acbc1..8c9502bac 100644 --- a/modules/time/fsw/src/cfe_time_utils.h +++ b/modules/time/fsw/src/cfe_time_utils.h @@ -331,12 +331,6 @@ CFE_TIME_SysTime_t CFE_TIME_LatchClock(void); */ int32 CFE_TIME_TaskInit(void); -/*---------------------------------------------------------------------------------------*/ -/** - * @brief Process command pipe message - */ -void CFE_TIME_TaskPipe(CFE_SB_Buffer_t *SBBufPtr); - /*---------------------------------------------------------------------------------------*/ /** * @brief Initialize global time task data