Skip to content

Commit

Permalink
Fix nasa#711, Update SB/CCSDS FSW for msg module
Browse files Browse the repository at this point in the history
- Fix nasa#733: Validate checksum description update
- Fix nasa#597: Remove local endian SID macros
- Updates SB to use msg module
- General cleanup
  • Loading branch information
skliper committed Aug 14, 2020
1 parent d3a073e commit 8563679
Show file tree
Hide file tree
Showing 10 changed files with 193 additions and 961 deletions.
505 changes: 23 additions & 482 deletions fsw/cfe-core/src/inc/ccsds.h

Large diffs are not rendered by default.

89 changes: 89 additions & 0 deletions fsw/cfe-core/src/inc/ccsds_hdr.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/*
** GSC-18128-1, "Core Flight Executive Version 6.7"
**
** Copyright (c) 2006-2019 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.
*/

/******************************************************************************
* Define CCSDS packet header types
* - Avoid direct access for portability, use APIs
* - Used to construct message structures
*/

#ifndef _ccsds_hdr_
#define _ccsds_hdr_

/*
* Include Files
*/

#include "common_types.h"
#include "cfe_mission_cfg.h"

/*
* Type Definitions
*/

/**********************************************************************
* Structure definitions for CCSDS headers.
*
* CCSDS headers must always be in network byte order per the standard.
* MSB at the lowest address which is commonly refered to as "BIG Endian"
*
*/

/**
* \brief CCSDS packet primary header
*/
typedef struct {

uint8 StreamId[2]; /**< \brief packet identifier word (stream ID) */
/* bits shift ------------ description ---------------- */
/* 0x07FF 0 : application ID */
/* 0x0800 11 : secondary header: 0 = absent, 1 = present */
/* 0x1000 12 : packet type: 0 = TLM, 1 = CMD */
/* 0xE000 13 : CCSDS version: 0 = ver 1, 1 = ver 2 */

uint8 Sequence[2]; /**< \brief packet sequence word */
/* bits shift ------------ description ---------------- */
/* 0x3FFF 0 : sequence count */
/* 0xC000 14 : segmentation flags: 3 = complete packet */

uint8 Length[2]; /**< \brief packet length word */
/* bits shift ------------ description ---------------- */
/* 0xFFFF 0 : (total packet length) - 7 */

} CCSDS_PrimaryHeader_t;

/**
* \brief CCSDS packet extended header
*/
typedef struct {

uint8 Subsystem[2]; /**< \brief subsystem qualifier */
/* bits shift ------------ description ---------------- */
/* 0x01FF 0 : Subsystem Id mission defined */
/* 0x0200 9 : Playback flag 0 = original, 1 = playback */
/* 0x0400 10 : Endian: Big = 0, Little (Intel) = 1 */
/* 0xF800 11 : EDS Version for packet definition used */

uint8 SystemId[2]; /**< \brief system qualifier */
/* 0xFFFF 0 : System Id mission defined */

} CCSDS_ExtendedHeader_t;

#endif /* _ccsds_hdr_ */
2 changes: 2 additions & 0 deletions fsw/cfe-core/src/inc/cfe.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
#include "cfe_time.h" /* Define Time Service API */
#include "cfe_tbl.h" /* Define Table Service API */

#include "cfe_msg_api.h" /* Define Message API */

#include "cfe_psp.h" /* Define Platform Support Package API */

#endif /* _cfe_ */
24 changes: 10 additions & 14 deletions fsw/cfe-core/src/inc/cfe_sb.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,19 @@
** Type Definitions
*/

/** \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;
/** \brief Software Bus generic message */
typedef CFE_MSG_Message_t CFE_SB_Msg_t;

/** \brief Generic Software Bus Command Header Type Definition */
/** \brief Aligned Software Bus command header */
typedef union {
CCSDS_CommandPacket_t Cmd;
CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */
CFE_MSG_CommandHeader_t Cmd;
CFE_SB_Msg_t BaseMsg;
} CFE_SB_CmdHdr_t;

/** \brief Generic Software Bus Telemetry Header Type Definition */
/** \brief Aligned Software Bus telemetry header */
typedef union {
CCSDS_TelemetryPacket_t Tlm;
CFE_SB_Msg_t BaseMsg; /**< Base type (primary header) */
CFE_MSG_TelemetryHeader_t Tlm;
CFE_SB_Msg_t BaseMsg;
} CFE_SB_TlmHdr_t;

#define CFE_SB_CMD_HDR_SIZE (sizeof(CFE_SB_CmdHdr_t))/**< \brief Size of #CFE_SB_CmdHdr_t in bytes */
Expand Down Expand Up @@ -1313,7 +1308,7 @@ void CFE_SB_GenerateChecksum(CFE_SB_MsgPtr_t MsgPtr);
**
** \par Assumptions, External Events, and Notes:
** - If the underlying implementation of software bus messages does not
** include a checksum field, then this routine will always return \c true.
** include a checksum field this routine will always return false.
**
** \param[in] MsgPtr A pointer to the buffer that contains the software bus message.
** This must point to the first byte of the message header.
Expand Down Expand Up @@ -1432,6 +1427,7 @@ static inline CFE_SB_MsgId_t CFE_SB_ValueToMsgId(CFE_SB_MsgId_Atom_t MsgIdValue)
/*****************************************************************************/
/**
* \brief Identifies packet type given message ID
*
* Provides the packet type associated with the given message ID
*
Expand Down
122 changes: 0 additions & 122 deletions fsw/cfe-core/src/sb/ccsds.c

This file was deleted.

93 changes: 15 additions & 78 deletions fsw/cfe-core/src/sb/cfe_sb_msg_id_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
#include "osapi.h"
#include "cfe_error.h"
#include "cfe_sb_priv.h"
#include "cfe_sb_msg_id_util.h"
#include "cfe_msg_api.h"


/******************************************************************************
Expand Down Expand Up @@ -120,34 +120,12 @@ CFE_SB_MsgKey_t CFE_SB_ConvertMsgIdtoMsgKey( CFE_SB_MsgId_t MsgId)
*/
CFE_SB_MsgId_t CFE_SB_GetMsgId(const CFE_SB_Msg_t *MsgPtr)
{
CFE_SB_MsgId_Atom_t MsgIdVal = 0;
CFE_SB_MsgId_t MsgId;

#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
MsgIdVal = CCSDS_RD_SID(MsgPtr->Hdr);
#else
/* Ignore return since no alternative action */
CFE_MSG_GetMsgId(MsgPtr, &MsgId);

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);
return MsgId;

}/* end CFE_SB_GetMsgId */

Expand All @@ -158,32 +136,10 @@ return CFE_SB_ValueToMsgId(MsgIdVal);
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

/* Ignore return, no alternate action */
CFE_MSG_SetMsgId(MsgPtr, MsgId);

}/* end CFE_SB_SetMsgId */

/*
Expand All @@ -192,31 +148,12 @@ void CFE_SB_SetMsgId(CFE_SB_MsgPtr_t MsgPtr,
uint32 CFE_SB_GetPktType(CFE_SB_MsgId_t MsgId)
{

CFE_SB_MsgId_Atom_t Val = CFE_SB_MsgIdToValue(MsgId);
uint8 PktType;

if (CFE_SB_IsValidMsgId(MsgId))
{
#ifndef MESSAGE_FORMAT_IS_CCSDS_VER_2
if (CFE_TST(Val,12))
{
PktType = CFE_SB_PKTTYPE_CMD;
} else {
PktType = CFE_SB_PKTTYPE_TLM;
}
#else
if (CFE_SB_RD_TYPE_FROM_MSGID(Val) == 1)
{
PktType = CFE_SB_PKTTYPE_CMD;
} else {
PktType = CFE_SB_PKTTYPE_TLM;
}
#endif /* MESSAGE_FORMAT_IS_CCSDS_VER_2 */
} else {
PktType = CFE_SB_PKTTYPE_INVALID;
}

return PktType;
CFE_MSG_Type_t type;

/* Ignores return, no alternate action */
CFE_MSG_GetTypeFromMsgId(MsgId, &type);

return type;

}/* end CFE_SB_GetPktType */

Expand Down
Loading

0 comments on commit 8563679

Please sign in to comment.