reapply clang format

This commit is contained in:
2022-02-02 10:29:30 +01:00
parent 70b593df65
commit ddcac2bbac
809 changed files with 52010 additions and 56052 deletions

View File

@ -1,34 +1,33 @@
#ifndef TMTCPACKET_PUS_TC_SETTABLEDATAPOINTERIF_H_
#define TMTCPACKET_PUS_TC_SETTABLEDATAPOINTERIF_H_
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstddef>
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
/**
* @brief This interface can be used for classes which store a reference to data. It allows
* the implementing class to redirect the data it refers too.
*/
class RedirectableDataPointerIF {
public:
virtual ~RedirectableDataPointerIF() {};
public:
virtual ~RedirectableDataPointerIF(){};
/**
* Redirect the data pointer, but allow an implementation to change the data.
* The default implementation also sets a read-only pointer where applicable.
* @param dataPtr
* @param maxSize Maximum allowed size in buffer which holds the data. Can be used for size
* checks if a struct is cast directly onto the data pointer to ensure that the buffer is
* large enough
* @param args Any additional user arguments required to set the data pointer
* @return
* - RETURN_OK if the pointer was set successfully
* - RETURN_FAILED on general error of if the maximum size is too small
*/
virtual ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) = 0;
/**
* Redirect the data pointer, but allow an implementation to change the data.
* The default implementation also sets a read-only pointer where applicable.
* @param dataPtr
* @param maxSize Maximum allowed size in buffer which holds the data. Can be used for size
* checks if a struct is cast directly onto the data pointer to ensure that the buffer is
* large enough
* @param args Any additional user arguments required to set the data pointer
* @return
* - RETURN_OK if the pointer was set successfully
* - RETURN_FAILED on general error of if the maximum size is too small
*/
virtual ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) = 0;
private:
private:
};
#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TC_SETTABLEDATAPOINTERIF_H_ */

View File

@ -1,27 +1,28 @@
#include "fsfw/tmtcpacket/ccsds_header.h"
#include "fsfw/tmtcpacket/SpacePacket.h"
#include <cstring>
#include "fsfw/tmtcpacket/ccsds_header.h"
SpacePacket::SpacePacket(uint16_t packetDataLength, bool isTelecommand, uint16_t apid,
uint16_t sequenceCount):
SpacePacketBase( (uint8_t*)&this->localData ) {
initSpacePacketHeader(isTelecommand, false, apid, sequenceCount);
this->setPacketSequenceCount(sequenceCount);
if ( packetDataLength <= sizeof(this->localData.fields.buffer) ) {
this->setPacketDataLength(packetDataLength);
} else {
this->setPacketDataLength( sizeof(this->localData.fields.buffer) );
}
uint16_t sequenceCount)
: SpacePacketBase((uint8_t*)&this->localData) {
initSpacePacketHeader(isTelecommand, false, apid, sequenceCount);
this->setPacketSequenceCount(sequenceCount);
if (packetDataLength <= sizeof(this->localData.fields.buffer)) {
this->setPacketDataLength(packetDataLength);
} else {
this->setPacketDataLength(sizeof(this->localData.fields.buffer));
}
}
SpacePacket::~SpacePacket( void ) {
}
SpacePacket::~SpacePacket(void) {}
bool SpacePacket::addWholeData( const uint8_t* p_Data, uint32_t packet_size ) {
if ( packet_size <= sizeof(this->data) ) {
memcpy( &this->localData.byteStream, p_Data, packet_size );
return true;
} else {
return false;
}
bool SpacePacket::addWholeData(const uint8_t* p_Data, uint32_t packet_size) {
if (packet_size <= sizeof(this->data)) {
memcpy(&this->localData.byteStream, p_Data, packet_size);
return true;
} else {
return false;
}
}

View File

@ -13,80 +13,77 @@
* so the parent's methods are reachable.
* @ingroup tmtcpackets
*/
class SpacePacket: public SpacePacketBase {
public:
static const uint16_t PACKET_MAX_SIZE = 1024;
/**
* The constructor initializes the packet and sets all header information
* according to the passed parameters.
* @param packetDataLength Sets the packet data length field and therefore specifies
* the size of the packet.
* @param isTelecommand Sets the packet type field to either TC (true) or TM (false).
* @param apid Sets the packet's APID field. The default value describes an idle packet.
* @param sequenceCount ets the packet's Source Sequence Count field.
*/
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
/**
* The class's default destructor.
*/
virtual ~SpacePacket();
/**
* With this call, the complete data content (including the CCSDS Primary
* Header) is overwritten with the byte stream given.
* @param p_data Pointer to data to overwrite the content with
* @param packet_size Size of the data
* @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE.
* @li \c false else.
*/
bool addWholeData(const uint8_t* p_data, uint32_t packet_size);
class SpacePacket : public SpacePacketBase {
public:
static const uint16_t PACKET_MAX_SIZE = 1024;
/**
* The constructor initializes the packet and sets all header information
* according to the passed parameters.
* @param packetDataLength Sets the packet data length field and therefore specifies
* the size of the packet.
* @param isTelecommand Sets the packet type field to either TC (true) or TM (false).
* @param apid Sets the packet's APID field. The default value describes an idle packet.
* @param sequenceCount ets the packet's Source Sequence Count field.
*/
SpacePacket(uint16_t packetDataLength, bool isTelecommand = false,
uint16_t apid = APID_IDLE_PACKET, uint16_t sequenceCount = 0);
/**
* The class's default destructor.
*/
virtual ~SpacePacket();
/**
* With this call, the complete data content (including the CCSDS Primary
* Header) is overwritten with the byte stream given.
* @param p_data Pointer to data to overwrite the content with
* @param packet_size Size of the data
* @return @li \c true if packet_size is smaller than \c MAX_PACKET_SIZE.
* @li \c false else.
*/
bool addWholeData(const uint8_t* p_data, uint32_t packet_size);
protected:
/**
* This structure defines the data structure of a Space Packet as local data.
* There's a buffer which corresponds to the Space Packet Data Field with a
* maximum size of \c PACKET_MAX_SIZE.
*/
struct PacketStructured {
CCSDSPrimaryHeader header;
uint8_t buffer[PACKET_MAX_SIZE];
};
/**
* This union simplifies accessing the full data content of the Space Packet.
* This is achieved by putting the \c PacketStructured struct in a union with
* a plain buffer.
*/
union SpacePacketData {
PacketStructured fields;
uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)];
};
/**
* This is the data representation of the class.
* It is a struct of CCSDS Primary Header and a data field, which again is
* packed in an union, so the data can be accessed as a byte stream without
* a cast.
*/
SpacePacketData localData;
protected:
/**
* This structure defines the data structure of a Space Packet as local data.
* There's a buffer which corresponds to the Space Packet Data Field with a
* maximum size of \c PACKET_MAX_SIZE.
*/
struct PacketStructured {
CCSDSPrimaryHeader header;
uint8_t buffer[PACKET_MAX_SIZE];
};
/**
* This union simplifies accessing the full data content of the Space Packet.
* This is achieved by putting the \c PacketStructured struct in a union with
* a plain buffer.
*/
union SpacePacketData {
PacketStructured fields;
uint8_t byteStream[PACKET_MAX_SIZE + sizeof(CCSDSPrimaryHeader)];
};
/**
* This is the data representation of the class.
* It is a struct of CCSDS Primary Header and a data field, which again is
* packed in an union, so the data can be accessed as a byte stream without
* a cast.
*/
SpacePacketData localData;
};
namespace spacepacket {
constexpr uint16_t getSpacePacketIdFromApid(bool isTc, uint16_t apid,
bool secondaryHeaderFlag = true) {
return ((isTc << 4) | (secondaryHeaderFlag << 3) |
((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
bool secondaryHeaderFlag = true) {
return ((isTc << 4) | (secondaryHeaderFlag << 3) | ((apid >> 8) & 0x07)) << 8 | (apid & 0x00ff);
}
constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid,
bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag);
constexpr uint16_t getTcSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(true, apid, secondaryHeaderFlag);
}
constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid,
bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag);
constexpr uint16_t getTmSpacePacketIdFromApid(uint16_t apid, bool secondaryHeaderFlag = true) {
return getSpacePacketIdFromApid(false, apid, secondaryHeaderFlag);
}
}
} // namespace spacepacket
#endif /* SPACEPACKET_H_ */

View File

