From 8b1c26d2c52d61197de46bafdc0e0db506285705 Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Mon, 1 Aug 2022 06:27:18 -0700 Subject: [PATCH 1/3] Fix #224, Support incoming PDUs as CMD or TLM --- fsw/src/cf_cfdp_sbintf.c | 19 +++++++++++++++---- fsw/src/cf_cfdp_sbintf.h | 32 ++++++++++++++++++++++++++++++++ fsw/src/cf_cfdp_types.h | 30 ------------------------------ unit-test/cf_cfdp_sbintf_tests.c | 16 ++++++++++++++-- 4 files changed, 61 insertions(+), 36 deletions(-) diff --git a/fsw/src/cf_cfdp_sbintf.c b/fsw/src/cf_cfdp_sbintf.c index 109b1e0a..f6a1984a 100644 --- a/fsw/src/cf_cfdp_sbintf.c +++ b/fsw/src/cf_cfdp_sbintf.c @@ -47,6 +47,7 @@ #include "cf_cfdp_r.h" #include "cf_cfdp_s.h" +#include "cf_cfdp_sbintf.h" #include #include "cf_assert.h" @@ -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) @@ -131,7 +132,7 @@ CF_Logical_PduBuffer_t *CF_CFDP_MsgOutGet(const CF_Transaction_t *t, bool silent 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); + offsetof(CF_PduTlmMsg_t, ph), offsetof(CF_PduTlmMsg_t, ph) + CF_MAX_PDU_SIZE); } return ret; @@ -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; @@ -182,6 +183,8 @@ void CF_CFDP_ReceiveMessage(CF_Channel_t *c) 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) @@ -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 */ diff --git a/fsw/src/cf_cfdp_sbintf.h b/fsw/src/cf_cfdp_sbintf.h index 704bdf19..142b5d29 100644 --- a/fsw/src/cf_cfdp_sbintf.h +++ b/fsw/src/cf_cfdp_sbintf.h @@ -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. * diff --git a/fsw/src/cf_cfdp_types.h b/fsw/src/cf_cfdp_types.h index ad2d409b..a0061acc 100644 --- a/fsw/src/cf_cfdp_types.h +++ b/fsw/src/cf_cfdp_types.h @@ -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 * diff --git a/unit-test/cf_cfdp_sbintf_tests.c b/unit-test/cf_cfdp_sbintf_tests.c index 8bc01aca..879234f9 100644 --- a/unit-test/cf_cfdp_sbintf_tests.c +++ b/unit-test/cf_cfdp_sbintf_tests.c @@ -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; @@ -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)); @@ -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) @@ -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); @@ -245,6 +250,13 @@ 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_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 From 9815dcd2883a0f127f47c533ca8d92ecc0365df2 Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Mon, 1 Aug 2022 13:55:49 -0700 Subject: [PATCH 2/3] Fix #224, Correct format errors --- fsw/src/cf_cfdp_sbintf.c | 18 +++++++++--------- unit-test/cf_cfdp_sbintf_tests.c | 4 ++-- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/fsw/src/cf_cfdp_sbintf.c b/fsw/src/cf_cfdp_sbintf.c index f6a1984a..4288c232 100644 --- a/fsw/src/cf_cfdp_sbintf.c +++ b/fsw/src/cf_cfdp_sbintf.c @@ -131,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_PduTlmMsg_t, ph), offsetof(CF_PduTlmMsg_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; @@ -177,13 +177,13 @@ 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; - CFE_MSG_Type_t msg_type = CFE_MSG_Type_Invalid; + 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; diff --git a/unit-test/cf_cfdp_sbintf_tests.c b/unit-test/cf_cfdp_sbintf_tests.c index 879234f9..4fcd3c4f 100644 --- a/unit-test/cf_cfdp_sbintf_tests.c +++ b/unit-test/cf_cfdp_sbintf_tests.c @@ -26,14 +26,14 @@ static union { - CF_PduCmdMsg_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_PduTlmMsg_t cf_msg; + CF_PduTlmMsg_t cf_msg; CFE_SB_Buffer_t sb_buf; uint8 bytes[CF_MAX_PDU_SIZE]; } UT_s_msg; From 900c71adea857a2f66d422dc6fc4d120d27e093d Mon Sep 17 00:00:00 2001 From: Alan Cudmore Date: Tue, 2 Aug 2022 06:25:55 -0700 Subject: [PATCH 3/3] Fix #224, fix unit test coverage error --- unit-test/cf_cfdp_sbintf_tests.c | 1 + 1 file changed, 1 insertion(+) diff --git a/unit-test/cf_cfdp_sbintf_tests.c b/unit-test/cf_cfdp_sbintf_tests.c index 4fcd3c4f..c37f31ac 100644 --- a/unit-test/cf_cfdp_sbintf_tests.c +++ b/unit-test/cf_cfdp_sbintf_tests.c @@ -254,6 +254,7 @@ void Test_CF_CFDP_ReceiveMessage(void) 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));