From 04e089e48653c4bcb60eb1eb8881a677882895b9 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 25 Oct 2023 09:22:08 -0400 Subject: [PATCH 1/2] Fix #147, reorganize source files Organize source files into a directory and naming pattern that is compliant with the CFE current recommended practice. Configurable items are moved to the respective header files and documentation is added to indicate what they do. --- CMakeLists.txt | 7 +- arch_build.cmake | 27 +++ config/default_ci_lab_fcncodes.h | 41 ++++ config/default_ci_lab_interface_cfg.h | 50 +++++ config/default_ci_lab_internal_cfg.h | 50 +++++ config/default_ci_lab_mission_cfg.h | 36 ++++ config/default_ci_lab_msg.h | 38 ++++ config/default_ci_lab_msgdefs.h | 48 +++++ .../default_ci_lab_msgids.h | 2 +- .../default_ci_lab_msgstruct.h | 55 +++--- .../default_ci_lab_perfids.h | 0 config/default_ci_lab_platform_cfg.h | 41 ++++ .../ci_lab_events.h => inc/ci_lab_eventids.h} | 4 +- fsw/src/ci_lab_app.c | 180 +----------------- fsw/src/ci_lab_app.h | 29 ++- fsw/src/ci_lab_cmds.c | 75 ++++++++ fsw/src/ci_lab_cmds.h | 62 ++++++ fsw/src/ci_lab_dispatch.c | 131 +++++++++++++ fsw/src/ci_lab_dispatch.h | 39 ++++ mission_build.cmake | 46 +++++ 20 files changed, 738 insertions(+), 223 deletions(-) create mode 100644 arch_build.cmake create mode 100644 config/default_ci_lab_fcncodes.h create mode 100644 config/default_ci_lab_interface_cfg.h create mode 100644 config/default_ci_lab_internal_cfg.h create mode 100644 config/default_ci_lab_mission_cfg.h create mode 100644 config/default_ci_lab_msg.h create mode 100644 config/default_ci_lab_msgdefs.h rename fsw/platform_inc/ci_lab_msgids.h => config/default_ci_lab_msgids.h (96%) rename fsw/src/ci_lab_msg.h => config/default_ci_lab_msgstruct.h (69%) rename fsw/mission_inc/ci_lab_perfids.h => config/default_ci_lab_perfids.h (100%) create mode 100644 config/default_ci_lab_platform_cfg.h rename fsw/{src/ci_lab_events.h => inc/ci_lab_eventids.h} (96%) create mode 100644 fsw/src/ci_lab_cmds.c create mode 100644 fsw/src/ci_lab_cmds.h create mode 100644 fsw/src/ci_lab_dispatch.c create mode 100644 fsw/src/ci_lab_dispatch.h create mode 100644 mission_build.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index e4b2e8d..bbcfb05 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,12 +3,11 @@ project(CFS_CI_LAB C) set(APP_SRC_FILES fsw/src/ci_lab_app.c + fsw/src/ci_lab_cmds.c + fsw/src/ci_lab_dispatch.c ) # 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..ac79159 --- /dev/null +++ b/arch_build.cmake @@ -0,0 +1,27 @@ +########################################################### +# +# 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 +) + +# 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}) + generate_config_includefile( + FILE_NAME "${CI_LAB_CFGFILE}" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${CI_LAB_CFGFILE}" + ) +endforeach() diff --git a/config/default_ci_lab_fcncodes.h b/config/default_ci_lab_fcncodes.h new file mode 100644 index 0000000..ad1e543 --- /dev/null +++ b/config/default_ci_lab_fcncodes.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 + * 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 + +#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/config/default_ci_lab_mission_cfg.h b/config/default_ci_lab_mission_cfg.h new file mode 100644 index 0000000..60c0a43 --- /dev/null +++ b/config/default_ci_lab_mission_cfg.h @@ -0,0 +1,36 @@ +/************************************************************************ + * 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 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_MISSION_CFG_H +#define CI_LAB_MISSION_CFG_H + +#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..c3005e6 --- /dev/null +++ b/config/default_ci_lab_msgdefs.h @@ -0,0 +1,48 @@ +/************************************************************************ + * 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/platform_inc/ci_lab_msgids.h b/config/default_ci_lab_msgids.h similarity index 96% rename from fsw/platform_inc/ci_lab_msgids.h rename to config/default_ci_lab_msgids.h index 45bc205..feefb97 100644 --- a/fsw/platform_inc/ci_lab_msgids.h +++ b/config/default_ci_lab_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/fsw/src/ci_lab_msg.h b/config/default_ci_lab_msgstruct.h similarity index 69% rename from fsw/src/ci_lab_msg.h rename to config/default_ci_lab_msgstruct.h index c72335e..9680039 100644 --- a/fsw/src/ci_lab_msg.h +++ b/config/default_ci_lab_msgstruct.h @@ -18,26 +18,28 @@ /** * @file - * Define CI Lab Messages and info + * 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_MSG_H -#define CI_LAB_MSG_H +#ifndef CI_LAB_MSGSTRUCT_H +#define CI_LAB_MSGSTRUCT_H -/* -** CI_LAB command codes -*/ -#define CI_LAB_NOOP_CC 0 -#define CI_LAB_RESET_COUNTERS_CC 1 +/************************************************************************ + * Includes + ************************************************************************/ + +#include "ci_lab_mission_cfg.h" +#include "ci_lab_msgdefs.h" +#include "cfe_msg_hdr.h" /*************************************************************************/ /* ** Type definition (generic "no arguments" command) */ -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeader; - -} CI_LAB_NoArgsCmd_t; /* * Neither the Noop nor ResetCounters command @@ -46,25 +48,20 @@ typedef struct * * This matches the pattern in CFE core and other modules. */ -typedef CI_LAB_NoArgsCmd_t CI_LAB_NoopCmd_t; -typedef CI_LAB_NoArgsCmd_t CI_LAB_ResetCountersCmd_t; +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_NoopCmd_t; -/*************************************************************************/ -/* -** Type definition (CI_LAB housekeeping)... -*/ typedef struct { - uint8 CommandErrorCounter; - uint8 CommandCounter; - uint8 EnableChecksums; - uint8 SocketConnected; - uint8 Spare1[8]; - uint32 IngestPackets; - uint32 IngestErrors; - uint32 Spare2; + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_ResetCountersCmd_t; -} CI_LAB_HkTlm_Payload_t; +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; +} CI_LAB_SendHkCmd_t; typedef struct { @@ -72,4 +69,4 @@ typedef struct CI_LAB_HkTlm_Payload_t Payload; } CI_LAB_HkTlm_t; -#endif +#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/fsw/src/ci_lab_events.h b/fsw/inc/ci_lab_eventids.h similarity index 96% rename from fsw/src/ci_lab_events.h rename to fsw/inc/ci_lab_eventids.h index 6ddf651..7380bd4 100644 --- a/fsw/src/ci_lab_events.h +++ b/fsw/inc/ci_lab_eventids.h @@ -20,8 +20,8 @@ * @file * Define CI Lab Events IDs */ -#ifndef CI_LAB_EVENTS_H -#define CI_LAB_EVENTS_H +#ifndef CI_LAB_EVENTIDS_H +#define CI_LAB_EVENTIDS_H #define CI_LAB_RESERVED_EID 0 #define CI_LAB_SOCKETCREATE_ERR_EID 1 diff --git a/fsw/src/ci_lab_app.c b/fsw/src/ci_lab_app.c index 909c8c8..11c9d0a 100644 --- a/fsw/src/ci_lab_app.c +++ b/fsw/src/ci_lab_app.c @@ -28,42 +28,13 @@ #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" /* ** CI global data... */ - -typedef struct -{ - bool SocketConnected; - CFE_SB_PipeId_t CommandPipe; - osal_id_t SocketID; - OS_SockAddr_t SocketAddress; - - CI_LAB_HkTlm_t HkTlm; - - CFE_SB_Buffer_t *NextIngestBufPtr; - -} CI_LAB_GlobalData_t; - CI_LAB_GlobalData_t CI_LAB_Global; -/* - * Individual message handler function prototypes - * - * Per the recommended code pattern, these should accept a const pointer - * to a structure type which matches the message, and return an int32 - * where CFE_SUCCESS (0) indicates successful handling of the message. - */ -int32 CI_LAB_Noop(const CI_LAB_NoopCmd_t *data); -int32 CI_LAB_ResetCounters(const CI_LAB_ResetCountersCmd_t *data); - -/* Housekeeping message handler */ -int32 CI_LAB_ReportHousekeeping(const CFE_MSG_CommandHeader_t *data); - /** * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* Application entry point and main process loop */ @@ -99,7 +70,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 */ @@ -181,122 +152,6 @@ void CI_LAB_TaskInit(void) CI_LAB_VERSION_STRING); } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* 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_ProcessCommandPacket(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_ReportHousekeeping((const CFE_MSG_CommandHeader_t *)SBBufPtr); - break; - - default: - 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", - (unsigned int)CFE_SB_MsgIdToValue(MsgId)); - break; - } -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* CI ground commands */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ - -void CI_LAB_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_MSG_FcnCode_t CommandCode = 0; - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - - /* Process "known" CI task ground commands */ - switch (CommandCode) - { - case CI_LAB_NOOP_CC: - if (CI_LAB_VerifyCmdLength(&SBBufPtr->Msg, sizeof(CI_LAB_NoopCmd_t))) - { - CI_LAB_Noop((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_ResetCounters((const CI_LAB_ResetCountersCmd_t *)SBBufPtr); - } - break; - - /* default case already found during FC vs length test */ - default: - break; - } -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* 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: */ @@ -375,36 +230,3 @@ void CI_LAB_ReadUpLink(void) } } } - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -/* */ -/* Verify command packet length */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * **/ -bool CI_LAB_VerifyCmdLength(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_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; -} diff --git a/fsw/src/ci_lab_app.h b/fsw/src/ci_lab_app.h index 16e245f..d196a70 100644 --- a/fsw/src/ci_lab_app.h +++ b/fsw/src/ci_lab_app.h @@ -27,9 +27,14 @@ ** 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 #include @@ -37,14 +42,23 @@ /****************************************************************************/ -#define CI_LAB_BASE_UDP_PORT 1234 -#define CI_LAB_MAX_INGEST 768 -#define CI_LAB_PIPE_DEPTH 32 - /************************************************************************ ** Type Definitions *************************************************************************/ +typedef struct +{ + bool SocketConnected; + CFE_SB_PipeId_t CommandPipe; + osal_id_t SocketID; + OS_SockAddr_t SocketAddress; + + CI_LAB_HkTlm_t HkTlm; + + CFE_SB_Buffer_t *NextIngestBufPtr; + +} CI_LAB_GlobalData_t; + /****************************************************************************/ /* ** Local function prototypes... @@ -54,11 +68,10 @@ */ void CI_Lab_AppMain(void); void CI_LAB_TaskInit(void); -void CI_LAB_ProcessCommandPacket(CFE_SB_Buffer_t *SBBufPtr); -void CI_LAB_ProcessGroundCommand(CFE_SB_Buffer_t *SBBufPtr); void CI_LAB_ResetCounters_Internal(void); void CI_LAB_ReadUpLink(void); -bool CI_LAB_VerifyCmdLength(CFE_MSG_Message_t *MsgPtr, size_t ExpectedLength); +/* Global State Object */ +extern CI_LAB_GlobalData_t CI_LAB_Global; #endif diff --git a/fsw/src/ci_lab_cmds.c b/fsw/src/ci_lab_cmds.c new file mode 100644 index 0000000..8910108 --- /dev/null +++ b/fsw/src/ci_lab_cmds.c @@ -0,0 +1,75 @@ +/************************************************************************ + * 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" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* 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_COMMANDNOP_INF_EID, CFE_EVS_EventType_INFORMATION, "CI: NOOP command"); + + 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_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 */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +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_dispatch.c b/fsw/src/ci_lab_dispatch.c new file mode 100644 index 0000000..d242db9 --- /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_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 CommandCode = 0; + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + + /* Process "known" CI task ground commands */ + switch (CommandCode) + { + 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_COMMAND_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/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() From 7d3eca979efaf7880955b87ca746c0b77a31809b Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 30 Oct 2023 12:38:06 -0400 Subject: [PATCH 2/2] Bump to v2.5.0-rc4+dev51 --- CHANGELOG.md | 4 ++++ fsw/src/ci_lab_version.h | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 09f90b3..2895d28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 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/fsw/src/ci_lab_version.h b/fsw/src/ci_lab_version.h index 0ff55d2..c242a62 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 51 /*!< 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 */