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