mirror of
https://github.com/opentx/opentx.git
synced 2025-07-25 01:05:10 +03:00
Better fix for model backups import
This commit is contained in:
parent
5da1e35efe
commit
7373ce2cae
4 changed files with 47 additions and 66 deletions
|
@ -4,6 +4,7 @@
|
|||
<li>EEPROM export warning when exporting logical switches > L12 on 9X128</li>
|
||||
<li>FAS offset was not exported on 9X/9XR 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>
|
||||
|
||||
<h2>Version 2.0.6</h2>
|
||||
|
|
|
@ -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<zeroes; i++)
|
||||
dst.append((char)0);
|
||||
zeroes = 0;
|
||||
|
||||
if (IS_SKY9X(board)) {
|
||||
int len = std::min((int)i_len, (int)m_size + (int)sizeof(t_eeprom_header) - (int)m_pos);
|
||||
if (len > 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<bRlc; i++) {
|
||||
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);
|
||||
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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue