Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #224, support dynamic pdu packets #295

Merged
merged 3 commits into from Aug 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions fsw/src/cf_cfdp_sbintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@

#include "cf_cfdp_r.h"
#include "cf_cfdp_s.h"
#include "cf_cfdp_sbintf.h"

#include <string.h>
#include "cf_assert.h"
Expand Down Expand Up @@ -101,7 +102,7 @@ CF_Logical_PduBuffer_t *CF_CFDP_MsgOutGet(const CF_Transaction_t *t, bool silent
/* Allocate message buffer on success */
if (os_status == OS_SUCCESS)
{
CF_AppData.engine.out.msg = CFE_SB_AllocateMessageBuffer(offsetof(CF_PduSendMsg_t, ph) + CF_MAX_PDU_SIZE);
CF_AppData.engine.out.msg = CFE_SB_AllocateMessageBuffer(offsetof(CF_PduTlmMsg_t, ph) + CF_MAX_PDU_SIZE);
}

if (!CF_AppData.engine.out.msg)
Expand Down Expand Up @@ -130,8 +131,8 @@ CF_Logical_PduBuffer_t *CF_CFDP_MsgOutGet(const CF_Transaction_t *t, bool silent
/* if returning a buffer, then reset the encoder state to point to the beginning of the encapsulation msg */
if (success && ret != NULL)
{
CF_CFDP_EncodeStart(&CF_AppData.engine.out.encode, CF_AppData.engine.out.msg, ret,
offsetof(CF_PduSendMsg_t, ph), offsetof(CF_PduSendMsg_t, ph) + CF_MAX_PDU_SIZE);
CF_CFDP_EncodeStart(&CF_AppData.engine.out.encode, CF_AppData.engine.out.msg, ret, offsetof(CF_PduTlmMsg_t, ph),
offsetof(CF_PduTlmMsg_t, ph) + CF_MAX_PDU_SIZE);
}

return ret;
Expand All @@ -153,7 +154,7 @@ void CF_CFDP_Send(uint8 chan_num, const CF_Logical_PduBuffer_t *ph)

/* now handle the SB encapsulation - this should reflect the
* length of the entire message, including encapsulation */
sb_msgsize = offsetof(CF_PduSendMsg_t, ph);
sb_msgsize = offsetof(CF_PduTlmMsg_t, ph);
sb_msgsize += ph->pdu_header.header_encoded_length;
sb_msgsize += ph->pdu_header.data_encoded_length;

Expand All @@ -176,12 +177,14 @@ void CF_CFDP_Send(uint8 chan_num, const CF_Logical_PduBuffer_t *ph)
*-----------------------------------------------------------------*/
void CF_CFDP_ReceiveMessage(CF_Channel_t *c)
{
CF_Transaction_t * t; /* initialized below */
uint32 count = 0;
int32 status;
const int chan_num = (c - CF_AppData.engine.channels);
CFE_SB_Buffer_t * bufptr;
CFE_MSG_Size_t msg_size;
CF_Transaction_t *t; /* initialized below */
uint32 count = 0;

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

count uses the basic integral type unsigned int rather than a typedef with size and signedness.
int32 status;

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

status uses the basic integral type signed int rather than a typedef with size and signedness.
const int chan_num = (c - CF_AppData.engine.channels);

Check warning

Code scanning / CodeQL-coding-standard

Unchecked function argument

This use of parameter c has not been checked.

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

chan_num uses the basic integral type int rather than a typedef with size and signedness.
CFE_SB_Buffer_t * bufptr;
CFE_MSG_Size_t msg_size;

Check notice

Code scanning / CodeQL-coding-standard

Use of basic integral type

msg_size uses the basic integral type unsigned long rather than a typedef with size and signedness.
CFE_MSG_Type_t msg_type = CFE_MSG_Type_Invalid;

CF_Logical_PduBuffer_t *ph;

for (; count < CF_AppData.config_table->chan[chan_num].rx_max_messages_per_wakeup; ++count)
Expand All @@ -200,7 +203,15 @@ void CF_CFDP_ReceiveMessage(CF_Channel_t *c)
ph = &CF_AppData.engine.in.rx_pdudata;
CFE_ES_PerfLogEntry(CF_PERF_ID_PDURCVD(chan_num));
CFE_MSG_GetSize(&bufptr->Msg, &msg_size);
CF_CFDP_DecodeStart(&CF_AppData.engine.in.decode, bufptr, ph, offsetof(CF_PduRecvMsg_t, ph), msg_size);
CFE_MSG_GetType(&bufptr->Msg, &msg_type);

Check warning

Code scanning / CodeQL-coding-standard

Unchecked return value

The return value of non-void function [CFE_MSG_GetType](1) is not checked.
if (msg_type == CFE_MSG_Type_Tlm)
{
CF_CFDP_DecodeStart(&CF_AppData.engine.in.decode, bufptr, ph, offsetof(CF_PduTlmMsg_t, ph), msg_size);
}
else
{
CF_CFDP_DecodeStart(&CF_AppData.engine.in.decode, bufptr, ph, offsetof(CF_PduCmdMsg_t, ph), msg_size);
}
if (!CF_CFDP_RecvPh(chan_num, ph))
{
/* got a valid pdu -- look it up by sequence number */
Expand Down
32 changes: 32 additions & 0 deletions fsw/src/cf_cfdp_sbintf.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,38 @@

#include "cf_cfdp_types.h"

/**
* @brief PDU command encapsulation structure
*
* This encapsulates a CFDP pdu into a format that is sent or received over the
* software bus, adding "command" encapsulation (even though these are not really
* commands).
*
* @note this is only the definition of the header. In reality all messages are
* larger than this, up to CF_MAX_PDU_SIZE.
*/
typedef struct CF_PduCmdMsg
{
CFE_MSG_CommandHeader_t hdr; /**< \brief software bus headers, not really used by CF */
CF_CFDP_PduHeader_t ph; /**< \brief Beginning of CFDP headers */
} CF_PduCmdMsg_t;

/**
* @brief PDU send encapsulation structure
*
* This encapsulates a CFDP pdu into a format that is sent or received over the
* software bus, adding "telemetry" encapsulation (even though these are not really
* telemetry items).
*
* @note this is only the definition of the header. In reality all messages are
* larger than this, up to CF_MAX_PDU_SIZE.
*/
typedef struct CF_PduTlmMsg
{
CFE_MSG_TelemetryHeader_t hdr; /**< \brief software bus headers, not really used by CF */
CF_CFDP_PduHeader_t ph; /**< \brief Beginning of CFDP headers */
} CF_PduTlmMsg_t;

/************************************************************************/
/** @brief Obtain a message buffer to construct a PDU inside.
*
Expand Down
30 changes: 0 additions & 30 deletions fsw/src/cf_cfdp_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,36 +402,6 @@ typedef struct CF_Channel
* structures are both longer than these definitions. They are always backed by a buffer
* of size CF_MAX_PDU_SIZE */

/**
* @brief PDU receive encapsulation structure
*
* This encapsulates a CFDP pdu into a format that is received over the software bus,
* adding "command" encapsulation (even though these are not really commands).
*
* @note this is only the definition of the header. In reality all messages are
* larger than this, up to CF_MAX_PDU_SIZE.
*/
typedef struct CF_PduRecvMsg
{
CFE_MSG_CommandHeader_t hdr; /**< \brief software bus headers, not really used by CF */
CF_CFDP_PduHeader_t ph; /**< \brief Beginning of CFDP headers */
} CF_PduRecvMsg_t;

/**
* @brief PDU send encapsulation structure
*
* This encapsulates a CFDP pdu into a format that is sent over the software bus,
* adding "telemetry" encapsulation (even though these are not really telemetry items).
*
* @note this is only the definition of the header. In reality all messages are
* larger than this, up to CF_MAX_PDU_SIZE.
*/
typedef struct CF_PduSendMsg
{
CFE_MSG_TelemetryHeader_t hdr; /**< \brief software bus headers, not really used by CF */
CF_CFDP_PduHeader_t ph; /**< \brief Beginning of CFDP headers */
} CF_PduSendMsg_t;

/**
* @brief CF engine output state
*
Expand Down
17 changes: 15 additions & 2 deletions unit-test/cf_cfdp_sbintf_tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

static union
{
CF_PduRecvMsg_t cf_msg;
CF_PduCmdMsg_t cf_msg;
CFE_SB_Buffer_t sb_buf;
uint8 bytes[CF_MAX_PDU_SIZE];
} UT_r_msg;

static union
{
CF_PduRecvMsg_t cf_msg;
CF_PduTlmMsg_t cf_msg;
CFE_SB_Buffer_t sb_buf;
uint8 bytes[CF_MAX_PDU_SIZE];
} UT_s_msg;
Expand All @@ -50,6 +50,7 @@ static void UT_CFDP_SetupBasicRxState(CF_Logical_PduBuffer_t *pdu_buffer)
static uint8 bytes[CF_CFDP_MAX_HEADER_SIZE];
CFE_SB_Buffer_t * bufptr;
CFE_MSG_Size_t sz;
CFE_MSG_Type_t msg_type = CFE_MSG_Type_Cmd;

memset(pdu_buffer, 0, sizeof(*pdu_buffer));
memset(bytes, 0, sizeof(bytes));
Expand All @@ -68,6 +69,9 @@ static void UT_CFDP_SetupBasicRxState(CF_Logical_PduBuffer_t *pdu_buffer)
/* setup for a potential call to CFE_MSG_GetSize() */
sz = sizeof(UT_r_msg);
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetSize), &sz, sizeof(sz), true);

/* setup for a potential call to CFE_MSG_GetType() */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &msg_type, sizeof(msg_type), false);
}