@ -1,127 +1,118 @@
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) {
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
}
SpacePacketBase::~SpacePacketBase() {
};
SpacePacketBase::~SpacePacketBase(){};
//CCSDS Methods:
uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
return (this->data->header.packet_id_h & 0b11100000) >> 5;
// CCSDS Methods:
uint8_t SpacePacketBase::getPacketVersionNumber(void) {
return (this->data->header.packet_id_h & 0b11100000) >> 5;
}
ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
if(data == nullptr) {
ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
uint16_t apid, uint16_t sequenceCount) {
if (data == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid"
<< std::endl;
sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid" << std::endl;
#else
sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
#endif
#endif
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;
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 ) {
return (this->data->header.packet_id_h & 0b00010000) >> 4;
bool SpacePacketBase::isTelecommand(void) {
return (this->data->header.packet_id_h & 0b00010000) >> 4;
}
bool SpacePacketBase::hasSecondaryHeader( void ) {
return (this->data->header.packet_id_h & 0b00001000) >> 3;
bool SpacePacketBase::hasSecondaryHeader(void) {
return (this->data->header.packet_id_h & 0b00001000) >> 3;
}
uint16_t SpacePacketBase::getPacketId() {
return ( (this->data->header.packet_id_h) << 8 ) +
this->data->header.packet_id_l;
return ((this->data->header.packet_id_h) << 8) + this->data->header.packet_id_l;
}
uint16_t SpacePacketBase::getAPID( void ) const {
return ( (this->data->header.packet_id_h & 0b00000111) << 8 ) +
this->data->header.packet_id_l;
uint16_t SpacePacketBase::getAPID(void) const {
return ((this->data->header.packet_id_h & 0b00000111) << 8) + this->data->header.packet_id_l;
}
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).
this->data->header.packet_id_h = (this->data->header.packet_id_h & 0b11111000) |
( ( new_apid & 0x0700 ) >> 8 );
this->data->header.packet_id_l = ( new_apid & 0x00FF );
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).
this->data->header.packet_id_h =
(this->data->header.packet_id_h & 0b11111000) | ((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;
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 ) {
return ( (this->data->header.sequence_control_h) << 8 )
+ this->data->header.sequence_control_l;
uint16_t SpacePacketBase::getPacketSequenceControl(void) {
return ((this->data->header.sequence_control_h) << 8) + this->data->header.sequence_control_l;
}
uint8_t SpacePacketBase::getSequenceFlags( void ) {
return (this->data->header.sequence_control_h & 0b11000000) >> 6 ;
uint8_t SpacePacketBase::getSequenceFlags(void) {
return (this->data->header.sequence_control_h & 0b11000000) >> 6;
}
uint16_t SpacePacketBase::getPacketSequenceCount( void ) const {
return ( (this->data->header.sequence_control_h & 0b00111111) << 8 )
+ this->data->header.sequence_control_l;
uint16_t SpacePacketBase::getPacketSequenceCount(void) const {
return ((this->data->header.sequence_control_h & 0b00111111) << 8) +
this->data->header.sequence_control_l;
}
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_l = ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x00FF );
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_l = ((new_count % LIMIT_SEQUENCE_COUNT) & 0x00FF);
}
uint16_t SpacePacketBase::getPacketDataLength() const {
return ( (this->data->header.packet_length_h) << 8 )
+ this->data->header.packet_length_l;
return ((this->data->header.packet_length_h) << 8) + this->data->header.packet_length_l;
}
void SpacePacketBase::setPacketDataLength( uint16_t new_length) {
this->data->header.packet_length_h = ( ( new_length & 0xFF00 ) >> 8 );
this->data->header.packet_length_l = ( new_length & 0x00FF );
void SpacePacketBase::setPacketDataLength(uint16_t new_length) {
this->data->header.packet_length_h = ((new_length & 0xFF00) >> 8);
this->data->header.packet_length_l = (new_length & 0x00FF);
}
size_t SpacePacketBase::getFullSize() {
// +1 is done because size in packet data length field is: size of data field -1
return this->getPacketDataLength() + sizeof(this->data->header) + 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;
}
uint8_t* SpacePacketBase::getWholeData() {
return (uint8_t*)this->data;
}
uint8_t* SpacePacketBase::getWholeData() { return (uint8_t*)this->data; }
uint32_t SpacePacketBase::getApidAndSequenceCount() const {
return (getAPID() << 16) + getPacketSequenceCount();
return (getAPID() << 16) + getPacketSequenceCount();
}
uint8_t* SpacePacketBase::getPacketData() {
return &(data->packet_data);
}
uint8_t* SpacePacketBase::getPacketData() { return &(data->packet_data); }
ReturnValue_t SpacePacketBase::setData(uint8_t *pData, size_t maxSize, void *args) {
if(maxSize < 6) {
return HasReturnvaluesIF::RETURN_FAILED;
}
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(pData));
return HasReturnvaluesIF::RETURN_OK;
ReturnValue_t SpacePacketBase::setData(uint8_t* pData, size_t maxSize, void* args) {
if (maxSize < 6) {
return HasReturnvaluesIF::RETURN_FAILED;
}
this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(pData));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -2,11 +2,12 @@
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include "ccsds_header.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstddef>
#include "ccsds_header.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
/**
* @defgroup tmtcpackets Space Packets
* This is the group, where all classes associated with Telecommand and
@ -23,8 +24,8 @@
* @ingroup tmtcpackets
*/
struct SpacePacketPointer {
CCSDSPrimaryHeader header;
uint8_t packet_data;
CCSDSPrimaryHeader header;
uint8_t packet_data;
};
/**
@ -38,155 +39,154 @@ struct SpacePacketPointer {
* the most significant bit (from left).
* @ingroup tmtcpackets
*/
class SpacePacketBase: virtual public RedirectableDataPointerIF {
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet header.
* To be hardware-safe, all elements are of byte size.
*/
SpacePacketPointer* data;
public:
static const uint16_t LIMIT_APID = 2048; //2^1
static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14
static const uint16_t APID_IDLE_PACKET = 0x7FF;
static const uint8_t TELECOMMAND_PACKET = 1;
static const uint8_t TELEMETRY_PACKET = 0;
/**
* This definition defines the CRC size in byte.
*/
static const uint8_t CRC_SIZE = 2;
/**
* This is the minimum size of a SpacePacket.
*/
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed.
* @param set_address The position where the packet data lies.
*/
SpacePacketBase( const uint8_t* set_address );
/**
* No data is allocated, so the destructor is empty.
*/
virtual ~SpacePacketBase();
class SpacePacketBase : virtual public RedirectableDataPointerIF {
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet header.
* To be hardware-safe, all elements are of byte size.
*/
SpacePacketPointer* data;
//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 );
public:
static const uint16_t LIMIT_APID = 2048; // 2^1
static const uint16_t LIMIT_SEQUENCE_COUNT = 16384; // 2^14
static const uint16_t APID_IDLE_PACKET = 0x7FF;
static const uint8_t TELECOMMAND_PACKET = 1;
static const uint8_t TELEMETRY_PACKET = 0;
/**
* This definition defines the CRC size in byte.
*/
static const uint8_t CRC_SIZE = 2;
/**
* This is the minimum size of a SpacePacket.
*/
static const uint16_t MINIMUM_SIZE = sizeof(CCSDSPrimaryHeader) + CRC_SIZE;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed.
* @param set_address The position where the packet data lies.
*/
SpacePacketBase(const uint8_t* set_address);
/**
* No data is allocated, so the destructor is empty.
*/
virtual ~SpacePacketBase();
ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
uint16_t apid, uint16_t sequenceCount = 0);
/**
* The CCSDS header provides a secondary header flag (the fifth-highest bit),
* which is checked with this method.
* @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 );
// 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);
/**
* Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header.
* @param The sequence flags to set
*/
void setSequenceFlags( uint8_t sequenceflags );
ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid,
uint16_t sequenceCount = 0);
/**
* The CCSDS header provides a secondary header flag (the fifth-highest bit),
* which is checked with this method.
* @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);
/**
* 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 );
/**
* Sets the sequence flags of a packet, which are bit 17 and 18 in the space packet header.
* @param The sequence flags to set
*/
void setSequenceFlags(uint8_t sequenceflags);
//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 );
/**
* 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);
uint8_t* getPacketData();
// 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);
/**
* With this method, the packet data pointer can be redirected to another
* location.
* @param p_Data A pointer to another raw Space Packet.
*/
virtual ReturnValue_t setData(uint8_t* p_Data , size_t maxSize,
void* args = nullptr) override;
/**
* This method returns the full raw packet size.
* @return The full size of the packet in bytes.
*/
size_t getFullSize();
uint8_t* getPacketData();
uint32_t getApidAndSequenceCount() const;
/**
* With this method, the packet data pointer can be redirected to another
* location.
* @param p_Data A pointer to another raw Space Packet.
*/
virtual ReturnValue_t setData(uint8_t* p_Data, size_t maxSize, void* args = nullptr) override;
/**
* This method returns the full raw packet size.
* @return The full size of the packet in bytes.
*/
size_t getFullSize();
uint32_t getApidAndSequenceCount() const;
};
#endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */

View File

@ -4,12 +4,12 @@
#include <stdint.h>
struct CCSDSPrimaryHeader {
uint8_t packet_id_h;
uint8_t packet_id_l;
uint8_t sequence_control_h;
uint8_t sequence_control_l;
uint8_t packet_length_h;
uint8_t packet_length_l;
uint8_t packet_id_h;
uint8_t packet_id_l;
uint8_t sequence_control_h;
uint8_t sequence_control_l;
uint8_t packet_length_h;
uint8_t packet_length_l;
};
#endif /* CCSDS_HEADER_H_ */

View File

@ -1,20 +1,20 @@
#include "fsfw/tmtcpacket/cfdp/CFDPPacket.h"
#include <cstring>
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <cstring>
CFDPPacket::CFDPPacket(const uint8_t* setData): SpacePacketBase(setData) {}
CFDPPacket::CFDPPacket(const uint8_t* setData) : SpacePacketBase(setData) {}
CFDPPacket::~CFDPPacket() {}
void CFDPPacket::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "CFDPPacket::print:" << std::endl;
sif::info << "CFDPPacket::print:" << std::endl;
#else
sif::printInfo("CFDPPacket::print:\n");
sif::printInfo("CFDPPacket::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -4,24 +4,24 @@
#include "fsfw/tmtcpacket/SpacePacketBase.h"
class CFDPPacket : public SpacePacketBase {
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
CFDPPacket( const uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~CFDPPacket();
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
CFDPPacket(const uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~CFDPPacket();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
};
#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKET_H_ */

View File

@ -1,97 +1,92 @@
#include "fsfw/tmtcpacket/cfdp/CFDPPacketStored.h"
#include "fsfw/objectmanager/ObjectManager.h"
StorageManagerIF* CFDPPacketStored::store = nullptr;
CFDPPacketStored::CFDPPacketStored(): CFDPPacket(nullptr) {
CFDPPacketStored::CFDPPacketStored() : CFDPPacket(nullptr) {}
CFDPPacketStored::CFDPPacketStored(store_address_t setAddress) : CFDPPacket(nullptr) {
this->setStoreAddress(setAddress);
}
CFDPPacketStored::CFDPPacketStored(store_address_t setAddress): CFDPPacket(nullptr) {
this->setStoreAddress(setAddress);
}
CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size): CFDPPacket(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr, -1);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(const_cast<uint8_t*>(storePtr), size);
CFDPPacketStored::CFDPPacketStored(const uint8_t* data, size_t size) : CFDPPacket(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr, -1);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(const_cast<uint8_t*>(storePtr), size);
}
}
ReturnValue_t CFDPPacketStored::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
// To circumvent size checks
this->setData(nullptr, -1);
return result;
}
// CFDPPacket* CFDPPacketStored::getPacketBase() {
// return this;
// }
void CFDPPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
if (status == StorageManagerIF::RETURN_OK) {
this->setData(const_cast<uint8_t*>(tempData), tempSize);
} else {
// To circumvent size checks
this->setData(nullptr, -1);
return result;
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
//CFDPPacket* CFDPPacketStored::getPacketBase() {
// return this;
//}
void CFDPPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
if (status == StorageManagerIF::RETURN_OK) {
this->setData(const_cast<uint8_t*>(tempData), tempSize);
} else {
// To circumvent size checks
this->setData(nullptr, -1);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
store_address_t CFDPPacketStored::getStoreAddress() { return this->storeAddress; }
CFDPPacketStored::~CFDPPacketStored() {}
ReturnValue_t CFDPPacketStored::getData(const uint8_t** dataPtr, size_t* dataSize) {
return HasReturnvaluesIF::RETURN_OK;
}
store_address_t CFDPPacketStored::getStoreAddress() {
return this->storeAddress;
}
CFDPPacketStored::~CFDPPacketStored() {
}
ReturnValue_t CFDPPacketStored::getData(const uint8_t **dataPtr, size_t *dataSize) {
return HasReturnvaluesIF::RETURN_OK;
}
//ReturnValue_t CFDPPacketStored::setData(const uint8_t *data) {
// return HasReturnvaluesIF::RETURN_OK;
//}
// ReturnValue_t CFDPPacketStored::setData(const uint8_t *data) {
// return HasReturnvaluesIF::RETURN_OK;
// }
bool CFDPPacketStored::checkAndSetStore() {
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!"
<< std::endl;
sif::error << "CFDPPacketStored::CFDPPacketStored: TC Store not found!" << std::endl;
#endif
return false;
}
return false;
}
return true;
}
return true;
}
bool CFDPPacketStored::isSizeCorrect() {
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
return false;
}
return false;
}

View File

@ -4,64 +4,60 @@
#include "../pus/tc/TcPacketStoredBase.h"
#include "CFDPPacket.h"
class CFDPPacketStored:
public CFDPPacket,
public TcPacketStoredBase {
public:
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
CFDPPacketStored(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
CFDPPacketStored(store_address_t setAddress);
CFDPPacketStored();
class CFDPPacketStored : public CFDPPacket, public TcPacketStoredBase {
public:
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
CFDPPacketStored(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
CFDPPacketStored(store_address_t setAddress);
CFDPPacketStored();
virtual ~CFDPPacketStored();
virtual ~CFDPPacketStored();
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize);
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t** dataPtr, size_t* dataSize);
void setStoreAddress(store_address_t setAddress);
void setStoreAddress(store_address_t setAddress);
store_address_t getStoreAddress();
store_address_t getStoreAddress();
ReturnValue_t deletePacket();
ReturnValue_t deletePacket();
private:
private:
bool isSizeCorrect();
bool isSizeCorrect();
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
};
#endif /* FSFW_INC_FSFW_TMTCPACKET_CFDP_CFDPPACKETSTORED_H_ */

View File

@ -5,36 +5,28 @@
#include "../../serialize/SerializeAdapter.h"
#include "../../tmtcpacket/pus/tm/TmPacketMinimal.h"
class ApidMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
private:
uint16_t apid;
public:
ApidMatcher(uint16_t setApid) :
apid(setApid) {
}
ApidMatcher(TmPacketMinimal* test) :
apid(test->getAPID()) {
}
bool match(TmPacketMinimal* packet) {
if (packet->getAPID() == apid) {
return true;
} else {
return false;
}
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
return SerializeAdapter::serialize(&apid, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const {
return SerializeAdapter::getSerializedSize(&apid);
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&apid, buffer, size, streamEndianness);
class ApidMatcher : public SerializeableMatcherIF<TmPacketMinimal*> {
private:
uint16_t apid;
public:
ApidMatcher(uint16_t setApid) : apid(setApid) {}
ApidMatcher(TmPacketMinimal* test) : apid(test->getAPID()) {}
bool match(TmPacketMinimal* packet) {
if (packet->getAPID() == apid) {
return true;
} else {
return false;
}
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
return SerializeAdapter::serialize(&apid, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&apid); }
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&apid, buffer, size, streamEndianness);
}
};
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */

View File

@ -1,198 +1,190 @@
#include "fsfw/tmtcpacket/packetmatcher/ApidMatcher.h"
#include "fsfw/tmtcpacket/packetmatcher/PacketMatchTree.h"
#include "fsfw/tmtcpacket/packetmatcher/ApidMatcher.h"
#include "fsfw/tmtcpacket/packetmatcher/ServiceMatcher.h"
#include "fsfw/tmtcpacket/packetmatcher/SubserviceMatcher.h"
// This should be configurable..
const LocalPool::LocalPoolConfig PacketMatchTree::poolConfig = {
{10, sizeof(ServiceMatcher)},
{20, sizeof(SubServiceMatcher)},
{2, sizeof(ApidMatcher)},
{40, sizeof(PacketMatchTree::Node)}
};
{10, sizeof(ServiceMatcher)},
{20, sizeof(SubServiceMatcher)},
{2, sizeof(ApidMatcher)},
{40, sizeof(PacketMatchTree::Node)}};
PacketMatchTree::PacketMatchTree(Node* root): MatchTree<TmPacketMinimal*>(root, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {
}
PacketMatchTree::PacketMatchTree(Node* root)
: MatchTree<TmPacketMinimal*>(root, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {}
PacketMatchTree::PacketMatchTree(iterator root): MatchTree<TmPacketMinimal*>(root.element, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {
}
PacketMatchTree::PacketMatchTree(iterator root)
: MatchTree<TmPacketMinimal*>(root.element, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {}
PacketMatchTree::PacketMatchTree(): MatchTree<TmPacketMinimal*>((Node*) NULL, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {
}
PacketMatchTree::PacketMatchTree()
: MatchTree<TmPacketMinimal*>((Node*)NULL, 2),
factoryBackend(0, poolConfig, false, true),
factory(&factoryBackend) {}
PacketMatchTree::~PacketMatchTree() {
}
PacketMatchTree::~PacketMatchTree() {}
ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type,
uint8_t subtype) {
//We assume adding APID is always requested.
TmPacketMinimal::TmPacketMinimalPointer data;
data.data_field.service_type = type;
data.data_field.service_subtype = subtype;
TmPacketMinimal testPacket((uint8_t*) &data);
testPacket.setAPID(apid);
iterator lastTest;
iterator rollback;
ReturnValue_t result = findOrInsertMatch<TmPacketMinimal*, ApidMatcher>(
this->begin(), &testPacket, &lastTest);
if (result == NEW_NODE_CREATED) {
rollback = lastTest;
} else if (result != RETURN_OK) {
return result;
}
if (type == 0) {
//Check if lastTest has no children, otherwise, delete them,
//as a more general check is requested.
if (lastTest.left() != this->end()) {
removeElementAndAllChildren(lastTest.left());
}
return RETURN_OK;
}
//Type insertion required.
result = findOrInsertMatch<TmPacketMinimal*, ServiceMatcher>(
lastTest.left(), &testPacket, &lastTest);
if (result == NEW_NODE_CREATED) {
if (rollback == this->end()) {
rollback = lastTest;
}
} else if (result != RETURN_OK) {
if (rollback != this->end()) {
removeElementAndAllChildren(rollback);
}
return result;
}
if (subtype == 0) {
if (lastTest.left() != this->end()) {
//See above
removeElementAndAllChildren(lastTest.left());
}
return RETURN_OK;
}
//Subtype insertion required.
result = findOrInsertMatch<TmPacketMinimal*, SubServiceMatcher>(
lastTest.left(), &testPacket, &lastTest);
if (result == NEW_NODE_CREATED) {
return RETURN_OK;
} else if (result != RETURN_OK) {
if (rollback != this->end()) {
removeElementAndAllChildren(rollback);
}
return result;
ReturnValue_t PacketMatchTree::addMatch(uint16_t apid, uint8_t type, uint8_t subtype) {
// We assume adding APID is always requested.
TmPacketMinimal::TmPacketMinimalPointer data;
data.data_field.service_type = type;
data.data_field.service_subtype = subtype;
TmPacketMinimal testPacket((uint8_t*)&data);
testPacket.setAPID(apid);
iterator lastTest;
iterator rollback;
ReturnValue_t result =
findOrInsertMatch<TmPacketMinimal*, ApidMatcher>(this->begin(), &testPacket, &lastTest);
if (result == NEW_NODE_CREATED) {
rollback = lastTest;
} else if (result != RETURN_OK) {
return result;
}
if (type == 0) {
// Check if lastTest has no children, otherwise, delete them,
// as a more general check is requested.
if (lastTest.left() != this->end()) {
removeElementAndAllChildren(lastTest.left());
}
return RETURN_OK;
}
// Type insertion required.
result =
findOrInsertMatch<TmPacketMinimal*, ServiceMatcher>(lastTest.left(), &testPacket, &lastTest);
if (result == NEW_NODE_CREATED) {
if (rollback == this->end()) {
rollback = lastTest;
}
} else if (result != RETURN_OK) {
if (rollback != this->end()) {
removeElementAndAllChildren(rollback);
}
return result;
}
if (subtype == 0) {
if (lastTest.left() != this->end()) {
// See above
removeElementAndAllChildren(lastTest.left());
}
return RETURN_OK;
}
// Subtype insertion required.
result = findOrInsertMatch<TmPacketMinimal*, SubServiceMatcher>(lastTest.left(), &testPacket,
&lastTest);
if (result == NEW_NODE_CREATED) {
return RETURN_OK;
} else if (result != RETURN_OK) {
if (rollback != this->end()) {
removeElementAndAllChildren(rollback);
}
return result;
}
return RETURN_OK;
}
template<typename VALUE_T, typename INSERTION_T>
template <typename VALUE_T, typename INSERTION_T>
ReturnValue_t PacketMatchTree::findOrInsertMatch(iterator startAt, VALUE_T test,
iterator* lastTest) {
bool attachToBranch = AND;
iterator iter = startAt;
while (iter != this->end()) {
bool isMatch = iter->match(test);
attachToBranch = OR;
*lastTest = iter;
if (isMatch) {
return RETURN_OK;
} else {
//Go down OR branch.
iter = iter.right();
}
}
//Only reached if nothing was found.
SerializeableMatcherIF<VALUE_T>* newContent = factory.generate<INSERTION_T>(
test);
if (newContent == NULL) {
return FULL;
}
Node* newNode = factory.generate<Node>(newContent);
if (newNode == NULL) {
//Need to make sure partially generated content is deleted, otherwise, that's a leak.
factory.destroy<INSERTION_T>(static_cast<INSERTION_T*>(newContent));
return FULL;
}
*lastTest = insert(attachToBranch, *lastTest, newNode);
if (*lastTest == end()) {
//This actaully never fails, so creating a dedicated returncode seems an overshoot.
return RETURN_FAILED;
}
return NEW_NODE_CREATED;
}
ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type,
uint8_t subtype) {
TmPacketMinimal::TmPacketMinimalPointer data;
data.data_field.service_type = type;
data.data_field.service_subtype = subtype;
TmPacketMinimal testPacket((uint8_t*) &data);
testPacket.setAPID(apid);
iterator foundElement = findMatch(begin(), &testPacket);
if (foundElement == this->end()) {
return NO_MATCH;
}
if (type == 0) {
if (foundElement.left() == end()) {
return removeElementAndReconnectChildren(foundElement);
} else {
return TOO_GENERAL_REQUEST;
}
}
//Go down AND branch. Will abort if empty.
foundElement = findMatch(foundElement.left(), &testPacket);
if (foundElement == this->end()) {
return NO_MATCH;
}
if (subtype == 0) {
if (foundElement.left() == end()) {
return removeElementAndReconnectChildren(foundElement);
} else {
return TOO_GENERAL_REQUEST;
}
}
//Again, go down AND branch.
foundElement = findMatch(foundElement.left(), &testPacket);
if (foundElement == end()) {
return NO_MATCH;
}
return removeElementAndReconnectChildren(foundElement);
}
PacketMatchTree::iterator PacketMatchTree::findMatch(iterator startAt,
TmPacketMinimal* test) {
iterator iter = startAt;
while (iter != end()) {
bool isMatch = iter->match(test);
if (isMatch) {
break;
} else {
iter = iter.right(); //next OR element
}
}
return iter;
}
ReturnValue_t PacketMatchTree::initialize() {
return factoryBackend.initialize();
}
ReturnValue_t PacketMatchTree::changeMatch(bool addToMatch, uint16_t apid,
uint8_t type, uint8_t subtype) {
if (addToMatch) {
return addMatch(apid, type, subtype);
iterator* lastTest) {
bool attachToBranch = AND;
iterator iter = startAt;
while (iter != this->end()) {
bool isMatch = iter->match(test);
attachToBranch = OR;
*lastTest = iter;
if (isMatch) {
return RETURN_OK;
} else {
return removeMatch(apid, type, subtype);
// Go down OR branch.
iter = iter.right();
}
}
// Only reached if nothing was found.
SerializeableMatcherIF<VALUE_T>* newContent = factory.generate<INSERTION_T>(test);
if (newContent == NULL) {
return FULL;
}
Node* newNode = factory.generate<Node>(newContent);
if (newNode == NULL) {
// Need to make sure partially generated content is deleted, otherwise, that's a leak.
factory.destroy<INSERTION_T>(static_cast<INSERTION_T*>(newContent));
return FULL;
}
*lastTest = insert(attachToBranch, *lastTest, newNode);
if (*lastTest == end()) {
// This actaully never fails, so creating a dedicated returncode seems an overshoot.
return RETURN_FAILED;
}
return NEW_NODE_CREATED;
}
ReturnValue_t PacketMatchTree::removeMatch(uint16_t apid, uint8_t type, uint8_t subtype) {
TmPacketMinimal::TmPacketMinimalPointer data;
data.data_field.service_type = type;
data.data_field.service_subtype = subtype;
TmPacketMinimal testPacket((uint8_t*)&data);
testPacket.setAPID(apid);
iterator foundElement = findMatch(begin(), &testPacket);
if (foundElement == this->end()) {
return NO_MATCH;
}
if (type == 0) {
if (foundElement.left() == end()) {
return removeElementAndReconnectChildren(foundElement);
} else {
return TOO_GENERAL_REQUEST;
}
}
// Go down AND branch. Will abort if empty.
foundElement = findMatch(foundElement.left(), &testPacket);
if (foundElement == this->end()) {
return NO_MATCH;
}
if (subtype == 0) {
if (foundElement.left() == end()) {
return removeElementAndReconnectChildren(foundElement);
} else {
return TOO_GENERAL_REQUEST;
}
}
// Again, go down AND branch.
foundElement = findMatch(foundElement.left(), &testPacket);
if (foundElement == end()) {
return NO_MATCH;
}
return removeElementAndReconnectChildren(foundElement);
}
PacketMatchTree::iterator PacketMatchTree::findMatch(iterator startAt, TmPacketMinimal* test) {
iterator iter = startAt;
while (iter != end()) {
bool isMatch = iter->match(test);
if (isMatch) {
break;
} else {
iter = iter.right(); // next OR element
}
}
return iter;
}
ReturnValue_t PacketMatchTree::initialize() { return factoryBackend.initialize(); }
ReturnValue_t PacketMatchTree::changeMatch(bool addToMatch, uint16_t apid, uint8_t type,
uint8_t subtype) {
if (addToMatch) {
return addMatch(apid, type, subtype);
} else {
return removeMatch(apid, type, subtype);
}
}
ReturnValue_t PacketMatchTree::cleanUpElement(iterator position) {
factory.destroy(position.element->value);
//Go on anyway, there's nothing we can do.
//SHOULDDO: Throw event, or write debug message?
return factory.destroy(position.element);
factory.destroy(position.element->value);
// Go on anyway, there's nothing we can do.
// SHOULDDO: Throw event, or write debug message?
return factory.destroy(position.element);
}

View File

@ -6,32 +6,30 @@
#include "fsfw/storagemanager/LocalPool.h"
#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h"
class PacketMatchTree: public MatchTree<TmPacketMinimal*>, public HasReturnvaluesIF {
public:
PacketMatchTree(Node* root);
PacketMatchTree(iterator root);
PacketMatchTree();
virtual ~PacketMatchTree();
ReturnValue_t changeMatch(bool addToMatch, uint16_t apid, uint8_t type = 0,
uint8_t subtype = 0);
ReturnValue_t addMatch(uint16_t apid, uint8_t type = 0,
uint8_t subtype = 0);
ReturnValue_t removeMatch(uint16_t apid, uint8_t type = 0,
uint8_t subtype = 0);
ReturnValue_t initialize();
protected:
ReturnValue_t cleanUpElement(iterator position);
private:
static const uint8_t N_POOLS = 4;
LocalPool factoryBackend;
PlacementFactory factory;
static const LocalPool::LocalPoolConfig poolConfig;
static const uint16_t POOL_SIZES[N_POOLS];
static const uint16_t N_ELEMENTS[N_POOLS];
template<typename VALUE_T, typename INSERTION_T>
ReturnValue_t findOrInsertMatch(iterator startAt, VALUE_T test, iterator* lastTest);
iterator findMatch(iterator startAt, TmPacketMinimal* test);
class PacketMatchTree : public MatchTree<TmPacketMinimal*>, public HasReturnvaluesIF {
public:
PacketMatchTree(Node* root);
PacketMatchTree(iterator root);
PacketMatchTree();
virtual ~PacketMatchTree();
ReturnValue_t changeMatch(bool addToMatch, uint16_t apid, uint8_t type = 0, uint8_t subtype = 0);
ReturnValue_t addMatch(uint16_t apid, uint8_t type = 0, uint8_t subtype = 0);
ReturnValue_t removeMatch(uint16_t apid, uint8_t type = 0, uint8_t subtype = 0);
ReturnValue_t initialize();
protected:
ReturnValue_t cleanUpElement(iterator position);
private:
static const uint8_t N_POOLS = 4;
LocalPool factoryBackend;
PlacementFactory factory;
static const LocalPool::LocalPoolConfig poolConfig;
static const uint16_t POOL_SIZES[N_POOLS];
static const uint16_t N_ELEMENTS[N_POOLS];
template <typename VALUE_T, typename INSERTION_T>
ReturnValue_t findOrInsertMatch(iterator startAt, VALUE_T test, iterator* lastTest);
iterator findMatch(iterator startAt, TmPacketMinimal* test);
};
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_ */

View File

@ -5,35 +5,28 @@
#include "../../serialize/SerializeAdapter.h"
#include "../pus/tm/TmPacketMinimal.h"
class ServiceMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
private:
uint8_t service;
public:
ServiceMatcher(uint8_t setService) :
service(setService) {
}
ServiceMatcher(TmPacketMinimal* test) :
service(test->getService()) {
}
bool match(TmPacketMinimal* packet) {
if (packet->getService() == service) {
return true;
} else {
return false;
}
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
return SerializeAdapter::serialize(&service, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const {
return SerializeAdapter::getSerializedSize(&service);
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&service, buffer, size, streamEndianness);
class ServiceMatcher : public SerializeableMatcherIF<TmPacketMinimal*> {
private:
uint8_t service;
public:
ServiceMatcher(uint8_t setService) : service(setService) {}
ServiceMatcher(TmPacketMinimal* test) : service(test->getService()) {}
bool match(TmPacketMinimal* packet) {
if (packet->getService() == service) {
return true;
} else {
return false;
}
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
return SerializeAdapter::serialize(&service, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); }
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&service, buffer, size, streamEndianness);
}
};
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_ */

View File

@ -5,36 +5,28 @@
#include "../../serialize/SerializeAdapter.h"
#include "../pus/tm/TmPacketMinimal.h"
class SubServiceMatcher: public SerializeableMatcherIF<TmPacketMinimal*> {
public:
SubServiceMatcher(uint8_t subService) :
subService(subService) {
class SubServiceMatcher : public SerializeableMatcherIF<TmPacketMinimal*> {
public:
SubServiceMatcher(uint8_t subService) : subService(subService) {}
SubServiceMatcher(TmPacketMinimal* test) : subService(test->getSubService()) {}
bool match(TmPacketMinimal* packet) {
if (packet->getSubService() == subService) {
return true;
} else {
return false;
}
SubServiceMatcher(TmPacketMinimal* test) :
subService(test->getSubService()) {
}
bool match(TmPacketMinimal* packet) {
if (packet->getSubService() == subService) {
return true;
} else {
return false;
}
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
size_t maxSize, Endianness streamEndianness) const {
return SerializeAdapter::serialize(&subService, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const {
return SerializeAdapter::getSerializedSize(&subService);
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&subService, buffer, size, streamEndianness);
}
private:
uint8_t subService;
}
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const {
return SerializeAdapter::serialize(&subService, buffer, size, maxSize, streamEndianness);
}
size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); }
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&subService, buffer, size, streamEndianness);
}
private:
uint8_t subService;
};
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_ */

View File

@ -6,14 +6,11 @@
class TmPacketMinimal;
class PacketTimestampInterpreterIF {
public:
virtual ~PacketTimestampInterpreterIF() {}
virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet,
timeval* timestamp) const = 0;
virtual ReturnValue_t getPacketTimeRaw(TmPacketMinimal* packet, const uint8_t** timePtr,
uint32_t* size) const = 0;
public:
virtual ~PacketTimestampInterpreterIF() {}
virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet, timeval* timestamp) const = 0;
virtual ReturnValue_t getPacketTimeRaw(TmPacketMinimal* packet, const uint8_t** timePtr,
uint32_t* size) const = 0;
};
#endif /* FSFW_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ */

View File

@ -6,11 +6,8 @@
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
};
enum PusVersion : uint8_t { PUS_A_VERSION = 1, PUS_C_VERSION = 2 };
}
} // namespace pus
#endif /* FSFW_SRC_FSFW_TMTCPACKET_PUS_TM_DEFINITIONS_H_ */

View File

@ -1,7 +1,7 @@
#ifndef FSFW_TMTCPACKET_PUS_TC_H_
#define FSFW_TMTCPACKET_PUS_TC_H_
#include "tc/TcPacketStoredPus.h"
#include "tc/TcPacketPus.h"
#include "tc/TcPacketStoredPus.h"
#endif /* FSFW_TMTCPACKET_PUS_TC_H_ */

View File

@ -1,105 +1,99 @@
#include "TcPacketPus.h"
#include "fsfw/globalfunctions/CRC.h"
#include <cstring>
TcPacketPus::TcPacketPus(const uint8_t *setData): TcPacketPusBase(setData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(setData));
#include "fsfw/globalfunctions/CRC.h"
TcPacketPus::TcPacketPus(const uint8_t *setData) : TcPacketPusBase(setData) {
tcData = reinterpret_cast<TcPacketPointer *>(const_cast<uint8_t *>(setData));
}
void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice, pus::PusVersion pusVersion,
uint16_t sourceId) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header. For PUS A, the first bit (CCSDS Secondary Header Flag) is zero
tcData->dataField.versionTypeAck = pusVersion << 4 | (ack & 0x0F);
tcData->dataField.serviceType = service;
tcData->dataField.serviceSubtype = subservice;
void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack,
uint8_t service, uint8_t subservice,
pus::PusVersion pusVersion, uint16_t sourceId) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header. For PUS A, the first bit (CCSDS Secondary Header Flag) is zero
tcData->dataField.versionTypeAck = pusVersion << 4 | (ack & 0x0F);
tcData->dataField.serviceType = service;
tcData->dataField.serviceSubtype = subservice;
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
tcData->dataField.sourceIdH = (sourceId >> 8) | 0xff;
tcData->dataField.sourceIdL = sourceId & 0xff;
tcData->dataField.sourceIdH = (sourceId >> 8) | 0xff;
tcData->dataField.sourceIdL = sourceId & 0xff;
#else
tcData->dataField.sourceId = sourceId;
tcData->dataField.sourceId = sourceId;
#endif
}
uint8_t TcPacketPus::getService() const {
return tcData->dataField.serviceType;
}
uint8_t TcPacketPus::getService() const { return tcData->dataField.serviceType; }
uint8_t TcPacketPus::getSubService() const {
return tcData->dataField.serviceSubtype;
}
uint8_t TcPacketPus::getSubService() const { return tcData->dataField.serviceSubtype; }
uint8_t TcPacketPus::getAcknowledgeFlags() const {
return tcData->dataField.versionTypeAck & 0b00001111;
return tcData->dataField.versionTypeAck & 0b00001111;
}
const uint8_t* TcPacketPus::getApplicationData() const {
return &tcData->appData;
}
const uint8_t *TcPacketPus::getApplicationData() const { return &tcData->appData; }
uint16_t TcPacketPus::getApplicationDataSize() const {
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
}
uint16_t TcPacketPus::getErrorControl() const {
uint16_t size = getApplicationDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tcData->appData;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
uint16_t size = getApplicationDataSize() + CRC_SIZE;
uint8_t *p_to_buffer = &tcData->appData;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TcPacketPus::setErrorControl() {
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getApplicationDataSize();
(&tcData->appData)[size] = (crc & 0XFF00) >> 8; // CRCH
(&tcData->appData)[size + 1] = (crc) & 0X00FF; // CRCL
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getApplicationDataSize();
(&tcData->appData)[size] = (crc & 0XFF00) >> 8; // CRCH
(&tcData->appData)[size + 1] = (crc)&0X00FF; // CRCL
}
uint8_t TcPacketPus::getSecondaryHeaderFlag() const {
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
// Does not exist for PUS C
return 0;
// Does not exist for PUS C
return 0;
#else
return (tcData->dataField.versionTypeAck & 0b10000000) >> 7;
return (tcData->dataField.versionTypeAck & 0b10000000) >> 7;
#endif
}
uint8_t TcPacketPus::getPusVersionNumber() const {
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
return (tcData->dataField.versionTypeAck & 0b11110000) >> 4;
return (tcData->dataField.versionTypeAck & 0b11110000) >> 4;
#else
return (tcData->dataField.versionTypeAck & 0b01110000) >> 4;
return (tcData->dataField.versionTypeAck & 0b01110000) >> 4;
#endif
}
uint16_t TcPacketPus::getSourceId() const {
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
return (tcData->dataField.sourceIdH << 8) | tcData->dataField.sourceIdL;
return (tcData->dataField.sourceIdH << 8) | tcData->dataField.sourceIdL;
#else
return tcData->dataField.sourceId;
return tcData->dataField.sourceId;
#endif
}
size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const {
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
appDataLen + TcPacketPusBase::CRC_SIZE;
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + appDataLen +
TcPacketPusBase::CRC_SIZE;
}
ReturnValue_t TcPacketPus::setData(uint8_t *dataPtr, size_t maxSize, void *args) {
ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(maxSize < sizeof(TcPacketPointer)) {
return HasReturnvaluesIF::RETURN_FAILED;
}
// This function is const-correct, but it was decided to keep the pointer non-const
// for convenience. Therefore, cast away constness here and then cast to packet type.
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(dataPtr));
return HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = SpacePacketBase::setData(dataPtr, maxSize);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (maxSize < sizeof(TcPacketPointer)) {
return HasReturnvaluesIF::RETURN_FAILED;
}
// This function is const-correct, but it was decided to keep the pointer non-const
// for convenience. Therefore, cast away constness here and then cast to packet type.
tcData = reinterpret_cast<TcPacketPointer *>(const_cast<uint8_t *>(dataPtr));
return HasReturnvaluesIF::RETURN_OK;
}

