renormalized line endings
This commit is contained in:
@ -1,27 +1,27 @@
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../tmtcpacket/ccsds_header.h"
|
||||
#include "../tmtcpacket/SpacePacket.h"
|
||||
#include <string.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) );
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../tmtcpacket/ccsds_header.h"
|
||||
#include "../tmtcpacket/SpacePacket.h"
|
||||
#include <string.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) );
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -1,70 +1,70 @@
|
||||
#ifndef SPACEPACKET_H_
|
||||
#define SPACEPACKET_H_
|
||||
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
|
||||
/**
|
||||
* The SpacePacket class is a representation of a simple CCSDS Space Packet
|
||||
* without (control over) a secondary header.
|
||||
* It can be instantiated with a size smaller than \c PACKET_MAX_SIZE. Its
|
||||
* main use is to serve as an idle packet in case no other packets are sent.
|
||||
* For the ECSS PUS part the TcPacket and TmPacket classes are used.
|
||||
* A pointer to \c local_data is passed to the \c SpacePacketBase parent class,
|
||||
* 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);
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* SPACEPACKET_H_ */
|
||||
#ifndef SPACEPACKET_H_
|
||||
#define SPACEPACKET_H_
|
||||
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
|
||||
/**
|
||||
* The SpacePacket class is a representation of a simple CCSDS Space Packet
|
||||
* without (control over) a secondary header.
|
||||
* It can be instantiated with a size smaller than \c PACKET_MAX_SIZE. Its
|
||||
* main use is to serve as an idle packet in case no other packets are sent.
|
||||
* For the ECSS PUS part the TcPacket and TmPacket classes are used.
|
||||
* A pointer to \c local_data is passed to the \c SpacePacketBase parent class,
|
||||
* 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);
|
||||
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;
|
||||
};
|
||||
|
||||
#endif /* SPACEPACKET_H_ */
|
||||
|
@ -1,104 +1,104 @@
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
#include <string.h>
|
||||
|
||||
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) {
|
||||
this->data = (SpacePacketPointer*) set_address;
|
||||
}
|
||||
|
||||
SpacePacketBase::~SpacePacketBase() {
|
||||
};
|
||||
|
||||
//CCSDS Methods:
|
||||
uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
|
||||
return (this->data->header.packet_id_h & 0b11100000) >> 5;
|
||||
}
|
||||
|
||||
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
||||
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint16_t SpacePacketBase::getPacketId() {
|
||||
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;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
uint16_t SpacePacketBase::getPacketDataLength( void ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint8_t* SpacePacketBase::getWholeData() {
|
||||
return (uint8_t*)this->data;
|
||||
}
|
||||
|
||||
void SpacePacketBase::setData( const uint8_t* p_Data ) {
|
||||
this->data = (SpacePacketPointer*)p_Data;
|
||||
}
|
||||
|
||||
uint32_t SpacePacketBase::getApidAndSequenceCount() const {
|
||||
return (getAPID() << 16) + getPacketSequenceCount();
|
||||
}
|
||||
|
||||
uint8_t* SpacePacketBase::getPacketData() {
|
||||
return &(data->packet_data);
|
||||
}
|
||||
#include "../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../tmtcpacket/SpacePacketBase.h"
|
||||
#include <string.h>
|
||||
|
||||
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) {
|
||||
this->data = (SpacePacketPointer*) set_address;
|
||||
}
|
||||
|
||||
SpacePacketBase::~SpacePacketBase() {
|
||||
};
|
||||
|
||||
//CCSDS Methods:
|
||||
uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
|
||||
return (this->data->header.packet_id_h & 0b11100000) >> 5;
|
||||
}
|
||||
|
||||
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
|
||||
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint16_t SpacePacketBase::getPacketId() {
|
||||
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;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
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 ;
|
||||
}
|
||||
|
||||
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 );
|
||||
}
|
||||
|
||||
uint16_t SpacePacketBase::getPacketDataLength( void ) {
|
||||
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 );
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
uint8_t* SpacePacketBase::getWholeData() {
|
||||
return (uint8_t*)this->data;
|
||||
}
|
||||
|
||||
void SpacePacketBase::setData( const uint8_t* p_Data ) {
|
||||
this->data = (SpacePacketPointer*)p_Data;
|
||||
}
|
||||
|
||||
uint32_t SpacePacketBase::getApidAndSequenceCount() const {
|
||||
return (getAPID() << 16) + getPacketSequenceCount();
|
||||
}
|
||||
|
||||
uint8_t* SpacePacketBase::getPacketData() {
|
||||
return &(data->packet_data);
|
||||
}
|
||||
|
@ -1,177 +1,177 @@
|
||||
#ifndef SPACEPACKETBASE_H_
|
||||
#define SPACEPACKETBASE_H_
|
||||
|
||||
#include "../tmtcpacket/ccsds_header.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @defgroup tmtcpackets Space Packets
|
||||
* This is the group, where all classes associated with Telecommand and
|
||||
* Telemetry packets belong to.
|
||||
* The class hierarchy resembles the dependency between the different standards
|
||||
* applied, namely the CCSDS Space Packet standard and the ECCSS Packet
|
||||
* Utilization Standard. Most field and structure names are taken from these
|
||||
* standards.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a Space Packet when accessed
|
||||
* via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct SpacePacketPointer {
|
||||
CCSDSPrimaryHeader header;
|
||||
uint8_t packet_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any CCSDS Space Packet
|
||||
* compatible Telecommand and Telemetry packet.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* Remark: All bit numbers in this documentation are counted from
|
||||
* the most significant bit (from left).
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class SpacePacketBase {
|
||||
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();
|
||||
|
||||
//CCSDS Methods:
|
||||
/**
|
||||
* Getter for the packet version number field.
|
||||
* @return Returns the highest three bit of the packet in one byte.
|
||||
*/
|
||||
uint8_t getPacketVersionNumber( void );
|
||||
/**
|
||||
* This method checks the type field in the header.
|
||||
* This bit specifies, if the command is interpreted as Telecommand of
|
||||
* as Telemetry. For a Telecommand, the bit is set.
|
||||
* @return Returns true if the bit is set and false if not.
|
||||
*/
|
||||
bool isTelecommand( void );
|
||||
|
||||
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount = 0);
|
||||
/**
|
||||
* 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 getPacketDataLength( void ); //uint16_t is sufficient, because this is limit in CCSDS standard
|
||||
/**
|
||||
* Sets the packet data length, which is the fifth and sixth byte of the
|
||||
* CCSDS Primary Header.
|
||||
* @param setLength The value of the length to set. It must fit the true
|
||||
* CCSDS packet data length . The packet data length is
|
||||
* the size of every kind of data \b after the CCSDS
|
||||
* Primary Header \b -1.
|
||||
*/
|
||||
void setPacketDataLength( uint16_t setLength );
|
||||
|
||||
//Helper methods:
|
||||
/**
|
||||
* This method returns a raw uint8_t pointer to the packet.
|
||||
* @return A \c uint8_t pointer to the first byte of the CCSDS primary header.
|
||||
*/
|
||||
virtual uint8_t* getWholeData( void );
|
||||
|
||||
uint8_t* getPacketData();
|
||||
/**
|
||||
* With this method, the packet data pointer can be redirected to another
|
||||
* location.
|
||||
* @param p_Data A pointer to another raw Space Packet.
|
||||
*/
|
||||
virtual void setData( const uint8_t* p_Data );
|
||||
/**
|
||||
* This method returns the full raw packet size.
|
||||
* @return The full size of the packet in bytes.
|
||||
*/
|
||||
size_t getFullSize();
|
||||
|
||||
uint32_t getApidAndSequenceCount() const;
|
||||
|
||||
};
|
||||
|
||||
#endif /* SPACEPACKETBASE_H_ */
|
||||
#ifndef SPACEPACKETBASE_H_
|
||||
#define SPACEPACKETBASE_H_
|
||||
|
||||
#include "../tmtcpacket/ccsds_header.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* @defgroup tmtcpackets Space Packets
|
||||
* This is the group, where all classes associated with Telecommand and
|
||||
* Telemetry packets belong to.
|
||||
* The class hierarchy resembles the dependency between the different standards
|
||||
* applied, namely the CCSDS Space Packet standard and the ECCSS Packet
|
||||
* Utilization Standard. Most field and structure names are taken from these
|
||||
* standards.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a Space Packet when accessed
|
||||
* via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct SpacePacketPointer {
|
||||
CCSDSPrimaryHeader header;
|
||||
uint8_t packet_data;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any CCSDS Space Packet
|
||||
* compatible Telecommand and Telemetry packet.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* Remark: All bit numbers in this documentation are counted from
|
||||
* the most significant bit (from left).
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class SpacePacketBase {
|
||||
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();
|
||||
|
||||
//CCSDS Methods:
|
||||
/**
|
||||
* Getter for the packet version number field.
|
||||
* @return Returns the highest three bit of the packet in one byte.
|
||||
*/
|
||||
uint8_t getPacketVersionNumber( void );
|
||||
/**
|
||||
* This method checks the type field in the header.
|
||||
* This bit specifies, if the command is interpreted as Telecommand of
|
||||
* as Telemetry. For a Telecommand, the bit is set.
|
||||
* @return Returns true if the bit is set and false if not.
|
||||
*/
|
||||
bool isTelecommand( void );
|
||||
|
||||
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount = 0);
|
||||
/**
|
||||
* 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 getPacketDataLength( void ); //uint16_t is sufficient, because this is limit in CCSDS standard
|
||||
/**
|
||||
* Sets the packet data length, which is the fifth and sixth byte of the
|
||||
* CCSDS Primary Header.
|
||||
* @param setLength The value of the length to set. It must fit the true
|
||||
* CCSDS packet data length . The packet data length is
|
||||
* the size of every kind of data \b after the CCSDS
|
||||
* Primary Header \b -1.
|
||||
*/
|
||||
void setPacketDataLength( uint16_t setLength );
|
||||
|
||||
//Helper methods:
|
||||
/**
|
||||
* This method returns a raw uint8_t pointer to the packet.
|
||||
* @return A \c uint8_t pointer to the first byte of the CCSDS primary header.
|
||||
*/
|
||||
virtual uint8_t* getWholeData( void );
|
||||
|
||||
uint8_t* getPacketData();
|
||||
/**
|
||||
* With this method, the packet data pointer can be redirected to another
|
||||
* location.
|
||||
* @param p_Data A pointer to another raw Space Packet.
|
||||
*/
|
||||
virtual void setData( const uint8_t* p_Data );
|
||||
/**
|
||||
* This method returns the full raw packet size.
|
||||
* @return The full size of the packet in bytes.
|
||||
*/
|
||||
size_t getFullSize();
|
||||
|
||||
uint32_t getApidAndSequenceCount() const;
|
||||
|
||||
};
|
||||
|
||||
#endif /* SPACEPACKETBASE_H_ */
|
||||
|
@ -1,40 +1,40 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_APIDMATCHER_H_ */
|
||||
|
@ -1,195 +1,195 @@
|
||||
#include "../../tmtcpacket/packetmatcher/ApidMatcher.h"
|
||||
#include "../../tmtcpacket/packetmatcher/PacketMatchTree.h"
|
||||
#include "../../tmtcpacket/packetmatcher/ServiceMatcher.h"
|
||||
#include "../../tmtcpacket/packetmatcher/SubserviceMatcher.h"
|
||||
|
||||
PacketMatchTree::PacketMatchTree(Node* root) :
|
||||
MatchTree<TmPacketMinimal*>(root, 2), factoryBackend(0, POOL_SIZES,
|
||||
N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree(iterator root) :
|
||||
MatchTree<TmPacketMinimal*>(root.element, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree() :
|
||||
MatchTree<TmPacketMinimal*>((Node*) NULL, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
const uint16_t PacketMatchTree::POOL_SIZES[N_POOLS] = { sizeof(ServiceMatcher),
|
||||
sizeof(SubServiceMatcher), sizeof(ApidMatcher),
|
||||
sizeof(PacketMatchTree::Node) };
|
||||
//Maximum number of types and subtypes to filter should be more than sufficient.
|
||||
const uint16_t PacketMatchTree::N_ELEMENTS[N_POOLS] = { 10, 20, 2, 40 };
|
||||
|
||||
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);
|
||||
}
|
||||
#include "../../tmtcpacket/packetmatcher/ApidMatcher.h"
|
||||
#include "../../tmtcpacket/packetmatcher/PacketMatchTree.h"
|
||||
#include "../../tmtcpacket/packetmatcher/ServiceMatcher.h"
|
||||
#include "../../tmtcpacket/packetmatcher/SubserviceMatcher.h"
|
||||
|
||||
PacketMatchTree::PacketMatchTree(Node* root) :
|
||||
MatchTree<TmPacketMinimal*>(root, 2), factoryBackend(0, POOL_SIZES,
|
||||
N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree(iterator root) :
|
||||
MatchTree<TmPacketMinimal*>(root.element, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
PacketMatchTree::PacketMatchTree() :
|
||||
MatchTree<TmPacketMinimal*>((Node*) NULL, 2), factoryBackend(0,
|
||||
POOL_SIZES, N_ELEMENTS, false, true), factory(&factoryBackend) {
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
return RETURN_OK;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
const uint16_t PacketMatchTree::POOL_SIZES[N_POOLS] = { sizeof(ServiceMatcher),
|
||||
sizeof(SubServiceMatcher), sizeof(ApidMatcher),
|
||||
sizeof(PacketMatchTree::Node) };
|
||||
//Maximum number of types and subtypes to filter should be more than sufficient.
|
||||
const uint16_t PacketMatchTree::N_ELEMENTS[N_POOLS] = { 10, 20, 2, 40 };
|
||||
|
||||
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);
|
||||
}
|
||||
|
@ -1,36 +1,36 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
|
||||
#include "../../container/PlacementFactory.h"
|
||||
#include "../../globalfunctions/matching/MatchTree.h"
|
||||
#include "../../storagemanager/LocalPool.h"
|
||||
#include "../../tmtcpacket/pus/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<N_POOLS> factoryBackend;
|
||||
PlacementFactory factory;
|
||||
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_ */
|
||||
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_PACKETMATCHTREE_H_
|
||||
|
||||
#include "../../container/PlacementFactory.h"
|
||||
#include "../../globalfunctions/matching/MatchTree.h"
|
||||
#include "../../storagemanager/LocalPool.h"
|
||||
#include "../../tmtcpacket/pus/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<N_POOLS> factoryBackend;
|
||||
PlacementFactory factory;
|
||||
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_ */
|
||||
|
||||
|
@ -1,39 +1,39 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_ */
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/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);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PACKETMATCHER_SERVICEMATCHER_H_ */
|
||||
|
@ -1,40 +1,40 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketMinimal.h"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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_ */
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PACKETMATCHER_SUBSERVICEMATCHER_H_
|
||||
|
||||
#include "../../globalfunctions/matching/SerializeableMatcherIF.h"
|
||||
#include "../../serialize/SerializeAdapter.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketMinimal.h"
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
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_ */
|
||||
|
@ -1,16 +1,16 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ */
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_
|
||||
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PUS_PACKETTIMESTAMPINTERPRETERIF_H_ */
|
||||
|
@ -1,93 +1,93 @@
|
||||
#include "../../globalfunctions/CRC.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketBase.h"
|
||||
#include <string.h>
|
||||
|
||||
TcPacketBase::TcPacketBase(const uint8_t* set_data) :
|
||||
SpacePacketBase(set_data) {
|
||||
tcData = (TcPacketPointer*) set_data;
|
||||
}
|
||||
|
||||
TcPacketBase::~TcPacketBase() {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getService() {
|
||||
return tcData->dataField.service_type;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getSubService() {
|
||||
return tcData->dataField.service_subtype;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getAcknowledgeFlags() {
|
||||
return tcData->dataField.version_type_ack & 0b00001111;
|
||||
}
|
||||
|
||||
const uint8_t* TcPacketBase::getApplicationData() const {
|
||||
return &tcData->appData;
|
||||
}
|
||||
|
||||
uint16_t TcPacketBase::getApplicationDataSize() {
|
||||
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint16_t TcPacketBase::getErrorControl() {
|
||||
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 TcPacketBase::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
|
||||
}
|
||||
|
||||
void TcPacketBase::setData(const uint8_t* pData) {
|
||||
SpacePacketBase::setData(pData);
|
||||
tcData = (TcPacketPointer*) pData;
|
||||
}
|
||||
|
||||
void TcPacketBase::setAppData(uint8_t * appData, uint16_t dataLen) {
|
||||
memcpy(&tcData->appData, appData, dataLen);
|
||||
SpacePacketBase::setPacketDataLength(dataLen +
|
||||
sizeof(PUSTcDataFieldHeader) + TcPacketBase::CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
|
||||
return (tcData->dataField.version_type_ack & 0b10000000) >> 7;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getPusVersionNumber() {
|
||||
return (tcData->dataField.version_type_ack & 0b01110000) >> 4;
|
||||
}
|
||||
|
||||
void TcPacketBase::print() {
|
||||
uint8_t * wholeData = getWholeData();
|
||||
sif::debug << "TcPacket contains: " << std::endl;
|
||||
for (uint8_t count = 0; count < getFullSize(); ++count) {
|
||||
sif::debug << std::hex << (uint16_t) wholeData[count] << " ";
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
}
|
||||
|
||||
void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
|
||||
uint8_t ack, uint8_t service, uint8_t subservice) {
|
||||
initSpacePacketHeader(true, true, apid, sequenceCount);
|
||||
memset(&tcData->dataField, 0, sizeof(tcData->dataField));
|
||||
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
||||
//Data Field Header:
|
||||
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
|
||||
tcData->dataField.version_type_ack = 0b00010000;
|
||||
tcData->dataField.version_type_ack |= (ack & 0x0F);
|
||||
tcData->dataField.service_type = service;
|
||||
tcData->dataField.service_subtype = subservice;
|
||||
}
|
||||
|
||||
size_t TcPacketBase::calculateFullPacketLength(size_t appDataLen) {
|
||||
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
|
||||
appDataLen + TcPacketBase::CRC_SIZE;
|
||||
}
|
||||
#include "../../globalfunctions/CRC.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketBase.h"
|
||||
#include <string.h>
|
||||
|
||||
TcPacketBase::TcPacketBase(const uint8_t* set_data) :
|
||||
SpacePacketBase(set_data) {
|
||||
tcData = (TcPacketPointer*) set_data;
|
||||
}
|
||||
|
||||
TcPacketBase::~TcPacketBase() {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getService() {
|
||||
return tcData->dataField.service_type;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getSubService() {
|
||||
return tcData->dataField.service_subtype;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getAcknowledgeFlags() {
|
||||
return tcData->dataField.version_type_ack & 0b00001111;
|
||||
}
|
||||
|
||||
const uint8_t* TcPacketBase::getApplicationData() const {
|
||||
return &tcData->appData;
|
||||
}
|
||||
|
||||
uint16_t TcPacketBase::getApplicationDataSize() {
|
||||
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint16_t TcPacketBase::getErrorControl() {
|
||||
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 TcPacketBase::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
|
||||
}
|
||||
|
||||
void TcPacketBase::setData(const uint8_t* pData) {
|
||||
SpacePacketBase::setData(pData);
|
||||
tcData = (TcPacketPointer*) pData;
|
||||
}
|
||||
|
||||
void TcPacketBase::setAppData(uint8_t * appData, uint16_t dataLen) {
|
||||
memcpy(&tcData->appData, appData, dataLen);
|
||||
SpacePacketBase::setPacketDataLength(dataLen +
|
||||
sizeof(PUSTcDataFieldHeader) + TcPacketBase::CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
|
||||
return (tcData->dataField.version_type_ack & 0b10000000) >> 7;
|
||||
}
|
||||
|
||||
uint8_t TcPacketBase::getPusVersionNumber() {
|
||||
return (tcData->dataField.version_type_ack & 0b01110000) >> 4;
|
||||
}
|
||||
|
||||
void TcPacketBase::print() {
|
||||
uint8_t * wholeData = getWholeData();
|
||||
sif::debug << "TcPacket contains: " << std::endl;
|
||||
for (uint8_t count = 0; count < getFullSize(); ++count) {
|
||||
sif::debug << std::hex << (uint16_t) wholeData[count] << " ";
|
||||
}
|
||||
sif::debug << std::dec << std::endl;
|
||||
}
|
||||
|
||||
void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
|
||||
uint8_t ack, uint8_t service, uint8_t subservice) {
|
||||
initSpacePacketHeader(true, true, apid, sequenceCount);
|
||||
memset(&tcData->dataField, 0, sizeof(tcData->dataField));
|
||||
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
||||
//Data Field Header:
|
||||
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
|
||||
tcData->dataField.version_type_ack = 0b00010000;
|
||||
tcData->dataField.version_type_ack |= (ack & 0x0F);
|
||||
tcData->dataField.service_type = service;
|
||||
tcData->dataField.service_subtype = subservice;
|
||||
}
|
||||
|
||||
size_t TcPacketBase::calculateFullPacketLength(size_t appDataLen) {
|
||||
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
|
||||
appDataLen + TcPacketBase::CRC_SIZE;
|
||||
}
|
||||
|
@ -1,204 +1,204 @@
|
||||
#ifndef TCPACKETBASE_H_
|
||||
#define TCPACKETBASE_H_
|
||||
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* This struct defines a byte-wise structured PUS TC Data Field Header.
|
||||
* Any optional fields in the header must be added or removed here.
|
||||
* Currently, the Source Id field is present with one byte.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct PUSTcDataFieldHeader {
|
||||
uint8_t version_type_ack;
|
||||
uint8_t service_type;
|
||||
uint8_t service_subtype;
|
||||
uint8_t source_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a PUS Telecommand Packet when
|
||||
* accessed via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct TcPacketPointer {
|
||||
CCSDSPrimaryHeader primary;
|
||||
PUSTcDataFieldHeader dataField;
|
||||
uint8_t appData;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any ECSS PUS Telecommand packet.
|
||||
*
|
||||
* In addition to \SpacePacketBase, the class provides methods to handle
|
||||
* the standardized entries of the PUS TC Packet Data Field Header.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TcPacketBase : public SpacePacketBase {
|
||||
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.
|
||||
*/
|
||||
TcPacketPointer* tcData;
|
||||
public:
|
||||
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2);
|
||||
/**
|
||||
* With this constant for the acknowledge field responses on all levels are expected.
|
||||
*/
|
||||
static const uint8_t ACK_ALL = 0b1111;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on acceptance is expected.
|
||||
*/
|
||||
static const uint8_t ACK_ACCEPTANCE = 0b0001;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on start of execution is expected.
|
||||
*/
|
||||
static const uint8_t ACK_START = 0b0010;
|
||||
/**
|
||||
* With this constant for the acknowledge field responses on execution steps are expected.
|
||||
*/
|
||||
static const uint8_t ACK_STEP = 0b0100;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on completion is expected.
|
||||
*/
|
||||
static const uint8_t ACK_COMPLETION = 0b1000;
|
||||
/**
|
||||
* With this constant for the acknowledge field no responses are expected.
|
||||
*/
|
||||
static const uint8_t ACK_NONE = 0b000;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
TcPacketBase( const uint8_t* set_data );
|
||||
/**
|
||||
* This is the empty default destructor.
|
||||
*/
|
||||
virtual ~TcPacketBase();
|
||||
/**
|
||||
* Initializes the Tc Packet header.
|
||||
* @param apid APID used.
|
||||
* @param service PUS Service
|
||||
* @param subservice PUS Subservice
|
||||
* @param packetSubcounter Additional subcounter used.
|
||||
*/
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint8_t getSecondaryHeaderFlag();
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint8_t getPusVersionNumber();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
uint8_t getAcknowledgeFlags();
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const uint8_t* getApplicationData() const;
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
uint16_t getApplicationDataSize();
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint16_t getErrorControl();
|
||||
/**
|
||||
* With this method, the Error Control Field is updated to match the
|
||||
* current content of the packet.
|
||||
*/
|
||||
void setErrorControl();
|
||||
|
||||
/**
|
||||
* Copies the supplied data to the internal TC application data field.
|
||||
* @param pData
|
||||
* @param dataLen
|
||||
*/
|
||||
void setAppData(uint8_t * appData, uint16_t dataLen);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setData( const uint8_t* pData );
|
||||
|
||||
/**
|
||||
* This is a debugging helper method that prints the whole packet content
|
||||
* to the screen.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Calculate full packet length from application data length.
|
||||
* @param appDataLen
|
||||
* @return
|
||||
*/
|
||||
static size_t calculateFullPacketLength(size_t appDataLen);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCPACKETBASE_H_ */
|
||||
#ifndef TCPACKETBASE_H_
|
||||
#define TCPACKETBASE_H_
|
||||
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include <cstddef>
|
||||
|
||||
/**
|
||||
* This struct defines a byte-wise structured PUS TC Data Field Header.
|
||||
* Any optional fields in the header must be added or removed here.
|
||||
* Currently, the Source Id field is present with one byte.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct PUSTcDataFieldHeader {
|
||||
uint8_t version_type_ack;
|
||||
uint8_t service_type;
|
||||
uint8_t service_subtype;
|
||||
uint8_t source_id;
|
||||
};
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a PUS Telecommand Packet when
|
||||
* accessed via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct TcPacketPointer {
|
||||
CCSDSPrimaryHeader primary;
|
||||
PUSTcDataFieldHeader dataField;
|
||||
uint8_t appData;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any ECSS PUS Telecommand packet.
|
||||
*
|
||||
* In addition to \SpacePacketBase, the class provides methods to handle
|
||||
* the standardized entries of the PUS TC Packet Data Field Header.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TcPacketBase : public SpacePacketBase {
|
||||
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.
|
||||
*/
|
||||
TcPacketPointer* tcData;
|
||||
public:
|
||||
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2);
|
||||
/**
|
||||
* With this constant for the acknowledge field responses on all levels are expected.
|
||||
*/
|
||||
static const uint8_t ACK_ALL = 0b1111;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on acceptance is expected.
|
||||
*/
|
||||
static const uint8_t ACK_ACCEPTANCE = 0b0001;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on start of execution is expected.
|
||||
*/
|
||||
static const uint8_t ACK_START = 0b0010;
|
||||
/**
|
||||
* With this constant for the acknowledge field responses on execution steps are expected.
|
||||
*/
|
||||
static const uint8_t ACK_STEP = 0b0100;
|
||||
/**
|
||||
* With this constant for the acknowledge field a response on completion is expected.
|
||||
*/
|
||||
static const uint8_t ACK_COMPLETION = 0b1000;
|
||||
/**
|
||||
* With this constant for the acknowledge field no responses are expected.
|
||||
*/
|
||||
static const uint8_t ACK_NONE = 0b000;
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
TcPacketBase( const uint8_t* set_data );
|
||||
/**
|
||||
* This is the empty default destructor.
|
||||
*/
|
||||
virtual ~TcPacketBase();
|
||||
/**
|
||||
* Initializes the Tc Packet header.
|
||||
* @param apid APID used.
|
||||
* @param service PUS Service
|
||||
* @param subservice PUS Subservice
|
||||
* @param packetSubcounter Additional subcounter used.
|
||||
*/
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint8_t getSecondaryHeaderFlag();
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint8_t getPusVersionNumber();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
uint8_t getAcknowledgeFlags();
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
const uint8_t* getApplicationData() const;
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
uint16_t getApplicationDataSize();
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
uint16_t getErrorControl();
|
||||
/**
|
||||
* With this method, the Error Control Field is updated to match the
|
||||
* current content of the packet.
|
||||
*/
|
||||
void setErrorControl();
|
||||
|
||||
/**
|
||||
* Copies the supplied data to the internal TC application data field.
|
||||
* @param pData
|
||||
* @param dataLen
|
||||
*/
|
||||
void setAppData(uint8_t * appData, uint16_t dataLen);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setData( const uint8_t* pData );
|
||||
|
||||
/**
|
||||
* This is a debugging helper method that prints the whole packet content
|
||||
* to the screen.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Calculate full packet length from application data length.
|
||||
* @param appDataLen
|
||||
* @return
|
||||
*/
|
||||
static size_t calculateFullPacketLength(size_t appDataLen);
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCPACKETBASE_H_ */
|
||||
|
@ -1,118 +1,118 @@
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketStored.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
TcPacketStored::TcPacketStored(store_address_t setAddress) :
|
||||
TcPacketBase(nullptr), storeAddress(setAddress) {
|
||||
this->setStoreAddress(this->storeAddress);
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored(uint8_t service, uint8_t subservice,
|
||||
uint16_t apid, uint8_t sequence_count, const uint8_t* data,
|
||||
size_t size, uint8_t ack ) :
|
||||
TcPacketBase(nullptr) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!this->checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
uint8_t* p_data = nullptr;
|
||||
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
|
||||
(TC_PACKET_MIN_SIZE + size), &p_data);
|
||||
if (returnValue != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "TcPacketStored::TcPacketStored: Could not get "
|
||||
"free element from store!" << std::endl;
|
||||
return;
|
||||
}
|
||||
this->setData(p_data);
|
||||
initializeTcPacket(apid, sequence_count, ack, service, subservice);
|
||||
memcpy(&tcData->appData, data, size);
|
||||
this->setPacketDataLength(
|
||||
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
||||
this->setErrorControl();
|
||||
}
|
||||
|
||||
ReturnValue_t TcPacketStored::getData(const uint8_t ** dataPtr,
|
||||
size_t* dataSize) {
|
||||
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "TcPacketStored: Could not get data!" << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored() :
|
||||
TcPacketBase(NULL) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->checkAndSetStore();
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t TcPacketStored::deletePacket() {
|
||||
ReturnValue_t result = this->store->deleteData(this->storeAddress);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->setData( NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TcPacketStored::checkAndSetStore() {
|
||||
if (this->store == nullptr) {
|
||||
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (this->store == nullptr) {
|
||||
sif::error << "TcPacketStored::TcPacketStored: TC Store not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
this->storeAddress = setAddress;
|
||||
const uint8_t* temp_data = NULL;
|
||||
size_t temp_size;
|
||||
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
||||
if (this->checkAndSetStore()) {
|
||||
status = this->store->getData(this->storeAddress, &temp_data,
|
||||
&temp_size);
|
||||
}
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
this->setData(temp_data);
|
||||
} else {
|
||||
this->setData(NULL);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
store_address_t TcPacketStored::getStoreAddress() {
|
||||
return this->storeAddress;
|
||||
}
|
||||
|
||||
bool TcPacketStored::isSizeCorrect() {
|
||||
const uint8_t* temp_data = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
StorageManagerIF* TcPacketStored::store = NULL;
|
||||
|
||||
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
|
||||
TcPacketBase(data) {
|
||||
if (getFullSize() != size) {
|
||||
return;
|
||||
}
|
||||
if (this->checkAndSetStore()) {
|
||||
ReturnValue_t status = store->addData(&storeAddress, data, size);
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
this->setData(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketStored.h"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
TcPacketStored::TcPacketStored(store_address_t setAddress) :
|
||||
TcPacketBase(nullptr), storeAddress(setAddress) {
|
||||
this->setStoreAddress(this->storeAddress);
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored(uint8_t service, uint8_t subservice,
|
||||
uint16_t apid, uint8_t sequence_count, const uint8_t* data,
|
||||
size_t size, uint8_t ack ) :
|
||||
TcPacketBase(nullptr) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!this->checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
uint8_t* p_data = nullptr;
|
||||
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
|
||||
(TC_PACKET_MIN_SIZE + size), &p_data);
|
||||
if (returnValue != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "TcPacketStored::TcPacketStored: Could not get "
|
||||
"free element from store!" << std::endl;
|
||||
return;
|
||||
}
|
||||
this->setData(p_data);
|
||||
initializeTcPacket(apid, sequence_count, ack, service, subservice);
|
||||
memcpy(&tcData->appData, data, size);
|
||||
this->setPacketDataLength(
|
||||
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
|
||||
this->setErrorControl();
|
||||
}
|
||||
|
||||
ReturnValue_t TcPacketStored::getData(const uint8_t ** dataPtr,
|
||||
size_t* dataSize) {
|
||||
auto result = this->store->getData(storeAddress, dataPtr, dataSize);
|
||||
if(result != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::warning << "TcPacketStored: Could not get data!" << std::endl;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
TcPacketStored::TcPacketStored() :
|
||||
TcPacketBase(NULL) {
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->checkAndSetStore();
|
||||
|
||||
}
|
||||
|
||||
ReturnValue_t TcPacketStored::deletePacket() {
|
||||
ReturnValue_t result = this->store->deleteData(this->storeAddress);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
this->setData( NULL);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool TcPacketStored::checkAndSetStore() {
|
||||
if (this->store == nullptr) {
|
||||
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
|
||||
if (this->store == nullptr) {
|
||||
sif::error << "TcPacketStored::TcPacketStored: TC Store not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
this->storeAddress = setAddress;
|
||||
const uint8_t* temp_data = NULL;
|
||||
size_t temp_size;
|
||||
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
|
||||
if (this->checkAndSetStore()) {
|
||||
status = this->store->getData(this->storeAddress, &temp_data,
|
||||
&temp_size);
|
||||
}
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
this->setData(temp_data);
|
||||
} else {
|
||||
this->setData(NULL);
|
||||
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
store_address_t TcPacketStored::getStoreAddress() {
|
||||
return this->storeAddress;
|
||||
}
|
||||
|
||||
bool TcPacketStored::isSizeCorrect() {
|
||||
const uint8_t* temp_data = NULL;
|
||||
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;
|
||||
}
|
||||
|
||||
StorageManagerIF* TcPacketStored::store = NULL;
|
||||
|
||||
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
|
||||
TcPacketBase(data) {
|
||||
if (getFullSize() != size) {
|
||||
return;
|
||||
}
|
||||
if (this->checkAndSetStore()) {
|
||||
ReturnValue_t status = store->addData(&storeAddress, data, size);
|
||||
if (status != HasReturnvaluesIF::RETURN_OK) {
|
||||
this->setData(NULL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,110 +1,110 @@
|
||||
#ifndef TCPACKETSTORED_H_
|
||||
#define TCPACKETSTORED_H_
|
||||
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketBase.h"
|
||||
|
||||
/**
|
||||
* This class generates a ECSS PUS Telecommand packet within a given
|
||||
* intermediate storage.
|
||||
* As most packets are passed between tasks with the help of a storage
|
||||
* anyway, it seems logical to create a Packet-In-Storage access class
|
||||
* which saves the user almost all storage handling operation.
|
||||
* Packets can both be newly created with the class and be "linked" to
|
||||
* packets in a store with the help of a storeAddress.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TcPacketStored : public TcPacketBase {
|
||||
private:
|
||||
/**
|
||||
* 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();
|
||||
public:
|
||||
/**
|
||||
* This is a default constructor which does not set the data pointer.
|
||||
* However, it does try to set the packet store.
|
||||
*/
|
||||
TcPacketStored();
|
||||
/**
|
||||
* With this constructor, the class instance is linked to an existing
|
||||
* packet in the packet store.
|
||||
* The packet content is neither checked nor changed with this call. If
|
||||
* the packet could not be found, the data pointer is set to NULL.
|
||||
*/
|
||||
TcPacketStored( store_address_t setAddress );
|
||||
/**
|
||||
* 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 ack Set's the packet's Ack field,
|
||||
* which specifies number and size of verification packets returned
|
||||
* for this command.
|
||||
* @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.
|
||||
*/
|
||||
TcPacketStored( uint8_t service, uint8_t subservice, uint16_t apid,
|
||||
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
|
||||
size_t size = 0, uint8_t ack = TcPacketBase::ACK_ALL );
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
TcPacketStored( const uint8_t* data, uint32_t size);
|
||||
|
||||
ReturnValue_t getData(const uint8_t ** dataPtr,
|
||||
size_t* dataSize);
|
||||
/**
|
||||
* 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.
|
||||
* @return returncode from deleting the data.
|
||||
*/
|
||||
ReturnValue_t 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 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.
|
||||
*/
|
||||
bool isSizeCorrect();
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCPACKETSTORED_H_ */
|
||||
#ifndef TCPACKETSTORED_H_
|
||||
#define TCPACKETSTORED_H_
|
||||
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tmtcpacket/pus/TcPacketBase.h"
|
||||
|
||||
/**
|
||||
* This class generates a ECSS PUS Telecommand packet within a given
|
||||
* intermediate storage.
|
||||
* As most packets are passed between tasks with the help of a storage
|
||||
* anyway, it seems logical to create a Packet-In-Storage access class
|
||||
* which saves the user almost all storage handling operation.
|
||||
* Packets can both be newly created with the class and be "linked" to
|
||||
* packets in a store with the help of a storeAddress.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TcPacketStored : public TcPacketBase {
|
||||
private:
|
||||
/**
|
||||
* 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();
|
||||
public:
|
||||
/**
|
||||
* This is a default constructor which does not set the data pointer.
|
||||
* However, it does try to set the packet store.
|
||||
*/
|
||||
TcPacketStored();
|
||||
/**
|
||||
* With this constructor, the class instance is linked to an existing
|
||||
* packet in the packet store.
|
||||
* The packet content is neither checked nor changed with this call. If
|
||||
* the packet could not be found, the data pointer is set to NULL.
|
||||
*/
|
||||
TcPacketStored( store_address_t setAddress );
|
||||
/**
|
||||
* 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 ack Set's the packet's Ack field,
|
||||
* which specifies number and size of verification packets returned
|
||||
* for this command.
|
||||
* @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.
|
||||
*/
|
||||
TcPacketStored( uint8_t service, uint8_t subservice, uint16_t apid,
|
||||
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
|
||||
size_t size = 0, uint8_t ack = TcPacketBase::ACK_ALL );
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
TcPacketStored( const uint8_t* data, uint32_t size);
|
||||
|
||||
ReturnValue_t getData(const uint8_t ** dataPtr,
|
||||
size_t* dataSize);
|
||||
/**
|
||||
* 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.
|
||||
* @return returncode from deleting the data.
|
||||
*/
|
||||
ReturnValue_t 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 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.
|
||||
*/
|
||||
bool isSizeCorrect();
|
||||
};
|
||||
|
||||
|
||||
#endif /* TCPACKETSTORED_H_ */
|
||||
|
@ -1,119 +1,119 @@
|
||||
#include "../../globalfunctions/CRC.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketBase.h"
|
||||
#include "../../timemanager/CCSDSTime.h"
|
||||
#include <string.h>
|
||||
|
||||
TmPacketBase::TmPacketBase(uint8_t* set_data) :
|
||||
SpacePacketBase(set_data) {
|
||||
tm_data = (TmPacketPointer*) set_data;
|
||||
}
|
||||
|
||||
TmPacketBase::~TmPacketBase() {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
uint8_t TmPacketBase::getService() {
|
||||
return tm_data->data_field.service_type;
|
||||
}
|
||||
|
||||
uint8_t TmPacketBase::getSubService() {
|
||||
return tm_data->data_field.service_subtype;
|
||||
}
|
||||
|
||||
uint8_t* TmPacketBase::getSourceData() {
|
||||
return &tm_data->data;
|
||||
}
|
||||
|
||||
uint16_t TmPacketBase::getSourceDataSize() {
|
||||
return getPacketDataLength() - sizeof(tm_data->data_field)
|
||||
- CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint16_t TmPacketBase::getErrorControl() {
|
||||
uint32_t size = getSourceDataSize() + CRC_SIZE;
|
||||
uint8_t* p_to_buffer = &tm_data->data;
|
||||
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
|
||||
}
|
||||
|
||||
void TmPacketBase::setData(const uint8_t* p_Data) {
|
||||
SpacePacketBase::setData(p_Data);
|
||||
tm_data = (TmPacketPointer*) p_Data;
|
||||
}
|
||||
|
||||
void TmPacketBase::print() {
|
||||
/*uint8_t * wholeData = getWholeData();
|
||||
debug << "TmPacket contains: " << std::endl;
|
||||
for (uint8_t count = 0; count < getFullSize(); ++count ) {
|
||||
debug << std::hex << (uint16_t)wholeData[count] << " ";
|
||||
}
|
||||
debug << std::dec << std::endl;*/
|
||||
}
|
||||
|
||||
bool TmPacketBase::checkAndSetStamper() {
|
||||
if (timeStamper == NULL) {
|
||||
timeStamper = objectManager->get<TimeStamperIF>(timeStamperId);
|
||||
if (timeStamper == NULL) {
|
||||
sif::error << "TmPacketBase::checkAndSetStamper: Stamper not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
|
||||
uint32_t tempSize = 0;
|
||||
return CCSDSTime::convertFromCcsds(timestamp, tm_data->data_field.time,
|
||||
&tempSize, sizeof(tm_data->data_field.time));
|
||||
}
|
||||
|
||||
uint8_t* TmPacketBase::getPacketTimeRaw() const{
|
||||
return tm_data->data_field.time;
|
||||
|
||||
}
|
||||
|
||||
void TmPacketBase::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(&tm_data->data_field, 0, sizeof(tm_data->data_field));
|
||||
//Set CCSDS_secondary header flag to 0, version number to 001 and ack to 0000
|
||||
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits.
|
||||
// The other 4 bits of the first byte are the spacecraft time reference status
|
||||
// To change to PUS-C, set 0b00100000
|
||||
tm_data->data_field.version_type_ack = 0b00010000;
|
||||
tm_data->data_field.service_type = service;
|
||||
tm_data->data_field.service_subtype = subservice;
|
||||
tm_data->data_field.subcounter = packetSubcounter;
|
||||
//Timestamp packet
|
||||
if (checkAndSetStamper()) {
|
||||
timeStamper->addTimeStamp(tm_data->data_field.time, sizeof(tm_data->data_field.time));
|
||||
}
|
||||
}
|
||||
|
||||
void TmPacketBase::setSourceData(uint8_t* sourceData, size_t sourceSize) {
|
||||
memcpy(getSourceData(), sourceData, sourceSize);
|
||||
setSourceDataSize(sourceSize);
|
||||
}
|
||||
|
||||
void TmPacketBase::setSourceDataSize(uint16_t size) {
|
||||
setPacketDataLength(size + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
uint32_t TmPacketBase::getTimestampSize() const {
|
||||
return sizeof(tm_data->data_field.time);
|
||||
}
|
||||
|
||||
TimeStamperIF* TmPacketBase::timeStamper = NULL;
|
||||
object_id_t TmPacketBase::timeStamperId = 0;
|
||||
#include "../../globalfunctions/CRC.h"
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketBase.h"
|
||||
#include "../../timemanager/CCSDSTime.h"
|
||||
#include <string.h>
|
||||
|
||||
TmPacketBase::TmPacketBase(uint8_t* set_data) :
|
||||
SpacePacketBase(set_data) {
|
||||
tm_data = (TmPacketPointer*) set_data;
|
||||
}
|
||||
|
||||
TmPacketBase::~TmPacketBase() {
|
||||
//Nothing to do.
|
||||
}
|
||||
|
||||
uint8_t TmPacketBase::getService() {
|
||||
return tm_data->data_field.service_type;
|
||||
}
|
||||
|
||||
uint8_t TmPacketBase::getSubService() {
|
||||
return tm_data->data_field.service_subtype;
|
||||
}
|
||||
|
||||
uint8_t* TmPacketBase::getSourceData() {
|
||||
return &tm_data->data;
|
||||
}
|
||||
|
||||
uint16_t TmPacketBase::getSourceDataSize() {
|
||||
return getPacketDataLength() - sizeof(tm_data->data_field)
|
||||
- CRC_SIZE + 1;
|
||||
}
|
||||
|
||||
uint16_t TmPacketBase::getErrorControl() {
|
||||
uint32_t size = getSourceDataSize() + CRC_SIZE;
|
||||
uint8_t* p_to_buffer = &tm_data->data;
|
||||
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
|
||||
}
|
||||
|
||||
void TmPacketBase::setData(const uint8_t* p_Data) {
|
||||
SpacePacketBase::setData(p_Data);
|
||||
tm_data = (TmPacketPointer*) p_Data;
|
||||
}
|
||||
|
||||
void TmPacketBase::print() {
|
||||
/*uint8_t * wholeData = getWholeData();
|
||||
debug << "TmPacket contains: " << std::endl;
|
||||
for (uint8_t count = 0; count < getFullSize(); ++count ) {
|
||||
debug << std::hex << (uint16_t)wholeData[count] << " ";
|
||||
}
|
||||
debug << std::dec << std::endl;*/
|
||||
}
|
||||
|
||||
bool TmPacketBase::checkAndSetStamper() {
|
||||
if (timeStamper == NULL) {
|
||||
timeStamper = objectManager->get<TimeStamperIF>(timeStamperId);
|
||||
if (timeStamper == NULL) {
|
||||
sif::error << "TmPacketBase::checkAndSetStamper: Stamper not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
ReturnValue_t TmPacketBase::getPacketTime(timeval* timestamp) const {
|
||||
uint32_t tempSize = 0;
|
||||
return CCSDSTime::convertFromCcsds(timestamp, tm_data->data_field.time,
|
||||
&tempSize, sizeof(tm_data->data_field.time));
|
||||
}
|
||||
|
||||
uint8_t* TmPacketBase::getPacketTimeRaw() const{
|
||||
return tm_data->data_field.time;
|
||||
|
||||
}
|
||||
|
||||
void TmPacketBase::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(&tm_data->data_field, 0, sizeof(tm_data->data_field));
|
||||
//Set CCSDS_secondary header flag to 0, version number to 001 and ack to 0000
|
||||
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits.
|
||||
// The other 4 bits of the first byte are the spacecraft time reference status
|
||||
// To change to PUS-C, set 0b00100000
|
||||
tm_data->data_field.version_type_ack = 0b00010000;
|
||||
tm_data->data_field.service_type = service;
|
||||
tm_data->data_field.service_subtype = subservice;
|
||||
tm_data->data_field.subcounter = packetSubcounter;
|
||||
//Timestamp packet
|
||||
if (checkAndSetStamper()) {
|
||||
timeStamper->addTimeStamp(tm_data->data_field.time, sizeof(tm_data->data_field.time));
|
||||
}
|
||||
}
|
||||
|
||||
void TmPacketBase::setSourceData(uint8_t* sourceData, size_t sourceSize) {
|
||||
memcpy(getSourceData(), sourceData, sourceSize);
|
||||
setSourceDataSize(sourceSize);
|
||||
}
|
||||
|
||||
void TmPacketBase::setSourceDataSize(uint16_t size) {
|
||||
setPacketDataLength(size + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
uint32_t TmPacketBase::getTimestampSize() const {
|
||||
return sizeof(tm_data->data_field.time);
|
||||
}
|
||||
|
||||
TimeStamperIF* TmPacketBase::timeStamper = NULL;
|
||||
object_id_t TmPacketBase::timeStamperId = 0;
|
||||
|
@ -1,186 +1,186 @@
|
||||
#ifndef TMPACKETBASE_H_
|
||||
#define TMPACKETBASE_H_
|
||||
|
||||
#include "../../timemanager/TimeStamperIF.h"
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../../timemanager/Clock.h"
|
||||
#include "../../objectmanager/SystemObjectIF.h"
|
||||
|
||||
namespace Factory{
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* This struct defines a byte-wise structured PUS TM Data Field Header.
|
||||
* Any optional fields in the header must be added or removed here.
|
||||
* Currently, no Destination field is present, but an eigth-byte representation
|
||||
* for a time tag [TBD].
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct PUSTmDataFieldHeader {
|
||||
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];
|
||||
};
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a PUS Telecommand Packet when
|
||||
* accessed via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct TmPacketPointer {
|
||||
CCSDSPrimaryHeader primary;
|
||||
PUSTmDataFieldHeader data_field;
|
||||
uint8_t data;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any ECSS PUS Telemetry packet.
|
||||
*
|
||||
* In addition to \SpacePacketBase, the class provides methods to handle
|
||||
* the standardized entries of the PUS TM Packet Data Field Header.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TmPacketBase : public SpacePacketBase {
|
||||
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(PUSTmDataFieldHeader) + 2); //!< Minimum size of a valid PUS Telemetry Packet.
|
||||
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; //!< Maximum size of a TM Packet in this mission.
|
||||
static const uint8_t VERSION_NUMBER_BYTE_PUS_A = 0b00010000; //!< First byte of secondary header for PUS-A packets.
|
||||
/**
|
||||
* 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* set_data );
|
||||
/**
|
||||
* This is the empty default destructor.
|
||||
*/
|
||||
virtual ~TmPacketBase();
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
uint8_t* getSourceData();
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
uint16_t getSourceDataSize();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* With this method, the Error Control Field is updated to match the
|
||||
* current content of the packet.
|
||||
*/
|
||||
void setErrorControl();
|
||||
/**
|
||||
* This sets the source data. It copies the provided data to
|
||||
* the internal TmPacketPointer source data location.
|
||||
* @param sourceData
|
||||
* @param sourceSize
|
||||
*/
|
||||
void setSourceData(uint8_t* sourceData, size_t sourceSize);
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setData( const uint8_t* p_Data );
|
||||
/**
|
||||
* This is a debugging helper method that prints the whole packet content
|
||||
* to the screen.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Interprets the "time"-field in the secondary header and returns it in timeval format.
|
||||
* @return Converted timestamp of packet.
|
||||
*/
|
||||
ReturnValue_t getPacketTime(timeval* timestamp) const;
|
||||
/**
|
||||
* Returns a raw pointer to the beginning of the time field.
|
||||
* @return Raw pointer to time field.
|
||||
*/
|
||||
uint8_t* getPacketTimeRaw() const;
|
||||
|
||||
uint32_t getTimestampSize() const;
|
||||
|
||||
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.
|
||||
*/
|
||||
TmPacketPointer* tm_data;
|
||||
/**
|
||||
* The timeStamper is responsible for adding a timestamp to the packet.
|
||||
* It is initialized lazy.
|
||||
*/
|
||||
static TimeStamperIF* timeStamper;
|
||||
|
||||
static object_id_t timeStamperId; //!< The ID to use when looking for a time stamper.
|
||||
/**
|
||||
* Checks if a time stamper is available and tries to set it if not.
|
||||
* @return Returns false if setting failed.
|
||||
*/
|
||||
bool checkAndSetStamper();
|
||||
};
|
||||
|
||||
|
||||
#endif /* TMPACKETBASE_H_ */
|
||||
#ifndef TMPACKETBASE_H_
|
||||
#define TMPACKETBASE_H_
|
||||
|
||||
#include "../../timemanager/TimeStamperIF.h"
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../../timemanager/Clock.h"
|
||||
#include "../../objectmanager/SystemObjectIF.h"
|
||||
|
||||
namespace Factory{
|
||||
void setStaticFrameworkObjectIds();
|
||||
}
|
||||
|
||||
/**
|
||||
* This struct defines a byte-wise structured PUS TM Data Field Header.
|
||||
* Any optional fields in the header must be added or removed here.
|
||||
* Currently, no Destination field is present, but an eigth-byte representation
|
||||
* for a time tag [TBD].
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct PUSTmDataFieldHeader {
|
||||
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];
|
||||
};
|
||||
|
||||
/**
|
||||
* This struct defines the data structure of a PUS Telecommand Packet when
|
||||
* accessed via a pointer.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
struct TmPacketPointer {
|
||||
CCSDSPrimaryHeader primary;
|
||||
PUSTmDataFieldHeader data_field;
|
||||
uint8_t data;
|
||||
};
|
||||
|
||||
/**
|
||||
* This class is the basic data handler for any ECSS PUS Telemetry packet.
|
||||
*
|
||||
* In addition to \SpacePacketBase, the class provides methods to handle
|
||||
* the standardized entries of the PUS TM Packet Data Field Header.
|
||||
* It does not contain the packet data itself but a pointer to the
|
||||
* data must be set on instantiation. An invalid pointer may cause
|
||||
* damage, as no getter method checks data validity. Anyway, a NULL
|
||||
* check can be performed by making use of the getWholeData method.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TmPacketBase : public SpacePacketBase {
|
||||
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(PUSTmDataFieldHeader) + 2); //!< Minimum size of a valid PUS Telemetry Packet.
|
||||
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; //!< Maximum size of a TM Packet in this mission.
|
||||
static const uint8_t VERSION_NUMBER_BYTE_PUS_A = 0b00010000; //!< First byte of secondary header for PUS-A packets.
|
||||
/**
|
||||
* 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* set_data );
|
||||
/**
|
||||
* This is the empty default destructor.
|
||||
*/
|
||||
virtual ~TmPacketBase();
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
uint8_t* getSourceData();
|
||||
/**
|
||||
* 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)
|
||||
*/
|
||||
uint16_t getSourceDataSize();
|
||||
|
||||
/**
|
||||
* 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);
|
||||
/**
|
||||
* 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();
|
||||
/**
|
||||
* With this method, the Error Control Field is updated to match the
|
||||
* current content of the packet.
|
||||
*/
|
||||
void setErrorControl();
|
||||
/**
|
||||
* This sets the source data. It copies the provided data to
|
||||
* the internal TmPacketPointer source data location.
|
||||
* @param sourceData
|
||||
* @param sourceSize
|
||||
*/
|
||||
void setSourceData(uint8_t* sourceData, size_t sourceSize);
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
void setData( const uint8_t* p_Data );
|
||||
/**
|
||||
* This is a debugging helper method that prints the whole packet content
|
||||
* to the screen.
|
||||
*/
|
||||
void print();
|
||||
/**
|
||||
* Interprets the "time"-field in the secondary header and returns it in timeval format.
|
||||
* @return Converted timestamp of packet.
|
||||
*/
|
||||
ReturnValue_t getPacketTime(timeval* timestamp) const;
|
||||
/**
|
||||
* Returns a raw pointer to the beginning of the time field.
|
||||
* @return Raw pointer to time field.
|
||||
*/
|
||||
uint8_t* getPacketTimeRaw() const;
|
||||
|
||||
uint32_t getTimestampSize() const;
|
||||
|
||||
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.
|
||||
*/
|
||||
TmPacketPointer* tm_data;
|
||||
/**
|
||||
* The timeStamper is responsible for adding a timestamp to the packet.
|
||||
* It is initialized lazy.
|
||||
*/
|
||||
static TimeStamperIF* timeStamper;
|
||||
|
||||
static object_id_t timeStamperId; //!< The ID to use when looking for a time stamper.
|
||||
/**
|
||||
* Checks if a time stamper is available and tries to set it if not.
|
||||
* @return Returns false if setting failed.
|
||||
*/
|
||||
bool checkAndSetStamper();
|
||||
};
|
||||
|
||||
|
||||
#endif /* TMPACKETBASE_H_ */
|
||||
|
@ -1,45 +1,45 @@
|
||||
#include "../../tmtcpacket/pus/TmPacketMinimal.h"
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
#include "../../tmtcpacket/pus/PacketTimestampInterpreterIF.h"
|
||||
|
||||
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase( set_data ) {
|
||||
this->tm_data = (TmPacketMinimalPointer*)set_data;
|
||||
}
|
||||
|
||||
TmPacketMinimal::~TmPacketMinimal() {
|
||||
}
|
||||
|
||||
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::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);
|
||||
}
|
||||
|
||||
ReturnValue_t TmPacketMinimal::getPacketTimeRaw(const uint8_t** timePtr, uint32_t* 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;
|
||||
}
|
||||
}
|
||||
|
||||
PacketTimestampInterpreterIF* TmPacketMinimal::timestampInterpreter = NULL;
|
||||
#include "../../tmtcpacket/pus/TmPacketMinimal.h"
|
||||
#include <stddef.h>
|
||||
#include <time.h>
|
||||
#include "../../tmtcpacket/pus/PacketTimestampInterpreterIF.h"
|
||||
|
||||
TmPacketMinimal::TmPacketMinimal(const uint8_t* set_data) : SpacePacketBase( set_data ) {
|
||||
this->tm_data = (TmPacketMinimalPointer*)set_data;
|
||||
}
|
||||
|
||||
TmPacketMinimal::~TmPacketMinimal() {
|
||||
}
|
||||
|
||||
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::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);
|
||||
}
|
||||
|
||||
ReturnValue_t TmPacketMinimal::getPacketTimeRaw(const uint8_t** timePtr, uint32_t* 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;
|
||||
}
|
||||
}
|
||||
|
||||
PacketTimestampInterpreterIF* TmPacketMinimal::timestampInterpreter = NULL;
|
||||
|
@ -1,84 +1,84 @@
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
|
||||
|
||||
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
struct timeval;
|
||||
class PacketTimestampInterpreterIF;
|
||||
/**
|
||||
* This is a minimal version of a PUS TmPacket without any variable field, or,
|
||||
* in other words with Service Type, Subtype and subcounter only.
|
||||
* This is required for handling TM packets with different APIDs with different
|
||||
* 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;
|
||||
};
|
||||
|
||||
ReturnValue_t getPacketTime(timeval* timestamp);
|
||||
|
||||
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 PacketTimestampInterpreterIF* timestampInterpreter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ */
|
||||
#ifndef FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
|
||||
#define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
|
||||
|
||||
|
||||
#include "../../tmtcpacket/SpacePacketBase.h"
|
||||
#include "../../returnvalues/HasReturnvaluesIF.h"
|
||||
|
||||
struct timeval;
|
||||
class PacketTimestampInterpreterIF;
|
||||
/**
|
||||
* This is a minimal version of a PUS TmPacket without any variable field, or,
|
||||
* in other words with Service Type, Subtype and subcounter only.
|
||||
* This is required for handling TM packets with different APIDs with different
|
||||
* 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;
|
||||
};
|
||||
|
||||
ReturnValue_t getPacketTime(timeval* timestamp);
|
||||
|
||||
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 PacketTimestampInterpreterIF* timestampInterpreter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ */
|
||||
|
@ -1,146 +1,146 @@
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketStored.h"
|
||||
#include "../../tmtcservices/TmTcMessage.h"
|
||||
#include <string.h>
|
||||
|
||||
TmPacketStored::TmPacketStored(store_address_t setAddress) :
|
||||
TmPacketBase(NULL), storeAddress(setAddress) {
|
||||
setStoreAddress(storeAddress);
|
||||
}
|
||||
|
||||
TmPacketStored::TmPacketStored(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) :
|
||||
TmPacketBase(NULL) {
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
uint8_t *pData = NULL;
|
||||
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
||||
(TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData);
|
||||
|
||||
if (returnValue != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TmPacketStored::TmPacketStored: "
|
||||
"Issue getting free storage" << std::endl;
|
||||
checkAndReportLostTm();
|
||||
return;
|
||||
}
|
||||
setData(pData);
|
||||
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
||||
memcpy(getSourceData(), headerData, headerSize);
|
||||
memcpy(getSourceData() + headerSize, data, size);
|
||||
setPacketDataLength(
|
||||
size + headerSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
// todo: Endianness flags as optional parameter?
|
||||
TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
|
||||
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
|
||||
SerializeIF *header) :
|
||||
TmPacketBase(NULL) {
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
size_t sourceDataSize = 0;
|
||||
if (content != NULL) {
|
||||
sourceDataSize += content->getSerializedSize();
|
||||
}
|
||||
if (header != NULL) {
|
||||
sourceDataSize += header->getSerializedSize();
|
||||
}
|
||||
uint8_t *p_data = NULL;
|
||||
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
||||
(TmPacketBase::TM_PACKET_MIN_SIZE + sourceDataSize), &p_data);
|
||||
if (returnValue != store->RETURN_OK) {
|
||||
checkAndReportLostTm();
|
||||
}
|
||||
setData(p_data);
|
||||
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
||||
uint8_t *putDataHere = getSourceData();
|
||||
size_t size = 0;
|
||||
if (header != NULL) {
|
||||
header->serialize(&putDataHere, &size, sourceDataSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
}
|
||||
if (content != NULL) {
|
||||
content->serialize(&putDataHere, &size, sourceDataSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
}
|
||||
setPacketDataLength(
|
||||
sourceDataSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
store_address_t TmPacketStored::getStoreAddress() {
|
||||
return storeAddress;
|
||||
}
|
||||
|
||||
void TmPacketStored::deletePacket() {
|
||||
store->deleteData(storeAddress);
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
setData(NULL);
|
||||
}
|
||||
|
||||
void TmPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
storeAddress = setAddress;
|
||||
const uint8_t *temp_data = NULL;
|
||||
size_t temp_size;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
ReturnValue_t status = store->getData(storeAddress, &temp_data, &temp_size);
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
setData(temp_data);
|
||||
} else {
|
||||
setData(NULL);
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
bool TmPacketStored::checkAndSetStore() {
|
||||
if (store == NULL) {
|
||||
store = objectManager->get<StorageManagerIF>(objects::TM_STORE);
|
||||
if (store == NULL) {
|
||||
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StorageManagerIF *TmPacketStored::store = NULL;
|
||||
InternalErrorReporterIF *TmPacketStored::internalErrorReporter = NULL;
|
||||
|
||||
ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination,
|
||||
MessageQueueId_t sentFrom, bool doErrorReporting) {
|
||||
if (getWholeData() == NULL) {
|
||||
//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();
|
||||
}
|
||||
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 TmPacketStored::checkAndReportLostTm() {
|
||||
if (internalErrorReporter == NULL) {
|
||||
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||
objects::INTERNAL_ERROR_REPORTER);
|
||||
}
|
||||
if (internalErrorReporter != NULL) {
|
||||
internalErrorReporter->lostTm();
|
||||
}
|
||||
}
|
||||
#include "../../objectmanager/ObjectManagerIF.h"
|
||||
#include "../../serviceinterface/ServiceInterfaceStream.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketStored.h"
|
||||
#include "../../tmtcservices/TmTcMessage.h"
|
||||
#include <string.h>
|
||||
|
||||
TmPacketStored::TmPacketStored(store_address_t setAddress) :
|
||||
TmPacketBase(NULL), storeAddress(setAddress) {
|
||||
setStoreAddress(storeAddress);
|
||||
}
|
||||
|
||||
TmPacketStored::TmPacketStored(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) :
|
||||
TmPacketBase(NULL) {
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
uint8_t *pData = NULL;
|
||||
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
||||
(TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData);
|
||||
|
||||
if (returnValue != HasReturnvaluesIF::RETURN_OK) {
|
||||
sif::debug << "TmPacketStored::TmPacketStored: "
|
||||
"Issue getting free storage" << std::endl;
|
||||
checkAndReportLostTm();
|
||||
return;
|
||||
}
|
||||
setData(pData);
|
||||
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
||||
memcpy(getSourceData(), headerData, headerSize);
|
||||
memcpy(getSourceData() + headerSize, data, size);
|
||||
setPacketDataLength(
|
||||
size + headerSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
// todo: Endianness flags as optional parameter?
|
||||
TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
|
||||
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
|
||||
SerializeIF *header) :
|
||||
TmPacketBase(NULL) {
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
size_t sourceDataSize = 0;
|
||||
if (content != NULL) {
|
||||
sourceDataSize += content->getSerializedSize();
|
||||
}
|
||||
if (header != NULL) {
|
||||
sourceDataSize += header->getSerializedSize();
|
||||
}
|
||||
uint8_t *p_data = NULL;
|
||||
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
||||
(TmPacketBase::TM_PACKET_MIN_SIZE + sourceDataSize), &p_data);
|
||||
if (returnValue != store->RETURN_OK) {
|
||||
checkAndReportLostTm();
|
||||
}
|
||||
setData(p_data);
|
||||
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
||||
uint8_t *putDataHere = getSourceData();
|
||||
size_t size = 0;
|
||||
if (header != NULL) {
|
||||
header->serialize(&putDataHere, &size, sourceDataSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
}
|
||||
if (content != NULL) {
|
||||
content->serialize(&putDataHere, &size, sourceDataSize,
|
||||
SerializeIF::Endianness::BIG);
|
||||
}
|
||||
setPacketDataLength(
|
||||
sourceDataSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1);
|
||||
}
|
||||
|
||||
store_address_t TmPacketStored::getStoreAddress() {
|
||||
return storeAddress;
|
||||
}
|
||||
|
||||
void TmPacketStored::deletePacket() {
|
||||
store->deleteData(storeAddress);
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
setData(NULL);
|
||||
}
|
||||
|
||||
void TmPacketStored::setStoreAddress(store_address_t setAddress) {
|
||||
storeAddress = setAddress;
|
||||
const uint8_t *temp_data = NULL;
|
||||
size_t temp_size;
|
||||
if (!checkAndSetStore()) {
|
||||
return;
|
||||
}
|
||||
ReturnValue_t status = store->getData(storeAddress, &temp_data, &temp_size);
|
||||
if (status == StorageManagerIF::RETURN_OK) {
|
||||
setData(temp_data);
|
||||
} else {
|
||||
setData(NULL);
|
||||
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
||||
}
|
||||
}
|
||||
|
||||
bool TmPacketStored::checkAndSetStore() {
|
||||
if (store == NULL) {
|
||||
store = objectManager->get<StorageManagerIF>(objects::TM_STORE);
|
||||
if (store == NULL) {
|
||||
sif::error << "TmPacketStored::TmPacketStored: TM Store not found!"
|
||||
<< std::endl;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
StorageManagerIF *TmPacketStored::store = NULL;
|
||||
InternalErrorReporterIF *TmPacketStored::internalErrorReporter = NULL;
|
||||
|
||||
ReturnValue_t TmPacketStored::sendPacket(MessageQueueId_t destination,
|
||||
MessageQueueId_t sentFrom, bool doErrorReporting) {
|
||||
if (getWholeData() == NULL) {
|
||||
//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();
|
||||
}
|
||||
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 TmPacketStored::checkAndReportLostTm() {
|
||||
if (internalErrorReporter == NULL) {
|
||||
internalErrorReporter = objectManager->get<InternalErrorReporterIF>(
|
||||
objects::INTERNAL_ERROR_REPORTER);
|
||||
}
|
||||
if (internalErrorReporter != NULL) {
|
||||
internalErrorReporter->lostTm();
|
||||
}
|
||||
}
|
||||
|
@ -1,96 +1,96 @@
|
||||
#ifndef TMPACKETSTORED_H_
|
||||
#define TMPACKETSTORED_H_
|
||||
|
||||
#include "../../serialize/SerializeIF.h"
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketBase.h"
|
||||
#include "../../internalError/InternalErrorReporterIF.h"
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
/**
|
||||
* This class generates a ECSS PUS Telemetry packet within a given
|
||||
* intermediate storage.
|
||||
* As most packets are passed between tasks with the help of a storage
|
||||
* anyway, it seems logical to create a Packet-In-Storage access class
|
||||
* which saves the user almost all storage handling operation.
|
||||
* Packets can both be newly created with the class and be "linked" to
|
||||
* packets in a store with the help of a storeAddress.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TmPacketStored : public TmPacketBase {
|
||||
private:
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
public:
|
||||
/**
|
||||
* This is a default constructor which does not set the data pointer.
|
||||
* However, it does try to set the packet store.
|
||||
*/
|
||||
TmPacketStored( 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
|
||||
*/
|
||||
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0, const uint8_t* data = NULL, uint32_t size = 0, const uint8_t* headerData = NULL, uint32_t headerSize = 0);
|
||||
/**
|
||||
* Another ctor to directly pass structured content and header data to the packet to avoid additional buffers.
|
||||
*/
|
||||
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter, SerializeIF* content, SerializeIF* header = NULL);
|
||||
/**
|
||||
* 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 );
|
||||
};
|
||||
|
||||
|
||||
#endif /* TMPACKETSTORED_H_ */
|
||||
#ifndef TMPACKETSTORED_H_
|
||||
#define TMPACKETSTORED_H_
|
||||
|
||||
#include "../../serialize/SerializeIF.h"
|
||||
#include "../../storagemanager/StorageManagerIF.h"
|
||||
#include "../../tmtcpacket/pus/TmPacketBase.h"
|
||||
#include "../../internalError/InternalErrorReporterIF.h"
|
||||
#include "../../ipc/MessageQueueSenderIF.h"
|
||||
|
||||
/**
|
||||
* This class generates a ECSS PUS Telemetry packet within a given
|
||||
* intermediate storage.
|
||||
* As most packets are passed between tasks with the help of a storage
|
||||
* anyway, it seems logical to create a Packet-In-Storage access class
|
||||
* which saves the user almost all storage handling operation.
|
||||
* Packets can both be newly created with the class and be "linked" to
|
||||
* packets in a store with the help of a storeAddress.
|
||||
* @ingroup tmtcpackets
|
||||
*/
|
||||
class TmPacketStored : public TmPacketBase {
|
||||
private:
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
public:
|
||||
/**
|
||||
* This is a default constructor which does not set the data pointer.
|
||||
* However, it does try to set the packet store.
|
||||
*/
|
||||
TmPacketStored( 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
|
||||
*/
|
||||
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0, const uint8_t* data = NULL, uint32_t size = 0, const uint8_t* headerData = NULL, uint32_t headerSize = 0);
|
||||
/**
|
||||
* Another ctor to directly pass structured content and header data to the packet to avoid additional buffers.
|
||||
*/
|
||||
TmPacketStored( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter, SerializeIF* content, SerializeIF* header = NULL);
|
||||
/**
|
||||
* 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 );
|
||||
};
|
||||
|
||||
|
||||
#endif /* TMPACKETSTORED_H_ */
|
||||
|
Reference in New Issue
Block a user