DPL: replace _plState enum with a simple boolean switch

This commit is contained in:
Bernhard Kirchen 2023-06-29 21:49:10 +02:00
parent b2d58af5e8
commit 9bab740c43
2 changed files with 5 additions and 17 deletions

View File

@ -53,15 +53,8 @@ public:
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;

View File

@ -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);