diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.cpp index a6f73fcc..a220e8d2 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/firmwareupdatedialog.cpp @@ -2,6 +2,7 @@ #include "ui_firmwareupdatedialog.h" #include "../../VNA_embedded/Application/Communication/PacketConstants.h" +#include "CustomWidgets/informationbox.h" #include #include @@ -60,8 +61,25 @@ void FirmwareUpdateDialog::on_bStart_clicked() char header[24]; file->read(header, sizeof(header)); if(strncmp(header, dev->getFirmwareMagicString().toStdString().c_str(), 4)) { - abortWithError("Invalid magic header constant"); - return; + // might be a firmware file for a wrong LibreVNA + if(dev->getProtocolVersion() == Protocol::Version) { + // we are talking to a LibreVNA with the correct protocol, this is definitely the wrong firmware file + abortWithError("Invalid magic header constant"); + return; + } else { + // we might be talking to the correct hardware but with the wrong protocol version (which might result + // in the magic string check falsely failing. Process after user confirmation + auto confirm = InformationBox::AskQuestion("Continue?", "The firmware magic header constant does not match the expected" + " value for your LibreVNA. Either this is the wrong firmware file" + " or the hardware ID of your LibreVNA was read incorrectly. This" + " can happen if the LibreVNA uses a different protocol version than" + " what it expected by the GUI. Do you want to continue with the firmware update?", true); + if(!confirm) { + abortWithError("Aborted by user"); + return; + } + } + } file->seek(0); state = State::ErasingFLASH; diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp index 8418b89c..42b8c809 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.cpp @@ -114,6 +114,7 @@ LibreVNADriver::LibreVNADriver() skipOwnPacketHandling = false; SApoints = 0; hardwareVersion = 0; + protocolVersion = 0; setSynchronization(Synchronization::Disabled, false); auto manual = new QAction("Manual Control"); @@ -589,6 +590,7 @@ void LibreVNADriver::handleReceivedPacket(const Protocol::PacketInfo &packet) switch(packet.type) { case Protocol::PacketType::DeviceInfo: { // Check protocol version + protocolVersion = packet.info.ProtocolVersion; if(packet.info.ProtocolVersion != Protocol::Version) { auto ret = InformationBox::AskQuestion("Warning", "The device reports a different protocol" @@ -703,6 +705,11 @@ QString LibreVNADriver::hardwareVersionToString(uint8_t version) } } +unsigned int LibreVNADriver::getProtocolVersion() const +{ + return protocolVersion; +} + unsigned int LibreVNADriver::getMaxAmplitudePoints() const { return limits_maxAmplitudePoints; diff --git a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h index b5052dcc..4c0014c0 100644 --- a/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h +++ b/Software/PC_Application/LibreVNA-GUI/Device/LibreVNA/librevnadriver.h @@ -184,6 +184,8 @@ class LibreVNADriver : public DeviceDriver QString getFirmwareMagicString(); + unsigned int getProtocolVersion() const; + signals: void receivedAnswer(const LibreVNADriver::TransmissionResult &result); void receivedPacket(const Protocol::PacketInfo& packet); @@ -194,6 +196,7 @@ protected slots: QString hardwareVersionToString(uint8_t version); bool connected; + unsigned int protocolVersion; QString serial; Info info; uint8_t hardwareVersion;