2021-04-12 22:24:11 +02:00
|
|
|
#include "TmPacketStoredPusA.h"
|
2020-10-28 19:44:37 +01:00
|
|
|
|
2021-06-14 10:19:01 +02:00
|
|
|
#include "../../../serviceinterface/ServiceInterface.h"
|
|
|
|
#include "../../../tmtcservices/TmTcMessage.h"
|
2020-10-28 19:44:37 +01:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2021-04-12 21:53:08 +02:00
|
|
|
TmPacketStoredPusA::TmPacketStoredPusA(store_address_t setAddress) :
|
|
|
|
TmPacketStoredBase(setAddress), TmPacketPusA(nullptr){
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:53:08 +02:00
|
|
|
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
|
2020-04-21 22:28:43 +02:00
|
|
|
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
|
|
|
|
uint32_t size, const uint8_t *headerData, uint32_t headerSize) :
|
2021-04-12 21:17:53 +02:00
|
|
|
TmPacketPusA(nullptr) {
|
2018-07-12 16:29:32 +02:00
|
|
|
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2021-04-12 21:53:08 +02:00
|
|
|
if (not TmPacketStoredBase::checkAndSetStore()) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return;
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2020-10-28 19:44:37 +01:00
|
|
|
uint8_t *pData = nullptr;
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
2021-04-12 21:17:53 +02:00
|
|
|
(getPacketMinimumSize() + size + headerSize), &pData);
|
2018-07-12 16:29:32 +02:00
|
|
|
|
|
|
|
if (returnValue != store->RETURN_OK) {
|
2021-04-12 21:53:08 +02:00
|
|
|
TmPacketStoredBase::checkAndReportLostTm();
|
2018-07-12 16:29:32 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
setData(pData);
|
|
|
|
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
|
|
|
memcpy(getSourceData(), headerData, headerSize);
|
|
|
|
memcpy(getSourceData() + headerSize, data, size);
|
|
|
|
setPacketDataLength(
|
2021-04-12 21:53:08 +02:00
|
|
|
size + headerSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:53:08 +02:00
|
|
|
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
|
2020-04-21 22:28:43 +02:00
|
|
|
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
|
|
|
|
SerializeIF *header) :
|
2021-04-12 21:17:53 +02:00
|
|
|
TmPacketPusA(nullptr) {
|
2016-06-15 23:48:41 +02:00
|
|
|
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
|
2021-04-12 22:02:16 +02:00
|
|
|
if (not TmPacketStoredBase::checkAndSetStore()) {
|
2018-07-12 16:29:32 +02:00
|
|
|
return;
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
size_t sourceDataSize = 0;
|
2018-07-12 16:29:32 +02:00
|
|
|
if (content != NULL) {
|
|
|
|
sourceDataSize += content->getSerializedSize();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
2018-07-12 16:29:32 +02:00
|
|
|
if (header != NULL) {
|
|
|
|
sourceDataSize += header->getSerializedSize();
|
|
|
|
}
|
2020-04-21 22:28:43 +02:00
|
|
|
uint8_t *p_data = NULL;
|
2018-07-12 16:29:32 +02:00
|
|
|
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
|
2021-04-12 21:17:53 +02:00
|
|
|
(getPacketMinimumSize() + sourceDataSize), &p_data);
|
2018-07-12 16:29:32 +02:00
|
|
|
if (returnValue != store->RETURN_OK) {
|
2021-04-12 21:53:08 +02:00
|
|
|
TmPacketStoredBase::checkAndReportLostTm();
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
setData(p_data);
|
|
|
|
initializeTmPacket(apid, service, subservice, packetSubcounter);
|
2020-04-21 22:28:43 +02:00
|
|
|
uint8_t *putDataHere = getSourceData();
|
|
|
|
size_t size = 0;
|
2018-07-12 16:29:32 +02:00
|
|
|
if (header != NULL) {
|
2020-04-21 22:28:43 +02:00
|
|
|
header->serialize(&putDataHere, &size, sourceDataSize,
|
|
|
|
SerializeIF::Endianness::BIG);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
if (content != NULL) {
|
2020-04-21 22:28:43 +02:00
|
|
|
content->serialize(&putDataHere, &size, sourceDataSize,
|
|
|
|
SerializeIF::Endianness::BIG);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|
|
|
|
setPacketDataLength(
|
2021-04-12 21:53:08 +02:00
|
|
|
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:53:08 +02:00
|
|
|
uint8_t* TmPacketStoredPusA::getAllTmData() {
|
|
|
|
return getWholeData();
|
2016-06-15 23:48:41 +02:00
|
|
|
}
|
|
|
|
|
2021-04-12 21:53:08 +02:00
|
|
|
void TmPacketStoredPusA::setDataPointer(const uint8_t *newPointer) {
|
|
|
|
setData(newPointer);
|
2018-07-12 16:29:32 +02:00
|
|
|
}
|