From 5b536fc2ec5e16c385fbc80fe108cf2b39304b98 Mon Sep 17 00:00:00 2001 From: Chris Knight Date: Thu, 4 Jun 2020 18:03:48 -0700 Subject: [PATCH] fix #32 - make the TO table a proper table --- CMakeLists.txt | 2 + fsw/platform_inc/to_lab_sub_table.h | 79 ++++++------------------ fsw/src/to_lab_app.c | 68 ++++++++++++++------- fsw/src/to_lab_app.h | 1 + fsw/src/to_lab_events.h | 1 + fsw/tables/to_lab_sub.c | 93 +++++++++++++++++++++++++++++ 6 files changed, 161 insertions(+), 83 deletions(-) create mode 100644 fsw/tables/to_lab_sub.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 61e67ce..b83c57d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,3 +11,5 @@ aux_source_directory(fsw/src APP_SRC_FILES) # Create the app module add_cfe_app(to_lab ${APP_SRC_FILES}) +add_cfe_tables(TO_LAB_Subs fsw/tables/to_lab_sub.c) + diff --git a/fsw/platform_inc/to_lab_sub_table.h b/fsw/platform_inc/to_lab_sub_table.h index 7ce00c7..a78384b 100644 --- a/fsw/platform_inc/to_lab_sub_table.h +++ b/fsw/platform_inc/to_lab_sub_table.h @@ -2,7 +2,7 @@ ** ** GSC-18128-1, "Core Flight Executive Version 6.7" ** -** Copyright (c) 2006-2019 United States Government as represented by +** Copyright (c) 2006-2002 United States Government as represented by ** the Administrator of the National Aeronautics and Space Administration. ** All Rights Reserved. ** @@ -18,7 +18,7 @@ ** See the License for the specific language governing permissions and ** limitations under the License. ** -** File: to_sub_table.h +** File: to_lab_sub_table.h ** ** Purpose: ** Define TO Lab CPU specific subscription table @@ -27,64 +27,19 @@ ** *************************************************************************/ -/* -** Add the proper include file for the message IDs below -*/ #include "cfe_msgids.h" - -/* -** Common CFS app includes below are commented out -*/ -#include "ci_lab_msgids.h" - -#include "sample_app_msgids.h" - -#if 0 -#include "hs_msgids.h" -#include "fm_msgids.h" -#include "sc_msgids.h" -#include "ds_msgids.h" -#include "lc_msgids.h" -#endif - -static TO_subscription_t TO_SubTable[] = { - /* CFS App Subscriptions */ - {CFE_SB_MSGID_WRAP_VALUE(TO_LAB_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(TO_LAB_DATA_TYPES_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CI_LAB_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(SAMPLE_APP_HK_TLM_MID), {0, 0}, 4}, - -#if 0 - /* Add these if needed */ - {HS_HK_TLM_MID, {0,0}, 4}, - {FM_HK_TLM_MID, {0,0}, 4}, - {SC_HK_TLM_MID, {0,0}, 4}, - {DS_HK_TLM_MID, {0,0}, 4}, - {LC_HK_TLM_MID, {0,0}, 4}, -#endif - - /* cFE Core subscriptions */ - {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_SB_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_HK_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_DIAG_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_SB_STATS_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_REG_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_LONG_EVENT_MSG_MID), {0, 0}, 32}, - -#ifndef CFE_OMIT_DEPRECATED_6_7 - {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SHELL_TLM_MID), {0, 0}, 32}, -#endif - - {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_APP_TLM_MID), {0, 0}, 4}, - {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_MEMSTATS_TLM_MID), {0, 0}, 4}, - - {TO_UNUSED, {0, 0}, 0}, - {TO_UNUSED, {0, 0}, 0}, - {TO_UNUSED, {0, 0}, 0}}; - -/************************ -** End of File Comment ** -************************/ +#include "cfe_platform_cfg.h" +#include "cfe_sb.h" + +typedef struct +{ + CFE_SB_MsgId_t Stream; + CFE_SB_Qos_t Flags; + uint16 BufLimit; +} TO_LAB_Sub_t; + +typedef struct +{ + TO_LAB_Sub_t Subs[CFE_PLATFORM_SB_MAX_MSG_IDS]; +} +TO_LAB_Subs_t; diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 9cf0628..5bf34d6 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -33,6 +33,7 @@ #include "to_lab_msgids.h" #include "to_lab_perfids.h" #include "to_lab_version.h" +#include "to_lab_sub_table.h" /* ** Global Data Section @@ -64,14 +65,8 @@ typedef struct TO_LAB_GlobalData_t TO_LAB_Global; -/* -** Include the TO subscription table -** This header is in the platform include directory -** and can be changed for default TO subscriptions in -** each CPU. -*/ -#include "to_lab_sub_table.h" - +TO_LAB_Subs_t *TO_LAB_Subs; +CFE_TBL_Handle_t TO_SubTblHandle; /* ** Event Filter Table */ @@ -85,7 +80,7 @@ static CFE_EVS_BinFilter_t CFE_TO_EVS_Filters[] = {/* Event ID mask */ ** Prototypes Section */ void TO_LAB_openTLM(void); -void TO_LAB_init(void); +int32 TO_LAB_init(void); void TO_LAB_exec_local_command(CFE_SB_MsgPtr_t cmd); void TO_LAB_process_commands(void); void TO_LAB_forward_telemetry(void); @@ -110,10 +105,16 @@ int32 TO_LAB_SendHousekeeping(const CCSDS_CommandPacket_t *data); void TO_Lab_AppMain(void) { uint32 RunStatus = CFE_ES_RunStatus_APP_RUN; + int32 status; CFE_ES_PerfLogEntry(TO_MAIN_TASK_PERF_ID); - TO_LAB_init(); + status = TO_LAB_init(); + + if (status != CFE_SUCCESS) + { + return; + } /* ** TO RunLoop @@ -154,7 +155,7 @@ void TO_delete_callback(void) /* TO_init() -- TO initialization */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -void TO_LAB_init(void) +int TO_LAB_init(void) { int32 status; char PipeName[16]; @@ -180,6 +181,30 @@ void TO_LAB_init(void) */ CFE_SB_InitMsg(&TO_LAB_Global.HkBuf.MsgHdr, TO_LAB_HK_TLM_MID, sizeof(TO_LAB_Global.HkBuf.HkTlm), true); + status = CFE_TBL_Register(&TO_SubTblHandle, "TO_LAB_Subs", sizeof(*TO_LAB_Subs), CFE_TBL_OPT_DEFAULT, NULL); + + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(TO_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't register table status %i", __LINE__, (int)status); + return status; + } + + status = CFE_TBL_Load(TO_SubTblHandle, CFE_TBL_SRC_FILE, "/cf/to_lab_sub.tbl"); + + if (status != CFE_SUCCESS) + { + CFE_EVS_SendEvent(TO_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't load table status %i", __LINE__, (int)status); + return status; + } + + status = CFE_TBL_GetAddress((void *)&TO_LAB_Subs, TO_SubTblHandle); + + if (status != CFE_SUCCESS && status != CFE_TBL_INFO_UPDATED) + { + CFE_EVS_SendEvent(TO_TBL_ERR_EID, CFE_EVS_EventType_ERROR, "L%d TO Can't get table addr status %i", __LINE__, (int)status); + return status; + } + /* Subscribe to my commands */ status = CFE_SB_CreatePipe(&TO_LAB_Global.Cmd_pipe, PipeDepth, PipeName); if (status == CFE_SUCCESS) @@ -200,16 +225,16 @@ void TO_LAB_init(void) } /* Subscriptions for TLM pipe*/ - for (i = 0; (i < (sizeof(TO_SubTable) / sizeof(TO_subscription_t))); i++) + for (i = 0; (i < (sizeof(TO_LAB_Subs->Subs) / sizeof(TO_LAB_Subs->Subs[0]))); i++) { - if (CFE_SB_IsValidMsgId(TO_SubTable[i].Stream)) - status = CFE_SB_SubscribeEx(TO_SubTable[i].Stream, TO_LAB_Global.Tlm_pipe, TO_SubTable[i].Flags, - TO_SubTable[i].BufLimit); + 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); if (status != CFE_SUCCESS) CFE_EVS_SendEvent(TO_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_SubTable[i].Stream), (int)status); + (unsigned int)CFE_SB_MsgIdToValue(TO_LAB_Subs->Subs[i].Stream), (int)status); } /* @@ -221,7 +246,8 @@ void TO_LAB_init(void) "TO Lab Initialized. Version %d.%d.%d.%d Awaiting enable command.", TO_LAB_MAJOR_VERSION, TO_LAB_MINOR_VERSION, TO_LAB_REVISION, TO_LAB_MISSION_REV); -} /* End of TO_Init() */ + return CFE_SUCCESS; +} /* End of TO_LAB_init() */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -500,16 +526,16 @@ int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAll_t *data) int32 status; int i; - for (i = 0; (i < (sizeof(TO_SubTable) / sizeof(TO_subscription_t))); i++) + for (i = 0; (i < (sizeof(TO_LAB_Subs->Subs) / sizeof(TO_LAB_Subs->Subs[0]))); i++) { - if (CFE_SB_IsValidMsgId(TO_SubTable[i].Stream)) + if (CFE_SB_IsValidMsgId(TO_LAB_Subs->Subs[i].Stream)) { - status = CFE_SB_Unsubscribe(TO_SubTable[i].Stream, TO_LAB_Global.Tlm_pipe); + status = CFE_SB_Unsubscribe(TO_LAB_Subs->Subs[i].Stream, TO_LAB_Global.Tlm_pipe); if (status != CFE_SUCCESS) CFE_EVS_SendEvent(TO_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_SubTable[i].Stream), (int)status); + (unsigned int)CFE_SB_MsgIdToValue(TO_LAB_Subs->Subs[i].Stream), (int)status); } } diff --git a/fsw/src/to_lab_app.h b/fsw/src/to_lab_app.h index 095e9ca..1e2aa84 100644 --- a/fsw/src/to_lab_app.h +++ b/fsw/src/to_lab_app.h @@ -36,6 +36,7 @@ #include "cfe_evs.h" #include "cfe_sb.h" #include "cfe_es.h" +#include "cfe_tbl.h" #include #include diff --git a/fsw/src/to_lab_events.h b/fsw/src/to_lab_events.h index d9c1ad2..a133bfe 100644 --- a/fsw/src/to_lab_events.h +++ b/fsw/src/to_lab_events.h @@ -52,6 +52,7 @@ #define TO_REMOVEPKT_INF_EID 16 #define TO_REMOVEALLPKTS_INF_EID 17 #define TO_NOOP_INF_EID 18 +#define TO_TBL_ERR_EID 19 /******************************************************************************/ diff --git a/fsw/tables/to_lab_sub.c b/fsw/tables/to_lab_sub.c new file mode 100644 index 0000000..868ebd9 --- /dev/null +++ b/fsw/tables/to_lab_sub.c @@ -0,0 +1,93 @@ +/************************************************************************ +** +** GSC-18128-1, "Core Flight Executive Version 6.7" +** +** Copyright (c) 2006-2002 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_sub_table.c +** +** Purpose: +** Define TO Lab CPU specific subscription table +** +** Notes: +** +*************************************************************************/ + +#include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */ + +#include "to_lab_sub_table.h" + +/* +** Add the proper include file for the message IDs below +*/ + +/* +** Common CFS app includes below are commented out +*/ +#include "to_lab_msgids.h" +#include "ci_lab_msgids.h" + +#include "sample_app_msgids.h" + +#if 0 +#include "hs_msgids.h" +#include "fm_msgids.h" +#include "sc_msgids.h" +#include "ds_msgids.h" +#include "lc_msgids.h" +#endif + +TO_LAB_Subs_t TO_LAB_Subs = +{ + .Subs = + { + /* CFS App Subscriptions */ + {CFE_SB_MSGID_WRAP_VALUE(TO_LAB_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(TO_LAB_DATA_TYPES_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CI_LAB_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(SAMPLE_APP_HK_TLM_MID), {0, 0}, 4}, + + #if 0 + /* Add these if needed */ + {CFE_SB_MSGID_WRAP_VALUE(HS_HK_TLM_MID), {0,0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(FM_HK_TLM_MID), {0,0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(SC_HK_TLM_MID), {0,0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(DS_HK_TLM_MID), {0,0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(LC_HK_TLM_MID), {0,0}, 4}, + #endif + + /* cFE Core subscriptions */ + {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_SB_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_HK_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_TIME_DIAG_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_SB_STATS_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_TBL_REG_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_EVS_LONG_EVENT_MSG_MID), {0, 0}, 32}, + + #ifndef CFE_OMIT_DEPRECATED_6_7 + {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_SHELL_TLM_MID), {0, 0}, 32}, + #endif + + {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_APP_TLM_MID), {0, 0}, 4}, + {CFE_SB_MSGID_WRAP_VALUE(CFE_ES_MEMSTATS_TLM_MID), {0, 0}, 4} + } +}; + +CFE_TBL_FILEDEF(TO_LAB_Subs, TO_LAB_APP.TO_LAB_Subs, TO Lab Sub Tbl, to_lab_sub.tbl)