Skip to content

Commit

Permalink
Merge pull request #295 from acudmore/fix-224-support-dynamic-pdu-pkts
Browse files Browse the repository at this point in the history
Fix #224, support dynamic pdu packets
  • Loading branch information
dzbaker committed Aug 3, 2022
2 parents f6fbc87 + 900c71a commit 0442109
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 43 deletions.
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;
int32 status;
const int chan_num = (c - CF_AppData.engine.channels);
CFE_SB_Buffer_t * bufptr;
CFE_MSG_Size_t msg_size;
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);
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

0 comments on commit 0442109

Please sign in to comment.