From cfae090de4c40c775d0fef574093780a5e1f65f9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 23 Dec 2022 11:46:01 +0100 Subject: [PATCH] improvements for ploc supv SW --- linux/devices/ploc/PlocSupervisorHandler.cpp | 38 +++++++++++--------- linux/devices/ploc/PlocSupervisorHandler.h | 8 ++--- 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/linux/devices/ploc/PlocSupervisorHandler.cpp b/linux/devices/ploc/PlocSupervisorHandler.cpp index 54af97ec..17657b50 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.cpp +++ b/linux/devices/ploc/PlocSupervisorHandler.cpp @@ -136,29 +136,34 @@ ReturnValue_t PlocSupervisorHandler::executeAction(ActionId_t actionId, } void PlocSupervisorHandler::doStartUp() { - if (setTimeDuringStartup) { - if (startupState == StartupState::OFF) { - bootTimeout.resetTimer(); - startupState = StartupState::BOOTING; - } - if (startupState == StartupState::BOOTING) { - if (bootTimeout.hasTimedOut()) { - uartIsolatorSwitch.pullHigh(); - uartManager.start(); + if (startupState == StartupState::OFF) { + bootTimeout.resetTimer(); + startupState = StartupState::BOOTING; + } + if (startupState == StartupState::BOOTING) { + if (bootTimeout.hasTimedOut()) { + uartIsolatorSwitch.pullHigh(); + uartManager.start(); + if (SET_TIME_DURING_BOOT) { startupState = StartupState::SET_TIME; + } else { + startupState = StartupState::ON; } } - if (startupState == StartupState::ON) { - setMode(_MODE_TO_ON); - } - } else { - uartIsolatorSwitch.pullHigh(); + } + if (startupState == StartupState::SET_TIME_EXECUTING) { + startupState = StartupState::ON; + } + if (startupState == StartupState::ON) { setMode(_MODE_TO_ON); } } void PlocSupervisorHandler::doShutDown() { setMode(_MODE_POWER_DOWN); + shutdownCmdSent = false; + packetInBuffer = false; + nextReplyId = supv::NONE; uartManager.stop(); uartIsolatorSwitch.pullLow(); startupState = StartupState::OFF; @@ -1896,9 +1901,8 @@ ReturnValue_t PlocSupervisorHandler::handleExecutionSuccessReport(ExecutionRepor break; } case supv::SET_TIME_REF: { - if (startupState == StartupState::SET_TIME_EXECUTING) { - startupState = StartupState::ON; - } + // We could only allow proper bootup when the time was set successfully, but + // this makes debugging difficult. break; } default: diff --git a/linux/devices/ploc/PlocSupervisorHandler.h b/linux/devices/ploc/PlocSupervisorHandler.h index 4ffe4166..85934cdc 100644 --- a/linux/devices/ploc/PlocSupervisorHandler.h +++ b/linux/devices/ploc/PlocSupervisorHandler.h @@ -97,11 +97,11 @@ class PlocSupervisorHandler : public DeviceHandlerBase { static const uint32_t COPY_ADC_TO_MRAM_TIMEOUT = 70000; // 60 s static const uint32_t MRAM_DUMP_TIMEOUT = 60000; - // 2 s - static const uint32_t BOOT_TIMEOUT = 2000; + // 5 s + static const uint32_t BOOT_TIMEOUT = 5000; enum class StartupState : uint8_t { OFF, BOOTING, SET_TIME, SET_TIME_EXECUTING, ON }; - bool setTimeDuringStartup = true; + static constexpr bool SET_TIME_DURING_BOOT = true; StartupState startupState = StartupState::OFF; @@ -138,8 +138,6 @@ class PlocSupervisorHandler : public DeviceHandlerBase { uint32_t receivedMramDumpPackets = 0; /** Set to true as soon as a complete space packet is present in the spacePacketBuffer */ bool packetInBuffer = false; - /** Points to the next free position in the space packet buffer */ - uint16_t bufferTop = 0; /** This buffer is used to concatenate space packets received in two different read steps */ uint8_t spacePacketBuffer[supv::MAX_PACKET_SIZE];