Skip to content

Commit

Permalink
DPL: replace _plState enum with a simple boolean switch
Browse files Browse the repository at this point in the history
  • Loading branch information
schlimmchen committed Jun 30, 2023
1 parent b2d58af commit 9bab740
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
9 changes: 1 addition & 8 deletions include/PowerLimiter.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
13 changes: 4 additions & 9 deletions src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand All @@ -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.
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 9bab740

Please sign in to comment.