From 3c62cbf200e746adebbd0251bbfaf61b65345dc4 Mon Sep 17 00:00:00 2001 From: Bertrand Songis Date: Thu, 19 Jan 2017 21:19:17 +0100 Subject: [PATCH] [Companion] Better storage traces --- companion/src/storage/bineeprom.cpp | 2 +- companion/src/storage/bineeprom.h | 1 + companion/src/storage/eepe.cpp | 8 ++++---- companion/src/storage/eepe.h | 1 + companion/src/storage/hexeeprom.h | 1 + companion/src/storage/otx.h | 1 + companion/src/storage/sdcard.h | 1 + companion/src/storage/storage.h | 21 +++++++++++++++++---- 8 files changed, 27 insertions(+), 9 deletions(-) diff --git a/companion/src/storage/bineeprom.cpp b/companion/src/storage/bineeprom.cpp index a267eca4f..437e57e5a 100644 --- a/companion/src/storage/bineeprom.cpp +++ b/companion/src/storage/bineeprom.cpp @@ -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; } diff --git a/companion/src/storage/bineeprom.h b/companion/src/storage/bineeprom.h index 68085e164..ccda3d850 100644 --- a/companion/src/storage/bineeprom.h +++ b/companion/src/storage/bineeprom.h @@ -31,6 +31,7 @@ class BinEepromFormat : public StorageFormat { } + virtual QString name() { return "bin"; }; virtual bool load(RadioData & radioData); virtual bool write(const RadioData & radioData); diff --git a/companion/src/storage/eepe.cpp b/companion/src/storage/eepe.cpp index 59e5a1b92..a1e399d61 100644 --- a/companion/src/storage/eepe.cpp +++ b/companion/src/storage/eepe.cpp @@ -28,23 +28,23 @@ bool EepeFormat::load(RadioData & radioData) QFile file(filename); 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; } QTextStream inputStream(&file); QString hline = inputStream.readLine(); if (hline != EEPE_EEPROM_FILE_HEADER) { - qDebug() << "No EEPE header"; + qDebug() << qPrintable("[eepe] No EEPE header"); return false; } - qDebug() << "EEPE header found"; + qDebug() << qPrintable("[eepe] EEPE header found"); QByteArray eeprom(EESIZE_MAX, 0); int eeprom_size = HexInterface(inputStream).load((uint8_t *)eeprom.data(), EESIZE_MAX); if (!eeprom_size) { - setError(QObject::tr("Invalid EEPROM File %1").arg(filename)); + setError(QObject::tr("Invalid EEPROM file %1").arg(filename)); return false; } eeprom.resize(eeprom_size); diff --git a/companion/src/storage/eepe.h b/companion/src/storage/eepe.h index 069676c70..bebb395b8 100644 --- a/companion/src/storage/eepe.h +++ b/companion/src/storage/eepe.h @@ -31,6 +31,7 @@ class EepeFormat : public HexEepromFormat { } + virtual QString name() { return "eepe"; }; virtual bool load(RadioData & radioData); }; diff --git a/companion/src/storage/hexeeprom.h b/companion/src/storage/hexeeprom.h index e3b426f24..f1eda57e7 100644 --- a/companion/src/storage/hexeeprom.h +++ b/companion/src/storage/hexeeprom.h @@ -31,6 +31,7 @@ class HexEepromFormat : public BinEepromFormat { } + virtual QString name() { return "hex"; }; virtual bool load(RadioData & radioData); protected: diff --git a/companion/src/storage/otx.h b/companion/src/storage/otx.h index 3d81cd4b4..82fbaa34a 100644 --- a/companion/src/storage/otx.h +++ b/companion/src/storage/otx.h @@ -35,6 +35,7 @@ class OtxFormat : public CategorizedStorageFormat { } + virtual QString name() { return "otx"; }; virtual bool load(RadioData & radioData); virtual bool write(const RadioData & radioData); diff --git a/companion/src/storage/sdcard.h b/companion/src/storage/sdcard.h index 6ab8bbdea..3c7f4d0bd 100644 --- a/companion/src/storage/sdcard.h +++ b/companion/src/storage/sdcard.h @@ -31,6 +31,7 @@ class SdcardFormat : public CategorizedStorageFormat { } + virtual QString name() { return "sdcard"; }; virtual bool write(const RadioData & radioData); protected: diff --git a/companion/src/storage/storage.h b/companion/src/storage/storage.h index 6fe665945..c4f5500e4 100644 --- a/companion/src/storage/storage.h +++ b/companion/src/storage/storage.h @@ -58,18 +58,19 @@ class StorageFormat QString warning() { return _warning; } - + + virtual QString name() = 0; + protected: void setError(const QString & error) { - qDebug() << "error:" << error; + qDebug() << qPrintable(QString("[%1] error: %2").arg(name()).arg(error)); _error = error; } void setWarning(const QString & warning) { - if (!warning.isEmpty()) - qDebug() << "warning:" << warning; + qDebug() << qPrintable(QString("[%1] warning: %2").arg(name()).arg(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 write(const RadioData & radioData); };