View File

@ -1,13 +1,13 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_
#include "fsfw/FSFW.h"
#include "../definitions.h"
#include "fsfw/tmtcpacket/ccsds_header.h"
#include "TcPacketPusBase.h"
#include <cstdint>
#include "../definitions.h"
#include "TcPacketPusBase.h"
#include "fsfw/FSFW.h"
#include "fsfw/tmtcpacket/ccsds_header.h"
/**
* This struct defines a byte-wise structured PUS TC A Data Field Header.
* Any optional fields in the header must be added or removed here.
@ -15,14 +15,14 @@
* @ingroup tmtcpackets
*/
struct PUSTcDataFieldHeader {
uint8_t versionTypeAck;
uint8_t serviceType;
uint8_t serviceSubtype;
uint8_t versionTypeAck;
uint8_t serviceType;
uint8_t serviceSubtype;
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
uint8_t sourceIdH;
uint8_t sourceIdL;
uint8_t sourceIdH;
uint8_t sourceIdL;
#else
uint8_t sourceId;
uint8_t sourceId;
#endif
};
@ -32,62 +32,57 @@ struct PUSTcDataFieldHeader {
* @ingroup tmtcpackets
*/
struct TcPacketPointer {
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader dataField;
uint8_t appData;
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader dataField;
uint8_t appData;
};
class TcPacketPus : public TcPacketPusBase {
public:
static const uint16_t TC_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2);
class TcPacketPus: public TcPacketPusBase {
public:
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTcDataFieldHeader) + 2);
/**
* Initialize a PUS A telecommand packet which already exists. You can also
* create an empty (invalid) object by passing nullptr as the data pointer
* @param setData
*/
TcPacketPus(const uint8_t* setData);
/**
* Initialize a PUS A telecommand packet which already exists. You can also
* create an empty (invalid) object by passing nullptr as the data pointer
* @param setData
*/
TcPacketPus(const uint8_t* setData);
// Base class overrides
uint8_t getSecondaryHeaderFlag() const override;
uint8_t getPusVersionNumber() const override;
uint8_t getAcknowledgeFlags() const override;
uint8_t getService() const override;
uint8_t getSubService() const override;
uint16_t getSourceId() const override;
const uint8_t* getApplicationData() const override;
uint16_t getApplicationDataSize() const override;
uint16_t getErrorControl() const override;
void setErrorControl() override;
size_t calculateFullPacketLength(size_t appDataLen) const override;
// Base class overrides
uint8_t getSecondaryHeaderFlag() const override;
uint8_t getPusVersionNumber() const override;
uint8_t getAcknowledgeFlags() const override;
uint8_t getService() const override;
uint8_t getSubService() const override;
uint16_t getSourceId() const override;
const uint8_t* getApplicationData() const override;
uint16_t getApplicationDataSize() const override;
uint16_t getErrorControl() const override;
void setErrorControl() override;
size_t calculateFullPacketLength(size_t appDataLen) const override;
protected:
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize, void* args = nullptr) override;
protected:
/**
* Initializes the Tc Packet header.
* @param apid APID used.
* @param sequenceCount Sequence Count in the primary header.
* @param ack Which acknowledeges are expected from the receiver.
* @param service PUS Service
* @param subservice PUS Subservice
*/
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service,
uint8_t subservice, pus::PusVersion pusVersion, uint16_t sourceId = 0);
ReturnValue_t setData(uint8_t* dataPtr, size_t maxSize,
void* args = nullptr) override;
/**
* Initializes the Tc Packet header.
* @param apid APID used.
* @param sequenceCount Sequence Count in the primary header.
* @param ack Which acknowledeges are expected from the receiver.
* @param service PUS Service
* @param subservice PUS Subservice
*/
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack,
uint8_t service, uint8_t subservice, pus::PusVersion pusVersion,
uint16_t sourceId = 0);
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TcPacketPointer* tcData = nullptr;
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TcPacketPointer* tcData = nullptr;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETPUSA_H_ */