static void UT_CFDP_SetupBasicTxState(CF_Logical_PduBuffer_t *pdu_buffer)
Expand Down Expand Up @@ -216,6 +220,7 @@ void Test_CF_CFDP_ReceiveMessage(void)
CF_ConfigTable_t * config;
CF_Transaction_t * t;
CF_Logical_PduBuffer_t *ph;
CFE_MSG_Type_t msg_type = CFE_MSG_Type_Tlm;

/* no-config - the max per wakeup will be 0, and this is a noop */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_NONE, NULL, &c, NULL, NULL, NULL);
Expand Down Expand Up @@ -245,6 +250,14 @@ void Test_CF_CFDP_ReceiveMessage(void)
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_RecvPh), 1, -1);
UtAssert_VOIDCALL(CF_CFDP_ReceiveMessage(c));

/* Test the path where the function recieves a telemetry packet on it's pipe */
UT_CFDP_SetupBasicTestState(UT_CF_Setup_RX, NULL, &c, NULL, &t, &config);
UT_SetDeferredRetcode(UT_KEY(CF_CFDP_RecvPh), 1, -1);
/* Override message type to take the command branch of the if then/else clause */
UT_ResetState(UT_KEY(CFE_MSG_GetType)); /* clears the previous cmd type */
UT_SetDataBuffer(UT_KEY(CFE_MSG_GetType), &msg_type, sizeof(msg_type), false);
UtAssert_VOIDCALL(CF_CFDP_ReceiveMessage(c));

/*
* - CF_CFDP_RecvPh() succeeds
* - CF_FindTransactionBySequenceNumber() returns non-NULL
Expand Down