Firmio: Improve exit from Find loop

Device: Null check return from std::dynamic_pointer_cast
136-add-android-support
Jonathan Schwartz 2023-10-03 16:24:28 +00:00
parent cc7cffe068
commit e0cef880f0
2 changed files with 8 additions and 4 deletions

View File

@ -1878,7 +1878,7 @@ bool Device::subscribeLiveData(std::shared_ptr<LiveDataCommandMessage> message)
if(response) {
auto statusMsg = std::dynamic_pointer_cast<LiveDataStatusMessage>(response);
if(statusMsg->requestedCommand == message->cmd) {
if(statusMsg && statusMsg->requestedCommand == message->cmd) {
switch(statusMsg->status) {
case LiveDataStatus::SUCCESS:
return true;

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