fsfw/tmtcpacket/pus/TmPacketPusC.cpp

88 lines
2.5 KiB
C++
Raw Normal View History

#include "TmPacketPusC.h"
2021-04-12 23:55:33 +02:00
#include "TmPacketBase.h"
2021-04-12 23:55:33 +02:00
#include "../../globalfunctions/CRC.h"
#include "../../globalfunctions/arrayprinter.h"
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.h"
#include "../../timemanager/CCSDSTime.h"
#include <cstring>
TmPacketPusC::TmPacketPusC(uint8_t* setData) : TmPacketBase(setData) {
tmData = reinterpret_cast<TmPacketPointerPusC*>(setData);
}
TmPacketPusC::~TmPacketPusC() {
//Nothing to do.
}
uint8_t TmPacketPusC::getService() {
return tmData->dataField.serviceType;
}
uint8_t TmPacketPusC::getSubService() {
return tmData->dataField.serviceSubtype;
}
uint8_t* TmPacketPusC::getSourceData() {
return &tmData->data;
}
uint16_t TmPacketPusC::getSourceDataSize() {
return getPacketDataLength() - sizeof(tmData->dataField) - CRC_SIZE + 1;
}
void TmPacketPusC::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tmData = (TmPacketPointerPusC*) p_Data;
}
size_t TmPacketPusC::getPacketMinimumSize() const {
return TM_PACKET_MIN_SIZE;
}
uint16_t TmPacketPusC::getDataFieldSize() {
return sizeof(PUSTmDataFieldHeaderPusC);
}
uint8_t* TmPacketPusC::getPacketTimeRaw() const{
return tmData->dataField.time;
}
void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
2021-04-13 00:19:09 +02:00
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) {
2021-04-12 23:55:33 +02:00
//Set primary header:
initSpacePacketHeader(false, true, apid);
//Set data Field Header:
//First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField));
2021-04-15 10:07:39 +02:00
/* Only account for last 4 bytes for time reference field */
2021-04-13 00:19:09 +02:00
timeRefField &= 0b1111;
2021-04-12 23:55:33 +02:00
tmData->dataField.versionTimeReferenceField = VERSION_NUMBER_BYTE | timeRefField;
tmData->dataField.serviceType = service;
tmData->dataField.serviceSubtype = subservice;
2021-04-13 01:24:26 +02:00
tmData->dataField.subcounterMsb = packetSubcounter << 8 & 0xff;
tmData->dataField.subcounterLsb = packetSubcounter & 0xff;
tmData->dataField.destinationIdMsb = destinationId << 8 & 0xff;
tmData->dataField.destinationIdLsb = destinationId & 0xff;
2021-04-12 23:55:33 +02:00
//Timestamp packet
2021-04-13 00:19:09 +02:00
if (TmPacketBase::checkAndSetStamper()) {
2021-04-12 23:55:33 +02:00
timeStamper->addTimeStamp(tmData->dataField.time,
sizeof(tmData->dataField.time));
}
}
void TmPacketPusC::setSourceDataSize(uint16_t size) {
setPacketDataLength(size + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1);
}
size_t TmPacketPusC::getTimestampSize() const {
return sizeof(tmData->dataField.time);
}