2023-03-14 11:21:37 +01:00
|
|
|
#include "PcduHandlerDummy.h"
|
|
|
|
|
2023-03-26 16:13:54 +02:00
|
|
|
#include <mission/power/gsDefs.h>
|
2023-03-14 11:21:37 +01:00
|
|
|
|
2023-03-31 23:41:30 +02:00
|
|
|
#include "mission/power/defs.h"
|
|
|
|
|
2023-03-14 11:21:37 +01:00
|
|
|
PcduHandlerDummy::PcduHandlerDummy(object_id_t objectId, object_id_t comif, CookieIF *comCookie)
|
2023-03-31 23:41:30 +02:00
|
|
|
: DeviceHandlerBase(objectId, comif, comCookie), dummySwitcher(objectId, 18, 18, false) {
|
|
|
|
switcherLock = MutexFactory::instance()->createMutex();
|
|
|
|
}
|
2023-03-14 11:21:37 +01:00
|
|
|
|
|
|
|
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) {
|
2023-03-31 23:41:30 +02:00
|
|
|
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;
|
|
|
|
}
|
2023-03-14 11:21:37 +01:00
|
|
|
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(); }
|
2023-03-31 23:41:30 +02:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|