more refactoring

This commit is contained in:
Robin Müller 2020-10-28 02:20:12 +01:00
parent ce322ed121
commit 546db47db4
10 changed files with 241 additions and 254 deletions

View File

@ -14,8 +14,12 @@ public:
static const uint8_t INTERFACE_ID = CLASS_ID::TIME_STAMPER_IF;
static const ReturnValue_t BAD_TIMESTAMP = MAKE_RETURN_CODE(1);
static const uint8_t MISSION_TIMESTAMP_SIZE = 8; //!< This is a mission-specific constant and determines the total size reserved for timestamps.
virtual ReturnValue_t addTimeStamp(uint8_t* buffer, const uint8_t maxSize) = 0;
//! This is a mission-specific constant and determines the total
//! size reserved for timestamps.
//! TODO: Default define in FSFWConfig ?
static const uint8_t MISSION_TIMESTAMP_SIZE = 8;
virtual ReturnValue_t addTimeStamp(uint8_t* buffer,
const uint8_t maxSize) = 0;
virtual ~TimeStamperIF() {}
};

View File

@ -1,6 +1,6 @@
#include "../serviceinterface/ServiceInterfaceStream.h"
#include "SpacePacketBase.h"
#include <string.h>
#include "../serviceinterface/ServiceInterfaceStream.h"
#include <cstring>
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) {
this->data = (SpacePacketPointer*) set_address;

View File

@ -1,5 +1,5 @@
#ifndef SPACEPACKETBASE_H_
#define SPACEPACKETBASE_H_
#ifndef FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#include "ccsds_header.h"
#include <cstddef>
@ -82,7 +82,8 @@ public:
*/
bool isTelecommand( void );
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount = 0);
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.
@ -174,4 +175,4 @@ public:
};
#endif /* SPACEPACKETBASE_H_ */
#endif /* FSFW_TMTCPACKET_SPACEPACKETBASE_H_ */

View File

@ -7,7 +7,8 @@ class TmPacketMinimal;
class PacketTimestampInterpreterIF {
public:
virtual ~PacketTimestampInterpreterIF() {}
virtual ReturnValue_t getPacketTime(TmPacketMinimal* packet, timeval* timestamp) const = 0;
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;
};

View File

@ -1,11 +1,14 @@
#include "../../globalfunctions/CRC.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "TcPacketBase.h"
#include <string.h>
TcPacketBase::TcPacketBase(const uint8_t* set_data) :
SpacePacketBase(set_data) {
tcData = (TcPacketPointer*) set_data;
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include <cstring>
TcPacketBase::TcPacketBase(const uint8_t* setData) :
SpacePacketBase(setData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(setData));
}
TcPacketBase::~TcPacketBase() {
@ -51,12 +54,6 @@ void TcPacketBase::setData(const uint8_t* 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;
}
@ -66,21 +63,17 @@ uint8_t TcPacketBase::getPusVersionNumber() {
}
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;
sif::debug << "TcPacketBase::print: " << std::endl;
arrayprinter::print(getWholeData(), getFullSize());
}
void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
memset(&tcData->dataField, 0, sizeof(tcData->dataField));
std::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
//Set CCSDS_secondary_header_flag to 0 and version number to 001
tcData->dataField.version_type_ack = 0b00010000;
tcData->dataField.version_type_ack |= (ack & 0x0F);
tcData->dataField.service_type = service;

View File

@ -1,5 +1,5 @@
#ifndef TCPACKETBASE_H_
#define TCPACKETBASE_H_
#ifndef TMTCPACKET_PUS_TCPACKETBASE_H_
#define TMTCPACKET_PUS_TCPACKETBASE_H_
#include "../../tmtcpacket/SpacePacketBase.h"
#include <cstddef>
@ -32,7 +32,7 @@ struct TcPacketPointer {
/**
* This class is the basic data handler for any ECSS PUS Telecommand packet.
*
* In addition to \SpacePacketBase, the class provides methods to handle
* 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
@ -41,68 +41,35 @@ struct TcPacketPointer {
* @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;
static const uint16_t TC_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTcDataFieldHeader) + 2);
enum AckField {
//! Acknowledgements on all levels are expected.
ACK_ALL = 0b1111,
//! Acknowledgements on acceptance are expected.
ACK_ACCEPTANCE = 0b0001,
//! Acknowledgements on start are expected.
ACK_START = 0b0010,
//! Acknowledgements on step are expected.
ACK_STEP = 0b0100,
//! No acknowledgements are expected.
ACK_NONE = 0b0000
};
/**
* 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.
* @param setData The position where the packet data lies.
*/
TcPacketBase( const uint8_t* set_data );
TcPacketBase( const uint8_t* setData );
/**
* 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
@ -170,24 +137,6 @@ public:
*/
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.
@ -199,7 +148,37 @@ public:
* @return
*/
static size_t calculateFullPacketLength(size_t appDataLen);
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;
/**
* 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);
/**
* 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 );
};
#endif /* TCPACKETBASE_H_ */
#endif /* TMTCPACKET_PUS_TCPACKETBASE_H_ */

View File

@ -1,31 +1,34 @@
#include "TcPacketStored.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "TcPacketStored.h"
#include <cstring>
StorageManagerIF* TcPacketStored::store = nullptr;
TcPacketStored::TcPacketStored(store_address_t setAddress) :
TcPacketBase(nullptr), storeAddress(setAddress) {
this->setStoreAddress(this->storeAddress);
setStoreAddress(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 ) :
TcPacketStored::TcPacketStored(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t sequenceCount, const uint8_t* data,
size_t size, uint8_t ack) :
TcPacketBase(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
if (!this->checkAndSetStore()) {
if (not this->checkAndSetStore()) {
return;
}
uint8_t* p_data = nullptr;
uint8_t* pData = nullptr;
ReturnValue_t returnValue = this->store->getFreeElement(&this->storeAddress,
(TC_PACKET_MIN_SIZE + size), &p_data);
(TC_PACKET_MIN_SIZE + size), &pData);
if (returnValue != this->store->RETURN_OK) {
sif::warning << "TcPacketStored: Could not get free element from store!"
<< std::endl;
return;
}
this->setData(p_data);
initializeTcPacket(apid, sequence_count, ack, service, subservice);
this->setData(pData);
initializeTcPacket(apid, sequenceCount, ack, service, subservice);
memcpy(&tcData->appData, data, size);
this->setPacketDataLength(
size + sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
@ -41,8 +44,7 @@ ReturnValue_t TcPacketStored::getData(const uint8_t ** dataPtr,
return result;
}
TcPacketStored::TcPacketStored() :
TcPacketBase(NULL) {
TcPacketStored::TcPacketStored(): TcPacketBase(nullptr) {
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->checkAndSetStore();
@ -51,14 +53,14 @@ TcPacketStored::TcPacketStored() :
ReturnValue_t TcPacketStored::deletePacket() {
ReturnValue_t result = this->store->deleteData(this->storeAddress);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
this->setData( NULL);
this->setData(nullptr);
return result;
}
bool TcPacketStored::checkAndSetStore() {
if (this->store == NULL) {
if (this->store == nullptr) {
this->store = objectManager->get<StorageManagerIF>(objects::TC_STORE);
if (this->store == NULL) {
if (this->store == nullptr) {
sif::error << "TcPacketStored::TcPacketStored: TC Store not found!"
<< std::endl;
return false;
@ -69,17 +71,17 @@ bool TcPacketStored::checkAndSetStore() {
void TcPacketStored::setStoreAddress(store_address_t setAddress) {
this->storeAddress = setAddress;
const uint8_t* temp_data = NULL;
const uint8_t* tempData = nullptr;
size_t temp_size;
ReturnValue_t status = StorageManagerIF::RETURN_FAILED;
if (this->checkAndSetStore()) {
status = this->store->getData(this->storeAddress, &temp_data,
status = this->store->getData(this->storeAddress, &tempData,
&temp_size);
}
if (status == StorageManagerIF::RETURN_OK) {
this->setData(temp_data);
this->setData(tempData);
} else {
this->setData(NULL);
this->setData(nullptr);
this->storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
}
}
@ -89,7 +91,7 @@ store_address_t TcPacketStored::getStoreAddress() {
}
bool TcPacketStored::isSizeCorrect() {
const uint8_t* temp_data = NULL;
const uint8_t* temp_data = nullptr;
size_t temp_size;
ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data,
&temp_size);
@ -101,8 +103,6 @@ bool TcPacketStored::isSizeCorrect() {
return false;
}
StorageManagerIF* TcPacketStored::store = NULL;
TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
TcPacketBase(data) {
if (getFullSize() != size) {
@ -111,7 +111,7 @@ TcPacketStored::TcPacketStored(const uint8_t* data, uint32_t size) :
if (this->checkAndSetStore()) {
ReturnValue_t status = store->addData(&storeAddress, data, size);
if (status != HasReturnvaluesIF::RETURN_OK) {
this->setData(NULL);
this->setData(nullptr);
}
}
}

View File

@ -1,8 +1,8 @@
#ifndef TCPACKETSTORED_H_
#define TCPACKETSTORED_H_
#ifndef TMTCPACKET_PUS_TCPACKETSTORED_H_
#define TMTCPACKET_PUS_TCPACKETSTORED_H_
#include "../../storagemanager/StorageManagerIF.h"
#include "TcPacketBase.h"
#include "../../storagemanager/StorageManagerIF.h"
/**
* This class generates a ECSS PUS Telecommand packet within a given
@ -15,26 +15,6 @@
* @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.
@ -53,20 +33,20 @@ public:
* 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.
* 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.
* This specifies the destination sub-service.
* @param sequence_count Sets the packet's Source Sequence Count field.
* @param data The data to be copied to the Application Data Field.
* @param size The amount of data to be copied.
* @param ack Set's the packet's Ack field, which specifies
* number of verification packets returned
* for this command.
*/
TcPacketStored( uint8_t service, uint8_t subservice, uint16_t apid,
TcPacketStored(uint16_t apid, uint8_t service, uint8_t subservice,
uint8_t sequence_count = 0, const uint8_t* data = nullptr,
size_t size = 0, uint8_t ack = TcPacketBase::ACK_ALL );
size_t size = 0, uint8_t ack = TcPacketBase::AckField::ACK_ALL);
/**
* Another constructor to create a TcPacket from a raw packet stream.
* Takes the data and adds it unchecked to the TcStore.
@ -110,7 +90,28 @@ public:
* store or size is incorrect.
*/
bool isSizeCorrect();
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();
};
#endif /* TCPACKETSTORED_H_ */
#endif /* TMTCPACKET_PUS_TCPACKETSTORED_H_ */

View File

@ -1,13 +1,19 @@
#include "TmPacketBase.h"
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "TmPacketBase.h"
#include "../../timemanager/CCSDSTime.h"
#include <string.h>
TmPacketBase::TmPacketBase(uint8_t* set_data) :
SpacePacketBase(set_data) {
tm_data = (TmPacketPointer*) set_data;
#include <cstring>
TimeStamperIF* TmPacketBase::timeStamper = nullptr;
object_id_t TmPacketBase::timeStamperId = 0;
TmPacketBase::TmPacketBase(uint8_t* setData) :
SpacePacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointer*>(setData);
}
TmPacketBase::~TmPacketBase() {
@ -15,25 +21,25 @@ TmPacketBase::~TmPacketBase() {
}
uint8_t TmPacketBase::getService() {
return tm_data->data_field.service_type;
return tmData->data_field.service_type;
}
uint8_t TmPacketBase::getSubService() {
return tm_data->data_field.service_subtype;
return tmData->data_field.service_subtype;
}
uint8_t* TmPacketBase::getSourceData() {
return &tm_data->data;
return &tmData->data;
}
uint16_t TmPacketBase::getSourceDataSize() {
return getPacketDataLength() - sizeof(tm_data->data_field)
return getPacketDataLength() - sizeof(tmData->data_field)
- CRC_SIZE + 1;
}
uint16_t TmPacketBase::getErrorControl() {
uint32_t size = getSourceDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tm_data->data;
uint8_t* p_to_buffer = &tmData->data;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
}
@ -47,16 +53,12 @@ void TmPacketBase::setErrorControl() {
void TmPacketBase::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tm_data = (TmPacketPointer*) p_Data;
tmData = (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;*/
sif::debug << "TmPacketBase::print: " << std::endl;
arrayprinter::print(getWholeData(), getFullSize());
}
bool TmPacketBase::checkAndSetStamper() {
@ -73,47 +75,43 @@ bool TmPacketBase::checkAndSetStamper() {
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));
return CCSDSTime::convertFromCcsds(timestamp, tmData->data_field.time,
&tempSize, sizeof(tmData->data_field.time));
}
uint8_t* TmPacketBase::getPacketTimeRaw() const{
return tm_data->data_field.time;
return tmData->data_field.time;
}
void TmPacketBase::initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, uint8_t packetSubcounter) {
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
memset(&tmData->data_field, 0, sizeof(tmData->data_field));
// NOTE: In PUS-C, the PUS Version is 2 and specified for the first 4 bits.
// 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;
// The other 4 bits of the first byte are the spacecraft time reference
// status. To change to PUS-C, set 0b00100000.
// Set CCSDS_secondary header flag to 0, version number to 001 and ack
// to 0000
tmData->data_field.version_type_ack = 0b00010000;
tmData->data_field.service_type = service;
tmData->data_field.service_subtype = subservice;
tmData->data_field.subcounter = packetSubcounter;
//Timestamp packet
if (checkAndSetStamper()) {
timeStamper->addTimeStamp(tm_data->data_field.time, sizeof(tm_data->data_field.time));
timeStamper->addTimeStamp(tmData->data_field.time,
sizeof(tmData->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);
size_t TmPacketBase::getTimestampSize() const {
return sizeof(tmData->data_field.time);
}
TimeStamperIF* TmPacketBase::timeStamper = NULL;
object_id_t TmPacketBase::timeStamperId = 0;

View File

@ -1,8 +1,8 @@
#ifndef TMPACKETBASE_H_
#define TMPACKETBASE_H_
#ifndef TMTCPACKET_PUS_TMPACKETBASE_H_
#define TMTCPACKET_PUS_TMPACKETBASE_H_
#include "../SpacePacketBase.h"
#include "../../timemanager/TimeStamperIF.h"
#include "../../tmtcpacket/SpacePacketBase.h"
#include "../../timemanager/Clock.h"
#include "../../objectmanager/SystemObjectIF.h"
@ -14,7 +14,7 @@ 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].
* for a time tag.
* @ingroup tmtcpackets
*/
struct PUSTmDataFieldHeader {
@ -40,7 +40,7 @@ struct TmPacketPointer {
/**
* This class is the basic data handler for any ECSS PUS Telemetry packet.
*
* In addition to \SpacePacketBase, the class provides methods to handle
* 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
@ -54,29 +54,27 @@ 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.
static const uint32_t TM_PACKET_MIN_SIZE = (sizeof(CCSDSPrimaryHeader) +
sizeof(PUSTmDataFieldHeader) + 2);
//! Maximum size of a TM Packet in this mission.
//! TODO: Make this dependant on a config variable.
static const uint32_t MISSION_TM_PACKET_MAX_SIZE = 2048;
//! First byte of secondary header for PUS-A packets.
//! TODO: Maybe also support PUS-C via config?
static const uint8_t VERSION_NUMBER_BYTE_PUS_A = 0b00010000;
/**
* 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 );
TmPacketBase( uint8_t* setData );
/**
* 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.
@ -106,11 +104,14 @@ public:
*/
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);
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet. This method is not protected because
* a recalculation by the user might be necessary when manipulating fields
* like the sequence count.
*/
void setErrorControl();
/**
* This getter returns the Error Control Field of the packet.
*
@ -120,35 +121,15 @@ public:
* @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.
* 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;
@ -158,7 +139,7 @@ public:
*/
uint8_t* getPacketTimeRaw() const;
uint32_t getTimestampSize() const;
size_t getTimestampSize() const;
protected:
/**
@ -167,20 +148,49 @@ protected:
*
* To be hardware-safe, all elements are of byte size.
*/
TmPacketPointer* tm_data;
TmPacketPointer* tmData;
/**
* The timeStamper is responsible for adding a timestamp to the packet.
* It is initialized lazy.
*/
static TimeStamperIF* timeStamper;
//! The ID to use when looking for a time stamper.
static object_id_t timeStamperId;
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();
/**
* 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);
/**
* 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* pData );
/**
* In case data was filled manually (almost never the case).
* @param size Size of source data (without CRC and data filed header!).
*/
void setSourceDataSize(uint16_t size);
/**
* Checks if a time stamper is available and tries to set it if not.
* @return Returns false if setting failed.
*/
bool checkAndSetStamper();
};
#endif /* TMPACKETBASE_H_ */
#endif /* TMTCPACKET_PUS_TMPACKETBASE_H_ */