1
0
Fork 0
mirror of https://github.com/EdgeTX/edgetx.git synced 2025-07-24 08:45:15 +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

@ -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("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") QObject::tr("L31"), QObject::tr("L32")
}; };
if (index<0) { if (index<0) {
return QObject::tr("----"); return QObject::tr("----");
} }
@ -528,7 +528,7 @@ QString RawSource::toString(const ModelData * model) const
return CHECK_IN_ARRAY(telemetry, index); return CHECK_IN_ARRAY(telemetry, index);
} }
case SOURCE_TYPE_GVAR: case SOURCE_TYPE_GVAR:
return QObject::tr("GV%1").arg(index+1); return QObject::tr("GV%1").arg(index+1);
default: default:
return QObject::tr("----"); return QObject::tr("----");
} }
@ -536,15 +536,15 @@ QString RawSource::toString(const ModelData * model) const
bool RawSource::isPot() const bool RawSource::isPot() const
{ {
return (type == SOURCE_TYPE_STICK && return (type == SOURCE_TYPE_STICK &&
index >= NUM_STICKS && index >= NUM_STICKS &&
index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)); index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots));
} }
bool RawSource::isSlider() const bool RawSource::isSlider() const
{ {
return (type == SOURCE_TYPE_STICK && return (type == SOURCE_TYPE_STICK &&
index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) && index >= NUM_STICKS+GetCurrentFirmware()->getCapability(Pots) &&
index < NUM_STICKS+GetCurrentFirmware()->getCapability(Pots)+GetCurrentFirmware()->getCapability(Sliders)); 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" ; qs << "SciFi" << "Robot" << "Chirp" << "Tada" << "Crickt" << "AlmClk" ;
} }
void CustomFunctionData::populateHapticParams(QStringList & qs) void CustomFunctionData::populateHapticParams(QStringList & qs)
{ {
qs << "0" << "1" << "2" << "3"; qs << "0" << "1" << "2" << "3";
} }
@ -892,7 +892,7 @@ QString CustomFunctionData::paramToString(const ModelData * model) const
int pos = cb.findData(param); int pos = cb.findData(param);
if (pos >= 0) if (pos >= 0)
return cb.itemText(pos); return cb.itemText(pos);
else else
return QObject::tr("<font color=red><b>Inconsistent parameter</b></font>"); return QObject::tr("<font color=red><b>Inconsistent parameter</b></font>");
} }
else if ((func==FuncVolume)|| (func==FuncPlayValue)) { 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_SKY9X));
eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_9XRPRO)); eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_9XRPRO));
eepromInterfaces.push_back(new OpenTxEepromInterface(BOARD_TARANIS)); 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 OpenTxEepromInterface(BOARD_TARANIS_X9E));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_STOCK));
eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X)); eepromInterfaces.push_back(new Gruvin9xInterface(BOARD_GRUVIN9X));
@ -1622,7 +1622,7 @@ void unregisterEEpromInterfaces()
foreach(EEPROMInterface * intf, eepromInterfaces) { foreach(EEPROMInterface * intf, eepromInterfaces) {
// qDebug() << "UnregisterEepromInterfaces(): deleting " << QString::number( reinterpret_cast<uint64_t>(intf), 16 ); // qDebug() << "UnregisterEepromInterfaces(): deleting " << QString::number( reinterpret_cast<uint64_t>(intf), 16 );
delete intf; delete intf;
} }
OpenTxEepromCleanup(); 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) { 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"
@ -841,7 +842,7 @@ class ModuleData {
int failsafeChannels[C9X_NUM_CHNOUT]; int failsafeChannels[C9X_NUM_CHNOUT];
int ppmDelay; int ppmDelay;
bool ppmPulsePol; // false = positive bool ppmPulsePol; // false = positive
bool ppmOutputType; // false = open drain, true = push pull bool ppmOutputType; // false = open drain, true = push pull
int ppmFrameLength; int ppmFrameLength;
void clear() { memset(this, 0, sizeof(ModuleData)); } void clear() { memset(this, 0, sizeof(ModuleData)); }
QString polarityToString() const { return ppmPulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter QString polarityToString() const { return ppmPulsePol ? QObject::tr("Positive") : QObject::tr("Negative"); } // TODO ModelPrinter
@ -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

@ -1,6 +1,6 @@
/* /*
* Author - Bertrand Songis <bsongis@gmail.com> * Author - Bertrand Songis <bsongis@gmail.com>
* *
* Based on th9x -> http://code.google.com/p/th9x/ * Based on th9x -> http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -29,21 +29,21 @@ class Er9xInterface : public EEPROMInterface
virtual ~Er9xInterface(); virtual ~Er9xInterface();
virtual const char * getName(); virtual const char * getName();
virtual const int getEEpromSize(); virtual const int getEEpromSize();
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);
virtual int getSize(const ModelData &); virtual int getSize(const ModelData &);
virtual int getSize(const GeneralSettings &settings); virtual int getSize(const GeneralSettings &settings);
virtual int isAvailable(PulsesProtocol proto, int port=0); virtual int isAvailable(PulsesProtocol proto, int port=0);
@ -54,17 +54,17 @@ class Er9xInterface : public EEPROMInterface
private: private:
void appendTextElement(QDomDocument * qdoc, QDomElement * pe, QString name, QString value); void appendTextElement(QDomDocument * qdoc, QDomElement * pe, QString name, QString value);
void appendNumberElement(QDomDocument * qdoc, QDomElement * pe,QString name, int value, bool forceZeroWrite = false); 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); 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 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 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 loadGeneralDataXML(QDomDocument * qdoc, Er9xGeneral * tgen); // get data from XML
bool loadModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum = -1); // get data from XML bool loadModelDataXML(QDomDocument * qdoc, Er9xModelData * tmod, int modelNum = -1); // get data from XML
}; };

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

@ -1,6 +1,6 @@
/* /*
* Author - Bertrand Songis <bsongis@gmail.com> * Author - Bertrand Songis <bsongis@gmail.com>
* *
* Based on th9x -> http://code.google.com/p/th9x/ * Based on th9x -> http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -30,21 +30,22 @@ class Gruvin9xInterface : public EEPROMInterface
virtual ~Gruvin9xInterface(); virtual ~Gruvin9xInterface();
virtual const char * getName(); virtual const char * getName();
virtual const int getEEpromSize(); virtual const int getEEpromSize();
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);
virtual int getSize(const ModelData &); virtual int getSize(const ModelData &);
virtual int getSize(const GeneralSettings & settings); virtual int getSize(const GeneralSettings & settings);
virtual int isAvailable(PulsesProtocol proto, int port=0); virtual int isAvailable(PulsesProtocol proto, int port=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()
@ -1346,7 +1370,7 @@ void registerOpenTxFirmwares()
firmware->addOption("bluetooth", QObject::tr("Bluetooth interface")); firmware->addOption("bluetooth", QObject::tr("Bluetooth interface"));
addOpenTxCommonOptions(firmware); addOpenTxCommonOptions(firmware);
firmwares.push_back(firmware); firmwares.push_back(firmware);
/* ar9x board */ /* ar9x board */
firmware = new OpenTxFirmware("opentx-ar9x", QObject::tr("ar9x board / 9X"), BOARD_AR9X); firmware = new OpenTxFirmware("opentx-ar9x", QObject::tr("ar9x board / 9X"), BOARD_AR9X);
firmware->addOption("heli", QObject::tr("Enable HELI menu and cyclic mix support")); firmware->addOption("heli", QObject::tr("Enable HELI menu and cyclic mix support"));

View file

@ -1,6 +1,6 @@
/* /*
* Author - Bertrand Songis <bsongis@gmail.com> * Author - Bertrand Songis <bsongis@gmail.com>
* *
* Based on th9x -> http://code.google.com/p/th9x/ * Based on th9x -> http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * 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 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);
virtual int getSize(const ModelData &); virtual int getSize(const ModelData &);
virtual int getSize(const GeneralSettings &); virtual int getSize(const GeneralSettings &);
virtual int isAvailable(PulsesProtocol proto, int port=0); virtual int isAvailable(PulsesProtocol proto, int port=0);
protected: protected:
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);
@ -112,7 +112,7 @@ class OpenTxFirmware: public Firmware {
} }
virtual Firmware * getFirmwareVariant(const QString & id); virtual Firmware * getFirmwareVariant(const QString & id);
virtual QString getStampUrl(); virtual QString getStampUrl();
virtual QString getReleaseNotesUrl(); virtual QString getReleaseNotesUrl();
@ -122,7 +122,7 @@ class OpenTxFirmware: public Firmware {
virtual int getCapability(const Capability); virtual int getCapability(const Capability);
virtual bool isTelemetrySourceAvailable(int source); virtual bool isTelemetrySourceAvailable(int source);
protected: protected:
QString getFirmwareBaseUrl(); QString getFirmwareBaseUrl();

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

@ -104,7 +104,7 @@ int FlashEEpromDialog::getEEpromVersion(const QString &filename)
QByteArray eeprom(EESIZE_MAX, 0); QByteArray eeprom(EESIZE_MAX, 0);
int fileType = getFileType(filename); int fileType = getFileType(filename);
#if 0 #if 0
if (fileType==FILE_TYPE_XML) { if (fileType==FILE_TYPE_XML) {
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
@ -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 {
@ -303,7 +305,7 @@ void FlashEEpromDialog::on_burnButton_clicked()
backupPath = g.profile[g.id()].pBackupDir(); backupPath = g.profile[g.id()].pBackupDir();
if (backupPath.isEmpty()) { if (backupPath.isEmpty()) {
backupPath=g.backupDir(); backupPath=g.backupDir();
} }
backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin"; backupFilename = backupPath + "/backup-" + QDateTime().currentDateTime().toString("yyyy-MM-dd-HHmmss") + ".bin";
} }
else if (ui->checkFirmwareCompatibility->isChecked()) { else if (ui->checkFirmwareCompatibility->isChecked()) {

View file

@ -115,12 +115,12 @@ MainWindow::MainWindow():
this->setIconSize(QSize(32, 32)); this->setIconSize(QSize(32, 32));
QNetworkProxyFactory::setUseSystemConfiguration(true); QNetworkProxyFactory::setUseSystemConfiguration(true);
setAcceptDrops(true); setAcceptDrops(true);
// give time to the splash to disappear and main window to open before starting updates // give time to the splash to disappear and main window to open before starting updates
int updateDelay = 1000; int updateDelay = 1000;
bool showSplash = g.showSplash(); bool showSplash = g.showSplash();
if (showSplash) { if (showSplash) {
updateDelay += (SPLASH_TIME*1000); updateDelay += (SPLASH_TIME*1000);
} }
QTimer::singleShot(updateDelay, this, SLOT(doAutoUpdates())); QTimer::singleShot(updateDelay, this, SLOT(doAutoUpdates()));
QTimer::singleShot(updateDelay, this, SLOT(displayWarnings())); QTimer::singleShot(updateDelay, this, SLOT(displayWarnings()));
@ -158,13 +158,13 @@ MainWindow::MainWindow():
child->show(); child->show();
} }
else { else {
child->show(); child->show();
child->print(model,printfilename); child->print(model,printfilename);
child->close(); child->close();
} }
} }
} }
} }
if (printing) { if (printing) {
QTimer::singleShot(0, this, SLOT(autoClose())); QTimer::singleShot(0, this, SLOT(autoClose()));
} }
@ -185,7 +185,7 @@ void MainWindow::displayWarnings()
} }
} }
else if (warnId==0) { 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); int c9xver = version2index(c9xversion);
if (c9xver < vnum) { 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)<br>" int ret = QMessageBox::question(this, "Companion", tr("A new version of Companion is available (version %1)<br>"
"Would you like to download it?").arg(version) , "Would you like to download it?").arg(version) ,
QMessageBox::Yes | QMessageBox::No); QMessageBox::Yes | QMessageBox::No);
if (ret == QMessageBox::Yes) { 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)); 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)")); QString fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.updatesDir() + QString(COMPANION_INSTALLER).arg(version), tr("Executable (*.exe)"));
#endif #endif
if (!fileName.isEmpty()) { if (!fileName.isEmpty()) {
@ -313,7 +313,7 @@ void MainWindow::checkForCompanionUpdateFinished(QNetworkReply * reply)
} }
#else #else
QMessageBox::warning(this, tr("New release available"), tr("A new release of Companion is available, please check the OpenTX website!")); QMessageBox::warning(this, tr("New release available"), tr("A new release of Companion is available, please check the OpenTX website!"));
#endif #endif
} }
else { else {
if (downloadDialog_forWait && checkForUpdatesState==0) { if (downloadDialog_forWait && checkForUpdatesState==0) {
@ -539,19 +539,19 @@ void MainWindow::closeEvent(QCloseEvent *event)
} }
void MainWindow::setLanguage(const QString & langString) void MainWindow::setLanguage(const QString & langString)
{ {
g.locale(langString); g.locale(langString);
QMessageBox::information(this, tr("Companion"), tr("The selected language will be used the next time you start Companion.")); QMessageBox::information(this, tr("Companion"), tr("The selected language will be used the next time you start Companion."));
} }
void MainWindow::setTheme(int index) void MainWindow::setTheme(int index)
{ {
g.theme(index); g.theme(index);
QMessageBox::information(this, tr("Companion"), tr("The new theme will be loaded the next time you start Companion.")); QMessageBox::information(this, tr("Companion"), tr("The new theme will be loaded the next time you start Companion."));
} }
void MainWindow::setIconThemeSize(int index) void MainWindow::setIconThemeSize(int index)
{ {
g.iconSize(index); g.iconSize(index);
QMessageBox::information(this, tr("Companion"), tr("The icon size will be used the next time you start Companion.")); 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() void MainWindow::customizeSplash()
{ {
customizeSplashDialog * dialog = new customizeSplashDialog(this); customizeSplashDialog * dialog = new customizeSplashDialog(this);
dialog->exec(); dialog->exec();
} }
@ -763,7 +763,7 @@ void MainWindow::readEeprom()
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (IS_ARM(eepromInterface->getBoard())) if (IS_ARM(eepromInterface->getBoard()))
tempFile = generateProcessUniqueTempFileName("temp.bin"); tempFile = generateProcessUniqueTempFileName("temp.bin");
else else
tempFile += generateProcessUniqueTempFileName("temp.hex"); tempFile += generateProcessUniqueTempFileName("temp.hex");
@ -920,7 +920,7 @@ void MainWindow::updateMenus()
pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false); pasteAct->setEnabled(hasMdiChild ? activeMdiChild()->hasPasteData() : false);
writeEepromAct->setEnabled(hasMdiChild); writeEepromAct->setEnabled(hasMdiChild);
separatorAct->setVisible(hasMdiChild); separatorAct->setVisible(hasMdiChild);
bool hasSelection = (activeMdiChild() && activeMdiChild()->hasSelection()); bool hasSelection = (activeMdiChild() && activeMdiChild()->hasSelection());
cutAct->setEnabled(hasSelection); cutAct->setEnabled(hasSelection);
copyAct->setEnabled(hasSelection); copyAct->setEnabled(hasSelection);
@ -962,7 +962,7 @@ QAction * MainWindow::addAct(const QString & icon, const QString & sName, const
QAction * newAction = new QAction( this ); QAction * newAction = new QAction( this );
if (!icon.isEmpty()) if (!icon.isEmpty())
newAction->setIcon(CompanionIcon(icon)); newAction->setIcon(CompanionIcon(icon));
if (!sName.isEmpty()) if (!sName.isEmpty())
newAction->setText(sName); newAction->setText(sName);
if (!lName.isEmpty()) if (!lName.isEmpty())
newAction->setStatusTip(lName); newAction->setStatusTip(lName);
@ -983,7 +983,7 @@ QAction * MainWindow::addAct(QActionGroup *aGroup, const QString & sName, const
{ {
QAction *action = addAct("", sName, lName, QKeySequence::UnknownKey, slot); QAction *action = addAct("", sName, lName, QKeySequence::UnknownKey, slot);
action->setCheckable(true); action->setCheckable(true);
aGroup->addAction(action); aGroup->addAction(action);
return 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())); 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())); 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())); pasteAct = addAct("paste.png", tr("Paste Model"), tr("Paste model from clipboard"), QKeySequence::Paste, SLOT(paste()));
QActionGroup *themeAlignGroup = new QActionGroup(this); QActionGroup *themeAlignGroup = new QActionGroup(this);
classicThemeAct = addAct( themeAlignGroup, tr("Classical"), tr("The classic companion9x icon theme"), SLOT(setClassicTheme())); 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())); 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())); 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())); 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())); sdsyncAct = addAct("sdsync.png", tr("Synchronize SD"), tr("SD card synchronization"), SLOT(sdsync()));
compareAct->setEnabled(false); compareAct->setEnabled(false);
simulateAct->setEnabled(false); simulateAct->setEnabled(false);
printAct->setEnabled(false); printAct->setEnabled(false);
@ -1156,7 +1156,7 @@ void MainWindow::createMenus()
burnMenu->addSeparator(); burnMenu->addSeparator();
burnMenu->addSeparator(); burnMenu->addSeparator();
EEPROMInterface *eepromInterface = GetEepromInterface(); EEPROMInterface *eepromInterface = GetEepromInterface();
if (!IS_ARM(eepromInterface->getBoard())) { if (!IS_ARM(eepromInterface->getBoard())) {
burnMenu->addAction(burnFusesAct); burnMenu->addAction(burnFusesAct);
burnMenu->addAction(burnListAct); burnMenu->addAction(burnListAct);
} }
@ -1173,7 +1173,7 @@ void MainWindow::createMenus()
helpMenu->addSeparator(); helpMenu->addSeparator();
helpMenu->addAction(contributorsAct); helpMenu->addAction(contributorsAct);
} }
QMenu *MainWindow::createRecentFileMenu() QMenu *MainWindow::createRecentFileMenu()
{ {
QMenu *recentFileMenu = new QMenu(this); QMenu *recentFileMenu = new QMenu(this);
@ -1214,7 +1214,7 @@ void MainWindow::createToolBars()
break; break;
default: default:
size=QSize(24,24); size=QSize(24,24);
break; break;
} }
fileToolBar = addToolBar(tr("File")); fileToolBar = addToolBar(tr("File"));
fileToolBar->setIconSize(size); fileToolBar->setIconSize(size);
@ -1260,7 +1260,7 @@ void MainWindow::createToolBars()
editToolBar->addAction(cutAct); editToolBar->addAction(cutAct);
editToolBar->addAction(copyAct); editToolBar->addAction(copyAct);
editToolBar->addAction(pasteAct); editToolBar->addAction(pasteAct);
burnToolBar = new QToolBar(tr("Write")); burnToolBar = new QToolBar(tr("Write"));
addToolBar( Qt::LeftToolBarArea, burnToolBar ); addToolBar( Qt::LeftToolBarArea, burnToolBar );
burnToolBar->setIconSize(size); burnToolBar->setIconSize(size);
@ -1317,7 +1317,7 @@ void MainWindow::setActiveSubWindow(QWidget *window)
void MainWindow::updateRecentFileActions() void MainWindow::updateRecentFileActions()
{ {
int i, numRecentFiles; int i, numRecentFiles;
// Hide all document slots // Hide all document slots
for ( i=0 ; i < g.historySize(); i++) for ( i=0 ; i < g.historySize(); i++)
recentFileActs[i]->setVisible(false); recentFileActs[i]->setVisible(false);
@ -1325,7 +1325,7 @@ void MainWindow::updateRecentFileActions()
// Fill slots with content and unhide them // Fill slots with content and unhide them
QStringList files = g.recentFiles(); QStringList files = g.recentFiles();
numRecentFiles = qMin(files.size(), g.historySize()); numRecentFiles = qMin(files.size(), g.historySize());
for ( i = 0; i < numRecentFiles; i++) { for ( i = 0; i < numRecentFiles; i++) {
QString text = strippedName(files[i]); QString text = strippedName(files[i]);
if (!text.trimmed().isEmpty()) if (!text.trimmed().isEmpty())
@ -1352,33 +1352,33 @@ void MainWindow::updateLanguageActions()
{ {
QString langId = g.locale(); QString langId = g.locale();
if (langId=="") if (langId=="")
sysLangAct->setChecked(true); sysLangAct->setChecked(true);
else if (langId=="cs_CZ") else if (langId=="cs_CZ")
czechLangAct->setChecked(true); czechLangAct->setChecked(true);
else if (langId=="de_DE") else if (langId=="de_DE")
germanLangAct->setChecked(true); germanLangAct->setChecked(true);
else if (langId=="en") else if (langId=="en")
englishLangAct->setChecked(true); englishLangAct->setChecked(true);
else if (langId=="fi_FI") else if (langId=="fi_FI")
finnishLangAct->setChecked(true); finnishLangAct->setChecked(true);
else if (langId=="fr_FR") else if (langId=="fr_FR")
frenchLangAct->setChecked(true); frenchLangAct->setChecked(true);
else if (langId=="it_IT") else if (langId=="it_IT")
italianLangAct->setChecked(true); italianLangAct->setChecked(true);
// else if (langId=="he_IL") // else if (langId=="he_IL")
// hebrewLangAct->setChecked(true); // hebrewLangAct->setChecked(true);
else if (langId=="pl_PL") else if (langId=="pl_PL")
polishLangAct->setChecked(true); polishLangAct->setChecked(true);
// else if (langId=="pt_PT") // else if (langId=="pt_PT")
// portugueseLangAct->setChecked(true); // portugueseLangAct->setChecked(true);
else if (langId=="es_ES") else if (langId=="es_ES")
spanishLangAct->setChecked(true); spanishLangAct->setChecked(true);
else if (langId=="sv_SE") else if (langId=="sv_SE")
swedishLangAct->setChecked(true); swedishLangAct->setChecked(true);
// else if (langId=="ru_RU") // else if (langId=="ru_RU")
// russianLangAct->setChecked(true); // russianLangAct->setChecked(true);
// else if (langId=="nl_NL") // else if (langId=="nl_NL")
// dutchLangAct->setChecked(true); // dutchLangAct->setChecked(true);
} }
@ -1396,9 +1396,9 @@ void MainWindow::updateIconThemeActions()
void MainWindow::updateProfilesActions() void MainWindow::updateProfilesActions()
{ {
for (int i=0; i<MAX_PROFILES; i++) for (int i=0; i<MAX_PROFILES; i++)
{ {
if (g.profile[i].existsOnDisk()) if (g.profile[i].existsOnDisk())
{ {
QString text = tr("%2").arg(g.profile[i].name()); QString text = tr("%2").arg(g.profile[i].name());
profileActs[i]->setText(text); profileActs[i]->setText(text);
@ -1406,8 +1406,8 @@ void MainWindow::updateProfilesActions()
profileActs[i]->setVisible(true); profileActs[i]->setVisible(true);
if (i == g.id()) if (i == g.id())
profileActs[i]->setChecked(true); profileActs[i]->setChecked(true);
} }
else else
{ {
profileActs[i]->setVisible(false); profileActs[i]->setVisible(false);
} }
@ -1421,7 +1421,7 @@ void MainWindow::createProfile()
; ;
if (i==MAX_PROFILES) //Failed to find free slot if (i==MAX_PROFILES) //Failed to find free slot
return; return;
// Copy current profile to new and give it a new name // Copy current profile to new and give it a new name
g.profile[i] = g.profile[g.id()]; g.profile[i] = g.profile[g.id()];
g.profile[i].name(tr("New Radio")); g.profile[i].name(tr("New Radio"));

View file

@ -81,7 +81,7 @@ MdiChild::MdiChild():
} }
} }
MdiChild::~MdiChild() MdiChild::~MdiChild()
{ {
delete ui; delete ui;
} }
@ -174,7 +174,7 @@ void MdiChild::modelEdit()
if (row == 0){ if (row == 0){
generalEdit(); generalEdit();
} }
else { else {
QApplication::setOverrideCursor(Qt::WaitCursor); QApplication::setOverrideCursor(Qt::WaitCursor);
checkAndInitModel( row ); checkAndInitModel( row );
@ -251,7 +251,7 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile)
XmlInterface(inputStream).load(radioData); XmlInterface(inputStream).load(radioData);
} }
else else
#endif #endif
if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file if (fileType==FILE_TYPE_HEX || fileType==FILE_TYPE_EEPE) { //read HEX file
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { //reading HEX TEXT file
QMessageBox::critical(this, tr("Error"), QMessageBox::critical(this, tr("Error"),
@ -260,18 +260,19 @@ bool MdiChild::loadFile(const QString &fileName, bool resetCurrentFile)
.arg(file.errorString())); .arg(file.errorString()));
return false; return false;
} }
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;
} }
} }
file.reset(); file.reset();
QTextStream inputStream(&file); QTextStream inputStream(&file);
if (fileType==FILE_TYPE_EEPE) { // read EEPE file header if (fileType==FILE_TYPE_EEPE) { // read EEPE file header
@ -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,11 +333,18 @@ 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)) {
return false; 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(); ui->modelsList->refreshList();
@ -367,7 +377,7 @@ bool MdiChild::saveAs(bool isNew)
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName()); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
#else #else
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER)); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(BIN_FILES_FILTER));
#endif #endif
} }
else { else {
QFileInfo fi(curFile); QFileInfo fi(curFile);
@ -375,14 +385,14 @@ bool MdiChild::saveAs(bool isNew)
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName()); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName());
#else #else
fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER)); fileName = QFileDialog::getSaveFileName(this, tr("Save As"), g.eepromDir() + "/" +fi.fileName(), tr(EEPROM_FILES_FILTER));
#endif #endif
} }
if (fileName.isEmpty()) if (fileName.isEmpty())
return false; return false;
g.eepromDir( QFileInfo(fileName).dir().absolutePath() ); g.eepromDir( QFileInfo(fileName).dir().absolutePath() );
if (isNew) if (isNew)
return saveFile(fileName); return saveFile(fileName);
else else
return saveFile(fileName,true); return saveFile(fileName,true);
} }
@ -505,7 +515,7 @@ void MdiChild::setCurrentFile(const QString &fileName)
files.prepend(fileName); files.prepend(fileName);
while (files.size() > MaxRecentFiles) while (files.size() > MaxRecentFiles)
files.removeLast(); files.removeLast();
g.recentFiles( files ); g.recentFiles( files );
} }
@ -544,7 +554,7 @@ void MdiChild::print(int model, QString filename)
else if (getCurrentRow() > 0) { else if (getCurrentRow() > 0) {
pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[getCurrentRow()-1]); pd = new PrintDialog(this, GetCurrentFirmware()/*firmware*/, radioData.generalSettings, radioData.models[getCurrentRow()-1]);
} }
if (pd) { if (pd) {
pd->setAttribute(Qt::WA_DeleteOnClose, true); pd->setAttribute(Qt::WA_DeleteOnClose, true);
pd->show(); pd->show();
@ -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();

View file

@ -1,6 +1,6 @@
/* /*
* Author - Bertrand Songis <bsongis@gmail.com> * Author - Bertrand Songis <bsongis@gmail.com>
* *
* Based on th9x -> http://code.google.com/p/th9x/ * Based on th9x -> http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * 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) { 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 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); 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) { 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; radio r;
// the general settings // the general settings
global_settings gs; global_settings gs;
saveGeneralSettings(settings, gs); saveGeneralSettings(settings, gs);
r.global_settings(gs); r.global_settings(gs);