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 #2335, generalize update header parameter #2336

Merged
merged 1 commit into from
May 22, 2023
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
13 changes: 7 additions & 6 deletions modules/cfe_testcase/src/sb_sendrecv_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ void TestBasicTransmitRecv(void)
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, -100), CFE_SB_BAD_ARGUMENT);

/*
* Note, the CFE_SB_TransmitMsg ignores the "IncrementSequence" flag for commands.
* Thus, all the sequence numbers should come back with the original value set (11)
* Note, the CFE_SB_TransmitMsg now adheres to the "UpdateHeader" flag.
* Thus, the sequence numbers should come back with the value from the Route (1-2)
* rather than the value the message was filled with initially.
*
* Note this also utilizes the CFE_SB_PEND_FOREVER flag - if working correctly,
* there should be a message in the queue, so it should not block.
Expand All @@ -157,15 +158,15 @@ void TestBasicTransmitRecv(void)
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x0c0ffee);
UtAssert_UINT32_EQ(Seq1, 11);
UtAssert_UINT32_EQ(Seq1, 1);

UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &Seq1), CFE_SUCCESS);
CFE_Assert_MSGID_EQ(MsgId, CFE_FT_CMD_MSGID);
CmdPtr = (const CFE_FT_TestCmdMessage_t *)MsgBuf;
UtAssert_UINT32_EQ(CmdPtr->CmdPayload, 0x1c0ffee);
UtAssert_UINT32_EQ(Seq1, 11);
UtAssert_UINT32_EQ(Seq1, 2);

UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_PEND_FOREVER), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetMsgId(&MsgBuf->Msg, &MsgId), CFE_SUCCESS);
Expand Down Expand Up @@ -480,7 +481,7 @@ void TestZeroCopyTransmitRecv(void)
/* Receive and get initial sequence count */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqCmd1), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqCmd1, 1234); /* NOTE: commands currently do NOT honor "Increment" flag */
UtAssert_UINT32_EQ(SeqCmd1, 6); /* NOTE: commands now honor "Update" flag */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqTlm1), CFE_SUCCESS);

Expand All @@ -497,7 +498,7 @@ void TestZeroCopyTransmitRecv(void)
/* Receive and get current sequence count */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId1, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqCmd2), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqCmd2, 1234); /* NOTE: commands currently do NOT honor "Increment" flag */
UtAssert_UINT32_EQ(SeqCmd2, 7); /* NOTE: commands now honor "Update" flag */
UtAssert_INT32_EQ(CFE_SB_ReceiveBuffer(&MsgBuf, PipeId2, CFE_SB_POLL), CFE_SUCCESS);
UtAssert_INT32_EQ(CFE_MSG_GetSequenceCount(&MsgBuf->Msg, &SeqTlm2), CFE_SUCCESS);
UtAssert_UINT32_EQ(SeqTlm2, CFE_MSG_GetNextSequenceCount(SeqTlm1)); /* should be +1 from the previous */
Expand Down
25 changes: 25 additions & 0 deletions modules/core_api/fsw/inc/cfe_msg.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,31 @@
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
CFE_Status_t CFE_MSG_Init(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_MSG_Size_t Size);

/*****************************************************************************/
/**
* \brief Set/compute all dynamically-updated headers on a message
*
* \par Description
* This routine updates all dynamic header fields on a message, and is typically
* invoked via SB just prior to broadcasting the message. Dynamic headers include
* are values that should be computed/updated per message, including:
* - the sequence number
* - the timestamp, if present
* - any error control or checksum fields, if present
*
* The MSG module implementation determines which header fields meet this criteria
* and how they should be computed.
*
* \param[inout] MsgPtr A pointer to the buffer that contains the message @nonnull.
* \param[in] SeqCnt The current sequence number from the message route
*
* \return Execution status, see \ref CFEReturnCodes
* \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
* \retval #CFE_MSG_BAD_ARGUMENT \copybrief CFE_MSG_BAD_ARGUMENT
*/
CFE_Status_t CFE_MSG_UpdateHeader(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t SeqCnt);

/**\}*/

