diff --git a/companion/releasenotes.txt b/companion/releasenotes.txt
index c2924785b..0fbfc75a5 100644
--- a/companion/releasenotes.txt
+++ b/companion/releasenotes.txt
@@ -4,6 +4,7 @@
EEPROM export warning when exporting logical switches > L12 on 9X128
FAS offset was not exported on 9X/9XR boards
Trims modes bugfix on non Taranis boards
+It was impossible to open a backuped model from the Tx
Version 2.0.6
diff --git a/companion/src/file.cpp b/companion/src/file.cpp
index bed78afb4..6741cf32e 100644
--- a/companion/src/file.cpp
+++ b/companion/src/file.cpp
@@ -344,75 +344,55 @@ unsigned int RleFile::readRlc12(uint8_t *buf, unsigned int i_len, bool rlc2)
}
}
-unsigned int RleFile::importRlc2(QByteArray & dst, QByteArray & src)
+unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersion)
{
- // TODO reset dst
+ uint8_t *buf = (uint8_t *)src.data();
+ unsigned int len = src.size();
+ uint8_t zeroes = 0;
+ uint8_t bRlc = 0;
- unsigned int i_len = src.size();
- unsigned int i_ofs = 0;
- uint8_t *buf = (uint8_t *)dst.data();
- m_pos = 0;
- m_ofs = 0;
- m_zeroes = 0;
- m_bRlc = 0;
- m_err = ERR_NONE; //error reasons
+ dst.resize(0);
+ for( ; 1; ) {
+ for (int i=0; i 0) {
- eeprom_read_block(buf, (m_fileId << 12) + m_pos, len);
- m_pos += len;
+ if (len == 0)
+ return dst.size();
+
+ for (int i=0; i(m_zeroes, i_len-i);
- memset(&buf[i], 0, ln);
- i += ln;
- m_zeroes -= ln;
- if(m_zeroes) break;
- ln = std::min(m_bRlc, i_len-i);
- memcpy(&buf[i], ((uint8_t *)src.data()) + i_ofs, ln);
- i_ofs += ln;
- uint8_t lr = ln;
+ bRlc = *buf++;
+ --len;
- i += lr ;
- m_bRlc -= lr;
- if(m_bRlc) break;
+ if (!(bRlc & 0x7f)) {
+ qDebug() << "RLC decoding error!";
+ return 0;
+ }
- // if (read(&m_bRlc, 1) !=1) break; //read how many bytes to read
- m_bRlc = *(((uint8_t *)src.data()) + i_ofs);
- i_ofs += 1;
-
- if (!(m_bRlc & 0x7f)) {
- qDebug() << "RLC decoding error!";
- return 0;
+ if (rlcVersion == 2) {
+ if (bRlc&0x80){ // if contains high byte
+ zeroes = (bRlc>>4) & 0x07;
+ bRlc = bRlc & 0x0f;
}
-
- if (1/*rlc2*/) {
- if(m_bRlc&0x80){ // if contains high byte
- m_zeroes =(m_bRlc>>4) & 0x7;
- m_bRlc = m_bRlc & 0x0f;
- }
- else if(m_bRlc&0x40){
- m_zeroes = m_bRlc & 0x3f;
- m_bRlc = 0;
- }
- //else m_bRlc
- }
- else {
- if(m_bRlc&0x80){ // if contains high byte
- m_zeroes = m_bRlc & 0x7f;
- m_bRlc = 0;
- }
+ else if (bRlc&0x40){
+ zeroes = bRlc & 0x3f;
+ bRlc = 0;
+ }
+ }
+ else {
+ if (bRlc&0x80){ // if contains high byte
+ zeroes = bRlc & 0x7f;
+ bRlc = 0;
}
}
- return i;
}
+ return dst.size();
}
unsigned int RleFile::write1(uint8_t b)
diff --git a/companion/src/file.h b/companion/src/file.h
index 93918d0cd..8ec517237 100644
--- a/companion/src/file.h
+++ b/companion/src/file.h
@@ -140,11 +140,12 @@ public:
{
return readRlc12(buf, i_len, true);
}
- unsigned int importRlc2(QByteArray & dst, QByteArray & src);
uint8_t byte_checksum(uint8_t *p, unsigned int size);
unsigned int ee32_check_header(struct t_eeprom_header *hptr);
unsigned int get_current_block_number(unsigned int block_no, uint16_t *p_size);
};
+unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersion=2);
+
#endif
diff --git a/companion/src/firmwares/opentx/opentxinterface.cpp b/companion/src/firmwares/opentx/opentxinterface.cpp
index 641bcf29b..e6887c937 100644
--- a/companion/src/firmwares/opentx/opentxinterface.cpp
+++ b/companion/src/firmwares/opentx/opentxinterface.cpp
@@ -163,12 +163,13 @@ bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData &mode
}
else {
// load from SD Backup, size is stored in index
- QByteArray eepromData((char *)data, index);
- QByteArray modelData(sizeof(model), 0); // ModelData should be always bigger than the EEPROM struct
- // memcpy(eepromData.data(), data, index);
- // efile->openRd(FILE_MODEL(0));
- int numbytes = efile->importRlc2(modelData, eepromData);
- if (numbytes) {
+ QByteArray backupData((char *)data, index);
+ QByteArray modelData;
+ if (IS_SKY9X(board))
+ modelData = backupData;
+ else
+ importRlc(modelData, backupData);
+ if (modelData.size()) {
open9xModel.Import(modelData);
// open9xModel.Dump();
model.used = true;
@@ -176,8 +177,6 @@ bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData &mode
else {
model.clear();
}
- // open9xModel.Import(eepromData);
- // model.used = true;
}
return true;