diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 77851904..17c7ad1d 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -35,7 +35,7 @@ LocalDataPoolManager::LocalDataPoolManager(HasLocalDataPoolIF* owner, AcceptsHkPacketsIF* hkPacketReceiver = objectManager->get(defaultHkDestination); if(hkPacketReceiver != nullptr) { - defaultHkDestinationId = hkPacketReceiver->getHkQueue(); + hkDestinationId = hkPacketReceiver->getHkQueue(); } } } @@ -78,9 +78,6 @@ ReturnValue_t LocalDataPoolManager::initializeHousekeepingPoolEntriesOnce() { ReturnValue_t LocalDataPoolManager::performHkOperation() { for(auto& hkReceiversIter: hkReceiversMap) { HkReceiver* receiver = &hkReceiversIter.second; - if(not receiver->reportingEnabled) { - return HasReturnvaluesIF::RETURN_OK; - } switch(receiver->reportingType) { case(ReportingType::PERIODIC): { @@ -118,7 +115,7 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, hkReceiver.dataId.dataSetSid = sid; hkReceiver.reportingType = ReportingType::PERIODIC; hkReceiver.destinationQueue = hkReceiverObject->getHkQueue(); - hkReceiver.reportingEnabled = enableReporting; + if(not isDiagnostics) { hkReceiver.hkParameter.collectionIntervalTicks = intervalSecondsToInterval(isDiagnostics, collectionInterval * @@ -129,7 +126,13 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, intervalSecondsToInterval(isDiagnostics, collectionInterval); } - hkReceiver.isDiagnostics = isDiagnostics; + LocalPoolDataSetBase* dataSet = dynamic_cast( + owner->getDataSetHandle(sid)); + if(dataSet != nullptr) { + dataSet->setReportingEnabled(enableReporting); + dataSet->setIsDiagnostic(isDiagnostics); + } + hkReceiver.intervalCounter = 1; hkReceiversMap.emplace(packetDestination, hkReceiver); @@ -139,16 +142,51 @@ ReturnValue_t LocalDataPoolManager::subscribeForPeriodicPacket(sid_t sid, ReturnValue_t LocalDataPoolManager::handleHousekeepingMessage( CommandMessage* message) { Command_t command = message->getCommand(); + sid_t sid = HousekeepingMessage::getSid(message); switch(command) { + case(HousekeepingMessage::ENABLE_PERIODIC_DIAGNOSTICS_GENERATION): + return togglePeriodicGeneration(sid, true, true); + case(HousekeepingMessage::DISABLE_PERIODIC_DIAGNOSTICS_GENERATION): + return togglePeriodicGeneration(sid, false, true); + case(HousekeepingMessage::ENABLE_PERIODIC_HK_REPORT_GENERATION): + return togglePeriodicGeneration(sid, true, false); + case(HousekeepingMessage::DISABLE_PERIODIC_HK_REPORT_GENERATION): + return togglePeriodicGeneration(sid, false, false); + case(HousekeepingMessage::REPORT_DIAGNOSTICS_REPORT_STRUCTURES): case(HousekeepingMessage::REPORT_HK_REPORT_STRUCTURES): - //return generateSetStructurePacket(message->getSid()); + return generateSetStructurePacket(sid); + + case(HousekeepingMessage::MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL): + case(HousekeepingMessage::MODIFY_PARAMETER_REPORT_COLLECTION_INTERVAL): { + float newCollIntvl = 0; + HousekeepingMessage::getCollectionIntervalModificationCommand(message, + &newCollIntvl); + if(command == HousekeepingMessage:: + MODIFY_DIAGNOSTICS_REPORT_COLLECTION_INTERVAL) { + return changeCollectionInterval(sid, newCollIntvl, true); + } + else { + return changeCollectionInterval(sid, newCollIntvl, false); + } + } + case(HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT): - return generateHousekeepingPacket(HousekeepingMessage::getSid(message), - false, true); - case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): - return generateHousekeepingPacket(HousekeepingMessage::getSid(message), - true, true); + case(HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT): { + LocalPoolDataSetBase* dataSet = dynamic_cast( + owner->getDataSetHandle(sid)); + if(command == HousekeepingMessage::GENERATE_ONE_PARAMETER_REPORT + and dataSet->getIsDiagnostics()) { + return WRONG_HK_PACKET_TYPE; + } + else if(command == HousekeepingMessage::GENERATE_ONE_DIAGNOSTICS_REPORT + and not dataSet->getIsDiagnostics()) { + return WRONG_HK_PACKET_TYPE; + } + return generateHousekeepingPacket(HousekeepingMessage::getSid(message), + dataSet, true); + } + default: return CommandMessageIF::UNKNOWN_COMMAND; } @@ -175,17 +213,17 @@ const HasLocalDataPoolIF* LocalDataPoolManager::getOwner() const { } ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, - bool isDiagnostics, bool forDownlink, MessageQueueId_t destination) { - LocalPoolDataSetBase* dataSetToSerialize = - dynamic_cast(owner->getDataSetHandle(sid)); - if(dataSetToSerialize == nullptr) { + LocalPoolDataSetBase* dataSet, bool forDownlink, + MessageQueueId_t destination) { + if(dataSet == nullptr) { + // Configuration error. sif::warning << "HousekeepingManager::generateHousekeepingPacket:" " Set ID not found or dataset not assigned!" << std::endl; return HasReturnvaluesIF::RETURN_FAILED; } store_address_t storeId; - HousekeepingPacketDownlink hkPacket(sid, dataSetToSerialize); + HousekeepingPacketDownlink hkPacket(sid, dataSet); size_t serializedSize = 0; ReturnValue_t result = serializeHkPacketIntoStore(hkPacket, storeId, forDownlink, &serializedSize); @@ -195,7 +233,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, // and now we set a HK message and send it the HK packet destination. CommandMessage hkMessage; - if(isDiagnostics) { + if(dataSet->getIsDiagnostics()) { HousekeepingMessage::setHkDiagnosticsReply(&hkMessage, sid, storeId); } else { @@ -206,11 +244,11 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, return QUEUE_OR_DESTINATION_NOT_SET; } if(destination == MessageQueueIF::NO_QUEUE) { - if(defaultHkDestinationId == MessageQueueIF::NO_QUEUE) { + if(hkDestinationId == MessageQueueIF::NO_QUEUE) { // error, all destinations invalid return HasReturnvaluesIF::RETURN_FAILED; } - destination = defaultHkDestinationId; + destination = hkDestinationId; } return hkQueue->sendMessage(destination, &hkMessage); @@ -273,8 +311,15 @@ void LocalDataPoolManager::setNonDiagnosticIntervalFactor( void LocalDataPoolManager::performPeriodicHkGeneration(HkReceiver* receiver) { if(receiver->intervalCounter >= receiver->hkParameter.collectionIntervalTicks) { + sid_t sid = receiver->dataId.dataSetSid; + LocalPoolDataSetBase* dataSet = dynamic_cast( + owner->getDataSetHandle(sid)); + if(not dataSet->getReportingEnabled()) { + return; + } + ReturnValue_t result = generateHousekeepingPacket( - receiver->dataId.dataSetSid, receiver->isDiagnostics, true); + sid, dataSet, true); if(result != HasReturnvaluesIF::RETURN_OK) { // configuration error sif::debug << "LocalDataPoolManager::performHkOperation:" @@ -312,3 +357,43 @@ float LocalDataPoolManager::intervalToIntervalSeconds(bool isDiagnostics, regularMinimumInterval); } } + +ReturnValue_t LocalDataPoolManager::togglePeriodicGeneration(sid_t sid, + bool enable, bool isDiagnostics) { + LocalPoolDataSetBase* dataSet = dynamic_cast( + owner->getDataSetHandle(sid)); + if((dataSet->getIsDiagnostics() and not isDiagnostics) or + (not dataSet->getIsDiagnostics() and isDiagnostics)) { + return WRONG_HK_PACKET_TYPE; + } + + if((dataSet->getReportingEnabled() and enable) or + (not dataSet->getReportingEnabled() and not enable)) { + return REPORTING_STATUS_UNCHANGED; + } + + dataSet->setReportingEnabled(enable); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t LocalDataPoolManager::changeCollectionInterval(sid_t sid, + float newCollectionInterval, bool isDiagnostics) { + LocalPoolDataSetBase* dataSet = dynamic_cast( + owner->getDataSetHandle(sid)); + bool targetIsDiagnostics = dataSet->getIsDiagnostics(); + if((targetIsDiagnostics and not isDiagnostics) or + (not targetIsDiagnostics and isDiagnostics)) { + return WRONG_HK_PACKET_TYPE; + } + + for(auto& receiver: hkReceiversMap) { + if(receiver.second.reportingType != ReportingType::PERIODIC) { + continue; + } + + uint32_t newInterval = intervalSecondsToInterval(isDiagnostics, + newCollectionInterval); + receiver.second.hkParameter.collectionIntervalTicks = newInterval; + } + return HasReturnvaluesIF::RETURN_OK; +} diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index 1ab08903..559b8cc2 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -23,7 +23,7 @@ class LocalDataSetBase; /** - * @brief This class is the managing instance for local data pool. + * @brief This class is the managing instance for the local data pool. * @details * The actual data pool structure is a member of this class. Any class which * has a local data pool shall have this class as a member and implement @@ -37,7 +37,7 @@ class LocalDataSetBase; * value is stored. The helper classes offer a read() and commit() interface * through the PoolVariableIF which is used to read and update values. * Each pool entry has a valid state too. - * @author R. Mueller + * @author R. Mueller */ class LocalDataPoolManager { template @@ -49,11 +49,13 @@ class LocalDataPoolManager { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; - static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x0); - static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x1); + static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x00); + static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x01); - static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x2); + static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x02); + static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(0x03); + static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(0x04); /** * This constructor is used by a class which wants to implement * a personal local data pool. The queueToUse can be supplied if it @@ -110,8 +112,8 @@ public: * @return */ ReturnValue_t generateHousekeepingPacket(sid_t sid, - bool isDiagnostics, bool forDownlink, - MessageQueueId_t destination = MessageQueueIF::NO_QUEUE); + LocalPoolDataSetBase* dataSet, bool forDownlink, + MessageQueueId_t destination = MessageQueueIF::NO_QUEUE); ReturnValue_t generateSetStructurePacket(sid_t sid); ReturnValue_t handleHousekeepingMessage(CommandMessage* message); @@ -169,7 +171,7 @@ private: /** Default receiver for periodic HK packets */ static object_id_t defaultHkDestination; - MessageQueueId_t defaultHkDestinationId = MessageQueueIF::NO_QUEUE; + MessageQueueId_t hkDestinationId = MessageQueueIF::NO_QUEUE; /** The data pool manager will keep an internal map of HK receivers. */ struct HkReceiver { @@ -185,8 +187,11 @@ private: DataId dataId; ReportingType reportingType = ReportingType::PERIODIC; + // SHOULDDO: it would be nice to also have the object ID instead of + // a queue (or in addition).. but the FSFW is not ready for that yet. + // Also, an object can have multiple queues. MessageQueueId_t destinationQueue = MessageQueueIF::NO_QUEUE; - bool reportingEnabled = true; + /** Different members of this union will be used depending on reporting type */ union HkParameter { @@ -196,7 +201,6 @@ private: bool hkDataChanged; }; HkParameter hkParameter; - bool isDiagnostics; /** General purpose counter which is used for periodic generation. */ uint32_t intervalCounter; }; @@ -245,7 +249,6 @@ private: template ReturnValue_t fetchPoolEntry(lp_id_t localPoolId, PoolEntry **poolEntry); - void setMinimalSamplingFrequency(float frequencySeconds); ReturnValue_t serializeHkPacketIntoStore( HousekeepingPacketDownlink& hkPacket, store_address_t& storeId, bool forDownlink, size_t* serializedSize); @@ -256,6 +259,10 @@ private: uint32_t collectionInterval); void performPeriodicHkGeneration(HkReceiver* hkReceiver); + ReturnValue_t togglePeriodicGeneration(sid_t sid, bool enable, + bool isDiagnostics); + ReturnValue_t changeCollectionInterval(sid_t sid, + float newCollectionInterval, bool isDiagnostics); }; diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index 859f1f2c..362e8981 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -175,6 +175,22 @@ void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const { *byte |= 1 << shiftNumber; } +void LocalPoolDataSetBase::setIsDiagnostic(bool isDiagnostics) { + this->isDiagnostics = isDiagnostics; +} + +bool LocalPoolDataSetBase::getIsDiagnostics() const { + return isDiagnostics; +} + +void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) { + this->reportingEnabled = reportingEnabled; +} + +bool LocalPoolDataSetBase::getReportingEnabled() const { + return reportingEnabled; +} + bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte, uint8_t position) const { if(position > 7) { diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 17c20d4f..69c71d5a 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -32,6 +32,7 @@ class LocalDataPoolManager; * @ingroup data_pool */ class LocalPoolDataSetBase: public PoolDataSetBase { + friend class LocalDataPoolManager; public: /** * @brief Constructor for the creator of local pool data. @@ -97,11 +98,23 @@ public: * If this is true, all contained datasets will also be set recursively. */ void setValidity(bool valid, bool setEntriesRecursively); - bool isValid() const override; + void setIsDiagnostic(bool diagnostics); + bool getIsDiagnostics() const; + protected: sid_t sid; + + bool isDiagnostics = false; + + void setReportingEnabled(bool enabled); + bool getReportingEnabled() const; + /** + * Used for periodic generation. + */ + bool reportingEnabled = false; + /** * If the valid state of a dataset is always relevant to the whole * data set we can use this flag. diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index 7107bffe..6047342e 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -38,13 +38,14 @@ public: * @param poolId ID of the local pool entry. * @param hkOwner Pointer of the owner. This will generally be the calling * class itself which passes "this". - * @param setReadWriteMode Specify the read-write mode of the pool variable. * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. + * @param setReadWriteMode Specify the read-write mode of the pool variable. + */ LocalPoolVar(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, - DataSetIF* dataSet = nullptr); + DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); /** * This constructor is used by data users like controllers to have @@ -58,13 +59,14 @@ public: * the pool variable in that dataset directly. * @param poolId ID of the local pool entry. * @param hkOwner object ID of the pool owner. - * @param setReadWriteMode Specify the read-write mode of the pool variable. * @param dataSet The data set in which the variable shall register itself. * If nullptr, the variable is not registered. + * @param setReadWriteMode Specify the read-write mode of the pool variable. + * */ LocalPoolVar(lp_id_t poolId, object_id_t poolOwner, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, - DataSetIF* dataSet = nullptr); + DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); virtual~ LocalPoolVar() {}; diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index 6e6f27aa..09d10acc 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -7,8 +7,8 @@ template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, - HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, - DataSetIF* dataSet): + HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode): localPoolId(poolId),readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " @@ -27,7 +27,7 @@ inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, template inline LocalPoolVar::LocalPoolVar(lp_id_t poolId, object_id_t poolOwner, - pool_rwm_t setReadWriteMode, DataSetIF *dataSet): + DataSetIF *dataSet, pool_rwm_t setReadWriteMode): readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " diff --git a/datapoollocal/LocalPoolVector.h b/datapoollocal/LocalPoolVector.h index 86705bb0..69df192c 100644 --- a/datapoollocal/LocalPoolVector.h +++ b/datapoollocal/LocalPoolVector.h @@ -47,8 +47,9 @@ public: * If nullptr, the variable is not registered. */ LocalPoolVector(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, - DataSetIF* dataSet = nullptr); + DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE + ); /** * This constructor is used by data users like controllers to have @@ -65,8 +66,9 @@ public: * If nullptr, the variable is not registered. */ LocalPoolVector(lp_id_t poolId, object_id_t poolOwner, - pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE, - DataSetIF* dataSet = nullptr); + DataSetIF* dataSet = nullptr, + pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE + ); /** * @brief This is the local copy of the data pool entry. diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 7c3d2c1e..2aa6fbb5 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -7,14 +7,14 @@ template inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, - HasLocalDataPoolIF* hkOwner, pool_rwm_t setReadWriteMode, - DataSetIF* dataSet) : + HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, + pool_rwm_t setReadWriteMode): localPoolId(poolId), valid(false), readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " - "NO_PARAMETER value!" << std::endl; + sif::warning << "LocalPoolVector: PoolVariableIF::NO_PARAMETER passed " + << "as pool ID, which is the NO_PARAMETER value!" << std::endl; } - memset(this->value, 0, vectorSize * sizeof(T)); + std::memset(this->value, 0, vectorSize * sizeof(T)); hkManager = hkOwner->getHkManagerHandle(); if (dataSet != nullptr) { dataSet->registerVariable(this); @@ -23,17 +23,18 @@ inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, template inline LocalPoolVector::LocalPoolVector(lp_id_t poolId, - object_id_t poolOwner, pool_rwm_t setReadWriteMode, DataSetIF *dataSet): - readWriteMode(readWriteMode) { + object_id_t poolOwner, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): + readWriteMode(setReadWriteMode) { if(poolId == PoolVariableIF::NO_PARAMETER) { - sif::warning << "LocalPoolVector: 0 passed as pool ID, which is the " - "NO_PARAMETER value!" << std::endl; + sif::warning << "LocalPoolVector: PoolVariableIF::NO_PARAMETER passed " + << "as pool ID, which is the NO_PARAMETER value!" << std::endl; } HasLocalDataPoolIF* hkOwner = objectManager->get(poolOwner); if(hkOwner == nullptr) { - sif::error << "LocalPoolVariable: The supplied pool owner did not implement" - "the correct interface HasHkPoolParametersIF!" << std::endl; + sif::error << "LocalPoolVariable: The supplied pool owner did not " + << "implement the correct interface HasHkPoolParametersIF!" + << std::endl; return; } hkManager = hkOwner->getHkManagerHandle(); @@ -67,7 +68,7 @@ inline ReturnValue_t LocalPoolVector::readWithoutLock() { std::dec << " failed." << std::endl; return result; } - memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); + std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); this->valid = poolEntry->valid; return RETURN_OK; } @@ -96,7 +97,7 @@ inline ReturnValue_t LocalPoolVector::commitWithoutLock() { std::dec << " failed.\n" << std::flush; return result; } - memcpy(poolEntry->address, this->value, poolEntry->getByteSize()); + std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize()); poolEntry->valid = this->valid; return RETURN_OK; } diff --git a/globalfunctions/PeriodicOperationDivider.cpp b/globalfunctions/PeriodicOperationDivider.cpp index ad3b8bbd..28e98feb 100644 --- a/globalfunctions/PeriodicOperationDivider.cpp +++ b/globalfunctions/PeriodicOperationDivider.cpp @@ -7,16 +7,26 @@ PeriodicOperationDivider::PeriodicOperationDivider(uint32_t divider, } bool PeriodicOperationDivider::checkAndIncrement() { - if(counter >= divider) { + bool opNecessary = check(); + if(opNecessary) { if(resetAutomatically) { counter = 0; } - return true; + return opNecessary; } counter ++; + return opNecessary; +} + +bool PeriodicOperationDivider::check() { + if(counter >= divider) { + return true; + } return false; } + + void PeriodicOperationDivider::resetCounter() { counter = 0; } diff --git a/globalfunctions/PeriodicOperationDivider.h b/globalfunctions/PeriodicOperationDivider.h index dd970fb8..7f7fb469 100644 --- a/globalfunctions/PeriodicOperationDivider.h +++ b/globalfunctions/PeriodicOperationDivider.h @@ -21,17 +21,27 @@ public: */ PeriodicOperationDivider(uint32_t divider, bool resetAutomatically = true); + /** * Check whether operation is necessary. * If an operation is necessary and the class has been * configured to be reset automatically, the counter will be reset. - * If not, the counter will be incremented. + * * @return * -@c true if the counter is larger or equal to the divider * -@c false otherwise */ bool checkAndIncrement(); + /** + * Checks whether an operation is necessary. + * This function will not increment the counter! + * @return + * -@c true if the counter is larger or equal to the divider + * -@c false otherwise + */ + bool check(); + /** * Can be used to reset the counter to 0 manually. */ diff --git a/housekeeping/HousekeepingMessage.cpp b/housekeeping/HousekeepingMessage.cpp index 65ba8c94..a3aab03a 100644 --- a/housekeeping/HousekeepingMessage.cpp +++ b/housekeeping/HousekeepingMessage.cpp @@ -39,7 +39,7 @@ void HousekeepingMessage::setToggleReportingCommand(CommandMessage *message, } else { if(enableReporting) { - message->setCommand(ENABLE_PERIODIC_HK_GENERATION); + message->setCommand(ENABLE_PERIODIC_HK_REPORT_GENERATION); } else { message->setCommand(DISABLE_PERIODIC_HK_REPORT_GENERATION); diff --git a/housekeeping/HousekeepingMessage.h b/housekeeping/HousekeepingMessage.h index 81fa2f02..6a3ca616 100644 --- a/housekeeping/HousekeepingMessage.h +++ b/housekeeping/HousekeepingMessage.h @@ -33,6 +33,14 @@ union sid_t { bool notSet() const { return raw == INVALID_ADDRESS; } + + bool operator==(const sid_t& other) const { + return raw == other.raw; + } + + bool operator!=(const sid_t& other) const { + return not (raw == other.raw); + } }; @@ -57,7 +65,7 @@ public: static constexpr uint8_t MESSAGE_ID = messagetypes::HOUSEKEEPING; - static constexpr Command_t ENABLE_PERIODIC_HK_GENERATION = + static constexpr Command_t ENABLE_PERIODIC_HK_REPORT_GENERATION = MAKE_COMMAND_ID(5); static constexpr Command_t DISABLE_PERIODIC_HK_REPORT_GENERATION = MAKE_COMMAND_ID(6); diff --git a/housekeeping/HousekeepingPacketDownlink.h b/housekeeping/HousekeepingPacketDownlink.h index 0be1551d..ae0cc988 100644 --- a/housekeeping/HousekeepingPacketDownlink.h +++ b/housekeeping/HousekeepingPacketDownlink.h @@ -14,13 +14,8 @@ */ class HousekeepingPacketDownlink: public SerialLinkedListAdapter { public: - HousekeepingPacketDownlink(sid_t sid, /*bool reportingStatus, - float collectionInterval, uint8_t numberOfParameters, */ - LocalPoolDataSetBase* dataSetPtr): - sourceId(sid.objectId), setId(sid.ownerSetId), - /*reportingStatus(reportingStatus), - collectionInterval(collectionInterval), - numberOfParameters(numberOfParameters), */hkData(dataSetPtr) { + HousekeepingPacketDownlink(sid_t sid, LocalPoolDataSetBase* dataSetPtr): + sourceId(sid.objectId), setId(sid.ownerSetId), hkData(dataSetPtr) { setLinks(); } @@ -29,17 +24,10 @@ private: setStart(&sourceId); sourceId.setNext(&setId); setId.setNext(&hkData); - //setId.setNext(&reportingStatus); - //reportingStatus.setNext(&collectionInterval); - //collectionInterval.setNext(&numberOfParameters); - //numberOfParameters.setNext(&hkData); } SerializeElement sourceId; SerializeElement setId; - //SerializeElement reportingStatus; - //SerializeElement collectionInterval; - //SerializeElement numberOfParameters; LinkedElement hkData; }; diff --git a/housekeeping/HousekeepingPacketUpdate.h b/housekeeping/HousekeepingPacketUpdate.h index e7b644f5..eebdc11c 100644 --- a/housekeeping/HousekeepingPacketUpdate.h +++ b/housekeeping/HousekeepingPacketUpdate.h @@ -1,9 +1,9 @@ #ifndef FRAMEWORK_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_ #define FRAMEWORK_HOUSEKEEPING_HOUSEKEEPINGPACKETUPDATE_H_ -#include -#include -#include +#include "../serialize/SerialBufferAdapter.h" +#include "../serialize/SerialLinkedListAdapter.h" +#include "../datapoollocal/LocalPoolDataSetBase.h" /** * @brief This helper class will be used to serialize and deserialize diff --git a/housekeeping/HousekeepingSetPacket.h b/housekeeping/HousekeepingSetPacket.h new file mode 100644 index 00000000..9a717420 --- /dev/null +++ b/housekeeping/HousekeepingSetPacket.h @@ -0,0 +1,13 @@ +#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ +#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ + +#include "../serialize/SerialLinkedListAdapter.h" + +class HousekeepingSetPacket: public SerialLinkedListAdapter { + + +}; + + + +#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ */ diff --git a/pus/Service3Housekeeping.cpp b/pus/Service3Housekeeping.cpp index d8e4466b..0d63a4e2 100644 --- a/pus/Service3Housekeeping.cpp +++ b/pus/Service3Housekeeping.cpp @@ -116,7 +116,7 @@ ReturnValue_t Service3Housekeeping::prepareReportingTogglingCommand( CommandMessage *command, object_id_t objectId, bool enableReporting, bool isDiagnostics, const uint8_t* tcData, size_t tcDataLen) { - if(tcDataLen < sizeof(object_id_t)) { + if(tcDataLen < sizeof(sid_t)) { // TC data should consist of object ID and set ID. return CommandingServiceBase::INVALID_TC; }