Skip to content

Commit

Permalink
Fix #167, add encode hook
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jphickey committed Oct 27, 2023
1 parent 9a1f5ca commit e7db7d9
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 13 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 23 additions & 13 deletions fsw/src/to_lab_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
}

/************************/
Expand Down
41 changes: 41 additions & 0 deletions fsw/src/to_lab_encode.h
Original file line number Diff line number Diff line change
@@ -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
52 changes: 52 additions & 0 deletions fsw/src/to_lab_passthru_encode.c
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit e7db7d9

Please sign in to comment.