Does this work? (#4269)

Read an Horus SD card produces a temporary .otx file now
This commit is contained in:
Bertrand Songis
2017-01-22 14:08:13 +01:00
committed by GitHub
parent 9bbc595eb1
commit c21be4845e
3 changed files with 83 additions and 76 deletions
+14 -28
View File
@@ -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);
}
}
+3 -2
View File
@@ -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;
+66 -46
View File
@@ -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 <QFile>
#include <QMessageBox>
#include "storage.h"
#if defined WIN32 || !defined __GNUC__
#include <windows.h>
@@ -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;