From 65aecc356590778da5f66939d8bfe0c10226f8bb Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 3 Nov 2020 23:23:05 +0100 Subject: [PATCH] IT IS DONE --- datapoollocal/LocalDataPoolManager.cpp | 59 ++++++++++++++++--------- datapoollocal/LocalDataPoolManager.h | 4 +- housekeeping/HousekeepingPacketUpdate.h | 35 ++++++++++----- 3 files changed, 65 insertions(+), 33 deletions(-) diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 440afa238..132dc3971 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -211,30 +211,24 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( } // prepare and send update snapshot. - CommandMessage notification; timeval now; Clock::getClock_timeval(&now); CCSDSTime::CDS_short cds; CCSDSTime::convertToCcsds(&cds, &now); HousekeepingPacketUpdate updatePacket(reinterpret_cast(&cds), - sizeof(cds), owner->getDataSetHandle(receiver.dataId.sid)); + sizeof(cds), owner->getPoolObjectHandle( + receiver.dataId.localPoolId)); size_t updatePacketSize = updatePacket.getSerializedSize(); store_address_t storeId; - uint8_t *storePtr = nullptr; - ReturnValue_t result = ipcStore->getFreeElement(&storeId, - updatePacket.getSerializedSize(), &storePtr); - if (result != HasReturnvaluesIF::RETURN_OK) { + ReturnValue_t result = addUpdateToStore(updatePacket, storeId); + if(result != HasReturnvaluesIF::RETURN_OK) { return result; } - size_t serializedSize = 0; - result = updatePacket.serialize(&storePtr, &serializedSize, - updatePacketSize, SerializeIF::Endianness::MACHINE); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - HousekeepingMessage::setUpdateSnapshotSetCommand(¬ification, - receiver.dataId.sid, storeId); + + CommandMessage notification; + HousekeepingMessage::setUpdateSnapshotVariableCommand(¬ification, + receiver.dataId.localPoolId, storeId); result = hkQueue->sendMessage(receiver.destinationQueue, ¬ification); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -254,13 +248,23 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( } // prepare and send update snapshot. - CommandMessage notification; - // todo: serialize into store with timestamp. + timeval now; + Clock::getClock_timeval(&now); + CCSDSTime::CDS_short cds; + CCSDSTime::convertToCcsds(&cds, &now); + HousekeepingPacketUpdate updatePacket(reinterpret_cast(&cds), + sizeof(cds), owner->getDataSetHandle(receiver.dataId.sid)); + store_address_t storeId; - HousekeepingMessage::setUpdateSnapshotVariableCommand( - ¬ification, receiver.dataId.localPoolId, storeId); - ReturnValue_t result = hkQueue->sendMessage( - receiver.destinationQueue, ¬ification); + ReturnValue_t result = addUpdateToStore(updatePacket, storeId); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + CommandMessage notification; + HousekeepingMessage::setUpdateSnapshotSetCommand( + ¬ification, receiver.dataId.sid, storeId); + result = hkQueue->sendMessage(receiver.destinationQueue, ¬ification); if(result != HasReturnvaluesIF::RETURN_OK) { status = result; } @@ -274,6 +278,21 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( return HasReturnvaluesIF::RETURN_OK; } +ReturnValue_t LocalDataPoolManager::addUpdateToStore( + HousekeepingPacketUpdate& updatePacket, store_address_t& storeId) { + size_t updatePacketSize = updatePacket.getSerializedSize(); + uint8_t *storePtr = nullptr; + ReturnValue_t result = ipcStore->getFreeElement(&storeId, + updatePacket.getSerializedSize(), &storePtr); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + size_t serializedSize = 0; + result = updatePacket.serialize(&storePtr, &serializedSize, + updatePacketSize, SerializeIF::Endianness::MACHINE); + return result;; +} + void LocalDataPoolManager::handleChangeResetLogic( DataType type, DataId dataId, MarkChangedIF* toReset) { if(hkUpdateResetList == nullptr) { diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index a5cd0f98c..f48b14ceb 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -21,7 +21,7 @@ void setStaticFrameworkObjectIds(); } class LocalDataSetBase; - +class HousekeepingPacketUpdate; /** * @brief This class is the managing instance for the local data pool. @@ -357,6 +357,8 @@ private: ReturnValue_t& status); ReturnValue_t handleNotificationSnapshot(HkReceiver& hkReceiver, ReturnValue_t& status); + ReturnValue_t addUpdateToStore(HousekeepingPacketUpdate& updatePacket, + store_address_t& storeId); }; diff --git a/housekeeping/HousekeepingPacketUpdate.h b/housekeeping/HousekeepingPacketUpdate.h index 37d38be75..702db55ee 100644 --- a/housekeeping/HousekeepingPacketUpdate.h +++ b/housekeeping/HousekeepingPacketUpdate.h @@ -12,6 +12,7 @@ class HousekeepingPacketUpdate: public SerializeIF { public: /** + * Update packet constructor for datasets * @param timeStamp * @param timeStampSize * @param hkData @@ -19,8 +20,19 @@ public: */ HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize, LocalPoolDataSetBase* dataSetPtr): - timeStamp(timeStamp), timeStampSize(timeStampSize), - dataSetPtr(dataSetPtr) {}; + timeStamp(timeStamp), timeStampSize(timeStampSize), + updateData(dataSetPtr) {}; + + /** + * Update packet constructor for pool variables. + * @param timeStamp + * @param timeStampSize + * @param dataSetPtr + */ + HousekeepingPacketUpdate(uint8_t* timeStamp, size_t timeStampSize, + LocalPoolObjectBase* dataSetPtr): + timeStamp(timeStamp), timeStampSize(timeStampSize), + updateData(dataSetPtr) {}; virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, Endianness streamEndianness) const { @@ -31,18 +43,18 @@ public: *size += timeStampSize; *buffer += timeStampSize; } - if(dataSetPtr == nullptr) { + if(updateData == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - return dataSetPtr->serialize(buffer, size, maxSize, streamEndianness); + return updateData->serialize(buffer, size, maxSize, streamEndianness); } virtual size_t getSerializedSize() const { - if(dataSetPtr == nullptr) { + if(updateData == nullptr) { return 0; } - return timeStampSize + dataSetPtr->getSerializedSize(); + return timeStampSize + updateData->getSerializedSize(); } virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, @@ -55,19 +67,18 @@ public: *buffer += timeStampSize; } - if(dataSetPtr == nullptr) { + if(updateData == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } - return dataSetPtr->deSerialize(buffer, size, streamEndianness); + return updateData->deSerialize(buffer, size, streamEndianness); } private: - uint8_t* timeStamp; - size_t timeStampSize; + uint8_t* timeStamp = nullptr; + size_t timeStampSize = 0; - LocalPoolDataSetBase* dataSetPtr = nullptr; + SerializeIF* updateData = nullptr; }; - #endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_ */