Search for rebooted device after update
This commit is contained in:
parent
8c33ae523a
commit
37511fa404
Binary file not shown.
@ -181,15 +181,15 @@ bool Device::SendCommandWithoutPayload(Protocol::PacketType type)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<QString> Device::GetDevices()
|
std::set<QString> Device::GetDevices()
|
||||||
{
|
{
|
||||||
std::vector<QString> serials;
|
std::set<QString> serials;
|
||||||
|
|
||||||
libusb_context *ctx;
|
libusb_context *ctx;
|
||||||
libusb_init(&ctx);
|
libusb_init(&ctx);
|
||||||
|
|
||||||
SearchDevices([&serials](libusb_device_handle *, QString serial) -> bool {
|
SearchDevices([&serials](libusb_device_handle *, QString serial) -> bool {
|
||||||
serials.push_back(serial);
|
serials.insert(serial);
|
||||||
return true;
|
return true;
|
||||||
}, ctx);
|
}, ctx);
|
||||||
|
|
||||||
|
@ -7,6 +7,7 @@
|
|||||||
#include <thread>
|
#include <thread>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <condition_variable>
|
#include <condition_variable>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(Protocol::Datapoint);
|
Q_DECLARE_METATYPE(Protocol::Datapoint);
|
||||||
Q_DECLARE_METATYPE(Protocol::ManualStatus);
|
Q_DECLARE_METATYPE(Protocol::ManualStatus);
|
||||||
@ -50,7 +51,7 @@ public:
|
|||||||
bool SendFirmwareChunk(Protocol::FirmwarePacket &fw);
|
bool SendFirmwareChunk(Protocol::FirmwarePacket &fw);
|
||||||
bool SendCommandWithoutPayload(Protocol::PacketType type);
|
bool SendCommandWithoutPayload(Protocol::PacketType type);
|
||||||
// Returns serial numbers of all connected devices
|
// Returns serial numbers of all connected devices
|
||||||
static std::vector<QString> GetDevices();
|
static std::set<QString> GetDevices();
|
||||||
QString serial() const;
|
QString serial() const;
|
||||||
Protocol::DeviceInfo getLastInfo() const;
|
Protocol::DeviceInfo getLastInfo() const;
|
||||||
QString getLastDeviceInfoString();
|
QString getLastDeviceInfoString();
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#include "ui_firmwareupdatedialog.h"
|
#include "ui_firmwareupdatedialog.h"
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
FirmwareUpdateDialog::FirmwareUpdateDialog(Device &dev, QWidget *parent) :
|
FirmwareUpdateDialog::FirmwareUpdateDialog(Device *&dev, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::FirmwareUpdateDialog),
|
ui(new Ui::FirmwareUpdateDialog),
|
||||||
dev(dev),
|
dev(dev),
|
||||||
@ -13,10 +13,7 @@ FirmwareUpdateDialog::FirmwareUpdateDialog(Device &dev, QWidget *parent) :
|
|||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->bFile->setIcon(this->style()->standardPixmap(QStyle::SP_FileDialogStart));
|
ui->bFile->setIcon(this->style()->standardPixmap(QStyle::SP_FileDialogStart));
|
||||||
ui->bStart->setIcon(this->style()->standardPixmap(QStyle::SP_MediaPlay));
|
ui->bStart->setIcon(this->style()->standardPixmap(QStyle::SP_MediaPlay));
|
||||||
timer.setSingleShot(true);
|
connect(&timer, &QTimer::timeout, this, &FirmwareUpdateDialog::timerCallback);
|
||||||
connect(&timer, &QTimer::timeout, [=](){
|
|
||||||
abortWithError("Response timed out");
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
FirmwareUpdateDialog::~FirmwareUpdateDialog()
|
FirmwareUpdateDialog::~FirmwareUpdateDialog()
|
||||||
@ -62,7 +59,8 @@ void FirmwareUpdateDialog::on_bStart_clicked()
|
|||||||
}
|
}
|
||||||
state = State::ErasingFLASH;
|
state = State::ErasingFLASH;
|
||||||
addStatus("Erasing device memory...");
|
addStatus("Erasing device memory...");
|
||||||
dev.SendCommandWithoutPayload(Protocol::PacketType::ClearFlash);
|
dev->SendCommandWithoutPayload(Protocol::PacketType::ClearFlash);
|
||||||
|
timer.setSingleShot(true);
|
||||||
timer.start(10000);
|
timer.start(10000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +82,22 @@ void FirmwareUpdateDialog::abortWithError(QString error)
|
|||||||
state = State::Idle;
|
state = State::Idle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FirmwareUpdateDialog::timerCallback()
|
||||||
|
{
|
||||||
|
if(state != State::WaitingForReboot) {
|
||||||
|
abortWithError("Response timed out");
|
||||||
|
} else {
|
||||||
|
// Currently waiting for the reboot, check device list
|
||||||
|
auto devices = Device::GetDevices();
|
||||||
|
if(devices.find(serialnumber) != devices.end()) {
|
||||||
|
// the device rebooted and is available again
|
||||||
|
dev = new Device(serialnumber);
|
||||||
|
addStatus("...device reattached, update complete");
|
||||||
|
timer.stop();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FirmwareUpdateDialog::receivedAck()
|
void FirmwareUpdateDialog::receivedAck()
|
||||||
{
|
{
|
||||||
switch(state) {
|
switch(state) {
|
||||||
@ -105,7 +119,7 @@ void FirmwareUpdateDialog::receivedAck()
|
|||||||
// complete file transferred
|
// complete file transferred
|
||||||
addStatus("Triggering device update...");
|
addStatus("Triggering device update...");
|
||||||
state = State::TriggeringUpdate;
|
state = State::TriggeringUpdate;
|
||||||
dev.SendCommandWithoutPayload(Protocol::PacketType::PerformFirmwareUpdate);
|
dev->SendCommandWithoutPayload(Protocol::PacketType::PerformFirmwareUpdate);
|
||||||
timer.start(5000);
|
timer.start(5000);
|
||||||
}
|
}
|
||||||
sendNextFirmwareChunk();
|
sendNextFirmwareChunk();
|
||||||
@ -113,8 +127,14 @@ void FirmwareUpdateDialog::receivedAck()
|
|||||||
break;
|
break;
|
||||||
case State::TriggeringUpdate:
|
case State::TriggeringUpdate:
|
||||||
addStatus("Rebooting device...");
|
addStatus("Rebooting device...");
|
||||||
// TODO delete current device and listen for reconnect
|
serialnumber = dev->serial();
|
||||||
state = State::Idle;
|
delete dev;
|
||||||
|
dev = nullptr;
|
||||||
|
state = State::WaitingForReboot;
|
||||||
|
timer.setSingleShot(false);
|
||||||
|
timer.start(1000);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -124,5 +144,5 @@ void FirmwareUpdateDialog::sendNextFirmwareChunk()
|
|||||||
Protocol::FirmwarePacket fw;
|
Protocol::FirmwarePacket fw;
|
||||||
fw.address = transferredBytes;
|
fw.address = transferredBytes;
|
||||||
file->read((char*) &fw.data, Protocol::FirmwareChunkSize);
|
file->read((char*) &fw.data, Protocol::FirmwareChunkSize);
|
||||||
dev.SendFirmwareChunk(fw);
|
dev->SendFirmwareChunk(fw);
|
||||||
}
|
}
|
||||||
|
@ -15,13 +15,20 @@ class FirmwareUpdateDialog : public QDialog
|
|||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit FirmwareUpdateDialog(Device &dev, QWidget *parent = nullptr);
|
/*
|
||||||
|
* Depending on the result of the firmware update, the device pointer will be modified:
|
||||||
|
* - In case of user-aborted firmware update, the device pointer will be unchanged
|
||||||
|
* - If the update fails during transmission of firmware data, the device pointer will be unchanged
|
||||||
|
* - If the update fails during device reboot, the device pointer is set to zero and the device deleted
|
||||||
|
* - If the update succeeds, the device pointer will be set to the new device instance
|
||||||
|
*/
|
||||||
|
explicit FirmwareUpdateDialog(Device *&dev, QWidget *parent = nullptr);
|
||||||
~FirmwareUpdateDialog();
|
~FirmwareUpdateDialog();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_bFile_clicked();
|
void on_bFile_clicked();
|
||||||
|
|
||||||
void on_bStart_clicked();
|
void on_bStart_clicked();
|
||||||
|
void timerCallback();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void addStatus(QString line);
|
void addStatus(QString line);
|
||||||
@ -29,7 +36,7 @@ private:
|
|||||||
void receivedAck();
|
void receivedAck();
|
||||||
void sendNextFirmwareChunk();
|
void sendNextFirmwareChunk();
|
||||||
Ui::FirmwareUpdateDialog *ui;
|
Ui::FirmwareUpdateDialog *ui;
|
||||||
Device &dev;
|
Device *&dev;
|
||||||
QFile *file;
|
QFile *file;
|
||||||
QTimer timer;
|
QTimer timer;
|
||||||
|
|
||||||
@ -38,9 +45,11 @@ private:
|
|||||||
ErasingFLASH,
|
ErasingFLASH,
|
||||||
TransferringData,
|
TransferringData,
|
||||||
TriggeringUpdate,
|
TriggeringUpdate,
|
||||||
|
WaitingForReboot,
|
||||||
};
|
};
|
||||||
State state;
|
State state;
|
||||||
unsigned int transferredBytes;
|
unsigned int transferredBytes;
|
||||||
|
QString serialnumber;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // FIRMWAREUPDATEDIALOG_H
|
#endif // FIRMWAREUPDATEDIALOG_H
|
||||||
|
@ -109,7 +109,7 @@ VNA::VNA(QWidget *parent)
|
|||||||
});
|
});
|
||||||
connect(ui->actionFirmware_Update, &QAction::triggered, [=](){
|
connect(ui->actionFirmware_Update, &QAction::triggered, [=](){
|
||||||
if(device) {
|
if(device) {
|
||||||
auto fw_update = new FirmwareUpdateDialog(*device);
|
auto fw_update = new FirmwareUpdateDialog(device);
|
||||||
fw_update->exec();
|
fw_update->exec();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user