diff --git a/pus/Service17Test.cpp b/pus/Service17Test.cpp index cdd8817c2..daed987ae 100644 --- a/pus/Service17Test.cpp +++ b/pus/Service17Test.cpp @@ -1,8 +1,9 @@ #include "Service17Test.h" +#include -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "../serviceinterface/ServiceInterface.h" #include "../objectmanager/SystemObject.h" -#include "../tmtcpacket/pus/TmPacketStoredPusA.h" +#include "../tmtcpacket/pus/TmPacketStored.h" Service17Test::Service17Test(object_id_t objectId, @@ -17,15 +18,25 @@ Service17Test::~Service17Test() { ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { switch(subservice) { case Subservice::CONNECTION_TEST: { +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); +#else + TmPacketStoredPusC connectionPacket(apid, serviceId, + Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); +#endif connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); return HasReturnvaluesIF::RETURN_OK; } case Subservice::EVENT_TRIGGER_TEST: { +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); +#else + TmPacketStoredPusC connectionPacket(apid, serviceId, + Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); +#endif connectionPacket.sendPacket(requestQueue->getDefaultDestination(), requestQueue->getId()); triggerEvent(TEST, 1234, 5678); diff --git a/pus/Service1TelecommandVerification.cpp b/pus/Service1TelecommandVerification.cpp index 358d1faa5..7ef08de77 100644 --- a/pus/Service1TelecommandVerification.cpp +++ b/pus/Service1TelecommandVerification.cpp @@ -3,7 +3,7 @@ #include "../ipc/QueueFactory.h" #include "../tmtcservices/PusVerificationReport.h" -#include "../tmtcpacket/pus/TmPacketStoredPusA.h" +#include "../tmtcpacket/pus/TmPacketStored.h" #include "../serviceinterface/ServiceInterfaceStream.h" #include "../tmtcservices/AcceptsTelemetryIF.h" @@ -68,8 +68,13 @@ ReturnValue_t Service1TelecommandVerification::generateFailureReport( message->getTcSequenceControl(), message->getStep(), message->getErrorCode(), message->getParameter1(), message->getParameter2()); +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); +#else + TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), + packetSubCounter++, &report); +#endif ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId()); return result; @@ -79,8 +84,13 @@ ReturnValue_t Service1TelecommandVerification::generateSuccessReport( PusVerificationMessage *message) { SuccessReport report(message->getReportId(),message->getTcPacketId(), message->getTcSequenceControl(),message->getStep()); +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacket(apid, serviceId, message->getReportId(), packetSubCounter++, &report); +#else + TmPacketStoredPusC tmPacket(apid, serviceId, message->getReportId(), + packetSubCounter++, &report); +#endif ReturnValue_t result = tmPacket.sendPacket(tmQueue->getDefaultDestination(), tmQueue->getId()); return result; diff --git a/pus/Service5EventReporting.cpp b/pus/Service5EventReporting.cpp index f6281fe9e..62eefcb3f 100644 --- a/pus/Service5EventReporting.cpp +++ b/pus/Service5EventReporting.cpp @@ -4,7 +4,7 @@ #include "../serviceinterface/ServiceInterfaceStream.h" #include "../events/EventManagerIF.h" #include "../ipc/QueueFactory.h" -#include "../tmtcpacket/pus/TmPacketStoredPusA.h" +#include "../tmtcpacket/pus/TmPacketStored.h" Service5EventReporting::Service5EventReporting(object_id_t objectId, @@ -52,8 +52,13 @@ ReturnValue_t Service5EventReporting::generateEventReport( { EventReport report(message.getEventId(),message.getReporter(), message.getParameter1(),message.getParameter2()); +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacket(PusServiceBase::apid, PusServiceBase::serviceId, message.getSeverity(), packetSubCounter++, &report); +#else + TmPacketStoredPusC tmPacket(PusServiceBase::apid, PusServiceBase::serviceId, + message.getSeverity(), packetSubCounter++, &report); +#endif ReturnValue_t result = tmPacket.sendPacket( requestQueue->getDefaultDestination(),requestQueue->getId()); if(result != HasReturnvaluesIF::RETURN_OK) { diff --git a/tmtcpacket/pus/CMakeLists.txt b/tmtcpacket/pus/CMakeLists.txt index 747ed0702..cd4f49f17 100644 --- a/tmtcpacket/pus/CMakeLists.txt +++ b/tmtcpacket/pus/CMakeLists.txt @@ -5,6 +5,7 @@ target_sources(${LIB_FSFW_NAME} TmPacketBase.cpp TmPacketMinimal.cpp TmPacketStoredPusA.cpp + TmPacketStoredPusC.cpp TmPacketPusA.cpp TmPacketPusC.cpp TmPacketStoredBase.cpp diff --git a/tmtcpacket/pus/TmPacketPusC.cpp b/tmtcpacket/pus/TmPacketPusC.cpp index e6aa50dda..a6b4c4289 100644 --- a/tmtcpacket/pus/TmPacketPusC.cpp +++ b/tmtcpacket/pus/TmPacketPusC.cpp @@ -54,8 +54,8 @@ uint8_t* TmPacketPusC::getPacketTimeRaw() const{ } void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, - uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId = 0, - uint8_t timeRefField = 0) { + uint8_t subservice, uint16_t packetSubcounter, uint16_t destinationId, + uint8_t timeRefField) { //Set primary header: initSpacePacketHeader(false, true, apid); //Set data Field Header: @@ -67,13 +67,15 @@ void TmPacketPusC::initializeTmPacket(uint16_t apid, uint8_t service, // status. To change to PUS-C, set 0b00100000. // Set CCSDS_secondary header flag to 0, version number to 001 and ack // to 0000 + /* Only account for last 4 bytes */ + timeRefField &= 0b1111; tmData->dataField.versionTimeReferenceField = VERSION_NUMBER_BYTE | timeRefField; tmData->dataField.serviceType = service; tmData->dataField.serviceSubtype = subservice; tmData->dataField.subcounter = packetSubcounter; tmData->dataField.destinationId = destinationId; //Timestamp packet - if (checkAndSetStamper()) { + if (TmPacketBase::checkAndSetStamper()) { timeStamper->addTimeStamp(tmData->dataField.time, sizeof(tmData->dataField.time)); } diff --git a/tmtcpacket/pus/TmPacketPusC.h b/tmtcpacket/pus/TmPacketPusC.h index 975d134f7..d072d5b9c 100644 --- a/tmtcpacket/pus/TmPacketPusC.h +++ b/tmtcpacket/pus/TmPacketPusC.h @@ -73,19 +73,13 @@ public: uint16_t getSourceDataSize() override; uint16_t getDataFieldSize() override; - /** - * Interprets the "time"-field in the secondary header and returns it in - * timeval format. - * @return Converted timestamp of packet. - */ - ReturnValue_t getPacketTime(timeval* timestamp) const override; /** * Returns a raw pointer to the beginning of the time field. * @return Raw pointer to time field. */ uint8_t* getPacketTimeRaw() const override; - size_t getTimestampSize() const override; + size_t getPacketMinimumSize() const override; protected: @@ -106,7 +100,7 @@ protected: * @param packetSubcounter Additional subcounter used. */ void initializeTmPacket(uint16_t apid, uint8_t service, uint8_t subservice, - uint16_t packetSubcounter, uint16_t destinationId, uint8_t timeRefField); + uint16_t packetSubcounter, uint16_t destinationId = 0, uint8_t timeRefField = 0); /** * With this method, the packet data pointer can be redirected to another @@ -125,11 +119,6 @@ protected: */ void setSourceDataSize(uint16_t size); - /** - * Checks if a time stamper is available and tries to set it if not. - * @return Returns false if setting failed. - */ - bool checkAndSetStamper(); }; #endif /* FSFW_TMTCPACKET_PUS_TMPACKETPUSC_H_ */ diff --git a/tmtcpacket/pus/TmPacketStored.h b/tmtcpacket/pus/TmPacketStored.h index 53ef3f4dd..fadda5610 100644 --- a/tmtcpacket/pus/TmPacketStored.h +++ b/tmtcpacket/pus/TmPacketStored.h @@ -4,6 +4,7 @@ #include #if FSFW_USE_PUS_C_TELEMETRY == 1 +#include "TmPacketStoredPusC.h" #else #include "TmPacketStoredPusA.h" #endif diff --git a/tmtcpacket/pus/TmPacketStoredPusA.cpp b/tmtcpacket/pus/TmPacketStoredPusA.cpp index 4931f8d94..68102b621 100644 --- a/tmtcpacket/pus/TmPacketStoredPusA.cpp +++ b/tmtcpacket/pus/TmPacketStoredPusA.cpp @@ -1,7 +1,6 @@ #include "TmPacketStoredPusA.h" -#include "../../objectmanager/ObjectManagerIF.h" -#include "../../serviceinterface/ServiceInterfaceStream.h" +#include "../../serviceinterface/ServiceInterface.h" #include "../../tmtcservices/TmTcMessage.h" #include diff --git a/tmtcpacket/pus/TmPacketStoredPusA.h b/tmtcpacket/pus/TmPacketStoredPusA.h index aeeba2757..0cfcf0b80 100644 --- a/tmtcpacket/pus/TmPacketStoredPusA.h +++ b/tmtcpacket/pus/TmPacketStoredPusA.h @@ -1,18 +1,12 @@ #ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ #define FSFW_TMTCPACKET_PUS_TMPACKETSTORED_PUSA_H_ -#include "TmPacketBase.h" #include "TmPacketStoredBase.h" +#include "TmPacketPusA.h" #include -#include "../../tmtcpacket/pus/TmPacketPusA.h" -#include "../../serialize/SerializeIF.h" -#include "../../storagemanager/StorageManagerIF.h" -#include "../../internalError/InternalErrorReporterIF.h" -#include "../../ipc/MessageQueueSenderIF.h" - /** - * This class generates a ECSS PUS Telemetry packet within a given + * This class generates a ECSS PUS A Telemetry packet within a given * intermediate storage. * As most packets are passed between tasks with the help of a storage * anyway, it seems logical to create a Packet-In-Storage access class diff --git a/tmtcpacket/pus/TmPacketStoredPusC.cpp b/tmtcpacket/pus/TmPacketStoredPusC.cpp index bb27b80f3..f006412e2 100644 --- a/tmtcpacket/pus/TmPacketStoredPusC.cpp +++ b/tmtcpacket/pus/TmPacketStoredPusC.cpp @@ -1,2 +1,80 @@ #include "TmPacketStoredPusC.h" +#include "../../serviceinterface/ServiceInterface.h" +#include "../../tmtcservices/TmTcMessage.h" + +#include + +TmPacketStoredPusC::TmPacketStoredPusC(store_address_t setAddress) : + TmPacketStoredBase(setAddress), TmPacketPusC(nullptr){ +} + +TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, + uint8_t subservice, uint16_t packetSubcounter, const uint8_t *data, + uint32_t size, const uint8_t *headerData, uint32_t headerSize, uint16_t destinationId, + uint8_t timeRefField) : + TmPacketPusC(nullptr) { + storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + if (not TmPacketStoredBase::checkAndSetStore()) { + return; + } + uint8_t *pData = nullptr; + ReturnValue_t returnValue = store->getFreeElement(&storeAddress, + (getPacketMinimumSize() + size + headerSize), &pData); + + if (returnValue != store->RETURN_OK) { + TmPacketStoredBase::checkAndReportLostTm(); + return; + } + setData(pData); + initializeTmPacket(apid, service, subservice, packetSubcounter, destinationId, timeRefField); + memcpy(getSourceData(), headerData, headerSize); + memcpy(getSourceData() + headerSize, data, size); + setPacketDataLength( + size + headerSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); +} + +TmPacketStoredPusC::TmPacketStoredPusC(uint16_t apid, uint8_t service, + uint8_t subservice, uint16_t packetSubcounter, SerializeIF *content, + SerializeIF *header, uint16_t destinationId, uint8_t timeRefField) : + TmPacketPusC(nullptr) { + storeAddress.raw = StorageManagerIF::INVALID_ADDRESS; + if (not TmPacketStoredBase::checkAndSetStore()) { + return; + } + size_t sourceDataSize = 0; + if (content != NULL) { + sourceDataSize += content->getSerializedSize(); + } + if (header != NULL) { + sourceDataSize += header->getSerializedSize(); + } + uint8_t *p_data = NULL; + ReturnValue_t returnValue = store->getFreeElement(&storeAddress, + (getPacketMinimumSize() + sourceDataSize), &p_data); + if (returnValue != store->RETURN_OK) { + TmPacketStoredBase::checkAndReportLostTm(); + } + setData(p_data); + initializeTmPacket(apid, service, subservice, packetSubcounter); + uint8_t *putDataHere = getSourceData(); + size_t size = 0; + if (header != NULL) { + header->serialize(&putDataHere, &size, sourceDataSize, + SerializeIF::Endianness::BIG); + } + if (content != NULL) { + content->serialize(&putDataHere, &size, sourceDataSize, + SerializeIF::Endianness::BIG); + } + setPacketDataLength( + sourceDataSize + sizeof(PUSTmDataFieldHeaderPusC) + CRC_SIZE - 1); +} + +uint8_t* TmPacketStoredPusC::getAllTmData() { + return getWholeData(); +} + +void TmPacketStoredPusC::setDataPointer(const uint8_t *newPointer) { + setData(newPointer); +} diff --git a/tmtcpacket/pus/TmPacketStoredPusC.h b/tmtcpacket/pus/TmPacketStoredPusC.h index 53b39414c..83478a942 100644 --- a/tmtcpacket/pus/TmPacketStoredPusC.h +++ b/tmtcpacket/pus/TmPacketStoredPusC.h @@ -1,7 +1,64 @@ #ifndef FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ #define FSFW_TMTCPACKET_PUS_TMPACKETSTOREDPUSC_H_ +#include +#include +/** + * This class generates a ECSS PUS A Telemetry packet within a given + * intermediate storage. + * As most packets are passed between tasks with the help of a storage + * anyway, it seems logical to create a Packet-In-Storage access class + * which saves the user almost all storage handling operation. + * Packets can both be newly created with the class and be "linked" to + * packets in a store with the help of a storeAddress. + * @ingroup tmtcpackets + */ +class TmPacketStoredPusC: + public TmPacketStoredBase, + public TmPacketPusC { +public: + /** + * This is a default constructor which does not set the data pointer. + * However, it does try to set the packet store. + */ + TmPacketStoredPusC( store_address_t setAddress ); + /** + * With this constructor, new space is allocated in the packet store and + * a new PUS Telemetry Packet is created there. + * Packet Application Data passed in data is copied into the packet. + * The Application data is passed in two parts, first a header, then a + * data field. This allows building a Telemetry Packet from two separate + * data sources. + * @param apid Sets the packet's APID field. + * @param service Sets the packet's Service ID field. + * This specifies the source service. + * @param subservice Sets the packet's Service Subtype field. + * This specifies the source sub-service. + * @param packet_counter Sets the Packet counter field of this packet + * @param data The payload data to be copied to the + * Application Data Field + * @param size The amount of data to be copied. + * @param headerData The header Data of the Application field, + * will be copied in front of data + * @param headerSize The size of the headerDataF + */ + TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice, + uint16_t packetCounter = 0, const uint8_t* data = nullptr, + uint32_t size = 0, const uint8_t* headerData = nullptr, + uint32_t headerSize = 0, uint16_t destinationId = 0, uint8_t timeRefField = 0); + /** + * Another ctor to directly pass structured content and header data to the + * packet to avoid additional buffers. + */ + TmPacketStoredPusC( uint16_t apid, uint8_t service, uint8_t subservice, + uint16_t packetCounter, SerializeIF* content, + SerializeIF* header = nullptr, uint16_t destinationId = 0, uint8_t timeRefField = 0); + + uint8_t* getAllTmData() override; + void setDataPointer(const uint8_t* newPointer) override; + +}; diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index 147c87969..fbd294685 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -1,12 +1,13 @@ #include "AcceptsTelemetryIF.h" #include "CommandingServiceBase.h" #include "TmTcMessage.h" +#include #include "../tcdistribution/PUSDistributorIF.h" #include "../objectmanager/ObjectManagerIF.h" #include "../ipc/QueueFactory.h" #include "../tmtcpacket/pus/TcPacketStored.h" -#include "../tmtcpacket/pus/TmPacketStoredPusA.h" +#include "../tmtcpacket/pus/TmPacketStored.h" #include "../serviceinterface/ServiceInterface.h" object_id_t CommandingServiceBase::defaultPacketSource = objects::NO_OBJECT; @@ -293,8 +294,13 @@ void CommandingServiceBase::handleRequestQueue() { ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, const uint8_t* data, size_t dataLen, const uint8_t* headerData, size_t headerSize) { +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, data, dataLen, headerData, headerSize); +#else + TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, + this->tmPacketCounter, data, dataLen, headerData, headerSize); +#endif ReturnValue_t result = tmPacketStored.sendPacket( requestQueue->getDefaultDestination(), requestQueue->getId()); if (result == HasReturnvaluesIF::RETURN_OK) { @@ -311,8 +317,13 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, size_t size = 0; SerializeAdapter::serialize(&objectId, &pBuffer, &size, sizeof(object_id_t), SerializeIF::Endianness::BIG); +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, data, dataLen, buffer, size); +#else + TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, + this->tmPacketCounter, data, dataLen, buffer, size); +#endif ReturnValue_t result = tmPacketStored.sendPacket( requestQueue->getDefaultDestination(), requestQueue->getId()); if (result == HasReturnvaluesIF::RETURN_OK) { @@ -324,8 +335,13 @@ ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, ReturnValue_t CommandingServiceBase::sendTmPacket(uint8_t subservice, SerializeIF* content, SerializeIF* header) { +#if FSFW_USE_PUS_C_TELEMETRY == 0 TmPacketStoredPusA tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, content, header); +#else + TmPacketStoredPusC tmPacketStored(this->apid, this->service, subservice, + this->tmPacketCounter, content, header); +#endif ReturnValue_t result = tmPacketStored.sendPacket( requestQueue->getDefaultDestination(), requestQueue->getId()); if (result == HasReturnvaluesIF::RETURN_OK) { diff --git a/unittest/user/unittest/core/CatchFactory.cpp b/unittest/user/unittest/core/CatchFactory.cpp index 2c4eaf243..9afb4fdd4 100644 --- a/unittest/user/unittest/core/CatchFactory.cpp +++ b/unittest/user/unittest/core/CatchFactory.cpp @@ -1,6 +1,6 @@ +#include "CatchFactory.h" #include #include -#include "CatchFactory.h" #include #include @@ -74,7 +74,7 @@ void Factory::setStaticFrameworkObjectIds() { DeviceHandlerFailureIsolation::powerConfirmationId = objects::NO_OBJECT; - TmPacketStoredPusA::timeStamperId = objects::NO_OBJECT; + TmPacketBase::timeStamperId = objects::NO_OBJECT; }