Skip to content

Commit

Permalink
Work in progress on modular message formats
Browse files Browse the repository at this point in the history
All message header field access is done via an accessor which
is implemented in an external library
  • Loading branch information
jphickey committed Jun 1, 2020
1 parent 64a8a7a commit 6861acb
Show file tree
Hide file tree
Showing 12 changed files with 374 additions and 449 deletions.
17 changes: 17 additions & 0 deletions cmake/cfe_sb_msgformat_accessors.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* CFE Software Bus Message header format configuration
* The copy of this file in build/inc is generated by CMake, do not edit.
*/

#ifndef INCLUDE_CFE_SB_MSGFORMAT_ACCESSORS_H
#define INCLUDE_CFE_SB_MSGFORMAT_ACCESSORS_H

#include <@MISSION_SB_MSGFORMAT_LIBNAME@_accessors.h>

/*
* Message accessor functions shall use a @MISSION_SB_MSGFORMAT@ prefix
*/
#define CFE_SB_MSGFORMAT_FUNCNAME(x) @MISSION_SB_MSGFORMAT@_ ## x

#endif /* INCLUDE_CFE_SB_MSGFORMAT_ACCESSORS_H */

17 changes: 17 additions & 0 deletions cmake/cfe_sb_msgformat_types.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* CFE Software Bus Message header format configuration
* The copy of this file in build/inc is generated by CMake, do not edit.
*/

#ifndef INCLUDE_CFE_SB_MSGFORMAT_TYPES_H
#define INCLUDE_CFE_SB_MSGFORMAT_TYPES_H

#include <@MISSION_SB_MSGFORMAT_LIBNAME@_types.h>

/*
* Message header types shall use a @MISSION_SB_MSGFORMAT@ prefix
*/
#define CFE_SB_MSGFORMAT_TYPE(x) @MISSION_SB_MSGFORMAT@_ ## x ## _t

#endif /* INCLUDE_CFE_SB_MSGFORMAT_TYPES_H */

20 changes: 19 additions & 1 deletion cmake/mission_build.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ function(prepare)
add_custom_target(mission-clean COMMAND $(MAKE) clean)
add_custom_target(mission-prebuild)

# The convention should be that there is a library/module name
# matching the Software Bus message format name. The library
# names are always lower case, per file naming conventions.
string(TOLOWER "${MISSION_SB_MSGFORMAT}" MISSION_SB_MSGFORMAT_LIBNAME)

# Locate the source location for all the apps found within the target file
# Each of those may in turn have a "mission_build" file that calls out additional dependencies for that app,
# so this is run in a loop until the list of unfound apps is empty
Expand Down Expand Up @@ -245,7 +250,20 @@ function(prepare)

configure_file("${CFE_SOURCE_DIR}/cmake/osalguide.doxyfile.in"
"${CMAKE_BINARY_DIR}/doc/osalguide.doxyfile")



# generate a header file for the message header format abstraction
# this is based on the header format configured in targets.cmake
if (NOT DEFINED ${MISSION_SB_MSGFORMAT_LIBNAME}_MISSION_DIR)
message(FATAL_ERROR "No core library found corresponding to message format ${MISSION_SB_MSGFORMAT}")
endif()

configure_file("${CFE_SOURCE_DIR}/cmake/cfe_sb_msgformat_types.h.in"
"${CMAKE_BINARY_DIR}/inc/cfe_sb_msgformat_types.h")

configure_file("${CFE_SOURCE_DIR}/cmake/cfe_sb_msgformat_accessors.h.in"
"${CMAKE_BINARY_DIR}/inc/cfe_sb_msgformat_accessors.h")

add_custom_target(mission-doc
doxygen mission-detaildesign.doxyfile
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}/doc")
Expand Down
1 change: 1 addition & 0 deletions fsw/cfe-core/src/evs/cfe_evs_task.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ bool CFE_EVS_VerifyCmdLength(CFE_SB_MsgPtr_t Msg, uint16 ExpectedLength);

/* Function Definitions */

extern

/*
** Function Prologue
Expand Down
1 change: 1 addition & 0 deletions fsw/cfe-core/src/inc/ccsds.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#ifndef _ccsds_
#define _ccsds_

#error "should not include this"
/*
** Include Files
*/
Expand Down
35 changes: 20 additions & 15 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
#include "cfe_psp.h"
#include "common_types.h"
#include "cfe_mission_cfg.h"
#include "ccsds.h"
#include "cfe_sb_msgformat_types.h"
#include "cfe_time.h"


Expand Down Expand Up @@ -147,22 +147,27 @@
*/

/** \brief Generic Software Bus Message Type Definition */
typedef union {
CCSDS_PriHdr_t Hdr; /**< \brief CCSDS Primary Header #CCSDS_PriHdr_t */
CCSDS_SpacePacket_t SpacePacket;
uint32 Dword; /**< \brief Forces minimum of 32-bit alignment for this object */
uint8 Byte[sizeof(CCSDS_PriHdr_t)]; /**< \brief Allows byte-level access */
}CFE_SB_Msg_t;
typedef union
{
CFE_SB_MSGFORMAT_TYPE(BaseHeader) Base;

uint32 Dword; /**< \brief Forces minimum of 32-bit alignment for this object */
uint8 Byte[4]; /**< \brief Allows byte-level access */
} CFE_SB_Msg_t;

/** \brief Generic Software Bus Command Header Type Definition */
typedef union {
CCSDS_CommandPacket_t Cmd;
typedef union
{
CFE_SB_MSGFORMAT_TYPE(CommandPacket) Cmd;

CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */
} CFE_SB_CmdHdr_t;

/** \brief Generic Software Bus Telemetry Header Type Definition */
typedef union {
CCSDS_TelemetryPacket_t Tlm;
typedef union
{
CFE_SB_MSGFORMAT_TYPE(TelemetryPacket) Tlm;

CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */
} CFE_SB_TlmHdr_t;

Expand Down Expand Up @@ -896,7 +901,7 @@ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr,
** \sa #CFE_SB_SetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_SetTotalMsgLength,
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode, #CFE_SB_InitMsg
**/
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,uint16 DataLength);
void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,uint32 DataLength);

/*****************************************************************************/
/**
Expand All @@ -921,7 +926,7 @@ void CFE_SB_SetUserDataLength(CFE_SB_MsgPtr_t MsgPtr,uint16 DataLength);
** \sa #CFE_SB_SetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** #CFE_SB_SetMsgTime, #CFE_SB_TimeStampMsg, #CFE_SB_SetCmdCode, #CFE_SB_InitMsg
**/
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint16 TotalLength);
void CFE_SB_SetTotalMsgLength(CFE_SB_MsgPtr_t MsgPtr,uint32 TotalLength);

/*****************************************************************************/
/**
Expand Down Expand Up @@ -1103,7 +1108,7 @@ CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr);
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_SetUserDataLength, #CFE_SB_GetTotalMsgLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);
uint32 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);

/*****************************************************************************/
/**
Expand All @@ -1124,7 +1129,7 @@ uint16 CFE_SB_GetUserDataLength(const CFE_SB_Msg_t *MsgPtr);
** \sa #CFE_SB_GetUserData, #CFE_SB_GetMsgId, #CFE_SB_GetUserDataLength, #CFE_SB_SetTotalMsgLength,
** #CFE_SB_GetMsgTime, #CFE_SB_GetCmdCode, #CFE_SB_GetChecksum
**/
uint16 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr);
uint32 CFE_SB_GetTotalMsgLength(const CFE_SB_Msg_t *MsgPtr);

/*****************************************************************************/
/**
Expand Down
122 changes: 0 additions & 122 deletions fsw/cfe-core/src/sb/ccsds.c

This file was deleted.

73 changes: 0 additions & 73 deletions fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
** Include Files
*/
#include "cfe_mission_cfg.h"
#include "ccsds.h"
#include "cfe_sb.h"
#include "osapi.h"
#include "cfe_error.h"
Expand Down Expand Up @@ -115,83 +114,11 @@ CFE_SB_MsgKey_t CFE_SB_ConvertMsgIdtoMsgKey( CFE_SB_MsgId_t MsgId)
return CFE_SB_ValueToMsgKey(CFE_SB_MsgIdToValue(MsgId));
}/* CFE_SB_ConvertMsgIdtoMsgKey */

/*
* Function: CFE_SB_GetMsgId - See API and header file for details
*/
CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr)
{
CFE_SB_MsgId_Atom_t MsgIdVal = 0;

#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
MsgIdVal = CCSDS_RD_SID(MsgPtr->Hdr);
#else

uint32 SubSystemId;

MsgIdVal = CCSDS_RD_APID(MsgPtr->Hdr); /* Primary header APID */

if ( CCSDS_RD_TYPE(MsgPtr->Hdr) == CCSDS_CMD)
MsgIdVal = MsgIdVal | CFE_SB_CMD_MESSAGE_TYPE;

/* Add in the SubSystem ID as needed */
SubSystemId = CCSDS_RD_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ);
MsgIdVal = (MsgIdVal | (SubSystemId << 8));

/* Example code to add in the System ID as needed. */
/* The default is to init this field to the Spacecraft ID but ignore for routing. */
/* To fully implement this field would require significant SB optimization to avoid */
/* prohibitively large routing and index tables. */
/* uint16 SystemId; */
/* SystemId = CCSDS_RD_SYSTEM_ID(HdrPtr->ApidQ); */
/* MsgIdVal = (MsgIdVal | (SystemId << 16)); */

#endif

return CFE_SB_ValueToMsgId(MsgIdVal);

}/* end CFE_SB_GetMsgId */


/*
* Function: CFE_SB_SetMsgId - See API and header file for details
*/
void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr,
CFE_SB_MsgId_t MsgId)
{
CFE_SB_MsgId_Atom_t MsgIdVal = CFE_SB_MsgIdToValue(MsgId);

#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
CCSDS_WR_SID(MsgPtr->Hdr, MsgIdVal);
#else
CCSDS_WR_VERS(MsgPtr->SpacePacket.Hdr, 1);

/* Set the stream ID APID in the primary header. */
CCSDS_WR_APID(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_APID_FROM_MSGID(MsgIdVal) );

CCSDS_WR_TYPE(MsgPtr->SpacePacket.Hdr, CFE_SB_RD_TYPE_FROM_MSGID(MsgIdVal) );


CCSDS_CLR_SEC_APIDQ(MsgPtr->SpacePacket.ApidQ);

CCSDS_WR_EDS_VER(MsgPtr->SpacePacket.ApidQ, 1);

CCSDS_WR_ENDIAN(MsgPtr->SpacePacket.ApidQ, CFE_PLATFORM_ENDIAN);

CCSDS_WR_PLAYBACK(MsgPtr->SpacePacket.ApidQ, false);

CCSDS_WR_SUBSYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_SB_RD_SUBSYS_ID_FROM_MSGID(MsgIdVal));

CCSDS_WR_SYSTEM_ID(MsgPtr->SpacePacket.ApidQ, CFE_MISSION_SPACECRAFT_ID);

#endif
}/* end CFE_SB_SetMsgId */

/*
* Function: CFE_SB_GetPktType - See API and header file for details
*/
uint32 CFE_SB_GetPktType(CFE_SB_MsgId_t MsgId)
{

CFE_SB_MsgId_Atom_t Val = CFE_SB_MsgIdToValue(MsgId);
uint8 PktType;

Expand Down
Loading

0 comments on commit 6861acb

Please sign in to comment.