From 9bab740c4361d0fe9666059a60db8029f9d87ac3 Mon Sep 17 00:00:00 2001 From: Bernhard Kirchen Date: Thu, 29 Jun 2023 21:49:10 +0200 Subject: [PATCH] DPL: replace _plState enum with a simple boolean switch --- include/PowerLimiter.h | 9 +-------- src/PowerLimiter.cpp | 13 ++++--------- 2 files changed, 5 insertions(+), 17 deletions(-) diff --git a/include/PowerLimiter.h b/include/PowerLimiter.h index 52d6f2cb7..6249bb4e3 100644 --- a/include/PowerLimiter.h +++ b/include/PowerLimiter.h @@ -53,15 +53,8 @@ class PowerLimiterClass { void calcNextInverterRestart(); private: - enum class plStates : unsigned { - INIT, // looping for the first time after system startup - ACTIVE, // normal operation, sending power limit updates to inverter - SHUTDOWN, // power limiter shuts down inverter - OFF // inverter was shut down, power limiter is NOT active - }; - int32_t _lastRequestedPowerLimit = 0; - plStates _plState = plStates::INIT; + bool _shutdownInProgress; Status _lastStatus = Status::Initializing; uint32_t _lastStatusPrinted = 0; uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP; diff --git a/src/PowerLimiter.cpp b/src/PowerLimiter.cpp index 622316b78..3ccf979aa 100644 --- a/src/PowerLimiter.cpp +++ b/src/PowerLimiter.cpp @@ -69,16 +69,14 @@ void PowerLimiterClass::shutdown(PowerLimiterClass::Status status) { announceStatus(status); - if (_plState == plStates::OFF) { return; } - - _plState = plStates::SHUTDOWN; - if (_inverter == nullptr || !_inverter->isProducing() || !_inverter->isReachable()) { _inverter = nullptr; - _plState = plStates::OFF; + _shutdownInProgress = false; return; } + _shutdownInProgress = true; + auto lastLimitCommandState = _inverter->SystemConfigPara()->getLastLimitCommandSuccess(); if (CMD_PENDING == lastLimitCommandState) { return; } @@ -93,7 +91,7 @@ void PowerLimiterClass::loop() { CONFIG_T& config = Configuration.get(); - if (plStates::SHUTDOWN == _plState) { + if (_shutdownInProgress) { // we transition from SHUTDOWN to OFF when we know the inverter was // shut down. until then, we retry shutting it down. in this case we // preserve the original status that lead to the decision to shut down. @@ -126,9 +124,6 @@ void PowerLimiterClass::loop() // update our pointer as the configuration might have changed _inverter = currentInverter; - // controlling an inverter means the DPL will shut it down eventually - _plState = plStates::ACTIVE; - // data polling is disabled or the inverter is deemed offline if (!_inverter->isReachable()) { return announceStatus(Status::InverterOffline);