1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-26 01:35:21 +03:00

Better fix for model backups import

This commit is contained in:
bsongis 2014-07-16 19:06:49 +02:00
parent 5da1e35efe
commit 7373ce2cae
4 changed files with 47 additions and 66 deletions

View file

@ -4,6 +4,7 @@
<li>EEPROM export warning when exporting logical switches > L12 on 9X128</li> <li>EEPROM export warning when exporting logical switches > L12 on 9X128</li>
<li>FAS offset was not exported on 9X/9XR boards</li> <li>FAS offset was not exported on 9X/9XR boards</li>
<li>Trims modes bugfix on non Taranis boards</li> <li>Trims modes bugfix on non Taranis boards</li>
<li>It was impossible to open a backuped model from the Tx</li>
</ul> </ul>
<h2>Version 2.0.6</h2> <h2>Version 2.0.6</h2>

View file

@ -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(); dst.resize(0);
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
for( ; 1; ) {
for (int i=0; i<zeroes; i++)
dst.append((char)0);
zeroes = 0;
if (IS_SKY9X(board)) { if (len == 0)
int len = std::min((int)i_len, (int)m_size + (int)sizeof(t_eeprom_header) - (int)m_pos); return dst.size();
if (len > 0) {
eeprom_read_block(buf, (m_fileId << 12) + m_pos, len); for (int i=0; i<bRlc; i++) {
m_pos += len; dst.append(*buf++);
if (--len == 0)
return dst.size();
} }
return len;
}
else {
unsigned int i=0;
for( ; 1; ) {
uint8_t ln = std::min<uint16_t>(m_zeroes, i_len-i);
memset(&buf[i], 0, ln);
i += ln;
m_zeroes -= ln;
if(m_zeroes) break;
ln = std::min<uint16_t>(m_bRlc, i_len-i); bRlc = *buf++;
memcpy(&buf[i], ((uint8_t *)src.data()) + i_ofs, ln); --len;
i_ofs += ln;
uint8_t lr = ln;
i += lr ; if (!(bRlc & 0x7f)) {
m_bRlc -= lr; qDebug() << "RLC decoding error!";
if(m_bRlc) break; return 0;
}
// if (read(&m_bRlc, 1) !=1) break; //read how many bytes to read if (rlcVersion == 2) {
m_bRlc = *(((uint8_t *)src.data()) + i_ofs); if (bRlc&0x80){ // if contains high byte
i_ofs += 1; zeroes = (bRlc>>4) & 0x07;
bRlc = bRlc & 0x0f;
if (!(m_bRlc & 0x7f)) {
qDebug() << "RLC decoding error!";
return 0;
} }
else if (bRlc&0x40){
if (1/*rlc2*/) { zeroes = bRlc & 0x3f;
if(m_bRlc&0x80){ // if contains high byte bRlc = 0;
m_zeroes =(m_bRlc>>4) & 0x7; }
m_bRlc = m_bRlc & 0x0f; }
} else {
else if(m_bRlc&0x40){ if (bRlc&0x80){ // if contains high byte
m_zeroes = m_bRlc & 0x3f; zeroes = bRlc & 0x7f;
m_bRlc = 0; bRlc = 0;
}
//else m_bRlc
}
else {
if(m_bRlc&0x80){ // if contains high byte
m_zeroes = m_bRlc & 0x7f;
m_bRlc = 0;
}
} }
} }
return i;
} }
return dst.size();
} }
unsigned int RleFile::write1(uint8_t b) unsigned int RleFile::write1(uint8_t b)

View file

@ -140,11 +140,12 @@ public:
{ {
return readRlc12(buf, i_len, true); return readRlc12(buf, i_len, true);
} }
unsigned int importRlc2(QByteArray & dst, QByteArray & src);
uint8_t byte_checksum(uint8_t *p, unsigned int size); uint8_t byte_checksum(uint8_t *p, unsigned int size);
unsigned int ee32_check_header(struct t_eeprom_header *hptr); 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 get_current_block_number(unsigned int block_no, uint16_t *p_size);
}; };
unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersion=2);
#endif #endif

View file

@ -163,12 +163,13 @@ bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData &mode
} }
else { else {
// load from SD Backup, size is stored in index // load from SD Backup, size is stored in index
QByteArray eepromData((char *)data, index); QByteArray backupData((char *)data, index);
QByteArray modelData(sizeof(model), 0); // ModelData should be always bigger than the EEPROM struct QByteArray modelData;
// memcpy(eepromData.data(), data, index); if (IS_SKY9X(board))
// efile->openRd(FILE_MODEL(0)); modelData = backupData;
int numbytes = efile->importRlc2(modelData, eepromData); else
if (numbytes) { importRlc(modelData, backupData);
if (modelData.size()) {
open9xModel.Import(modelData); open9xModel.Import(modelData);
// open9xModel.Dump(); // open9xModel.Dump();
model.used = true; model.used = true;
@ -176,8 +177,6 @@ bool OpenTxEepromInterface::loadModelVariant(unsigned int index, ModelData &mode
else { else {
model.clear(); model.clear();
} }
// open9xModel.Import(eepromData);
// model.used = true;
} }
return true; return true;