[Companion] Work in progress - QTreeView in MdiChild (#4197)
[Companion] QTreeView in MdiChild, Horus and X7 support added, fixes for #4224
This commit is contained in:
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "bineeprom.h"
|
||||
#include "eeprominterface.h"
|
||||
#include <QFile>
|
||||
#include <bitset>
|
||||
|
||||
// TODO should be RleFormat, RawFormat etc.
|
||||
|
||||
bool BinEepromFormat::load(RadioData & radioData)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
int size = file.size();
|
||||
|
||||
if (!file.open(QFile::ReadOnly)) {
|
||||
qDebug() << "Unable to open" << filename << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QByteArray eeprom(size, 0);
|
||||
int result = file.read((char *)eeprom.data(), size);
|
||||
if (result != size) {
|
||||
setError(QObject::tr("Error reading %1: %2").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return extract(radioData, eeprom);
|
||||
}
|
||||
|
||||
bool BinEepromFormat::write(const RadioData & radioData)
|
||||
{
|
||||
bool result;
|
||||
EEPROMInterface * eepromInterface = GetEepromInterface();
|
||||
uint8_t * eeprom = (uint8_t *)malloc(getEEpromSize(eepromInterface->getBoard()));
|
||||
int eeprom_size = eepromInterface->save(eeprom, radioData, 0, GetCurrentFirmware()->getVariantNumber());
|
||||
if (eeprom_size) {
|
||||
result = writeToFile(eeprom, eeprom_size);
|
||||
}
|
||||
else {
|
||||
setError(QObject::tr("Cannot save EEPROM"));
|
||||
result = false;
|
||||
}
|
||||
free(eeprom);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool BinEepromFormat::writeToFile(const uint8_t * eeprom, uint32_t size)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly)) {
|
||||
setError(QObject::tr("Cannot open file %1:\n%2.").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream outputStream(&file);
|
||||
long len = file.write((char *)eeprom, size);
|
||||
if (len != size) {
|
||||
setError(QObject::tr("Error writing file %1:\n%2.").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BinEepromFormat::extract(RadioData & radioData, const QByteArray & eeprom)
|
||||
{
|
||||
std::bitset<NUM_ERRORS> errors;
|
||||
|
||||
foreach(EEPROMInterface * eepromInterface, eepromInterfaces) {
|
||||
std::bitset<NUM_ERRORS> result((unsigned long long)eepromInterface->load(radioData, (uint8_t *)eeprom.data(), eeprom.size()));
|
||||
if (result.test(ALL_OK)) {
|
||||
if (errors.test(HAS_WARNINGS)) {
|
||||
// TODO ShowEepromWarnings(this, QObject::tr("Warning"), errors.to_ulong());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
errors |= result;
|
||||
}
|
||||
}
|
||||
|
||||
setError(QObject::tr("Invalid EEPROM File %1: %2").arg(filename).arg(errors.to_ulong()));
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user