View File

@ -1,20 +1,20 @@
#include "TcPacketPusBase.h"
#include <cstring>
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <cstring>
TcPacketPusBase::TcPacketPusBase(const uint8_t* setData): SpacePacketBase(setData) {}
TcPacketPusBase::TcPacketPusBase(const uint8_t* setData) : SpacePacketBase(setData) {}
TcPacketPusBase::~TcPacketPusBase() {}
void TcPacketPusBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TcPacketBase::print:" << std::endl;
sif::info << "TcPacketBase::print:" << std::endl;
#else
sif::printInfo("TcPacketBase::print:\n");
sif::printInfo("TcPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -2,9 +2,11 @@
#define TMTCPACKET_PUS_TCPACKETBASE_H_
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include <cstddef>
#include "fsfw/tmtcpacket/SpacePacketBase.h"
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
*
@ -16,139 +18,134 @@
* check can be performed by making use of the getWholeData method.
* @ingroup tmtcpackets
*/
class TcPacketPusBase : public SpacePacketBase,
virtual public RedirectableDataPointerIF {
friend class TcPacketStoredBase;
public:
class TcPacketPusBase : public SpacePacketBase, virtual public RedirectableDataPointerIF {
friend class TcPacketStoredBase;
enum AckField {
//! No acknowledgements are expected.
ACK_NONE = 0b0000,
//! Acknowledgements on acceptance are expected.
ACK_ACCEPTANCE = 0b0001,
//! Acknowledgements on start are expected.
ACK_START = 0b0010,
//! Acknowledgements on step are expected.
ACK_STEP = 0b0100,
//! Acknowledfgement on completion are expected.
ACK_COMPLETION = 0b1000
};
public:
enum AckField {
//! No acknowledgements are expected.
ACK_NONE = 0b0000,
//! Acknowledgements on acceptance are expected.
ACK_ACCEPTANCE = 0b0001,
//! Acknowledgements on start are expected.
ACK_START = 0b0010,
//! Acknowledgements on step are expected.
ACK_STEP = 0b0100,
//! Acknowledfgement on completion are expected.
ACK_COMPLETION = 0b1000
};
static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP |
ACK_COMPLETION;
static constexpr uint8_t ACK_ALL = ACK_ACCEPTANCE | ACK_START | ACK_STEP | ACK_COMPLETION;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
TcPacketPusBase( const uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TcPacketPusBase();
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param setData The position where the packet data lies.
*/
TcPacketPusBase(const uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TcPacketPusBase();
/**
* This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
*/
virtual uint8_t getSecondaryHeaderFlag() const = 0;
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.
* It consists of the second to fourth highest bits of the
* first byte.
* @return
*/
virtual uint8_t getPusVersionNumber() const = 0;
/**
* This is a getter for the packet's Ack field, which are the lowest four
* bits of the first byte of the Data Field Header.
*
* It is packed in a uint8_t variable.
* @return The packet's PUS Ack field.
*/
virtual uint8_t getAcknowledgeFlags() const = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() const = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() const = 0;
/**
* The source ID can be used to have an additional identifier, e.g. for different ground
* station.
* @return
*/
virtual uint16_t getSourceId() const = 0;
/**
* This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
*/
virtual uint8_t getSecondaryHeaderFlag() const = 0;
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.
* It consists of the second to fourth highest bits of the
* first byte.
* @return
*/
virtual uint8_t getPusVersionNumber() const = 0;
/**
* This is a getter for the packet's Ack field, which are the lowest four
* bits of the first byte of the Data Field Header.
*
* It is packed in a uint8_t variable.
* @return The packet's PUS Ack field.
*/
virtual uint8_t getAcknowledgeFlags() const = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() const = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() const = 0;
/**
* The source ID can be used to have an additional identifier, e.g. for different ground
* station.
* @return
*/
virtual uint16_t getSourceId() const = 0;
/**
* This is a getter for a pointer to the packet's Application data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's application data.
* @return A pointer to the PUS Application Data.
*/
virtual const uint8_t* getApplicationData() const = 0;
/**
* This method calculates the size of the PUS Application data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Application Data (without Error Control
* field)
*/
virtual uint16_t getApplicationDataSize() const = 0;
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Application Data. If no
* Application Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
virtual uint16_t getErrorControl() const = 0;
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet.
*/
virtual void setErrorControl() = 0;
/**
* This is a getter for a pointer to the packet's Application data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's application data.
* @return A pointer to the PUS Application Data.
*/
virtual const uint8_t* getApplicationData() const = 0;
/**
* This method calculates the size of the PUS Application data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Application Data (without Error Control
* field)
*/
virtual uint16_t getApplicationDataSize() const = 0;
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Application Data. If no
* Application Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
virtual uint16_t getErrorControl() const = 0;
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet.
*/
virtual void setErrorControl() = 0;
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
virtual size_t calculateFullPacketLength(size_t appDataLen) const = 0;
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
virtual size_t calculateFullPacketLength(size_t appDataLen) const = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
protected:
/**
* With this method, the packet data pointer can be redirected to another
* location.
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
virtual ReturnValue_t setData(uint8_t* pData, size_t maxSize,
void* args = nullptr) override = 0;
protected:
/**
* With this method, the packet data pointer can be redirected to another
* location.
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
virtual ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override = 0;
};
#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */

View File

@ -1,70 +1,61 @@
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredBase.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/objectmanager/frameworkObjects.h"
#include <cstring>
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/objectmanager/frameworkObjects.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
StorageManagerIF* TcPacketStoredBase::store = nullptr;
TcPacketStoredBase::TcPacketStoredBase() {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
}
TcPacketStoredBase::~TcPacketStoredBase() {
}
TcPacketStoredBase::~TcPacketStoredBase() {}
ReturnValue_t TcPacketStoredBase::getData(const uint8_t ** dataPtr,
size_t* dataSize) {
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
ReturnValue_t TcPacketStoredBase::getData(const uint8_t** dataPtr, size_t* dataSize) {
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
if (result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStoredBase: Could not get data!" << std::endl;
sif::warning << "TcPacketStoredBase: Could not get data!" << std::endl;
#else
sif::printWarning("TcPacketStoredBase: Could not get data!\n");
sif::printWarning("TcPacketStoredBase: Could not get data!\n");
#endif
}
return result;
}
return result;
}
bool TcPacketStoredBase::checkAndSetStore() {
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
this->store = ObjectManager::instance()->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found!"
<< std::endl;
sif::error << "TcPacketStoredBase::TcPacketStoredBase: TC Store not found!" << std::endl;
#endif
return false;
}
return false;
}
return true;
}
return true;
}
void TcPacketStoredBase::setStoreAddress(store_address_t setAddress,
RedirectableDataPointerIF* packet) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
RedirectableDataPointerIF* packet) {
this->storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &tempData, &tempSize);
}
if (status == StorageManagerIF::RETURN_OK) {
packet->setData(const_cast<uint8_t*>(tempData), tempSize);
}
else {
packet->setData(nullptr, -1);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
if (status == StorageManagerIF::RETURN_OK) {
packet->setData(const_cast<uint8_t*>(tempData), tempSize);
} else {
packet->setData(nullptr, -1);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
store_address_t TcPacketStoredBase::getStoreAddress() {
return this->storeAddress;
}
store_address_t TcPacketStoredBase::getStoreAddress() { return this->storeAddress; }

View File

@ -8,77 +8,76 @@
* Base class for telecommand packets like CFDP or PUS packets.
* @ingroup tmtcpackets
*/
class TcPacketStoredBase: public TcPacketStoredIF {
public:
/**
* This is a default constructor which does not set the data pointer to initialize
* with an empty cached store address
*/
TcPacketStoredBase();
/**
* Constructor to set to an existing store address.
* @param setAddress
*/
TcPacketStoredBase(store_address_t setAddress);
/**
* Another constructor to create a TcPacket from a raw packet stream.
* Takes the data and adds it unchecked to the TcStore.
* @param data Pointer to the complete TC Space Packet.
* @param Size size of the packet.
*/
TcPacketStoredBase(const uint8_t* data, uint32_t size);
class TcPacketStoredBase : public TcPacketStoredIF {
public:
/**
* This is a default constructor which does not set the data pointer to initialize
* with an empty cached store address
*/
TcPacketStoredBase();
/**
* Constructor to set to an existing store address.
* @param setAddress
*/
TcPacketStoredBase(store_address_t setAddress);
/**
* Another constructor to create a TcPacket from a raw packet stream.
* Takes the data and adds it unchecked to the TcStore.
* @param data Pointer to the complete TC Space Packet.
* @param Size size of the packet.
*/
TcPacketStoredBase(const uint8_t* data, uint32_t size);
virtual~ TcPacketStoredBase();
virtual ~TcPacketStoredBase();
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize) override;
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
ReturnValue_t getData(const uint8_t** dataPtr, size_t* dataSize) override;
void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) override;
store_address_t getStoreAddress() override;
void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) override;
store_address_t getStoreAddress() override;
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
* @return returncode from deleting the data.
*/
virtual ReturnValue_t deletePacket() = 0;
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
* @return returncode from deleting the data.
*/
virtual ReturnValue_t deletePacket() = 0;
/**
* This method performs a size check.
* It reads the stored size and compares it with the size entered in the
* packet header. This class is the optimal place for such a check as it
* has access to both the header data and the store.
* @return true if size is correct, false if packet is not registered in
* store or size is incorrect.
*/
virtual bool isSizeCorrect() = 0;
/**
* This method performs a size check.
* It reads the stored size and compares it with the size entered in the
* packet header. This class is the optimal place for such a check as it
* has access to both the header data and the store.
* @return true if size is correct, false if packet is not registered in
* store or size is incorrect.
*/
virtual bool isSizeCorrect() = 0;
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TC_STORE.
*/
static StorageManagerIF* store;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
};
#endif /* TMTCPACKET_PUS_TcPacketStoredBase_H_ */

