1
0
forked from fsfw/fsfw

Today's the day. Renamed platform to framework.

This commit is contained in:
Bastian Baetz
2016-06-15 23:48:41 +02:00
committed by Ulrich Mohr
parent 40987d0b27
commit 1d22a6c97e
356 changed files with 33946 additions and 3 deletions

View File

@ -0,0 +1,74 @@
/*
* TcPacket.cpp
*
* Created on: 18.06.2012
* Author: baetz
*/
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcpacket/pus/TcPacket.h>
#include <string.h>
template <uint32_t byte_size>
TcPacket<byte_size>::TcPacket() : TcPacketBase( (uint8_t*)&this->local_data ) {
memset( &this->local_data, 0, sizeof(this->local_data) );
//Set all constant elements in header according to ECSS E-70-41A (2003)
//Primary header:
//Set APID to idle packet
this->local_data.primary.packet_id_h = 0b00011000;
this->setAPID( APID_IDLE_PACKET );
//Set Sequence Flags to "stand-alone packet"
this->local_data.primary.sequence_control_h = 0b11000000;
//Set packet size to size of data field header + CRC
this->setPacketDataLength( sizeof(this->local_data.data_field) + CRC_SIZE );
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
this->local_data.data_field.version_type_ack = 0b00010000;
}
template <uint32_t byte_size>
TcPacket<byte_size>::TcPacket( uint16_t new_apid, uint8_t new_ack, uint8_t new_service, uint8_t new_subservice, uint16_t new_sequence_count) : TcPacketBase( (uint8_t*)&this->local_data ) {
memset( &this->local_data, 0, sizeof(this->local_data) );
//Set all constant elements in header according to ECSS E-70-41A (2003)
//Primary header:
//Set APID to idle packet
this->local_data.primary.packet_id_h = 0b00011000;
this->setAPID( new_apid );
//Set Sequence Flags to "stand-alone packet"
this->local_data.primary.sequence_control_h = 0b11000000;
this->setPacketSequenceCount( new_sequence_count );
this->setPacketDataLength( sizeof(this->local_data.data_field) + CRC_SIZE );
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
this->local_data.data_field.version_type_ack = 0b00010000;
this->local_data.data_field.version_type_ack |= ( new_ack & 0x0F);
this->local_data.data_field.service_type = new_service;
this->local_data.data_field.service_subtype = new_subservice;
this->setErrorControl();
}
template <uint32_t byte_size>
TcPacket< byte_size >::~TcPacket() {
}
template <uint32_t byte_size>
bool TcPacket<byte_size>::addApplicationData( uint8_t* newData, uint32_t amount ) {
if ( amount <= ( sizeof(this->local_data.application_data) - CRC_SIZE ) ) {
memcpy( this->local_data.application_data, newData, amount );
this->setPacketDataLength( amount + sizeof(this->local_data.data_field) + CRC_SIZE - 1 );
this->setErrorControl();
return true;
} else {
return false;
}
}
template class TcPacket<TC_PACKET_MIN_SIZE>;
template class TcPacket<32>;
template class TcPacket<64>;
template class TcPacket<128>;
template class TcPacket<256>;
template class TcPacket<1024>;

83
tmtcpacket/pus/TcPacket.h Normal file
View File

