TMTC Packet Base improvements #80

Merged
gaisser merged 20 commits from KSat/fsfw:mueller_tcPacketBase into master 2020-10-29 13:17:36 +01:00
3 changed files with 36 additions and 9 deletions
Showing only changes of commit 1fb87db82e - Show all commits

View File

@ -14,7 +14,8 @@ uint8_t SpacePacketBase::getPacketVersionNumber( void ) {
return (this->data->header.packet_id_h & 0b11100000) >> 5;
}
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand, bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
void SpacePacketBase::initSpacePacketHeader(bool isTelecommand,
bool hasSecondaryHeader, uint16_t apid, uint16_t sequenceCount) {
//reset header to zero:
memset(data,0, sizeof(this->data->header) );
//Set TC/TM bit.

View File

@ -28,7 +28,7 @@ const uint8_t* TcPacketBase::getApplicationData() const {
return &tcData->data;
}
uint16_t TcPacketBase::getApplicationDataSize() {
size_t TcPacketBase::getApplicationDataSize() {
return getPacketDataLength() - sizeof(tcData->data_field) - CRC_SIZE + 1;
}
@ -46,9 +46,16 @@ void TcPacketBase::setErrorControl() {
(&tcData->data)[size + 1] = (crc) & 0X00FF; // CRCL
}
void TcPacketBase::setData(const uint8_t* p_Data) {
SpacePacketBase::setData(p_Data);
tcData = (TcPacketPointer*) p_Data;
void TcPacketBase::setData(const uint8_t* pData) {
SpacePacketBase::setData(pData);
tcData = (TcPacketPointer*) pData;
}
void TcPacketBase::setApplicationData(const uint8_t * pData, size_t dataLen) {

The getter is called "getApplicationData", we should keep the names the same.

The getter is called "getApplicationData", we should keep the names the same.
SpacePacketBase::setData(pData);

As tcData->appData is only a "fake" pointer of which we are not able to check the length, this operation is dangerous and there is no warning about it. TcPacketStored is the way the user does not have to thing about that. The whole class is only intended as Parsing Helper for a existing Packet or it is hidden behind a safe operation as in TcPacketStored.

I'm not sure if we should allow setting of anything here after the constructor.
Even the setData function is interessting maybe we could make that protected as its only used in TcPacketStored.

As tcData->appData is only a "fake" pointer of which we are not able to check the length, this operation is dangerous and there is no warning about it. TcPacketStored is the way the user does not have to thing about that. The whole class is only intended as Parsing Helper for a existing Packet or it is hidden behind a safe operation as in TcPacketStored. I'm not sure if we should allow setting of anything here after the constructor. Even the setData function is interessting maybe we could make that protected as its only used in TcPacketStored.
tcData = (TcPacketPointer*) pData;
SpacePacketBase::setPacketDataLength(dataLen +
sizeof(PUSTcDataFieldHeader) + TcPacketBase::CRC_SIZE-1);
}
uint8_t TcPacketBase::getSecondaryHeaderFlag() {
@ -72,7 +79,7 @@ void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
memset(&tcData->data_field, 0, sizeof(tcData->data_field));
setPacketDataLength(sizeof(tcData->data_field) + CRC_SIZE);
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);

Bug here. I think a minus one was missing: the value is the data length field should be the actual size of the data field minus 1.

Bug here. I think a minus one was missing: the value is the data length field should be the actual size of the data field minus 1.
//Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
tcData->data_field.version_type_ack = 0b00010000;
@ -80,3 +87,8 @@ void TcPacketBase::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
tcData->data_field.service_type = service;
tcData->data_field.service_subtype = subservice;
}
size_t TcPacketBase::calculateFullPacketLength(size_t appDataLen) {
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
appDataLen + TcPacketBase::CRC_SIZE;
}

View File

@ -2,6 +2,7 @@
#define TCPACKETBASE_H_
#include <framework/tmtcpacket/SpacePacketBase.h>
#include <cstddef>
/**
* This struct defines a byte-wise structured PUS TC Data Field Header.
@ -99,7 +100,8 @@ public:
* @param service PUS Service
* @param subservice PUS Subservice
*/
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack, uint8_t service, uint8_t subservice);
void initializeTcPacket(uint16_t apid, uint16_t sequenceCount, uint8_t ack,
uint8_t service, uint8_t subservice);
/**
* This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the
@ -151,7 +153,7 @@ public:
* @return The size of the PUS Application Data (without Error Control
* field)
*/
uint16_t getApplicationDataSize();
size_t getApplicationDataSize();
/**
* This getter returns the Error Control Field of the packet.
*
@ -175,12 +177,24 @@ public:
*
* @param p_data A pointer to another PUS Telecommand Packet.
*/
void setData( const uint8_t* p_data );
void setData( const uint8_t* pData );
/**
* Set application data and corresponding length field.
* @param pData
* @param dataLen
*/
void setApplicationData(const uint8_t * pData, size_t dataLen);
/**
* This is a debugging helper method that prints the whole packet content
* to the screen.
*/
void print();
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
static size_t calculateFullPacketLength(size_t appDataLen);
};