View File

@ -2,32 +2,31 @@
#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDIF_H_
#include <fsfw/tmtcpacket/RedirectableDataPointerIF.h>
#include "TcPacketPusBase.h"
#include "fsfw/storagemanager/storeAddress.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/storagemanager/storeAddress.h"
class TcPacketStoredIF {
public:
virtual~TcPacketStoredIF() {};
public:
virtual ~TcPacketStoredIF(){};
/**
* With this call, the stored packet can be set to another packet in a store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
virtual void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) = 0;
/**
* With this call, the stored packet can be set to another packet in a store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
virtual void setStoreAddress(store_address_t setAddress, RedirectableDataPointerIF* packet) = 0;
virtual store_address_t getStoreAddress() = 0;
virtual store_address_t getStoreAddress() = 0;
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
virtual ReturnValue_t getData(const uint8_t ** dataPtr, size_t* dataSize) = 0;
/**
* Getter function for the raw data.
* @param dataPtr [out] Pointer to the data pointer to set
* @param dataSize [out] Address of size to set.
* @return -@c RETURN_OK if data was retrieved successfully.
*/
virtual ReturnValue_t getData(const uint8_t** dataPtr, size_t* dataSize) = 0;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDIF_H_ */

View File

@ -1,85 +1,78 @@
#include "fsfw/tmtcpacket/pus/tc/TcPacketStoredPus.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include <cstring>
TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
size_t size, uint8_t ack) :
TcPacketPus(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
(TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
#include "fsfw/serviceinterface/ServiceInterface.h"
TcPacketStoredPus::TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequenceCount, const uint8_t* data, size_t size,
uint8_t ack)
: TcPacketPus(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not this->checkAndSetStore()) {
return;
}
uint8_t* pData = nullptr;
ReturnValue_t returnValue =
this->store->getFreeElement(&this->storeAddress, (TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TcPacketStoredBase: Could not get free element from store!"
<< std::endl;
sif::warning << "TcPacketStoredBase: Could not get free element from store!" << std::endl;
#endif
return;
}
this->setData(pData, TC_PACKET_MIN_SIZE + size);
return;
}
this->setData(pData, TC_PACKET_MIN_SIZE + size);
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION;
pus::PusVersion pusVersion = pus::PusVersion::PUS_C_VERSION;
#else
pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION;
pus::PusVersion pusVersion = pus::PusVersion::PUS_A_VERSION;
#endif
initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion);
std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
initializeTcPacket(apid, sequenceCount, ack, service, subservice, pusVersion);
std::memcpy(&tcData->appData, data, size);
this->setPacketDataLength(size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
this->setErrorControl();
}
TcPacketStoredPus::TcPacketStoredPus(): TcPacketStoredBase(), TcPacketPus(nullptr) {
TcPacketStoredPus::TcPacketStoredPus() : TcPacketStoredBase(), TcPacketPus(nullptr) {}
TcPacketStoredPus::TcPacketStoredPus(store_address_t setAddress) : TcPacketPus(nullptr) {
TcPacketStoredBase::setStoreAddress(setAddress, this);
}
TcPacketStoredPus::TcPacketStoredPus(store_address_t setAddress): TcPacketPus(nullptr) {
TcPacketStoredBase::setStoreAddress(setAddress, this);
}
TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size): TcPacketPus(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr, size);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(const_cast<uint8_t*>(storePtr), size);
TcPacketStoredPus::TcPacketStoredPus(const uint8_t* data, size_t size) : TcPacketPus(data) {
if (this->getFullSize() != size) {
return;
}
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(nullptr, size);
}
const uint8_t* storePtr = nullptr;
// Repoint base data pointer to the data in the store.
store->getData(storeAddress, &storePtr, &size);
this->setData(const_cast<uint8_t*>(storePtr), size);
}
}
ReturnValue_t TcPacketStoredPus::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
// To circumvent size checks
this->setData(nullptr, -1);
return result;
}
TcPacketPusBase* TcPacketStoredPus::getPacketBase() {
return this;
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
// To circumvent size checks
this->setData(nullptr, -1);
return result;
}
TcPacketPusBase* TcPacketStoredPus::getPacketBase() { return this; }
bool TcPacketStoredPus::isSizeCorrect() {
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size);
if (status == StorageManagerIF::RETURN_OK) {
if (this->getFullSize() == temp_size) {
return true;
}
return false;
}
return false;
}

View File

