Prevent null pointer exception

It could occur that the command queue contained commands for inverters which are already deleted.
Therefor it has to be checked that getInverterBySerial returns a valid inverter
This commit is contained in:
Thomas Basler 2022-11-10 18:32:28 +01:00
parent 26b9bbf537
commit 0d619e780a

View File

@ -127,7 +127,7 @@ void HoymilesRadio::loop()
}
} else {
// If inverter was not found, assume the command is invalid
Serial.println(F("Invalid inverter found"));
Serial.println(F("RX: Invalid inverter found"));
_commandQueue.pop();
_busyFlag = false;
}
@ -137,8 +137,13 @@ void HoymilesRadio::loop()
CommandAbstract* cmd = _commandQueue.front().get();
auto inv = Hoymiles.getInverterBySerial(cmd->getTargetAddress());
inv->clearRxFragmentBuffer();
sendEsbPacket(cmd);
if (nullptr != inv) {
inv->clearRxFragmentBuffer();
sendEsbPacket(cmd);
} else {
Serial.println(F("TX: Invalid inverter found"));
_commandQueue.pop();
}
}
}
}