diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 611a7d1..b9cc6fb 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -5,7 +5,7 @@ A clear and concise description of what the contribution is. **Testing performed** Steps taken to test the contribution: 1. Build steps '...' -1. Execution steps '...' +2. Execution steps '...' **Expected behavior changes** A clear and concise description of how this contribution will change behavior and level of impact. diff --git a/.github/workflows/codeql-build.yml b/.github/workflows/codeql-build.yml index cb55561..7ddc2e2 100644 --- a/.github/workflows/codeql-build.yml +++ b/.github/workflows/codeql-build.yml @@ -8,7 +8,7 @@ jobs: codeql: name: Codeql uses: nasa/cFS/.github/workflows/codeql-reusable.yml@main - with: + with: component-path: apps/to_lab prep: 'make prep; make -C build/tools/elf2cfetbl' make: 'make -C build/native/default_cpu1/apps/to_lab' diff --git a/CHANGELOG.md b/CHANGELOG.md index ebf354c..d935628 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## Development Build: v2.5.0-rc4+dev66 +- reorganize source files +- Apply consistent Event ID names to common events +- Refactor mutually exclusive logic in if, else if block +- Add check for failure of CFE_EVS_Register() during initialization +- Convert int32 return codes and variables to CFE_Status_t +- Move function prototypes to header file +- Update misnamed CmdHeader variable in to_lab_msg.h +- See , , , , , , and + ## Development Build: v2.5.0-rc4+dev49 - Remove unused/unnecessary TO_LAB_UNUSED - See diff --git a/CMakeLists.txt b/CMakeLists.txt index f3fa9a8..376023f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,13 @@ endforeach() set(APP_SRC_FILES fsw/src/to_lab_app.c + fsw/src/to_lab_cmds.c + fsw/src/to_lab_dispatch.c + fsw/src/to_lab_passthru_encode.c ) # Create the app module add_cfe_app(to_lab ${APP_SRC_FILES}) add_cfe_tables(to_lab fsw/tables/to_lab_sub.c) -target_include_directories(to_lab PUBLIC - fsw/mission_inc - fsw/platform_inc -) +target_include_directories(to_lab PUBLIC fsw/inc) diff --git a/arch_build.cmake b/arch_build.cmake new file mode 100644 index 0000000..306476b --- /dev/null +++ b/arch_build.cmake @@ -0,0 +1,27 @@ +########################################################### +# +# TO_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 TO_LAB configuration +set(TO_LAB_PLATFORM_CONFIG_FILE_LIST + to_lab_internal_cfg.h + to_lab_platform_cfg.h + to_lab_perfids.h + to_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(TO_LAB_CFGFILE ${TO_LAB_PLATFORM_CONFIG_FILE_LIST}) + generate_config_includefile( + FILE_NAME "${TO_LAB_CFGFILE}" + FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${TO_LAB_CFGFILE}" + ) +endforeach() diff --git a/config/default_to_lab_fcncodes.h b/config/default_to_lab_fcncodes.h new file mode 100644 index 0000000..686ab3e --- /dev/null +++ b/config/default_to_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 TO_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 TO_LAB_FCNCODES_H +#define TO_LAB_FCNCODES_H + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/* +** TO_LAB command codes +*/ +#define TO_LAB_NOOP_CC 0 /* no-op command */ +#define TO_LAB_RESET_STATUS_CC 1 /* reset status */ +#define TO_LAB_ADD_PKT_CC 2 /* add packet */ +#define TO_LAB_SEND_DATA_TYPES_CC 3 /* send data types */ +#define TO_LAB_REMOVE_PKT_CC 4 /* remove packet */ +#define TO_LAB_REMOVE_ALL_PKT_CC 5 /* remove all packet */ +#define TO_LAB_OUTPUT_ENABLE_CC 6 /* output enable */ + +#endif diff --git a/config/default_to_lab_interface_cfg.h b/config/default_to_lab_interface_cfg.h new file mode 100644 index 0000000..210bdfd --- /dev/null +++ b/config/default_to_lab_interface_cfg.h @@ -0,0 +1,45 @@ +/************************************************************************ + * 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 + * TO_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 TO_LAB_INTERFACE_CFG_H +#define TO_LAB_INTERFACE_CFG_H + +/** + * @brief The base UDP port number that TO_LAB will send to + */ +#define TO_LAB_TLM_PORT 1235 + +/** + * @brief The maximum number of subscriptions that TO_LAB can subscribe to + */ +#define TO_LAB_MAX_SUBSCRIPTIONS 32 + +#endif diff --git a/config/default_to_lab_internal_cfg.h b/config/default_to_lab_internal_cfg.h new file mode 100644 index 0000000..99f7e68 --- /dev/null +++ b/config/default_to_lab_internal_cfg.h @@ -0,0 +1,49 @@ +/************************************************************************ + * 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 + * TO_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 TO_LAB_INTERNAL_CFG_H +#define TO_LAB_INTERNAL_CFG_H + +/*****************************************************************************/ + +#define TO_LAB_TASK_MSEC 500 /* run at 2 Hz */ + +/** + * Depth of pipe for commands to the TO_LAB application itself + */ +#define TO_LAB_CMD_PIPE_DEPTH 8 + +/** + * Depth of pipe for telemetry forwarded through the TO_LAB application + */ +#define TO_LAB_TLM_PIPE_DEPTH OS_QUEUE_MAX_DEPTH + +#endif diff --git a/config/default_to_lab_mission_cfg.h b/config/default_to_lab_mission_cfg.h new file mode 100644 index 0000000..2a1b0f7 --- /dev/null +++ b/config/default_to_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 + * + * TO_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 TO_LAB_MISSION_CFG_H +#define TO_LAB_MISSION_CFG_H + +#include "to_lab_interface_cfg.h" + +#endif diff --git a/config/default_to_lab_msg.h b/config/default_to_lab_msg.h new file mode 100644 index 0000000..3f4999d --- /dev/null +++ b/config/default_to_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 TO_LAB command and telemetry + * message data types. + * + * This is a compatibility header for the "to_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 TO_LAB_MSG_H +#define TO_LAB_MSG_H + +#include "to_lab_interface_cfg.h" +#include "to_lab_msgdefs.h" +#include "to_lab_msgstruct.h" + +#endif diff --git a/config/default_to_lab_msgdefs.h b/config/default_to_lab_msgdefs.h new file mode 100644 index 0000000..b614eb7 --- /dev/null +++ b/config/default_to_lab_msgdefs.h @@ -0,0 +1,69 @@ +/************************************************************************ + * 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 TO_LAB command and telemetry + * message constant definitions. + * + * For TO_LAB this is only the function/command code definitions + */ +#ifndef TO_LAB_MSGDEFS_H +#define TO_LAB_MSGDEFS_H + +#include "common_types.h" +#include "cfe_sb_extern_typedefs.h" +#include "to_lab_fcncodes.h" + +typedef struct +{ + uint8 CommandCounter; + uint8 CommandErrorCounter; + uint8 spareToAlign[2]; +} TO_LAB_HkTlm_Payload_t; + +typedef struct +{ + uint16 synch; + uint8 bl1, bl2; /* boolean */ + int8 b1, b2, b3, b4; + int16 w1, w2; + int32 dw1, dw2; + float f1, f2; + double df1, df2; + char str[10]; +} TO_LAB_DataTypes_Payload_t; + +typedef struct +{ + CFE_SB_MsgId_t Stream; + CFE_SB_Qos_t Flags; + uint8 BufLimit; +} TO_LAB_AddPacket_Payload_t; + +typedef struct +{ + CFE_SB_MsgId_t Stream; +} TO_LAB_RemovePacket_Payload_t; + +typedef struct +{ + char dest_IP[16]; +} TO_LAB_EnableOutput_Payload_t; + +#endif diff --git a/fsw/platform_inc/to_lab_msgids.h b/config/default_to_lab_msgids.h similarity index 97% rename from fsw/platform_inc/to_lab_msgids.h rename to config/default_to_lab_msgids.h index 4c3609c..1efc360 100644 --- a/fsw/platform_inc/to_lab_msgids.h +++ b/config/default_to_lab_msgids.h @@ -18,7 +18,7 @@ /** * @file - * Define TO Lab Message IDs + * TO_LAB Application Message IDs */ #ifndef TO_LAB_MSGIDS_H #define TO_LAB_MSGIDS_H diff --git a/config/default_to_lab_msgstruct.h b/config/default_to_lab_msgstruct.h new file mode 100644 index 0000000..1550186 --- /dev/null +++ b/config/default_to_lab_msgstruct.h @@ -0,0 +1,107 @@ +/************************************************************************ + * 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 TO_LAB command and telemetry + * message data types. + * + * @note + * Constants and enumerated types related to these message structures + * are defined in to_lab_msgdefs.h. + */ +#ifndef TO_LAB_MSGSTRUCT_H +#define TO_LAB_MSGSTRUCT_H + +/************************************************************************ + * Includes + ************************************************************************/ + +#include "to_lab_mission_cfg.h" +#include "to_lab_msgdefs.h" +#include "cfe_msg_hdr.h" + +/******************************************************************************/ + +typedef struct +{ + CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry header */ + TO_LAB_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */ +} TO_LAB_HkTlm_t; + +/******************************************************************************/ + +typedef struct +{ + CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry header */ + TO_LAB_DataTypes_Payload_t Payload; /**< \brief Telemetry payload */ +} TO_LAB_DataTypesTlm_t; + +/******************************************************************************/ + +/* + * The following commands do not 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; /**< \brief Command header */ +} TO_LAB_SendHkCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} TO_LAB_NoopCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} TO_LAB_ResetCountersCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} TO_LAB_RemoveAllCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ +} TO_LAB_SendDataTypesCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ + TO_LAB_AddPacket_Payload_t Payload; /**< \brief Command payload */ +} TO_LAB_AddPacketCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ + TO_LAB_RemovePacket_Payload_t Payload; /**< \brief Command payload */ +} TO_LAB_RemovePacketCmd_t; + +typedef struct +{ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ + TO_LAB_EnableOutput_Payload_t Payload; /**< \brief Command payload */ +} TO_LAB_EnableOutputCmd_t; + +#endif /* TO_LAB_MSGSTRUCT_H */ diff --git a/fsw/mission_inc/to_lab_perfids.h b/config/default_to_lab_perfids.h similarity index 100% rename from fsw/mission_inc/to_lab_perfids.h rename to config/default_to_lab_perfids.h diff --git a/config/default_to_lab_platform_cfg.h b/config/default_to_lab_platform_cfg.h new file mode 100644 index 0000000..0e16e5f --- /dev/null +++ b/config/default_to_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 + * + * TO_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 TO_LAB_PLATFORM_CFG_H +#define TO_LAB_PLATFORM_CFG_H + +#include "to_lab_mission_cfg.h" +#include "to_lab_internal_cfg.h" + +#endif diff --git a/config/default_to_lab_tbl.h b/config/default_to_lab_tbl.h new file mode 100644 index 0000000..521116a --- /dev/null +++ b/config/default_to_lab_tbl.h @@ -0,0 +1,33 @@ +/************************************************************************ + * 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 TO_LAB table structures + * + * @note + * Constants and enumerated types related to these table structures + * are defined in to_lab_tbldefs.h. + */ +#ifndef TO_LAB_TBL_H +#define TO_LAB_TBL_H + +#include "to_lab_tbldefs.h" +#include "to_lab_tblstruct.h" + +#endif diff --git a/config/default_to_lab_tbldefs.h b/config/default_to_lab_tbldefs.h new file mode 100644 index 0000000..4aa1510 --- /dev/null +++ b/config/default_to_lab_tbldefs.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 TO_LAB table related + * constant definitions. + * + * @note + * These Macro definitions have been put in this file (instead of + * to_lab_tbl.h). DO NOT PUT ANY TYPEDEFS OR + * STRUCTURE DEFINITIONS IN THIS FILE! + * ADD THEM TO to_lab_tbl.h IF NEEDED! + */ +#ifndef TO_LAB_TBLDEFS_H +#define TO_LAB_TBLDEFS_H + +#include "common_types.h" +#include "to_lab_mission_cfg.h" +#include "cfe_sb_extern_typedefs.h" + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +typedef struct +{ + CFE_SB_MsgId_t Stream; + CFE_SB_Qos_t Flags; + uint16 BufLimit; +} TO_LAB_Sub_t; + +#endif diff --git a/config/default_to_lab_tblstruct.h b/config/default_to_lab_tblstruct.h new file mode 100644 index 0000000..17e3ba1 --- /dev/null +++ b/config/default_to_lab_tblstruct.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 + * Specification for the TO_LAB table structures + * + * Provides default definitions for TO_LAB table structures + * + * @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 TO_LAB_TBLSTRUCT_H +#define TO_LAB_TBLSTRUCT_H + +/************************************************************************* + * Includes + *************************************************************************/ +#include "to_lab_tbldefs.h" + +/************************************************************************ + * Macro Definitions + ************************************************************************/ + +/************************************************************************* + * Type Definitions + *************************************************************************/ + +typedef struct +{ + TO_LAB_Sub_t Subs[TO_LAB_MAX_SUBSCRIPTIONS]; +} TO_LAB_Subs_t; + +#endif diff --git a/fsw/src/to_lab_events.h b/fsw/inc/to_lab_eventids.h similarity index 91% rename from fsw/src/to_lab_events.h rename to fsw/inc/to_lab_eventids.h index 44369fa..ddf3dde 100644 --- a/fsw/src/to_lab_events.h +++ b/fsw/inc/to_lab_eventids.h @@ -20,8 +20,8 @@ * @file * Define TO Lab Event messages */ -#ifndef TO_LAB_EVENTS_H -#define TO_LAB_EVENTS_H +#ifndef TO_LAB_EVENTIDS_H +#define TO_LAB_EVENTIDS_H /*****************************************************************************/ @@ -29,13 +29,13 @@ #define TO_LAB_EVM_RESERVED 0 #define TO_LAB_INIT_INF_EID 1 -#define TO_LAB_CRCMDPIPE_ERR_EID 2 +#define TO_LAB_CR_PIPE_ERR_EID 2 #define TO_LAB_TLMOUTENA_INF_EID 3 #define TO_LAB_SUBSCRIBE_ERR_EID 4 #define TO_LAB_TLMPIPE_ERR_EID 5 #define TO_LAB_TLMOUTSOCKET_ERR_EID 6 #define TO_LAB_TLMOUTSTOP_ERR_EID 7 -#define TO_LAB_MSGID_ERR_EID 8 +#define TO_LAB_MID_ERR_EID 8 #define TO_LAB_FNCODE_ERR_EID 9 #define TO_LAB_ADDPKT_ERR_EID 10 #define TO_LAB_REMOVEPKT_ERR_EID 11 @@ -45,6 +45,7 @@ #define TO_LAB_REMOVEALLPKTS_INF_EID 17 #define TO_LAB_NOOP_INF_EID 18 #define TO_LAB_TBL_ERR_EID 19 +#define TO_LAB_ENCODE_ERR_EID 20 /******************************************************************************/ diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 7a47b7e..d1fb0fd 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -21,56 +21,22 @@ * This file contains the source code for the TO lab application */ +#include "cfe.h" + #include "to_lab_app.h" -#include "to_lab_msg.h" -#include "to_lab_events.h" +#include "to_lab_encode.h" +#include "to_lab_eventids.h" #include "to_lab_msgids.h" #include "to_lab_perfids.h" #include "to_lab_version.h" -#include "to_lab_sub_table.h" +#include "to_lab_msg.h" +#include "to_lab_tbl.h" /* -** Global Data Section +** TO Global Data Section */ -typedef struct -{ - CFE_SB_PipeId_t Tlm_pipe; - CFE_SB_PipeId_t Cmd_pipe; - osal_id_t TLMsockid; - bool downlink_on; - char tlm_dest_IP[17]; - bool suppress_sendto; - - TO_LAB_HkTlm_t HkTlm; - TO_LAB_DataTypesTlm_t DataTypesTlm; -} TO_LAB_GlobalData_t; - TO_LAB_GlobalData_t TO_LAB_Global; -TO_LAB_Subs_t * TO_LAB_Subs; -CFE_TBL_Handle_t TO_SubTblHandle; - -/* -** Prototypes Section -*/ -void TO_LAB_openTLM(void); -int32 TO_LAB_init(void); -void TO_LAB_exec_local_command(CFE_SB_Buffer_t *SBBufPtr); -void TO_LAB_process_commands(void); -void TO_LAB_forward_telemetry(void); - -/* - * Individual Command Handler prototypes - */ -int32 TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data); -int32 TO_LAB_Noop(const TO_LAB_NoopCmd_t *data); -int32 TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data); -int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data); -int32 TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data); -int32 TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data); -int32 TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data); -int32 TO_LAB_SendHousekeeping(const CFE_MSG_CommandHeader_t *data); - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* TO_LAB_AppMain() -- Application entry point and main process loop */ @@ -78,8 +44,8 @@ int32 TO_LAB_SendHousekeeping(const CFE_MSG_CommandHeader_t *data); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ void TO_LAB_AppMain(void) { - uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; - int32 status; + uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; + CFE_Status_t status; CFE_ES_PerfLogEntry(TO_LAB_MAIN_TASK_PERF_ID); @@ -128,14 +94,16 @@ void TO_LAB_delete_callback(void) /* TO_LAB_init() -- TO initialization */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_init(void) +CFE_Status_t TO_LAB_init(void) { - int32 status; - char PipeName[16]; - uint16 PipeDepth; - uint16 i; - char ToTlmPipeName[16]; - uint16 ToTlmPipeDepth; + CFE_Status_t status; + char PipeName[16]; + uint16 PipeDepth; + uint16 i; + char ToTlmPipeName[16]; + uint16 ToTlmPipeDepth; + void * TblPtr; + TO_LAB_Sub_t *SubEntry; TO_LAB_Global.downlink_on = false; PipeDepth = TO_LAB_CMD_PIPE_DEPTH; @@ -146,14 +114,21 @@ int32 TO_LAB_init(void) /* ** Register with EVS */ - 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("TO_LAB: Error registering for Event Services, RC = 0x%08X\n", (unsigned int)status); + return status; + } + /* ** Initialize housekeeping packet (clear user data area)... */ CFE_MSG_Init(CFE_MSG_PTR(TO_LAB_Global.HkTlm.TelemetryHeader), CFE_SB_ValueToMsgId(TO_LAB_HK_TLM_MID), sizeof(TO_LAB_Global.HkTlm)); - status = CFE_TBL_Register(&TO_SubTblHandle, "TO_LAB_Subs", sizeof(*TO_LAB_Subs), CFE_TBL_OPT_DEFAULT, NULL); + status = + CFE_TBL_Register(&TO_LAB_Global.SubsTblHandle, "TO_LAB_Subs", sizeof(TO_LAB_Subs_t), CFE_TBL_OPT_DEFAULT, NULL); if (status != CFE_SUCCESS) { @@ -162,7 +137,7 @@ int32 TO_LAB_init(void) return status; } - status = CFE_TBL_Load(TO_SubTblHandle, CFE_TBL_SRC_FILE, "/cf/to_lab_sub.tbl"); + status = CFE_TBL_Load(TO_LAB_Global.SubsTblHandle, CFE_TBL_SRC_FILE, "/cf/to_lab_sub.tbl"); if (status != CFE_SUCCESS) { @@ -171,7 +146,7 @@ int32 TO_LAB_init(void) return status; } - status = CFE_TBL_GetAddress((void *)&TO_LAB_Subs, TO_SubTblHandle); + status = CFE_TBL_GetAddress((void **)&TblPtr, TO_LAB_Global.SubsTblHandle); if (status != CFE_SUCCESS && status != CFE_TBL_INFO_UPDATED) { @@ -180,6 +155,8 @@ int32 TO_LAB_init(void) return status; } + TO_LAB_Global.SubsTblPtr = TblPtr; /* Save returned address */ + /* Subscribe to my commands */ status = CFE_SB_CreatePipe(&TO_LAB_Global.Cmd_pipe, PipeDepth, PipeName); if (status == CFE_SUCCESS) @@ -188,7 +165,7 @@ int32 TO_LAB_init(void) CFE_SB_Subscribe(CFE_SB_ValueToMsgId(TO_LAB_SEND_HK_MID), TO_LAB_Global.Cmd_pipe); } else - CFE_EVS_SendEvent(TO_LAB_CRCMDPIPE_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't create cmd pipe status %i", + CFE_EVS_SendEvent(TO_LAB_CR_PIPE_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't create cmd pipe status %i", __LINE__, (int)status); /* Create TO TLM pipe */ @@ -200,23 +177,24 @@ int32 TO_LAB_init(void) } /* Subscriptions for TLM pipe*/ - for (i = 0; (i < (sizeof(TO_LAB_Subs->Subs) / sizeof(TO_LAB_Subs->Subs[0]))); i++) + SubEntry = TO_LAB_Global.SubsTblPtr->Subs; + for (i = 0; i < TO_LAB_MAX_SUBSCRIPTIONS; i++) { - if (!CFE_SB_IsValidMsgId(TO_LAB_Subs->Subs[i].Stream)) + if (!CFE_SB_IsValidMsgId(SubEntry->Stream)) { /* Only process until invalid MsgId is found*/ break; } - else if (CFE_SB_IsValidMsgId(TO_LAB_Subs->Subs[i].Stream)) - { - status = CFE_SB_SubscribeEx(TO_LAB_Subs->Subs[i].Stream, TO_LAB_Global.Tlm_pipe, TO_LAB_Subs->Subs[i].Flags, - TO_LAB_Subs->Subs[i].BufLimit); - } + status = CFE_SB_SubscribeEx(SubEntry->Stream, TO_LAB_Global.Tlm_pipe, SubEntry->Flags, SubEntry->BufLimit); if (status != CFE_SUCCESS) + { CFE_EVS_SendEvent(TO_LAB_SUBSCRIBE_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't subscribe to stream 0x%x status %i", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(TO_LAB_Subs->Subs[i].Stream), (int)status); + (unsigned int)CFE_SB_MsgIdToValue(SubEntry->Stream), (int)status); + } + + ++SubEntry; } /* @@ -230,31 +208,6 @@ int32 TO_LAB_init(void) return CFE_SUCCESS; } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_EnableOutput() -- TLM output enabled */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data) -{ - const TO_LAB_EnableOutput_Payload_t *pCmd = &data->Payload; - - (void)CFE_SB_MessageStringGet(TO_LAB_Global.tlm_dest_IP, pCmd->dest_IP, "", sizeof(TO_LAB_Global.tlm_dest_IP), - sizeof(pCmd->dest_IP)); - TO_LAB_Global.suppress_sendto = false; - CFE_EVS_SendEvent(TO_LAB_TLMOUTENA_INF_EID, CFE_EVS_EventType_INFORMATION, "TO telemetry output enabled for IP %s", - TO_LAB_Global.tlm_dest_IP); - - if (!TO_LAB_Global.downlink_on) /* Then turn it on, otherwise we will just switch destination addresses*/ - { - TO_LAB_openTLM(); - TO_LAB_Global.downlink_on = true; - } - - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* TO_LAB_process_commands() -- Process command pipe message */ @@ -263,177 +216,21 @@ int32 TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data) void TO_LAB_process_commands(void) { CFE_SB_Buffer_t *SBBufPtr; - CFE_SB_MsgId_t MsgId = CFE_SB_INVALID_MSG_ID; + CFE_Status_t Status; + /* Exit command processing loop if no message received. */ while (1) { - switch (CFE_SB_ReceiveBuffer(&SBBufPtr, TO_LAB_Global.Cmd_pipe, CFE_SB_POLL)) + Status = CFE_SB_ReceiveBuffer(&SBBufPtr, TO_LAB_Global.Cmd_pipe, CFE_SB_POLL); + if (Status != CFE_SUCCESS) { - case CFE_SUCCESS: - - CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); - - /* For SB return statuses that imply a message: process it. */ - switch (CFE_SB_MsgIdToValue(MsgId)) - { - case TO_LAB_CMD_MID: - TO_LAB_exec_local_command(SBBufPtr); - break; - - case TO_LAB_SEND_HK_MID: - TO_LAB_SendHousekeeping((const CFE_MSG_CommandHeader_t *)SBBufPtr); - break; - - default: - CFE_EVS_SendEvent(TO_LAB_MSGID_ERR_EID, CFE_EVS_EventType_ERROR, - "L%d TO: Invalid Msg ID Rcvd 0x%x", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(MsgId)); - break; - } - break; - default: - /* Exit command processing loop if no message received. */ - return; - } - } -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_exec_local_command() -- Process local message */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void TO_LAB_exec_local_command(CFE_SB_Buffer_t *SBBufPtr) -{ - CFE_MSG_FcnCode_t CommandCode = 0; - - CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); - - switch (CommandCode) - { - case TO_LAB_NOOP_CC: - TO_LAB_Noop((const TO_LAB_NoopCmd_t *)SBBufPtr); - break; - - case TO_LAB_RESET_STATUS_CC: - TO_LAB_ResetCounters((const TO_LAB_ResetCountersCmd_t *)SBBufPtr); - break; - - case TO_LAB_SEND_DATA_TYPES_CC: - TO_LAB_SendDataTypes((const TO_LAB_SendDataTypesCmd_t *)SBBufPtr); - break; - - case TO_LAB_ADD_PKT_CC: - TO_LAB_AddPacket((const TO_LAB_AddPacketCmd_t *)SBBufPtr); - break; - - case TO_LAB_REMOVE_PKT_CC: - TO_LAB_RemovePacket((const TO_LAB_RemovePacketCmd_t *)SBBufPtr); - break; - - case TO_LAB_REMOVE_ALL_PKT_CC: - TO_LAB_RemoveAll((const TO_LAB_RemoveAllCmd_t *)SBBufPtr); - break; - - case TO_LAB_OUTPUT_ENABLE_CC: - TO_LAB_EnableOutput((const TO_LAB_EnableOutputCmd_t *)SBBufPtr); break; + } - default: - CFE_EVS_SendEvent(TO_LAB_FNCODE_ERR_EID, CFE_EVS_EventType_ERROR, - "L%d TO: Invalid Function Code Rcvd In Ground Command 0x%x", __LINE__, - (unsigned int)CommandCode); - ++TO_LAB_Global.HkTlm.Payload.CommandErrorCounter; + TO_LAB_TaskPipe(SBBufPtr); } } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_Noop() -- Noop Handler */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_Noop(const TO_LAB_NoopCmd_t *data) -{ - CFE_EVS_SendEvent(TO_LAB_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command"); - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_ResetCounters() -- Reset counters */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data) -{ - TO_LAB_Global.HkTlm.Payload.CommandErrorCounter = 0; - TO_LAB_Global.HkTlm.Payload.CommandCounter = 0; - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_SendDataTypes() -- Output data types */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data) -{ - int16 i; - char string_variable[10] = "ABCDEFGHIJ"; - - /* initialize data types packet */ - CFE_MSG_Init(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader), CFE_SB_ValueToMsgId(TO_LAB_DATA_TYPES_MID), - sizeof(TO_LAB_Global.DataTypesTlm)); - - CFE_SB_TimeStampMsg(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader)); - - /* initialize the packet data */ - TO_LAB_Global.DataTypesTlm.Payload.synch = 0x6969; -#if 0 - TO_LAB_Global.DataTypesTlm.Payload.bit1 = 1; - TO_LAB_Global.DataTypesTlm.Payload.bit2 = 0; - TO_LAB_Global.DataTypesTlm.Payload.bit34 = 2; - TO_LAB_Global.DataTypesTlm.Payload.bit56 = 3; - TO_LAB_Global.DataTypesTlm.Payload.bit78 = 1; - TO_LAB_Global.DataTypesTlm.Payload.nibble1 = 0xA; - TO_LAB_Global.DataTypesTlm.Payload.nibble2 = 0x4; -#endif - TO_LAB_Global.DataTypesTlm.Payload.bl1 = false; - TO_LAB_Global.DataTypesTlm.Payload.bl2 = true; - TO_LAB_Global.DataTypesTlm.Payload.b1 = 16; - TO_LAB_Global.DataTypesTlm.Payload.b2 = 127; - TO_LAB_Global.DataTypesTlm.Payload.b3 = 0x7F; - TO_LAB_Global.DataTypesTlm.Payload.b4 = 0x45; - TO_LAB_Global.DataTypesTlm.Payload.w1 = 0x2468; - TO_LAB_Global.DataTypesTlm.Payload.w2 = 0x7FFF; - TO_LAB_Global.DataTypesTlm.Payload.dw1 = 0x12345678; - TO_LAB_Global.DataTypesTlm.Payload.dw2 = 0x87654321; - TO_LAB_Global.DataTypesTlm.Payload.f1 = 90.01; - TO_LAB_Global.DataTypesTlm.Payload.f2 = .0000045; - TO_LAB_Global.DataTypesTlm.Payload.df1 = 99.9; - TO_LAB_Global.DataTypesTlm.Payload.df2 = .4444; - - for (i = 0; i < 10; i++) - TO_LAB_Global.DataTypesTlm.Payload.str[i] = string_variable[i]; - - CFE_SB_TransmitMsg(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader), true); - - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_SendHousekeeping() -- HK status */ -/* Does not increment CommandCounter */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_SendHousekeeping(const CFE_MSG_CommandHeader_t *data) -{ - CFE_SB_TimeStampMsg(CFE_MSG_PTR(TO_LAB_Global.HkTlm.TelemetryHeader)); - CFE_SB_TransmitMsg(CFE_MSG_PTR(TO_LAB_Global.HkTlm.TelemetryHeader), true); - return CFE_SUCCESS; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* TO_LAB_openTLM() -- Open TLM */ @@ -453,83 +250,6 @@ void TO_LAB_openTLM(void) /*---------------- Add static arp entries ----------------*/ } -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_AddPacket() -- Add packets */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data) -{ - const TO_LAB_AddPacket_Payload_t *pCmd = &data->Payload; - int32 status; - - status = CFE_SB_SubscribeEx(pCmd->Stream, TO_LAB_Global.Tlm_pipe, pCmd->Flags, pCmd->BufLimit); - - if (status != CFE_SUCCESS) - CFE_EVS_SendEvent(TO_LAB_ADDPKT_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't subscribe 0x%x status %i", - __LINE__, (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), (int)status); - else - CFE_EVS_SendEvent(TO_LAB_ADDPKT_INF_EID, CFE_EVS_EventType_INFORMATION, - "L%d TO AddPkt 0x%x, QoS %d.%d, limit %d", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), pCmd->Flags.Priority, - pCmd->Flags.Reliability, pCmd->BufLimit); - - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_RemovePacket() -- Remove Packet */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data) -{ - const TO_LAB_RemovePacket_Payload_t *pCmd = &data->Payload; - int32 status; - - status = CFE_SB_Unsubscribe(pCmd->Stream, TO_LAB_Global.Tlm_pipe); - if (status != CFE_SUCCESS) - CFE_EVS_SendEvent(TO_LAB_REMOVEPKT_ERR_EID, CFE_EVS_EventType_ERROR, - "L%d TO Can't Unsubscribe to Stream 0x%x, status %i", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), (int)status); - else - CFE_EVS_SendEvent(TO_LAB_REMOVEPKT_INF_EID, CFE_EVS_EventType_INFORMATION, "L%d TO RemovePkt 0x%x", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream)); - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -/* */ -/* TO_LAB_RemoveAll() -- Remove All Packets */ -/* */ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data) -{ - int32 status; - int i; - - for (i = 0; (i < (sizeof(TO_LAB_Subs->Subs) / sizeof(TO_LAB_Subs->Subs[0]))); i++) - { - if (CFE_SB_IsValidMsgId(TO_LAB_Subs->Subs[i].Stream)) - { - status = CFE_SB_Unsubscribe(TO_LAB_Subs->Subs[i].Stream, TO_LAB_Global.Tlm_pipe); - - if (status != CFE_SUCCESS) - CFE_EVS_SendEvent(TO_LAB_REMOVEALLPTKS_ERR_EID, CFE_EVS_EventType_ERROR, - "L%d TO Can't Unsubscribe to stream 0x%x status %i", __LINE__, - (unsigned int)CFE_SB_MsgIdToValue(TO_LAB_Subs->Subs[i].Stream), (int)status); - } - } - - CFE_EVS_SendEvent(TO_LAB_REMOVEALLPKTS_INF_EID, CFE_EVS_EventType_INFORMATION, - "L%d TO Unsubscribed to all Commands and Telemetry", __LINE__); - - ++TO_LAB_Global.HkTlm.Payload.CommandCounter; - return CFE_SUCCESS; -} - /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ /* TO_LAB_forward_telemetry() -- Forward telemetry */ @@ -538,45 +258,53 @@ int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data) void TO_LAB_forward_telemetry(void) { OS_SockAddr_t d_addr; - int32 status; - int32 CFE_SB_status; - size_t size; + int32 OsStatus; + CFE_Status_t CfeStatus; CFE_SB_Buffer_t *SBBufPtr; + const void * NetBufPtr; + size_t NetBufSize; OS_SocketAddrInit(&d_addr, OS_SocketDomain_INET); - OS_SocketAddrSetPort(&d_addr, cfgTLM_PORT); + OS_SocketAddrSetPort(&d_addr, TO_LAB_TLM_PORT); OS_SocketAddrFromString(&d_addr, TO_LAB_Global.tlm_dest_IP); - status = 0; + OsStatus = 0; do { - CFE_SB_status = CFE_SB_ReceiveBuffer(&SBBufPtr, TO_LAB_Global.Tlm_pipe, CFE_SB_POLL); + CfeStatus = CFE_SB_ReceiveBuffer(&SBBufPtr, TO_LAB_Global.Tlm_pipe, CFE_SB_POLL); - if ((CFE_SB_status == CFE_SUCCESS) && (TO_LAB_Global.suppress_sendto == false)) + if ((CfeStatus == CFE_SUCCESS) && (TO_LAB_Global.suppress_sendto == false)) { - CFE_MSG_GetSize(&SBBufPtr->Msg, &size); + OsStatus = OS_SUCCESS; if (TO_LAB_Global.downlink_on == true) { CFE_ES_PerfLogEntry(TO_LAB_SOCKET_SEND_PERF_ID); - status = OS_SocketSendTo(TO_LAB_Global.TLMsockid, SBBufPtr, size, &d_addr); + CfeStatus = TO_LAB_EncodeOutputMessage(SBBufPtr, &NetBufPtr, &NetBufSize); + + if (CfeStatus != CFE_SUCCESS) + { + CFE_EVS_SendEvent(TO_LAB_ENCODE_ERR_EID, CFE_EVS_EventType_ERROR, "Error packing output: %d\n", + (int)CfeStatus); + } + else + { + OsStatus = OS_SocketSendTo(TO_LAB_Global.TLMsockid, NetBufPtr, NetBufSize, &d_addr); + } CFE_ES_PerfLogExit(TO_LAB_SOCKET_SEND_PERF_ID); } - else - { - status = 0; - } - if (status < 0) + + if (OsStatus < 0) { CFE_EVS_SendEvent(TO_LAB_TLMOUTSTOP_ERR_EID, CFE_EVS_EventType_ERROR, - "L%d TO sendto error %d. Tlm output suppressed\n", __LINE__, (int)status); + "L%d TO sendto error %d. Tlm output suppressed\n", __LINE__, (int)OsStatus); TO_LAB_Global.suppress_sendto = true; } } /* If CFE_SB_status != CFE_SUCCESS, then no packet was received from CFE_SB_ReceiveBuffer() */ - } while (CFE_SB_status == CFE_SUCCESS); + } while (CfeStatus == CFE_SUCCESS); } /************************/ diff --git a/fsw/src/to_lab_app.h b/fsw/src/to_lab_app.h index 4cfb2b1..30c7e34 100644 --- a/fsw/src/to_lab_app.h +++ b/fsw/src/to_lab_app.h @@ -24,40 +24,54 @@ #ifndef TO_LAB_APP_H #define TO_LAB_APP_H -#include "cfe.h" - -#include -#include -#include - #include "common_types.h" #include "osapi.h" +#include "cfe.h" -/*****************************************************************************/ +#include "to_lab_mission_cfg.h" +#include "to_lab_platform_cfg.h" +#include "to_lab_cmds.h" +#include "to_lab_dispatch.h" +#include "to_lab_msg.h" +#include "to_lab_tbl.h" -#define TO_LAB_TASK_MSEC 500 /* run at 2 Hz */ +/************************************************************************ +** Type Definitions +*************************************************************************/ /** - * Depth of pipe for commands to the TO_LAB application itself + * CI global data structure */ -#define TO_LAB_CMD_PIPE_DEPTH 8 +typedef struct +{ + CFE_SB_PipeId_t Tlm_pipe; + CFE_SB_PipeId_t Cmd_pipe; + osal_id_t TLMsockid; + bool downlink_on; + char tlm_dest_IP[17]; + bool suppress_sendto; -/** - * Depth of pipe for telemetry forwarded through the TO_LAB application - */ -#define TO_LAB_TLM_PIPE_DEPTH OS_QUEUE_MAX_DEPTH + TO_LAB_HkTlm_t HkTlm; + TO_LAB_DataTypesTlm_t DataTypesTlm; -#define cfgTLM_ADDR "192.168.1.81" -#define cfgTLM_PORT 1235 -#define TO_LAB_VERSION_NUM "5.1.0" + TO_LAB_Subs_t * SubsTblPtr; + CFE_TBL_Handle_t SubsTblHandle; -/******************************************************************************/ +} TO_LAB_GlobalData_t; + +/************************************************************************ + * Function Prototypes + ************************************************************************/ -/* -** Prototypes Section -*/ -void TO_LAB_AppMain(void); +void TO_LAB_AppMain(void); +void TO_LAB_openTLM(void); +int32 TO_LAB_init(void); +void TO_LAB_process_commands(void); +void TO_LAB_forward_telemetry(void); /******************************************************************************/ +/* Global State Object */ +extern TO_LAB_GlobalData_t TO_LAB_Global; + #endif diff --git a/fsw/src/to_lab_cmds.c b/fsw/src/to_lab_cmds.c new file mode 100644 index 0000000..980d7d7 --- /dev/null +++ b/fsw/src/to_lab_cmds.c @@ -0,0 +1,221 @@ +/************************************************************************ + * 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 TO lab application + */ + +#include "cfe.h" + +#include "to_lab_app.h" +#include "to_lab_cmds.h" +#include "to_lab_msg.h" +#include "to_lab_eventids.h" +#include "to_lab_msgids.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_EnableOutput() -- TLM output enabled */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_EnableOutputCmd(const TO_LAB_EnableOutputCmd_t *data) +{ + const TO_LAB_EnableOutput_Payload_t *pCmd = &data->Payload; + + (void)CFE_SB_MessageStringGet(TO_LAB_Global.tlm_dest_IP, pCmd->dest_IP, "", sizeof(TO_LAB_Global.tlm_dest_IP), + sizeof(pCmd->dest_IP)); + TO_LAB_Global.suppress_sendto = false; + CFE_EVS_SendEvent(TO_LAB_TLMOUTENA_INF_EID, CFE_EVS_EventType_INFORMATION, "TO telemetry output enabled for IP %s", + TO_LAB_Global.tlm_dest_IP); + + if (!TO_LAB_Global.downlink_on) /* Then turn it on, otherwise we will just switch destination addresses*/ + { + TO_LAB_openTLM(); + TO_LAB_Global.downlink_on = true; + } + + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_Noop() -- Noop Handler */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_NoopCmd(const TO_LAB_NoopCmd_t *data) +{ + CFE_EVS_SendEvent(TO_LAB_NOOP_INF_EID, CFE_EVS_EventType_INFORMATION, "No-op command"); + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_ResetCounters() -- Reset counters */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_ResetCountersCmd(const TO_LAB_ResetCountersCmd_t *data) +{ + TO_LAB_Global.HkTlm.Payload.CommandErrorCounter = 0; + TO_LAB_Global.HkTlm.Payload.CommandCounter = 0; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_SendDataTypes() -- Output data types */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_SendDataTypesCmd(const TO_LAB_SendDataTypesCmd_t *data) +{ + int16 i; + char string_variable[10] = "ABCDEFGHIJ"; + + /* initialize data types packet */ + CFE_MSG_Init(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader), CFE_SB_ValueToMsgId(TO_LAB_DATA_TYPES_MID), + sizeof(TO_LAB_Global.DataTypesTlm)); + + CFE_SB_TimeStampMsg(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader)); + + /* initialize the packet data */ + TO_LAB_Global.DataTypesTlm.Payload.synch = 0x6969; +#if 0 + TO_LAB_Global.DataTypesTlm.Payload.bit1 = 1; + TO_LAB_Global.DataTypesTlm.Payload.bit2 = 0; + TO_LAB_Global.DataTypesTlm.Payload.bit34 = 2; + TO_LAB_Global.DataTypesTlm.Payload.bit56 = 3; + TO_LAB_Global.DataTypesTlm.Payload.bit78 = 1; + TO_LAB_Global.DataTypesTlm.Payload.nibble1 = 0xA; + TO_LAB_Global.DataTypesTlm.Payload.nibble2 = 0x4; +#endif + TO_LAB_Global.DataTypesTlm.Payload.bl1 = false; + TO_LAB_Global.DataTypesTlm.Payload.bl2 = true; + TO_LAB_Global.DataTypesTlm.Payload.b1 = 16; + TO_LAB_Global.DataTypesTlm.Payload.b2 = 127; + TO_LAB_Global.DataTypesTlm.Payload.b3 = 0x7F; + TO_LAB_Global.DataTypesTlm.Payload.b4 = 0x45; + TO_LAB_Global.DataTypesTlm.Payload.w1 = 0x2468; + TO_LAB_Global.DataTypesTlm.Payload.w2 = 0x7FFF; + TO_LAB_Global.DataTypesTlm.Payload.dw1 = 0x12345678; + TO_LAB_Global.DataTypesTlm.Payload.dw2 = 0x87654321; + TO_LAB_Global.DataTypesTlm.Payload.f1 = 90.01; + TO_LAB_Global.DataTypesTlm.Payload.f2 = .0000045; + TO_LAB_Global.DataTypesTlm.Payload.df1 = 99.9; + TO_LAB_Global.DataTypesTlm.Payload.df2 = .4444; + + for (i = 0; i < 10; i++) + TO_LAB_Global.DataTypesTlm.Payload.str[i] = string_variable[i]; + + CFE_SB_TransmitMsg(CFE_MSG_PTR(TO_LAB_Global.DataTypesTlm.TelemetryHeader), true); + + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_SendHousekeeping() -- HK status */ +/* Does not increment CommandCounter */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_SendHkCmd(const TO_LAB_SendHkCmd_t *data) +{ + CFE_SB_TimeStampMsg(CFE_MSG_PTR(TO_LAB_Global.HkTlm.TelemetryHeader)); + CFE_SB_TransmitMsg(CFE_MSG_PTR(TO_LAB_Global.HkTlm.TelemetryHeader), true); + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_AddPacket() -- Add packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_AddPacketCmd(const TO_LAB_AddPacketCmd_t *data) +{ + const TO_LAB_AddPacket_Payload_t *pCmd = &data->Payload; + int32 status; + + status = CFE_SB_SubscribeEx(pCmd->Stream, TO_LAB_Global.Tlm_pipe, pCmd->Flags, pCmd->BufLimit); + + if (status != CFE_SUCCESS) + CFE_EVS_SendEvent(TO_LAB_ADDPKT_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't subscribe 0x%x status %i", + __LINE__, (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), (int)status); + else + CFE_EVS_SendEvent(TO_LAB_ADDPKT_INF_EID, CFE_EVS_EventType_INFORMATION, + "L%d TO AddPkt 0x%x, QoS %d.%d, limit %d", __LINE__, + (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), pCmd->Flags.Priority, + pCmd->Flags.Reliability, pCmd->BufLimit); + + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_RemovePacket() -- Remove Packet */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_RemovePacketCmd(const TO_LAB_RemovePacketCmd_t *data) +{ + const TO_LAB_RemovePacket_Payload_t *pCmd = &data->Payload; + int32 status; + + status = CFE_SB_Unsubscribe(pCmd->Stream, TO_LAB_Global.Tlm_pipe); + if (status != CFE_SUCCESS) + CFE_EVS_SendEvent(TO_LAB_REMOVEPKT_ERR_EID, CFE_EVS_EventType_ERROR, + "L%d TO Can't Unsubscribe to Stream 0x%x, status %i", __LINE__, + (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream), (int)status); + else + CFE_EVS_SendEvent(TO_LAB_REMOVEPKT_INF_EID, CFE_EVS_EventType_INFORMATION, "L%d TO RemovePkt 0x%x", __LINE__, + (unsigned int)CFE_SB_MsgIdToValue(pCmd->Stream)); + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_RemoveAll() -- Remove All Packets */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +CFE_Status_t TO_LAB_RemoveAllCmd(const TO_LAB_RemoveAllCmd_t *data) +{ + int32 status; + int i; + TO_LAB_Sub_t *SubEntry; + + SubEntry = TO_LAB_Global.SubsTblPtr->Subs; + for (i = 0; i < TO_LAB_MAX_SUBSCRIPTIONS; i++) + { + if (CFE_SB_IsValidMsgId(SubEntry->Stream)) + { + status = CFE_SB_Unsubscribe(SubEntry->Stream, TO_LAB_Global.Tlm_pipe); + + if (status != CFE_SUCCESS) + CFE_EVS_SendEvent(TO_LAB_REMOVEALLPTKS_ERR_EID, CFE_EVS_EventType_ERROR, + "L%d TO Can't Unsubscribe to stream 0x%x status %i", __LINE__, + (unsigned int)CFE_SB_MsgIdToValue(SubEntry->Stream), (int)status); + } + } + + CFE_EVS_SendEvent(TO_LAB_REMOVEALLPKTS_INF_EID, CFE_EVS_EventType_INFORMATION, + "L%d TO Unsubscribed to all Commands and Telemetry", __LINE__); + + ++TO_LAB_Global.HkTlm.Payload.CommandCounter; + return CFE_SUCCESS; +} diff --git a/fsw/src/to_lab_cmds.h b/fsw/src/to_lab_cmds.h new file mode 100644 index 0000000..f9c0cd1 --- /dev/null +++ b/fsw/src/to_lab_cmds.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 + * Define TO Lab Application header file + */ + +#ifndef TO_LAB_CMDS_H +#define TO_LAB_CMDS_H + +#include "common_types.h" +#include "cfe_error.h" +#include "to_lab_msg.h" + +/******************************************************************************/ + +/* +** Prototypes Section +*/ +CFE_Status_t TO_LAB_AddPacketCmd(const TO_LAB_AddPacketCmd_t *data); +CFE_Status_t TO_LAB_NoopCmd(const TO_LAB_NoopCmd_t *data); +CFE_Status_t TO_LAB_EnableOutputCmd(const TO_LAB_EnableOutputCmd_t *data); +CFE_Status_t TO_LAB_RemoveAllCmd(const TO_LAB_RemoveAllCmd_t *data); +CFE_Status_t TO_LAB_RemovePacketCmd(const TO_LAB_RemovePacketCmd_t *data); +CFE_Status_t TO_LAB_ResetCountersCmd(const TO_LAB_ResetCountersCmd_t *data); +CFE_Status_t TO_LAB_SendDataTypesCmd(const TO_LAB_SendDataTypesCmd_t *data); +CFE_Status_t TO_LAB_SendHkCmd(const TO_LAB_SendHkCmd_t *data); + +/******************************************************************************/ + +#endif diff --git a/fsw/src/to_lab_dispatch.c b/fsw/src/to_lab_dispatch.c new file mode 100644 index 0000000..4f6c77c --- /dev/null +++ b/fsw/src/to_lab_dispatch.c @@ -0,0 +1,104 @@ +/************************************************************************ + * 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 TO lab application + */ + +#include "cfe.h" + +#include "to_lab_app.h" +#include "to_lab_dispatch.h" +#include "to_lab_cmds.h" +#include "to_lab_msg.h" +#include "to_lab_eventids.h" +#include "to_lab_msgids.h" + +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +/* */ +/* TO_LAB_ProcessGroundCommand() -- Process local message */ +/* */ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ +void TO_LAB_ProcessGroundCommand(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_MSG_FcnCode_t CommandCode = 0; + + CFE_MSG_GetFcnCode(&SBBufPtr->Msg, &CommandCode); + + switch (CommandCode) + { + case TO_LAB_NOOP_CC: + TO_LAB_NoopCmd((const TO_LAB_NoopCmd_t *)SBBufPtr); + break; + + case TO_LAB_RESET_STATUS_CC: + TO_LAB_ResetCountersCmd((const TO_LAB_ResetCountersCmd_t *)SBBufPtr); + break; + + case TO_LAB_SEND_DATA_TYPES_CC: + TO_LAB_SendDataTypesCmd((const TO_LAB_SendDataTypesCmd_t *)SBBufPtr); + break; + + case TO_LAB_ADD_PKT_CC: + TO_LAB_AddPacketCmd((const TO_LAB_AddPacketCmd_t *)SBBufPtr); + break; + + case TO_LAB_REMOVE_PKT_CC: + TO_LAB_RemovePacketCmd((const TO_LAB_RemovePacketCmd_t *)SBBufPtr); + break; + + case TO_LAB_REMOVE_ALL_PKT_CC: + TO_LAB_RemoveAllCmd((const TO_LAB_RemoveAllCmd_t *)SBBufPtr); + break; + + case TO_LAB_OUTPUT_ENABLE_CC: + TO_LAB_EnableOutputCmd((const TO_LAB_EnableOutputCmd_t *)SBBufPtr); + break; + + default: + CFE_EVS_SendEvent(TO_LAB_FNCODE_ERR_EID, CFE_EVS_EventType_ERROR, + "L%d TO: Invalid Function Code Rcvd In Ground Command 0x%x", __LINE__, + (unsigned int)CommandCode); + ++TO_LAB_Global.HkTlm.Payload.CommandErrorCounter; + } +} + +void TO_LAB_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr) +{ + CFE_SB_MsgId_t MsgId; + + CFE_MSG_GetMsgId(&SBBufPtr->Msg, &MsgId); + + /* For SB return statuses that imply a message: process it. */ + switch (CFE_SB_MsgIdToValue(MsgId)) + { + case TO_LAB_CMD_MID: + TO_LAB_ProcessGroundCommand(SBBufPtr); + break; + + case TO_LAB_SEND_HK_MID: + TO_LAB_SendHkCmd((const TO_LAB_SendHkCmd_t *)SBBufPtr); + break; + + default: + CFE_EVS_SendEvent(TO_LAB_MID_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO: Invalid Msg ID Rcvd 0x%x", + __LINE__, (unsigned int)CFE_SB_MsgIdToValue(MsgId)); + break; + } +} diff --git a/fsw/platform_inc/to_lab_sub_table.h b/fsw/src/to_lab_dispatch.h similarity index 71% rename from fsw/platform_inc/to_lab_sub_table.h rename to fsw/src/to_lab_dispatch.h index 7df5d94..286ca0e 100644 --- a/fsw/platform_inc/to_lab_sub_table.h +++ b/fsw/src/to_lab_dispatch.h @@ -18,25 +18,21 @@ /** * @file - * Define TO Lab CPU specific subscription table + * Define TO Lab Application header file */ -#ifndef TO_LAB_SUB_TABLE_H -#define TO_LAB_SUB_TABLE_H -#include "cfe_msgids.h" -#include "cfe_platform_cfg.h" -#include "cfe_sb.h" +#ifndef TO_LAB_DISPATCH_H +#define TO_LAB_DISPATCH_H -typedef struct -{ - CFE_SB_MsgId_t Stream; - CFE_SB_Qos_t Flags; - uint16 BufLimit; -} TO_LAB_Sub_t; +#include "common_types.h" -typedef struct -{ - TO_LAB_Sub_t Subs[CFE_PLATFORM_SB_MAX_MSG_IDS]; -} TO_LAB_Subs_t; +/******************************************************************************/ + +/* +** Prototypes Section +*/ +void TO_LAB_TaskPipe(const CFE_SB_Buffer_t *SBBufPtr); + +/******************************************************************************/ #endif diff --git a/fsw/src/to_lab_encode.h b/fsw/src/to_lab_encode.h new file mode 100644 index 0000000..bab2486 --- /dev/null +++ b/fsw/src/to_lab_encode.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 + * Define TO Lab Application header file + */ + +#ifndef TO_LAB_ENCODE_H +#define TO_LAB_ENCODE_H + +#include "common_types.h" +#include "cfe_msg.h" +#include "cfe_error.h" + +/******************************************************************************/ + +/* +** Prototypes Section +*/ +CFE_Status_t TO_LAB_EncodeOutputMessage(const CFE_SB_Buffer_t *SourceBuffer, const void **DestBufferOut, + size_t *DestSizeOut); + +/******************************************************************************/ + +#endif diff --git a/fsw/src/to_lab_msg.h b/fsw/src/to_lab_msg.h deleted file mode 100644 index 09bd1df..0000000 --- a/fsw/src/to_lab_msg.h +++ /dev/null @@ -1,148 +0,0 @@ -/************************************************************************ - * 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 TO Lab Messages and info - */ -#ifndef TO_LAB_MSG_H -#define TO_LAB_MSG_H - -#define TO_LAB_NOOP_CC 0 /* no-op command */ -#define TO_LAB_RESET_STATUS_CC 1 /* reset status */ -#define TO_LAB_ADD_PKT_CC 2 /* add packet */ -#define TO_LAB_SEND_DATA_TYPES_CC 3 /* send data types */ -#define TO_LAB_REMOVE_PKT_CC 4 /* remove packet */ -#define TO_LAB_REMOVE_ALL_PKT_CC 5 /* remove all packet */ -#define TO_LAB_OUTPUT_ENABLE_CC 6 /* output enable */ - -/******************************************************************************/ - -typedef struct -{ - uint8 CommandCounter; - uint8 CommandErrorCounter; - uint8 spareToAlign[2]; -} TO_LAB_HkTlm_Payload_t; - -typedef struct -{ - CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry header */ - TO_LAB_HkTlm_Payload_t Payload; /**< \brief Telemetry payload */ -} TO_LAB_HkTlm_t; - -/******************************************************************************/ - -typedef struct -{ - uint16 synch; -#if 0 - bit_field bit1:1; - bit_field bit2:1; - bit_field bit34:2; - bit_field bit56:2; - bit_field bit78:2; - - bit_field nibble1:4; - bit_field nibble2:4; -#endif - uint8 bl1, bl2; /* boolean */ - int8 b1, b2, b3, b4; - int16 w1, w2; - int32 dw1, dw2; - float f1, f2; - double df1, df2; - char str[10]; -} TO_LAB_DataTypes_Payload_t; - -typedef struct -{ - CFE_MSG_TelemetryHeader_t TelemetryHeader; /**< \brief Telemetry header */ - TO_LAB_DataTypes_Payload_t Payload; /**< \brief Telemetry payload */ -} TO_LAB_DataTypesTlm_t; - -/******************************************************************************/ - -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeade; /**< \brief Command header */ -} TO_LAB_NoArgsCmd_t; - -/* - * The following commands do not 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 TO_LAB_NoArgsCmd_t TO_LAB_NoopCmd_t; -typedef TO_LAB_NoArgsCmd_t TO_LAB_ResetCountersCmd_t; -typedef TO_LAB_NoArgsCmd_t TO_LAB_RemoveAllCmd_t; -typedef TO_LAB_NoArgsCmd_t TO_LAB_SendDataTypesCmd_t; - -typedef struct -{ - CFE_SB_MsgId_t Stream; - CFE_SB_Qos_t Flags; - uint8 BufLimit; -} TO_LAB_AddPacket_Payload_t; - -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */ - TO_LAB_AddPacket_Payload_t Payload; /**< \brief Command payload */ -} TO_LAB_AddPacketCmd_t; - -/*****************************************************************************/ - -typedef struct -{ - CFE_SB_MsgId_t Stream; - CFE_SB_Qos_t Flags; - uint16 BufLimit; -} TO_LAB_subscription_t; - -/******************************************************************************/ - -typedef struct -{ - CFE_SB_MsgId_t Stream; -} TO_LAB_RemovePacket_Payload_t; - -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */ - TO_LAB_RemovePacket_Payload_t Payload; /**< \brief Command payload */ -} TO_LAB_RemovePacketCmd_t; - -/******************************************************************************/ - -typedef struct -{ - char dest_IP[16]; -} TO_LAB_EnableOutput_Payload_t; - -typedef struct -{ - CFE_MSG_CommandHeader_t CmdHeader; /**< \brief Command header */ - TO_LAB_EnableOutput_Payload_t Payload; /**< \brief Command payload */ -} TO_LAB_EnableOutputCmd_t; - -/******************************************************************************/ - -#endif diff --git a/fsw/src/to_lab_passthru_encode.c b/fsw/src/to_lab_passthru_encode.c new file mode 100644 index 0000000..1ed591f --- /dev/null +++ b/fsw/src/to_lab_passthru_encode.c @@ -0,0 +1,52 @@ +/************************************************************************ + * 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 TO lab application + */ + +#include "cfe_config.h" +#include "cfe_sb.h" +#include "cfe_msg.h" + +#include "to_lab_app.h" +#include "to_lab_encode.h" + +/* + * -------------------------------------------- + * This implements an "encoder" that simply outputs the same pointer that was passed in. + * This matches the traditional TO behavior where the "C" struct is passed directly to the socket. + * + * The only thing this needs to do get the real size of the output datagram, which should be + * the size stored in the CFE message header. + * -------------------------------------------- + */ +CFE_Status_t TO_LAB_EncodeOutputMessage(const CFE_SB_Buffer_t *SourceBuffer, const void **DestBufferOut, + size_t *DestSizeOut) +{ + CFE_Status_t ResultStatus; + CFE_MSG_Size_t SourceBufferSize; + + ResultStatus = CFE_MSG_GetSize(&SourceBuffer->Msg, &SourceBufferSize); + + *DestBufferOut = SourceBuffer; + *DestSizeOut = SourceBufferSize; + + return ResultStatus; +} diff --git a/fsw/src/to_lab_version.h b/fsw/src/to_lab_version.h index 459c027..0d4697c 100644 --- a/fsw/src/to_lab_version.h +++ b/fsw/src/to_lab_version.h @@ -24,7 +24,7 @@ #define TO_LAB_VERSION_H /* Development Build Macro Definitions */ -#define TO_LAB_BUILD_NUMBER 49 /*!< Development Build: Number of commits since baseline */ +#define TO_LAB_BUILD_NUMBER 66 /*!< Development Build: Number of commits since baseline */ #define TO_LAB_BUILD_BASELINE \ "v2.5.0-rc4" /*!< Development Build: git tag that is the base for the current development */ diff --git a/fsw/tables/to_lab_sub.c b/fsw/tables/to_lab_sub.c index 1fc926f..83ab24b 100644 --- a/fsw/tables/to_lab_sub.c +++ b/fsw/tables/to_lab_sub.c @@ -22,8 +22,9 @@ */ #include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */ - -#include "to_lab_sub_table.h" +#include "cfe_sb_api_typedefs.h" +#include "to_lab_tbl.h" +#include "cfe_msgids.h" /* ** Add the proper include file for the message IDs below diff --git a/mission_build.cmake b/mission_build.cmake new file mode 100644 index 0000000..16344b3 --- /dev/null +++ b/mission_build.cmake @@ -0,0 +1,51 @@ +########################################################### +# +# TO_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 TO_LAB configuration +set(TO_LAB_MISSION_CONFIG_FILE_LIST + to_lab_fcncodes.h + to_lab_interface_cfg.h + to_lab_mission_cfg.h + to_lab_perfids.h + to_lab_msg.h + to_lab_msgdefs.h + to_lab_msgstruct.h + to_lab_tbl.h + to_lab_tbldefs.h + to_lab_tblstruct.h +) + +if (CFE_EDS_ENABLED_BUILD) + + # In an EDS-based build, these files come generated from the EDS tool + set(TO_LAB_CFGFILE_SRC_to_lab_interface_cfg "to_lab_eds_designparameters.h") + set(TO_LAB_CFGFILE_SRC_to_lab_tbldefs "to_lab_eds_typedefs.h") + set(TO_LAB_CFGFILE_SRC_to_lab_tblstruct "to_lab_eds_typedefs.h") + set(TO_LAB_CFGFILE_SRC_to_lab_msgdefs "to_lab_eds_typedefs.h") + set(TO_LAB_CFGFILE_SRC_to_lab_msgstruct "to_lab_eds_typedefs.h") + set(TO_LAB_CFGFILE_SRC_to_lab_fcncodes "to_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(TO_LAB_CFGFILE ${TO_LAB_MISSION_CONFIG_FILE_LIST}) + get_filename_component(CFGKEY "${TO_LAB_CFGFILE}" NAME_WE) + if (DEFINED TO_LAB_CFGFILE_SRC_${CFGKEY}) + set(DEFAULT_SOURCE GENERATED_FILE "${TO_LAB_CFGFILE_SRC_${CFGKEY}}") + else() + set(DEFAULT_SOURCE FALLBACK_FILE "${CMAKE_CURRENT_LIST_DIR}/config/default_${TO_LAB_CFGFILE}") + endif() + generate_config_includefile( + FILE_NAME "${TO_LAB_CFGFILE}" + ${DEFAULT_SOURCE} + ) +endforeach()