From 6326445423e0daef63bb13a7700a2795f190799e Mon Sep 17 00:00:00 2001 From: Avi Date: Fri, 21 Oct 2022 20:28:47 +1000 Subject: [PATCH 01/10] Fix #133, Apply consistent Event ID names to common events in to_lab --- fsw/src/to_lab_app.c | 4 ++-- fsw/src/to_lab_events.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 17e2660..72b0912 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -188,7 +188,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 */ @@ -285,7 +285,7 @@ void TO_LAB_process_commands(void) break; default: - CFE_EVS_SendEvent(TO_LAB_MSGID_ERR_EID, CFE_EVS_EventType_ERROR, + 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/src/to_lab_events.h b/fsw/src/to_lab_events.h index 44369fa..8c2dfa8 100644 --- a/fsw/src/to_lab_events.h +++ b/fsw/src/to_lab_events.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 From 53caa1f6820af26efd1aa60de7e4a03abcc67446 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Wed, 5 Apr 2023 11:27:47 +1000 Subject: [PATCH 02/10] Fix #147, Add check for failure of `CFE_EVS_Register()` during initialization --- fsw/src/to_lab_app.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 17e2660..b54f192 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -146,7 +146,13 @@ 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)... */ From d7b7f46e7432d691e3240804c637b35e7c913437 Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Mon, 24 Apr 2023 11:24:19 +1000 Subject: [PATCH 03/10] Fix #155, Convert `int32` return codes and variables to `CFE_Status_t` --- .github/workflows/codeql-build.yml | 2 +- fsw/src/to_lab_app.c | 72 +++++++++++++++--------------- 2 files changed, 37 insertions(+), 37 deletions(-) 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/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 17e2660..f2898c8 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -53,23 +53,23 @@ 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); +void TO_LAB_openTLM(void); +CFE_Status_t 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); +CFE_Status_t TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data); +CFE_Status_t TO_LAB_Noop(const TO_LAB_NoopCmd_t *data); +CFE_Status_t TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data); +CFE_Status_t TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data); +CFE_Status_t TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data); +CFE_Status_t TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data); +CFE_Status_t TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data); +CFE_Status_t TO_LAB_SendHousekeeping(const CFE_MSG_CommandHeader_t *data); /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -78,8 +78,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 +128,14 @@ 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; TO_LAB_Global.downlink_on = false; PipeDepth = TO_LAB_CMD_PIPE_DEPTH; @@ -235,7 +235,7 @@ int32 TO_LAB_init(void) /* TO_LAB_EnableOutput() -- TLM output enabled */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data) +CFE_Status_t TO_LAB_EnableOutput(const TO_LAB_EnableOutputCmd_t *data) { const TO_LAB_EnableOutput_Payload_t *pCmd = &data->Payload; @@ -352,7 +352,7 @@ void TO_LAB_exec_local_command(CFE_SB_Buffer_t *SBBufPtr) /* TO_LAB_Noop() -- Noop Handler */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_Noop(const TO_LAB_NoopCmd_t *data) +CFE_Status_t 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; @@ -364,7 +364,7 @@ int32 TO_LAB_Noop(const TO_LAB_NoopCmd_t *data) /* TO_LAB_ResetCounters() -- Reset counters */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data) +CFE_Status_t TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data) { TO_LAB_Global.HkTlm.Payload.CommandErrorCounter = 0; TO_LAB_Global.HkTlm.Payload.CommandCounter = 0; @@ -376,7 +376,7 @@ int32 TO_LAB_ResetCounters(const TO_LAB_ResetCountersCmd_t *data) /* TO_LAB_SendDataTypes() -- Output data types */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data) +CFE_Status_t TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data) { int16 i; char string_variable[10] = "ABCDEFGHIJ"; @@ -427,7 +427,7 @@ int32 TO_LAB_SendDataTypes(const TO_LAB_SendDataTypesCmd_t *data) /* TO_LAB_SendHousekeeping() -- HK status */ /* Does not increment CommandCounter */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_SendHousekeeping(const CFE_MSG_CommandHeader_t *data) +CFE_Status_t 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); @@ -458,10 +458,10 @@ void TO_LAB_openTLM(void) /* TO_LAB_AddPacket() -- Add packets */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data) +CFE_Status_t TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data) { const TO_LAB_AddPacket_Payload_t *pCmd = &data->Payload; - int32 status; + CFE_Status_t status; status = CFE_SB_SubscribeEx(pCmd->Stream, TO_LAB_Global.Tlm_pipe, pCmd->Flags, pCmd->BufLimit); @@ -483,10 +483,10 @@ int32 TO_LAB_AddPacket(const TO_LAB_AddPacketCmd_t *data) /* TO_LAB_RemovePacket() -- Remove Packet */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data) +CFE_Status_t TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data) { const TO_LAB_RemovePacket_Payload_t *pCmd = &data->Payload; - int32 status; + CFE_Status_t status; status = CFE_SB_Unsubscribe(pCmd->Stream, TO_LAB_Global.Tlm_pipe); if (status != CFE_SUCCESS) @@ -505,10 +505,10 @@ int32 TO_LAB_RemovePacket(const TO_LAB_RemovePacketCmd_t *data) /* TO_LAB_RemoveAll() -- Remove All Packets */ /* */ /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ -int32 TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data) +CFE_Status_t TO_LAB_RemoveAll(const TO_LAB_RemoveAllCmd_t *data) { - int32 status; - int i; + CFE_Status_t status; + int i; for (i = 0; (i < (sizeof(TO_LAB_Subs->Subs) / sizeof(TO_LAB_Subs->Subs[0]))); i++) { @@ -538,8 +538,8 @@ 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; + CFE_Status_t status; + CFE_Status_t CFE_SB_status; size_t size; CFE_SB_Buffer_t *SBBufPtr; From d81ddd36c33b1f8114c3f93970bf1f65cc398a6d Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Tue, 2 May 2023 19:16:22 +1000 Subject: [PATCH 04/10] Fix #157, Move function prototypes to header file --- fsw/src/to_lab_app.c | 41 ++++------------------------------ fsw/src/to_lab_app.h | 52 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 44 deletions(-) diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 17e2660..798584c 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -30,46 +30,12 @@ #include "to_lab_sub_table.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_Subs_t * TO_LAB_Subs; +CFE_TBL_Handle_t TO_SubTblHandle; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -344,6 +310,7 @@ void TO_LAB_exec_local_command(CFE_SB_Buffer_t *SBBufPtr) "L%d TO: Invalid Function Code Rcvd In Ground Command 0x%x", __LINE__, (unsigned int)CommandCode); ++TO_LAB_Global.HkTlm.Payload.CommandErrorCounter; + break; } } diff --git a/fsw/src/to_lab_app.h b/fsw/src/to_lab_app.h index b686c2e..7748402 100644 --- a/fsw/src/to_lab_app.h +++ b/fsw/src/to_lab_app.h @@ -33,7 +33,11 @@ #include "common_types.h" #include "osapi.h" -/*****************************************************************************/ +#include "to_lab_msg.h" + +/************************************************************************ + * Macro Definitions + ************************************************************************/ #define TO_LAB_TASK_MSEC 500 /* run at 2 Hz */ #define TO_LAB_UNUSED CFE_SB_MSGID_RESERVED @@ -52,13 +56,47 @@ #define cfgTLM_PORT 1235 #define TO_LAB_VERSION_NUM "5.1.0" -/******************************************************************************/ +/************************************************************************ +** Type Definitions +*************************************************************************/ -/* -** Prototypes Section -*/ -void TO_LAB_AppMain(void); +/** + * CI global data structure + */ +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; + +/************************************************************************ + * Function Prototypes + ************************************************************************/ + +void TO_LAB_AppMain(void); +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); #endif From fce77cf01a645f04393f8c4413156b3c886f9805 Mon Sep 17 00:00:00 2001 From: Avi Date: Fri, 27 Jan 2023 12:20:21 +1000 Subject: [PATCH 05/10] Fix #145, Refactor mutually exclusive logic in if, else if block --- fsw/src/to_lab_app.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 7a47b7e..eff2859 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -207,16 +207,16 @@ int32 TO_LAB_init(void) /* 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(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_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); + } } /* From 60968b15ee3c504cb1c1441706960fcf588f1f2b Mon Sep 17 00:00:00 2001 From: Avi Weiss Date: Fri, 22 Sep 2023 12:12:54 +1000 Subject: [PATCH 06/10] Fix #162, Update misnamed `CmdHeader` variable in `to_lab_msg.h` --- .github/pull_request_template.md | 2 +- fsw/src/to_lab_msg.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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/fsw/src/to_lab_msg.h b/fsw/src/to_lab_msg.h index 09bd1df..77a674e 100644 --- a/fsw/src/to_lab_msg.h +++ b/fsw/src/to_lab_msg.h @@ -80,7 +80,7 @@ typedef struct typedef struct { - CFE_MSG_CommandHeader_t CmdHeade; /**< \brief Command header */ + CFE_MSG_CommandHeader_t CommandHeader; /**< \brief Command header */ } TO_LAB_NoArgsCmd_t; /* From ae2fceefc5cd9584d3e943b3432c684d84adceec Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Wed, 25 Oct 2023 10:03:25 -0400 Subject: [PATCH 07/10] Fix #166, reorganize source files Organize source files into a directory and naming pattern that is compliant with the CFE current recommended practice. Configurable items are moved to the respective header files and documentation is added to indicate what they do. --- CMakeLists.txt | 7 +- arch_build.cmake | 27 ++ config/default_to_lab_fcncodes.h | 46 +++ config/default_to_lab_interface_cfg.h | 45 +++ config/default_to_lab_internal_cfg.h | 49 +++ config/default_to_lab_mission_cfg.h | 36 ++ config/default_to_lab_msg.h | 38 ++ config/default_to_lab_msgdefs.h | 69 ++++ .../default_to_lab_msgids.h | 2 +- config/default_to_lab_msgstruct.h | 107 ++++++ .../default_to_lab_perfids.h | 0 config/default_to_lab_platform_cfg.h | 41 ++ config/default_to_lab_tbl.h | 33 ++ config/default_to_lab_tbldefs.h | 48 +++ config/default_to_lab_tblstruct.h | 50 +++ .../to_lab_events.h => inc/to_lab_eventids.h} | 4 +- fsw/src/to_lab_app.c | 357 ++---------------- fsw/src/to_lab_app.h | 49 ++- fsw/src/to_lab_cmds.c | 221 +++++++++++ fsw/src/to_lab_cmds.h | 47 +++ fsw/src/to_lab_dispatch.c | 104 +++++ .../to_lab_dispatch.h} | 28 +- fsw/src/to_lab_msg.h | 148 -------- fsw/tables/to_lab_sub.c | 4 +- mission_build.cmake | 51 +++ 25 files changed, 1096 insertions(+), 515 deletions(-) create mode 100644 arch_build.cmake create mode 100644 config/default_to_lab_fcncodes.h create mode 100644 config/default_to_lab_interface_cfg.h create mode 100644 config/default_to_lab_internal_cfg.h create mode 100644 config/default_to_lab_mission_cfg.h create mode 100644 config/default_to_lab_msg.h create mode 100644 config/default_to_lab_msgdefs.h rename fsw/platform_inc/to_lab_msgids.h => config/default_to_lab_msgids.h (97%) create mode 100644 config/default_to_lab_msgstruct.h rename fsw/mission_inc/to_lab_perfids.h => config/default_to_lab_perfids.h (100%) create mode 100644 config/default_to_lab_platform_cfg.h create mode 100644 config/default_to_lab_tbl.h create mode 100644 config/default_to_lab_tbldefs.h create mode 100644 config/default_to_lab_tblstruct.h rename fsw/{src/to_lab_events.h => inc/to_lab_eventids.h} (97%) create mode 100644 fsw/src/to_lab_cmds.c create mode 100644 fsw/src/to_lab_cmds.h create mode 100644 fsw/src/to_lab_dispatch.c rename fsw/{platform_inc/to_lab_sub_table.h => src/to_lab_dispatch.h} (71%) delete mode 100644 fsw/src/to_lab_msg.h create mode 100644 mission_build.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index f3fa9a8..bb68567 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,13 +18,12 @@ endforeach() set(APP_SRC_FILES fsw/src/to_lab_app.c + fsw/src/to_lab_cmds.c + fsw/src/to_lab_dispatch.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 97% rename from fsw/src/to_lab_events.h rename to fsw/inc/to_lab_eventids.h index 44369fa..72a7ac4 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 /*****************************************************************************/ diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index 7a47b7e..de20b36 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -21,56 +21,21 @@ * 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_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 */ -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 */ @@ -130,12 +95,14 @@ void TO_LAB_delete_callback(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ int32 TO_LAB_init(void) { - int32 status; - char PipeName[16]; - uint16 PipeDepth; - uint16 i; - char ToTlmPipeName[16]; - uint16 ToTlmPipeDepth; + int32 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; @@ -153,7 +120,8 @@ int32 TO_LAB_init(void) 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 +130,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 +139,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 +148,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) @@ -200,23 +170,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 +201,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 +209,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 +243,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 */ @@ -544,7 +257,7 @@ void TO_LAB_forward_telemetry(void) CFE_SB_Buffer_t *SBBufPtr; 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; diff --git a/fsw/src/to_lab_app.h b/fsw/src/to_lab_app.h index 4cfb2b1..7c74661 100644 --- a/fsw/src/to_lab_app.h +++ b/fsw/src/to_lab_app.h @@ -24,40 +24,49 @@ #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 */ +/******************************************************************************/ -/** - * Depth of pipe for commands to the TO_LAB application itself - */ -#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; /* ** Prototypes Section */ 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..42cc7b7 --- /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_MSGID_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_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/tables/to_lab_sub.c b/fsw/tables/to_lab_sub.c index 1fc926f..c839cb8 100644 --- a/fsw/tables/to_lab_sub.c +++ b/fsw/tables/to_lab_sub.c @@ -22,8 +22,8 @@ */ #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" /* ** 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() From 511a3dcd0c9b2b7128f43c60b54e393f96de8391 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 27 Oct 2023 13:01:06 -0400 Subject: [PATCH 08/10] Fix #167, add encode hook Add a separate "encode" step as part of TO_LAB output forwarding. Initially, this is just a pass through implementation, so it matches current behavior. --- CMakeLists.txt | 1 + fsw/inc/to_lab_eventids.h | 1 + fsw/src/to_lab_app.c | 39 +++++++++++++++--------- fsw/src/to_lab_encode.h | 41 +++++++++++++++++++++++++ fsw/src/to_lab_passthru_encode.c | 52 ++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 15 deletions(-) create mode 100644 fsw/src/to_lab_encode.h create mode 100644 fsw/src/to_lab_passthru_encode.c diff --git a/CMakeLists.txt b/CMakeLists.txt index bb68567..376023f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ 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 diff --git a/fsw/inc/to_lab_eventids.h b/fsw/inc/to_lab_eventids.h index 72a7ac4..d21cdae 100644 --- a/fsw/inc/to_lab_eventids.h +++ b/fsw/inc/to_lab_eventids.h @@ -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 de20b36..cfd238e 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -24,6 +24,7 @@ #include "cfe.h" #include "to_lab_app.h" +#include "to_lab_encode.h" #include "to_lab_eventids.h" #include "to_lab_msgids.h" #include "to_lab_perfids.h" @@ -251,45 +252,53 @@ void TO_LAB_openTLM(void) 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, 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_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_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; +} From 500839d781c633912e447d0b0daa3fe92cc56e6b Mon Sep 17 00:00:00 2001 From: Dylan Date: Mon, 13 Nov 2023 13:15:12 -0500 Subject: [PATCH 09/10] Updating documentation and version numbers for v2.5.0-rc4+dev66 --- CHANGELOG.md | 10 ++++++++++ fsw/src/to_lab_version.h | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) 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/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 */ From 3316bfa423088259699fc1f98057c1b4ff738139 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Tue, 14 Nov 2023 10:47:07 -0500 Subject: [PATCH 10/10] HotFix #170, correct IC merge issues Correct various merge issues in the latest IC --- fsw/src/to_lab_app.c | 20 ++++++++------------ fsw/src/to_lab_app.h | 32 ++++---------------------------- fsw/src/to_lab_dispatch.c | 2 +- fsw/tables/to_lab_sub.c | 1 + 4 files changed, 14 insertions(+), 41 deletions(-) diff --git a/fsw/src/to_lab_app.c b/fsw/src/to_lab_app.c index af855fa..d1fb0fd 100644 --- a/fsw/src/to_lab_app.c +++ b/fsw/src/to_lab_app.c @@ -36,8 +36,6 @@ ** TO Global Data Section */ TO_LAB_GlobalData_t TO_LAB_Global; -TO_LAB_Subs_t * TO_LAB_Subs; -CFE_TBL_Handle_t TO_SubTblHandle; /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ /* */ @@ -98,12 +96,12 @@ void TO_LAB_delete_callback(void) /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ CFE_Status_t TO_LAB_init(void) { - CFE_Status_t 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; @@ -187,8 +185,6 @@ CFE_Status_t TO_LAB_init(void) /* Only process until invalid MsgId is found*/ break; } - 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) @@ -262,8 +258,8 @@ void TO_LAB_openTLM(void) void TO_LAB_forward_telemetry(void) { OS_SockAddr_t d_addr; - CFE_Status_t status; - CFE_Status_t CFE_SB_status; + int32 OsStatus; + CFE_Status_t CfeStatus; CFE_SB_Buffer_t *SBBufPtr; const void * NetBufPtr; size_t NetBufSize; diff --git a/fsw/src/to_lab_app.h b/fsw/src/to_lab_app.h index 726a0be..30c7e34 100644 --- a/fsw/src/to_lab_app.h +++ b/fsw/src/to_lab_app.h @@ -42,30 +42,6 @@ /** * CI global data structure */ -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; - -/************************************************************************ - * Function Prototypes - ************************************************************************/ - -void TO_LAB_AppMain(void); -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); - typedef struct { CFE_SB_PipeId_t Tlm_pipe; @@ -83,11 +59,11 @@ typedef struct } TO_LAB_GlobalData_t; -/* -** Prototypes Section -*/ -void TO_LAB_AppMain(void); +/************************************************************************ + * Function Prototypes + ************************************************************************/ +void TO_LAB_AppMain(void); void TO_LAB_openTLM(void); int32 TO_LAB_init(void); void TO_LAB_process_commands(void); diff --git a/fsw/src/to_lab_dispatch.c b/fsw/src/to_lab_dispatch.c index 42cc7b7..4f6c77c 100644 --- a/fsw/src/to_lab_dispatch.c +++ b/fsw/src/to_lab_dispatch.c @@ -97,7 +97,7 @@ void TO_LAB_TaskPipe(const CFE_SB_Buffer_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", + 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/tables/to_lab_sub.c b/fsw/tables/to_lab_sub.c index c839cb8..83ab24b 100644 --- a/fsw/tables/to_lab_sub.c +++ b/fsw/tables/to_lab_sub.c @@ -24,6 +24,7 @@ #include "cfe_tbl_filedef.h" /* Required to obtain the CFE_TBL_FILEDEF macro definition */ #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