Merge remote-tracking branch 'upstream/development' into mueller/tcp-keep-open-pr

This commit is contained in:
Robin Müller 2021-10-11 18:52:52 +02:00
commit 4924da1667
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
16 changed files with 392 additions and 307 deletions

View File

@ -26,12 +26,11 @@ public:
* @param sequenceCount ets the packet's Source Sequence Count field. * @param sequenceCount ets the packet's Source Sequence Count field.
*/ */
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false, SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0); uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
/** /**
* The class's default destructor. * The class's default destructor.
*/ */
virtual ~SpacePacket(); virtual ~SpacePacket();
/** /**
* With this call, the complete data content (including the CCSDS Primary * With this call, the complete data content (including the CCSDS Primary
* Header) is overwritten with the byte stream given. * Header) is overwritten with the byte stream given.
@ -41,6 +40,7 @@ public:
* @li \c false else. * @li \c false else.
*/ */
bool addWholeData(const uint8_t* p_data, uint32_t packet_size); bool addWholeData(const uint8_t* p_data, uint32_t packet_size);
protected: protected:
/** /**
* This structure defines the data structure of a Space Packet as local data. * This structure defines the data structure of a Space Packet as local data.

View File

@ -3,8 +3,8 @@
#include <cstring> #include <cstring>
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) { SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) {
this->data = (SpacePacketPointer*) set_address; this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
} }
SpacePacketBase::~SpacePacketBase() { SpacePacketBase::~SpacePacketBase() {
@ -12,94 +12,112 @@ SpacePacketBase::~SpacePacketBase() {
//CCSDS Methods: //CCSDS Methods:
uint8_t SpacePacketBase::getPacketVersionNumber( void ) { uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
return (this->data->header.packet_id_h & 0b11100000) >> 5; return (this->data->header.packet_id_h & 0b11100000) >> 5;
} }
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand, ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) { bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
//reset header to zero: if(data == nullptr) {
memset(data,0, sizeof(this->data->header) ); #if FSFW_VERBOSE_LEVEL >= 1
//Set TC/TM bit. #if FSFW_CPP_OSTREAM_ENABLED == 1
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4; sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid"
//Set secondaryHeader bit << std::endl;
data->header.packet_id_h |= ((hasSecondaryHeader? 1 : 0)) << 3; #else
this->setAPID( apid ); sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
//Always initialize as standalone packets. #endif
data->header.sequence_control_h = 0b11000000; #endif
setPacketSequenceCount(sequenceCount); return HasReturnvaluesIF::RETURN_FAILED;
}
//reset header to zero:
memset(data, 0, sizeof(this->data->header) );
//Set TC/TM bit.
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4;
//Set secondaryHeader bit
data->header.packet_id_h |= ((hasSecondaryHeader? 1 : 0)) << 3;
this->setAPID( apid );
//Always initialize as standalone packets.
data->header.sequence_control_h = 0b11000000;
setPacketSequenceCount(sequenceCount);
return HasReturnvaluesIF::RETURN_OK;
} }
bool SpacePacketBase::isTelecommand( void ) { bool SpacePacketBase::isTelecommand( void ) {
return (this->data->header.packet_id_h & 0b00010000) >> 4; return (this->data->header.packet_id_h & 0b00010000) >> 4;
} }
bool SpacePacketBase::hasSecondaryHeader( void ) { bool SpacePacketBase::hasSecondaryHeader( void ) {
return (this->data->header.packet_id_h & 0b00001000) >> 3; return (this->data->header.packet_id_h & 0b00001000) >> 3;
} }
uint16_t SpacePacketBase::getPacketId() { uint16_t SpacePacketBase::getPacketId() {
return ( (this->data->header.packet_id_h) << 8 ) + return ( (this->data->header.packet_id_h) << 8 ) +
this->data->header.packet_id_l; this->data->header.packet_id_l;
} }
uint16_t SpacePacketBase::getAPID( void ) const { uint16_t SpacePacketBase::getAPID( void ) const {
return ( (this->data->header.packet_id_h & 0b00000111) << 8 ) + return ( (this->data->header.packet_id_h & 0b00000111) << 8 ) +
this->data->header.packet_id_l; this->data->header.packet_id_l;
} }
void SpacePacketBase::setAPID( uint16_t new_apid ) { void SpacePacketBase::setAPID( uint16_t new_apid ) {
//Use first three bits of new APID, but keep rest of packet id as it was (see specification). // Use first three bits of new APID, but keep rest of packet id as it was (see specification).
this->data->header.packet_id_h = (this->data->header.packet_id_h & 0b11111000) | ( ( new_apid & 0x0700 ) >> 8 ); this->data->header.packet_id_h = (this->data->header.packet_id_h & 0b11111000) |
this->data->header.packet_id_l = ( new_apid & 0x00FF ); ( ( new_apid & 0x0700 ) >> 8 );
this->data->header.packet_id_l = ( new_apid & 0x00FF );
}
void SpacePacketBase::setSequenceFlags( uint8_t sequenceflags ) {
this->data->header.sequence_control_h &= 0x3F;
this->data->header.sequence_control_h |= sequenceflags << 6;
} }
uint16_t SpacePacketBase::getPacketSequenceControl( void ) { uint16_t SpacePacketBase::getPacketSequenceControl( void ) {
return ( (this->data->header.sequence_control_h) << 8 ) return ( (this->data->header.sequence_control_h) << 8 )
+ this->data->header.sequence_control_l; + this->data->header.sequence_control_l;
} }
uint8_t SpacePacketBase::getSequenceFlags( void ) { uint8_t SpacePacketBase::getSequenceFlags( void ) {
return (this->data->header.sequence_control_h & 0b11000000) >> 6 ; return (this->data->header.sequence_control_h & 0b11000000) >> 6 ;
} }
uint16_t SpacePacketBase::getPacketSequenceCount( void ) const { uint16_t SpacePacketBase::getPacketSequenceCount( void ) const {
return ( (this->data->header.sequence_control_h & 0b00111111) << 8 ) return ( (this->data->header.sequence_control_h & 0b00111111) << 8 )
+ this->data->header.sequence_control_l; + this->data->header.sequence_control_l;
} }
void SpacePacketBase::setPacketSequenceCount( uint16_t new_count) { void SpacePacketBase::setPacketSequenceCount( uint16_t new_count) {
this->data->header.sequence_control_h = ( this->data->header.sequence_control_h & 0b11000000 ) | ( ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x3F00 ) >> 8 ); this->data->header.sequence_control_h = ( this->data->header.sequence_control_h & 0b11000000 ) |
this->data->header.sequence_control_l = ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x00FF ); ( ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x3F00 ) >> 8 );
this->data->header.sequence_control_l = ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x00FF );
} }
uint16_t SpacePacketBase::getPacketDataLength() const { uint16_t SpacePacketBase::getPacketDataLength() const {
return ( (this->data->header.packet_length_h) << 8 ) return ( (this->data->header.packet_length_h) << 8 )
+ this->data->header.packet_length_l; + this->data->header.packet_length_l;
} }
void SpacePacketBase::setPacketDataLength( uint16_t new_length) { void SpacePacketBase::setPacketDataLength( uint16_t new_length) {
this->data->header.packet_length_h = ( ( new_length & 0xFF00 ) >> 8 ); this->data->header.packet_length_h = ( ( new_length & 0xFF00 ) >> 8 );
this->data->header.packet_length_l = ( new_length & 0x00FF ); this->data->header.packet_length_l = ( new_length & 0x00FF );
} }
size_t SpacePacketBase::getFullSize() { size_t SpacePacketBase::getFullSize() {
//+1 is done because size in packet data length field is: size of data field -1 // +1 is done because size in packet data length field is: size of data field -1
return this->getPacketDataLength() + sizeof(this->data->header) + 1; return this->getPacketDataLength() + sizeof(this->data->header) + 1;
} }
uint8_t* SpacePacketBase::getWholeData() { uint8_t* SpacePacketBase::getWholeData() {
return (uint8_t*)this->data; return (uint8_t*)this->data;
} }
void SpacePacketBase::setData( const uint8_t* p_Data ) { void SpacePacketBase::setData( const uint8_t* p_Data ) {
this->data = (SpacePacketPointer*)p_Data; this->data = (SpacePacketPointer*)p_Data;
} }
uint32_t SpacePacketBase::getApidAndSequenceCount() const { uint32_t SpacePacketBase::getApidAndSequenceCount() const {
return (getAPID() << 16) + getPacketSequenceCount(); return (getAPID() << 16) + getPacketSequenceCount();
} }
uint8_t* SpacePacketBase::getPacketData() { uint8_t* SpacePacketBase::getPacketData() {
return &(data->packet_data); return &(data->packet_data);
} }

View File

@ -2,6 +2,8 @@
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_ #define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#include "ccsds_header.h" #include "ccsds_header.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstddef> #include <cstddef>
/** /**
@ -20,8 +22,8 @@
* @ingroup tmtcpackets * @ingroup tmtcpackets
*/ */
struct SpacePacketPointer { struct SpacePacketPointer {
CCSDSPrimaryHeader header; CCSDSPrimaryHeader header;
uint8_t packet_data; uint8_t packet_data;
}; };
/** /**
@ -37,143 +39,151 @@ struct SpacePacketPointer {
*/ */
class SpacePacketBase { class SpacePacketBase {
protected: protected:
/** /**
* A pointer to a structure which defines the data structure of * A pointer to a structure which defines the data structure of
* the packet header. * the packet header.
* To be hardware-safe, all elements are of byte size. * To be hardware-safe, all elements are of byte size.
*/ */
SpacePacketPointer* data; SpacePacketPointer* data;
public: public:
static const uint16_t LIMIT_APID = 2048; //2^1 static const uint16_t LIMIT_APID = 2048; //2^1
static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14 static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14
static const uint16_t APID_IDLE_PACKET = 0x7FF; static const uint16_t APID_IDLE_PACKET = 0x7FF;
static const uint8_t TELECOMMAND_PACKET = 1; static const uint8_t TELECOMMAND_PACKET = 1;
static const uint8_t TELEMETRY_PACKET = 0; static const uint8_t TELEMETRY_PACKET = 0;
/** /**
* This definition defines the CRC size in byte. * This definition defines the CRC size in byte.
*/ */
static const uint8_t CRC_SIZE = 2; static const uint8_t CRC_SIZE = 2;
/** /**
* This is the minimum size of a SpacePacket. * This is the minimum size of a SpacePacket.
*/ */
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE; static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
/** /**
* This is the default constructor. * This is the default constructor.
* It sets its internal data pointer to the address passed. * It sets its internal data pointer to the address passed.
* @param set_address The position where the packet data lies. * @param set_address The position where the packet data lies.
*/ */
SpacePacketBase( const uint8_t* set_address ); SpacePacketBase( const uint8_t* set_address );
/** /**
* No data is allocated, so the destructor is empty. * No data is allocated, so the destructor is empty.
*/ */
virtual ~SpacePacketBase(); virtual ~SpacePacketBase();
//CCSDS Methods: //CCSDS Methods
/**
* Getter for the packet version number field.
* @return Returns the highest three bit of the packet in one byte.
*/
uint8_t getPacketVersionNumber( void );
/**
* This method checks the type field in the header.
* This bit specifies, if the command is interpreted as Telecommand of
* as Telemetry. For a Telecommand, the bit is set.
* @return Returns true if the bit is set and false if not.
*/
bool isTelecommand( void );
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, /**
uint16_t apid, uint16_t sequenceCount = 0); * Getter for the packet version number field.
/** * @return Returns the highest three bit of the packet in one byte.
* The CCSDS header provides a secondary header flag (the fifth-highest bit), */
* which is checked with this method. uint8_t getPacketVersionNumber( void );
* @return Returns true if the bit is set and false if not. /**
*/ * This method checks the type field in the header.
bool hasSecondaryHeader( void ); * This bit specifies, if the command is interpreted as Telecommand of
/** * as Telemetry. For a Telecommand, the bit is set.
* Returns the complete first two bytes of the packet, which together form * @return Returns true if the bit is set and false if not.
* the CCSDS packet id. */
* @return The CCSDS packet id. bool isTelecommand( void );
*/
uint16_t getPacketId( void );
/**
* Returns the APID of a packet, which are the lowest 11 bit of the packet
* id.
* @return The CCSDS APID.
*/
uint16_t getAPID( void ) const;
/**
* Sets the APID of a packet, which are the lowest 11 bit of the packet
* id.
* @param The APID to set. The highest five bits of the parameter are
* ignored.
*/
void setAPID( uint16_t setAPID );
/**
* Returns the CCSDS packet sequence control field, which are the third and
* the fourth byte of the CCSDS primary header.
* @return The CCSDS packet sequence control field.
*/
uint16_t getPacketSequenceControl( void );
/**
* Returns the SequenceFlags, which are the highest two bit of the packet
* sequence control field.
* @return The CCSDS sequence flags.
*/
uint8_t getSequenceFlags( void );
/**
* Returns the packet sequence count, which are the lowest 14 bit of the
* packet sequence control field.
* @return The CCSDS sequence count.
*/
uint16_t getPacketSequenceCount( void ) const;
/**
* Sets the packet sequence count, which are the lowest 14 bit of the
* packet sequence control field.
* setCount is modulo-divided by \c LIMIT_SEQUENCE_COUNT to avoid overflows.
* @param setCount The value to set the count to.
*/
void setPacketSequenceCount( uint16_t setCount );
/**
* Returns the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header. The packet data length is the size of every kind
* of data \b after the CCSDS Primary Header \b -1.
* @return
* The CCSDS packet data length. uint16_t is sufficient,
* because this is limit in CCSDS standard
*/
uint16_t getPacketDataLength(void) const;
/**
* Sets the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header.
* @param setLength The value of the length to set. It must fit the true
* CCSDS packet data length . The packet data length is
* the size of every kind of data \b after the CCSDS
* Primary Header \b -1.
*/
void setPacketDataLength( uint16_t setLength );
//Helper methods: ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
/** uint16_t apid, uint16_t sequenceCount = 0);
* This method returns a raw uint8_t pointer to the packet. /**
* @return A \c uint8_t pointer to the first byte of the CCSDS primary header. * The CCSDS header provides a secondary header flag (the fifth-highest bit),
*/ * which is checked with this method.
virtual uint8_t* getWholeData( void ); * @return Returns true if the bit is set and false if not.
*/
bool hasSecondaryHeader( void );
/**
* Returns the complete first two bytes of the packet, which together form
* the CCSDS packet id.
* @return The CCSDS packet id.
*/
uint16_t getPacketId( void );
/**
* Returns the APID of a packet, which are the lowest 11 bit of the packet
* id.
* @return The CCSDS APID.
*/
uint16_t getAPID( void ) const;
/**
* Sets the APID of a packet, which are the lowest 11 bit of the packet
* id.
* @param The APID to set. The highest five bits of the parameter are
* ignored.
*/
void setAPID( uint16_t setAPID );
uint8_t* getPacketData(); /**
/** * Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header.
* With this method, the packet data pointer can be redirected to another * @param The sequence flags to set
* location. */
* @param p_Data A pointer to another raw Space Packet. void setSequenceFlags( uint8_t sequenceflags );
*/
virtual void setData( const uint8_t* p_Data );
/**
* This method returns the full raw packet size.
* @return The full size of the packet in bytes.
*/
size_t getFullSize();
uint32_t getApidAndSequenceCount() const; /**
* Returns the CCSDS packet sequence control field, which are the third and
* the fourth byte of the CCSDS primary header.
* @return The CCSDS packet sequence control field.
*/
uint16_t getPacketSequenceControl( void );
/**
* Returns the SequenceFlags, which are the highest two bit of the packet
* sequence control field.
* @return The CCSDS sequence flags.
*/
uint8_t getSequenceFlags( void );
/**
* Returns the packet sequence count, which are the lowest 14 bit of the
* packet sequence control field.
* @return The CCSDS sequence count.
*/
uint16_t getPacketSequenceCount( void ) const;
/**
* Sets the packet sequence count, which are the lowest 14 bit of the
* packet sequence control field.
* setCount is modulo-divided by \c LIMIT_SEQUENCE_COUNT to avoid overflows.
* @param setCount The value to set the count to.
*/
void setPacketSequenceCount( uint16_t setCount );
/**
* Returns the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header. The packet data length is the size of every kind
* of data \b after the CCSDS Primary Header \b -1.
* @return
* The CCSDS packet data length. uint16_t is sufficient,
* because this is limit in CCSDS standard
*/
uint16_t getPacketDataLength(void) const;
/**
* Sets the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header.
* @param setLength The value of the length to set. It must fit the true
* CCSDS packet data length . The packet data length is
* the size of every kind of data \b after the CCSDS
* Primary Header \b -1.
*/
void setPacketDataLength( uint16_t setLength );
// Helper methods
/**
* This method returns a raw uint8_t pointer to the packet.
* @return A \c uint8_t pointer to the first byte of the CCSDS primary header.
*/
virtual uint8_t* getWholeData( void );
uint8_t* getPacketData();
/**
* With this method, the packet data pointer can be redirected to another
* location.
* @param p_Data A pointer to another raw Space Packet.
*/
virtual void setData( const uint8_t* p_Data );
/**
* This method returns the full raw packet size.
* @return The full size of the packet in bytes.
*/
size_t getFullSize();
uint32_t getApidAndSequenceCount() const;
}; };

