Remove code nesting
This commit is contained in:
parent
e9a55cf361
commit
e0c07b9bcf
@ -40,105 +40,107 @@ void HoymilesClass::loop()
|
|||||||
_radioNrf->loop();
|
_radioNrf->loop();
|
||||||
_radioCmt->loop();
|
_radioCmt->loop();
|
||||||
|
|
||||||
if (getNumInverters() > 0) {
|
if (getNumInverters() == 0) {
|
||||||
if (millis() - _lastPoll > (_pollInterval * 1000)) {
|
return;
|
||||||
static uint8_t inverterPos = 0;
|
}
|
||||||
|
|
||||||
std::shared_ptr<InverterAbstract> iv = getInverterByPos(inverterPos);
|
if (millis() - _lastPoll > (_pollInterval * 1000)) {
|
||||||
if ((iv == nullptr) || ((iv != nullptr) && (!iv->getRadio()->isInitialized()))) {
|
static uint8_t inverterPos = 0;
|
||||||
if (++inverterPos >= getNumInverters()) {
|
|
||||||
inverterPos = 0;
|
std::shared_ptr<InverterAbstract> iv = getInverterByPos(inverterPos);
|
||||||
}
|
if ((iv == nullptr) || ((iv != nullptr) && (!iv->getRadio()->isInitialized()))) {
|
||||||
|
if (++inverterPos >= getNumInverters()) {
|
||||||
|
inverterPos = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (iv != nullptr && iv->getRadio()->isInitialized() && iv->getRadio()->isQueueEmpty()) {
|
||||||
|
|
||||||
|
if (iv->getZeroValuesIfUnreachable() && !iv->isReachable()) {
|
||||||
|
Hoymiles.getMessageOutput()->println("Set runtime data to zero");
|
||||||
|
iv->Statistics()->zeroRuntimeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iv != nullptr && iv->getRadio()->isInitialized() && iv->getRadio()->isQueueEmpty()) {
|
if (iv->getEnablePolling() || iv->getEnableCommands()) {
|
||||||
|
_messageOutput->print("Fetch inverter: ");
|
||||||
|
_messageOutput->println(iv->serial(), HEX);
|
||||||
|
|
||||||
if (iv->getZeroValuesIfUnreachable() && !iv->isReachable()) {
|
if (!iv->isReachable()) {
|
||||||
Hoymiles.getMessageOutput()->println("Set runtime data to zero");
|
iv->sendChangeChannelRequest();
|
||||||
iv->Statistics()->zeroRuntimeData();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (iv->getEnablePolling() || iv->getEnableCommands()) {
|
iv->sendStatsRequest();
|
||||||
_messageOutput->print("Fetch inverter: ");
|
|
||||||
_messageOutput->println(iv->serial(), HEX);
|
|
||||||
|
|
||||||
if (!iv->isReachable()) {
|
// Fetch event log
|
||||||
iv->sendChangeChannelRequest();
|
bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
|
||||||
}
|
iv->sendAlarmLogRequest(force);
|
||||||
|
|
||||||
iv->sendStatsRequest();
|
// Fetch limit
|
||||||
|
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
|
||||||
// Fetch event log
|
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
|
||||||
bool force = iv->EventLog()->getLastAlarmRequestSuccess() == CMD_NOK;
|
_messageOutput->println("Request SystemConfigPara");
|
||||||
iv->sendAlarmLogRequest(force);
|
iv->sendSystemConfigParaRequest();
|
||||||
|
|
||||||
// Fetch limit
|
|
||||||
if (((millis() - iv->SystemConfigPara()->getLastUpdateRequest() > HOY_SYSTEM_CONFIG_PARA_POLL_INTERVAL)
|
|
||||||
&& (millis() - iv->SystemConfigPara()->getLastUpdateCommand() > HOY_SYSTEM_CONFIG_PARA_POLL_MIN_DURATION))) {
|
|
||||||
_messageOutput->println("Request SystemConfigPara");
|
|
||||||
iv->sendSystemConfigParaRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set limit if required
|
|
||||||
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
|
|
||||||
_messageOutput->println("Resend ActivePowerControl");
|
|
||||||
iv->resendActivePowerControlRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set power status if required
|
|
||||||
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
|
|
||||||
_messageOutput->println("Resend PowerCommand");
|
|
||||||
iv->resendPowerControlRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch dev info (but first fetch stats)
|
|
||||||
if (iv->Statistics()->getLastUpdate() > 0) {
|
|
||||||
bool invalidDevInfo = !iv->DevInfo()->containsValidData()
|
|
||||||
&& iv->DevInfo()->getLastUpdateAll() > 0
|
|
||||||
&& iv->DevInfo()->getLastUpdateSimple() > 0;
|
|
||||||
|
|
||||||
if (invalidDevInfo) {
|
|
||||||
_messageOutput->println("DevInfo: No Valid Data");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|
|
||||||
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|
|
||||||
|| invalidDevInfo) {
|
|
||||||
_messageOutput->println("Request device info");
|
|
||||||
iv->sendDevInfoRequest();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Fetch grid profile
|
|
||||||
if (iv->Statistics()->getLastUpdate() > 0 && iv->GridProfile()->getLastUpdate() == 0) {
|
|
||||||
iv->sendGridOnProFileParaRequest();
|
|
||||||
}
|
|
||||||
|
|
||||||
_lastPoll = millis();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (++inverterPos >= getNumInverters()) {
|
// Set limit if required
|
||||||
inverterPos = 0;
|
if (iv->SystemConfigPara()->getLastLimitCommandSuccess() == CMD_NOK) {
|
||||||
|
_messageOutput->println("Resend ActivePowerControl");
|
||||||
|
iv->resendActivePowerControlRequest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set power status if required
|
||||||
|
if (iv->PowerCommand()->getLastPowerCommandSuccess() == CMD_NOK) {
|
||||||
|
_messageOutput->println("Resend PowerCommand");
|
||||||
|
iv->resendPowerControlRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch dev info (but first fetch stats)
|
||||||
|
if (iv->Statistics()->getLastUpdate() > 0) {
|
||||||
|
bool invalidDevInfo = !iv->DevInfo()->containsValidData()
|
||||||
|
&& iv->DevInfo()->getLastUpdateAll() > 0
|
||||||
|
&& iv->DevInfo()->getLastUpdateSimple() > 0;
|
||||||
|
|
||||||
|
if (invalidDevInfo) {
|
||||||
|
_messageOutput->println("DevInfo: No Valid Data");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((iv->DevInfo()->getLastUpdateAll() == 0)
|
||||||
|
|| (iv->DevInfo()->getLastUpdateSimple() == 0)
|
||||||
|
|| invalidDevInfo) {
|
||||||
|
_messageOutput->println("Request device info");
|
||||||
|
iv->sendDevInfoRequest();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch grid profile
|
||||||
|
if (iv->Statistics()->getLastUpdate() > 0 && iv->GridProfile()->getLastUpdate() == 0) {
|
||||||
|
iv->sendGridOnProFileParaRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastPoll = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Perform housekeeping of all inverters on day change
|
if (++inverterPos >= getNumInverters()) {
|
||||||
int8_t currentWeekDay = Utils::getWeekDay();
|
inverterPos = 0;
|
||||||
static int8_t lastWeekDay = -1;
|
}
|
||||||
if (lastWeekDay == -1) {
|
}
|
||||||
|
|
||||||
|
// Perform housekeeping of all inverters on day change
|
||||||
|
int8_t currentWeekDay = Utils::getWeekDay();
|
||||||
|
static int8_t lastWeekDay = -1;
|
||||||
|
if (lastWeekDay == -1) {
|
||||||
|
lastWeekDay = currentWeekDay;
|
||||||
|
} else {
|
||||||
|
if (currentWeekDay != lastWeekDay) {
|
||||||
|
|
||||||
|
for (auto& inv : _inverters) {
|
||||||
|
if (inv->getZeroYieldDayOnMidnight()) {
|
||||||
|
inv->Statistics()->zeroDailyData();
|
||||||
|
}
|
||||||
|
inv->Statistics()->resetYieldDayCorrection();
|
||||||
|
}
|
||||||
|
|
||||||
lastWeekDay = currentWeekDay;
|
lastWeekDay = currentWeekDay;
|
||||||
} else {
|
|
||||||
if (currentWeekDay != lastWeekDay) {
|
|
||||||
|
|
||||||
for (auto& inv : _inverters) {
|
|
||||||
if (inv->getZeroYieldDayOnMidnight()) {
|
|
||||||
inv->Statistics()->zeroDailyData();
|
|
||||||
}
|
|
||||||
inv->Statistics()->resetYieldDayCorrection();
|
|
||||||
}
|
|
||||||
|
|
||||||
lastWeekDay = currentWeekDay;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user