[Companion] Better storage traces

This commit is contained in:
Bertrand Songis
2017-01-19 21:19:17 +01:00
parent 0d6f5b470b
commit 3c62cbf200
8 changed files with 27 additions and 9 deletions
+1 -1
View File
@@ -98,6 +98,6 @@ bool BinEepromFormat::extract(RadioData & radioData, const QByteArray & eeprom)
} }
} }
setError(QObject::tr("Invalid EEPROM File %1: %2").arg(filename).arg(errors.to_ulong())); setError(QObject::tr("Invalid binary EEPROM file %1").arg(filename)));
return false; return false;
} }
+1
View File
@@ -31,6 +31,7 @@ class BinEepromFormat : public StorageFormat
{ {
} }
virtual QString name() { return "bin"; };
virtual bool load(RadioData & radioData); virtual bool load(RadioData & radioData);
virtual bool write(const RadioData & radioData); virtual bool write(const RadioData & radioData);
+4 -4
View File
@@ -28,23 +28,23 @@ bool EepeFormat::load(RadioData & radioData)
QFile file(filename); QFile file(filename);
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
qDebug() << "Unable to open" << filename << file.errorString(); setError(QObject::tr("Unable to open %1: %2").arg(filename).arg(file.errorString()));
return false; return false;
} }
QTextStream inputStream(&file); QTextStream inputStream(&file);
QString hline = inputStream.readLine(); QString hline = inputStream.readLine();
if (hline != EEPE_EEPROM_FILE_HEADER) { if (hline != EEPE_EEPROM_FILE_HEADER) {
qDebug() << "No EEPE header"; qDebug() << qPrintable("[eepe] No EEPE header");
return false; return false;
} }
qDebug() << "EEPE header found"; qDebug() << qPrintable("[eepe] EEPE header found");
QByteArray eeprom(EESIZE_MAX, 0); QByteArray eeprom(EESIZE_MAX, 0);
int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), EESIZE_MAX); int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), EESIZE_MAX);
if (!eeprom_size) { if (!eeprom_size) {
setError(QObject::tr("Invalid EEPROM File %1").arg(filename)); setError(QObject::tr("Invalid EEPROM file %1").arg(filename));
return false; return false;
} }
eeprom.resize(eeprom_size); eeprom.resize(eeprom_size);
+1
View File
@@ -31,6 +31,7 @@ class EepeFormat : public HexEepromFormat
{ {
} }
virtual QString name() { return "eepe"; };
virtual bool load(RadioData & radioData); virtual bool load(RadioData & radioData);
}; };
+1
View File
@@ -31,6 +31,7 @@ class HexEepromFormat : public BinEepromFormat
{ {
} }
virtual QString name() { return "hex"; };
virtual bool load(RadioData & radioData); virtual bool load(RadioData & radioData);
protected: protected:
+1
View File
@@ -35,6 +35,7 @@ class OtxFormat : public CategorizedStorageFormat
{ {
} }
virtual QString name() { return "otx"; };
virtual bool load(RadioData & radioData); virtual bool load(RadioData & radioData);
virtual bool write(const RadioData & radioData); virtual bool write(const RadioData & radioData);
+1
View File
@@ -31,6 +31,7 @@ class SdcardFormat : public CategorizedStorageFormat
{ {
} }
virtual QString name() { return "sdcard"; };
virtual bool write(const RadioData & radioData); virtual bool write(const RadioData & radioData);
protected: protected:
+17 -4
View File
@@ -58,18 +58,19 @@ class StorageFormat
QString warning() { QString warning() {
return _warning; return _warning;
} }
virtual QString name() = 0;
protected: protected:
void setError(const QString & error) void setError(const QString & error)
{ {
qDebug() << "error:" << error; qDebug() << qPrintable(QString("[%1] error: %2").arg(name()).arg(error));
_error = error; _error = error;
} }
void setWarning(const QString & warning) void setWarning(const QString & warning)
{ {
if (!warning.isEmpty()) qDebug() << qPrintable(QString("[%1] warning: %2").arg(name()).arg(warning));
qDebug() << "warning:" << warning;
_warning = warning; _warning = warning;
} }
@@ -126,6 +127,18 @@ class Storage : public StorageFormat
{ {
} }
virtual QString name() { return "storage"; };
void setError(const QString & error)
{
_error = error;
}
void setWarning(const QString & warning)
{
_warning = warning;
}
virtual bool load(RadioData & radioData); virtual bool load(RadioData & radioData);
virtual bool write(const RadioData & radioData); virtual bool write(const RadioData & radioData);
}; };