From b1e3a1b2b586809e45b0a741f9e62fc1d2125093 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 14 Jun 2021 11:16:56 +0200 Subject: [PATCH] const correctness --- tmtcpacket/SpacePacketBase.cpp | 2 +- tmtcpacket/SpacePacketBase.h | 6 ++-- tmtcpacket/pus/tc/TcPacketBase.h | 16 +++++----- tmtcpacket/pus/tc/TcPacketPus.cpp | 44 +++++++++++++++----------- tmtcpacket/pus/tc/TcPacketPus.h | 20 ++++++------ tmtcservices/CommandingServiceBase.cpp | 1 + 6 files changed, 51 insertions(+), 38 deletions(-) diff --git a/tmtcpacket/SpacePacketBase.cpp b/tmtcpacket/SpacePacketBase.cpp index e13af8d06..14198027d 100644 --- a/tmtcpacket/SpacePacketBase.cpp +++ b/tmtcpacket/SpacePacketBase.cpp @@ -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; } diff --git a/tmtcpacket/SpacePacketBase.h b/tmtcpacket/SpacePacketBase.h index 19cbd0741..13cb31308 100644 --- a/tmtcpacket/SpacePacketBase.h +++ b/tmtcpacket/SpacePacketBase.h @@ -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. diff --git a/tmtcpacket/pus/tc/TcPacketBase.h b/tmtcpacket/pus/tc/TcPacketBase.h index f29f9b35d..68f088963 100644 --- a/tmtcpacket/pus/tc/TcPacketBase.h +++ b/tmtcpacket/pus/tc/TcPacketBase.h @@ -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 diff --git a/tmtcpacket/pus/tc/TcPacketPus.cpp b/tmtcpacket/pus/tc/TcPacketPus.cpp index 7a184f3c6..1df61c079 100644 --- a/tmtcpacket/pus/tc/TcPacketPus.cpp +++ b/tmtcpacket/pus/tc/TcPacketPus.cpp @@ -7,15 +7,28 @@ TcPacketPus::TcPacketPus(const uint8_t *setData): TcPacketBase(setData) { tcData = reinterpret_cast(const_cast(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(const_cast(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; } diff --git a/tmtcpacket/pus/tc/TcPacketPus.h b/tmtcpacket/pus/tc/TcPacketPus.h index fb8483c52..b50b868d2 100644 --- a/tmtcpacket/pus/tc/TcPacketPus.h +++ b/tmtcpacket/pus/tc/TcPacketPus.h @@ -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: diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index b416ffbe1..307a2a982 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -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);