fsfw/tmtcpacket/pus/TmPacketStored.cpp

81 lines
2.5 KiB
C++
Raw Normal View History

2020-10-28 19:44:37 +01:00
#include "TmPacketStored.h"
2020-08-13 20:53:35 +02:00
#include "../../objectmanager/ObjectManagerIF.h"
#include "../../serviceinterface/ServiceInterfaceStream.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){
}
2021-04-12 21:53:08 +02:00
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, const uint8_t *data,
uint32_t size, const uint8_t *headerData, uint32_t headerSize) :
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
2021-04-12 21:53:08 +02:00
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
2020-10-28 19:44:37 +01:00
uint8_t *pData = nullptr;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + size + headerSize), &pData);
if (returnValue != store->RETURN_OK) {
2021-04-12 21:53:08 +02:00
TmPacketStoredBase::checkAndReportLostTm();
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);
}
2021-04-12 21:53:08 +02:00
TmPacketStoredPusA::TmPacketStoredPusA(uint16_t apid, uint8_t service,
uint8_t subservice, uint8_t packetSubcounter, SerializeIF *content,
SerializeIF *header) :
TmPacketPusA(nullptr) {
storeAddress.raw = StorageManagerIF::INVALID_ADDRESS;
2021-04-12 22:02:16 +02:00
if (not TmPacketStoredBase::checkAndSetStore()) {
return;
}
size_t sourceDataSize = 0;
if (content != NULL) {
sourceDataSize += content->getSerializedSize();
}
if (header != NULL) {
sourceDataSize += header->getSerializedSize();
}
uint8_t *p_data = NULL;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + sourceDataSize), &p_data);
if (returnValue != store->RETURN_OK) {
2021-04-12 21:53:08 +02:00
TmPacketStoredBase::checkAndReportLostTm();
}
setData(p_data);
initializeTmPacket(apid, service, subservice, packetSubcounter);
uint8_t *putDataHere = getSourceData();
size_t size = 0;
if (header != NULL) {
header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
if (content != NULL) {
content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG);
}
setPacketDataLength(
2021-04-12 21:53:08 +02:00
sourceDataSize + sizeof(PUSTmDataFieldHeaderPusA) + CRC_SIZE - 1);
}
2021-04-12 21:53:08 +02:00
uint8_t* TmPacketStoredPusA::getAllTmData() {
return getWholeData();
}
2021-04-12 21:53:08 +02:00
void TmPacketStoredPusA::setDataPointer(const uint8_t *newPointer) {
setData(newPointer);
}