@ -0,0 +1,83 @@
#ifndef TCPACKET_H_
#define TCPACKET_H_
#include <framework/tmtcpacket/pus/TcPacketBase.h>
/**
* This constant defines the minimum size of a valid PUS Telecommand Packet.
*/
#define TC_PACKET_MIN_SIZE (sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) + 2)
/**
* The TcPacket class is a representation of a ECSS PUS Telecommand packet.
* The template parameter is used to instantiate the class with different
* maximum Application Data sizes (to avoid wasting stack size).
* Telecommand packets are mainly created on ground, which are accessed with
* the TcPacketBase class. However, there are occasions when command packets
* are created on-board, for example when commanding another PUS compatible
* device such as the star trackers.
* These packets can be created with the TcPacket class.
* A pointer to \c local_data is passed to the \c TcPacketBase parent class,
* so the parent's methods are reachable.
* @t_param byte_size The maximum size of the complete packet (including CRC
* and headers)
* @ingroup tmtcpackets
*/
template<uint32_t byte_size>
class TcPacket : public TcPacketBase {
private:
/**
* This structure defines the data structure of a Telecommand Packet as
* local data.
*
* There's a buffer which corresponds to the Telecommand Application Data
* Field with a maximum size of \c byte_size.
*/
struct TcPacketData {
CCSDSPrimaryHeader primary;
PUSTcDataFieldHeader data_field;
uint8_t application_data[byte_size - sizeof(CCSDSPrimaryHeader) - sizeof(PUSTcDataFieldHeader)];
};
/**
* This is the data representation of the class.
*/
TcPacketData local_data;
public:
/**
* This is the default constructor of the class.
*
* It sets all values to default for a CCSDS Idle Packet (i.e. APID is 2047).
*/
TcPacket( void );
/**
* A constructor which directly sets all relevant header information.
* @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.
*/
TcPacket( uint16_t apid, uint8_t ack, uint8_t service, uint8_t subservice, uint16_t sequence_count = 0 );
/**
* This is the empty default destructor of the class.
*/
~TcPacket( void );
/**
* With this call, application data can be added to the Application Data
* buffer.
* The Error Control Field is updated automatically.
* @param data The data to add to the Application Data field.
* @param size The size of the data to add.
* @return @li \c true if \c size is smaller than the Application Data
* buffer.
* @li \c false else.
*/
bool addApplicationData( uint8_t* data, uint32_t size );
};
#endif /* TCPACKET_H_ */

View File

@ -0,0 +1,74 @@
/*
* TcPacketBase.cpp
*
* Created on: 18.06.2012
* Author: baetz
*/
#include <framework/globalfunctions/crc_ccitt.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcpacket/pus/TcPacketBase.h>
TcPacketBase::TcPacketBase( const uint8_t* set_data ) : SpacePacketBase( set_data ) {
this->tc_data = (TcPacketPointer*)set_data;
}
TcPacketBase::~TcPacketBase() {
//Nothing to do.
}
uint8_t TcPacketBase::getService() {
return this->tc_data->data_field.service_type;
}
uint8_t TcPacketBase::getSubService() {
return this->tc_data->data_field.service_subtype;
}
uint8_t TcPacketBase::getAcknowledgeFlags() {
return this->tc_data->data_field.version_type_ack & 0b00001111;
}
const uint8_t* TcPacketBase::getApplicationData() const {
return &this->tc_data->data;
}
uint16_t TcPacketBase::getApplicationDataSize() {
return this->getPacketDataLength() - sizeof(this->tc_data->data_field) - CRC_SIZE + 1;
}
uint16_t TcPacketBase::getErrorControl() {
uint16_t size = this->getApplicationDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &this->tc_data->data;
return ( p_to_buffer[size - 2] << 8 ) + p_to_buffer[size - 1];
}
void TcPacketBase::setErrorControl() {
uint32_t full_size = this->getFullSize();
uint16_t crc = ::Calculate_CRC ( this->getWholeData(), full_size - CRC_SIZE );
uint32_t size = this->getApplicationDataSize();
(&tc_data->data)[ size ] = ( crc & 0XFF00) >> 8; // CRCH
(&tc_data->data)[ size + 1 ] = ( crc ) & 0X00FF; // CRCL
}
void TcPacketBase::setData(const uint8_t* p_Data) {
this->SpacePacketBase::setData( p_Data );
this->tc_data = (TcPacketPointer*)p_Data;
}
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
return (this->tc_data->data_field.version_type_ack & 0b10000000) >> 7;
}
uint8_t TcPacketBase::getPusVersionNumber() {
return (this->tc_data->data_field.version_type_ack & 0b01110000) >> 4;
}
void TcPacketBase::print() {
uint8_t * wholeData = this->getWholeData();
debug << "TcPacket contains: " << std::endl;
for (uint8_t count = 0; count < this->getFullSize(); ++count ) {
debug << std::hex << (uint16_t)wholeData[count] << " ";
}
debug << std::dec << std::endl;
}

View File

@ -0,0 +1,170 @@
#ifndef TCPACKETBASE_H_
#define TCPACKETBASE_H_
#include <framework/tmtcpacket/SpacePacketBase.h>
/**
* 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 data_field;
uint8_t data;
};
/**
* 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* tc_data;
public:
/**
* 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();
/**
* 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();
/**
* 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* p_data );
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
};
#endif /* TCPACKETBASE_H_ */

View File

@ -0,0 +1,104 @@
/*
* TcPacketStored.cpp
*
* Created on: 20.11.2012
* Author: baetz
*/
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcpacket/pus/TcPacket.h>
#include <framework/tmtcpacket/pus/TcPacketStored.h>
#include <string.h>
TcPacketStored::TcPacketStored( store_address_t setAddress) : TcPacketBase(NULL), storeAddress(setAddress) {
this->setStoreAddress( this->storeAddress );
}
TcPacketStored::TcPacketStored( uint16_t apid, uint8_t ack, uint8_t service, uint8_t subservice,
uint8_t sequence_count, const uint8_t* data, uint32_t size) : TcPacketBase(NULL) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if ( this->checkAndSetStore() ) {
TcPacket<TC_PACKET_MIN_SIZE> temp_packet( apid, ack, service, subservice, sequence_count);
uint8_t* p_data = NULL;
ReturnValue_t returnValue = this->store->getFreeElement( &this->storeAddress, (TC_PACKET_MIN_SIZE + size), &p_data );
if ( returnValue == this->store->RETURN_OK ) {
memcpy(p_data, temp_packet.getWholeData(), temp_packet.getFullSize() );
this->setData( p_data );
memcpy( &tc_data->data, data, size );
this->setPacketDataLength( size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1 );
this->setErrorControl();
}
}
}
TcPacketStored::TcPacketStored() : TcPacketBase(NULL) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
}
//TODO: return code?
void TcPacketStored::deletePacket() {
this->store->deleteData( this->storeAddress );
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData( NULL );
}
bool TcPacketStored::checkAndSetStore() {
if (this->store == NULL) {
this->store = objectManager->get<StorageManagerIF>( objects::TC_STORE );
if ( this->store == NULL ) {
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;
uint32_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;
uint32_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);
}
}
}

View File

@ -0,0 +1,104 @@
#ifndef TCPACKETSTORED_H_
#define TCPACKETSTORED_H_
#include <framework/storagemanager/StorageManagerIF.h>
#include <framework/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( uint16_t apid, uint8_t ack, uint8_t service, uint8_t subservice, uint8_t sequence_count = 0, const uint8_t* data = NULL, uint32_t size = 0 );
/**
* 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);
/**
* This is a getter for the current store address of the packet.
* @return The current store address. The (raw) value is \c StorageManagerIF::INVALID_ADDRESS if
* the packet is not linked.
*/
store_address_t getStoreAddress();
/**
* With this call, the packet is deleted.
* It removes itself from the store and sets its data pointer to NULL.
*/
void deletePacket();
/**
* With this call, a packet can be linked to another store. This is useful
* if the packet is a class member and used for more than one packet.
* @param setAddress The new packet id to link to.
*/
void setStoreAddress( store_address_t setAddress );
/**
* This 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_ */

View File

@ -0,0 +1,80 @@
/*
* TmPacket.cpp
*
* Created on: 18.06.2012
* Author: baetz
*/
#include <framework/tmtcpacket/pus/TmPacket.h>
#include <string.h>
template <uint32_t byte_size>
TmPacket<byte_size>::TmPacket() : TmPacketBase( (uint8_t*)&this->local_data ) {
memset( &this->local_data, 0, sizeof(this->local_data) );
//Set all constant elements in header according to ECSS E-70-41A (2003)
//Primary header:
//Set APID to idle packet
local_data.primary.packet_id_h = 0b00001000;
setAPID( APID_IDLE_PACKET );
//Set Sequence Flags to "stand-alone packet"
local_data.primary.sequence_control_h = 0b11000000;
//Set packet size to size of data field header + CRC
setPacketDataLength( sizeof(this->local_data.data_field) + CRC_SIZE );
if (checkAndSetStamper()) {
timeStamper->addTimeStamp(local_data.data_field.time, sizeof(local_data.data_field.time));
}
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
this->local_data.data_field.version_type_ack = 0b00010000;
}
template <uint32_t byte_size>
TmPacket<byte_size>::TmPacket( uint16_t new_apid, uint8_t new_service, uint8_t new_subservice, uint8_t new_packet_counter ) : TmPacketBase( (uint8_t*)&this->local_data ) {
memset( &this->local_data, 0, sizeof(this->local_data) );
//Set all constant elements in header according to ECSS E-70-41A (2003)
//Primary header:
//Set APID to idle packet
this->local_data.primary.packet_id_h = 0b00001000;
this->setAPID( new_apid );
//Set Sequence Flags to "stand-alone packet"
this->local_data.primary.sequence_control_h = 0b11000000;
//Set Data Length to minimum size (Data Field Header + CRC size)
this->setPacketDataLength( sizeof(this->local_data.data_field) + CRC_SIZE );
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
this->local_data.data_field.version_type_ack = 0b00010000;
this->local_data.data_field.service_type = new_service;
this->local_data.data_field.service_subtype = new_subservice;
this->local_data.data_field.subcounter = new_packet_counter;
if (checkAndSetStamper()) {
timeStamper->addTimeStamp(local_data.data_field.time, sizeof(local_data.data_field.time));
}
// this->local_data.data_field.destination = new_destination;
this->setErrorControl();
}
template <uint32_t byte_size>
TmPacket< byte_size >::~TmPacket() {
}
template <uint32_t byte_size>
bool TmPacket<byte_size>::addSourceData( uint8_t* newData, uint32_t amount ) {
if ( amount <= ( sizeof(this->local_data.source_data) - CRC_SIZE ) ) {
memcpy( this->local_data.source_data, newData, amount );
this->setPacketDataLength( amount + sizeof(this->local_data.data_field) + CRC_SIZE - 1 );
this->setErrorControl();
return true;
} else {
return false;
}
}
template class TmPacket<TmPacketBase::TM_PACKET_MIN_SIZE>;
template class TmPacket<64>;
template class TmPacket<128>;
template class TmPacket<256>;
template class TmPacket<512>;
template class TmPacket<1024>;

72
tmtcpacket/pus/TmPacket.h Normal file
View File

@ -0,0 +1,72 @@
#ifndef TMPACKET_H_
#define TMPACKET_H_
#include <framework/tmtcpacket/pus/TmPacketBase.h>
/**
* The TmPacket class is a representation of a ECSS PUS Telemetry packet.
* The template parameter is used to instantiate the class with different
* maximum Application Data sizes (to avoid wasting stack size). Almost every
* on-board service is a source of telemetry packets. These packets are created
* with the TmPacket class, which is instantiated similar to the TcPacket
* class.
* A pointer to \c local_data is passed to the \c TmPacketBase parent class,
* so the parent's methods are reachable.
* @t_param byte_size The maximum size of the complete packet (including CRC
* and headers)
* @ingroup tmtcpackets
*/
template<uint32_t byte_size>
class TmPacket : public TmPacketBase {
public:
/**
* This is the default constructor of the class.
*
* It sets all values to default for a CCSDS Idle Packet (i.e. APID is 2047).
*/
TmPacket( void );
/**
* A constructor which directly sets all relevant header information.
* @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.
*/
TmPacket( uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packet_counter = 0 );
/**
* This is the empty default destructor of the class.
*/
~TmPacket( void );
/**
* With this call, application data can be added to the Source Data
* buffer.
* The Error Control Field is updated automatically.
* @param data The data to add to the Source Data field.
* @param size The size of the data to add.
* @return @li \c true if \c size is smaller than the Source Data buffer.
* @li \c false else.
*/
bool addSourceData( uint8_t*, uint32_t );
private:
/**
* This structure defines the data structure of a Telemetry Packet as
* local data.
*
* There's a buffer which corresponds to the Telemetry Source Data Field
* with a maximum size of \c byte_size.
*/
struct TmPacketData {
CCSDSPrimaryHeader primary;
PUSTmDataFieldHeader data_field;
uint8_t source_data[byte_size - sizeof(CCSDSPrimaryHeader) - sizeof(PUSTmDataFieldHeader)];
};
/**
* This is the data representation of the class.
*/
TmPacketData local_data;
};
#endif /* TMPACKET_H_ */

View File

@ -0,0 +1,78 @@
/*
* TmPacketBase.cpp
*
* Created on: 18.06.2012
* Author: baetz
*/
#include <framework/globalfunctions/crc_ccitt.h>
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcpacket/pus/TmPacketBase.h>
TmPacketBase::TmPacketBase( uint8_t* set_data ) : SpacePacketBase( set_data ) {
this->tm_data = (TmPacketPointer*)set_data;
}
TmPacketBase::~TmPacketBase() {
//Nothing to do.
}
uint8_t TmPacketBase::getService() {
return this->tm_data->data_field.service_type;
}
uint8_t TmPacketBase::getSubService() {
return this->tm_data->data_field.service_subtype;
}
uint8_t* TmPacketBase::getSourceData() {
return &this->tm_data->data;
}
uint16_t TmPacketBase::getSourceDataSize() {
return this->getPacketDataLength() - sizeof(this->tm_data->data_field) - CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {
uint32_t size = this->getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &this->tm_data->data;
return ( p_to_buffer[size - 2] << 8 ) + p_to_buffer[size - 1];
}
void TmPacketBase::setErrorControl() {
uint32_t full_size = this->getFullSize();
uint16_t crc = ::Calculate_CRC ( this->getWholeData(), full_size - CRC_SIZE );
uint32_t size = this->getSourceDataSize();
this->getSourceData()[ size ] = ( crc & 0XFF00) >> 8; // CRCH
this->getSourceData()[ size + 1 ] = ( crc ) & 0X00FF; // CRCL
}
void TmPacketBase::setData(const uint8_t* p_Data) {
this->SpacePacketBase::setData( p_Data );
this->tm_data = (TmPacketPointer*)p_Data;
}
void TmPacketBase::print() {
/*uint8_t * wholeData = this->getWholeData();
debug << "TmPacket contains: " << std::endl;
for (uint8_t count = 0; count < this->getFullSize(); ++count ) {
debug << std::hex << (uint16_t)wholeData[count] << " ";
}
debug << std::dec << std::endl;*/
}
bool TmPacketBase::checkAndSetStamper() {
if (timeStamper == NULL) {
//TODO: Adjust name?
timeStamper = objectManager->get<TimeStamperIF>( objects::TIME_MANAGER );
if ( timeStamper == NULL ) {
error << "TmPacketBase::checkAndSetStamper: Stamper not found!" << std::endl;
return false;
}
}
return true;
}
TimeStamperIF* TmPacketBase::timeStamper = NULL;

View File

@ -0,0 +1,143 @@
#ifndef TMPACKETBASE_H_
#define TMPACKETBASE_H_
#include <framework/timemanager/TimeStamperIF.h>
#include <framework/tmtcpacket/SpacePacketBase.h>
/**
* 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;
};
//TODO: add getTime, getSubcounter, getDestionation (if required)
/**
* 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 {
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.
*/
TmPacketBase( uint8_t* set_data );
/**
* This is the empty default destructor.
*/
virtual ~TmPacketBase();
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
* @return The packet's PUS Service ID.
*/
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();
/**
* 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();
/**
* 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();
/**
* 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);
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048; //!< Maximum size of a TM Packet in this mission.
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;
/**
* 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_ */

View File

@ -0,0 +1,21 @@
#include <framework/tmtcpacket/pus/TmPacketMinimal.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;
}

View File

@ -0,0 +1,80 @@
/*
* TmPacketMinimal.h
*
* Created on: 09.03.2015
* Author: baetz
*/
#ifndef FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
#define FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_
#include <framework/tmtcpacket/SpacePacketBase.h>
/**
* 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;
};
/**
* 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;
};
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;
};
#endif /* FRAMEWORK_TMTCPACKET_PUS_TMPACKETMINIMAL_H_ */

View File

@ -0,0 +1,105 @@
/*
* TmPacketStored.cpp
*
* Created on: 19.11.2012
* Author: baetz
*/
#include <framework/objectmanager/ObjectManagerIF.h>
#include <framework/serviceinterface/ServiceInterfaceStream.h>
#include <framework/tmtcpacket/pus/TmPacket.h>
#include <framework/tmtcpacket/pus/TmPacketStored.h>
#include <string.h>
TmPacketStored::TmPacketStored( store_address_t setAddress ) : TmPacketBase(NULL), storeAddress(setAddress) {
this->setStoreAddress( this->storeAddress );
}
TmPacketStored::TmPacketStored( uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packet_counter, const uint8_t* data, uint32_t size,const uint8_t* headerData, uint32_t headerSize) : TmPacketBase(NULL) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if ( this->checkAndSetStore() ) {
TmPacket<TmPacketBase::TM_PACKET_MIN_SIZE> temp_packet( apid, service, subservice, packet_counter );
uint8_t* p_data = NULL;
ReturnValue_t returnValue = this->store->getFreeElement( &this->storeAddress, (TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &p_data );
if ( returnValue == this->store->RETURN_OK ) {
memcpy(p_data, temp_packet.getWholeData(), temp_packet.getFullSize() );
this->setData( p_data );
memcpy( this->getSourceData(), headerData, headerSize );
memcpy( this->getSourceData() + headerSize, data, size );
this->setPacketDataLength( size + headerSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1 );
this->setErrorControl();
}
}
}
TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packet_counter, SerializeIF* content,
SerializeIF* header) : TmPacketBase(NULL) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if ( checkAndSetStore() ) {
TmPacket<TmPacketBase::TM_PACKET_MIN_SIZE> temp_packet( apid, service, subservice, packet_counter );
uint32_t sourceDataSize = 0;
if (content != NULL) {
sourceDataSize += content->getSerializedSize();
}
if (header != NULL) {
sourceDataSize += header->getSerializedSize();
}
uint8_t* p_data = NULL;
ReturnValue_t returnValue = this->store->getFreeElement( &this->storeAddress, (TmPacketBase::TM_PACKET_MIN_SIZE + sourceDataSize), &p_data );
if ( returnValue == store->RETURN_OK ) {
memcpy(p_data, temp_packet.getWholeData(), temp_packet.getFullSize() );
this->setData( p_data );
uint8_t* putDataHere = getSourceData();
uint32_t size = 0;
if (header != NULL) {
header->serialize(&putDataHere, &size, sourceDataSize, true);
}
if (content != NULL) {
content->serialize(&putDataHere, &size, sourceDataSize, true);
}
this->setPacketDataLength( sourceDataSize + sizeof(PUSTmDataFieldHeader) + CRC_SIZE - 1 );
this->setErrorControl();
}
}
}
store_address_t TmPacketStored::getStoreAddress() {
return this->storeAddress;
}
void TmPacketStored::deletePacket() {
this->store->deleteData( this->storeAddress );
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData( NULL );
}
void TmPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* temp_data = NULL;
uint32_t temp_size;
if (!checkAndSetStore()) {
return;
}
ReturnValue_t 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;
}
}
bool TmPacketStored::checkAndSetStore() {
if (this->store == NULL) {
this->store = objectManager->get<StorageManagerIF>( objects::TM_STORE );
if ( this->store == NULL ) {
error << "TmPacketStored::TmPacketStored: TM Store not found!" << std::endl;
return false;
}
}
return true;
}
StorageManagerIF* TmPacketStored::store = NULL;

View File

@ -0,0 +1,87 @@
#ifndef TMPACKETSTORED_H_
#define TMPACKETSTORED_H_
#include <framework/serialize/SerializeIF.h>
#include <framework/storagemanager/StorageManagerIF.h>
#include <framework/tmtcpacket/pus/TmPacketBase.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;
/**
* 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.
*/
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 );
};
#endif /* TMPACKETSTORED_H_ */