From 59028ccc3ff0421d5e35a1431e21897ebe5dc403 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 14:48:41 +0100 Subject: [PATCH 1/5] updated power component --- power/PowerComponent.cpp | 20 ++++++++++---------- power/PowerComponent.h | 4 ++-- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index 778d2b71..9ea84dad 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -9,23 +9,23 @@ PowerComponent::PowerComponent(): switchId1(0xFF), switchId2(0xFF), PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min, float max, uint8_t switchId1, bool twoSwitches, uint8_t switchId2) : deviceObjectId(setId), switchId1(switchId1), switchId2(switchId2), - doIHaveTwoSwitches(twoSwitches), minVoltage(min), maxVoltage(max), + doIHaveTwoSwitches(twoSwitches), minPower(min), maxPower(max), moduleId(moduleId) { } ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size, size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = SerializeAdapter::serialize(&minVoltage, buffer, + ReturnValue_t result = SerializeAdapter::serialize(&minPower, buffer, size, maxSize, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - return SerializeAdapter::serialize(&maxVoltage, buffer, size, maxSize, + return SerializeAdapter::serialize(&maxPower, buffer, size, maxSize, streamEndianness); } size_t PowerComponent::getSerializedSize() const { - return sizeof(minVoltage) + sizeof(maxVoltage); + return sizeof(minPower) + sizeof(maxPower); } object_id_t PowerComponent::getDeviceObjectId() { @@ -45,21 +45,21 @@ bool PowerComponent::hasTwoSwitches() { } float PowerComponent::getMin() { - return minVoltage; + return minPower; } float PowerComponent::getMax() { - return maxVoltage; + return maxPower; } ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) { - ReturnValue_t result = SerializeAdapter::deSerialize(&minVoltage, buffer, + ReturnValue_t result = SerializeAdapter::deSerialize(&minPower, buffer, size, streamEndianness); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - return SerializeAdapter::deSerialize(&maxVoltage, buffer, size, streamEndianness); + return SerializeAdapter::deSerialize(&maxPower, buffer, size, streamEndianness); } ReturnValue_t PowerComponent::getParameter(uint8_t domainId, uint8_t uniqueId, @@ -70,10 +70,10 @@ ReturnValue_t PowerComponent::getParameter(uint8_t domainId, uint8_t uniqueId, } switch (uniqueId) { case 0: - parameterWrapper->set<>(minVoltage); + parameterWrapper->set<>(minPower); break; case 1: - parameterWrapper->set<>(maxVoltage); + parameterWrapper->set<>(maxPower); break; default: return INVALID_IDENTIFIER_ID; diff --git a/power/PowerComponent.h b/power/PowerComponent.h index 68b07c32..ce45f142 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -41,8 +41,8 @@ private: const bool doIHaveTwoSwitches; - float minVoltage = 0.0; - float maxVoltage = 0.0; + float minPower = 0.0; + float maxPower = 0.0; uint8_t moduleId = 0; From 7b3616c41f9912d91b2ffcc959db84f99f38b4ba Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 21:09:01 +0100 Subject: [PATCH 2/5] corrections --- power/PowerComponent.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/power/PowerComponent.h b/power/PowerComponent.h index ce45f142..6b9778a5 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -9,7 +9,7 @@ class PowerComponent: public PowerComponentIF { public: - PowerComponent(object_id_t setId, uint8_t moduleId, float minVoltage, float maxVoltage, + PowerComponent(object_id_t setId, uint8_t moduleId, float minPower, float maxPower, uint8_t switchId1, bool twoSwitches = false, uint8_t switchId2 = 0xFF); From 3e9c19ee11950e73a5d67276697add9f07521097 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 21:25:22 +0100 Subject: [PATCH 3/5] important replacements --- ipc/MutexGuard.h | 18 +++++++++--------- osal/host/MessageQueue.cpp | 6 +++--- osal/host/QueueMapManager.cpp | 4 ++-- osal/rtems/Clock.cpp | 6 +++--- osal/windows/TmTcWinUdpBridge.cpp | 8 +++++++- 5 files changed, 24 insertions(+), 18 deletions(-) diff --git a/ipc/MutexGuard.h b/ipc/MutexGuard.h index 7eee47b5..00baa2da 100644 --- a/ipc/MutexGuard.h +++ b/ipc/MutexGuard.h @@ -1,5 +1,5 @@ -#ifndef FRAMEWORK_IPC_MUTEXHELPER_H_ -#define FRAMEWORK_IPC_MUTEXHELPER_H_ +#ifndef FRAMEWORK_IPC_MUTEXGUARD_H_ +#define FRAMEWORK_IPC_MUTEXGUARD_H_ #include "MutexFactory.h" #include "../serviceinterface/ServiceInterface.h" @@ -12,9 +12,9 @@ public: if(mutex == nullptr) { #if FSFW_VERBOSE_LEVEL >= 1 #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexHelper: Passed mutex is invalid!" << std::endl; + sif::error << "MutexGuard: Passed mutex is invalid!" << std::endl; #else - sif::printError("MutexHelper: Passed mutex is invalid!\n"); + sif::printError("MutexGuard: Passed mutex is invalid!\n"); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_VERBOSE_LEVEL >= 1 */ return; @@ -24,19 +24,19 @@ public: #if FSFW_VERBOSE_LEVEL >= 1 if(result == MutexIF::MUTEX_TIMEOUT) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexHelper: Lock of mutex failed with timeout of " + sif::error << "MutexGuard: Lock of mutex failed with timeout of " << timeoutMs << " milliseconds!" << std::endl; #else - sif::printError("MutexHelper: Lock of mutex failed with timeout of %lu milliseconds\n", + sif::printError("MutexGuard: Lock of mutex failed with timeout of %lu milliseconds\n", timeoutMs); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ } else if(result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "MutexHelper: Lock of Mutex failed with code " << result << std::endl; + sif::error << "MutexGuard: Lock of Mutex failed with code " << result << std::endl; #else - sif::printError("MutexHelper: Lock of Mutex failed with code %d\n", result); + sif::printError("MutexGuard: Lock of Mutex failed with code %d\n", result); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ } #else @@ -59,4 +59,4 @@ private: ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; }; -#endif /* FRAMEWORK_IPC_MUTEXHELPER_H_ */ +#endif /* FRAMEWORK_IPC_MUTEXGUARD_H_ */ diff --git a/osal/host/MessageQueue.cpp b/osal/host/MessageQueue.cpp index dfc045e8..fe7b8c08 100644 --- a/osal/host/MessageQueue.cpp +++ b/osal/host/MessageQueue.cpp @@ -3,7 +3,7 @@ #include "../../serviceinterface/ServiceInterfaceStream.h" #include "../../ipc/MutexFactory.h" -#include "../../ipc/MutexHelper.h" +#include "../../ipc/MutexGuard.h" MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize): messageSize(maxMessageSize), messageDepth(messageDepth) { @@ -65,7 +65,7 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) { } // not sure this will work.. //*message = std::move(messageQueue.front()); - MutexHelper mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20); + MutexGuard mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20); MessageQueueMessage* currentMessage = &messageQueue.front(); std::copy(currentMessage->getBuffer(), currentMessage->getBuffer() + messageSize, message->getBuffer()); @@ -130,7 +130,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, return HasReturnvaluesIF::RETURN_FAILED; } if(targetQueue->messageQueue.size() < targetQueue->messageDepth) { - MutexHelper mutexLock(targetQueue->queueLock, + MutexGuard mutexLock(targetQueue->queueLock, MutexIF::TimeoutType::WAITING, 20); // not ideal, works for now though. MessageQueueMessage* mqmMessage = diff --git a/osal/host/QueueMapManager.cpp b/osal/host/QueueMapManager.cpp index 2a54f813..b50d62dc 100644 --- a/osal/host/QueueMapManager.cpp +++ b/osal/host/QueueMapManager.cpp @@ -2,7 +2,7 @@ #include "../../serviceinterface/ServiceInterface.h" #include "../../ipc/MutexFactory.h" -#include "../../ipc/MutexHelper.h" +#include "../../ipc/MutexGuard.h" QueueMapManager* QueueMapManager::mqManagerInstance = nullptr; @@ -43,7 +43,7 @@ ReturnValue_t QueueMapManager::addMessageQueue( MessageQueueIF* QueueMapManager::getMessageQueue( MessageQueueId_t messageQueueId) const { - MutexHelper(mapLock, MutexIF::TimeoutType::WAITING, 50); + MutexGuard(mapLock, MutexIF::TimeoutType::WAITING, 50); auto queueIter = queueMap.find(messageQueueId); if(queueIter != queueMap.end()) { return queueIter->second; diff --git a/osal/rtems/Clock.cpp b/osal/rtems/Clock.cpp index aef71fe1..b80786f7 100644 --- a/osal/rtems/Clock.cpp +++ b/osal/rtems/Clock.cpp @@ -1,7 +1,7 @@ #include "RtemsBasic.h" #include "../../timemanager/Clock.h" -#include "../../ipc/MutexHelper.h" +#include "../../ipc/MutexGuard.h" #include #include @@ -183,7 +183,7 @@ ReturnValue_t Clock::setLeapSeconds(const uint16_t leapSeconds_) { if(checkOrCreateClockMutex()!=HasReturnvaluesIF::RETURN_OK){ return HasReturnvaluesIF::RETURN_FAILED; } - MutexHelper helper(timeMutex); + MutexGuard helper(timeMutex); leapSeconds = leapSeconds_; @@ -196,7 +196,7 @@ ReturnValue_t Clock::getLeapSeconds(uint16_t* leapSeconds_) { if(timeMutex==nullptr){ return HasReturnvaluesIF::RETURN_FAILED; } - MutexHelper helper(timeMutex); + MutexGuard helper(timeMutex); *leapSeconds_ = leapSeconds; diff --git a/osal/windows/TmTcWinUdpBridge.cpp b/osal/windows/TmTcWinUdpBridge.cpp index 94805cdc..d0de33d3 100644 --- a/osal/windows/TmTcWinUdpBridge.cpp +++ b/osal/windows/TmTcWinUdpBridge.cpp @@ -1,6 +1,12 @@ -#include #include "TmTcWinUdpBridge.h" +#include + +#if defined(_MSC_VER) +#include +typedef SSIZE_T ssize_t; +#endif + TmTcWinUdpBridge::TmTcWinUdpBridge(object_id_t objectId, object_id_t tcDestination, object_id_t tmStoreId, object_id_t tcStoreId, uint16_t serverPort, uint16_t clientPort): From 7525c883925a2e0e9eae6932337eab459b061cfe Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 9 Mar 2021 21:21:01 +0100 Subject: [PATCH 4/5] renamed mutex helper --- ipc/MutexGuard.h | 2 -- osal/linux/TmTcUnixUdpBridge.cpp | 6 +++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/ipc/MutexGuard.h b/ipc/MutexGuard.h index 00baa2da..9ee68c81 100644 --- a/ipc/MutexGuard.h +++ b/ipc/MutexGuard.h @@ -40,8 +40,6 @@ public: #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ } #else - /* To avoid unused variable warning */ - static_cast(status); #endif /* FSFW_VERBOSE_LEVEL >= 1 */ } diff --git a/osal/linux/TmTcUnixUdpBridge.cpp b/osal/linux/TmTcUnixUdpBridge.cpp index 0af1fc68..7f110114 100644 --- a/osal/linux/TmTcUnixUdpBridge.cpp +++ b/osal/linux/TmTcUnixUdpBridge.cpp @@ -1,6 +1,6 @@ #include "TmTcUnixUdpBridge.h" #include "../../serviceinterface/ServiceInterface.h" -#include "../../ipc/MutexHelper.h" +#include "../../ipc/MutexGuard.h" #include #include @@ -69,7 +69,7 @@ TmTcUnixUdpBridge::~TmTcUnixUdpBridge() { ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { int flags = 0; - MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10); + MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10); if(ipAddrAnySet){ clientAddress.sin_addr.s_addr = htons(INADDR_ANY); @@ -100,7 +100,7 @@ ReturnValue_t TmTcUnixUdpBridge::sendTm(const uint8_t *data, size_t dataLen) { } void TmTcUnixUdpBridge::checkAndSetClientAddress(sockaddr_in& newAddress) { - MutexHelper lock(mutex, MutexIF::TimeoutType::WAITING, 10); + MutexGuard lock(mutex, MutexIF::TimeoutType::WAITING, 10); // char ipAddress [15]; #if FSFW_CPP_OSTREAM_ENABLED == 1 From 8dec4c931147d7c3c39c812aaa985953f37380b2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 16 Mar 2021 14:53:17 +0100 Subject: [PATCH 5/5] updated pool data set base --- datapoollocal/LocalPoolDataSetBase.cpp | 30 +++++++++++++++++++------- datapoollocal/LocalPoolDataSetBase.h | 16 ++++++++++---- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index 2d70712b..6aa66f82 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -44,7 +44,7 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, const size_t maxNumberOfVariables): - PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { + PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { HasLocalDataPoolIF* hkOwner = objectManager->get( sid.objectId); if(hkOwner != nullptr) { @@ -96,15 +96,22 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer SerializeIF::Endianness streamEndianness) const { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; const uint8_t validityMaskSize = std::ceil(static_cast(fillCount)/8.0); + uint8_t* validityPtr = nullptr; +#ifdef _MSC_VER /* Use a std::vector here because MSVC will (rightly) not create a fixed size array with a non constant size specifier */ std::vector validityMask(validityMaskSize); + validityPtr = validityMask.data(); +#else + uint8_t validityMask[validityMaskSize]; + validityPtr = validityMask; +#endif uint8_t validBufferIndex = 0; uint8_t validBufferIndexBit = 0; for (uint16_t count = 0; count < fillCount; count++) { if(registeredVariables[count]->isValid()) { /* Set bit at correct position */ - bitutil::bitSet(validityMask.data() + validBufferIndex, validBufferIndexBit); + bitutil::bitSet(validityMask + validBufferIndex, validBufferIndexBit); } if(validBufferIndexBit == 7) { validBufferIndex ++; @@ -125,7 +132,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer return SerializeIF::BUFFER_TOO_SHORT; } // copy validity buffer to end - std::memcpy(*buffer, validityMask.data(), validityMaskSize); + std::memcpy(*buffer, validityPtr, validityMaskSize); *size += validityMaskSize; return result; } @@ -264,11 +271,9 @@ bool LocalPoolDataSetBase::getReportingEnabled() const { return reportingEnabled; } -void LocalPoolDataSetBase::initializePeriodicHelper( - float collectionInterval, dur_millis_t minimumPeriodicInterval, - bool isDiagnostics, uint8_t nonDiagIntervalFactor) { - periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, - isDiagnostics, nonDiagIntervalFactor); +void LocalPoolDataSetBase::initializePeriodicHelper(float collectionInterval, + dur_millis_t minimumPeriodicInterval, uint8_t nonDiagIntervalFactor) { + periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, nonDiagIntervalFactor); } void LocalPoolDataSetBase::setChanged(bool changed) { @@ -308,3 +313,12 @@ void LocalPoolDataSetBase::setAllVariablesReadOnly() { registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ); } } + +float LocalPoolDataSetBase::getCollectionInterval() const { + if(periodicHelper != nullptr) { + return periodicHelper->getCollectionIntervalInSeconds(); + } + else { + return 0.0; + } +} diff --git a/datapoollocal/LocalPoolDataSetBase.h b/datapoollocal/LocalPoolDataSetBase.h index 404509ae..ab67dc3f 100644 --- a/datapoollocal/LocalPoolDataSetBase.h +++ b/datapoollocal/LocalPoolDataSetBase.h @@ -166,6 +166,16 @@ public: object_id_t getCreatorObjectId(); + bool getReportingEnabled() const; + + /** + * Returns the current periodic HK generation interval this set + * belongs to a HK manager and the interval is not 0. Otherwise, + * returns 0.0 + * @return + */ + float getCollectionInterval() const; + protected: sid_t sid; //! This mutex is used if the data is created by one object only. @@ -180,11 +190,9 @@ protected: */ bool reportingEnabled = false; void setReportingEnabled(bool enabled); - bool getReportingEnabled() const; - void initializePeriodicHelper(float collectionInterval, - dur_millis_t minimumPeriodicInterval, - bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5); + void initializePeriodicHelper(float collectionInterval, dur_millis_t minimumPeriodicInterval, + uint8_t nonDiagIntervalFactor = 5); /** * If the valid state of a dataset is always relevant to the whole