View File

@ -0,0 +1,16 @@
#ifndef FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_
#define FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_
#include <cstdint>
namespace pus {
//! Version numbers according to ECSS-E-ST-70-41C p.439
enum PusVersion: uint8_t {
PUS_A_VERSION = 1,
PUS_C_VERSION = 2
};
}
#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */

View File

@ -1,4 +1,4 @@
#include "fsfw/tmtcpacket/pus/tc/TcPacketPus.h" #include "TcPacketPus.h"
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include <cstring> #include <cstring>
@ -8,14 +8,13 @@ TcPacketPus::TcPacketPus(const uint8_t *setData): TcPacketBase(setData) {
} }
void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount, void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice, uint16_t sourceId) { uint8_t ack, uint8_t service, uint8_t subservice, pus::PusVersion pusVersion,
uint16_t sourceId) {
initSpacePacketHeader(true, true, apid, sequenceCount); initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField)); std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header: // Data Field Header. For PUS A, the first bit (CCSDS Secondary Header Flag) is zero
// Set CCSDS_secondary_header_flag to 0 and version number to 001 tcData->dataField.versionTypeAck = pusVersion << 4 | (ack & 0x0F);
tcData->dataField.versionTypeAck = 0b00010000;
tcData->dataField.versionTypeAck |= (ack & 0x0F);
tcData->dataField.serviceType = service; tcData->dataField.serviceType = service;
tcData->dataField.serviceSubtype = subservice; tcData->dataField.serviceSubtype = subservice;
#if FSFW_USE_PUS_C_TELECOMMANDS == 1 #if FSFW_USE_PUS_C_TELECOMMANDS == 1

View File

@ -2,6 +2,7 @@
#define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ #define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_
#include "fsfw/FSFW.h" #include "fsfw/FSFW.h"
#include "../definitions.h"
#include "fsfw/tmtcpacket/ccsds_header.h" #include "fsfw/tmtcpacket/ccsds_header.h"
#include "TcPacketBase.h" #include "TcPacketBase.h"
@ -75,7 +76,8 @@ protected:
* @param subservice PUS Subservice * @param subservice PUS Subservice
*/ */
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack,
uint8_t service, uint8_t subservice, uint16_t sourceId = 0); uint8_t service, uint8_t subservice, pus::PusVersion pusVersion,
uint16_t sourceId = 0);
/** /**
* A pointer to a structure which defines the data structure of * A pointer to a structure which defines the data structure of

View File

@ -23,7 +23,12 @@ TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service,
return; return;
} }
this->setData(pData); this->setData(pData);
initializeTcPacket(apid, sequenceCount, ack, service, subservice); #if FSFW_USE_PUS_C_TELECOMMANDS == 1
pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION;
#else
pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION;
#endif
initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion);
std::memcpy(&tcData->appData, data, size); std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength( this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1); size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);

View File

@ -31,8 +31,6 @@ public:
//! Maximum size of a TM Packet in this mission. //! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable. //! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
//! First four bits of first byte of secondary header
static const uint8_t VERSION_NUMBER_BYTE = 0b00010000;
/** /**
* This is the default constructor. * This is the default constructor.

View File

@ -1,5 +1,6 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketPusA.h" #include "../definitions.h"
#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" #include "TmPacketPusA.h"
#include "TmPacketBase.h"
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/globalfunctions/arrayprinter.h"
@ -62,12 +63,7 @@ void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service,
//First, set to zero. //First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field)); memset(&tmData->data_field, 0, sizeof(tmData->data_field));
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits. tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4;
// The other 4 bits of the first byte are the spacecraft time reference
// status. To change to PUS-C, set 0b00100000.
// Set CCSDS_secondary header flag to 0, version number to 001 and ack
// to 0000
tmData->data_field.version_type_ack = 0b00010000;
tmData->data_field.service_type = service; tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice; tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter; tmData->data_field.subcounter = packetSubcounter;

View File

@ -1,5 +1,6 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketPusC.h" #include "../definitions.h"
#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h" #include "TmPacketPusC.h"
#include "TmPacketBase.h"
#include "fsfw/globalfunctions/CRC.h" #include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h" #include "fsfw/globalfunctions/arrayprinter.h"
@ -53,18 +54,22 @@ uint8_t* TmPacketPusC::getPacketTimeRaw() const{
} }
void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId, uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) { uint8_t timeRefField) {
//Set primary header: //Set primary header:
initSpacePacketHeader(false, true, apid); ReturnValue_t result = initSpacePacketHeader(false, true, apid);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
//Set data Field Header: //Set data Field Header:
//First, set to zero. //First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField)); memset(&tmData->dataField, 0, sizeof(tmData->dataField));
/* Only account for last 4 bytes for time reference field */ /* Only account for last 4 bytes for time reference field */
timeRefField &= 0b1111; timeRefField &= 0b1111;
tmData->dataField.versionTimeReferenceField = VERSION_NUMBER_BYTE | timeRefField; tmData->dataField.versionTimeReferenceField =
(pus::PusVersion::PUS_C_VERSION << 4) | timeRefField;
tmData->dataField.serviceType = service; tmData->dataField.serviceType = service;
tmData->dataField.serviceSubtype = subservice; tmData->dataField.serviceSubtype = subservice;
tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff; tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;
@ -76,6 +81,7 @@ void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
timeStamper->addTimeStamp(tmData->dataField.time, timeStamper->addTimeStamp(tmData->dataField.time,
sizeof(tmData->dataField.time)); sizeof(tmData->dataField.time));
} }
return HasReturnvaluesIF::RETURN_OK;
} }
void TmPacketPusC::setSourceDataSize(uint16_t size) { void TmPacketPusC::setSourceDataSize(uint16_t size) {

View File

@ -100,7 +100,7 @@ protected:
* @param subservice PUS Subservice * @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used. * @param packetSubcounter Additional subcounter used.
*/ */
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0); uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
/** /**

View File

@ -91,4 +91,34 @@ void TmPacketStoredBase::checkAndReportLostTm() {
} }
} }
void TmPacketStoredBase::handleStoreFailure(const char *const packetType, ReturnValue_t result,
size_t sizeToReserve) {
checkAndReportLostTm();
#if FSFW_VERBOSE_LEVEL >= 1
switch(result) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
case(StorageManagerIF::DATA_STORAGE_FULL): {
sif::warning << "TmPacketStoredPus" << packetType << ": " <<
"Store full for packet with size" << sizeToReserve << std::endl;
break;
}
case(StorageManagerIF::DATA_TOO_LARGE): {
sif::warning << "TmPacketStoredPus" << packetType << ": Data with size " <<
sizeToReserve << " too large" << std::endl;
break;
}
#else
case(StorageManagerIF::DATA_STORAGE_FULL): {
sif::printWarning("TmPacketStoredPus%s: Store full for packet with "
"size %d\n", packetType, sizeToReserve);
break;
}
case(StorageManagerIF::DATA_TOO_LARGE): {
sif::printWarning("TmPacketStoredPus%s: Data with size "
"%d too large\n", packetType, sizeToReserve);
break;
}
#endif
#endif
}
}

View File

@ -82,6 +82,9 @@ protected:
bool checkAndSetStore(); bool checkAndSetStore();
void checkAndReportLostTm(); void checkAndReportLostTm();
void handleStoreFailure(const char* const packetType, ReturnValue_t result,
size_t sizeToReserve);
}; };

View File

@ -5,69 +5,70 @@
#include <cstring> #include <cstring>
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) : TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress):
TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){ TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){
} }
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data, uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) : uint32_t size, const uint8_t *headerData, uint32_t headerSize):
TmPacketPusA(nullptr) { TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) { if (not TmPacketStoredBase::checkAndSetStore()) {
return; return;
} }
uint8_t *pData = nullptr; uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
(getPacketMinimumSize() + size + headerSize), &pData); ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm(); handleStoreFailure("A", returnValue, sizeToReserve);
return; return;
} }
setData(pData); setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter); initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size); memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength( setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
} }
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content, uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) : SerializeIF *header) :
TmPacketPusA(nullptr) { TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) { if (not TmPacketStoredBase::checkAndSetStore()) {
return; return;
} }
size_t sourceDataSize = 0; size_t sourceDataSize = 0;
if (content != NULL) { if (content != nullptr) {
sourceDataSize += content->getSerializedSize(); sourceDataSize += content->getSerializedSize();
} }
if (header != NULL) { if (header != nullptr) {
sourceDataSize += header->getSerializedSize(); sourceDataSize += header->getSerializedSize();
} }
uint8_t *p_data = NULL; uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
(getPacketMinimumSize() + sourceDataSize), &p_data); ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
if (returnValue != store->RETURN_OK) { sizeToReserve, &pData);
TmPacketStoredBase::checkAndReportLostTm(); if (returnValue != store->RETURN_OK) {
} handleStoreFailure("A", returnValue, sizeToReserve);
setData(p_data); return;
initializeTmPacket(apid, service, subservice, packetSubcounter); }
uint8_t *putDataHere = getSourceData(); setData(pData);
size_t size = 0; initializeTmPacket(apid, service, subservice, packetSubcounter);
if (header != NULL) { uint8_t *putDataHere = getSourceData();
header->serialize(&putDataHere, &size, sourceDataSize, size_t size = 0;
SerializeIF::Endianness::BIG); if (header != nullptr) {
} header->serialize(&putDataHere, &size, sourceDataSize,
if (content != NULL) { SerializeIF::Endianness::BIG);
content->serialize(&putDataHere, &size, sourceDataSize, }
SerializeIF::Endianness::BIG); if (content != nullptr) {
} content->serialize(&putDataHere, &size, sourceDataSize,
setPacketDataLength( SerializeIF::Endianness::BIG);
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1); }
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
} }
uint8_t* TmPacketStoredPusA::getAllTmData() { uint8_t* TmPacketStoredPusA::getAllTmData() {

View File

@ -15,46 +15,46 @@
* packets in a store with the help of a storeAddress. * packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets * @ingroup tmtcpackets
*/ */
class TmPacketStoredPusA : class TmPacketStoredPusA:
public TmPacketStoredBase, public TmPacketStoredBase,
public TmPacketPusA { public TmPacketPusA {
public: public:
/** /**
* This is a default constructor which does not set the data pointer. * This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store. * However, it does try to set the packet store.
*/ */
TmPacketStoredPusA( store_address_t setAddress ); TmPacketStoredPusA( store_address_t setAddress );
/** /**
* With this constructor, new space is allocated in the packet store and * With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there. * a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet. * Packet Application Data passed in data is copied into the packet.
* The Application data is passed in two parts, first a header, then a * The Application data is passed in two parts, first a header, then a
* data field. This allows building a Telemetry Packet from two separate * data field. This allows building a Telemetry Packet from two separate
* data sources. * data sources.
* @param apid Sets the packet's APID field. * @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field. * @param service Sets the packet's Service ID field.
* This specifies the source service. * This specifies the source service.
* @param subservice Sets the packet's Service Subtype field. * @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service. * This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet * @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the * @param data The payload data to be copied to the
* Application Data Field * Application Data Field
* @param size The amount of data to be copied. * @param size The amount of data to be copied.
* @param headerData The header Data of the Application field, * @param headerData The header Data of the Application field,
* will be copied in front of data * will be copied in front of data
* @param headerSize The size of the headerDataF * @param headerSize The size of the headerDataF
*/ */
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr, uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr, uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0); uint32_t headerSize = 0);
/** /**
* Another ctor to directly pass structured content and header data to the * Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers. * packet to avoid additional buffers.
*/ */
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice, TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content, uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr); SerializeIF* header = nullptr);
uint8_t* getAllTmData() override; uint8_t* getAllTmData() override;
void setDataPointer(const uint8_t* newPointer) override; void setDataPointer(const uint8_t* newPointer) override;

View File

@ -19,19 +19,19 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
return; return;
} }
uint8_t *pData = nullptr; uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + size + headerSize), &pData); sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm(); handleStoreFailure("C", returnValue, sizeToReserve);
return; return;
} }
setData(pData); setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
memcpy(getSourceData(), headerData, headerSize); memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size); memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength( setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
} }
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
@ -43,27 +43,28 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
return; return;
} }
size_t sourceDataSize = 0; size_t sourceDataSize = 0;
if (content != NULL) { if (content != nullptr) {
sourceDataSize += content->getSerializedSize(); sourceDataSize += content->getSerializedSize();
} }
if (header != NULL) { if (header != nullptr) {
sourceDataSize += header->getSerializedSize(); sourceDataSize += header->getSerializedSize();
} }
uint8_t *p_data = NULL; uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
(getPacketMinimumSize() + sourceDataSize), &p_data); ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
TmPacketStoredBase::checkAndReportLostTm(); handleStoreFailure("C", returnValue, sizeToReserve);
return;
} }
setData(p_data); setData(pData);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
uint8_t *putDataHere = getSourceData(); uint8_t *putDataHere = getSourceData();
size_t size = 0; size_t size = 0;
if (header != NULL) { if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
if (content != NULL) { if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }