Skip to content

Commit

Permalink
Fix nasa#2335, generalize update header parameter
Browse files Browse the repository at this point in the history
Expand the "Increment Sequence" boolean on transmit message functions to
be a more general "Update Header" boolean, so it can be used for other
fields like timestamps, checksums, or user-defined fields too.
  • Loading branch information
jphickey committed May 17, 2023
1 parent 4deea95 commit c13e761
Show file tree
Hide file tree
Showing 18 changed files with 224 additions and 65 deletions.
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
37 changes: 37 additions & 0 deletions modules/msg/ut-coverage/test_cfe_msg_init.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,40 @@ void Test_MSG_Init(void)
UtAssert_UINT32_EQ(Test_MSG_Pri_NotZero(CFE_MSG_PTR(cmd)) & ~MSG_HDRVER_FLAG,
MSG_APID_FLAG | MSG_HASSEC_FLAG | MSG_TYPE_FLAG | MSG_LENGTH_FLAG | MSG_SEGMENT_FLAG);
}

/*
* Test MSG Update Header
*/
void Test_MSG_UpdateHeader(void)
{
union
{
CFE_MSG_Message_t msg;
CFE_MSG_CommandHeader_t cmd;
CFE_MSG_TelemetryHeader_t tlm;

} LocalBuf;
CFE_MSG_SequenceCount_t SeqCnt;
CFE_MSG_SequenceCount_t CheckCnt;

memset(&LocalBuf, 0, sizeof(LocalBuf));
SeqCnt = 1;
CheckCnt = 0;

/* bad buffer */
UtAssert_INT32_EQ(CFE_MSG_UpdateHeader(NULL, SeqCnt), CFE_MSG_BAD_ARGUMENT);

/* nominal, cmd */
CFE_MSG_SetType(&LocalBuf.msg, CFE_MSG_Type_Cmd);
CFE_UtAssert_SUCCESS(CFE_MSG_UpdateHeader(&LocalBuf.msg, SeqCnt));
CFE_MSG_GetSequenceCount(&LocalBuf.msg, &CheckCnt);
UtAssert_UINT32_EQ(CheckCnt, SeqCnt);
++SeqCnt;

/* nominal, tlm */
CFE_MSG_SetType(&LocalBuf.msg, CFE_MSG_Type_Tlm);
CFE_UtAssert_SUCCESS(CFE_MSG_UpdateHeader(&LocalBuf.msg, SeqCnt));
CFE_MSG_GetSequenceCount(&LocalBuf.msg, &CheckCnt);
UtAssert_UINT32_EQ(CheckCnt, SeqCnt);
++SeqCnt;
}
1 change: 1 addition & 0 deletions modules/msg/ut-coverage/test_cfe_msg_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@
*/
/* Test extended header mission functionality */
void Test_MSG_Init(void);
void Test_MSG_UpdateHeader(void);

#endif /* TEST_CFE_MSG_INIT_H */
Loading

0 comments on commit c13e761

Please sign in to comment.