@ -1,53 +1,48 @@
#ifndef FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_
#define FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_
#include "TcPacketStoredBase.h"
#include "TcPacketPus.h"
#include "TcPacketStoredBase.h"
class TcPacketStoredPus:
public TcPacketStoredBase,
public TcPacketPus {
public:
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telecommand Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the destination service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the destination sub-service.
* @param sequence_count Sets the packet's Source Sequence Count field.
* @param data The data to be copied to the Application Data Field.
* @param size The amount of data to be copied.
* @param ack Set's the packet's Ack field, which specifies
* number of verification packets returned
* for this command.
*/
TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
size_t size = 0, uint8_t ack = TcPacketPusBase::ACK_ALL);
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
TcPacketStoredPus(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
TcPacketStoredPus(store_address_t setAddress);
TcPacketStoredPus();
class TcPacketStoredPus : public TcPacketStoredBase, public TcPacketPus {
public:
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telecommand Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the destination service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the destination sub-service.
* @param sequence_count Sets the packet's Source Sequence Count field.
* @param data The data to be copied to the Application Data Field.
* @param size The amount of data to be copied.
* @param ack Set's the packet's Ack field, which specifies
* number of verification packets returned
* for this command.
*/
TcPacketStoredPus(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t sequence_count = 0,
const uint8_t* data = nullptr, size_t size = 0,
uint8_t ack = TcPacketPusBase::ACK_ALL);
/**
* Create stored packet with existing data.
* @param data
* @param size
*/
TcPacketStoredPus(const uint8_t* data, size_t size);
/**
* Create stored packet from existing packet in store
* @param setAddress
*/
TcPacketStoredPus(store_address_t setAddress);
TcPacketStoredPus();
ReturnValue_t deletePacket() override;
TcPacketPusBase* getPacketBase();
ReturnValue_t deletePacket() override;
TcPacketPusBase* getPacketBase();
private:
bool isSizeCorrect() override;
private:
bool isSizeCorrect() override;
};
#endif /* FSFW_TMTCPACKET_PUS_TCPACKETSTOREDPUSA_H_ */

View File

@ -1,67 +1,65 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketBase.h"
#include <cstring>
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
#include <cstring>
TimeStamperIF* TmPacketBase::timeStamper = nullptr;
object_id_t TmPacketBase::timeStamperId = objects::NO_OBJECT;
TmPacketBase::TmPacketBase(uint8_t* setData): SpacePacketBase(setData) {}
TmPacketBase::TmPacketBase(uint8_t* setData) : SpacePacketBase(setData) {}
TmPacketBase::~TmPacketBase() {
//Nothing to do.
// Nothing to do.
}
uint16_t TmPacketBase::getSourceDataSize() {
return getPacketDataLength() - getDataFieldSize() - CRC_SIZE + 1;
return getPacketDataLength() - getDataFieldSize() - CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = getSourceData();
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = getSourceData();
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
void TmPacketBase::setErrorControl() {
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getSourceDataSize();
getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH
getSourceData()[size + 1] = (crc) & 0X00FF; // CRCL
uint32_t full_size = getFullSize();
uint16_t crc = CRC::crc16ccitt(getWholeData(), full_size - CRC_SIZE);
uint32_t size = getSourceDataSize();
getSourceData()[size] = (crc & 0XFF00) >> 8; // CRCH
getSourceData()[size + 1] = (crc)&0X00FF; // CRCL
}
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
size_t tempSize = 0;
return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(),
&tempSize, getTimestampSize());
size_t tempSize = 0;
return CCSDSTime::convertFromCcsds(timestamp, getPacketTimeRaw(), &tempSize, getTimestampSize());
}
bool TmPacketBase::checkAndSetStamper() {
if (timeStamper == NULL) {
timeStamper = ObjectManager::instance()->get<TimeStamperIF>(timeStamperId);
if (timeStamper == NULL) {
timeStamper = ObjectManager::instance()->get<TimeStamperIF>(timeStamperId);
if (timeStamper == NULL) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
sif::warning << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
#else
sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n");
sif::printWarning("TmPacketBase::checkAndSetStamper: Stamper not found!\n");
#endif
return false;
}
return false;
}
return true;
}
return true;
}
void TmPacketBase::print() {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::info << "TmPacketBase::print:" << std::endl;
sif::info << "TmPacketBase::print:" << std::endl;
#else
sif::printInfo("TmPacketBase::print:\n");
sif::printInfo("TmPacketBase::print:\n");
#endif
arrayprinter::print(getWholeData(), getFullSize());
arrayprinter::print(getWholeData(), getFullSize());
}

View File

@ -1,10 +1,10 @@
#ifndef TMTCPACKET_PUS_TMPACKETBASE_H_
#define TMTCPACKET_PUS_TMPACKETBASE_H_
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
namespace Factory {
@ -12,7 +12,6 @@ void setStaticFrameworkObjectIds();
}
/**
* This class is the basic data handler for any ECSS PUS Telemetry packet.
*
@ -25,113 +24,112 @@ void setStaticFrameworkObjectIds();
* @ingroup tmtcpackets
*/
class TmPacketBase : public SpacePacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
friend void(Factory::setStaticFrameworkObjectIds)();
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
public:
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketBase( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketBase();
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketBase(uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TmPacketBase();
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() = 0;
/**
* This is a getter for a pointer to the packet's Source data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's source data.
* @return A pointer to the PUS Source Data.
*/
virtual uint8_t* getSourceData() = 0;
/**
* This method calculates the size of the PUS Source data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Source Data (without Error Control field)
*/
virtual uint16_t getSourceDataSize() = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
virtual uint8_t getService() = 0;
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() = 0;
/**
* This is a getter for a pointer to the packet's Source data.
*
* These are the bytes that follow after the Data Field Header. They form
* the packet's source data.
* @return A pointer to the PUS Source Data.
*/
virtual uint8_t* getSourceData() = 0;
/**
* This method calculates the size of the PUS Source data field.
*
* It takes the information stored in the CCSDS Packet Data Length field
* and subtracts the Data Field Header size and the CRC size.
* @return The size of the PUS Source Data (without Error Control field)
*/
virtual uint16_t getSourceDataSize() = 0;
/**
* Get size of data field which can differ based on implementation
* @return
*/
virtual uint16_t getDataFieldSize() = 0;
/**
* Get size of data field which can differ based on implementation
* @return
*/
virtual uint16_t getDataFieldSize() = 0;
virtual size_t getPacketMinimumSize() const = 0;
virtual size_t getPacketMinimumSize() const = 0;
/**
* Interprets the "time"-field in the secondary header and returns it in
* timeval format.
* @return Converted timestamp of packet.
*/
virtual ReturnValue_t getPacketTime(timeval* timestamp) const;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
virtual uint8_t* getPacketTimeRaw() const = 0;
/**
* Interprets the "time"-field in the secondary header and returns it in
* timeval format.
* @return Converted timestamp of packet.
*/
virtual ReturnValue_t getPacketTime(timeval* timestamp) const;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
virtual uint8_t* getPacketTimeRaw() const = 0;
virtual size_t getTimestampSize() const = 0;
virtual size_t getTimestampSize() const = 0;
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet. This method is not protected because
* a recalculation by the user might be necessary when manipulating fields
* like the sequence count.
*/
void setErrorControl();
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Source Data. If no
* Source Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
uint16_t getErrorControl();
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet. This method is not protected because
* a recalculation by the user might be necessary when manipulating fields
* like the sequence count.
*/
void setErrorControl();
/**
* This getter returns the Error Control Field of the packet.
*
* The field is placed after any possible Source Data. If no
* Source Data is present there's still an Error Control field. It is
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
uint16_t getErrorControl();
protected:
/**
* The timeStamper is responsible for adding a timestamp to the packet.
* It is initialized lazy.
*/
static TimeStamperIF* timeStamper;
//! The ID to use when looking for a time stamper.
static object_id_t timeStamperId;
protected:
/**
* The timeStamper is responsible for adding a timestamp to the packet.
* It is initialized lazy.
*/
static TimeStamperIF* timeStamper;
//! The ID to use when looking for a time stamper.
static object_id_t timeStamperId;
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
};
#endif /* TMTCPACKET_PUS_TMPACKETBASE_H_ */

View File

@ -1,46 +1,40 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketMinimal.h"
#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h"
#include <cstddef>
#include <ctime>
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase( set_data ) {
this->tm_data = (TmPacketMinimalPointer*)set_data;
#include "fsfw/tmtcpacket/pus/PacketTimestampInterpreterIF.h"
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase(set_data) {
this->tm_data = (TmPacketMinimalPointer*)set_data;
}
TmPacketMinimal::~TmPacketMinimal() {
}
TmPacketMinimal::~TmPacketMinimal() {}
uint8_t TmPacketMinimal::getService() {
return tm_data->data_field.service_type;
}
uint8_t TmPacketMinimal::getService() { return tm_data->data_field.service_type; }
uint8_t TmPacketMinimal::getSubService() {
return tm_data->data_field.service_subtype;
}
uint8_t TmPacketMinimal::getSubService() { return tm_data->data_field.service_subtype; }
uint8_t TmPacketMinimal::getPacketSubcounter() {
return tm_data->data_field.subcounter;
}
uint8_t TmPacketMinimal::getPacketSubcounter() { return tm_data->data_field.subcounter; }
ReturnValue_t TmPacketMinimal::getPacketTime(timeval* timestamp) {
if (timestampInterpreter == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return timestampInterpreter->getPacketTime(this, timestamp);
if (timestampInterpreter == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return timestampInterpreter->getPacketTime(this, timestamp);
}
ReturnValue_t TmPacketMinimal::getPacketTimeRaw(const uint8_t** timePtr, uint32_t* size) {
if (timestampInterpreter == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return timestampInterpreter->getPacketTimeRaw(this, timePtr, size);
if (timestampInterpreter == NULL) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return timestampInterpreter->getPacketTimeRaw(this, timePtr, size);
}
void TmPacketMinimal::setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter) {
if (TmPacketMinimal::timestampInterpreter == NULL) {
TmPacketMinimal::timestampInterpreter = interpreter;
}
if (TmPacketMinimal::timestampInterpreter == NULL) {
TmPacketMinimal::timestampInterpreter = interpreter;
}
}
PacketTimestampInterpreterIF* TmPacketMinimal::timestampInterpreter = NULL;

View File

@ -1,9 +1,8 @@
#ifndef FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
#define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
#include "../../SpacePacketBase.h"
#include "../../../returnvalues/HasReturnvaluesIF.h"
#include "../../SpacePacketBase.h"
struct timeval;
class PacketTimestampInterpreterIF;
@ -14,71 +13,70 @@ class PacketTimestampInterpreterIF;
* secondary headers.
*/
class TmPacketMinimal : public SpacePacketBase {
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketMinimal( const uint8_t* set_data );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketMinimal();
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
uint8_t getService();
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
uint8_t getSubService();
/**
* Returns the subcounter.
* @return the subcounter of the Data Field Header.
*/
uint8_t getPacketSubcounter();
struct PUSTmMinimalHeader {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
};
public:
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketMinimal(const uint8_t* set_data);
/**
* This is the empty default destructor.
*/
virtual ~TmPacketMinimal();
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
uint8_t getService();
/**
* This is a getter for the packet's PUS Service Subtype, which is the
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
uint8_t getSubService();
/**
* Returns the subcounter.
* @return the subcounter of the Data Field Header.
*/
uint8_t getPacketSubcounter();
struct PUSTmMinimalHeader {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
};
ReturnValue_t getPacketTime(timeval* timestamp);
ReturnValue_t getPacketTime(timeval* timestamp);
ReturnValue_t getPacketTimeRaw(const uint8_t** timePtr, uint32_t* size);
ReturnValue_t getPacketTimeRaw(const uint8_t** timePtr, uint32_t* size);
static void setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter);
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketMinimalPointer {
CCSDSPrimaryHeader primary;
PUSTmMinimalHeader data_field;
uint8_t rest;
};
//Must include a checksum and is therefore at least one larger than the above struct.
static const uint16_t MINIMUM_SIZE = sizeof(TmPacketMinimalPointer) +1;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketMinimalPointer* tm_data;
static void setInterpretTimestampObject(PacketTimestampInterpreterIF* interpreter);
/**
* This struct defines the data structure of a PUS Telecommand Packet when
* accessed via a pointer.
* @ingroup tmtcpackets
*/
struct TmPacketMinimalPointer {
CCSDSPrimaryHeader primary;
PUSTmMinimalHeader data_field;
uint8_t rest;
};
// Must include a checksum and is therefore at least one larger than the above struct.
static const uint16_t MINIMUM_SIZE = sizeof(TmPacketMinimalPointer) + 1;
static PacketTimestampInterpreterIF* timestampInterpreter;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketMinimalPointer* tm_data;
static PacketTimestampInterpreterIF* timestampInterpreter;
};
#endif /* FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ */

View File

@ -1,87 +1,68 @@
#include "../definitions.h"
#include "TmPacketPusA.h"
#include "TmPacketBase.h"
#include <cstring>
#include "../definitions.h"
#include "TmPacketBase.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
#include <cstring>
TmPacketPusA::TmPacketPusA(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusA*>(setData);
tmData = reinterpret_cast<TmPacketPointerPusA*>(setData);
}
TmPacketPusA::~TmPacketPusA() {
//Nothing to do.
// Nothing to do.
}
uint8_t TmPacketPusA::getService() {
return tmData->data_field.service_type;
}
uint8_t TmPacketPusA::getService() { return tmData->data_field.service_type; }
uint8_t TmPacketPusA::getSubService() {
return tmData->data_field.service_subtype;
}
uint8_t TmPacketPusA::getSubService() { return tmData->data_field.service_subtype; }
uint8_t* TmPacketPusA::getSourceData() {
return &tmData->data;
}
uint8_t* TmPacketPusA::getSourceData() { return &tmData->data; }
uint16_t TmPacketPusA::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->data_field)
- CRC_SIZE + 1;
return getPacketDataLength() - sizeof(tmData->data_field) - CRC_SIZE + 1;
}
ReturnValue_t TmPacketPusA::setData(uint8_t* p_Data, size_t maxSize, void* args) {
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
tmData = reinterpret_cast<TmPacketPointerPusA*>(const_cast<uint8_t*>(p_Data));
return HasReturnvaluesIF::RETURN_OK;
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
tmData = reinterpret_cast<TmPacketPointerPusA*>(const_cast<uint8_t*>(p_Data));
return HasReturnvaluesIF::RETURN_OK;
}
size_t TmPacketPusA::getPacketMinimumSize() const { return TM_PACKET_MIN_SIZE; }
size_t TmPacketPusA::getPacketMinimumSize() const {
return TM_PACKET_MIN_SIZE;
}
uint16_t TmPacketPusA::getDataFieldSize() { return sizeof(PUSTmDataFieldHeaderPusA); }
uint16_t TmPacketPusA::getDataFieldSize() {
return sizeof(PUSTmDataFieldHeaderPusA);
}
uint8_t* TmPacketPusA::getPacketTimeRaw() const { return tmData->data_field.time; }
uint8_t* TmPacketPusA::getPacketTimeRaw() const {
return tmData->data_field.time;
void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter) {
// Set primary header:
initSpacePacketHeader(false, true, apid);
// Set data Field Header:
// First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
}
void TmPacketPusA::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter) {
//Set primary header:
initSpacePacketHeader(false, true, apid);
//Set data Field Header:
//First, set to zero.
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
//Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->data_field.time,
sizeof(tmData->data_field.time));
}
tmData->data_field.version_type_ack = pus::PusVersion::PUS_A_VERSION << 4;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
// Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->data_field.time, sizeof(tmData->data_field.time));
}
}
void TmPacketPusA::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
size_t TmPacketPusA::getTimestampSize() const {
return sizeof(tmData->data_field.time);
}
size_t TmPacketPusA::getTimestampSize() const { return sizeof(tmData->data_field.time); }

