From 6d520392666c7b17e1d422993bce54fab328491b Mon Sep 17 00:00:00 2001 From: Grieb Date: Thu, 27 Aug 2015 14:54:45 -0300 Subject: [PATCH 1/2] Refactoring to have messages in Companion when opening eeprom. --- companion/src/converteeprom.cpp | 5 +- companion/src/eeprominterface.cpp | 123 ++++++++++++++---- companion/src/eeprominterface.h | 40 +++++- .../src/firmwares/er9x/er9xinterface.cpp | 39 ++++-- companion/src/firmwares/er9x/er9xinterface.h | 26 ++-- .../firmwares/ersky9x/ersky9xinterface.cpp | 45 ++++--- .../src/firmwares/ersky9x/ersky9xinterface.h | 6 +- .../firmwares/gruvin9x/gruvin9xinterface.cpp | 58 ++++++--- .../firmwares/gruvin9x/gruvin9xinterface.h | 15 ++- .../src/firmwares/opentx/opentxinterface.cpp | 76 +++++++---- .../src/firmwares/opentx/opentxinterface.h | 20 +-- .../src/firmwares/th9x/th9xinterface.cpp | 34 +++-- companion/src/firmwares/th9x/th9xinterface.h | 6 +- companion/src/flasheepromdialog.cpp | 10 +- companion/src/mainwindow.cpp | 86 ++++++------ companion/src/mdichild.cpp | 64 +++++---- companion/src/xmlinterface.cpp | 6 +- 17 files changed, 433 insertions(+), 226 deletions(-) diff --git a/companion/src/converteeprom.cpp b/companion/src/converteeprom.cpp index 8c75be049..065123d29 100755 --- a/companion/src/converteeprom.cpp +++ b/companion/src/converteeprom.cpp @@ -26,8 +26,11 @@ bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom sourceFile.close(); QSharedPointer radioData = QSharedPointer(new RadioData()); - if (!loadEEprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size) || !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version)) + std::bitset errors(LoadEeprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size)); + if (!errors.test(NO_ERROR) + || !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version)) { return false; + } QFile destinationFile(destinationEEprom); if (!destinationFile.open(QIODevice::WriteOnly)) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index f06b5eb8e..e1ef47b02 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -481,7 +481,7 @@ QString RawSource::toString(const ModelData * model) const QObject::tr("L21"), QObject::tr("L22"), QObject::tr("L23"), QObject::tr("L24"), QObject::tr("L25"), QObject::tr("L26"), QObject::tr("L27"), QObject::tr("L28"), QObject::tr("L29"), QObject::tr("L30"), QObject::tr("L31"), QObject::tr("L32") }; - + if (index<0) { return QObject::tr("----"); } @@ -528,7 +528,7 @@ QString RawSource::toString(const ModelData * model) const return CHECK_IN_ARRAY(telemetry, index); } case SOURCE_TYPE_GVAR: - return QObject::tr("GV%1").arg(index+1); + return QObject::tr("GV%1").arg(index+1); default: return QObject::tr("----"); } @@ -536,15 +536,15 @@ QString RawSource::toString(const ModelData * model) const bool RawSource::isPot() const { - return (type == SOURCE_TYPE_STICK && - index >= NUM_STICKS && + return (type == SOURCE_TYPE_STICK && + index >= NUM_STICKS && index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)); } bool RawSource::isSlider() const { - return (type == SOURCE_TYPE_STICK && - index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) && + return (type == SOURCE_TYPE_STICK && + index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) && index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders)); } @@ -858,7 +858,7 @@ void CustomFunctionData::populatePlaySoundParams(QStringList & qs) qs << "SciFi" << "Robot" << "Chirp" << "Tada" << "Crickt" << "AlmClk" ; } -void CustomFunctionData::populateHapticParams(QStringList & qs) +void CustomFunctionData::populateHapticParams(QStringList & qs) { qs << "0" << "1" << "2" << "3"; } @@ -892,7 +892,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const int pos = cb.findData(param); if (pos >= 0) return cb.itemText(pos); - else + else return QObject::tr("Inconsistent parameter"); } else if ((func==FuncVolume)|| (func==FuncPlayValue)) { @@ -1608,7 +1608,7 @@ void registerEEpromInterfaces() eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_SKY9X)); eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_9XRPRO)); eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS)); - eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_PLUS)); + eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_PLUS)); eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS_X9E)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X)); @@ -1622,7 +1622,7 @@ void unregisterEEpromInterfaces() foreach(EEPROMInterface * intf, eepromInterfaces) { // qDebug() << "UnregisterEepromInterfaces(): deleting " << QString::number( reinterpret_cast(intf), 16 ); delete intf; - } + } OpenTxEepromCleanup(); } @@ -1637,35 +1637,112 @@ void unregisterFirmwares() } } -bool loadEEprom(RadioData &radioData, const uint8_t *eeprom, const int size) +void ShowEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound) { - foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { - if (eepromInterface->load(radioData, eeprom, size)) - return true; + std::bitset errors(errorsFound); + QStringList errorsList; + + errorsList << QT_TRANSLATE_NOOP("EepromInterface", "Possible causes for this:"); + + if (errors.test(UNSUPPORTED_NEWER_VERSION)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is from a newer version of OpenTX"); } + if (errors.test(NOT_OPENTX)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is not from OpenTX"); } + if (errors.test(NOT_TH9X)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is not from Th9X"); } + if (errors.test(NOT_GRUVIN9X)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is not from Gruvin9X"); } + if (errors.test(NOT_ERSKY9X)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is not from ErSky9X"); } + if (errors.test(NOT_ER9X)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is not from Er9X"); } + if (errors.test(WRONG_SIZE)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom size is invalid"); } + if (errors.test(WRONG_FILE_SYSTEM)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom file system is invalid"); } + if (errors.test(UNKNOWN_BOARD)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is from a unknown board"); } + if (errors.test(WRONG_BOARD)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom is from the wrong board"); } + if (errors.test(BACKUP_NOT_SUPPORTED)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Eeprom backup not supported"); } + + if (errors.test(UNKNOWN_ERROR)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Something that couldn't be guessed, sorry"); } + + if (errors.test(HAS_WARNINGS)) { + errorsList << QT_TRANSLATE_NOOP("EepromInterface", "Warning:"); + if (errors.test(WARNING_WRONG_FIRMWARE)) { errorsList << QT_TRANSLATE_NOOP("EepromInterface", "- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"); } } - return false; + QMessageBox msgBox(parent); + msgBox.setWindowTitle(title); + msgBox.setIcon(QMessageBox::Critical); + msgBox.setText(mainMessage); + msgBox.setInformativeText(errorsList.join("\n")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); } -bool loadBackup(RadioData &radioData, uint8_t *eeprom, int size, int index) +void ShowEepromWarnings(QWidget *parent, const QString &title, unsigned long errorsFound) { + std::bitset errors(errorsFound); + QStringList warningsList; + if (errors.test(WARNING_WRONG_FIRMWARE)) { warningsList << QT_TRANSLATE_NOOP("EepromInterface", "- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"); } + + QMessageBox msgBox(parent); + msgBox.setWindowTitle(title); + msgBox.setIcon(QMessageBox::Warning); + msgBox.setText(QT_TRANSLATE_NOOP("EepromInterface", "Warnings!")); + msgBox.setInformativeText(warningsList.join("\n")); + msgBox.setStandardButtons(QMessageBox::Ok); + msgBox.exec(); +} + +unsigned long LoadEeprom(RadioData &radioData, const uint8_t *eeprom, const int size) +{ + std::bitset errors; + foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { - if (eepromInterface->loadBackup(radioData, eeprom, size, index)) - return true; + std::bitset result(eepromInterface->load(radioData, eeprom, size)); + if (result.test(NO_ERROR)) { + return result.to_ulong(); + } else { + errors |= result; + } } - return false; + if (errors.none()) { + errors.set(UNKNOWN_ERROR); + } + return errors.to_ulong(); +} + +unsigned long LoadBackup(RadioData &radioData, uint8_t *eeprom, int size, int index) +{ + std::bitset errors; + + foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { + std::bitset result(eepromInterface->loadBackup(radioData, eeprom, size, index)); + if (result.test(NO_ERROR)) { + return result.to_ulong(); + } else { + errors |= result; + } + } + + if (errors.none()) { + errors.set(UNKNOWN_ERROR); + } + return errors.to_ulong(); } -bool loadEEpromXml(RadioData &radioData, QDomDocument &doc) +unsigned long LoadEepromXml(RadioData &radioData, QDomDocument &doc) { + std::bitset errors; + foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { - if (eepromInterface->loadxml(radioData, doc)) - return true; + std::bitset result(eepromInterface->loadxml(radioData, doc)); + if (result.test(NO_ERROR)) { + return result.to_ulong(); + } else { + errors |= result; + } } - return false; + if (errors.none()) { + errors.set(UNKNOWN_ERROR); + } + return errors.to_ulong(); } QString getBoardName(BoardEnum board) diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 69cd2d61f..88849b723 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -24,6 +24,7 @@ #include #include #include +#include #include "constants.h" #include "simulatorinterface.h" @@ -841,7 +842,7 @@ class ModuleData { int failsafeChannels[C9X_NUM_CHNOUT]; int ppmDelay; bool ppmPulsePol; // false = positive - bool ppmOutputType; // false = open drain, true = push pull + bool ppmOutputType; // false = open drain, true = push pull int ppmFrameLength; void clear() { memset(this, 0, sizeof(ModuleData)); } QString polarityToString() const { return ppmPulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter @@ -1353,11 +1354,11 @@ class EEPROMInterface inline BoardEnum getBoard() { return board; } - virtual bool load(RadioData &radioData, const uint8_t *eeprom, int size) = 0; + virtual unsigned long load(RadioData &radioData, const uint8_t *eeprom, int size) = 0; - virtual bool loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) = 0; + virtual unsigned long loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) = 0; - virtual bool loadxml(RadioData &radioData, QDomDocument &doc) = 0; + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc) = 0; virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0) = 0; @@ -1480,9 +1481,34 @@ void unregisterEEpromInterfaces(); void registerOpenTxFirmwares(); void unregisterFirmwares(); -bool loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index); -bool loadEEprom(RadioData &radioData, const uint8_t *eeprom, int size); -bool loadEEpromXml(RadioData &radioData, QDomDocument &doc); +enum EepromLoadErrors { + NO_ERROR, + + UNKNOWN_ERROR, + UNSUPPORTED_NEWER_VERSION, + WRONG_SIZE, + WRONG_FILE_SYSTEM, + NOT_OPENTX, + NOT_TH9X, + NOT_GRUVIN9X, + NOT_ERSKY9X, + NOT_ER9X, + UNKNOWN_BOARD, + WRONG_BOARD, + BACKUP_NOT_SUPPORTED, + + HAS_WARNINGS, + WARNING_WRONG_FIRMWARE, + + NUM_ERRORS +}; + +void ShowEepromErrors(QWidget *parent, const QString &title, const QString &mainMessage, unsigned long errorsFound); +void ShowEepromWarnings(QWidget *parent, const QString &title, unsigned long errorsFound); + +unsigned long LoadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index); +unsigned long LoadEeprom(RadioData &radioData, const uint8_t *eeprom, int size); +unsigned long LoadEepromXml(RadioData &radioData, QDomDocument &doc); struct Option { const char * name; diff --git a/companion/src/firmwares/er9x/er9xinterface.cpp b/companion/src/firmwares/er9x/er9xinterface.cpp index a04678b4b..f7859f1f0 100644 --- a/companion/src/firmwares/er9x/er9xinterface.cpp +++ b/companion/src/firmwares/er9x/er9xinterface.cpp @@ -89,14 +89,17 @@ inline void applyStickModeToModel(Er9xModelData & model, unsigned int mode) model.swashCollectiveSource = applyStickMode(model.swashCollectiveSource, mode); } -bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) +unsigned long Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) { std::cout << "trying er9x xml import... "; + std::bitset errors; + Er9xGeneral er9xGeneral; memset(&er9xGeneral,0,sizeof(er9xGeneral)); if(!loadGeneralDataXML(&doc, &er9xGeneral)) { - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } else { radioData.generalSettings=er9xGeneral; std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; @@ -111,21 +114,26 @@ bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) } } std::cout << "ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } -bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) +unsigned long Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying er9x import... "; + std::bitset errors; + if (size != getEEpromSize()) { std::cout << "wrong size\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { std::cout << "wrong file system\n"; - return false; + errors.set(WRONG_FILE_SYSTEM); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); @@ -133,7 +141,8 @@ bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) if (efile->readRlc1((uint8_t*)&er9xGeneral, 1) != 1) { std::cout << "no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; @@ -151,13 +160,16 @@ bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) break; default: std::cout << "not er9x\n"; - return false; + errors.set(NOT_ER9X); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); if (!efile->readRlc1((uint8_t*)&er9xGeneral, sizeof(Er9xGeneral))) { std::cout << "ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); + } radioData.generalSettings = er9xGeneral; @@ -174,12 +186,15 @@ bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) } std::cout << "ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } -bool Er9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) +unsigned long Er9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } int Er9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) diff --git a/companion/src/firmwares/er9x/er9xinterface.h b/companion/src/firmwares/er9x/er9xinterface.h index 0dbff2b88..8774fa441 100644 --- a/companion/src/firmwares/er9x/er9xinterface.h +++ b/companion/src/firmwares/er9x/er9xinterface.h @@ -1,6 +1,6 @@ /* * Author - Bertrand Songis - * + * * Based on th9x -> http://code.google.com/p/th9x/ * * This program is free software; you can redistribute it and/or modify @@ -29,21 +29,21 @@ class Er9xInterface : public EEPROMInterface virtual ~Er9xInterface(); virtual const char * getName(); - + virtual const int getEEpromSize(); virtual const int getMaxModels(); - virtual bool load(RadioData &, const uint8_t * eeprom, int size); + virtual unsigned long load(RadioData &, const uint8_t * eeprom, int size); - virtual bool loadBackup(RadioData &, uint8_t * eeprom, int esize, int index); - - virtual bool loadxml(RadioData &radioData, QDomDocument &doc); + virtual unsigned long loadBackup(RadioData &, uint8_t * eeprom, int esize, int index); + + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); virtual int save(uint8_t * eeprom, RadioData & radioData, uint32_t variant=0, uint8_t version=0); virtual int getSize(const ModelData &); - + virtual int getSize(const GeneralSettings &settings); virtual int isAvailable(PulsesProtocol proto, int port=0); @@ -54,17 +54,17 @@ class Er9xInterface : public EEPROMInterface private: void appendTextElement(QDomDocument * qdoc, QDomElement * pe, QString name, QString value); - + void appendNumberElement(QDomDocument * qdoc, QDomElement * pe,QString name, int value, bool forceZeroWrite = false); - + void appendCDATAElement(QDomDocument * qdoc, QDomElement * pe,QString name, const char * data, int size); - + QDomElement getGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen); //parse out data to XML format - + QDomElement getModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum, int mdver); //parse out data to XML format - + bool loadGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen); // get data from XML - + bool loadModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum = -1); // get data from XML }; diff --git a/companion/src/firmwares/ersky9x/ersky9xinterface.cpp b/companion/src/firmwares/ersky9x/ersky9xinterface.cpp index 958853d1f..8b4721e45 100644 --- a/companion/src/firmwares/ersky9x/ersky9xinterface.cpp +++ b/companion/src/firmwares/ersky9x/ersky9xinterface.cpp @@ -15,7 +15,6 @@ */ #include -#include #include "ersky9xinterface.h" #include "ersky9xeeprom.h" #include "simulator/ersky9xsimulator.h" @@ -120,14 +119,17 @@ inline void applyStickModeToModel(Ersky9xModelData_v11 & model, unsigned int mod model.swashCollectiveSource = applyStickMode(model.swashCollectiveSource, mode); } -bool Ersky9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) +unsigned long Ersky9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) { std::cout << "trying ersky9x xml import... "; + std::bitset errors; + Ersky9xGeneral ersky9xGeneral; memset(&ersky9xGeneral,0,sizeof(ersky9xGeneral)); if(!loadGeneralDataXML(&doc, &ersky9xGeneral)) { - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } else { radioData.generalSettings=ersky9xGeneral; @@ -137,32 +139,39 @@ bool Ersky9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) if (ersky9xGeneral.myVers == 10) { if (!loadModelDataXML(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) { std::cout << "ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } } else { if (!loadModelDataXML(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) { std::cout << "ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } } } std::cout << "ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } -bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) +unsigned long Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying ersky9x import... "; + std::bitset errors; + if (size != EESIZE_SKY9X) { std::cout << "wrong size\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_SKY9X)) { std::cout << "wrong file system\n"; - return false; + errors.set(WRONG_FILE_SYSTEM); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); @@ -170,7 +179,8 @@ bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int siz if (efile->readRlc2((uint8_t*)&ersky9xGeneral, 1) != 1) { std::cout << "no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } std::cout << "version " << (unsigned int)ersky9xGeneral.myVers << " "; @@ -182,12 +192,14 @@ bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int siz break; default: std::cout << "not ersky9x\n"; - return false; + errors.set(NOT_ERSKY9X); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); if (!efile->readRlc2((uint8_t*)&ersky9xGeneral, sizeof(Ersky9xGeneral))) { std::cout << "ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } radioData.generalSettings = ersky9xGeneral; @@ -218,12 +230,15 @@ bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int siz } std::cout << "ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } -bool Ersky9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) +unsigned long Ersky9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } int Ersky9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) diff --git a/companion/src/firmwares/ersky9x/ersky9xinterface.h b/companion/src/firmwares/ersky9x/ersky9xinterface.h index 47c3b9687..3a2a0eae8 100644 --- a/companion/src/firmwares/ersky9x/ersky9xinterface.h +++ b/companion/src/firmwares/ersky9x/ersky9xinterface.h @@ -34,11 +34,11 @@ class Ersky9xInterface : public EEPROMInterface virtual const int getMaxModels(); - virtual bool load(RadioData &, const uint8_t * eeprom, int size); + virtual unsigned long load(RadioData &, const uint8_t * eeprom, int size); - virtual bool loadBackup(RadioData &, uint8_t * eeprom, int esize, int index); + virtual unsigned long loadBackup(RadioData &, uint8_t * eeprom, int esize, int index); - virtual bool loadxml(RadioData &radioData, QDomDocument &doc); + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); virtual int save(uint8_t * eeprom, RadioData & radioData, uint32_t variant=0, uint8_t version=0); diff --git a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp b/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp index d038efdf9..007b492eb 100644 --- a/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp +++ b/companion/src/firmwares/gruvin9x/gruvin9xinterface.cpp @@ -93,24 +93,30 @@ bool Gruvin9xInterface::loadGeneral(GeneralSettings &settings, int version) return false; } -bool Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) +unsigned long Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } -bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) +unsigned long Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying " << getName() << " import... "; + std::bitset errors; + if (size != this->getEEpromSize()) { std::cout << "wrong size\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { std::cout << "wrong file system\n"; - return false; + errors.set(WRONG_FILE_SYSTEM); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); @@ -118,14 +124,16 @@ bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int si uint8_t version; if (efile->readRlc2(&version, 1) != 1) { std::cout << "no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } if (version == 0) { efile->openRd(FILE_GENERAL); if (efile->readRlc1(&version, 1) != 1) { std::cout << "no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } } @@ -145,25 +153,33 @@ bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int si break; default: std::cout << "not gruvin9x\n"; - return false; + errors.set(NOT_GRUVIN9X); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); if (version == 5) { - if (!loadGeneral(radioData.generalSettings, 1)) - return false; + if (!loadGeneral(radioData.generalSettings, 1)) { + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); + } } else if (version < 104) { - if (!loadGeneral(radioData.generalSettings)) - return false; + if (!loadGeneral(radioData.generalSettings)) { + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); + } } else if (version <= 106) { - if (!loadGeneral(radioData.generalSettings)) - return false; + if (!loadGeneral(radioData.generalSettings)) { + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); + } } else { std::cout << "ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } for (int i=0; i errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } int Gruvin9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) diff --git a/companion/src/firmwares/gruvin9x/gruvin9xinterface.h b/companion/src/firmwares/gruvin9x/gruvin9xinterface.h index 84482df06..152cd5862 100644 --- a/companion/src/firmwares/gruvin9x/gruvin9xinterface.h +++ b/companion/src/firmwares/gruvin9x/gruvin9xinterface.h @@ -1,6 +1,6 @@ /* * Author - Bertrand Songis - * + * * Based on th9x -> http://code.google.com/p/th9x/ * * This program is free software; you can redistribute it and/or modify @@ -30,21 +30,22 @@ class Gruvin9xInterface : public EEPROMInterface virtual ~Gruvin9xInterface(); virtual const char * getName(); - + virtual const int getEEpromSize(); virtual const int getMaxModels(); - virtual bool load(RadioData &, const uint8_t *eeprom, int size); + virtual unsigned long load(RadioData &, const uint8_t *eeprom, int size); - virtual bool loadBackup(RadioData &, uint8_t *eeprom,int esize, int index); - - virtual bool loadxml(RadioData &radioData, QDomDocument &doc); + + virtual unsigned long loadBackup(RadioData &, uint8_t *eeprom,int esize, int index); + + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0); virtual int getSize(const ModelData &); - + virtual int getSize(const GeneralSettings & settings); virtual int isAvailable(PulsesProtocol proto, int port=0); diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index b1915eb5a..b4c14ad85 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -307,15 +307,19 @@ bool OpenTxEepromInterface::saveModel(unsigned int index, ModelData &model, unsi return (sz == eeprom.size()); } -bool OpenTxEepromInterface::loadxml(RadioData &radioData, QDomDocument &doc) +unsigned long OpenTxEepromInterface::loadxml(RadioData &radioData, QDomDocument &doc) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } -bool OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) +unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying " << getName() << " import..."; + std::bitset errors; + if (size != getEEpromSize()) { if (size==4096) { int notnull=false; @@ -326,21 +330,25 @@ bool OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, in } if (notnull) { std::cout << " wrong size (" << size << ")\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } else { - QMessageBox::warning(NULL, "companion", QObject::tr("Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used")); + errors.set(HAS_WARNINGS); + errors.set(WARNING_WRONG_FIRMWARE); size=2048; } } else { std::cout << " wrong size (" << size << "/" << getEEpromSize() << ")\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } } if (!efile->EeFsOpen((uint8_t *)eeprom, size, board)) { std::cout << " wrong file system\n"; - return false; + errors.set(WRONG_FILE_SYSTEM); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); @@ -348,30 +356,36 @@ bool OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, in uint8_t version; if (efile->readRlc2(&version, 1) != 1) { std::cout << " no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } std::cout << " version " << (unsigned int)version; - if (!checkVersion(version)) { + EepromLoadErrors version_error = checkVersion(version); + if (version_error != NO_ERROR) { std::cout << " not open9x\n"; - return false; + errors.set(version_error); + return errors.to_ulong(); } if (!loadGeneral(radioData.generalSettings, version)) { std::cout << " ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } std::cout << " variant " << radioData.generalSettings.variant; for (int i=0; i errors; + std::cout << "trying " << getName() << " backup import..."; if (esize < 8 || memcmp(eeprom, "o9x", 3) != 0) { std::cout << " no\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } BoardEnum backupBoard = (BoardEnum)-1; @@ -1013,12 +1030,14 @@ bool OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, in break; default: std::cout << " unknown board\n"; - return false; + errors.set(UNKNOWN_BOARD); + return errors.to_ulong(); } if (backupBoard != board) { std::cout << " not right board\n"; - return false; + errors.set(WRONG_BOARD); + return errors.to_ulong(); } uint8_t version = eeprom[4]; @@ -1030,27 +1049,32 @@ bool OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, in if (!checkVersion(version)) { std::cout << " not open9x\n"; - return false; + errors.set(NOT_OPENTX); + return errors.to_ulong(); } if (size > esize-8) { std::cout << " wrong size\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } if (bcktype=='M') { if (!loadModel(version, radioData.models[index], &eeprom[8], size, variant)) { std::cout << " ko\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } } else { std::cout << " backup type not supported\n"; - return false; + errors.set(BACKUP_NOT_SUPPORTED); + return errors.to_ulong(); } std::cout << " ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } QString OpenTxFirmware::getFirmwareBaseUrl() @@ -1346,7 +1370,7 @@ void registerOpenTxFirmwares() firmware->addOption("bluetooth", QObject::tr("Bluetooth interface")); addOpenTxCommonOptions(firmware); firmwares.push_back(firmware); - + /* ar9x board */ firmware = new OpenTxFirmware("opentx-ar9x", QObject::tr("ar9x board / 9X"), BOARD_AR9X); firmware->addOption("heli", QObject::tr("Enable HELI menu and cyclic mix support")); diff --git a/companion/src/firmwares/opentx/opentxinterface.h b/companion/src/firmwares/opentx/opentxinterface.h index e830f139a..e7db6737a 100644 --- a/companion/src/firmwares/opentx/opentxinterface.h +++ b/companion/src/firmwares/opentx/opentxinterface.h @@ -1,6 +1,6 @@ /* * Author - Bertrand Songis - * + * * Based on th9x -> http://code.google.com/p/th9x/ * * This program is free software; you can redistribute it and/or modify @@ -33,25 +33,25 @@ class OpenTxEepromInterface : public EEPROMInterface virtual const int getMaxModels(); - virtual bool load(RadioData &, const uint8_t *eeprom, int size); + virtual unsigned long load(RadioData &, const uint8_t *eeprom, int size); - virtual bool loadBackup(RadioData &, uint8_t *eeprom, int esize, int index); - - virtual bool loadxml(RadioData &radioData, QDomDocument &doc); + virtual unsigned long loadBackup(RadioData &, uint8_t *eeprom, int esize, int index); + + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0); virtual int getSize(const ModelData &); virtual int getSize(const GeneralSettings &); - + virtual int isAvailable(PulsesProtocol proto, int port=0); - + protected: const char * getName(); - bool checkVersion(unsigned int version); + EepromLoadErrors checkVersion(unsigned int version); bool checkVariant(unsigned int version, unsigned int variant); @@ -112,7 +112,7 @@ class OpenTxFirmware: public Firmware { } virtual Firmware * getFirmwareVariant(const QString & id); - + virtual QString getStampUrl(); virtual QString getReleaseNotesUrl(); @@ -122,7 +122,7 @@ class OpenTxFirmware: public Firmware { virtual int getCapability(const Capability); virtual bool isTelemetrySourceAvailable(int source); - + protected: QString getFirmwareBaseUrl(); diff --git a/companion/src/firmwares/th9x/th9xinterface.cpp b/companion/src/firmwares/th9x/th9xinterface.cpp index ebff0a673..ca8781d3b 100644 --- a/companion/src/firmwares/th9x/th9xinterface.cpp +++ b/companion/src/firmwares/th9x/th9xinterface.cpp @@ -57,23 +57,29 @@ const int Th9xInterface::getMaxModels() return 16; } -bool Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) +unsigned long Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } -bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) +unsigned long Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) { std::cout << "trying th9x import... "; + std::bitset errors; + if (size != getEEpromSize()) { std::cout << "wrong size\n"; - return false; + errors.set(WRONG_SIZE); + return errors.to_ulong(); } if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { std::cout << "wrong file system\n"; - return false; + errors.set(WRONG_FILE_SYSTEM); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); @@ -81,7 +87,8 @@ bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) if (efile->readRlc2((uint8_t*)&th9xGeneral, 1) != 1) { std::cout << "no\n"; - return false; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } std::cout << "version " << (unsigned int)th9xGeneral.myVers << " "; @@ -91,14 +98,16 @@ bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) break; default: std::cout << "not th9x\n"; - return false; + errors.set(NOT_TH9X); + return errors.to_ulong(); } efile->openRd(FILE_GENERAL); int len = efile->readRlc2((uint8_t*)&th9xGeneral, sizeof(Th9xGeneral)); if (len != sizeof(Th9xGeneral)) { std::cout << "not th9x\n"; - return false; + errors.set(NOT_TH9X); + return errors.to_ulong(); } radioData.generalSettings = th9xGeneral; @@ -114,12 +123,15 @@ bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size) } std::cout << "ok\n"; - return true; + errors.set(NO_ERROR); + return errors.to_ulong(); } -bool Th9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) +unsigned long Th9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) { - return false; + std::bitset errors; + errors.set(UNKNOWN_ERROR); + return errors.to_ulong(); } int Th9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) diff --git a/companion/src/firmwares/th9x/th9xinterface.h b/companion/src/firmwares/th9x/th9xinterface.h index 9c7a3bf4f..d1be1fc8f 100644 --- a/companion/src/firmwares/th9x/th9xinterface.h +++ b/companion/src/firmwares/th9x/th9xinterface.h @@ -34,11 +34,11 @@ class Th9xInterface : public EEPROMInterface virtual const int getMaxModels(); - virtual bool load(RadioData &, const uint8_t *eeprom, int size); + virtual unsigned long load(RadioData &, const uint8_t *eeprom, int size); - virtual bool loadBackup(RadioData &, uint8_t *eeprom, int esize, int index); + virtual unsigned long loadBackup(RadioData &, uint8_t *eeprom, int esize, int index); - virtual bool loadxml(RadioData &radioData, QDomDocument &doc); + virtual unsigned long loadxml(RadioData &radioData, QDomDocument &doc); virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0); diff --git a/companion/src/flasheepromdialog.cpp b/companion/src/flasheepromdialog.cpp index f077e9976..b1dbee9a4 100755 --- a/companion/src/flasheepromdialog.cpp +++ b/companion/src/flasheepromdialog.cpp @@ -104,7 +104,7 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename) QByteArray eeprom(EESIZE_MAX, 0); int fileType = getFileType(filename); - + #if 0 if (fileType==FILE_TYPE_XML) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { @@ -125,7 +125,8 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename) bool xmlOK = doc.setContent(&file); if (xmlOK) { RadioData * radioData = new RadioData(); - if (!loadEEpromXml(*radioData, doc)) { + std::bitset errors(LoadEepromXml(*radioData, doc)); + if (!errors.test(NO_ERROR)) { QMessageBox::warning(this, tr("Error"), tr("Invalid Models and Settings File %1").arg(filename)); } else { @@ -160,7 +161,8 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename) } RadioData * radioData = new RadioData(); - if (eeprom_size == 0 || !loadEEprom(*radioData, (const uint8_t *)eeprom.data(), eeprom_size)) { + std::bitset errors(LoadEeprom(*radioData, (const uint8_t *)eeprom.data(), eeprom_size)); + if (eeprom_size == 0 || !errors.test(NO_ERROR)) { QMessageBox::warning(this, tr("Error"), tr("Invalid Models and Settings file %1").arg(filename)); } else { @@ -303,7 +305,7 @@ void FlashEEpromDialog::on_burnButton_clicked() backupPath = g.profile[g.id()].pBackupDir(); if (backupPath.isEmpty()) { backupPath=g.backupDir(); - } + } backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin"; } else if (ui->checkFirmwareCompatibility->isChecked()) { diff --git a/companion/src/mainwindow.cpp b/companion/src/mainwindow.cpp index 1fa723f5f..2460d461a 100644 --- a/companion/src/mainwindow.cpp +++ b/companion/src/mainwindow.cpp @@ -115,12 +115,12 @@ MainWindow::MainWindow(): this->setIconSize(QSize(32, 32)); QNetworkProxyFactory::setUseSystemConfiguration(true); setAcceptDrops(true); - + // give time to the splash to disappear and main window to open before starting updates int updateDelay = 1000; bool showSplash = g.showSplash(); if (showSplash) { - updateDelay += (SPLASH_TIME*1000); + updateDelay += (SPLASH_TIME*1000); } QTimer::singleShot(updateDelay, this, SLOT(doAutoUpdates())); QTimer::singleShot(updateDelay, this, SLOT(displayWarnings())); @@ -158,13 +158,13 @@ MainWindow::MainWindow(): child->show(); } else { - child->show(); + child->show(); child->print(model,printfilename); child->close(); } } } - } + } if (printing) { QTimer::singleShot(0, this, SLOT(autoClose())); } @@ -185,7 +185,7 @@ void MainWindow::displayWarnings() } } else if (warnId==0) { - g.warningId(WARNING_ID); + g.warningId(WARNING_ID); } } @@ -292,15 +292,15 @@ void MainWindow::checkForCompanionUpdateFinished(QNetworkReply * reply) int c9xver = version2index(c9xversion); if (c9xver < vnum) { -#if defined WIN32 || !defined __GNUC__ // || defined __APPLE__ // OSX should only notify of updates since no update packages are available. +#if defined WIN32 || !defined __GNUC__ // || defined __APPLE__ // OSX should only notify of updates since no update packages are available. int ret = QMessageBox::question(this, "Companion", tr("A new version of Companion is available (version %1)
" "Would you like to download it?").arg(version) , QMessageBox::Yes | QMessageBox::No); if (ret == QMessageBox::Yes) { -#if defined __APPLE__ +#if defined __APPLE__ QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.updatesDir() + QString(COMPANION_INSTALLER).arg(version)); -#else +#else QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.updatesDir() + QString(COMPANION_INSTALLER).arg(version), tr("Executable (*.exe)")); #endif if (!fileName.isEmpty()) { @@ -313,7 +313,7 @@ void MainWindow::checkForCompanionUpdateFinished(QNetworkReply * reply) } #else QMessageBox::warning(this, tr("New release available"), tr("A new release of Companion is available, please check the OpenTX website!")); -#endif +#endif } else { if (downloadDialog_forWait && checkForUpdatesState==0) { @@ -539,19 +539,19 @@ void MainWindow::closeEvent(QCloseEvent *event) } void MainWindow::setLanguage(const QString & langString) -{ +{ g.locale(langString); QMessageBox::information(this, tr("Companion"), tr("The selected language will be used the next time you start Companion.")); } void MainWindow::setTheme(int index) -{ +{ g.theme(index); QMessageBox::information(this, tr("Companion"), tr("The new theme will be loaded the next time you start Companion.")); } void MainWindow::setIconThemeSize(int index) -{ +{ g.iconSize(index); QMessageBox::information(this, tr("Companion"), tr("The icon size will be used the next time you start Companion.")); } @@ -705,7 +705,7 @@ void MainWindow::fwchangelog() } void MainWindow::customizeSplash() -{ +{ customizeSplashDialog * dialog = new customizeSplashDialog(this); dialog->exec(); } @@ -763,7 +763,7 @@ void MainWindow::readEeprom() EEPROMInterface *eepromInterface = GetEepromInterface(); - if (IS_ARM(eepromInterface->getBoard())) + if (IS_ARM(eepromInterface->getBoard())) tempFile = generateProcessUniqueTempFileName("temp.bin"); else tempFile += generateProcessUniqueTempFileName("temp.hex"); @@ -920,7 +920,7 @@ void MainWindow::updateMenus() pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false); writeEepromAct->setEnabled(hasMdiChild); separatorAct->setVisible(hasMdiChild); - + bool hasSelection = (activeMdiChild() && activeMdiChild()->hasSelection()); cutAct->setEnabled(hasSelection); copyAct->setEnabled(hasSelection); @@ -962,7 +962,7 @@ QAction * MainWindow::addAct(const QString & icon, const QString & sName, const QAction * newAction = new QAction( this ); if (!icon.isEmpty()) newAction->setIcon(CompanionIcon(icon)); - if (!sName.isEmpty()) + if (!sName.isEmpty()) newAction->setText(sName); if (!lName.isEmpty()) newAction->setStatusTip(lName); @@ -983,7 +983,7 @@ QAction * MainWindow::addAct(QActionGroup *aGroup, const QString & sName, const { QAction *action = addAct("", sName, lName, QKeySequence::UnknownKey, slot); action->setCheckable(true); - aGroup->addAction(action); + aGroup->addAction(action); return action; } @@ -1017,7 +1017,7 @@ void MainWindow::createActions() cutAct = addAct("cut.png", tr("Cut Model"), tr("Cut current model to the clipboard"), QKeySequence::Cut, SLOT(cut())); copyAct = addAct("copy.png", tr("Copy Model"), tr("Copy current model to the clipboard"), QKeySequence::Copy, SLOT(copy())); pasteAct = addAct("paste.png", tr("Paste Model"), tr("Paste model from clipboard"), QKeySequence::Paste, SLOT(paste())); - + QActionGroup *themeAlignGroup = new QActionGroup(this); classicThemeAct = addAct( themeAlignGroup, tr("Classical"), tr("The classic companion9x icon theme"), SLOT(setClassicTheme())); yericoThemeAct = addAct( themeAlignGroup, tr("Yerico"), tr("Yellow round honey sweet icon theme"), SLOT(setYericoTheme())); @@ -1072,7 +1072,7 @@ void MainWindow::createActions() readBackupToFileAct = addAct("read_eeprom_file.png", tr("Backup Radio to File"), tr("Save a complete backup file of all settings and model data in the Radio"), SLOT(readBackup())); contributorsAct = addAct("contributors.png", tr("Contributors..."), tr("A tribute to those who have contributed to OpenTX and Companion"), SLOT(contributors())); sdsyncAct = addAct("sdsync.png", tr("Synchronize SD"), tr("SD card synchronization"), SLOT(sdsync())); - + compareAct->setEnabled(false); simulateAct->setEnabled(false); printAct->setEnabled(false); @@ -1156,7 +1156,7 @@ void MainWindow::createMenus() burnMenu->addSeparator(); burnMenu->addSeparator(); EEPROMInterface *eepromInterface = GetEepromInterface(); - if (!IS_ARM(eepromInterface->getBoard())) { + if (!IS_ARM(eepromInterface->getBoard())) { burnMenu->addAction(burnFusesAct); burnMenu->addAction(burnListAct); } @@ -1173,7 +1173,7 @@ void MainWindow::createMenus() helpMenu->addSeparator(); helpMenu->addAction(contributorsAct); } - + QMenu *MainWindow::createRecentFileMenu() { QMenu *recentFileMenu = new QMenu(this); @@ -1214,7 +1214,7 @@ void MainWindow::createToolBars() break; default: size=QSize(24,24); - break; + break; } fileToolBar = addToolBar(tr("File")); fileToolBar->setIconSize(size); @@ -1260,7 +1260,7 @@ void MainWindow::createToolBars() editToolBar->addAction(cutAct); editToolBar->addAction(copyAct); editToolBar->addAction(pasteAct); - + burnToolBar = new QToolBar(tr("Write")); addToolBar( Qt::LeftToolBarArea, burnToolBar ); burnToolBar->setIconSize(size); @@ -1317,7 +1317,7 @@ void MainWindow::setActiveSubWindow(QWidget *window) void MainWindow::updateRecentFileActions() { int i, numRecentFiles; - + // Hide all document slots for ( i=0 ; i < g.historySize(); i++) recentFileActs[i]->setVisible(false); @@ -1325,7 +1325,7 @@ void MainWindow::updateRecentFileActions() // Fill slots with content and unhide them QStringList files = g.recentFiles(); numRecentFiles = qMin(files.size(), g.historySize()); - + for ( i = 0; i < numRecentFiles; i++) { QString text = strippedName(files[i]); if (!text.trimmed().isEmpty()) @@ -1352,33 +1352,33 @@ void MainWindow::updateLanguageActions() { QString langId = g.locale(); - if (langId=="") + if (langId=="") sysLangAct->setChecked(true); - else if (langId=="cs_CZ") + else if (langId=="cs_CZ") czechLangAct->setChecked(true); - else if (langId=="de_DE") + else if (langId=="de_DE") germanLangAct->setChecked(true); - else if (langId=="en") + else if (langId=="en") englishLangAct->setChecked(true); - else if (langId=="fi_FI") + else if (langId=="fi_FI") finnishLangAct->setChecked(true); - else if (langId=="fr_FR") + else if (langId=="fr_FR") frenchLangAct->setChecked(true); - else if (langId=="it_IT") + else if (langId=="it_IT") italianLangAct->setChecked(true); - // else if (langId=="he_IL") + // else if (langId=="he_IL") // hebrewLangAct->setChecked(true); - else if (langId=="pl_PL") + else if (langId=="pl_PL") polishLangAct->setChecked(true); - // else if (langId=="pt_PT") + // else if (langId=="pt_PT") // portugueseLangAct->setChecked(true); else if (langId=="es_ES") spanishLangAct->setChecked(true); - else if (langId=="sv_SE") + else if (langId=="sv_SE") swedishLangAct->setChecked(true); - // else if (langId=="ru_RU") + // else if (langId=="ru_RU") // russianLangAct->setChecked(true); - // else if (langId=="nl_NL") + // else if (langId=="nl_NL") // dutchLangAct->setChecked(true); } @@ -1396,9 +1396,9 @@ void MainWindow::updateIconThemeActions() void MainWindow::updateProfilesActions() { - for (int i=0; isetText(text); @@ -1406,8 +1406,8 @@ void MainWindow::updateProfilesActions() profileActs[i]->setVisible(true); if (i == g.id()) profileActs[i]->setChecked(true); - } - else + } + else { profileActs[i]->setVisible(false); } @@ -1421,7 +1421,7 @@ void MainWindow::createProfile() ; if (i==MAX_PROFILES) //Failed to find free slot return; - + // Copy current profile to new and give it a new name g.profile[i] = g.profile[g.id()]; g.profile[i].name(tr("New Radio")); diff --git a/companion/src/mdichild.cpp b/companion/src/mdichild.cpp index 84d4d2cf4..484b5d4f7 100644 --- a/companion/src/mdichild.cpp +++ b/companion/src/mdichild.cpp @@ -81,7 +81,7 @@ MdiChild::MdiChild(): } } -MdiChild::~MdiChild() +MdiChild::~MdiChild() { delete ui; } @@ -174,7 +174,7 @@ void MdiChild::modelEdit() if (row == 0){ generalEdit(); - } + } else { QApplication::setOverrideCursor(Qt::WaitCursor); checkAndInitModel( row ); @@ -251,7 +251,7 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) XmlInterface(inputStream).load(radioData); } else -#endif +#endif if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file QMessageBox::critical(this, tr("Error"), @@ -260,18 +260,19 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) .arg(file.errorString())); return false; } - + QDomDocument doc(ER9X_EEPROM_FILE_TYPE); bool xmlOK = doc.setContent(&file); if(xmlOK) { - if (loadEEpromXml(radioData, doc)){ + std::bitset errors(LoadEepromXml(radioData, doc)); + if (errors.test(NO_ERROR)) { ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); return true; } } file.reset(); - + QTextStream inputStream(&file); if (fileType==FILE_TYPE_EEPE) { // read EEPE file header @@ -294,12 +295,14 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) file.close(); - if (!loadEEprom(radioData, (uint8_t *)eeprom.data(), eeprom_size)) { - QMessageBox::critical(this, tr("Error"), - tr("Invalid EEPROM File %1") - .arg(fileName)); + std::bitset errors(LoadEeprom(radioData, (uint8_t *)eeprom.data(), eeprom_size)); + if (!errors.test(NO_ERROR)) { + ShowEepromErrors(this, tr("Error"), tr("Invalid EEPROM File %1").arg(fileName), errors.to_ulong()); return false; } + if (errors.test(HAS_WARNINGS)) { + ShowEepromWarnings(this, tr("Warning"), errors.to_ulong()); + } ui->modelsList->refreshList(); if(resetCurrentFile) setCurrentFile(fileName); @@ -330,11 +333,18 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile) return false; } - if (!loadEEprom(radioData, eeprom, eeprom_size) && !::loadBackup(radioData, eeprom, eeprom_size, 0)) { - QMessageBox::critical(this, tr("Error"), - tr("Invalid binary EEPROM File %1") - .arg(fileName)); - return false; + std::bitset errorsEeprom(LoadEeprom(radioData, eeprom, eeprom_size)); + if (!errorsEeprom.test(NO_ERROR)) { + std::bitset errorsBackup(LoadBackup(radioData, eeprom, eeprom_size, 0)); + if (!errorsBackup.test(NO_ERROR)) { + ShowEepromErrors(this, tr("Error"), tr("Invalid binary EEPROM File %1").arg(fileName), (errorsEeprom | errorsBackup).to_ulong()); + return false; + } + if (errorsBackup.test(HAS_WARNINGS)) { + ShowEepromWarnings(this, tr("Warning"), errorsBackup.to_ulong()); + } + } else if (errorsEeprom.test(HAS_WARNINGS)) { + ShowEepromWarnings(this, tr("Warning"), errorsEeprom.to_ulong()); } ui->modelsList->refreshList(); @@ -367,7 +377,7 @@ bool MdiChild::saveAs(bool isNew) fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName()); #else fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); -#endif +#endif } else { QFileInfo fi(curFile); @@ -375,14 +385,14 @@ bool MdiChild::saveAs(bool isNew) fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName()); #else fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); -#endif +#endif } if (fileName.isEmpty()) return false; g.eepromDir( QFileInfo(fileName).dir().absolutePath() ); if (isNew) return saveFile(fileName); - else + else return saveFile(fileName,true); } @@ -505,7 +515,7 @@ void MdiChild::setCurrentFile(const QString &fileName) files.prepend(fileName); while (files.size() > MaxRecentFiles) files.removeLast(); - + g.recentFiles( files ); } @@ -544,7 +554,7 @@ void MdiChild::print(int model, QString filename) else if (getCurrentRow() > 0) { pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[getCurrentRow()-1]); } - + if (pd) { pd->setAttribute(Qt::WA_DeleteOnClose, true); pd->show(); @@ -601,12 +611,14 @@ bool MdiChild::loadBackup() return false; } - if (!::loadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index)) { - QMessageBox::critical(this, tr("Error"), - tr("Invalid binary backup File %1") - .arg(fileName)); - return false; - } + std::bitset errorsEeprom(LoadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index)); + if (!errorsEeprom.test(NO_ERROR)) { + ShowEepromErrors(this, tr("Error"), tr("Invalid binary backup File %1").arg(fileName), (errorsEeprom).to_ulong()); + return false; + } + if (errorsEeprom.test(HAS_WARNINGS)) { + ShowEepromWarnings(this, tr("Warning"), errorsEeprom.to_ulong()); + } ui->modelsList->refreshList(); diff --git a/companion/src/xmlinterface.cpp b/companion/src/xmlinterface.cpp index 1bbb7ee74..1f88b0116 100644 --- a/companion/src/xmlinterface.cpp +++ b/companion/src/xmlinterface.cpp @@ -1,6 +1,6 @@ /* * Author - Bertrand Songis - * + * * Based on th9x -> http://code.google.com/p/th9x/ * * This program is free software; you can redistribute it and/or modify @@ -121,7 +121,7 @@ void saveModel(ModelData & m, model & xm) if (t.mode) { timer xt(TimerSwitch::value(t.mode+TMR_NUM_OPTION), direction::value(t.dir), timer::value_type(t.val/3600, (t.val%3600)/60, t.val%60)); timer_sequence.push_back(xt); - } + } } */ if (m.moduleData[0].protocol != PULSES_PPM || m.moduleData[0].channelsCount != 8 || m.moduleData[0].ppmDelay != 300 || m.moduleData[0].ppmPulsePol != 0) { @@ -185,7 +185,7 @@ bool XmlInterface::save(RadioData &radioData) radio r; // the general settings - global_settings gs; + global_settings gs; saveGeneralSettings(settings, gs); r.global_settings(gs); From 646cc937ac7be44307dcd96cb85ade5fddb60ecd Mon Sep 17 00:00:00 2001 From: Grieb Date: Wed, 16 Sep 2015 22:12:55 -0300 Subject: [PATCH 2/2] Fixes #2778. --- companion/src/eeprominterface.cpp | 1 + companion/src/eeprominterface.h | 1 + .../src/firmwares/opentx/opentxinterface.cpp | 28 ++++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/companion/src/eeprominterface.cpp b/companion/src/eeprominterface.cpp index e1ef47b02..19f5174f1 100644 --- a/companion/src/eeprominterface.cpp +++ b/companion/src/eeprominterface.cpp @@ -1677,6 +1677,7 @@ void ShowEepromWarnings(QWidget *parent, const QString &title, unsigned long err std::bitset errors(errorsFound); QStringList warningsList; if (errors.test(WARNING_WRONG_FIRMWARE)) { warningsList << QT_TRANSLATE_NOOP("EepromInterface", "- Your radio probably uses a wrong firmware,\n eeprom size is 4096 but only the first 2048 are used"); } + if (errors.test(OLD_VERSION)) { warningsList << QT_TRANSLATE_NOOP("EepromInterface", "- Your eeprom is from an old version of OpenTX, upgrading!\n You should 'save as' to keep the old file as a backup."); } QMessageBox msgBox(parent); msgBox.setWindowTitle(title); diff --git a/companion/src/eeprominterface.h b/companion/src/eeprominterface.h index 88849b723..7d21d12a8 100644 --- a/companion/src/eeprominterface.h +++ b/companion/src/eeprominterface.h @@ -1498,6 +1498,7 @@ enum EepromLoadErrors { BACKUP_NOT_SUPPORTED, HAS_WARNINGS, + OLD_VERSION, WARNING_WRONG_FIRMWARE, NUM_ERRORS diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp index b4c14ad85..88e24c070 100644 --- a/companion/src/firmwares/opentx/opentxinterface.cpp +++ b/companion/src/firmwares/opentx/opentxinterface.cpp @@ -363,7 +363,10 @@ unsigned long OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *e std::cout << " version " << (unsigned int)version; EepromLoadErrors version_error = checkVersion(version); - if (version_error != NO_ERROR) { + if (version_error == OLD_VERSION) { + errors.set(version_error); + errors.set(HAS_WARNINGS); + } else if (version_error == NOT_OPENTX) { std::cout << " not open9x\n"; errors.set(version_error); return errors.to_ulong(); @@ -908,59 +911,46 @@ EepromLoadErrors OpenTxEepromInterface::checkVersion(unsigned int version) switch(version) { case 201: // first version - break; case 202: // channel order is now always RUD - ELE - THR - AIL // changes in timers // ppmFrameLength added // thrTraceSrc added - break; case 203: // mixers changed (for the trims use for change the offset of a mix) // telemetry offset raised to -127 +127 // function switches now have a param on 4 bits - break; case 204: // telemetry changes (bars) - break; case 205: // mixer changes (differential, negative curves)... - break; // case 206: case 207: // V4: Rotary Encoders position in FlightModes - break; case 208: // Trim value in 16bits // FrSky A1/A2 offset on 12bits // ARM: More Mixers / Expos / CSW / FSW / CHNOUT - break; case 209: // Add TrmR, TrmE, TrmT, TrmA as Mix sources // Trims are now OFF / ON / Rud / Ele / Thr / Ail - break; case 210: // Add names in Mixes / Expos // Add a new telemetry screen // Add support for Play Track - break; case 211: // Curves big change - break; case 212: // Big changes in mixers / limitse - break; case 213: // GVARS / Variants introduction - break; case 214: // Massive EEPROM change! - break; case 215: // M128 revert because too much RAM used! - break; case 216: // A lot of things (first github release) + return OLD_VERSION; break; case 217: // 3 logical switches removed on M128 / gruvin9x boards @@ -1047,9 +1037,13 @@ unsigned long OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *e std::cout << " version " << (unsigned int)version << " "; - if (!checkVersion(version)) { + EepromLoadErrors version_error = checkVersion(version); + if (version_error == OLD_VERSION) { + errors.set(version_error); + errors.set(HAS_WARNINGS); + } else if (version_error == NOT_OPENTX) { std::cout << " not open9x\n"; - errors.set(NOT_OPENTX); + errors.set(version_error); return errors.to_ulong(); }