From c21be4845e5f00f89c395aaa8f775c6036f82769 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Sun, 22 Jan 2017 14:08:13 +0100 Subject: [PATCH] Does this work? (#4269) Read an Horus SD card produces a temporary .otx file now --- companion/src/mainwindow.cpp | 42 ++++-------- companion/src/mdichild.cpp | 5 +- companion/src/radiointerface.cpp | 112 ++++++++++++++++++------------- 3 files changed, 83 insertions(+), 76 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 0738024e1..d0c8e6b06 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -728,36 +728,22 @@ void MainWindow::loadBackup() void MainWindow::readEeprom() { BoardEnum board = getCurrentBoard(); - if (board == BOARD_HORUS) { - QString radioPath = findMassstoragePath("RADIO", true); - qDebug() << "Searching for SD card, found" << radioPath; - if (radioPath.isEmpty()) { - qDebug() << "MainWindow::readEeprom(): Horus radio not found"; - QMessageBox::critical(this, tr("Error"), tr("Unable to find Horus radio SD card!")); - return; - } - MdiChild *child = createMdiChild(); - if (child->loadFile(radioPath)) { - statusBar()->showMessage(tr("Models and Settings read"), 2000); - child->show(); - } - } - else { - QString tempFile; - if (IS_ARM(board)) - tempFile = generateProcessUniqueTempFileName("temp.bin"); - else - tempFile += generateProcessUniqueTempFileName("temp.hex"); + QString tempFile; + if (IS_HORUS(board)) + tempFile = generateProcessUniqueTempFileName("temp.otx"); + else if (IS_ARM(board)) + tempFile = generateProcessUniqueTempFileName("temp.bin"); + else + tempFile = generateProcessUniqueTempFileName("temp.hex"); - qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile; + qDebug() << "MainWindow::readEeprom(): using temp file: " << tempFile; - if (readEepromFromRadio(tempFile)) { - MdiChild * child = createMdiChild(); - child->newFile(); - child->loadFile(tempFile, false); - child->show(); - qunlink(tempFile); - } + if (readEepromFromRadio(tempFile)) { + MdiChild * child = createMdiChild(); + child->newFile(); + child->loadFile(tempFile, false); + child->show(); + qunlink(tempFile); } } diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 2bd71c140..99cfaa021 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -487,8 +487,9 @@ bool MdiChild::loadFile(const QString & filename, bool resetCurrentFile) } refresh(true); - if (resetCurrentFile) + if (resetCurrentFile) { setCurrentFile(filename); + } return true; } @@ -588,7 +589,7 @@ bool MdiChild::maybeSave() return true; } -void MdiChild::setCurrentFile(const QString &fileName) +void MdiChild::setCurrentFile(const QString & fileName) { curFile = QFileInfo(fileName).canonicalFilePath(); isUntitled = false; diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index 515b1fdf0..1fdbaab20 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -24,12 +24,10 @@ #include "process_flash.h" #include "radionotfound.h" #include "burnconfigdialog.h" -#include "firmwareinterface.h" #include "helpers.h" #include "mountlist.h" #include "process_copy.h" -#include -#include +#include "storage.h" #if defined WIN32 || !defined __GNUC__ #include @@ -99,7 +97,7 @@ QStringList getDfuArgs(const QString & cmd, const QString & filename) return args; } -QStringList getSambaArgs(const QString &tcl) +QStringList getSambaArgs(const QString & tcl) { QStringList result; @@ -121,7 +119,7 @@ QStringList getSambaArgs(const QString &tcl) return result; } -QStringList getReadEEpromCmd(const QString &filename) +QStringList getReadEEpromCmd(const QString & filename) { QStringList result; EEPROMInterface *eepromInterface = getCurrentEEpromInterface(); @@ -137,7 +135,7 @@ QStringList getReadEEpromCmd(const QString &filename) return result; } -QStringList getWriteEEpromCmd(const QString &filename) +QStringList getWriteEEpromCmd(const QString & filename) { BoardEnum board = getCurrentBoard(); if (IS_STM32(board)) { @@ -152,7 +150,7 @@ QStringList getWriteEEpromCmd(const QString &filename) } } -QStringList getWriteFirmwareArgs(const QString &filename) +QStringList getWriteFirmwareArgs(const QString & filename) { BoardEnum board = getCurrentBoard(); if (IS_STM32(board)) { @@ -169,7 +167,7 @@ QStringList getWriteFirmwareArgs(const QString &filename) } } -QStringList getReadFirmwareArgs(const QString &filename) +QStringList getReadFirmwareArgs(const QString & filename) { BoardEnum board = getCurrentBoard(); if (IS_STM32(board)) { @@ -186,7 +184,7 @@ QStringList getReadFirmwareArgs(const QString &filename) } } -void readAvrdudeFuses(ProgressWidget *progress) +void readAvrdudeFuses(ProgressWidget * progress) { burnConfigDialog bcd; QStringList args; @@ -195,7 +193,7 @@ void readAvrdudeFuses(ProgressWidget *progress) flashProcess.run(); } -void resetAvrdudeFuses(bool eepromProtect, ProgressWidget *progress) +void resetAvrdudeFuses(bool eepromProtect, ProgressWidget * progress) { //fuses //avrdude -c usbasp -p m64 -U lfuse:w:<0x0E>:m @@ -261,7 +259,7 @@ void resetAvrdudeFuses(bool eepromProtect, ProgressWidget *progress) } -bool readFirmware(const QString &filename, ProgressWidget *progress) +bool readFirmware(const QString & filename, ProgressWidget * progress) { bool result = false; @@ -293,7 +291,7 @@ bool readFirmware(const QString &filename, ProgressWidget *progress) return result; } -bool writeFirmware(const QString &filename, ProgressWidget *progress) +bool writeFirmware(const QString & filename, ProgressWidget * progress) { if (IS_ARM(getCurrentBoard())) { QString path = findMassstoragePath("FIRMWARE.BIN"); @@ -309,53 +307,75 @@ bool writeFirmware(const QString &filename, ProgressWidget *progress) return flashProcess.run(); } - -bool readEeprom(const QString &filename, ProgressWidget *progress) +bool readEeprom(const QString & filename, ProgressWidget * progress) { - bool result = false; + BoardEnum board = getCurrentBoard(); QFile file(filename); if (file.exists() && !file.remove()) { - QMessageBox::warning(NULL, QObject::tr("Error"), QObject::tr("Could not delete temporary file: %1").arg(filename)); + QMessageBox::warning(NULL, + QObject::tr("Error"), + QObject::tr("Could not delete temporary file: %1").arg(filename)); return false; } - if (IS_ARM(getCurrentBoard())) { - QString path = findMassstoragePath("EEPROM.BIN"); - if (path.isEmpty()) { - // On previous OpenTX we called the EEPROM file "TARANIS.BIN" :( - path = findMassstoragePath("TARANIS.BIN"); + if (IS_HORUS(board)) { + QString radioPath = findMassstoragePath("RADIO", true); + qDebug() << "Searching for SD card, found" << radioPath; + if (radioPath.isEmpty()) { + return false; } - if (path.isEmpty()) { - // Mike's bootloader calls the EEPROM file "ERSKY9X.BIN" :( - path = findMassstoragePath("ERSKY9X.BIN"); + RadioData radioData; + Storage inputStorage(radioPath); + if (!inputStorage.load(radioData)) { + return false; } - if (!path.isEmpty()) { + Storage outputStorage(filename); + if (!outputStorage.write(radioData)) { + return false; + } + } + else { + if (IS_ARM(board)) { + QString path = findMassstoragePath("EEPROM.BIN"); + if (path.isEmpty()) { + // On previous OpenTX we called the EEPROM file "TARANIS.BIN" :( + path = findMassstoragePath("TARANIS.BIN"); + } + if (path.isEmpty()) { + // Mike's bootloader calls the EEPROM file "ERSKY9X.BIN" :( + path = findMassstoragePath("ERSKY9X.BIN"); + } + if (path.isEmpty()) { + return false; + } CopyProcess copyProcess(path, filename, progress); - result = copyProcess.run(); + if (!copyProcess.run()) { + return false; + } + } + + if (!IS_STM32(board)) { + FlashProcess flashProcess(getRadioInterfaceCmd(), getReadEEpromCmd(filename), progress); + if (!flashProcess.run()) { + return false; + } + } + + if (IS_ARM(board)) { + RadioNotFoundDialog dialog; + dialog.exec(); } } - if (result == false && !IS_STM32(getCurrentBoard())) { - FlashProcess flashProcess(getRadioInterfaceCmd(), getReadEEpromCmd(filename), progress); - result = flashProcess.run(); - } - - if (result == false && IS_ARM(getCurrentBoard())) { - RadioNotFoundDialog dialog; - dialog.exec(); - } - - if (!QFileInfo(filename).exists()) { - result = false; - } - - return result; + return QFileInfo(filename).exists(); } -bool writeEeprom(const QString &filename, ProgressWidget *progress) +bool writeEeprom(const QString & filename, ProgressWidget * progress) { - if (IS_ARM(getCurrentBoard())) { + BoardEnum board = getCurrentBoard(); + + if (IS_ARM(board)) { QString path = findMassstoragePath("EEPROM.BIN"); if (path.isEmpty()) { // On previous OpenTX we called the EEPROM file "TARANIS.BIN" :( @@ -371,12 +391,12 @@ bool writeEeprom(const QString &filename, ProgressWidget *progress) } } - if (!IS_TARANIS(getCurrentBoard())) { + if (!IS_TARANIS(board)) { FlashProcess flashProcess(getRadioInterfaceCmd(), getWriteEEpromCmd(filename), progress); return flashProcess.run(); } - if (IS_ARM(getCurrentBoard())) { + if (IS_ARM(board)) { RadioNotFoundDialog dialog; dialog.exec(); } @@ -400,7 +420,7 @@ bool isRemovableMedia(const QString & vol) } #endif -QString findMassstoragePath(const QString &filename, bool onlyPath) +QString findMassstoragePath(const QString & filename, bool onlyPath) { QString temppath; QStringList drives;