From e59a51e25f577014452da2281fc9a9f119d9336d Mon Sep 17 00:00:00 2001 From: Damjan Adamic Date: Thu, 19 Jan 2017 21:26:18 +0100 Subject: [PATCH] =?UTF-8?q?Re=20#4224:=20Enable=20reading=20and=20writing?= =?UTF-8?q?=20Models=20and=20Settings=20from/to=20Horu=E2=80=A6=20(#4254)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Re #4224: Enable reading and writing Models and Settings from/to Horus radio (SD card) * Fix for findMassstoragePath() on Windows (which got there in previous commit) --- companion/src/mainwindow.cpp | 18 +++++++++++++---- companion/src/mdichild.cpp | 34 +++++++++++++++++++++++++------- companion/src/mdichild.h | 1 + companion/src/radiointerface.cpp | 6 +++--- companion/src/radiointerface.h | 2 +- 5 files changed, 46 insertions(+), 15 deletions(-) diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index e7744d74c..13018b3e0 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -740,13 +740,23 @@ void MainWindow::loadBackup() void MainWindow::readEeprom() { - if (getCurrentBoard()== BOARD_HORUS) { - qDebug() << "TODO readEEPROM HORUS"; + 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; - - BoardEnum board = getCurrentBoard(); if (IS_ARM(board)) tempFile = generateProcessUniqueTempFileName("temp.bin"); else diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index e01f98e89..84a28e674 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -31,6 +31,7 @@ #include "wizarddialog.h" #include "flashfirmwaredialog.h" #include "storage.h" +#include "radiointerface.h" #if defined _MSC_VER || !defined __GNUC__ #include @@ -41,6 +42,7 @@ MdiChild::MdiChild(MainWindow * parent): QWidget(), + parent(parent), ui(new Ui::MdiChild), modelsListModel(NULL), firmware(getCurrentFirmware()), @@ -599,14 +601,32 @@ void MdiChild::setCurrentFile(const QString &fileName) void MdiChild::writeEeprom() // write to Tx { - QString tempFile = generateProcessUniqueTempFileName("temp.bin"); - saveFile(tempFile, false); - if (!QFileInfo(tempFile).exists()) { - QMessageBox::critical(this, tr("Error"), tr("Cannot write temporary file!")); - return; + BoardEnum board = getCurrentBoard(); + if (board == BOARD_HORUS) { + QString radioPath = findMassstoragePath("RADIO", true); + qDebug() << "Searching for SD card, found" << radioPath; + if (radioPath.isEmpty()) { + qDebug() << "MdiChild::writeEeprom(): Horus radio not found"; + QMessageBox::critical(this, tr("Error"), tr("Unable to find Horus radio SD card!")); + return; + } + if (saveFile(radioPath, false)) { + parent->statusBar()->showMessage(tr("Models and Settings written"), 2000); + } + else { + qDebug() << "MdiChild::writeEeprom(): saveFile error"; + } + } + else { + QString tempFile = generateProcessUniqueTempFileName("temp.bin"); + saveFile(tempFile, false); + if (!QFileInfo(tempFile).exists()) { + QMessageBox::critical(this, tr("Error"), tr("Cannot write temporary file!")); + return; + } + FlashEEpromDialog * cd = new FlashEEpromDialog(this, tempFile); + cd->exec(); } - FlashEEpromDialog * cd = new FlashEEpromDialog(this, tempFile); - cd->exec(); } void MdiChild::on_radioSettings_clicked() diff --git a/companion/src/mdichild.h b/companion/src/mdichild.h index 5a31b54cc..d1834a0f5 100644 --- a/companion/src/mdichild.h +++ b/companion/src/mdichild.h @@ -100,6 +100,7 @@ class MdiChild : public QWidget void doPaste(QByteArray * gmData, int index); void initModelsList(); + MainWindow * parent; Ui::MdiChild * ui; TreeModel * modelsListModel; diff --git a/companion/src/radiointerface.cpp b/companion/src/radiointerface.cpp index e87389851..515b1fdf0 100644 --- a/companion/src/radiointerface.cpp +++ b/companion/src/radiointerface.cpp @@ -400,7 +400,7 @@ bool isRemovableMedia(const QString & vol) } #endif -QString findMassstoragePath(const QString &filename) +QString findMassstoragePath(const QString &filename, bool onlyPath) { QString temppath; QStringList drives; @@ -426,7 +426,7 @@ QString findMassstoragePath(const QString &filename) eepromfile = temppath; eepromfile.append("/" + filename); if (QFile::exists(eepromfile)) { - return eepromfile; + return onlyPath ? temppath : eepromfile; } } } @@ -452,7 +452,7 @@ QString findMassstoragePath(const QString &filename) if (QFile::exists(eepromfile)) { #endif free_file_system_list(firstEntry); - return eepromfile; + return onlyPath ? temppath : eepromfile; } } entry = entry->me_next; diff --git a/companion/src/radiointerface.h b/companion/src/radiointerface.h index 270d8f1ff..f896d96c5 100644 --- a/companion/src/radiointerface.h +++ b/companion/src/radiointerface.h @@ -28,7 +28,7 @@ class ProgressWidget; QString getRadioInterfaceCmd(); -QString findMassstoragePath(const QString &filename); +QString findMassstoragePath(const QString &filename, bool onlyPath = false); QStringList getAvrdudeArgs(const QString &cmd, const QString &filename); QStringList getSambaArgs(const QString &tcl);