const correctness

This commit is contained in:
Robin Müller 2021-06-14 11:16:56 +02:00
parent 56d2af9d25
commit b1e3a1b2b5
No known key found for this signature in database
GPG Key ID: 71B58F8A3CDFA9AC
6 changed files with 51 additions and 38 deletions

View File

@ -72,7 +72,7 @@ void SpacePacketBase::setPacketSequenceCount( uint16_t new_count) {
this->data->header.sequence_control_l = ( (new_count%LIMIT_SEQUENCE_COUNT) & 0x00FF );
}
uint16_t SpacePacketBase::getPacketDataLength( void ) {
uint16_t SpacePacketBase::getPacketDataLength() const {
return ( (this->data->header.packet_length_h) << 8 )
+ this->data->header.packet_length_l;
}

View File

@ -138,9 +138,11 @@ public:
* Returns the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header. The packet data length is the size of every kind
* of data \b after the CCSDS Primary Header \b -1.
* @return The CCSDS packet data length.
* @return
* The CCSDS packet data length. uint16_t is sufficient,
* because this is limit in CCSDS standard
*/
uint16_t getPacketDataLength( void ); //uint16_t is sufficient, because this is limit in CCSDS standard
uint16_t getPacketDataLength(void) const;
/**
* Sets the packet data length, which is the fifth and sixth byte of the
* CCSDS Primary Header.

View File

@ -53,7 +53,7 @@ public:
* highest bit of the first byte of the Data Field Header.
* @return the CCSDS Secondary Header Flag
*/
virtual uint8_t getSecondaryHeaderFlag() = 0;
virtual uint8_t getSecondaryHeaderFlag() const = 0;
/**
* This command returns the TC Packet PUS Version Number.
* The version number of ECSS PUS 2003 is 1.
@ -61,7 +61,7 @@ public:
* first byte.
* @return
*/
virtual uint8_t getPusVersionNumber() = 0;
virtual uint8_t getPusVersionNumber() const = 0;
/**
* This is a getter for the packet's Ack field, which are the lowest four
* bits of the first byte of the Data Field Header.
@ -69,7 +69,7 @@ public:
* It is packed in a uint8_t variable.
* @return The packet's PUS Ack field.
*/
virtual uint8_t getAcknowledgeFlags() = 0;
virtual uint8_t getAcknowledgeFlags() const = 0;
/**
* This is a getter for the packet's PUS Service ID, which is the second
* byte of the Data Field Header.
@ -81,13 +81,13 @@ public:
* third byte of the Data Field Header.
* @return The packet's PUS Service Subtype.
*/
virtual uint8_t getSubService() = 0;
virtual uint8_t getSubService() const = 0;
/**
* The source ID can be used to have an additional identifier, e.g. for different ground
* station.
* @return
*/
uint8_t getSourceId();
virtual uint16_t getSourceId() const = 0;
/**
* This is a getter for a pointer to the packet's Application data.
@ -105,7 +105,7 @@ public:
* @return The size of the PUS Application Data (without Error Control
* field)
*/
virtual uint16_t getApplicationDataSize() = 0;
virtual uint16_t getApplicationDataSize() const = 0;
/**
* This getter returns the Error Control Field of the packet.
*
@ -114,7 +114,7 @@ public:
* supposed to be a 16bit-CRC.
* @return The PUS Error Control
*/
virtual uint16_t getErrorControl() = 0;
virtual uint16_t getErrorControl() const = 0;
/**
* With this method, the Error Control Field is updated to match the
* current content of the packet.
@ -126,7 +126,7 @@ public:
* @param appDataLen
* @return
*/
virtual size_t calculateFullPacketLength(size_t appDataLen) = 0;
virtual size_t calculateFullPacketLength(size_t appDataLen) const = 0;
/**
* This is a debugging helper method that prints the whole packet content

View File

@ -7,15 +7,28 @@ TcPacketPus::TcPacketPus(const uint8_t *setData): TcPacketBase(setData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(setData));
}
void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header:
// Set CCSDS_secondary_header_flag to 0 and version number to 001
tcData->dataField.versionTypeAck = 0b00010000;
tcData->dataField.versionTypeAck |= (ack & 0x0F);
tcData->dataField.serviceType = service;
tcData->dataField.serviceSubtype = subservice;
}
uint8_t TcPacketPus::getService() const {
return tcData->dataField.serviceType;
}
uint8_t TcPacketPus::getSubService() {
uint8_t TcPacketPus::getSubService() const {
return tcData->dataField.serviceSubtype;
}
uint8_t TcPacketPus::getAcknowledgeFlags() {
uint8_t TcPacketPus::getAcknowledgeFlags() const {
return tcData->dataField.versionTypeAck & 0b00001111;
}
@ -23,11 +36,11 @@ const uint8_t* TcPacketPus::getApplicationData() const {
return &tcData->appData;
}
uint16_t TcPacketPus::getApplicationDataSize() {
uint16_t TcPacketPus::getApplicationDataSize() const {
return getPacketDataLength() - sizeof(tcData->dataField) - CRC_SIZE + 1;
}
uint16_t TcPacketPus::getErrorControl() {
uint16_t TcPacketPus::getErrorControl() const {
uint16_t size = getApplicationDataSize() + CRC_SIZE;
uint8_t* p_to_buffer = &tcData->appData;
return (p_to_buffer[size - 2] << 8) + p_to_buffer[size - 1];
@ -48,28 +61,23 @@ void TcPacketPus::setData(const uint8_t* pData) {
tcData = reinterpret_cast<TcPacketPointer*>(const_cast<uint8_t*>(pData));
}
uint8_t TcPacketPus::getSecondaryHeaderFlag() {
uint8_t TcPacketPus::getSecondaryHeaderFlag() const {
return (tcData->dataField.versionTypeAck & 0b10000000) >> 7;
}
uint8_t TcPacketPus::getPusVersionNumber() {
uint8_t TcPacketPus::getPusVersionNumber() const {
return (tcData->dataField.versionTypeAck & 0b01110000) >> 4;
}
void TcPacketPus::initializeTcPacket(uint16_t apid, uint16_t sequenceCount,
uint8_t ack, uint8_t service, uint8_t subservice) {
initSpacePacketHeader(true, true, apid, sequenceCount);
std::memset(&tcData->dataField, 0, sizeof(tcData->dataField));
setPacketDataLength(sizeof(PUSTcDataFieldHeader) + CRC_SIZE - 1);
// Data Field Header:
// Set CCSDS_secondary_header_flag to 0 and version number to 001
tcData->dataField.versionTypeAck = 0b00010000;
tcData->dataField.versionTypeAck |= (ack & 0x0F);
tcData->dataField.serviceType = service;
tcData->dataField.serviceSubtype = subservice;
uint16_t TcPacketPus::getSourceId() const {
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
return (tcData->dataField.sourceIdH << 8) | tcData->dataField.sourceIdL;
#else
return tcData->dataField.sourceId;
#endif
}
size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) {
size_t TcPacketPus::calculateFullPacketLength(size_t appDataLen) const {
return sizeof(CCSDSPrimaryHeader) + sizeof(PUSTcDataFieldHeader) +
appDataLen + TcPacketBase::CRC_SIZE;
}

View File

@ -18,7 +18,8 @@ struct PUSTcDataFieldHeader {
uint8_t serviceType;
uint8_t serviceSubtype;
#if FSFW_USE_PUS_C_TELECOMMANDS == 1
uint16_t sourceId;
uint8_t sourceIdH;
uint8_t sourceIdL;
#else
uint8_t sourceId;
#endif
@ -49,16 +50,17 @@ public:
TcPacketPus(const uint8_t* setData);
// Base class overrides
virtual uint8_t getSecondaryHeaderFlag() override;
virtual uint8_t getPusVersionNumber() override;
virtual uint8_t getAcknowledgeFlags() override;
virtual uint8_t getService() const override;
virtual uint8_t getSubService() override;
uint8_t getSecondaryHeaderFlag() const override;
uint8_t getPusVersionNumber() const override;
uint8_t getAcknowledgeFlags() const override;
uint8_t getService() const override;
uint8_t getSubService() const override;
uint16_t getSourceId() const override;
const uint8_t* getApplicationData() const override;
uint16_t getApplicationDataSize() override;
uint16_t getErrorControl() override;
uint16_t getApplicationDataSize() const override;
uint16_t getErrorControl() const override;
void setErrorControl() override;
size_t calculateFullPacketLength(size_t appDataLen) override;
size_t calculateFullPacketLength(size_t appDataLen) const override;
protected:

View File

@ -259,6 +259,7 @@ void CommandingServiceBase::handleRequestQueue() {
rejectPacket(tc_verification::START_FAILURE, &packet, INVALID_SUBSERVICE);
continue;
}
result = getMessageQueueAndObject(packet.getSubService(),
packet.getApplicationData(), packet.getApplicationDataSize(),
&queue, &objectId);