chore(cpn): remove unused hex/eepe storage format code (#7550)
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
a6c1397dc0
commit
884b306592
@@ -77,7 +77,6 @@
|
||||
#define EEPROM_FILES_FILTER CPN_STR_RAD_MOD_SETTINGS % " " % CPN_STR_FILES % " (*.etx *.yml);;" % ETX_FILES_FILTER % YML_FILES_FILTER
|
||||
#define FIRMWARE_FILES_FILTER "Firmware " % CPN_STR_FILES % " (*.bin *.uf2);;" % BIN_FILES_FILTER % UF2_FILES_FILTER
|
||||
#define EXTERNAL_EEPROM_FILES_FILTER "EEPROM " % CPN_STR_FILES % " (*.bin);;" % BIN_FILES_FILTER
|
||||
#define EEPE_EEPROM_FILE_HEADER "EEPE EEPROM FILE"
|
||||
#define SIMU_FILES_FILTER ETX_FILES_FILTER
|
||||
|
||||
#define CPN_STR_APP_SETTINGS QCoreApplication::translate("Companion", "Application Settings")
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#include "version.h"
|
||||
#include "customizesplashdialog.h"
|
||||
#include "flashfirmwaredialog.h"
|
||||
#include "hexinterface.h"
|
||||
#include "warnings.h"
|
||||
#include "helpers.h"
|
||||
#include "appdata.h"
|
||||
|
||||
@@ -1538,7 +1538,7 @@ void MdiChild::setCurrentFile(const QString & fileName)
|
||||
|
||||
void MdiChild::forceNewFilename(const QString & suffix, const QString & ext)
|
||||
{
|
||||
curFile.replace(QRegularExpression("\\.(eepe|bin|hex|otx|etx)$"), suffix + "." + ext);
|
||||
curFile.replace(QRegularExpression("\\.etx$"), suffix + "." + ext);
|
||||
}
|
||||
|
||||
bool MdiChild::convertStorage(Board::Type from, Board::Type to, bool newFile)
|
||||
|
||||
@@ -2,13 +2,10 @@
|
||||
project(storage)
|
||||
|
||||
set(${PROJECT_NAME}_NAMES
|
||||
hexinterface
|
||||
mountlist
|
||||
appdata
|
||||
firmwareinterface
|
||||
storage
|
||||
eepe
|
||||
hexeeprom
|
||||
labeled
|
||||
sdcard
|
||||
etx
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "eepe.h"
|
||||
#include <QFile>
|
||||
#include "eeprominterface.h"
|
||||
#include "hexinterface.h"
|
||||
|
||||
bool EepeFormat::load(RadioData & radioData)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
setError(tr("Unable to open %1: %2").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream inputStream(&file);
|
||||
QString hline = inputStream.readLine();
|
||||
if (hline != EEPE_EEPROM_FILE_HEADER) {
|
||||
qDebug() << qPrintable("[eepe] No EEPE header");
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << qPrintable("[eepe] EEPE header found");
|
||||
|
||||
QByteArray eeprom(Boards::getEEpromSize(Board::BOARD_UNKNOWN), 0);
|
||||
int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), Boards::getEEpromSize(Board::BOARD_UNKNOWN));
|
||||
if (!eeprom_size) {
|
||||
setError(tr("Invalid EEPROM file %1").arg(filename));
|
||||
return false;
|
||||
}
|
||||
eeprom.resize(eeprom_size);
|
||||
|
||||
return extract(radioData, eeprom);
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _EEPE_H_
|
||||
#define _EEPE_H_
|
||||
|
||||
#include "hexeeprom.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class EepeFormat : public HexEepromFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(EepeFormat)
|
||||
|
||||
public:
|
||||
EepeFormat(const QString & filename):
|
||||
HexEepromFormat(filename)
|
||||
{
|
||||
}
|
||||
|
||||
virtual QString name() { return "eepe"; }
|
||||
virtual bool load(RadioData & radioData);
|
||||
};
|
||||
|
||||
#endif // _EEPE_H_
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
// TODO not enabled for now
|
||||
|
||||
bool EepeXmlFormat::load(RadioData & radioData)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug() << "Unable to open" << filename << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QDomDocument doc(ER9X_EEPROM_FILE_TYPE);
|
||||
bool xmlOK = doc.setContent(&file);
|
||||
if (xmlOK) {
|
||||
std::bitset<NUM_ERRORS> errors((unsigned long long) LoadEepromXml(radioData, doc));
|
||||
if (errors.test(ALL_OK)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
qDebug() << "XML parsing error";
|
||||
}
|
||||
}
|
||||
else {
|
||||
qDebug() << "No XML content";
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -19,7 +19,6 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "hexinterface.h"
|
||||
#include "firmwareinterface.h"
|
||||
#include "helpers.h"
|
||||
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "hexeeprom.h"
|
||||
#include "eeprominterface.h"
|
||||
#include "hexinterface.h"
|
||||
#include <QFile>
|
||||
|
||||
bool HexEepromFormat::load(RadioData & radioData)
|
||||
{
|
||||
QFile file(filename);
|
||||
|
||||
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||
qDebug() << "Unable to open" << filename << file.errorString();
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream inputStream(&file);
|
||||
QByteArray eeprom(Boards::getEEpromSize(Board::BOARD_UNKNOWN), 0);
|
||||
int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), Boards::getEEpromSize(Board::BOARD_UNKNOWN));
|
||||
if (!eeprom_size) {
|
||||
setError(tr("Invalid EEPROM File %1").arg(filename));
|
||||
return false;
|
||||
}
|
||||
eeprom.resize(eeprom_size);
|
||||
|
||||
return extract(radioData, eeprom);
|
||||
}
|
||||
|
||||
bool HexEepromFormat::writeToFile(const uint8_t * eeprom, uint32_t size)
|
||||
{
|
||||
QFile file(filename);
|
||||
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
|
||||
setError(tr("Cannot open file %1:\n%2.").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
QTextStream outputStream(&file);
|
||||
if (!HexInterface(outputStream).save(eeprom, size)) {
|
||||
setError(tr("Error writing file %1:\n%2.").arg(filename).arg(file.errorString()));
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef _HEXEEPROM_H_
|
||||
#define _HEXEEPROM_H_
|
||||
|
||||
#include "bineeprom.h"
|
||||
|
||||
#include <QtCore>
|
||||
|
||||
class HexEepromFormat : public BinEepromFormat
|
||||
{
|
||||
Q_DECLARE_TR_FUNCTIONS(HexEepromFormat)
|
||||
|
||||
public:
|
||||
HexEepromFormat(const QString & filename):
|
||||
BinEepromFormat(filename)
|
||||
{
|
||||
}
|
||||
|
||||
virtual QString name() { return "hex"; }
|
||||
virtual bool load(RadioData & radioData);
|
||||
|
||||
protected:
|
||||
virtual bool writeToFile(const uint8_t * eeprom, uint32_t size);
|
||||
};
|
||||
|
||||
#endif // _HEXEEPROM_H_
|
||||
@@ -1,134 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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 "hexinterface.h"
|
||||
|
||||
HexInterface::HexInterface(QTextStream &stream):
|
||||
stream(stream)
|
||||
{
|
||||
}
|
||||
|
||||
int HexInterface::getValueFromLine(const QString &line, int pos, int len)
|
||||
{
|
||||
bool ok;
|
||||
int hex = line.mid(pos,len).toInt(&ok, 16);
|
||||
return ok ? hex : -1;
|
||||
}
|
||||
|
||||
int HexInterface::load(uint8_t *data, int maxsize)
|
||||
{
|
||||
int result = 0;
|
||||
int offset = 0;
|
||||
while (!stream.atEnd()) {
|
||||
QString line = stream.readLine();
|
||||
|
||||
if(line.left(1)!=":") continue;
|
||||
|
||||
int byteCount = getValueFromLine(line,1);
|
||||
int address = getValueFromLine(line,3,4);
|
||||
int recType = getValueFromLine(line,7);
|
||||
|
||||
if (recType==0x02)
|
||||
offset+=0x010000;
|
||||
|
||||
if(byteCount<0 || address<0 || recType<0)
|
||||
return 0;
|
||||
|
||||
QByteArray ba;
|
||||
ba.clear();
|
||||
|
||||
quint8 chkSum = 0;
|
||||
chkSum -= byteCount;
|
||||
chkSum -= recType;
|
||||
chkSum -= address & 0xFF;
|
||||
chkSum -= address >> 8;
|
||||
for(int i=0; i<byteCount; i++) {
|
||||
quint8 v = getValueFromLine(line,(i*2)+9) & 0xFF;
|
||||
chkSum -= v;
|
||||
ba.append(v);
|
||||
}
|
||||
|
||||
quint8 retV = getValueFromLine(line,(byteCount*2)+9) & 0xFF;
|
||||
if(chkSum!=retV)
|
||||
return 0;
|
||||
|
||||
if (address+offset + byteCount <= maxsize) {
|
||||
if (recType == 0x00) { //data record - ba holds record
|
||||
memcpy(&data[address+offset],ba.data(),byteCount);
|
||||
result = std::max(result, address+offset+byteCount);
|
||||
}
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool HexInterface::save(const uint8_t * data, const int size)
|
||||
{
|
||||
int addr = 0;
|
||||
int nextbank = 1;
|
||||
while (addr < size) {
|
||||
if (addr>(nextbank*0x010000)-1) {
|
||||
stream << iHEXExtRec(nextbank) << "\n";
|
||||
nextbank++;
|
||||
}
|
||||
int llen = 32;
|
||||
if ((size - addr) < llen)
|
||||
llen = size - addr;
|
||||
stream << iHEXLine(data, addr, llen) << "\n";
|
||||
addr += llen;
|
||||
}
|
||||
stream << ":00000001FF\n"; // write EOF
|
||||
return true;
|
||||
}
|
||||
|
||||
QString HexInterface::iHEXLine(const quint8 * data, quint32 addr, quint8 len)
|
||||
{
|
||||
unsigned int bankaddr;
|
||||
bankaddr=addr&0xffff;
|
||||
QString str = QString(":%1%2000").arg(len, 2, 16, QChar('0')).arg(bankaddr, 4, 16, QChar('0')); //write start, bytecount (32), address and record type
|
||||
quint8 chkSum = 0;
|
||||
chkSum = -len; //-bytecount; recordtype is zero
|
||||
chkSum -= bankaddr & 0xFF;
|
||||
chkSum -= bankaddr >> 8;
|
||||
for (int j = 0; j < len; j++) {
|
||||
str += QString("%1").arg(data[addr + j], 2, 16, QChar('0'));
|
||||
chkSum -= data[addr + j];
|
||||
}
|
||||
|
||||
str += QString("%1").arg(chkSum, 2, 16, QChar('0'));
|
||||
return str.toUpper(); // output to file and lf;
|
||||
}
|
||||
|
||||
QString HexInterface::iHEXExtRec(quint8 bank)
|
||||
{
|
||||
QString str = QString(":02000002"); //write record type 2 record
|
||||
quint8 chkSum = 0;
|
||||
chkSum = -2; //-bytecount; recordtype is zero
|
||||
chkSum -= 2; // type 2 record type
|
||||
str += QString("%1000").arg((bank&0x0f)<<4,1,16,QChar('0'));
|
||||
chkSum -= ((bank&0x0f)<<4); // type 2 record type
|
||||
str += QString("%1").arg(chkSum, 2, 16, QChar('0'));
|
||||
return str.toUpper(); // output to file and lf;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QString>
|
||||
|
||||
class HexInterface {
|
||||
public:
|
||||
HexInterface(QTextStream &stream);
|
||||
|
||||
int load(uint8_t * output, int maxsize);
|
||||
bool save(const uint8_t * data, const int size);
|
||||
|
||||
protected:
|
||||
|
||||
int getValueFromLine(const QString &line, int pos, int len=2);
|
||||
QString iHEXLine(const quint8 * data, quint32 addr, quint8 len);
|
||||
QString iHEXExtRec(quint8 bank);
|
||||
|
||||
QTextStream & stream;
|
||||
};
|
||||
Reference in New Issue
Block a user