Firmio: Improve exit from Find loop

Device: Null check return from std::dynamic_pointer_cast
This commit is contained in:
Jonathan Schwartz
2023-10-03 16:24:28 +00:00
parent cc7cffe068
commit e0cef880f0
2 changed files with 8 additions and 4 deletions
+7 -3
View File
@@ -42,9 +42,13 @@ void FirmIO::Find(std::vector<FoundDevice>& found) {
Decoder decoder([](APIEvent::Type, APIEvent::Severity) {});
using namespace std::chrono;
const auto start = steady_clock::now();
auto timeout = milliseconds(50);
while(temp.readWait(payload, timeout)) {
timeout -= duration_cast<milliseconds>(steady_clock::now() - start);
// Get an absolute wall clock to compare to
const auto overallTimeout = start + milliseconds(500);
while(temp.readWait(payload, milliseconds(50))) {
if(steady_clock::now() > overallTimeout) {
// failed to read out a serial number reponse in time
break;
}
if(!packetizer.input(payload))
continue; // A full packet has not yet been read out