5 * th9x - http://code.google.com/p/th9x
6 * er9x - http://code.google.com/p/er9x
7 * gruvin9x - http://code.google.com/p/gruvin9x
9 * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2 as
13 * published by the Free Software Foundation.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
24 #include "radiodata.h"
40 StorageType
getStorageType(const QString
& filename
);
45 StorageFormat(const QString
& filename
, uint8_t version
=0):
48 board(Board::BOARD_UNKNOWN
)
51 virtual ~StorageFormat() {}
52 virtual bool load(RadioData
& radioData
) = 0;
53 virtual bool write(const RadioData
& radioData
) = 0;
63 virtual QString
name() = 0;
65 virtual Board::Type
getBoard()
70 static uint32_t getFourCC(Board::Type board
)
73 case Board::BOARD_X12S
:
74 case Board::BOARD_X10
:
76 case Board::BOARD_TARANIS_X7
:
78 case Board::BOARD_TARANIS_X9E
:
80 case Board::BOARD_TARANIS_X9D
:
81 case Board::BOARD_TARANIS_X9DP
:
83 case Board::BOARD_SKY9X
:
84 case Board::BOARD_AR9X
:
85 case Board::BOARD_9XRPRO
:
87 case Board::BOARD_MEGA2560
:
88 case Board::BOARD_GRUVIN9X
:
97 return getFourCC(board
);
100 virtual bool isBoardCompatible(Board::Type board
)
102 return getFourCC() == getFourCC(board
);
106 void setError(const QString
& error
)
108 qDebug() << qPrintable(QString("[%1] error: %2").arg(name()).arg(error
));
112 void setWarning(const QString
& warning
)
114 qDebug() << qPrintable(QString("[%1] warning: %2").arg(name()).arg(warning
));
131 virtual ~StorageFactory() {}
132 virtual QString
name() = 0;
133 virtual bool probe(const QString
& filename
) = 0;
134 virtual StorageFormat
* instance(const QString
& filename
) = 0;
138 class DefaultStorageFactory
: public StorageFactory
141 DefaultStorageFactory(const QString
& name
):
147 virtual QString
name()
152 virtual bool probe(const QString
& filename
)
154 return filename
.toLower().endsWith("." + _name
);
157 virtual StorageFormat
* instance(const QString
& filename
)
159 return new T(filename
);
165 class Storage
: public StorageFormat
168 Storage(const QString
& filename
):
169 StorageFormat(filename
)
173 virtual QString
name() { return "storage"; }
175 void setError(const QString
& error
)
180 void setWarning(const QString
& warning
)
185 virtual bool load(RadioData
& radioData
);
186 virtual bool write(const RadioData
& radioData
);
189 void registerStorageFactories();
190 void unregisterStorageFactories();
193 unsigned long LoadBackup(RadioData
&radioData
, uint8_t *eeprom
, int esize
, int index
);
194 unsigned long LoadEeprom(RadioData
&radioData
, const uint8_t *eeprom
, int size
);
195 unsigned long LoadEepromXml(RadioData
&radioData
, QDomDocument
&doc
);
198 bool convertEEprom(const QString
& sourceEEprom
, const QString
& destinationEEprom
, const QString
& firmware
);
200 #endif // _STORAGE_H_