bugfix for TM packet stored PUS C

This commit is contained in:
Robin Müller 2021-09-15 18:37:44 +02:00
parent bdd7d59d82
commit d986ab7720
5 changed files with 61 additions and 15 deletions

View File

@ -3,8 +3,8 @@
#include <cstring> #include <cstring>
SpacePacketBase::SpacePacketBase( const uint8_t* set_address ) { SpacePacketBase::SpacePacketBase(const uint8_t* setAddress) {
this->data = (SpacePacketPointer*) set_address; this->data = reinterpret_cast<SpacePacketPointer*>(const_cast<uint8_t*>(setAddress));
} }
SpacePacketBase::~SpacePacketBase() { SpacePacketBase::~SpacePacketBase() {
@ -15,10 +15,21 @@ uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
return (this->data->header.packet_id_h & 0b11100000) >> 5; return (this->data->header.packet_id_h & 0b11100000) >> 5;
} }
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand, ReturnValue_t SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) { bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
if(data == nullptr) {
#if FSFW_VERBOSE_LEVEL >= 1
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "SpacePacketBase::initSpacePacketHeader: Data pointer is invalid"
<< std::endl;
#else
sif::printWarning("SpacePacketBase::initSpacePacketHeader: Data pointer is invalid!\n");
#endif
#endif
return HasReturnvaluesIF::RETURN_FAILED;
}
//reset header to zero: //reset header to zero:
memset(data,0, sizeof(this->data->header) ); memset(data, 0, sizeof(this->data->header) );
//Set TC/TM bit. //Set TC/TM bit.
data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4; data->header.packet_id_h = ((isTelecommand? 1 : 0)) << 4;
//Set secondaryHeader bit //Set secondaryHeader bit
@ -27,7 +38,7 @@ void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
//Always initialize as standalone packets. //Always initialize as standalone packets.
data->header.sequence_control_h = 0b11000000; data->header.sequence_control_h = 0b11000000;
setPacketSequenceCount(sequenceCount); setPacketSequenceCount(sequenceCount);
return HasReturnvaluesIF::RETURN_OK;
} }
bool SpacePacketBase::isTelecommand( void ) { bool SpacePacketBase::isTelecommand( void ) {

View File

@ -2,6 +2,8 @@
#define FSFW_TMTCPACKET_SPACEPACKETBASE_H_ #define FSFW_TMTCPACKET_SPACEPACKETBASE_H_
#include "ccsds_header.h" #include "ccsds_header.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include <cstddef> #include <cstddef>
/** /**
@ -82,7 +84,7 @@ public:
*/ */
bool isTelecommand( void ); bool isTelecommand( void );
void initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, ReturnValue_t initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader,
uint16_t apid, uint16_t sequenceCount = 0); uint16_t apid, uint16_t sequenceCount = 0);
/** /**
* The CCSDS header provides a secondary header flag (the fifth-highest bit), * The CCSDS header provides a secondary header flag (the fifth-highest bit),

View File

@ -53,11 +53,14 @@ uint8_t* TmPacketPusC::getPacketTimeRaw() const{
} }
void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, ReturnValue_t TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId, uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId,
uint8_t timeRefField) { uint8_t timeRefField) {
//Set primary header: //Set primary header:
initSpacePacketHeader(false, true, apid); ReturnValue_t result = initSpacePacketHeader(false, true, apid);
if(result != HasReturnvaluesIF::RETURN_OK) {
return result;
}
//Set data Field Header: //Set data Field Header:
//First, set to zero. //First, set to zero.
memset(&tmData->dataField, 0, sizeof(tmData->dataField)); memset(&tmData->dataField, 0, sizeof(tmData->dataField));
@ -76,6 +79,7 @@ void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service,
timeStamper->addTimeStamp(tmData->dataField.time, timeStamper->addTimeStamp(tmData->dataField.time,
sizeof(tmData->dataField.time)); sizeof(tmData->dataField.time));
} }
return HasReturnvaluesIF::RETURN_OK;
} }
void TmPacketPusC::setSourceDataSize(uint16_t size) { void TmPacketPusC::setSourceDataSize(uint16_t size) {

View File

@ -100,7 +100,7 @@ protected:
* @param subservice PUS Subservice * @param subservice PUS Subservice
* @param packetSubcounter Additional subcounter used. * @param packetSubcounter Additional subcounter used.
*/ */
void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, ReturnValue_t initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice,
uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0); uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0);
/** /**

View File

@ -43,27 +43,56 @@ TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service,
return; return;
} }
size_t sourceDataSize = 0; size_t sourceDataSize = 0;
if (content != NULL) { if (content != nullptr) {
sourceDataSize += content->getSerializedSize(); sourceDataSize += content->getSerializedSize();
} }
if (header != NULL) { if (header != nullptr) {
sourceDataSize += header->getSerializedSize(); sourceDataSize += header->getSerializedSize();
} }
uint8_t *p_data = NULL; uint8_t *p_data = nullptr;
size_t sizeToReserve = getPacketMinimumSize() + sourceDataSize;
ReturnValue_t returnValue = store->getFreeElement(&storeAddress, ReturnValue_t returnValue = store->getFreeElement(&storeAddress,
(getPacketMinimumSize() + sourceDataSize), &p_data); sizeToReserve, &p_data);
if (returnValue != store->RETURN_OK) { if (returnValue != store->RETURN_OK) {
#if FSFW_VERBOSE_LEVEL >= 1
switch(returnValue) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
case(StorageManagerIF::DATA_STORAGE_FULL): {
sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with "
"size " << sizeToReserve << std::endl;
break;
}
case(StorageManagerIF::DATA_TOO_LARGE): {
sif::warning << "TmPacketStoredPusC::TmPacketStoredPusC: Data with size " <<
sizeToReserve << " too large" << std::endl;
break;
}
#else
case(StorageManagerIF::DATA_STORAGE_FULL): {
sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Store full for packet with "
"size %d\n", sizeToReserve);
break;
}
case(StorageManagerIF::DATA_TOO_LARGE): {
sif::printWarning("TmPacketStoredPusC::TmPacketStoredPusC: Data with size "
"%d too large\n", sizeToReserve);
break;
}
#endif
#endif
}
TmPacketStoredBase::checkAndReportLostTm(); TmPacketStoredBase::checkAndReportLostTm();
return;
} }
setData(p_data); setData(p_data);
initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField);
uint8_t *putDataHere = getSourceData(); uint8_t *putDataHere = getSourceData();
size_t size = 0; size_t size = 0;
if (header != NULL) { if (header != nullptr) {
header->serialize(&putDataHere, &size, sourceDataSize, header->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }
if (content != NULL) { if (content != nullptr) {
content->serialize(&putDataHere, &size, sourceDataSize, content->serialize(&putDataHere, &size, sourceDataSize,
SerializeIF::Endianness::BIG); SerializeIF::Endianness::BIG);
} }