Skip to content

Commit

Permalink
flash: ping360flashworker: robustify initial part of flash procedure
Browse files Browse the repository at this point in the history
  • Loading branch information
jaxxzer committed Dec 20, 2023
1 parent 70d3feb commit f48765b
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions src/flash/ping360flashworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,30 @@ void Ping360FlashWorker::run()
QSerialPortInfo pInfo(_link.serialPort());
_port->setPort(pInfo);
_port->setBaudRate(115200);
_port->open(QIODevice::ReadWrite);

for (int i = 0; i < 10; i++) {
QThread::msleep(10);
if (_port->open(QIODevice::ReadWrite)) {
break;
}
}

if (!_port->isOpen()) {
error("error opening port");
}

qCInfo(PING360FLASHWORKER) << "fetch device id...";
uint16_t id;
if (bl_read_device_id(&id)) {
uint16_t id = 0;
bool id_read = false;
for (int i = 0; i < 10; i++) {
QThread::msleep(10);
if (bl_read_device_id(&id)) {
id_read = true;
break;
}
}

if (id_read) {
qCInfo(PING360FLASHWORKER) << QString::asprintf(" > device id: 0x%04x <\n", id);
} else {
error("error fetching device id");
Expand All @@ -45,7 +64,7 @@ void Ping360FlashWorker::run()
return;
}

printf(" > device type 0x%02x : hardware revision %c : bootloader v%d.%d.%d <\n", version.message.device_type,
qCInfo(PING360FLASHWORKER) << QString::asprintf(" > device type 0x%02x : hardware revision %c : bootloader v%d.%d.%d <\n", version.message.device_type,
version.message.device_revision, version.message.version_major, version.message.version_minor,
version.message.version_patch);

Expand Down

0 comments on commit f48765b

Please sign in to comment.