2016-06-15 23:48:41 +02:00
|
|
|
#ifndef FRAMEWORK_TMSTORAGE_TMSTOREPACKETS_H_
|
|
|
|
#define FRAMEWORK_TMSTORAGE_TMSTOREPACKETS_H_
|
|
|
|
|
2020-08-13 20:53:35 +02:00
|
|
|
#include "../serialize/SerialFixedArrayListAdapter.h"
|
|
|
|
#include "../serialize/SerializeElement.h"
|
|
|
|
#include "../serialize/SerialLinkedListAdapter.h"
|
|
|
|
#include "../serialize/SerialBufferAdapter.h"
|
|
|
|
#include "../tmtcpacket/pus/TmPacketMinimal.h"
|
|
|
|
#include "../timemanager/TimeStamperIF.h"
|
|
|
|
#include "../timemanager/CCSDSTime.h"
|
|
|
|
#include "../globalfunctions/timevalOperations.h"
|
2016-06-15 23:48:41 +02:00
|
|
|
|
|
|
|
class ServiceSubservice: public SerialLinkedListAdapter<SerializeIF> {
|
|
|
|
public:
|
|
|
|
SerializeElement<uint8_t> service;
|
|
|
|
SerialFixedArrayListAdapter<uint8_t, 16> subservices;
|
|
|
|
LinkedElement<SerializeIF> linkedSubservices;
|
|
|
|
ServiceSubservice() :
|
|
|
|
SerialLinkedListAdapter<SerializeIF>(&service), linkedSubservices(
|
|
|
|
&subservices) {
|
|
|
|
service.setNext(&linkedSubservices);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
class ApidSsc: public SerializeIF {
|
|
|
|
public:
|
|
|
|
ApidSsc() :
|
|
|
|
apid(SpacePacketBase::LIMIT_APID), ssc(0) {
|
|
|
|
}
|
|
|
|
ApidSsc(uint16_t apid, uint16_t ssc) :
|
|
|
|
apid(apid), ssc(ssc) {
|
|
|
|
}
|
|
|
|
uint16_t apid;
|
|
|
|
uint16_t ssc;
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
size_t maxSize, Endianness streamEndianness) const {
|
2020-04-21 21:34:03 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter::serialize(&apid,
|
2020-04-21 22:28:43 +02:00
|
|
|
buffer, size, maxSize, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
return SerializeAdapter::serialize(&ssc, buffer, size,
|
2020-04-21 22:28:43 +02:00
|
|
|
maxSize, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
size_t getSerializedSize() const {
|
2018-07-12 16:29:32 +02:00
|
|
|
return sizeof(apid) + sizeof(ssc);
|
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
Endianness streamEndianness) {
|
2020-04-21 21:34:03 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter::deSerialize(&apid,
|
2020-04-21 22:28:43 +02:00
|
|
|
buffer, size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
return SerializeAdapter::deSerialize(&ssc, buffer, size,
|
2020-04-21 22:28:43 +02:00
|
|
|
streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-15 23:48:41 +02:00
|
|
|
class ChangeSelectionDefinition: public SerialLinkedListAdapter<SerializeIF> {
|
|
|
|
public:
|
|
|
|
SerializeElement<uint16_t> apid;
|
|
|
|
SerialFixedArrayListAdapter<ServiceSubservice, 16> serviceList;
|
|
|
|
LinkedElement<SerializeIF> linkedServiceList;
|
|
|
|
ChangeSelectionDefinition() :
|
|
|
|
SerialLinkedListAdapter<SerializeIF>(&apid), linkedServiceList(
|
|
|
|
&serviceList) {
|
|
|
|
apid.setNext(&linkedServiceList);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
class TmPacketInformation: public SerializeIF {
|
2016-06-15 23:48:41 +02:00
|
|
|
public:
|
2018-07-12 16:29:32 +02:00
|
|
|
TmPacketInformation(TmPacketMinimal* packet){
|
2016-06-15 23:48:41 +02:00
|
|
|
setContent(packet);
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
TmPacketInformation() :apid(
|
2016-06-15 23:48:41 +02:00
|
|
|
SpacePacketBase::LIMIT_APID), sourceSequenceCount(0), serviceType(
|
|
|
|
0), serviceSubtype(0), subCounter(0) {
|
|
|
|
}
|
|
|
|
void reset() {
|
|
|
|
apid = SpacePacketBase::LIMIT_APID;
|
|
|
|
sourceSequenceCount = 0;
|
|
|
|
serviceType = 0;
|
|
|
|
serviceSubtype = 0;
|
|
|
|
subCounter = 0;
|
2018-07-12 16:29:32 +02:00
|
|
|
memset(rawTimestamp, 0, sizeof(rawTimestamp));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
void setContent(TmPacketMinimal* packet) {
|
|
|
|
apid = packet->getAPID();
|
|
|
|
sourceSequenceCount = packet->getPacketSequenceCount();
|
|
|
|
serviceType = packet->getService();
|
|
|
|
serviceSubtype = packet->getSubService();
|
|
|
|
subCounter = packet->getPacketSubcounter();
|
2018-07-12 16:29:32 +02:00
|
|
|
memset(rawTimestamp, 0, sizeof(rawTimestamp));
|
|
|
|
const uint8_t* pField = NULL;
|
|
|
|
uint32_t size = 0;
|
|
|
|
ReturnValue_t result = packet->getPacketTimeRaw(&pField, &size);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (*pField == CCSDSTime::P_FIELD_CDS_SHORT
|
|
|
|
&& size <= TimeStamperIF::MISSION_TIMESTAMP_SIZE) {
|
|
|
|
//Shortcut to avoid converting CDS back and forth.
|
|
|
|
memcpy(rawTimestamp, pField, size);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
timeval time = { 0, 0 };
|
|
|
|
result = packet->getPacketTime(&time);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CCSDSTime::CDS_short cdsFormat;
|
|
|
|
result = CCSDSTime::convertToCcsds(&cdsFormat, &time);
|
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
memcpy(rawTimestamp, &cdsFormat, sizeof(cdsFormat));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
void setContent(TmPacketInformation* content) {
|
2018-07-12 16:29:32 +02:00
|
|
|
apid = content->apid;
|
|
|
|
sourceSequenceCount = content->sourceSequenceCount;
|
|
|
|
serviceType = content->serviceType;
|
|
|
|
serviceSubtype = content->serviceSubtype;
|
|
|
|
subCounter = content->subCounter;
|
|
|
|
memcpy(rawTimestamp, content->rawTimestamp, sizeof(rawTimestamp));
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
bool isValid() const {
|
2016-06-15 23:48:41 +02:00
|
|
|
return (apid < SpacePacketBase::LIMIT_APID) ? true : false;
|
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
static void reset(TmPacketInformation* packet){
|
|
|
|
packet->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isOlderThan(const TmPacketInformation* packet, const timeval* cmpTime){
|
|
|
|
if(packet->isValid()){
|
|
|
|
timeval packetTime = {0,0};
|
2020-12-22 15:49:31 +01:00
|
|
|
size_t foundlen = 0;
|
2020-12-22 15:57:43 +01:00
|
|
|
CCSDSTime::convertFromCcsds(&packetTime,&packet->rawTimestamp[0],
|
|
|
|
&foundlen,sizeof(rawTimestamp));
|
2018-07-12 16:29:32 +02:00
|
|
|
if(packetTime <= *cmpTime){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isNewerThan(const TmPacketInformation* packet, const timeval* cmpTime){
|
|
|
|
if(packet->isValid()){
|
|
|
|
timeval packetTime = {0,0};
|
2020-12-22 15:49:31 +01:00
|
|
|
size_t foundlen = 0;
|
|
|
|
CCSDSTime::convertFromCcsds(&packetTime,&packet->rawTimestamp[0],
|
2020-12-22 15:57:43 +01:00
|
|
|
&foundlen,sizeof(rawTimestamp));
|
2018-07-12 16:29:32 +02:00
|
|
|
if(packetTime >= *cmpTime){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isSmallerSSC(const TmPacketInformation* packet,const ApidSsc* compareSSC){
|
|
|
|
if(packet->isValid()){
|
|
|
|
if(packet->apid == compareSSC->apid){
|
|
|
|
if(packet->sourceSequenceCount <= compareSSC->ssc){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isLargerSSC(const TmPacketInformation* packet,const ApidSsc* compareSSC){
|
|
|
|
if(packet->isValid()){
|
|
|
|
if(packet->apid == compareSSC->apid){
|
|
|
|
if(packet->sourceSequenceCount >= compareSSC->ssc){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2018-07-12 16:29:32 +02:00
|
|
|
uint16_t getApid() const{
|
|
|
|
return apid;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t getSsc() const{
|
|
|
|
return sourceSequenceCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t getServiceType() const{
|
|
|
|
return serviceType;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t getServiceSubtype() const{
|
|
|
|
return serviceSubtype;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint8_t getSubCounter() const{
|
|
|
|
return subCounter;
|
|
|
|
}
|
|
|
|
|
|
|
|
timeval getTime() const {
|
|
|
|
timeval packetTime = {0,0};
|
2020-12-22 15:49:31 +01:00
|
|
|
size_t foundlen = 0;
|
|
|
|
CCSDSTime::convertFromCcsds(&packetTime, &this->rawTimestamp[0],
|
2020-12-22 15:57:43 +01:00
|
|
|
&foundlen, sizeof(rawTimestamp));
|
2018-07-12 16:29:32 +02:00
|
|
|
return packetTime;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator==(const TmPacketInformation& other) {
|
|
|
|
//TODO Does not compare Raw Timestamp
|
|
|
|
return ((apid == other.getApid())
|
|
|
|
&& (sourceSequenceCount == other.getSsc())
|
|
|
|
&& (serviceType == other.getServiceType()) && (serviceSubtype =
|
|
|
|
other.getServiceSubtype()));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t serialize(uint8_t** buffer, size_t* size,
|
|
|
|
size_t maxSize, Endianness streamEndianness) const {
|
|
|
|
ReturnValue_t result = SerializeAdapter::serialize(&apid,buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if(result!=HasReturnvaluesIF::RETURN_OK){
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
result = SerializeAdapter::serialize(&sourceSequenceCount,buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if(result!=HasReturnvaluesIF::RETURN_OK){
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
result = SerializeAdapter::serialize(&serviceType,buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if(result!=HasReturnvaluesIF::RETURN_OK){
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
result = SerializeAdapter::serialize(&serviceSubtype,buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if(result!=HasReturnvaluesIF::RETURN_OK){
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
result = SerializeAdapter::serialize(&subCounter,buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if(result!=HasReturnvaluesIF::RETURN_OK){
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
SerialBufferAdapter<uint8_t> adapter(rawTimestamp,sizeof(rawTimestamp));
|
2020-04-21 22:28:43 +02:00
|
|
|
return adapter.serialize(buffer,size,maxSize,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
size_t getSerializedSize() const {
|
2018-07-12 16:29:32 +02:00
|
|
|
uint32_t size = 0;
|
2020-04-21 21:34:03 +02:00
|
|
|
size += SerializeAdapter::getSerializedSize(&apid);
|
|
|
|
size += SerializeAdapter::getSerializedSize(&sourceSequenceCount);
|
|
|
|
size += SerializeAdapter::getSerializedSize(&serviceType);
|
|
|
|
size += SerializeAdapter::getSerializedSize(&serviceSubtype);
|
|
|
|
size += SerializeAdapter::getSerializedSize(&subCounter);
|
2018-07-12 16:29:32 +02:00
|
|
|
SerialBufferAdapter<uint8_t> adapter(rawTimestamp,sizeof(rawTimestamp));
|
|
|
|
size += adapter.getSerializedSize();
|
|
|
|
return size;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2020-04-21 22:28:43 +02:00
|
|
|
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
|
|
|
|
Endianness streamEndianness) {
|
2020-04-21 21:34:03 +02:00
|
|
|
ReturnValue_t result = SerializeAdapter::deSerialize(&apid, buffer,
|
2020-04-21 22:28:43 +02:00
|
|
|
size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
result = SerializeAdapter::deSerialize(&sourceSequenceCount, buffer,
|
2020-04-21 22:28:43 +02:00
|
|
|
size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
result = SerializeAdapter::deSerialize(&serviceType, buffer, size,
|
2020-04-21 22:28:43 +02:00
|
|
|
streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
result = SerializeAdapter::deSerialize(&serviceSubtype, buffer,
|
2020-04-21 22:28:43 +02:00
|
|
|
size, streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
2020-04-21 21:34:03 +02:00
|
|
|
result = SerializeAdapter::deSerialize(&subCounter, buffer, size,
|
2020-04-21 22:28:43 +02:00
|
|
|
streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (result != HasReturnvaluesIF::RETURN_OK) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
SerialBufferAdapter<uint8_t> adapter(rawTimestamp,sizeof(rawTimestamp));
|
2020-04-21 22:28:43 +02:00
|
|
|
return adapter.deSerialize(buffer,size,streamEndianness);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
uint16_t apid;
|
|
|
|
uint16_t sourceSequenceCount;
|
|
|
|
uint8_t serviceType;
|
|
|
|
uint8_t serviceSubtype;
|
|
|
|
uint8_t subCounter;
|
|
|
|
uint8_t rawTimestamp[TimeStamperIF::MISSION_TIMESTAMP_SIZE];
|
|
|
|
|
|
|
|
};
|
2016-06-15 23:48:41 +02:00
|
|
|
#endif /* FRAMEWORK_TMSTORAGE_TMSTOREPACKETS_H_ */
|