Skip to content

Commit

Permalink
Merge pull request #45 from CDKnightNASA/fix-32-proper_table
Browse files Browse the repository at this point in the history
Fix #32, Make the TO table a proper table
  • Loading branch information
astrogeco authored Jun 16, 2020
2 parents daee638 + 5b536fc commit 7cbc526
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 83 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)

79 changes: 17 additions & 62 deletions fsw/platform_inc/to_lab_sub_table.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
**
Expand All @@ -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
Expand All @@ -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;
68 changes: 47 additions & 21 deletions fsw/src/to_lab_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
*/
Expand All @@ -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);
Expand All @@ -110,10 +105,16 @@ int32 TO_LAB_SendHousekeeping(const CFE_SB_CmdHdr_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
Expand Down Expand Up @@ -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];
Expand All @@ -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)
Expand All @@ -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);
}

/*
Expand All @@ -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() */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* */
Expand Down Expand Up @@ -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);
}
}

Expand Down
1 change: 1 addition & 0 deletions fsw/src/to_lab_app.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "cfe_evs.h"
#include "cfe_sb.h"
#include "cfe_es.h"
#include "cfe_tbl.h"

#include <errno.h>
#include <string.h>
Expand Down
1 change: 1 addition & 0 deletions fsw/src/to_lab_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/******************************************************************************/

Expand Down
93 changes: 93 additions & 0 deletions fsw/tables/to_lab_sub.c
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit 7cbc526

Please sign in to comment.