From e7db7d90edde4d765685dc179a2d5183f5bd9ac1 Mon Sep 17 00:00:00 2001 From: Joseph Hickey Date: Fri, 27 Oct 2023 13:01:06 -0400 Subject: [PATCH] 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/src/to_lab_app.c | 36 ++++++++++++++-------- fsw/src/to_lab_encode.h | 41 +++++++++++++++++++++++++ fsw/src/to_lab_passthru_encode.c | 52 ++++++++++++++++++++++++++++++++ 4 files changed, 117 insertions(+), 13 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/src/to_lab_app.c b/fsw/src/to_lab_app.c index de20b36..ef29f13 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,54 @@ 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); - 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_MSGID_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; + OsStatus = 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; +}