DPL: replace _plState enum with a simple boolean switch
This commit is contained in:
parent
b2d58af5e8
commit
9bab740c43
@ -53,15 +53,8 @@ public:
|
|||||||
void calcNextInverterRestart();
|
void calcNextInverterRestart();
|
||||||
|
|
||||||
private:
|
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;
|
int32_t _lastRequestedPowerLimit = 0;
|
||||||
plStates _plState = plStates::INIT;
|
bool _shutdownInProgress;
|
||||||
Status _lastStatus = Status::Initializing;
|
Status _lastStatus = Status::Initializing;
|
||||||
uint32_t _lastStatusPrinted = 0;
|
uint32_t _lastStatusPrinted = 0;
|
||||||
uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP;
|
uint8_t _mode = PL_MODE_ENABLE_NORMAL_OP;
|
||||||
|
|||||||
@ -69,16 +69,14 @@ void PowerLimiterClass::shutdown(PowerLimiterClass::Status status)
|
|||||||
{
|
{
|
||||||
announceStatus(status);
|
announceStatus(status);
|
||||||
|
|
||||||
if (_plState == plStates::OFF) { return; }
|
|
||||||
|
|
||||||
_plState = plStates::SHUTDOWN;
|
|
||||||
|
|
||||||
if (_inverter == nullptr || !_inverter->isProducing() || !_inverter->isReachable()) {
|
if (_inverter == nullptr || !_inverter->isProducing() || !_inverter->isReachable()) {
|
||||||
_inverter = nullptr;
|
_inverter = nullptr;
|
||||||
_plState = plStates::OFF;
|
_shutdownInProgress = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_shutdownInProgress = true;
|
||||||
|
|
||||||
auto lastLimitCommandState = _inverter->SystemConfigPara()->getLastLimitCommandSuccess();
|
auto lastLimitCommandState = _inverter->SystemConfigPara()->getLastLimitCommandSuccess();
|
||||||
if (CMD_PENDING == lastLimitCommandState) { return; }
|
if (CMD_PENDING == lastLimitCommandState) { return; }
|
||||||
|
|
||||||
@ -93,7 +91,7 @@ void PowerLimiterClass::loop()
|
|||||||
{
|
{
|
||||||
CONFIG_T& config = Configuration.get();
|
CONFIG_T& config = Configuration.get();
|
||||||
|
|
||||||
if (plStates::SHUTDOWN == _plState) {
|
if (_shutdownInProgress) {
|
||||||
// we transition from SHUTDOWN to OFF when we know the inverter was
|
// 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
|
// 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.
|
// 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
|
// update our pointer as the configuration might have changed
|
||||||
_inverter = currentInverter;
|
_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
|
// data polling is disabled or the inverter is deemed offline
|
||||||
if (!_inverter->isReachable()) {
|
if (!_inverter->isReachable()) {
|
||||||
return announceStatus(Status::InverterOffline);
|
return announceStatus(Status::InverterOffline);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user