View File

@ -2,12 +2,12 @@
#define FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_
#include "TmPacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
namespace Factory{
namespace Factory {
void setStaticFrameworkObjectIds();
}
@ -19,12 +19,12 @@ void setStaticFrameworkObjectIds();
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeaderPusA {
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
// uint8_t destination;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
uint8_t version_type_ack;
uint8_t service_type;
uint8_t service_subtype;
uint8_t subcounter;
// uint8_t destination;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
@ -33,97 +33,97 @@ struct PUSTmDataFieldHeaderPusA {
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusA {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusA data_field;
uint8_t data;
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusA data_field;
uint8_t data;
};
/**
* PUS A packet implementation
* @ingroup tmtcpackets
*/
class TmPacketPusA: public TmPacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeaderPusA) + 2);
//! Maximum size of a TM Packet in this mission.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE;
class TmPacketPusA : public TmPacketBase {
friend void(Factory::setStaticFrameworkObjectIds)();
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusA( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusA();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusA) + 2);
//! Maximum size of a TM Packet in this mission.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE;
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusA(uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusA();
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
size_t getPacketMinimumSize() const override;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusA* tmData;
size_t getPacketMinimumSize() const override;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter);
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusA* tmData;
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize,
void* args = nullptr) override;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter);
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param p_data A pointer to another PUS Telemetry Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override;
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSA_H_ */

View File

@ -1,100 +1,82 @@
#include "../definitions.h"
#include "TmPacketPusC.h"
#include "TmPacketBase.h"
#include <cstring>
#include "../definitions.h"
#include "TmPacketBase.h"
#include "fsfw/globalfunctions/CRC.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include "fsfw/objectmanager/ObjectManagerIF.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/timemanager/CCSDSTime.h"
#include <cstring>
TmPacketPusC::TmPacketPusC(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusC*>(setData);
tmData = reinterpret_cast<TmPacketPointerPusC*>(setData);
}
TmPacketPusC::~TmPacketPusC() {
//Nothing to do.
// Nothing to do.
}
uint8_t TmPacketPusC::getService() {
return tmData->dataField.serviceType;
}
uint8_t TmPacketPusC::getService() { return tmData->dataField.serviceType; }
uint8_t TmPacketPusC::getSubService() {
return tmData->dataField.serviceSubtype;
}
uint8_t TmPacketPusC::getSubService() { return tmData->dataField.serviceSubtype; }
uint8_t* TmPacketPusC::getSourceData() {
return &tmData->data;
}
uint8_t* TmPacketPusC::getSourceData() { return &tmData->data; }
uint16_t TmPacketPusC::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->dataField) - CRC_SIZE + 1;
return getPacketDataLength() - sizeof(tmData->dataField) - CRC_SIZE + 1;
}
ReturnValue_t TmPacketPusC::setData(uint8_t* p_Data, size_t maxSize, void* args) {
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if(maxSize < sizeof(TmPacketPointerPusC)) {
return HasReturnvaluesIF::RETURN_OK;
}
tmData = reinterpret_cast<TmPacketPointerPusC*>(const_cast<uint8_t*>(p_Data));
ReturnValue_t result = SpacePacketBase::setData(p_Data, maxSize);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
if (maxSize < sizeof(TmPacketPointerPusC)) {
return HasReturnvaluesIF::RETURN_OK;
}
tmData = reinterpret_cast<TmPacketPointerPusC*>(const_cast<uint8_t*>(p_Data));
return HasReturnvaluesIF::RETURN_OK;
}
size_t TmPacketPusC::getPacketMinimumSize() const { return TM_PACKET_MIN_SIZE; }
size_t TmPacketPusC::getPacketMinimumSize() const {
return TM_PACKET_MIN_SIZE;
}
uint16_t TmPacketPusC::getDataFieldSize() { return sizeof(PUSTmDataFieldHeaderPusC); }
uint16_t TmPacketPusC::getDataFieldSize() {
return sizeof(PUSTmDataFieldHeaderPusC);
}
uint8_t* TmPacketPusC::getPacketTimeRaw() const { return tmData->dataField.time; }
uint8_t* TmPacketPusC::getPacketTimeRaw() const{
return tmData->dataField.time;
ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) {
// Set primary header:
ReturnValue_t result = initSpacePacketHeader(false, true, apid);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
// Set data Field Header:
// First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
}
ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) {
//Set primary header:
ReturnValue_t result = initSpacePacketHeader(false, true, apid);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
//Set data Field Header:
//First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
/* Only account for last 4 bytes for time reference field */
timeRefField &= 0b1111;
tmData->dataField.versionTimeReferenceField =
(pus::PusVersion::PUS_C_VERSION << 4) | timeRefField;
tmData->dataField.serviceType = service;
tmData->dataField.serviceSubtype = subservice;
tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;
tmData->dataField.subcounterLsb = packetSubcounter & 0xff;
tmData->dataField.destinationIdMsb = destinationId << 8 & 0xff;
tmData->dataField.destinationIdLsb = destinationId & 0xff;
//Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->dataField.time,
sizeof(tmData->dataField.time));
}
return HasReturnvaluesIF::RETURN_OK;
/* Only account for last 4 bytes for time reference field */
timeRefField &= 0b1111;
tmData->dataField.versionTimeReferenceField =
(pus::PusVersion::PUS_C_VERSION << 4) | timeRefField;
tmData->dataField.serviceType = service;
tmData->dataField.serviceSubtype = subservice;
tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;
tmData->dataField.subcounterLsb = packetSubcounter & 0xff;
tmData->dataField.destinationIdMsb = destinationId << 8 & 0xff;
tmData->dataField.destinationIdLsb = destinationId & 0xff;
// Timestamp packet
if (TmPacketBase::checkAndSetStamper()) {
timeStamper->addTimeStamp(tmData->dataField.time, sizeof(tmData->dataField.time));
}
return HasReturnvaluesIF::RETURN_OK;
}
void TmPacketPusC::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
size_t TmPacketPusC::getTimestampSize() const {
return sizeof(tmData->dataField.time);
}
size_t TmPacketPusC::getTimestampSize() const { return sizeof(tmData->dataField.time); }

View File

