diff --git a/mpod.cpp b/mpod.cpp index 86030b73e0f2e4ab59f7c7ec25c4d00c5e58c31c..1190c9c592313c7d3edd9ae3fae4e7a3679bd364 100644 --- a/mpod.cpp +++ b/mpod.cpp @@ -221,13 +221,34 @@ void setChannelStateAndWait(const IPAddress *ipAddr, const uint16_t channel, con snmp.loop(); // Poll channel until it's settled + uint8_t loopCount = 0; + bool ramping = true; + bool settingChannelState = true; do { SNMP::Message *snmp_msg = mpod.read(channel); snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP); delete snmp_msg; + delay(MPOD_UPDATE_LATENCY); snmp.loop(); - } while (mpod.isOn() != (bool)output || mpod.isRampingDown() || mpod.isRampingUp()); + loopCount += 1; + ramping = (mpod.isRampingUp() || mpod.isRampingDown()); + if (!ramping) { + if (mpod.isOn() == (bool)output) { + settingChannelState = false; + } else if (loopCount >= 5) { + // Resend set command + Serial.print("!Resend command to "); + Serial.println(channel); + SNMP::Message *snmp_msg = mpod.setChannelState(channel, output); + snmp.send(snmp_msg, *ipAddr, SNMP::Port::SNMP); + delete snmp_msg; + delay(MPOD_UPDATE_LATENCY); + snmp.loop(); + loopCount = 0; + } + } + } while (settingChannelState); } void setChannelVoltageAndWait(const IPAddress *ipAddr, const uint16_t channel, diff --git a/mpod.hpp b/mpod.hpp index 639d993f1525f2fdba331cfe683ec71d68980ccb..8ecd78f17ddca1c1f65409a0f27da26575fd3e2b 100644 --- a/mpod.hpp +++ b/mpod.hpp @@ -59,7 +59,6 @@ class MPOD { } }; - // Create an SNMP SETREQUEST message to setup MPOD MPOD(); SNMP::Message* read(const uint16_t); SNMP::Message* setChannelState(const uint16_t, const bool);