Temporary commit for X10 conversions fixes

This commit is contained in:
Bertrand Songis
2019-08-23 14:21:02 +02:00
parent 6794212ada
commit a9255e802a
12 changed files with 95 additions and 25 deletions
@@ -21,8 +21,36 @@
#include "opentx.h"
#include "conversions.h"
void convertRadioData(int version)
{
TRACE("convertRadioData(%d)", version);
#if EEPROM_CONVERSIONS < 217
if (version == 216) {
version = 217;
convertRadioData_216_to_217(g_eeGeneral);
}
#endif
#if EEPROM_CONVERSIONS < 218
if (version == 217) {
version = 218;
convertRadioData_217_to_218(g_eeGeneral);
}
#endif
#if EEPROM_CONVERSIONS < 219
if (version == 218) {
version = 219;
convertRadioData_218_to_219(g_eeGeneral);
}
#endif
}
void convertModelData(int version)
{
TRACE("convertModelData(%d)", version);
#if EEPROM_CONVERSIONS < 217
if (version == 216) {
version = 217;
@@ -18,6 +18,7 @@
* GNU General Public License for more details.
*/
void convertRadioData(int version);
void convertModelData(int version);
bool eeConvert();
@@ -309,6 +309,8 @@ void convertModelData_218_to_219(ModelData &model)
void convertRadioData_218_to_219(RadioData & settings)
{
TRACE("Radio conversion from v218 to v219");
settings.version = 219;
settings.variant = EEPROM_VARIANT;
@@ -554,9 +554,9 @@ PACK(struct RadioData_v218 {
int8_t timezone:5;
uint8_t adjustRTC:1;
uint8_t inactivityTimer;
uint8_t telemetryBaudrate:3;
int8_t splashMode:3;
int8_t hapticMode:2;
int8_t spare2:3;
int8_t switchesDelay;
uint8_t lightAutoOff;
uint8_t templateSetup; // RETA order for receiver channels
+3 -1
View File
@@ -72,6 +72,8 @@ const BitmapBuffer * ModelCell::getBuffer()
void ModelCell::loadBitmap()
{
uint8_t version;
PACK(struct {
ModelHeader header;
TimerData timers[MAX_TIMERS];
@@ -87,7 +89,7 @@ void ModelCell::loadBitmap()
memcpy(&partialmodel.header, &g_model.header, sizeof(partialmodel));
}
else {
error = readModel(modelFilename, (uint8_t *)&partialmodel.header, sizeof(partialmodel));
error = readModel(modelFilename, (uint8_t *)&partialmodel.header, sizeof(partialmodel), &version);
}
buffer->clear(TEXT_BGCOLOR);
+26 -15
View File
@@ -101,16 +101,15 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
return nullptr;
}
const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize)
const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize, uint8_t * version)
{
FIL file;
UINT read;
uint16_t size;
uint8_t version;
TRACE("loadFile(%s)", fullpath);
const char * err = openFile(fullpath, &file, &size, &version);
const char * err = openFile(fullpath, &file, &size, version);
if (err)
return err;
@@ -121,26 +120,24 @@ const char * loadFile(const char * fullpath, uint8_t * data, uint16_t maxsize)
return SDCARD_ERROR(result);
}
if (version < EEPROM_VER) {
convertModelData(version);
}
f_close(&file);
return nullptr;
}
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size)
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version)
{
char path[256];
getModelPath(path, filename);
return loadFile(path, buffer, size);
return loadFile(path, buffer, size, version);
}
const char * loadModel(const char * filename, bool alarms)
{
uint8_t version;
preModelLoad();
const char * error = readModel(filename, (uint8_t *)&g_model, sizeof(g_model));
const char * error = readModel(filename, (uint8_t *)&g_model, sizeof(g_model), &version);
if (error) {
TRACE("loadModel error=%s", error);
}
@@ -150,20 +147,34 @@ const char * loadModel(const char * filename, bool alarms)
storageCheck(true);
alarms = false;
}
else if (version < EEPROM_VER) {
convertModelData(version);
}
postModelLoad(alarms);
return error;
}
const char * loadRadioSettings()
const char * loadRadioSettings(const char * path)
{
const char * error = loadFile(RADIO_SETTINGS_PATH, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral));
uint8_t version;
const char * error = loadFile(path, (uint8_t *)&g_eeGeneral, sizeof(g_eeGeneral), &version);
if (error) {
TRACE("loadRadioSettings error=%s", error);
return error;
}
return error;
if (version < EEPROM_VER) {
convertRadioData(version);
}
return nullptr;
}
const char * loadRadioSettings()
{
return loadRadioSettings(RADIO_SETTINGS_PATH);
}
const char * writeGeneralSettings()
@@ -174,7 +185,7 @@ const char * writeGeneralSettings()
void storageCheck(bool immediately)
{
if (storageDirtyMsk & EE_GENERAL) {
TRACE("eeprom write general");
TRACE("Storage write general");
storageDirtyMsk -= EE_GENERAL;
const char * error = writeGeneralSettings();
if (error) {
@@ -183,7 +194,7 @@ void storageCheck(bool immediately)
}
if (storageDirtyMsk & EE_MODEL) {
TRACE("eeprom write model");
TRACE("Storage write current model");
storageDirtyMsk -= EE_MODEL;
const char * error = writeModel();
if (error) {
+4 -1
View File
@@ -31,10 +31,13 @@ const char * openFile(const char * fullpath, FIL * file, uint16_t * size, uint8_
void getModelPath(char * path, const char * filename);
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size);
const char * readModel(const char * filename, uint8_t * buffer, uint32_t size, uint8_t * version);
const char * loadModel(const char * filename, bool alarms=true);
const char * createModel();
const char * loadRadioSettings(const char * path);
const char * loadRadioSettings();
PACK(struct RamBackup {
uint16_t size;
uint8_t data[4094];
Binary file not shown.
Binary file not shown.
+12 -2
View File
@@ -97,10 +97,20 @@ TEST(Conversions, ConversionX7From22)
#endif
#if defined(PCBX10)
TEST(Conversions, ConversionHorusFrom22)
TEST(X10Conversions, ConversionRadioFrom22)
{
simuFatfsSetPaths(TESTS_PATH "/tests/", TESTS_PATH "/tests/");
loadModel("model_22_horus.bin");
loadRadioSettings("/radio_22_x10.bin");
EXPECT_EQ(218, g_eeGeneral.version);
EXPECT_STRNEQ("en", g_eeGeneral.ttsLanguage);
EXPECT_STRNEQ("model1.bin", g_eeGeneral.currModelFilename);
}
TEST(X10Conversions, ConversionModelFrom22)
{
simuFatfsSetPaths(TESTS_PATH "/tests/", TESTS_PATH "/tests/");
loadModel("model_22_x10.bin");
EXPECT_ZSTREQ("Test", g_model.header.name);
EXPECT_EQ(80, g_model.mixData[0].weight);
+16 -5
View File
@@ -134,16 +134,27 @@ uint16_t getAnalogValue(uint8_t index)
return anaIn(index);
}
static char _zchar2stringResult[200];
static char _stringResult[200];
const char * zchar2string(const char * zstring, int size)
{
if (size > (int)sizeof(_zchar2stringResult) ) {
return 0;
if (size > (int)sizeof(_stringResult) ) {
return nullptr;
}
zchar2str(_zchar2stringResult, zstring, size);
return _zchar2stringResult;
zchar2str(_stringResult, zstring, size);
return _stringResult;
}
const char * nchar2string(const char * string, int size)
{
if (size > (int)sizeof(_stringResult) ) {
return nullptr;
}
strncpy(_stringResult, string, size);
_stringResult[size] = '\0';
return _stringResult;
}
int main(int argc, char **argv)
{
QCoreApplication app(argc, argv);
+2
View File
@@ -36,7 +36,9 @@ extern uint16_t anaInValues[NUM_STICKS+NUM_POTS+NUM_SLIDERS];
void doMixerCalculations();
extern const char * zchar2string(const char * zstring, int size);
extern const char * nchar2string(const char * string, int size);
#define EXPECT_ZSTREQ(c_string, z_string) EXPECT_STREQ(c_string, zchar2string(z_string, sizeof(z_string)))
#define EXPECT_STRNEQ(c_string, n_string) EXPECT_STREQ(c_string, nchar2string(n_string, sizeof(n_string)))
#if defined(PCBTARANIS) || defined(PCBHORUS)
#define RADIO_RESET() \