@ -2,12 +2,12 @@
#define FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_
#include "TmPacketBase.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/TimeStamperIF.h"
#include "fsfw/tmtcpacket/SpacePacketBase.h"
namespace Factory{
namespace Factory {
void setStaticFrameworkObjectIds();
}
@ -19,14 +19,14 @@ void setStaticFrameworkObjectIds();
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeaderPusC {
uint8_t versionTimeReferenceField;
uint8_t serviceType;
uint8_t serviceSubtype;
uint8_t subcounterMsb;
uint8_t subcounterLsb;
uint8_t destinationIdMsb;
uint8_t destinationIdLsb;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
uint8_t versionTimeReferenceField;
uint8_t serviceType;
uint8_t serviceSubtype;
uint8_t subcounterMsb;
uint8_t subcounterLsb;
uint8_t destinationIdMsb;
uint8_t destinationIdLsb;
uint8_t time[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
};
/**
@ -35,91 +35,92 @@ struct PUSTmDataFieldHeaderPusC {
* @ingroup tmtcpackets
*/
struct TmPacketPointerPusC {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusC dataField;
uint8_t data;
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeaderPusC dataField;
uint8_t data;
};
/**
* PUS A packet implementation
* @ingroup tmtcpackets
*/
class TmPacketPusC: public TmPacketBase {
friend void (Factory::setStaticFrameworkObjectIds)();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeaderPusC) + 2);
//! Maximum size of a TM Packet in this mission.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE;
class TmPacketPusC : public TmPacketBase {
friend void(Factory::setStaticFrameworkObjectIds)();
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusC( uint8_t* setData );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusC();
public:
/**
* This constant defines the minimum size of a valid PUS Telemetry Packet.
*/
static const uint32_t TM_PACKET_MIN_SIZE =
(sizeof(CCSDSPrimaryHeader) + sizeof(PUSTmDataFieldHeaderPusC) + 2);
//! Maximum size of a TM Packet in this mission.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = fsfwconfig::FSFW_MAX_TM_PACKET_SIZE;
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
/**
* This is the default constructor.
* It sets its internal data pointer to the address passed and also
* forwards the data pointer to the parent SpacePacketBase class.
* @param set_address The position where the packet data lies.
*/
TmPacketPusC(uint8_t* setData);
/**
* This is the empty default destructor.
*/
virtual ~TmPacketPusC();
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
/* TmPacketBase implementations */
uint8_t getService() override;
uint8_t getSubService() override;
uint8_t* getSourceData() override;
uint16_t getSourceDataSize() override;
uint16_t getDataFieldSize() override;
size_t getPacketMinimumSize() const override;
/**
* Returns a raw pointer to the beginning of the time field.
* @return Raw pointer to time field.
*/
uint8_t* getPacketTimeRaw() const override;
size_t getTimestampSize() const override;
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusC* tmData;
size_t getPacketMinimumSize() const override;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
protected:
/**
* A pointer to a structure which defines the data structure of
* the packet's data.
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointerPusC* tmData;
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param pData A pointer to another PUS Telemetry Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override;
/**
* Initializes the Tm Packet header.
* Does set the timestamp (to now), but not the error control field.
* @param apid APID used.
* @param service PUS Service
* @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used.
*/
ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId = 0,
uint8_t timeRefField = 0);
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* With this method, the packet data pointer can be redirected to another
* location.
*
* This call overwrites the parent's setData method to set both its
* @c tc_data pointer and the parent's @c data pointer.
*
* @param pData A pointer to another PUS Telemetry Packet.
*/
ReturnValue_t setData(uint8_t* pData, size_t maxSize, void* args = nullptr) override;
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ */

View File

@ -9,5 +9,4 @@
#include "TmPacketStoredPusA.h"
#endif
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_H_ */

View File

@ -1,124 +1,121 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredBase.h"
#include <cstring>
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
#include <cstring>
StorageManagerIF *TmPacketStoredBase::store = nullptr;
InternalErrorReporterIF *TmPacketStoredBase::internalErrorReporter = nullptr;
TmPacketStoredBase::TmPacketStoredBase(store_address_t setAddress): storeAddress(setAddress) {
setStoreAddress(storeAddress);
TmPacketStoredBase::TmPacketStoredBase(store_address_t setAddress) : storeAddress(setAddress) {
setStoreAddress(storeAddress);
}
TmPacketStoredBase::TmPacketStoredBase() {
}
TmPacketStoredBase::TmPacketStoredBase() {}
TmPacketStoredBase::~TmPacketStoredBase() {}
TmPacketStoredBase::~TmPacketStoredBase() {
}
store_address_t TmPacketStoredBase::getStoreAddress() {
return storeAddress;
}
store_address_t TmPacketStoredBase::getStoreAddress() { return storeAddress; }
void TmPacketStoredBase::deletePacket() {
store->deleteData(storeAddress);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
setData(nullptr, -1);
store->deleteData(storeAddress);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
setData(nullptr, -1);
}
void TmPacketStoredBase::setStoreAddress(store_address_t setAddress) {
storeAddress = setAddress;
const uint8_t* tempData = nullptr;
size_t tempSize;
if (not checkAndSetStore()) {
return;
}
ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize);
if (status == StorageManagerIF::RETURN_OK) {
setData(const_cast<uint8_t*>(tempData), tempSize);
} else {
setData(nullptr, -1);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
storeAddress = setAddress;
const uint8_t *tempData = nullptr;
size_t tempSize;
if (not checkAndSetStore()) {
return;
}
ReturnValue_t status = store->getData(storeAddress, &tempData, &tempSize);
if (status == StorageManagerIF::RETURN_OK) {
setData(const_cast<uint8_t *>(tempData), tempSize);
} else {
setData(nullptr, -1);
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
bool TmPacketStoredBase::checkAndSetStore() {
if (store == nullptr) {
store = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (store == nullptr) {
store = ObjectManager::instance()->get<StorageManagerIF>(objects::TM_STORE);
if (store == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
<< std::endl;
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!" << std::endl;
#endif
return false;
}
return false;
}
return true;
}
return true;
}
ReturnValue_t TmPacketStoredBase::sendPacket(MessageQueueId_t destination,
MessageQueueId_t sentFrom, bool doErrorReporting) {
if (getAllTmData() == nullptr) {
//SHOULDDO: More decent code.
return HasReturnvaluesIF::RETURN_FAILED;
MessageQueueId_t sentFrom, bool doErrorReporting) {
if (getAllTmData() == nullptr) {
// SHOULDDO: More decent code.
return HasReturnvaluesIF::RETURN_FAILED;
}
TmTcMessage tmMessage(getStoreAddress());
ReturnValue_t result = MessageQueueSenderIF::sendMessage(destination, &tmMessage, sentFrom);
if (result != HasReturnvaluesIF::RETURN_OK) {
deletePacket();
if (doErrorReporting) {
checkAndReportLostTm();
}
TmTcMessage tmMessage(getStoreAddress());
ReturnValue_t result = MessageQueueSenderIF::sendMessage(destination,
&tmMessage, sentFrom);
if (result != HasReturnvaluesIF::RETURN_OK) {
deletePacket();
if (doErrorReporting) {
checkAndReportLostTm();
}
return result;
}
//SHOULDDO: In many cases, some counter is incremented for successfully sent packets. The check is often not done, but just incremented.
return HasReturnvaluesIF::RETURN_OK;
return result;
}
// SHOULDDO: In many cases, some counter is incremented for successfully sent packets. The check
// is often not done, but just incremented.
return HasReturnvaluesIF::RETURN_OK;
}
void TmPacketStoredBase::checkAndReportLostTm() {
if (internalErrorReporter == nullptr) {
internalErrorReporter = ObjectManager::instance()->get<InternalErrorReporterIF>(
objects::INTERNAL_ERROR_REPORTER);
}
if (internalErrorReporter != nullptr) {
internalErrorReporter->lostTm();
}
if (internalErrorReporter == nullptr) {
internalErrorReporter =
ObjectManager::instance()->get<InternalErrorReporterIF>(objects::INTERNAL_ERROR_REPORTER);
}
if (internalErrorReporter != nullptr) {
internalErrorReporter->lostTm();
}
}
void TmPacketStoredBase::handleStoreFailure(const char *const packetType, ReturnValue_t result,
size_t sizeToReserve) {
checkAndReportLostTm();
size_t sizeToReserve) {
checkAndReportLostTm();
#if FSFW_VERBOSE_LEVEL >= 1
switch(result) {
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_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;
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_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;
case (StorageManagerIF::DATA_TOO_LARGE): {
sif::printWarning(
"TmPacketStoredPus%s: Data with size "
"%d too large\n",
packetType, sizeToReserve);
break;
}
#endif
}
}
#endif
}

View File

@ -1,15 +1,14 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_
#include "fsfw/FSFW.h"
#include "TmPacketBase.h"
#include "TmPacketStoredBase.h"
#include "TmPacketPusA.h"
#include "fsfw/serialize/SerializeIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
#include "TmPacketStoredBase.h"
#include "fsfw/FSFW.h"
#include "fsfw/internalerror/InternalErrorReporterIF.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
#include "fsfw/serialize/SerializeIF.h"
#include "fsfw/storagemanager/StorageManagerIF.h"
/**
* This class generates a ECSS PUS Telemetry packet within a given
@ -21,71 +20,68 @@
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredBase: virtual public RedirectableDataPointerIF {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredBase( store_address_t setAddress );
TmPacketStoredBase();
class TmPacketStoredBase : virtual public RedirectableDataPointerIF {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredBase(store_address_t setAddress);
TmPacketStoredBase();
virtual ~TmPacketStoredBase();
virtual ~TmPacketStoredBase();
virtual uint8_t* getAllTmData() = 0;
virtual uint8_t* getAllTmData() = 0;
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
*/
void deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress(store_address_t setAddress);
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is
* @c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
*/
void deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress(store_address_t setAddress);
ReturnValue_t sendPacket(MessageQueueId_t destination, MessageQueueId_t sentFrom,
bool doErrorReporting = true);
ReturnValue_t sendPacket(MessageQueueId_t destination, MessageQueueId_t sentFrom,
bool doErrorReporting = true);
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
protected:
/**
* This is a pointer to the store all instances of the class use.
* If the store is not yet set (i.e. @c store is NULL), every constructor
* call tries to set it and throws an error message in case of failures.
* The default store is objects::TM_STORE.
*/
static StorageManagerIF* store;
static InternalErrorReporterIF *internalErrorReporter;
static InternalErrorReporterIF* internalErrorReporter;
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
/**
* The address where the packet data of the object instance is stored.
*/
store_address_t storeAddress;
/**
* A helper method to check if a store is assigned to the class.
* If not, the method tries to retrieve the store from the global
* ObjectManager.
* @return @li @c true if the store is linked or could be created.
* @li @c false otherwise.
*/
bool checkAndSetStore();
void checkAndReportLostTm();
void checkAndReportLostTm();
void handleStoreFailure(const char* const packetType, ReturnValue_t result,
size_t sizeToReserve);
void handleStoreFailure(const char* const packetType, ReturnValue_t result, size_t sizeToReserve);
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDBASE_H_ */

View File

@ -1,80 +1,73 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusA.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
#include <cstring>
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress)
: TmPacketStoredBase(setAddress), TmPacketPusA(nullptr) {}
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress):
TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter, const uint8_t *data, uint32_t size,
const uint8_t *headerData, uint32_t headerSize)
: TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize):
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header)
: TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != nullptr) {
sourceDataSize += content->getSerializedSize();
}
if (header != nullptr) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) :
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != nullptr) {
sourceDataSize += content->getSerializedSize();
}
if (header != nullptr) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("A", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
uint8_t *TmPacketStoredPusA::getAllTmData() { return getWholeData(); }
uint8_t* TmPacketStoredPusA::getAllTmData() {
return getWholeData();
}
ReturnValue_t TmPacketStoredPusA::setData(uint8_t *newPointer, size_t maxSize, void* args) {
return TmPacketPusA::setData(newPointer, maxSize);
ReturnValue_t TmPacketStoredPusA::setData(uint8_t *newPointer, size_t maxSize, void *args) {
return TmPacketPusA::setData(newPointer, maxSize);
}

View File

@ -1,10 +1,11 @@
#ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_
#include "TmPacketStoredBase.h"
#include "TmPacketPusA.h"
#include <FSFWConfig.h>
#include "TmPacketPusA.h"
#include "TmPacketStoredBase.h"
/**
* This class generates a ECSS PUS A Telemetry packet within a given
* intermediate storage.
@ -15,61 +16,54 @@
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredPusA:
public TmPacketStoredBase,
public TmPacketPusA {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusA( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* 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 sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
*/
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusA( uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t packet_counter, SerializeIF* content,
SerializeIF* header = nullptr);
class TmPacketStoredPusA : public TmPacketStoredBase, public TmPacketPusA {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusA(store_address_t setAddress);
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* 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 sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
*/
TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0,
const uint8_t* data = nullptr, uint32_t size = 0,
const uint8_t* headerData = nullptr, uint32_t headerSize = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusA(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter,
SerializeIF* content, SerializeIF* header = nullptr);
uint8_t* getAllTmData() override;
private:
/**
* Implementation required by base class
* @param newPointer
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override;
uint8_t* getAllTmData() override;
private:
/**
* Implementation required by base class
* @param newPointer
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ */

View File

@ -1,82 +1,76 @@
#include "fsfw/tmtcpacket/pus/tm/TmPacketStoredPusC.h"
#include <cstring>
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "fsfw/tmtcservices/TmTcMessage.h"
#include <cstring>
TmPacketStoredPusC::TmPacketStoredPusC(store_address_t setAddress)
: TmPacketStoredBase(setAddress), TmPacketPusC(nullptr) {}
TmPacketStoredPusC::TmPacketStoredPusC(store_address_t setAddress) :
TmPacketStoredBase(setAddress), TmPacketPusC(nullptr){
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData,
uint32_t headerSize, uint16_t destinationId,
uint8_t timeRefField)
: TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("C", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize, uint16_t destinationId,
uint8_t timeRefField) :
TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + size + headerSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("C", returnValue, sizeToReserve);
return;
}
setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
memcpy(getSourceData(), headerData, headerSize);
memcpy(getSourceData() + headerSize, data, size);
setPacketDataLength(size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, SerializeIF *content,
SerializeIF *header, uint16_t destinationId,
uint8_t timeRefField)
: TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != nullptr) {
sourceDataSize += content->getSerializedSize();
}
if (header != nullptr) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("C", returnValue, sizeToReserve);
return;
}
TmPacketPusC::setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, SerializeIF::Endianness::BIG);
}
setPacketDataLength(sourceDataSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, SerializeIF *content,
SerializeIF *header, uint16_t destinationId, uint8_t timeRefField) :
TmPacketPusC(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != nullptr) {
sourceDataSize += content->getSerializedSize();
}
if (header != nullptr) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *pData = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, sizeToReserve, &pData);
if (returnValue != store->RETURN_OK) {
handleStoreFailure("C", returnValue, sizeToReserve);
return;
}
TmPacketPusC::setData(pData, sizeToReserve);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
uint8_t *TmPacketStoredPusC::getAllTmData() { return getWholeData(); }
uint8_t* TmPacketStoredPusC::getAllTmData() {
return getWholeData();
}
ReturnValue_t TmPacketStoredPusC::setData(uint8_t *newPointer, size_t maxSize,
void* args) {
return TmPacketPusC::setData(newPointer, maxSize);
ReturnValue_t TmPacketStoredPusC::setData(uint8_t *newPointer, size_t maxSize, void *args) {
return TmPacketPusC::setData(newPointer, maxSize);
}

View File

@ -14,65 +14,59 @@
* packets in a store with the help of a storeAddress.
* @ingroup tmtcpackets
*/
class TmPacketStoredPusC:
public TmPacketStoredBase,
public TmPacketPusC {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusC( store_address_t setAddress );
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* 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 sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
* @param destinationId Destination ID containing the application process ID as specified
* by PUS C
* @param timeRefField 4 bit time reference field as specified by PUS C
*/
TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetCounter = 0, const uint8_t* data = nullptr,
uint32_t size = 0, const uint8_t* headerData = nullptr,
uint32_t headerSize = 0, uint16_t destinationId = 0, uint8_t timeRefField = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetCounter, SerializeIF* content,
SerializeIF* header = nullptr, uint16_t destinationId = 0, uint8_t timeRefField = 0);
class TmPacketStoredPusC : public TmPacketStoredBase, public TmPacketPusC {
public:
/**
* This is a default constructor which does not set the data pointer.
* However, it does try to set the packet store.
*/
TmPacketStoredPusC(store_address_t setAddress);
/**
* With this constructor, new space is allocated in the packet store and
* a new PUS Telemetry Packet is created there.
* Packet Application Data passed in data is copied into the packet.
* 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 sources.
* @param apid Sets the packet's APID field.
* @param service Sets the packet's Service ID field.
* This specifies the source service.
* @param subservice Sets the packet's Service Subtype field.
* This specifies the source sub-service.
* @param packet_counter Sets the Packet counter field of this packet
* @param data The payload data to be copied to the
* Application Data Field
* @param size The amount of data to be copied.
* @param headerData The header Data of the Application field,
* will be copied in front of data
* @param headerSize The size of the headerDataF
* @param destinationId Destination ID containing the application process ID as specified
* by PUS C
* @param timeRefField 4 bit time reference field as specified by PUS C
*/
TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter = 0,
const uint8_t* data = nullptr, uint32_t size = 0,
const uint8_t* headerData = nullptr, uint32_t headerSize = 0,
uint16_t destinationId = 0, uint8_t timeRefField = 0);
/**
* Another ctor to directly pass structured content and header data to the
* packet to avoid additional buffers.
*/
TmPacketStoredPusC(uint16_t apid, uint8_t service, uint8_t subservice, uint16_t packetCounter,
SerializeIF* content, SerializeIF* header = nullptr,
uint16_t destinationId = 0, uint8_t timeRefField = 0);
uint8_t* getAllTmData() override;
private:
/**
* Implementation required by base class
* @param newPointer
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override;
uint8_t* getAllTmData() override;
private:
/**
* Implementation required by base class
* @param newPointer
* @param maxSize
* @param args
* @return
*/
ReturnValue_t setData(uint8_t* newPointer, size_t maxSize, void* args = nullptr) override;
};
#endif /* FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ */