2020-10-28 02:20:12 +01:00
|
|
|
#ifndef TMTCPACKET_PUS_TMPACKETBASE_H_
|
|
|
|
#define TMTCPACKET_PUS_TMPACKETBASE_H_
|
2016-06-15 23:48:41 +02:00
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
#include "../SpacePacketBase.h"
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../../timemanager/TimeStamperIF.h"
|
|
|
|
#include "../../timemanager/Clock.h"
|
|
|
|
#include "../../objectmanager/SystemObjectIF.h"
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
namespace Factory{
|
|
|
|
void setStaticFrameworkObjectIds();
|
|
|
|
}
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class is the basic data handler for any ECSS PUS Telemetry packet.
|
|
|
|
*
|
2020-10-28 02:20:12 +01:00
|
|
|
* In addition to #SpacePacketBase, the class provides methods to handle
|
2016-06-15 23:48:41 +02:00
|
|
|
* 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 {
|
2021-04-12 21:17:53 +02:00
|
|
|
friend void (Factory::setStaticFrameworkObjectIds)();
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2021-04-12 21:17:53 +02:00
|
|
|
|
|
|
|
//! 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;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
/**
|
2021-04-12 21:17:53 +02:00
|
|
|
* 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.
|
2020-10-28 02:20:12 +01:00
|
|
|
*/
|
2021-04-12 21:17:53 +02:00
|
|
|
TmPacketBase( uint8_t* setData );
|
|
|
|
/**
|
|
|
|
* This is the empty default destructor.
|
|
|
|
*/
|
|
|
|
virtual ~TmPacketBase();
|
2020-10-28 02:20:12 +01:00
|
|
|
|
2021-04-12 21:17:53 +02:00
|
|
|
/**
|
|
|
|
* This is a getter for the packet's PUS Service ID, which is the second
|
|
|
|
* byte of the Data Field Header.
|
|
|
|
* @return The packet's PUS Service ID.
|
|
|
|
*/
|
|
|
|
virtual uint8_t getService() = 0;
|
|
|
|
/**
|
|
|
|
* This is a getter for the packet's PUS Service Subtype, which is the
|
|
|
|
* third byte of the Data Field Header.
|
|
|
|
* @return The packet's PUS Service Subtype.
|
|
|
|
*/
|
|
|
|
virtual uint8_t getSubService() = 0;
|
|
|
|
/**
|
|
|
|
* This is a getter for a pointer to the packet's Source data.
|
|
|
|
*
|
|
|
|
* These are the bytes that follow after the Data Field Header. They form
|
|
|
|
* the packet's source data.
|
|
|
|
* @return A pointer to the PUS Source Data.
|
|
|
|
*/
|
|
|
|
virtual uint8_t* getSourceData() = 0;
|
|
|
|
/**
|
|
|
|
* This method calculates the size of the PUS Source data field.
|
|
|
|
*
|
|
|
|
* It takes the information stored in the CCSDS Packet Data Length field
|
|
|
|
* and subtracts the Data Field Header size and the CRC size.
|
|
|
|
* @return The size of the PUS Source Data (without Error Control field)
|
|
|
|
*/
|
|
|
|
virtual uint16_t getSourceDataSize() = 0;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2021-04-12 21:17:53 +02:00
|
|
|
/**
|
|
|
|
* Get size of data field which can differ based on implementation
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
virtual uint16_t getDataFieldSize() = 0;
|
|
|
|
|
|
|
|
virtual size_t getPacketMinimumSize() const = 0;
|
2018-07-12 16:29:32 +02:00
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
/**
|
2021-04-12 21:17:53 +02:00
|
|
|
* Interprets the "time"-field in the secondary header and returns it in
|
|
|
|
* timeval format.
|
|
|
|
* @return Converted timestamp of packet.
|
2020-10-28 02:20:12 +01:00
|
|
|
*/
|
2021-04-12 21:17:53 +02:00
|
|
|
virtual ReturnValue_t getPacketTime(timeval* timestamp) const = 0;
|
|
|
|
/**
|
|
|
|
* Returns a raw pointer to the beginning of the time field.
|
|
|
|
* @return Raw pointer to time field.
|
|
|
|
*/
|
|
|
|
virtual uint8_t* getPacketTimeRaw() const = 0;
|
|
|
|
|
|
|
|
virtual size_t getTimestampSize() const = 0;
|
2020-10-28 02:20:12 +01:00
|
|
|
|
|
|
|
/**
|
2021-04-12 21:17:53 +02:00
|
|
|
* This is a debugging helper method that prints the whole packet content
|
|
|
|
* to the screen.
|
|
|
|
*/
|
|
|
|
void print();
|
|
|
|
/**
|
|
|
|
* With this method, the Error Control Field is updated to match the
|
|
|
|
* current content of the packet. This method is not protected because
|
|
|
|
* a recalculation by the user might be necessary when manipulating fields
|
|
|
|
* like the sequence count.
|
|
|
|
*/
|
|
|
|
void setErrorControl();
|
|
|
|
/**
|
|
|
|
* This getter returns the Error Control Field of the packet.
|
2020-10-28 02:20:12 +01:00
|
|
|
*
|
2021-04-12 21:17:53 +02:00
|
|
|
* 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
|
2020-10-28 02:20:12 +01:00
|
|
|
*/
|
2021-04-12 21:17:53 +02:00
|
|
|
uint16_t getErrorControl();
|
2020-10-28 02:20:12 +01:00
|
|
|
|
2021-04-12 21:17:53 +02:00
|
|
|
protected:
|
2020-10-28 02:20:12 +01:00
|
|
|
/**
|
2021-04-12 21:17:53 +02:00
|
|
|
* The timeStamper is responsible for adding a timestamp to the packet.
|
|
|
|
* It is initialized lazy.
|
2020-10-28 02:20:12 +01:00
|
|
|
*/
|
2021-04-12 21:17:53 +02:00
|
|
|
static TimeStamperIF* timeStamper;
|
|
|
|
//! The ID to use when looking for a time stamper.
|
|
|
|
static object_id_t timeStamperId;
|
2020-10-28 02:20:12 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Checks if a time stamper is available and tries to set it if not.
|
|
|
|
* @return Returns false if setting failed.
|
|
|
|
*/
|
|
|
|
bool checkAndSetStamper();
|
2016-06-15 23:48:41 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2020-10-28 02:20:12 +01:00
|
|
|
#endif /* TMTCPACKET_PUS_TMPACKETBASE_H_ */
|