/** \defgroup CFEAPIMSGHeaderPri cFE Message Primary Header APIs
Expand Down
30 changes: 21 additions & 9 deletions modules/core_api/fsw/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -402,26 +402,34 @@ CFE_Status_t CFE_SB_UnsubscribeLocal(CFE_SB_MsgId_t MsgId, CFE_SB_PipeId_t PipeI
** software bus will read the message ID from the message header to
** determine which pipes should receive the message.
**
** In general, the "UpdateHeader" parameter should be passed as "true"
** if the message was newly constructed by the sender and is being sent
** for the first time. When forwarding a message that originated from
** an external entity (e.g. messages passing through CI or SBN), the
** parameter should be passed as "false" to not overwrite existing data.
**
** \par Assumptions, External Events, and Notes:
** - This routine will not normally wait for the receiver tasks to
** process the message before returning control to the caller's task.
** - However, if a higher priority task is pending and subscribed to
** this message, that task may get to run before returning
** control to the caller.
** - In previous versions of CFE, the boolean parameter referred to the
** sequence number header of telemetry messages only. This has been
** extended to apply more generically to any headers, as determined by
** the CFE MSG implementation.
**
** \param[in] MsgPtr A pointer to the message to be sent @nonnull. This must point
** to the first byte of the message header.
** \param[in] IncrementSequenceCount Boolean to increment the internally tracked
** sequence count and update the message if the
** buffer contains a telemetry message
** \param[in] UpdateHeader Update the headers of the message
**
** \return Execution status, see \ref CFEReturnCodes
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
** \retval #CFE_SB_BAD_ARGUMENT \copybrief CFE_SB_BAD_ARGUMENT
** \retval #CFE_SB_MSG_TOO_BIG \copybrief CFE_SB_MSG_TOO_BIG
** \retval #CFE_SB_BUF_ALOC_ERR \covtest \copybrief CFE_SB_BUF_ALOC_ERR
**/
CFE_Status_t CFE_SB_TransmitMsg(const CFE_MSG_Message_t *MsgPtr, bool IncrementSequenceCount);
CFE_Status_t CFE_SB_TransmitMsg(const CFE_MSG_Message_t *MsgPtr, bool UpdateHeader);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -536,6 +544,12 @@ CFE_Status_t CFE_SB_ReleaseMessageBuffer(CFE_SB_Buffer_t *BufPtr);
** internal buffer. The "zero copy" interface can be used to improve
** performance in high-rate, high-volume software bus traffic.
**
** In general, the "UpdateHeader" parameter should be passed as "true"
** if the message was newly constructed by the sender and is being sent
** for the first time. When forwarding a message that originated from
** an external entity (e.g. messages passing through CI or SBN), the
** parameter should be passed as "false" to not overwrite existing data.
**
** \par Assumptions, External Events, and Notes:
** -# A handle returned by #CFE_SB_AllocateMessageBuffer is "consumed" by
** a _successful_ call to #CFE_SB_TransmitBuffer.
Expand All @@ -553,17 +567,15 @@ CFE_Status_t CFE_SB_ReleaseMessageBuffer(CFE_SB_Buffer_t *BufPtr);
** -# This function will increment and apply the internally tracked
** sequence counter if set to do so.
**
** \param[in] BufPtr A pointer to the buffer to be sent @nonnull.
** \param[in] IncrementSequenceCount Boolean to increment the internally tracked
** sequence count and update the message if the
** buffer contains a telemetry message
** \param[in] BufPtr A pointer to the buffer to be sent @nonnull.
** \param[in] UpdateHeader Update the headers of the message
**
** \return Execution status, see \ref CFEReturnCodes
** \retval #CFE_SUCCESS \copybrief CFE_SUCCESS
** \retval #CFE_SB_BAD_ARGUMENT \copybrief CFE_SB_BAD_ARGUMENT
** \retval #CFE_SB_MSG_TOO_BIG \copybrief CFE_SB_MSG_TOO_BIG
**/
CFE_Status_t CFE_SB_TransmitBuffer(CFE_SB_Buffer_t *BufPtr, bool IncrementSequenceCount);
CFE_Status_t CFE_SB_TransmitBuffer(CFE_SB_Buffer_t *BufPtr, bool UpdateHeader);

/** @} */

Expand Down
4 changes: 2 additions & 2 deletions modules/core_api/ut-stubs/src/cfe_config_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
#include "cfe_config.h"
#include "utgenstub.h"

extern void UT_DefaultHandler_CFE_Config_GetObjPointer(void *, UT_EntryKey_t, const UT_StubContext_t *);
extern void UT_DefaultHandler_CFE_Config_GetString(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CFE_Config_GetObjPointer(void *, UT_EntryKey_t, const UT_StubContext_t *);
void UT_DefaultHandler_CFE_Config_GetString(void *, UT_EntryKey_t, const UT_StubContext_t *);

/*
* ----------------------------------------------------
Expand Down
43 changes: 43 additions & 0 deletions modules/core_api/ut-stubs/src/cfe_error_stubs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/************************************************************************
* 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
*
* Auto-Generated stub implementations for functions defined in cfe_error header
*/

#include "cfe_error.h"
#include "utgenstub.h"

/*
* ----------------------------------------------------
* Generated stub function for CFE_ES_StatusToString()
* ----------------------------------------------------
*/
char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string)
{
UT_GenStub_SetupReturnBuffer(CFE_ES_StatusToString, char *);

UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_Status_t, status);
UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_StatusString_t *, status_string);

UT_GenStub_Execute(CFE_ES_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_ES_StatusToString, char *);
}
21 changes: 4 additions & 17 deletions modules/core_api/ut-stubs/src/cfe_es_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ CFE_Status_t CFE_ES_AppID_ToIndex(CFE_ES_AppId_t AppID, uint32 *Idx)
*/
void CFE_ES_BackgroundWakeup(void)
{

UT_GenStub_Execute(CFE_ES_BackgroundWakeup, Basic, NULL);
}

Expand Down Expand Up @@ -216,6 +217,7 @@ void CFE_ES_ExitApp(uint32 ExitStatus)
*/
void CFE_ES_ExitChildTask(void)
{

UT_GenStub_Execute(CFE_ES_ExitChildTask, Basic, NULL);
}

Expand Down Expand Up @@ -602,6 +604,7 @@ CFE_Status_t CFE_ES_IncrementGenCounter(CFE_ES_CounterId_t CounterId)
*/
void CFE_ES_IncrementTaskCounter(void)
{

UT_GenStub_Execute(CFE_ES_IncrementTaskCounter, Basic, NULL);
}

Expand Down Expand Up @@ -731,6 +734,7 @@ int32 CFE_ES_PoolDelete(CFE_ES_MemHandle_t PoolID)
*/
void CFE_ES_ProcessAsyncEvent(void)
{

UT_GenStub_Execute(CFE_ES_ProcessAsyncEvent, Basic, NULL);
}

Expand Down Expand Up @@ -950,20 +954,3 @@ CFE_Status_t CFE_ES_WriteToSysLog(const char *SpecStringPtr, ...)

return UT_GenStub_GetReturnValue(CFE_ES_WriteToSysLog, CFE_Status_t);
}

/*
* ----------------------------------------------------
* Generated stub function for CFE_ES_StatusToString()
* ----------------------------------------------------
*/
char *CFE_ES_StatusToString(CFE_Status_t status, CFE_StatusString_t *status_string)
{
UT_GenStub_SetupReturnBuffer(CFE_ES_StatusToString, char *);

UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_Status_t, status);
UT_GenStub_AddParam(CFE_ES_StatusToString, CFE_StatusString_t *, status_string);

UT_GenStub_Execute(CFE_ES_StatusToString, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_ES_StatusToString, char *);
}
17 changes: 17 additions & 0 deletions modules/core_api/ut-stubs/src/cfe_msg_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,23 @@ CFE_Status_t CFE_MSG_SetType(CFE_MSG_Message_t *MsgPtr, CFE_MSG_Type_t Type)
return UT_GenStub_GetReturnValue(CFE_MSG_SetType, CFE_Status_t);
}

/*
* ----------------------------------------------------
* Generated stub function for CFE_MSG_UpdateHeader()
* ----------------------------------------------------
*/
CFE_Status_t CFE_MSG_UpdateHeader(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t SeqCnt)
{
UT_GenStub_SetupReturnBuffer(CFE_MSG_UpdateHeader, CFE_Status_t);

UT_GenStub_AddParam(CFE_MSG_UpdateHeader, CFE_MSG_Message_t *, MsgPtr);
UT_GenStub_AddParam(CFE_MSG_UpdateHeader, CFE_MSG_SequenceCount_t, SeqCnt);

UT_GenStub_Execute(CFE_MSG_UpdateHeader, Basic, NULL);

return UT_GenStub_GetReturnValue(CFE_MSG_UpdateHeader, CFE_Status_t);
}

