1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-25 17:25:10 +03:00

Refactoring to have messages in Companion when opening eeprom.

This commit is contained in:
Grieb 2015-08-27 14:54:45 -03:00
parent 14967b6a94
commit 6d52039266
17 changed files with 433 additions and 226 deletions

View file

@ -26,8 +26,11 @@ bool convertEEprom(const QString &sourceEEprom, const QString &destinationEEprom
sourceFile.close(); sourceFile.close();
QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData()); QSharedPointer<RadioData> radioData = QSharedPointer<RadioData>(new RadioData());
if (!loadEEprom(*radioData, (uint8_t *)eeprom.data(), eeprom_size) || !currentFirmware->saveEEPROM((uint8_t *)eeprom.data(), *radioData, variant, version)) std::bitset<NUM_ERRORS> 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; return false;
}
QFile destinationFile(destinationEEprom); QFile destinationFile(destinationEEprom);
if (!destinationFile.open(QIODevice::WriteOnly)) if (!destinationFile.open(QIODevice::WriteOnly))

View file

@ -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) { std::bitset<NUM_ERRORS> errors(errorsFound);
if (eepromInterface->load(radioData, eeprom, size)) QStringList errorsList;
return true;
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<NUM_ERRORS> 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<NUM_ERRORS> errors;
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
if (eepromInterface->loadBackup(radioData, eeprom, size, index)) std::bitset<NUM_ERRORS> result(eepromInterface->load(radioData, eeprom, size));
return true; 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<NUM_ERRORS> errors;
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
std::bitset<NUM_ERRORS> 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<NUM_ERRORS> errors;
foreach(EEPROMInterface *eepromInterface, eepromInterfaces) { foreach(EEPROMInterface *eepromInterface, eepromInterfaces) {
if (eepromInterface->loadxml(radioData, doc)) std::bitset<NUM_ERRORS> result(eepromInterface->loadxml(radioData, doc));
return true; 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) QString getBoardName(BoardEnum board)

View file

@ -24,6 +24,7 @@
#include <QtXml> #include <QtXml>
#include <QComboBox> #include <QComboBox>
#include <iostream> #include <iostream>
#include <bitset>
#include "constants.h" #include "constants.h"
#include "simulatorinterface.h" #include "simulatorinterface.h"
@ -1353,11 +1354,11 @@ class EEPROMInterface
inline BoardEnum getBoard() { return board; } 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; 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 registerOpenTxFirmwares();
void unregisterFirmwares(); void unregisterFirmwares();
bool loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index); enum EepromLoadErrors {
bool loadEEprom(RadioData &radioData, const uint8_t *eeprom, int size); NO_ERROR,
bool loadEEpromXml(RadioData &radioData, QDomDocument &doc);
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 { struct Option {
const char * name; const char * name;

View file

@ -89,14 +89,17 @@ inline void applyStickModeToModel(Er9xModelData & model, unsigned int mode)
model.swashCollectiveSource = applyStickMode(model.swashCollectiveSource, 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::cout << "trying er9x xml import... ";
std::bitset<NUM_ERRORS> errors;
Er9xGeneral er9xGeneral; Er9xGeneral er9xGeneral;
memset(&er9xGeneral,0,sizeof(er9xGeneral)); memset(&er9xGeneral,0,sizeof(er9xGeneral));
if(!loadGeneralDataXML(&doc, &er9xGeneral)) { if(!loadGeneralDataXML(&doc, &er9xGeneral)) {
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} else { } else {
radioData.generalSettings=er9xGeneral; radioData.generalSettings=er9xGeneral;
std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; std::cout << "version " << (unsigned int)er9xGeneral.myVers << " ";
@ -111,21 +114,26 @@ bool Er9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
} }
} }
std::cout << "ok\n"; 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::cout << "trying er9x import... ";
std::bitset<NUM_ERRORS> errors;
if (size != getEEpromSize()) { if (size != getEEpromSize()) {
std::cout << "wrong size\n"; std::cout << "wrong size\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
std::cout << "wrong file system\n"; std::cout << "wrong file system\n";
return false; errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); 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) { if (efile->readRlc1((uint8_t*)&er9xGeneral, 1) != 1) {
std::cout << "no\n"; std::cout << "no\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
std::cout << "version " << (unsigned int)er9xGeneral.myVers << " "; std::cout << "version " << (unsigned int)er9xGeneral.myVers << " ";
@ -151,13 +160,16 @@ bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
break; break;
default: default:
std::cout << "not er9x\n"; std::cout << "not er9x\n";
return false; errors.set(NOT_ER9X);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
if (!efile->readRlc1((uint8_t*)&er9xGeneral, sizeof(Er9xGeneral))) { if (!efile->readRlc1((uint8_t*)&er9xGeneral, sizeof(Er9xGeneral))) {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
radioData.generalSettings = er9xGeneral; radioData.generalSettings = er9xGeneral;
@ -174,12 +186,15 @@ bool Er9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
} }
std::cout << "ok\n"; 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<NUM_ERRORS> errors;
errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
int Er9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) int Er9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)

View file

@ -34,11 +34,11 @@ class Er9xInterface : public EEPROMInterface
virtual const int getMaxModels(); 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); virtual int save(uint8_t * eeprom, RadioData & radioData, uint32_t variant=0, uint8_t version=0);

View file

@ -15,7 +15,6 @@
*/ */
#include <iostream> #include <iostream>
#include <QMessageBox>
#include "ersky9xinterface.h" #include "ersky9xinterface.h"
#include "ersky9xeeprom.h" #include "ersky9xeeprom.h"
#include "simulator/ersky9xsimulator.h" #include "simulator/ersky9xsimulator.h"
@ -120,14 +119,17 @@ inline void applyStickModeToModel(Ersky9xModelData_v11 & model, unsigned int mod
model.swashCollectiveSource = applyStickMode(model.swashCollectiveSource, mode); 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::cout << "trying ersky9x xml import... ";
std::bitset<NUM_ERRORS> errors;
Ersky9xGeneral ersky9xGeneral; Ersky9xGeneral ersky9xGeneral;
memset(&ersky9xGeneral,0,sizeof(ersky9xGeneral)); memset(&ersky9xGeneral,0,sizeof(ersky9xGeneral));
if(!loadGeneralDataXML(&doc, &ersky9xGeneral)) { if(!loadGeneralDataXML(&doc, &ersky9xGeneral)) {
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
else { else {
radioData.generalSettings=ersky9xGeneral; radioData.generalSettings=ersky9xGeneral;
@ -137,32 +139,39 @@ bool Ersky9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
if (ersky9xGeneral.myVers == 10) { if (ersky9xGeneral.myVers == 10) {
if (!loadModelDataXML<Ersky9xModelData_v10>(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) { if (!loadModelDataXML<Ersky9xModelData_v10>(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
} }
else { else {
if (!loadModelDataXML<Ersky9xModelData_v11>(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) { if (!loadModelDataXML<Ersky9xModelData_v11>(&doc, &radioData.models[i], i, radioData.generalSettings.stickMode+1)) {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
} }
} }
std::cout << "ok\n"; 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::cout << "trying ersky9x import... ";
std::bitset<NUM_ERRORS> errors;
if (size != EESIZE_SKY9X) { if (size != EESIZE_SKY9X) {
std::cout << "wrong size\n"; std::cout << "wrong size\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_SKY9X)) { if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_SKY9X)) {
std::cout << "wrong file system\n"; std::cout << "wrong file system\n";
return false; errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); 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) { if (efile->readRlc2((uint8_t*)&ersky9xGeneral, 1) != 1) {
std::cout << "no\n"; std::cout << "no\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
std::cout << "version " << (unsigned int)ersky9xGeneral.myVers << " "; std::cout << "version " << (unsigned int)ersky9xGeneral.myVers << " ";
@ -182,12 +192,14 @@ bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int siz
break; break;
default: default:
std::cout << "not ersky9x\n"; std::cout << "not ersky9x\n";
return false; errors.set(NOT_ERSKY9X);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
if (!efile->readRlc2((uint8_t*)&ersky9xGeneral, sizeof(Ersky9xGeneral))) { if (!efile->readRlc2((uint8_t*)&ersky9xGeneral, sizeof(Ersky9xGeneral))) {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
radioData.generalSettings = ersky9xGeneral; radioData.generalSettings = ersky9xGeneral;
@ -218,12 +230,15 @@ bool Ersky9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int siz
} }
std::cout << "ok\n"; 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<NUM_ERRORS> errors;
errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
int Ersky9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) int Ersky9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)

View file

@ -34,11 +34,11 @@ class Ersky9xInterface : public EEPROMInterface
virtual const int getMaxModels(); 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); virtual int save(uint8_t * eeprom, RadioData & radioData, uint32_t variant=0, uint8_t version=0);

View file

@ -93,24 +93,30 @@ bool Gruvin9xInterface::loadGeneral(GeneralSettings &settings, int version)
return false; return false;
} }
bool Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) unsigned long Gruvin9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
{ {
return false; std::bitset<NUM_ERRORS> 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::cout << "trying " << getName() << " import... ";
std::bitset<NUM_ERRORS> errors;
if (size != this->getEEpromSize()) { if (size != this->getEEpromSize()) {
std::cout << "wrong size\n"; std::cout << "wrong size\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
std::cout << "wrong file system\n"; std::cout << "wrong file system\n";
return false; errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
@ -118,14 +124,16 @@ bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int si
uint8_t version; uint8_t version;
if (efile->readRlc2(&version, 1) != 1) { if (efile->readRlc2(&version, 1) != 1) {
std::cout << "no\n"; std::cout << "no\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
if (version == 0) { if (version == 0) {
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
if (efile->readRlc1(&version, 1) != 1) { if (efile->readRlc1(&version, 1) != 1) {
std::cout << "no\n"; 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; break;
default: default:
std::cout << "not gruvin9x\n"; std::cout << "not gruvin9x\n";
return false; errors.set(NOT_GRUVIN9X);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
if (version == 5) { if (version == 5) {
if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings, 1)) if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings, 1)) {
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
}
} }
else if (version < 104) { else if (version < 104) {
if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings)) if (!loadGeneral<Gruvin9xGeneral_v103>(radioData.generalSettings)) {
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
}
} }
else if (version <= 106) { else if (version <= 106) {
if (!loadGeneral<Gruvin9xGeneral_v104>(radioData.generalSettings)) if (!loadGeneral<Gruvin9xGeneral_v104>(radioData.generalSettings)) {
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
}
} }
else { else {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
for (int i=0; i<getMaxModels(); i++) { for (int i=0; i<getMaxModels(); i++) {
@ -185,17 +201,21 @@ bool Gruvin9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int si
} }
else { else {
std::cout << "ko\n"; std::cout << "ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
} }
std::cout << "ok\n"; std::cout << "ok\n";
return true; errors.set(NO_ERROR);
return errors.to_ulong();
} }
bool Gruvin9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) unsigned long Gruvin9xInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index)
{ {
return false; std::bitset<NUM_ERRORS> errors;
errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
int Gruvin9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) int Gruvin9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)

View file

@ -35,11 +35,12 @@ class Gruvin9xInterface : public EEPROMInterface
virtual const int getMaxModels(); 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 save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0);

View file

@ -307,15 +307,19 @@ bool OpenTxEepromInterface::saveModel(unsigned int index, ModelData &model, unsi
return (sz == eeprom.size()); return (sz == eeprom.size());
} }
bool OpenTxEepromInterface::loadxml(RadioData &radioData, QDomDocument &doc) unsigned long OpenTxEepromInterface::loadxml(RadioData &radioData, QDomDocument &doc)
{ {
return false; std::bitset<NUM_ERRORS> 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::cout << "trying " << getName() << " import...";
std::bitset<NUM_ERRORS> errors;
if (size != getEEpromSize()) { if (size != getEEpromSize()) {
if (size==4096) { if (size==4096) {
int notnull=false; int notnull=false;
@ -326,21 +330,25 @@ bool OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, in
} }
if (notnull) { if (notnull) {
std::cout << " wrong size (" << size << ")\n"; std::cout << " wrong size (" << size << ")\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
else { 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; size=2048;
} }
} else { } else {
std::cout << " wrong size (" << size << "/" << getEEpromSize() << ")\n"; 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)) { if (!efile->EeFsOpen((uint8_t *)eeprom, size, board)) {
std::cout << " wrong file system\n"; std::cout << " wrong file system\n";
return false; errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
@ -348,30 +356,36 @@ bool OpenTxEepromInterface::load(RadioData &radioData, const uint8_t *eeprom, in
uint8_t version; uint8_t version;
if (efile->readRlc2(&version, 1) != 1) { if (efile->readRlc2(&version, 1) != 1) {
std::cout << " no\n"; std::cout << " no\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
std::cout << " version " << (unsigned int)version; std::cout << " version " << (unsigned int)version;
if (!checkVersion(version)) { EepromLoadErrors version_error = checkVersion(version);
if (version_error != NO_ERROR) {
std::cout << " not open9x\n"; std::cout << " not open9x\n";
return false; errors.set(version_error);
return errors.to_ulong();
} }
if (!loadGeneral<OpenTxGeneralData>(radioData.generalSettings, version)) { if (!loadGeneral<OpenTxGeneralData>(radioData.generalSettings, version)) {
std::cout << " ko\n"; std::cout << " ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
std::cout << " variant " << radioData.generalSettings.variant; std::cout << " variant " << radioData.generalSettings.variant;
for (int i=0; i<getMaxModels(); i++) { for (int i=0; i<getMaxModels(); i++) {
if (!loadModel(version, radioData.models[i], NULL, i, radioData.generalSettings.variant, radioData.generalSettings.stickMode+1)) { if (!loadModel(version, radioData.models[i], NULL, i, radioData.generalSettings.variant, radioData.generalSettings.stickMode+1)) {
std::cout << " ko\n"; std::cout << " ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
} }
std::cout << " ok\n"; std::cout << " ok\n";
return true; errors.set(NO_ERROR);
return errors.to_ulong();
} }
int OpenTxEepromInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) int OpenTxEepromInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)
@ -889,7 +903,7 @@ size_t getSizeA(T (&)[SIZE]) {
return SIZE; return SIZE;
} }
bool OpenTxEepromInterface::checkVersion(unsigned int version) EepromLoadErrors OpenTxEepromInterface::checkVersion(unsigned int version)
{ {
switch(version) { switch(version) {
case 201: case 201:
@ -952,10 +966,10 @@ bool OpenTxEepromInterface::checkVersion(unsigned int version)
// 3 logical switches removed on M128 / gruvin9x boards // 3 logical switches removed on M128 / gruvin9x boards
break; break;
default: default:
return false; return NOT_OPENTX;
} }
return true; return NO_ERROR;
} }
bool OpenTxEepromInterface::checkVariant(unsigned int version, unsigned int variant) bool OpenTxEepromInterface::checkVariant(unsigned int version, unsigned int variant)
@ -991,13 +1005,16 @@ bool OpenTxEepromInterface::checkVariant(unsigned int version, unsigned int vari
return true; return true;
} }
bool OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index) unsigned long OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, int esize, int index)
{ {
std::bitset<NUM_ERRORS> errors;
std::cout << "trying " << getName() << " backup import..."; std::cout << "trying " << getName() << " backup import...";
if (esize < 8 || memcmp(eeprom, "o9x", 3) != 0) { if (esize < 8 || memcmp(eeprom, "o9x", 3) != 0) {
std::cout << " no\n"; std::cout << " no\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
BoardEnum backupBoard = (BoardEnum)-1; BoardEnum backupBoard = (BoardEnum)-1;
@ -1013,12 +1030,14 @@ bool OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, in
break; break;
default: default:
std::cout << " unknown board\n"; std::cout << " unknown board\n";
return false; errors.set(UNKNOWN_BOARD);
return errors.to_ulong();
} }
if (backupBoard != board) { if (backupBoard != board) {
std::cout << " not right board\n"; std::cout << " not right board\n";
return false; errors.set(WRONG_BOARD);
return errors.to_ulong();
} }
uint8_t version = eeprom[4]; uint8_t version = eeprom[4];
@ -1030,27 +1049,32 @@ bool OpenTxEepromInterface::loadBackup(RadioData &radioData, uint8_t *eeprom, in
if (!checkVersion(version)) { if (!checkVersion(version)) {
std::cout << " not open9x\n"; std::cout << " not open9x\n";
return false; errors.set(NOT_OPENTX);
return errors.to_ulong();
} }
if (size > esize-8) { if (size > esize-8) {
std::cout << " wrong size\n"; std::cout << " wrong size\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
if (bcktype=='M') { if (bcktype=='M') {
if (!loadModel(version, radioData.models[index], &eeprom[8], size, variant)) { if (!loadModel(version, radioData.models[index], &eeprom[8], size, variant)) {
std::cout << " ko\n"; std::cout << " ko\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
} }
else { else {
std::cout << " backup type not supported\n"; std::cout << " backup type not supported\n";
return false; errors.set(BACKUP_NOT_SUPPORTED);
return errors.to_ulong();
} }
std::cout << " ok\n"; std::cout << " ok\n";
return true; errors.set(NO_ERROR);
return errors.to_ulong();
} }
QString OpenTxFirmware::getFirmwareBaseUrl() QString OpenTxFirmware::getFirmwareBaseUrl()

View file

@ -33,11 +33,11 @@ class OpenTxEepromInterface : public EEPROMInterface
virtual const int getMaxModels(); 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); virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0);
@ -51,7 +51,7 @@ class OpenTxEepromInterface : public EEPROMInterface
const char * getName(); const char * getName();
bool checkVersion(unsigned int version); EepromLoadErrors checkVersion(unsigned int version);
bool checkVariant(unsigned int version, unsigned int variant); bool checkVariant(unsigned int version, unsigned int variant);

View file

@ -57,23 +57,29 @@ const int Th9xInterface::getMaxModels()
return 16; return 16;
} }
bool Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc) unsigned long Th9xInterface::loadxml(RadioData &radioData, QDomDocument &doc)
{ {
return false; std::bitset<NUM_ERRORS> 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::cout << "trying th9x import... ";
std::bitset<NUM_ERRORS> errors;
if (size != getEEpromSize()) { if (size != getEEpromSize()) {
std::cout << "wrong size\n"; std::cout << "wrong size\n";
return false; errors.set(WRONG_SIZE);
return errors.to_ulong();
} }
if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) { if (!efile->EeFsOpen((uint8_t *)eeprom, size, BOARD_STOCK)) {
std::cout << "wrong file system\n"; std::cout << "wrong file system\n";
return false; errors.set(WRONG_FILE_SYSTEM);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); 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) { if (efile->readRlc2((uint8_t*)&th9xGeneral, 1) != 1) {
std::cout << "no\n"; std::cout << "no\n";
return false; errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
std::cout << "version " << (unsigned int)th9xGeneral.myVers << " "; std::cout << "version " << (unsigned int)th9xGeneral.myVers << " ";
@ -91,14 +98,16 @@ bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
break; break;
default: default:
std::cout << "not th9x\n"; std::cout << "not th9x\n";
return false; errors.set(NOT_TH9X);
return errors.to_ulong();
} }
efile->openRd(FILE_GENERAL); efile->openRd(FILE_GENERAL);
int len = efile->readRlc2((uint8_t*)&th9xGeneral, sizeof(Th9xGeneral)); int len = efile->readRlc2((uint8_t*)&th9xGeneral, sizeof(Th9xGeneral));
if (len != sizeof(Th9xGeneral)) { if (len != sizeof(Th9xGeneral)) {
std::cout << "not th9x\n"; std::cout << "not th9x\n";
return false; errors.set(NOT_TH9X);
return errors.to_ulong();
} }
radioData.generalSettings = th9xGeneral; radioData.generalSettings = th9xGeneral;
@ -114,12 +123,15 @@ bool Th9xInterface::load(RadioData &radioData, const uint8_t *eeprom, int size)
} }
std::cout << "ok\n"; 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<NUM_ERRORS> errors;
errors.set(UNKNOWN_ERROR);
return errors.to_ulong();
} }
int Th9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version) int Th9xInterface::save(uint8_t *eeprom, RadioData &radioData, uint32_t variant, uint8_t version)

View file

@ -34,11 +34,11 @@ class Th9xInterface : public EEPROMInterface
virtual const int getMaxModels(); 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); virtual int save(uint8_t *eeprom, RadioData &radioData, uint32_t variant=0, uint8_t version=0);

View file

@ -125,7 +125,8 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename)
bool xmlOK = doc.setContent(&file); bool xmlOK = doc.setContent(&file);
if (xmlOK) { if (xmlOK) {
RadioData * radioData = new RadioData(); RadioData * radioData = new RadioData();
if (!loadEEpromXml(*radioData, doc)) { std::bitset<NUM_ERRORS> errors(LoadEepromXml(*radioData, doc));
if (!errors.test(NO_ERROR)) {
QMessageBox::warning(this, tr("Error"), tr("Invalid Models and Settings File %1").arg(filename)); QMessageBox::warning(this, tr("Error"), tr("Invalid Models and Settings File %1").arg(filename));
} }
else { else {
@ -160,7 +161,8 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename)
} }
RadioData * radioData = new RadioData(); RadioData * radioData = new RadioData();
if (eeprom_size == 0 || !loadEEprom(*radioData, (const uint8_t *)eeprom.data(), eeprom_size)) { std::bitset<NUM_ERRORS> 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)); QMessageBox::warning(this, tr("Error"), tr("Invalid Models and Settings file %1").arg(filename));
} }
else { else {

View file

@ -264,7 +264,8 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile)
QDomDocument doc(ER9X_EEPROM_FILE_TYPE); QDomDocument doc(ER9X_EEPROM_FILE_TYPE);
bool xmlOK = doc.setContent(&file); bool xmlOK = doc.setContent(&file);
if(xmlOK) { if(xmlOK) {
if (loadEEpromXml(radioData, doc)){ std::bitset<NUM_ERRORS> errors(LoadEepromXml(radioData, doc));
if (errors.test(NO_ERROR)) {
ui->modelsList->refreshList(); ui->modelsList->refreshList();
if(resetCurrentFile) setCurrentFile(fileName); if(resetCurrentFile) setCurrentFile(fileName);
return true; return true;
@ -294,12 +295,14 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile)
file.close(); file.close();
if (!loadEEprom(radioData, (uint8_t *)eeprom.data(), eeprom_size)) { std::bitset<NUM_ERRORS> errors(LoadEeprom(radioData, (uint8_t *)eeprom.data(), eeprom_size));
QMessageBox::critical(this, tr("Error"), if (!errors.test(NO_ERROR)) {
tr("Invalid EEPROM File %1") ShowEepromErrors(this, tr("Error"), tr("Invalid EEPROM File %1").arg(fileName), errors.to_ulong());
.arg(fileName));
return false; return false;
} }
if (errors.test(HAS_WARNINGS)) {
ShowEepromWarnings(this, tr("Warning"), errors.to_ulong());
}
ui->modelsList->refreshList(); ui->modelsList->refreshList();
if(resetCurrentFile) setCurrentFile(fileName); if(resetCurrentFile) setCurrentFile(fileName);
@ -330,12 +333,19 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile)
return false; return false;
} }
if (!loadEEprom(radioData, eeprom, eeprom_size) && !::loadBackup(radioData, eeprom, eeprom_size, 0)) { std::bitset<NUM_ERRORS> errorsEeprom(LoadEeprom(radioData, eeprom, eeprom_size));
QMessageBox::critical(this, tr("Error"), if (!errorsEeprom.test(NO_ERROR)) {
tr("Invalid binary EEPROM File %1") std::bitset<NUM_ERRORS> errorsBackup(LoadBackup(radioData, eeprom, eeprom_size, 0));
.arg(fileName)); if (!errorsBackup.test(NO_ERROR)) {
ShowEepromErrors(this, tr("Error"), tr("Invalid binary EEPROM File %1").arg(fileName), (errorsEeprom | errorsBackup).to_ulong());
return false; 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(); ui->modelsList->refreshList();
if(resetCurrentFile) setCurrentFile(fileName); if(resetCurrentFile) setCurrentFile(fileName);
@ -601,12 +611,14 @@ bool MdiChild::loadBackup()
return false; return false;
} }
if (!::loadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index)) { std::bitset<NUM_ERRORS> errorsEeprom(LoadBackup(radioData, (uint8_t *)eeprom.data(), eeprom_size, index));
QMessageBox::critical(this, tr("Error"), if (!errorsEeprom.test(NO_ERROR)) {
tr("Invalid binary backup File %1") ShowEepromErrors(this, tr("Error"), tr("Invalid binary backup File %1").arg(fileName), (errorsEeprom).to_ulong());
.arg(fileName));
return false; return false;
} }
if (errorsEeprom.test(HAS_WARNINGS)) {
ShowEepromWarnings(this, tr("Warning"), errorsEeprom.to_ulong());
}
ui->modelsList->refreshList(); ui->modelsList->refreshList();