eive-obsw/dummies/PcduHandlerDummy.cpp
Robin Mueller 23a4b08709
All checks were successful
EIVE/eive-obsw/pipeline/pr-develop This commit looks good
seems to work, improve dummy PCDU handler
2023-03-31 23:41:30 +02:00

97 lines
3.3 KiB
C++

#include "PcduHandlerDummy.h"
#include <mission/power/gsDefs.h>
#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) {
switcherLock = MutexFactory::instance()->createMutex();
}
PcduHandlerDummy::~PcduHandlerDummy() {}
void PcduHandlerDummy::doStartUp() { setMode(MODE_NORMAL); }
void PcduHandlerDummy::doShutDown() { setMode(MODE_OFF); }
ReturnValue_t PcduHandlerDummy::buildNormalDeviceCommand(DeviceCommandId_t *id) {
return NOTHING_TO_SEND;
}
ReturnValue_t PcduHandlerDummy::buildTransitionDeviceCommand(DeviceCommandId_t *id) {
return NOTHING_TO_SEND;
}
ReturnValue_t PcduHandlerDummy::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
return returnvalue::OK;
}
ReturnValue_t PcduHandlerDummy::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
return returnvalue::OK;
}
ReturnValue_t PcduHandlerDummy::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
return returnvalue::OK;
}
void PcduHandlerDummy::fillCommandAndReplyMap() {}
uint32_t PcduHandlerDummy::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
ReturnValue_t PcduHandlerDummy::initializeLocalDataPool(localpool::DataPool &localDataPoolMap,
LocalDataPoolManager &poolManager) {
return returnvalue::OK;
}
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);
}
ReturnValue_t PcduHandlerDummy::sendFuseOnCommand(uint8_t fuseNr) {
return dummySwitcher.sendFuseOnCommand(fuseNr);
}
ReturnValue_t PcduHandlerDummy::getSwitchState(power::Switch_t switchNr) const {
return dummySwitcher.getSwitchState(switchNr);
}
ReturnValue_t PcduHandlerDummy::getFuseState(uint8_t fuseNr) const {
return dummySwitcher.getFuseState(fuseNr);
}
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;
}
}
}