/*
* ----------------------------------------------------
* Generated stub function for CFE_MSG_ValidateChecksum()
Expand Down
8 changes: 4 additions & 4 deletions modules/core_api/ut-stubs/src/cfe_sb_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,12 +384,12 @@ void CFE_SB_TimeStampMsg(CFE_MSG_Message_t *MsgPtr)
* Generated stub function for CFE_SB_TransmitBuffer()
* ----------------------------------------------------
*/
CFE_Status_t CFE_SB_TransmitBuffer(CFE_SB_Buffer_t *BufPtr, bool IncrementSequenceCount)
CFE_Status_t CFE_SB_TransmitBuffer(CFE_SB_Buffer_t *BufPtr, bool UpdateHeader)
{
UT_GenStub_SetupReturnBuffer(CFE_SB_TransmitBuffer, CFE_Status_t);

UT_GenStub_AddParam(CFE_SB_TransmitBuffer, CFE_SB_Buffer_t *, BufPtr);
UT_GenStub_AddParam(CFE_SB_TransmitBuffer, bool, IncrementSequenceCount);
UT_GenStub_AddParam(CFE_SB_TransmitBuffer, bool, UpdateHeader);

UT_GenStub_Execute(CFE_SB_TransmitBuffer, Basic, UT_DefaultHandler_CFE_SB_TransmitBuffer);

Expand All @@ -401,12 +401,12 @@ CFE_Status_t CFE_SB_TransmitBuffer(CFE_SB_Buffer_t *BufPtr, bool IncrementSequen
* Generated stub function for CFE_SB_TransmitMsg()
* ----------------------------------------------------
*/
CFE_Status_t CFE_SB_TransmitMsg(const CFE_MSG_Message_t *MsgPtr, bool IncrementSequenceCount)
CFE_Status_t CFE_SB_TransmitMsg(const CFE_MSG_Message_t *MsgPtr, bool UpdateHeader)
{
UT_GenStub_SetupReturnBuffer(CFE_SB_TransmitMsg, CFE_Status_t);

UT_GenStub_AddParam(CFE_SB_TransmitMsg, const CFE_MSG_Message_t *, MsgPtr);
UT_GenStub_AddParam(CFE_SB_TransmitMsg, bool, IncrementSequenceCount);
UT_GenStub_AddParam(CFE_SB_TransmitMsg, bool, UpdateHeader);

UT_GenStub_Execute(CFE_SB_TransmitMsg, Basic, UT_DefaultHandler_CFE_SB_TransmitMsg);

Expand Down
2 changes: 2 additions & 0 deletions modules/core_api/ut-stubs/src/cfe_time_stubs.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ void CFE_TIME_ExternalTime(CFE_TIME_SysTime_t NewTime)
*/
void CFE_TIME_ExternalTone(void)
{

UT_GenStub_Execute(CFE_TIME_ExternalTone, Basic, NULL);
}

Expand Down Expand Up @@ -263,6 +264,7 @@ CFE_TIME_SysTime_t CFE_TIME_GetUTC(void)
*/
void CFE_TIME_Local1HzISR(void)
{

UT_GenStub_Execute(CFE_TIME_Local1HzISR, Basic, NULL);
}

Expand Down
32 changes: 32 additions & 0 deletions modules/msg/fsw/src/cfe_msg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "cfe_msg.h"
#include "cfe_msg_priv.h"
#include "cfe_msg_defaults.h"
#include "cfe_time.h"
#include "string.h"

/*----------------------------------------------------------------
Expand Down Expand Up @@ -52,3 +53,34 @@ CFE_Status_t CFE_MSG_Init(CFE_MSG_Message_t *MsgPtr, CFE_SB_MsgId_t MsgId, CFE_M

return status;
}

/*----------------------------------------------------------------
*
* Implemented per public API
* See description in header file for argument/return detail
*
*-----------------------------------------------------------------*/
CFE_Status_t CFE_MSG_UpdateHeader(CFE_MSG_Message_t *MsgPtr, CFE_MSG_SequenceCount_t SeqCnt)
{
if (MsgPtr == NULL)
{
return CFE_MSG_BAD_ARGUMENT;
}

/* Sequence count is in the basic CCSDS Primary Hdr, so all msgs have it */
CFE_MSG_SetSequenceCount(MsgPtr, SeqCnt);

/*
* TLM packets have a timestamp in the secondary header.
* This may fail if this is not a TLM packet (that is OK)
*/
CFE_MSG_SetMsgTime(MsgPtr, CFE_TIME_GetTime());

/*
* CMD packets have a checksum in the secondary header.
* This may fail if this is not a CMD packet (that is OK)
*/
CFE_MSG_GenerateChecksum(MsgPtr);

return CFE_SUCCESS;
}
1 change: 1 addition & 0 deletions modules/msg/ut-coverage/msg_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ void UtTest_Setup(void)
UtPrintf("Message header coverage test...");

UT_ADD_TEST(Test_MSG_Init);
UT_ADD_TEST(Test_MSG_UpdateHeader);
Test_MSG_CCSDSPri();
Test_MSG_CCSDSExt();
Test_MSG_MsgId_Shared();
Expand Down
Loading