diff --git a/.github/workflows/codeql-build.yml b/.github/workflows/codeql-build.yml index a364b0b..9e71f60 100644 --- a/.github/workflows/codeql-build.yml +++ b/.github/workflows/codeql-build.yml @@ -3,11 +3,11 @@ name: "CodeQL Analysis" on: push: pull_request: - + jobs: codeql: name: CodeQL Analysis uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main - with: + with: component-path: apps/ci_lab make: 'make -C build/native/default_cpu1/apps/ci_lab' diff --git a/CHANGELOG.md b/CHANGELOG.md index 09f90b3..fd706b1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## Development Build: v2.5.0-rc4+dev69 +- add decode hooks +- Add version information to NOOP event +- See and + +## Development Build: v2.5.0-rc4+dev51 +- reorganize source files +- See + ## Development Build: v2.5.0-rc4+dev47 - Create Workflow for IC Bundle Generation - See diff --git a/CMakeLists.txt b/CMakeLists.txt index d494d7f..a384943 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,13 +3,23 @@ project(CFS_CI_LAB C) set(APP_SRC_FILES fsw/src/ci_lab_app.c - fsw/src/ci_lab_eds_dispatch.c + fsw/src/ci_lab_cmds.c ) +if (CFE_EDS_ENABLED_BUILD) + list(APPEND APP_SRC_FILES + fsw/src/ci_lab_eds_dispatch.c + fsw/src/ci_lab_eds_decode.c + ) +else() + list(APPEND APP_SRC_FILES + fsw/src/ci_lab_dispatch.c + fsw/src/ci_lab_passthru_decode.c + ) +endif() + + # Create the app module add_cfe_app(ci_lab ${APP_SRC_FILES}) -target_include_directories(ci_lab PUBLIC - fsw/mission_inc - fsw/platform_inc -) +target_include_directories(ci_lab PUBLIC fsw/inc) diff --git a/arch_build.cmake b/arch_build.cmake new file mode 100644 index 0000000..6204bd3 --- /dev/null +++ b/arch_build.cmake @@ -0,0 +1,40 @@ +########################################################### +# +# CI_LAB platform build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# The list of header files that control the CI_LAB configuration +set(CI_LAB_PLATFORM_CONFIG_FILE_LIST + ci_lab_internal_cfg.h + ci_lab_platform_cfg.h + ci_lab_perfids.h + ci_lab_msgids.h +) + +if (CFE_EDS_ENABLED_BUILD) + + # In an EDS-based build, these files come generated from the EDS tool + set(CI_LAB_CFGFILE_SRC_ci_lab_msgids "ci_lab_eds_msgids.h") + +endif() + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(CI_LAB_CFGFILE ${CI_LAB_PLATFORM_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${CI_LAB_CFGFILE}" NAME_WE) + if (DEFINED CI_LAB_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE "${CI_LAB_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE "${CI_LAB_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${CI_LAB_CFGFILE}" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${DEFAULT_SOURCE}" + ) +endforeach() diff --git a/fsw/platform_inc/ci_lab_msgids.h b/config/default_ci_lab_eds_msgids.h similarity index 97% rename from fsw/platform_inc/ci_lab_msgids.h rename to config/default_ci_lab_eds_msgids.h index 666885c..c5cf951 100644 --- a/fsw/platform_inc/ci_lab_msgids.h +++ b/config/default_ci_lab_eds_msgids.h @@ -18,7 +18,7 @@ /** * @file - * Define CI Lab Message IDs + * CI_LAB Application Message IDs */ #ifndef CI_LAB_MSGIDS_H #define CI_LAB_MSGIDS_H diff --git a/config/default_ci_lab_fcncodes.h b/config/default_ci_lab_fcncodes.h new file mode 100644 index 0000000..8d1c456 --- /dev/null +++ b/config/default_ci_lab_fcncodes.h @@ -0,0 +1,46 @@ +/************************************************************************ + * 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 + * Specification for the CI_LAB command function codes + * + * @note + * This file should be strictly limited to the command/function code (CC) + * macro definitions. Other definitions such as enums, typedefs, or other + * macros should be placed in the msgdefs.h or msg.h files. + */ +#ifndef CI_LAB_FCNCODES_H +#define CI_LAB_FCNCODES_H + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/* +** CI_LAB command codes +*/ +#define CI_LAB_NOOP_CC 0 +#define CI_LAB_RESET_COUNTERS_CC 1 +#define CI_LAB_MODIFY_PDU_FILESIZE_CC 2 +#define CI_LAB_CORRUPT_PDU_CHECKSUM_CC 3 +#define CI_LAB_DROP_PDUS_CC 4 +#define CI_LAB_CAPTURE_PDUS_CC 5 +#define CI_LAB_STOP_PDU_CAPTURE_CC 6 + +#endif diff --git a/config/default_ci_lab_interface_cfg.h b/config/default_ci_lab_interface_cfg.h new file mode 100644 index 0000000..f2d9d48 --- /dev/null +++ b/config/default_ci_lab_interface_cfg.h @@ -0,0 +1,50 @@ +/************************************************************************ + * 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 + * CI_LAB Application Public Definitions + * + * This provides default values for configurable items that affect + * the interface(s) of this module. This includes the CMD/TLM message + * interface, tables definitions, and any other data products that + * serve to exchange information with other entities. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef CI_LAB_INTERFACE_CFG_H +#define CI_LAB_INTERFACE_CFG_H + +/** + * @brief The base UDP port where CI_LAB will listen for incoming messages + * + * In order to allow multiple instances of CFE to run on the same host, the + * processor number - 1 is added to this value. This, if this is set to + * "1234", then the following ports will be used at runtime: + * + * Processor 1: port 1234 + * Processor 2: port 1235 + * Processor 3: port 1236 + * + * And so forth for however many processor numbers exist in the system + */ +#define CI_LAB_BASE_UDP_PORT 1234 + +#endif diff --git a/config/default_ci_lab_internal_cfg.h b/config/default_ci_lab_internal_cfg.h new file mode 100644 index 0000000..114aeb8 --- /dev/null +++ b/config/default_ci_lab_internal_cfg.h @@ -0,0 +1,50 @@ +/************************************************************************ + * 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 + * CI_LAB Application Private Config Definitions + * + * This provides default values for configurable items that are internal + * to this module and do NOT affect the interface(s) of this module. Changes + * to items in this file only affect the local module and will be transparent + * to external entities that are using the public interface(s). + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef CI_LAB_INTERNAL_CFG_H +#define CI_LAB_INTERNAL_CFG_H + +/** + * @brief The size of the input buffer + * + * This definition controls the maximum size message that can be ingested + * from the UDP socket + */ +#define CI_LAB_MAX_INGEST 768 + +/** + * @brief The depth of the command input pipe + * + * This controls the depth of the SB input pipe + */ +#define CI_LAB_PIPE_DEPTH 32 + +#endif diff --git a/fsw/src/ci_lab_events.h b/config/default_ci_lab_mission_cfg.h similarity index 64% rename from fsw/src/ci_lab_events.h rename to config/default_ci_lab_mission_cfg.h index 6ddf651..60c0a43 100644 --- a/fsw/src/ci_lab_events.h +++ b/config/default_ci_lab_mission_cfg.h @@ -18,22 +18,19 @@ /** * @file - * Define CI Lab Events IDs + * + * CI_LAB Application Mission Configuration Header File + * + * This is a compatibility header for the "mission_cfg.h" file that has + * traditionally provided public config definitions for each CFS app. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. */ -#ifndef CI_LAB_EVENTS_H -#define CI_LAB_EVENTS_H +#ifndef CI_LAB_MISSION_CFG_H +#define CI_LAB_MISSION_CFG_H -#define CI_LAB_RESERVED_EID 0 -#define CI_LAB_SOCKETCREATE_ERR_EID 1 -#define CI_LAB_SOCKETBIND_ERR_EID 2 -#define CI_LAB_STARTUP_INF_EID 3 -#define CI_LAB_COMMAND_ERR_EID 4 -#define CI_LAB_COMMANDNOP_INF_EID 5 -#define CI_LAB_COMMANDRST_INF_EID 6 -#define CI_LAB_INGEST_INF_EID 7 -#define CI_LAB_INGEST_LEN_ERR_EID 8 -#define CI_LAB_INGEST_ALLOC_ERR_EID 9 -#define CI_LAB_INGEST_SEND_ERR_EID 10 -#define CI_LAB_LEN_ERR_EID 16 +#include "ci_lab_interface_cfg.h" #endif diff --git a/config/default_ci_lab_msg.h b/config/default_ci_lab_msg.h new file mode 100644 index 0000000..1f90517 --- /dev/null +++ b/config/default_ci_lab_msg.h @@ -0,0 +1,38 @@ +/************************************************************************ + * 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 + * Specification for the CI_LAB command and telemetry + * message data types. + * + * This is a compatibility header for the "ci_lab_msg.h" file that has + * traditionally provided the message definitions for cFS apps. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef CI_LAB_MSG_H +#define CI_LAB_MSG_H + +#include "ci_lab_interface_cfg.h" +#include "ci_lab_msgdefs.h" +#include "ci_lab_msgstruct.h" + +#endif diff --git a/config/default_ci_lab_msgdefs.h b/config/default_ci_lab_msgdefs.h new file mode 100644 index 0000000..04e876a --- /dev/null +++ b/config/default_ci_lab_msgdefs.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 + * Specification for the CI_LAB command and telemetry + * message constant definitions. + * + * For CI_LAB this is only the function/command code definitions + */ +#ifndef CI_LAB_MSGDEFS_H +#define CI_LAB_MSGDEFS_H + +#include "ci_lab_fcncodes.h" + +/*************************************************************************/ +/* +** Payload definition (CI_LAB housekeeping)... +*/ +typedef struct +{ + uint8 CommandErrorCounter; + uint8 CommandCounter; + uint8 EnableChecksums; + uint8 SocketConnected; + uint8 Spare1[8]; + uint32 IngestPackets; + uint32 IngestErrors; + uint32 Spare2; +} CI_LAB_HkTlm_Payload_t; + +#endif diff --git a/fsw/src/ci_lab_msg.h b/config/default_ci_lab_msgids.h similarity index 81% rename from fsw/src/ci_lab_msg.h rename to config/default_ci_lab_msgids.h index 48aab02..feefb97 100644 --- a/fsw/src/ci_lab_msg.h +++ b/config/default_ci_lab_msgids.h @@ -18,19 +18,14 @@ /** * @file - * Define CI Lab Messages and info + * CI_LAB Application Message IDs */ -#ifndef CI_LAB_MSG_H -#define CI_LAB_MSG_H +#ifndef CI_LAB_MSGIDS_H +#define CI_LAB_MSGIDS_H -/* - * EDS-defined function codes (*_CC) - */ -#include "ci_lab_eds_cc.h" +#define CI_LAB_CMD_MID 0x1884 +#define CI_LAB_SEND_HK_MID 0x1885 -/* - * EDS-defined message data types - */ -#include "ci_lab_eds_typedefs.h" +#define CI_LAB_HK_TLM_MID 0x0884 #endif diff --git a/config/default_ci_lab_msgstruct.h b/config/default_ci_lab_msgstruct.h new file mode 100644 index 0000000..9680039 --- /dev/null +++ b/config/default_ci_lab_msgstruct.h @@ -0,0 +1,72 @@ +/************************************************************************ + * 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 + * Specification for the CI_LAB command and telemetry + * message data types. + * + * @note + * Constants and enumerated types related to these message structures + * are defined in ci_lab_msgdefs.h. + */ +#ifndef CI_LAB_MSGSTRUCT_H +#define CI_LAB_MSGSTRUCT_H + +/************************************************************************ + * Includes + ************************************************************************/ + +#include "ci_lab_mission_cfg.h" +#include "ci_lab_msgdefs.h" +#include "cfe_msg_hdr.h" + +/*************************************************************************/ +/* +** Type definition (generic "no arguments" command) +*/ + +/* + * Neither the Noop nor ResetCounters command + * have any payload, but should still "reserve" a unique + * structure type to employ a consistent handler pattern. + * + * This matches the pattern in CFE core and other modules. + */ +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_NoopCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_ResetCountersCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_SendHkCmd_t; + +typedef struct +{ + CFE_MSG_TelemetryHeader_t TelemetryHeader; + CI_LAB_HkTlm_Payload_t Payload; +} CI_LAB_HkTlm_t; + +#endif /* CI_LAB_MSGSTRUCT_H */ diff --git a/fsw/mission_inc/ci_lab_perfids.h b/config/default_ci_lab_perfids.h similarity index 100% rename from fsw/mission_inc/ci_lab_perfids.h rename to config/default_ci_lab_perfids.h diff --git a/config/default_ci_lab_platform_cfg.h b/config/default_ci_lab_platform_cfg.h new file mode 100644 index 0000000..f179cbe --- /dev/null +++ b/config/default_ci_lab_platform_cfg.h @@ -0,0 +1,41 @@ +/************************************************************************ + * 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 + * + * CI_LAB Application Platform Configuration Header File + * + * This is a compatibility header for the "platform_cfg.h" file that has + * traditionally provided both public and private config definitions + * for each CFS app. + * + * These definitions are now provided in two separate files, one for + * the public/mission scope and one for internal scope. + * + * @note This file may be overridden/superceded by mission-provided defintions + * either by overriding this header or by generating definitions from a command/data + * dictionary tool. + */ +#ifndef CI_LAB_PLATFORM_CFG_H +#define CI_LAB_PLATFORM_CFG_H + +#include "ci_lab_mission_cfg.h" +#include "ci_lab_internal_cfg.h" + +#endif diff --git a/eds/ci_lab.xml b/eds/ci_lab.xml index 44d9cf0..52c4d80 100644 --- a/eds/ci_lab.xml +++ b/eds/ci_lab.xml @@ -42,6 +42,9 @@ + + + @@ -77,7 +80,7 @@ - + diff --git a/fsw/inc/ci_lab_eventids.h b/fsw/inc/ci_lab_eventids.h new file mode 100644 index 0000000..74b2842 --- /dev/null +++ b/fsw/inc/ci_lab_eventids.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 + * Define CI Lab Events IDs + */ +#ifndef CI_LAB_EVENTIDS_H +#define CI_LAB_EVENTIDS_H + +#define CI_LAB_RESERVED_EID 0 +#define CI_LAB_SOCKETCREATE_ERR_EID 1 +#define CI_LAB_SOCKETBIND_ERR_EID 2 +#define CI_LAB_INIT_INF_EID 3 +#define CI_LAB_MID_ERR_EID 4 +#define CI_LAB_NOOP_INF_EID 5 +#define CI_LAB_RESET_INF_EID 6 +#define CI_LAB_INGEST_INF_EID 7 +#define CI_LAB_INGEST_LEN_ERR_EID 8 +#define CI_LAB_INGEST_ALLOC_ERR_EID 9 +#define CI_LAB_INGEST_SEND_ERR_EID 10 +#define CI_LAB_CR_PIPE_ERR_EID 11 +#define CI_LAB_SB_SUBSCRIBE_CMD_ERR_EID 12 +#define CI_LAB_SB_SUBSCRIBE_HK_ERR_EID 13 +#define CI_LAB_CMD_LEN_ERR_EID 16 + +#endif diff --git a/fsw/src/ci_lab_app.c b/fsw/src/ci_lab_app.c index ae6e157..3a5cdcd 100644 --- a/fsw/src/ci_lab_app.c +++ b/fsw/src/ci_lab_app.c @@ -28,21 +28,11 @@ #include "ci_lab_app.h" #include "ci_lab_perfids.h" #include "ci_lab_msgids.h" -#include "ci_lab_msg.h" -#include "ci_lab_events.h" #include "ci_lab_version.h" - -#include "cfe_config.h" - -#include "edslib_datatypedb.h" -#include "ci_lab_eds_typedefs.h" -#include "cfe_missionlib_api.h" -#include "cfe_missionlib_runtime.h" -#include "cfe_mission_eds_parameters.h" -#include "cfe_mission_eds_interface_parameters.h" +#include "ci_lab_decode.h" /* -** CI global data... +** CI Global Data */ CI_LAB_GlobalData_t CI_LAB_Global; @@ -57,9 +47,9 @@ CI_LAB_GlobalData_t CI_LAB_Global; /* and acts accordingly to process them. */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -void CI_Lab_AppMain(void) +void CI_LAB_AppMain(void) { - int32 status; + CFE_Status_t status; uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; CFE_SB_Buffer_t *SBBufPtr; @@ -81,7 +71,7 @@ void CI_Lab_AppMain(void) if (status == CFE_SUCCESS) { - CI_LAB_ProcessCommandPacket(SBBufPtr); + CI_LAB_TaskPipe(SBBufPtr); } /* Regardless of packet vs timeout, always process uplink queue */ @@ -117,11 +107,34 @@ void CI_LAB_TaskInit(void) memset(&CI_LAB_Global, 0, sizeof(CI_LAB_Global)); - CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY); + status = CFE_EVS_Register(NULL, 0, CFE_EVS_EventFilter_BINARY); + if (status != CFE_SUCCESS) + { + CFE_ES_WriteToSysLog("CI_LAB: Error registering for Event Services, RC = 0x%08X\n", (unsigned int)status); + } + + status = CFE_SB_CreatePipe(&CI_LAB_Global.CommandPipe, CI_LAB_PIPE_DEPTH, "CI_LAB_CMD_PIPE"); + if (status == CFE_SUCCESS) + { + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CI_LAB_CMD_MID), CI_LAB_Global.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(CI_LAB_SB_SUBSCRIBE_CMD_ERR_EID, CFE_EVS_EventType_ERROR, + "Error subscribing to SB Commands, RC = 0x%08X", (unsigned int)status); + } - CFE_SB_CreatePipe(&CI_LAB_Global.CommandPipe, CI_LAB_PIPE_DEPTH, "CI_LAB_CMD_PIPE"); - CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CI_LAB_CMD_MID), CI_LAB_Global.CommandPipe); - CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CI_LAB_SEND_HK_MID), CI_LAB_Global.CommandPipe); + status = CFE_SB_Subscribe(CFE_SB_ValueToMsgId(CI_LAB_SEND_HK_MID), CI_LAB_Global.CommandPipe); + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(CI_LAB_SB_SUBSCRIBE_HK_ERR_EID, CFE_EVS_EventType_ERROR, + "Error subscribing to SB HK Request, RC = 0x%08X", (unsigned int)status); + } + } + else + { + CFE_EVS_SendEvent(CI_LAB_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, + "Error creating SB Command Pipe, RC = 0x%08X", (unsigned int)status); + } status = OS_SocketOpen(&CI_LAB_Global.SocketID, OS_SocketDomain_INET, OS_SocketType_DATAGRAM); if (status != OS_SUCCESS) @@ -159,56 +172,10 @@ void CI_LAB_TaskInit(void) CFE_MSG_Init(CFE_MSG_PTR(CI_LAB_Global.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(CI_LAB_HK_TLM_MID), sizeof(CI_LAB_Global.HkTlm)); - CFE_EVS_SendEvent(CI_LAB_STARTUP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI Lab Initialized.%s", + CFE_EVS_SendEvent(CI_LAB_INIT_INF_EID, CFE_EVS_EventType_INFORMATION, "CI Lab Initialized.%s", CI_LAB_VERSION_STRING); } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Purpose: */ -/* Handle NOOP command packets */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 CI_LAB_Noop(const CI_LAB_NoopCmd_t *data) -{ - /* Does everything the name implies */ - CI_LAB_Global.HkTlm.Payload.CommandCounter++; - - CFE_EVS_SendEvent(CI_LAB_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command"); - - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* Purpose: */ -/* Handle ResetCounters command packets */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 CI_LAB_ResetCounters(const CI_LAB_ResetCountersCmd_t *data) -{ - CFE_EVS_SendEvent(CI_LAB_COMMANDRST_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: RESET command"); - CI_LAB_ResetCounters_Internal(); - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Purpose: */ -/* This function is triggered in response to a task telemetry request */ -/* from the housekeeping task. This function will gather the CI task */ -/* telemetry, packetize it and send it to the housekeeping task via */ -/* the software bus */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 CI_LAB_ReportHousekeeping(const CFE_MSG_CommandHeader_t *data) -{ - CI_LAB_Global.HkTlm.Payload.SocketConnected = CI_LAB_Global.SocketConnected; - CFE_SB_TimeStampMsg(CFE_MSG_PTR(CI_LAB_Global.HkTlm.TelemetryHeader)); - CFE_SB_TransmitMsg(CFE_MSG_PTR(CI_LAB_Global.HkTlm.TelemetryHeader), true); - return CFE_SUCCESS; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ /* */ /* Purpose: */ @@ -234,131 +201,56 @@ void CI_LAB_ResetCounters_Internal(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ void CI_LAB_ReadUpLink(void) { - int i; - int32 status; - uint32 BitSize; - CFE_SB_SoftwareBus_PubSub_Interface_t PubSubParams; - CFE_SB_Listener_Component_t ListenerParams; - EdsLib_DataTypeDB_TypeInfo_t CmdHdrInfo; - EdsLib_DataTypeDB_TypeInfo_t FullCmdInfo; - EdsLib_Id_t EdsId; - CFE_SB_Buffer_t * NextIngestBufPtr; - - const EdsLib_DatabaseObject_t *EDS_DB = CFE_Config_GetObjPointer(CFE_CONFIGID_MISSION_EDS_DB); - - NextIngestBufPtr = NULL; - EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY); - status = EdsLib_DataTypeDB_GetTypeInfo(EDS_DB, EdsId, &CmdHdrInfo); - if (status != EDSLIB_SUCCESS) - { - OS_printf("EdsLib_DataTypeDB_GetTypeInfo(): %d\n", (int)status); - return; - } + int i; + int32 OsStatus; + + CFE_Status_t CfeStatus; + CFE_SB_Buffer_t *SBBufPtr; for (i = 0; i <= 10; i++) { - status = OS_SocketRecvFrom(CI_LAB_Global.SocketID, CI_LAB_Global.NetworkBuffer, - sizeof(CI_LAB_Global.NetworkBuffer), &CI_LAB_Global.SocketAddress, OS_CHECK); - - if (status >= 0) + if (CI_LAB_Global.NetBufPtr == NULL) { - BitSize = status; - BitSize *= 8; + CI_LAB_GetInputBuffer(&CI_LAB_Global.NetBufPtr, &CI_LAB_Global.NetBufSize); } - else + + if (CI_LAB_Global.NetBufPtr == NULL) { - BitSize = 0; + break; } - if (BitSize >= CmdHdrInfo.Size.Bits) + OsStatus = OS_SocketRecvFrom(CI_LAB_Global.SocketID, CI_LAB_Global.NetBufPtr, CI_LAB_Global.NetBufSize, + &CI_LAB_Global.SocketAddress, OS_CHECK); + if (OsStatus > 0) { - if (NextIngestBufPtr == NULL) - { - NextIngestBufPtr = CFE_SB_AllocateMessageBuffer(sizeof(CFE_HDR_CommandHeader_Buffer_t)); - if (NextIngestBufPtr == NULL) - { - CFE_EVS_SendEvent(CI_LAB_INGEST_ALLOC_ERR_EID, CFE_EVS_EventType_ERROR, - "CI: L%d, buffer allocation failed\n", __LINE__); - break; - } - } - - /* Packet is in external wire-format byte order - unpack it and copy */ - EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY); - status = - EdsLib_DataTypeDB_UnpackPartialObject(EDS_DB, &EdsId, NextIngestBufPtr, CI_LAB_Global.NetworkBuffer, - sizeof(CFE_HDR_CommandHeader_Buffer_t), BitSize, 0); - if (status != EDSLIB_SUCCESS) - { - OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(1): %d\n", (int)status); - break; - } - - /* Header decoded successfully - Now need to determine the type for the rest of the payload */ - CFE_MissionLib_Get_PubSub_Parameters(&PubSubParams, &NextIngestBufPtr->Msg.BaseMsg); - CFE_MissionLib_UnmapListenerComponent(&ListenerParams, &PubSubParams); - - status = CFE_MissionLib_GetArgumentType(&CFE_SOFTWAREBUS_INTERFACE, CFE_SB_Telecommand_Interface_ID, - ListenerParams.Telecommand.TopicId, 1, 1, &EdsId); - if (status != CFE_MISSIONLIB_SUCCESS) - { - OS_printf("CFE_MissionLib_GetArgumentType(): %d\n", (int)status); - break; - } - - status = EdsLib_DataTypeDB_UnpackPartialObject( - EDS_DB, &EdsId, NextIngestBufPtr, CI_LAB_Global.NetworkBuffer, sizeof(CFE_HDR_CommandHeader_Buffer_t), - BitSize, sizeof(CFE_HDR_CommandHeader_t)); - if (status != EDSLIB_SUCCESS) - { - OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(2): %d\n", (int)status); - break; - } - - /* Verify that the checksum and basic fields are correct, and recompute the length entry */ - status = EdsLib_DataTypeDB_VerifyUnpackedObject( - EDS_DB, EdsId, NextIngestBufPtr, CI_LAB_Global.NetworkBuffer, EDSLIB_DATATYPEDB_RECOMPUTE_LENGTH); - if (status != EDSLIB_SUCCESS) + CFE_ES_PerfLogEntry(CI_LAB_SOCKET_RCV_PERF_ID); + CfeStatus = CI_LAB_DecodeInputMessage(CI_LAB_Global.NetBufPtr, OsStatus, &SBBufPtr); + if (CfeStatus != CFE_SUCCESS) { - OS_printf("EdsLib_DataTypeDB_VerifyUnpackedObject(): %d\n", (int)status); - break; + CI_LAB_Global.HkTlm.Payload.IngestErrors++; } - - status = EdsLib_DataTypeDB_GetTypeInfo(EDS_DB, EdsId, &FullCmdInfo); - if (status != EDSLIB_SUCCESS) + else { - OS_printf("EdsLib_DataTypeDB_GetTypeInfo(): %d\n", (int)status); - return; + CI_LAB_Global.HkTlm.Payload.IngestPackets++; + CfeStatus = CFE_SB_TransmitBuffer(SBBufPtr, false); } - - CFE_ES_PerfLogEntry(CI_LAB_SOCKET_RCV_PERF_ID); - CI_LAB_Global.HkTlm.Payload.IngestPackets++; - status = CFE_SB_TransmitBuffer(NextIngestBufPtr, false); CFE_ES_PerfLogExit(CI_LAB_SOCKET_RCV_PERF_ID); - if (status == CFE_SUCCESS) + if (CfeStatus == CFE_SUCCESS) { /* Set NULL so a new buffer will be obtained next time around */ - NextIngestBufPtr = NULL; + CI_LAB_Global.NetBufPtr = NULL; + CI_LAB_Global.NetBufSize = 0; } else { CFE_EVS_SendEvent(CI_LAB_INGEST_SEND_ERR_EID, CFE_EVS_EventType_ERROR, - "CI: L%d, CFE_SB_TransmitBuffer() failed, status=%d\n", __LINE__, (int)status); + "CI_LAB: Ingest failed, status=%d\n", (int)CfeStatus); } } - else if (status > 0) + else { - /* bad size, report as ingest error */ - CI_LAB_Global.HkTlm.Payload.IngestErrors++; - - CFE_EVS_SendEvent(CI_LAB_INGEST_LEN_ERR_EID, CFE_EVS_EventType_ERROR, - "CI: L%d, cmd dropped, bad length=%u bits\n", __LINE__, (unsigned int)BitSize); + break; /* no (more) messages */ } } - - if (NextIngestBufPtr != NULL) - { - CFE_SB_ReleaseMessageBuffer(NextIngestBufPtr); - } } diff --git a/fsw/src/ci_lab_app.h b/fsw/src/ci_lab_app.h index 7e243f4..cb1510e 100644 --- a/fsw/src/ci_lab_app.h +++ b/fsw/src/ci_lab_app.h @@ -27,24 +27,29 @@ ** Required header files... */ #include "common_types.h" +#include "osapi.h" #include "cfe.h" -#include "osapi.h" +#include "ci_lab_mission_cfg.h" +#include "ci_lab_platform_cfg.h" +#include "ci_lab_eventids.h" +#include "ci_lab_dispatch.h" +#include "ci_lab_cmds.h" -#include "ci_lab_eds_typedefs.h" +#include "ci_lab_msg.h" #include #include #include -/****************************************************************************/ - -#define CI_LAB_BASE_UDP_PORT 1234 -#define CI_LAB_PIPE_DEPTH 32 +/************************************************************************ + * Macro Definitions + ************************************************************************/ /************************************************************************ ** Type Definitions *************************************************************************/ + typedef struct { bool SocketConnected; @@ -54,12 +59,11 @@ typedef struct CI_LAB_HkTlm_t HkTlm; - CFE_HDR_Message_PackedBuffer_t NetworkBuffer; + void * NetBufPtr; + size_t NetBufSize; } CI_LAB_GlobalData_t; -extern CI_LAB_GlobalData_t CI_LAB_Global; - /****************************************************************************/ /* ** Local function prototypes... @@ -67,12 +71,14 @@ extern CI_LAB_GlobalData_t CI_LAB_Global; ** Note: Except for the entry point (CI_LAB_AppMain), these ** functions are not called from any other source module. */ -void CI_Lab_AppMain(void); +void CI_LAB_AppMain(void); void CI_LAB_TaskInit(void); -void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr); void CI_LAB_ResetCounters_Internal(void); void CI_LAB_ReadUpLink(void); +/* Global State Object */ +extern CI_LAB_GlobalData_t CI_LAB_Global; + /* * Individual message handler function prototypes * diff --git a/fsw/src/ci_lab_cmds.c b/fsw/src/ci_lab_cmds.c new file mode 100644 index 0000000..2a02fe8 --- /dev/null +++ b/fsw/src/ci_lab_cmds.c @@ -0,0 +1,77 @@ +/************************************************************************ + * 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 + * This file contains the command handler functions for the Command Ingest task. + */ + +/* +** Include Files: +*/ + +#include "ci_lab_app.h" +#include "ci_lab_cmds.h" +#include "ci_lab_version.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Purpose: */ +/* Handle NOOP command packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t CI_LAB_NoopCmd(const CI_LAB_NoopCmd_t *cmd) +{ + /* Does everything the name implies */ + CI_LAB_Global.HkTlm.Payload.CommandCounter++; + + CFE_EVS_SendEvent(CI_LAB_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command. Version %d.%d.%d.%d", + CI_LAB_MAJOR_VERSION, CI_LAB_MINOR_VERSION, CI_LAB_REVISION, CI_LAB_MISSION_REV); + + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* Purpose: */ +/* Handle ResetCounters command packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t CI_LAB_ResetCountersCmd(const CI_LAB_ResetCountersCmd_t *cmd) +{ + CFE_EVS_SendEvent(CI_LAB_RESET_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: RESET command"); + CI_LAB_ResetCounters_Internal(); + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This function is triggered in response to a task telemetry request */ +/* from the housekeeping task. This function will gather the CI task */ +/* telemetry, packetize it and send it to the housekeeping task via */ +/* the software bus */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t CI_LAB_SendHkCmd(const CI_LAB_SendHkCmd_t *cmd) +{ + CI_LAB_Global.HkTlm.Payload.SocketConnected = CI_LAB_Global.SocketConnected; + CFE_SB_TimeStampMsg(CFE_MSG_PTR(CI_LAB_Global.HkTlm.TelemetryHeader)); + CFE_SB_TransmitMsg(CFE_MSG_PTR(CI_LAB_Global.HkTlm.TelemetryHeader), true); + return CFE_SUCCESS; +} diff --git a/fsw/src/ci_lab_cmds.h b/fsw/src/ci_lab_cmds.h new file mode 100644 index 0000000..b399ee4 --- /dev/null +++ b/fsw/src/ci_lab_cmds.h @@ -0,0 +1,62 @@ +/************************************************************************ + * 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 + * This file contains the command handler functions for the Command Ingest task. + */ +#ifndef CI_LAB_CMDS_H +#define CI_LAB_CMDS_H + +#include "common_types.h" +#include "cfe_error.h" +#include "ci_lab_msg.h" + +/** + * @brief Handle NOOP command packets + * + * @param cmd Input message pointer + * @returns CFE Status code + * @retval #CFE_SUCCESS on successful processing + */ +CFE_Status_t CI_LAB_NoopCmd(const CI_LAB_NoopCmd_t *cmd); + +/** + * @brief Handle ResetCounters command packets + * + * @param cmd Input message pointer + * @returns CFE Status code + * @retval #CFE_SUCCESS on successful processing + */ +CFE_Status_t CI_LAB_ResetCountersCmd(const CI_LAB_ResetCountersCmd_t *cmd); + +/** + * @brief Handle Send HK command packets + * + * This function is triggered in response to a task telemetry request + * from the housekeeping task. This function will gather the CI task + * telemetry, packetize it and send it to the housekeeping task via + * the software bus + * + * @param cmd Input message pointer + * @returns CFE Status code + * @retval #CFE_SUCCESS on successful processing + */ +CFE_Status_t CI_LAB_SendHkCmd(const CI_LAB_SendHkCmd_t *cmd); + +#endif diff --git a/fsw/src/ci_lab_decode.h b/fsw/src/ci_lab_decode.h new file mode 100644 index 0000000..db4b2ff --- /dev/null +++ b/fsw/src/ci_lab_decode.h @@ -0,0 +1,35 @@ +/************************************************************************ + * 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 + * This is the dispatch hdr file for the Command Ingest lab application. + */ +#ifndef CI_LAB_DECODE_H +#define CI_LAB_DECODE_H + +/* +** Required header files... +*/ +#include "common_types.h" +#include "cfe_sb_api_typedefs.h" + +CFE_Status_t CI_LAB_GetInputBuffer(void **BufferOut, size_t *SizeOut); +CFE_Status_t CI_LAB_DecodeInputMessage(void *SourceBuffer, size_t SourceSize, CFE_SB_Buffer_t **DestBufferOut); + +#endif diff --git a/fsw/src/ci_lab_dispatch.c b/fsw/src/ci_lab_dispatch.c new file mode 100644 index 0000000..038002d --- /dev/null +++ b/fsw/src/ci_lab_dispatch.c @@ -0,0 +1,131 @@ +/************************************************************************ + * 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 + * This file contains the command dispatch logic for the CI_LAB app + */ + +#include "cfe.h" +#include "ci_lab_app.h" +#include "ci_lab_dispatch.h" +#include "ci_lab_cmds.h" +#include "ci_lab_msgids.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Verify command packet length */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +bool CI_LAB_VerifyCmdLength(const CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength) +{ + bool result = true; + 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(CI_LAB_CMD_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; + CI_LAB_Global.HkTlm.Payload.CommandErrorCounter++; + } + + return result; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* CI ground commands */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ + +void CI_LAB_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_MSG_FcnCode_t FcnCode = 0; + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &FcnCode); + + /* Process "known" CI task ground commands */ + switch (FcnCode) + { + case CI_LAB_NOOP_CC: + if (CI_LAB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CI_LAB_NoopCmd_t))) + { + CI_LAB_NoopCmd((const CI_LAB_NoopCmd_t *)SBBufPtr); + } + break; + + case CI_LAB_RESET_COUNTERS_CC: + if (CI_LAB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CI_LAB_ResetCountersCmd_t))) + { + CI_LAB_ResetCountersCmd((const CI_LAB_ResetCountersCmd_t *)SBBufPtr); + } + break; + + /* default case already found during FC vs length test */ + default: + break; + } +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ +/* */ +/* Purpose: */ +/* This routine will process any packet that is received on the CI command*/ +/* pipe. The packets received on the CI command pipe are listed here: */ +/* */ +/* 1. NOOP command (from ground) */ +/* 2. Request to reset telemetry counters (from ground) */ +/* 3. Request for housekeeping telemetry packet (from HS task) */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void CI_LAB_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); + + switch (CFE_SB_MsgIdToValue(MsgId)) + { + case CI_LAB_CMD_MID: + CI_LAB_ProcessGroundCommand(SBBufPtr); + break; + + case CI_LAB_SEND_HK_MID: + CI_LAB_SendHkCmd((const CI_LAB_SendHkCmd_t *)SBBufPtr); + break; + + default: + CI_LAB_Global.HkTlm.Payload.CommandErrorCounter++; + CFE_EVS_SendEvent(CI_LAB_MID_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x", + (unsigned int)CFE_SB_MsgIdToValue(MsgId)); + break; + } +} diff --git a/fsw/src/ci_lab_dispatch.h b/fsw/src/ci_lab_dispatch.h new file mode 100644 index 0000000..be18fb8 --- /dev/null +++ b/fsw/src/ci_lab_dispatch.h @@ -0,0 +1,39 @@ +/************************************************************************ + * 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 + * This is the dispatch hdr file for the Command Ingest lab application. + */ +#ifndef CI_LAB_DISPATCH_H +#define CI_LAB_DISPATCH_H + +/* +** Required header files... +*/ +#include "common_types.h" +#include "cfe_sb_api_typedefs.h" + +/** + * @brief Process a message/packet received from the Software Bus + * + * @param SBBufPtr Pointer to buffer received from the pipe + */ +void CI_LAB_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); + +#endif diff --git a/fsw/src/ci_lab_eds_decode.c b/fsw/src/ci_lab_eds_decode.c new file mode 100644 index 0000000..3bc589b --- /dev/null +++ b/fsw/src/ci_lab_eds_decode.c @@ -0,0 +1,167 @@ +/************************************************************************ + * 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 + * This file contains the source code for the Command Ingest task. + */ + +/* +** Include Files: +*/ + +#include "ci_lab_app.h" +#include "ci_lab_perfids.h" +#include "ci_lab_msgids.h" +#include "ci_lab_version.h" + +#include "cfe_config.h" + +#include "edslib_datatypedb.h" +#include "ci_lab_eds_typedefs.h" +#include "cfe_missionlib_api.h" +#include "cfe_missionlib_runtime.h" +#include "cfe_mission_eds_parameters.h" +#include "cfe_mission_eds_interface_parameters.h" + + +/* + * --------------------------------------- + * In an EDS configuration - the data from the network is encoded + * and needs to be read into an intermediate buffer first + * --------------------------------------- + */ +CFE_Status_t CI_LAB_GetInputBuffer(void **BufferOut, size_t *SizeOut) +{ + static CFE_HDR_CommandHeader_PackedBuffer_t InputBuffer; + + *BufferOut = &InputBuffer; + *SizeOut = sizeof(InputBuffer); + + return CFE_SUCCESS; +} + +/* + * --------------------------------------- + * In an EDS configuration - the data from the network is encoded + * and this function translates the intermediate buffer content + * to an instance of the CFE_SB_Buffer_t that can be sent to SB. + * --------------------------------------- + */ +CFE_Status_t CI_LAB_DecodeInputMessage(void *SourceBuffer, size_t SourceSize, CFE_SB_Buffer_t **DestBufferOut) +{ + int32 EdsStatus; + uint32 BitSize; + CFE_SB_SoftwareBus_PubSub_Interface_t PubSubParams; + CFE_SB_Listener_Component_t ListenerParams; + EdsLib_DataTypeDB_TypeInfo_t CmdHdrInfo; + EdsLib_Id_t EdsId; + CFE_SB_Buffer_t * IngestBufPtr; + CFE_Status_t ResultStatus; + + const EdsLib_DatabaseObject_t *EDS_DB = CFE_Config_GetObjPointer(CFE_CONFIGID_MISSION_EDS_DB); + + ResultStatus = CFE_STATUS_VALIDATION_FAILURE; + IngestBufPtr = NULL; + + do + { + EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY); + EdsStatus = EdsLib_DataTypeDB_GetTypeInfo(EDS_DB, EdsId, &CmdHdrInfo); + if (EdsStatus != EDSLIB_SUCCESS) + { + OS_printf("EdsLib_DataTypeDB_GetTypeInfo(): %d\n", (int)EdsStatus); + break; + } + + /* sanity check - validate the incoming packet is at least the size of a command header */ + BitSize = 8 * SourceSize; + if (BitSize < CmdHdrInfo.Size.Bits) + { + OS_printf("CI_LAB: Size mismatch, BitSize=%lu (packet) / %lu (min)\n", + (unsigned long)BitSize, (unsigned long)CmdHdrInfo.Size.Bits); + + ResultStatus = CFE_STATUS_WRONG_MSG_LENGTH; + break; + } + + /* Now get a SB Buffer, as a place to put the decoded data */ + IngestBufPtr = CFE_SB_AllocateMessageBuffer(sizeof(CFE_HDR_CommandHeader_Buffer_t)); + if (IngestBufPtr == NULL) + { + CFE_EVS_SendEvent(CI_LAB_INGEST_ALLOC_ERR_EID, CFE_EVS_EventType_ERROR, + "CI_LAB: buffer allocation failed\n"); + + ResultStatus = CFE_SB_BUF_ALOC_ERR; + break; + } + + /* Packet is in external wire-format byte order - unpack it and copy */ + EdsId = EDSLIB_MAKE_ID(EDS_INDEX(CFE_HDR), CFE_HDR_CommandHeader_DATADICTIONARY); + EdsStatus = EdsLib_DataTypeDB_UnpackPartialObject(EDS_DB, &EdsId, IngestBufPtr, SourceBuffer, + sizeof(CFE_HDR_CommandHeader_t), BitSize, 0); + if (EdsStatus != EDSLIB_SUCCESS) + { + OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(1): %d\n", (int)EdsStatus); + break; + } + + /* Header decoded successfully - Now need to determine the type for the rest of the payload */ + CFE_MissionLib_Get_PubSub_Parameters(&PubSubParams, &IngestBufPtr->Msg.BaseMsg); + CFE_MissionLib_UnmapListenerComponent(&ListenerParams, &PubSubParams); + + EdsStatus = CFE_MissionLib_GetArgumentType(&CFE_SOFTWAREBUS_INTERFACE, CFE_SB_Telecommand_Interface_ID, + ListenerParams.Telecommand.TopicId, 1, 1, &EdsId); + if (EdsStatus != CFE_MISSIONLIB_SUCCESS) + { + OS_printf("CFE_MissionLib_GetArgumentType(): %d\n", (int)EdsStatus); + break; + } + + EdsStatus = EdsLib_DataTypeDB_UnpackPartialObject(EDS_DB, &EdsId, IngestBufPtr, SourceBuffer, + sizeof(CFE_HDR_CommandHeader_Buffer_t), BitSize, sizeof(CFE_HDR_CommandHeader_t)); + if (EdsStatus != EDSLIB_SUCCESS) + { + OS_printf("EdsLib_DataTypeDB_UnpackPartialObject(2): %d\n", (int)EdsStatus); + break; + } + + /* Verify that the checksum and basic fields are correct, and recompute the length entry */ + EdsStatus = EdsLib_DataTypeDB_VerifyUnpackedObject(EDS_DB, EdsId, IngestBufPtr, SourceBuffer, + EDSLIB_DATATYPEDB_RECOMPUTE_LENGTH); + if (EdsStatus != EDSLIB_SUCCESS) + { + OS_printf("EdsLib_DataTypeDB_VerifyUnpackedObject(): %d\n", (int)EdsStatus); + break; + } + + /* Finally - at this point, we should have a fully decoded buffer */ + ResultStatus = CFE_SUCCESS; + } + while(false); + + if (ResultStatus != CFE_SUCCESS && IngestBufPtr != NULL) + { + CFE_SB_ReleaseMessageBuffer(IngestBufPtr); + IngestBufPtr = NULL; + } + + *DestBufferOut = IngestBufPtr; + + return ResultStatus; +} diff --git a/fsw/src/ci_lab_eds_dispatch.c b/fsw/src/ci_lab_eds_dispatch.c index 3a3f9f6..fbe7383 100644 --- a/fsw/src/ci_lab_eds_dispatch.c +++ b/fsw/src/ci_lab_eds_dispatch.c @@ -30,7 +30,9 @@ */ #include "ci_lab_app.h" -#include "ci_lab_events.h" +#include "ci_lab_eventids.h" +#include "ci_lab_dispatch.h" +#include "ci_lab_cmds.h" #include "ci_lab_eds_dictionary.h" #include "ci_lab_eds_dispatcher.h" @@ -41,14 +43,14 @@ static const CI_LAB_Application_Component_Telecommand_DispatchTable_t CI_LAB_TC_DISPATCH_TABLE = { .CMD = { - .NoopCmd_indication = CI_LAB_Noop, - .ResetCountersCmd_indication = CI_LAB_ResetCounters, + .NoopCmd_indication = CI_LAB_NoopCmd, + .ResetCountersCmd_indication = CI_LAB_ResetCountersCmd, }, - .SEND_HK = {.indication = CI_LAB_ReportHousekeeping}}; + .SEND_HK = {.indication = CI_LAB_SendHkCmd}}; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* Name: CI_LAB_ProcessCommandPacket */ +/* Name: CI_LAB_TaskPipe */ /* */ /* Purpose: */ /* This routine will process any packet that is received on the CI command*/ @@ -59,7 +61,7 @@ static const CI_LAB_Application_Component_Telecommand_DispatchTable_t CI_LAB_TC_ /* 3. Request for housekeeping telemetry packet (from HS task) */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) +void CI_LAB_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) { CFE_SB_MsgId_t MsgId; CFE_Status_t Status; @@ -73,8 +75,8 @@ void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr) { CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); CI_LAB_Global.HkTlm.Payload.CommandErrorCounter++; - CFE_EVS_SendEvent(CI_LAB_COMMAND_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x", + CFE_EVS_SendEvent(CI_LAB_MID_ERR_EID, CFE_EVS_EventType_ERROR, "CI: invalid command packet,MID = 0x%x", (unsigned int)CFE_SB_MsgIdToValue(MsgId)); } -} /* End CI_LAB_ProcessCommandPacket */ +} /* End CI_LAB_TaskPipe */ diff --git a/fsw/src/ci_lab_passthru_decode.c b/fsw/src/ci_lab_passthru_decode.c new file mode 100644 index 0000000..05d41e8 --- /dev/null +++ b/fsw/src/ci_lab_passthru_decode.c @@ -0,0 +1,114 @@ +/************************************************************************ + * 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 + * This file contains the source code for the Command Ingest task. + */ + +/* +** Include Files: +*/ +#include "cfe.h" + +#include "ci_lab_app.h" +#include "ci_lab_perfids.h" +#include "ci_lab_msgids.h" +#include "ci_lab_decode.h" + +/* + * --------------------------------------- + * In a "passthrough" configuration - the data from the network + * is expected to be a direct instance of the CFE_MSG_Message_t base, + * and thus something can be sent directly to SB. + * + * Instead of using an intermediate buffer, just get a buffer from + * SB and put it directly in there. This reduces copying. + * --------------------------------------- + */ +CFE_Status_t CI_LAB_GetInputBuffer(void **BufferOut, size_t *SizeOut) +{ + CFE_SB_Buffer_t *IngestBuffer; + const size_t IngestSize = CI_LAB_MAX_INGEST; + + IngestBuffer = CFE_SB_AllocateMessageBuffer(IngestSize); + if (IngestBuffer == NULL) + { + *BufferOut = NULL; + *SizeOut = 0; + + CFE_EVS_SendEvent(CI_LAB_INGEST_ALLOC_ERR_EID, CFE_EVS_EventType_ERROR, "CI_LAB: buffer allocation failed\n"); + + return CFE_SB_BUF_ALOC_ERR; + } + + *BufferOut = IngestBuffer; + *SizeOut = IngestSize; + + return CFE_SUCCESS; +} + +/* + * --------------------------------------- + * In a "passthrough" configuration - the data from the network + * is expected to be a direct instance of the CFE_MSG_Message_t base, + * and thus something can be sent directly to SB. + * + * This just does a simple sanity check on the message size. But + * otherwise, the source buffer is used directly as the output buffer. + * --------------------------------------- + */ +CFE_Status_t CI_LAB_DecodeInputMessage(void *SourceBuffer, size_t SourceSize, CFE_SB_Buffer_t **DestBufferOut) +{ + CFE_SB_Buffer_t *MsgBufPtr; + CFE_MSG_Size_t MsgSize; + CFE_Status_t Status; + + if (SourceSize < sizeof(CFE_MSG_CommandHeader_t)) + { + MsgBufPtr = NULL; + Status = CFE_STATUS_WRONG_MSG_LENGTH; + + CFE_EVS_SendEvent(CI_LAB_INGEST_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "CI: cmd dropped, bad packet length=%lu\n", (unsigned long)SourceSize); + } + else + { + MsgBufPtr = SourceBuffer; + + /* Check the size from within the header itself, compare against network buffer size */ + CFE_MSG_GetSize(&MsgBufPtr->Msg, &MsgSize); + + if (MsgSize > SourceSize) + { + Status = CFE_STATUS_WRONG_MSG_LENGTH; + + CFE_EVS_SendEvent(CI_LAB_INGEST_LEN_ERR_EID, CFE_EVS_EventType_ERROR, + "CI: cmd dropped - length mismatch, %lu (hdr) / %lu (packet)\n", (unsigned long)MsgSize, + (unsigned long)SourceSize); + } + else + { + Status = CFE_SUCCESS; + } + } + + *DestBufferOut = MsgBufPtr; + + return Status; +} diff --git a/fsw/src/ci_lab_version.h b/fsw/src/ci_lab_version.h index 0ff55d2..cd7e58e 100644 --- a/fsw/src/ci_lab_version.h +++ b/fsw/src/ci_lab_version.h @@ -25,7 +25,7 @@ /* Development Build Macro Definitions */ -#define CI_LAB_BUILD_NUMBER 47 /*!< Development Build: Number of commits since baseline */ +#define CI_LAB_BUILD_NUMBER 69 /*!< Development Build: Number of commits since baseline */ #define CI_LAB_BUILD_BASELINE \ "v2.5.0-rc4" /*!< Development Build: git tag that is the base for the current development */ diff --git a/mission_build.cmake b/mission_build.cmake new file mode 100644 index 0000000..c851706 --- /dev/null +++ b/mission_build.cmake @@ -0,0 +1,46 @@ +########################################################### +# +# CI_LAB mission build setup +# +# This file is evaluated as part of the "prepare" stage +# and can be used to set up prerequisites for the build, +# such as generating header files +# +########################################################### + +# The list of header files that control the CI_LAB configuration +set(CI_LAB_MISSION_CONFIG_FILE_LIST + ci_lab_fcncodes.h + ci_lab_interface_cfg.h + ci_lab_mission_cfg.h + ci_lab_perfids.h + ci_lab_msgdefs.h + ci_lab_msg.h + ci_lab_msgstruct.h +) + +if (CFE_EDS_ENABLED_BUILD) + + # In an EDS-based build, these files come generated from the EDS tool + set(CI_LAB_CFGFILE_SRC_ci_lab_interface_cfg "ci_lab_eds_designparameters.h") + set(CI_LAB_CFGFILE_SRC_ci_lab_msgdefs "ci_lab_eds_typedefs.h") + set(CI_LAB_CFGFILE_SRC_ci_lab_msgstruct "ci_lab_eds_typedefs.h") + set(CI_LAB_CFGFILE_SRC_ci_lab_fcncodes "ci_lab_eds_cc.h") + +endif(CFE_EDS_ENABLED_BUILD) + +# Create wrappers around the all the config header files +# This makes them individually overridable by the missions, without modifying +# the distribution default copies +foreach(CI_LAB_CFGFILE ${CI_LAB_MISSION_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${CI_LAB_CFGFILE}" NAME_WE) + if (DEFINED CI_LAB_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE GENERATED_FILE "${CI_LAB_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${CI_LAB_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${CI_LAB_CFGFILE}" + ${DEFAULT_SOURCE} + ) +endforeach()