bugfix and additional functions

This commit is contained in:
Robin Müller 2020-05-15 19:44:14 +02:00
parent 6dc05e4951
commit 1fb87db82e
3 changed files with 36 additions and 9 deletions

View File

@ -14,7 +14,8 @@ 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, 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: //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.

View File

@ -28,7 +28,7 @@ const uint8_t* TcPacketBase::getApplicationData() const {
return &tcData->data; return &tcData->data;
} }
uint16_t TcPacketBase::getApplicationDataSize() { size_t TcPacketBase::getApplicationDataSize() {
return getPacketDataLength() - sizeof(tcData->data_field) - CRC_SIZE + 1; return getPacketDataLength() - sizeof(tcData->data_field) - CRC_SIZE + 1;
} }
@ -46,9 +46,16 @@ void TcPacketBase::setErrorControl() {
(&tcData->data)[size + 1] = (crc) & 0X00FF; // CRCL (&tcData->data)[size + 1] = (crc) & 0X00FF; // CRCL
} }
void TcPacketBase::setData(const uint8_t* p_Data) { void TcPacketBase::setData(const uint8_t* pData) {
SpacePacketBase::setData(p_Data); SpacePacketBase::setData(pData);
tcData = (TcPacketPointer*) p_Data; tcData = (TcPacketPointer*) pData;
}
void TcPacketBase::setApplicationData(const uint8_t * pData, size_t dataLen) {
SpacePacketBase::setData(pData);
tcData = (TcPacketPointer*) pData;
SpacePacketBase::setPacketDataLength(dataLen +
sizeof(PUSTcDataFieldHeader) + TcPacketBase::CRC_SIZE-1);
} }
uint8_t TcPacketBase::getSecondaryHeaderFlag() { 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) { uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount); initSpacePacketHeader(true, true, apid, sequenceCount);
memset(&tcData->data_field, 0, sizeof(tcData->data_field)); memset(&tcData->data_field, 0, sizeof(tcData->data_field));
setPacketDataLength(sizeof(tcData->data_field) + CRC_SIZE); setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
//Data Field Header: //Data Field Header:
//Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000 //Set CCSDS_secondary_header_flag to 0, version number to 001 and ack to 0000
tcData->data_field.version_type_ack = 0b00010000; 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_type = service;
tcData->data_field.service_subtype = subservice; 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_ #define TCPACKETBASE_H_
#include <framework/tmtcpacket/SpacePacketBase.h> #include <framework/tmtcpacket/SpacePacketBase.h>
#include <cstddef>
/** /**
* This struct defines a byte-wise structured PUS TC Data Field Header. * This struct defines a byte-wise structured PUS TC Data Field Header.
@ -99,7 +100,8 @@ public:
* @param service PUS Service * @param service PUS Service
* @param subservice PUS Subservice * @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. * This command returns the CCSDS Secondary Header Flag.
* It shall always be zero for PUS Packets. This is the * 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 * @return The size of the PUS Application Data (without Error Control
* field) * field)
*/ */
uint16_t getApplicationDataSize(); size_t getApplicationDataSize();
/** /**
* This getter returns the Error Control Field of the packet. * 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. * @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 * This is a debugging helper method that prints the whole packet content
* to the screen. * to the screen.
*/ */
void print(); void print();
/**
* Calculate full packet length from application data length.
* @param appDataLen
* @return
*/
static size_t calculateFullPacketLength(size_t appDataLen);
}; };