From 23a4b08709880a9a5d9ceeae44bda74836415959 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 31 Mar 2023 23:41:30 +0200 Subject: [PATCH] seems to work, improve dummy PCDU handler --- dummies/PcduHandlerDummy.cpp | 36 +++++++++++++++++++++++++++++++++++- dummies/PcduHandlerDummy.h | 4 ++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/dummies/PcduHandlerDummy.cpp b/dummies/PcduHandlerDummy.cpp index e3331c8d..0b1dec69 100644 --- a/dummies/PcduHandlerDummy.cpp +++ b/dummies/PcduHandlerDummy.cpp @@ -2,8 +2,12 @@ #include +#include "mission/power/defs.h" + PcduHandlerDummy::PcduHandlerDummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie) - : DeviceHandlerBase(objectId, comif, comCookie), dummySwitcher(objectId, 18, 18, false) {} + : DeviceHandlerBase(objectId, comif, comCookie), dummySwitcher(objectId, 18, 18, false) { + switcherLock = MutexFactory::instance()->createMutex(); +} PcduHandlerDummy::~PcduHandlerDummy() {} @@ -44,6 +48,17 @@ ReturnValue_t PcduHandlerDummy::initializeLocalDataPool(localpool::DataPool &loc } ReturnValue_t PcduHandlerDummy::sendSwitchCommand(power::Switch_t switchNr, ReturnValue_t onOff) { + if (onOff == SWITCH_ON) { + triggerEvent(power::SWITCH_CMD_SENT, true, switchNr); + } else { + triggerEvent(power::SWITCH_CMD_SENT, false, switchNr); + } + { + MutexGuard mg(switcherLock); + // To simulate a real PCDU, remember the switch change to trigger a SWITCH_HAS_CHANGED event + // at a later stage. + switchChangeArray[switchNr] = true; + } return dummySwitcher.sendSwitchCommand(switchNr, onOff); } @@ -60,3 +75,22 @@ ReturnValue_t PcduHandlerDummy::getFuseState(uint8_t fuseNr) const { } uint32_t PcduHandlerDummy::getSwitchDelayMs(void) const { return dummySwitcher.getSwitchDelayMs(); } + +void PcduHandlerDummy::performOperationHook() { + SwitcherBoolArray switcherChangeCopy{}; + { + MutexGuard mg(switcherLock); + std::memcpy(switcherChangeCopy.data(), switchChangeArray.data(), switchChangeArray.size()); + } + for (uint8_t idx = 0; idx < switcherChangeCopy.size(); idx++) { + if (switcherChangeCopy[idx]) { + if (dummySwitcher.getSwitchState(idx) == PowerSwitchIF::SWITCH_ON) { + triggerEvent(power::SWITCH_HAS_CHANGED, true, idx); + } else { + triggerEvent(power::SWITCH_HAS_CHANGED, false, idx); + } + MutexGuard mg(switcherLock); + switchChangeArray[idx] = false; + } + } +} diff --git a/dummies/PcduHandlerDummy.h b/dummies/PcduHandlerDummy.h index 2f4c167a..7980629b 100644 --- a/dummies/PcduHandlerDummy.h +++ b/dummies/PcduHandlerDummy.h @@ -15,8 +15,12 @@ class PcduHandlerDummy : public DeviceHandlerBase, public PowerSwitchIF { virtual ~PcduHandlerDummy(); protected: + MutexIF *switcherLock; DummyPowerSwitcher dummySwitcher; + using SwitcherBoolArray = std::array; + SwitcherBoolArray switchChangeArray{}; + void performOperationHook() override; void doStartUp() override; void doShutDown() override; ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t *id) override;