[Horus] Ram backup continued (RLC methods added)
This commit is contained in:
@@ -436,9 +436,11 @@ unsigned int importRlc(QByteArray & dst, QByteArray & src, unsigned int rlcVersi
|
||||
dst.resize(0);
|
||||
|
||||
for( ; 1; ) {
|
||||
for (int i=0; i<zeroes; i++)
|
||||
dst.append((char)0);
|
||||
zeroes = 0;
|
||||
if (zeroes > 0) {
|
||||
for (int i = 0; i < zeroes; i++)
|
||||
dst.append((char) 0);
|
||||
zeroes = 0;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
return dst.size();
|
||||
|
||||
@@ -703,7 +703,7 @@ set(GUI_SRC
|
||||
|
||||
if(RAMBACKUP)
|
||||
add_definitions(-DRAMBACKUP)
|
||||
set(SRC ${SRC} storage/rambackup.cpp)
|
||||
set(SRC ${SRC} storage/rambackup.cpp storage/rlc.cpp)
|
||||
endif()
|
||||
|
||||
if(VIRTUAL_INPUTS)
|
||||
|
||||
@@ -1975,11 +1975,6 @@ uint8_t calcStickScroll( uint8_t index )
|
||||
|
||||
void opentxStart()
|
||||
{
|
||||
#if defined(RAMBACKUP) && defined(SIMU)
|
||||
// TODO just for tests
|
||||
RamBackupWrite();
|
||||
#endif
|
||||
|
||||
doSplash();
|
||||
|
||||
#if defined(DEBUG_TRACE_BUFFER)
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
namespace Backup {
|
||||
#define BACKUP
|
||||
#include "datastructs.h"
|
||||
PACK(struct RamBackup {
|
||||
PACK(struct RamBackupUncompressed {
|
||||
ModelData model;
|
||||
RadioData radio;
|
||||
});
|
||||
@@ -32,17 +32,42 @@ PACK(struct RamBackup {
|
||||
|
||||
#include "datacopy.cpp"
|
||||
|
||||
Backup::RamBackup ramBackup;
|
||||
Backup::RamBackupUncompressed ramBackupUncompressed __DMA;
|
||||
|
||||
void RamBackupWrite()
|
||||
PACK(struct RamBackup {
|
||||
uint16_t size;
|
||||
uint8_t data[4094];
|
||||
});
|
||||
|
||||
RamBackup ramBackup;
|
||||
|
||||
void rambackupWrite()
|
||||
{
|
||||
TRACE("RamBackup size=%d vs %d", sizeof(Backup::RamBackup), sizeof(ModelData)+sizeof(RadioData));
|
||||
copyRadioData(&ramBackup.radio, &g_eeGeneral);
|
||||
copyModelData(&ramBackup.model, &g_model);
|
||||
copyRadioData(&ramBackupUncompressed.radio, &g_eeGeneral);
|
||||
copyModelData(&ramBackupUncompressed.model, &g_model);
|
||||
ramBackup.size = compress(ramBackup.data, (const uint8_t *)&ramBackupUncompressed, sizeof(ramBackupUncompressed));
|
||||
TRACE("RamBackupWrite sdsize=%d backupsize=%d rlcsize=%d", sizeof(ModelData)+sizeof(RadioData), sizeof(Backup::RamBackupUncompressed), ramBackup.size);
|
||||
|
||||
#if 0
|
||||
// TODO move this code to non regression tests
|
||||
Backup::RamBackupUncompressed ramBackupRestored;
|
||||
if (uncompress((uint8_t *)&ramBackupRestored, ramBackup.data, ramBackup.size) != sizeof(ramBackupUncompressed))
|
||||
TRACE("ERROR size");
|
||||
if (memcmp(&ramBackupUncompressed, &ramBackupRestored, sizeof(ramBackupUncompressed)) != 0)
|
||||
TRACE("ERROR restore");
|
||||
#endif
|
||||
}
|
||||
|
||||
void RamBackupRead()
|
||||
bool rambackupRestore()
|
||||
{
|
||||
copyRadioData(&g_eeGeneral, &ramBackup.radio);
|
||||
copyModelData(&g_model, &ramBackup.model);
|
||||
if (ramBackup.size == 0)
|
||||
return false;
|
||||
|
||||
if (uncompress((uint8_t *)&ramBackupUncompressed, ramBackup.data, ramBackup.size) != sizeof(ramBackupUncompressed))
|
||||
return false;
|
||||
|
||||
copyRadioData(&g_eeGeneral, &ramBackupUncompressed.radio);
|
||||
copyModelData(&g_model, &ramBackupUncompressed.model);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) OpenTX
|
||||
*
|
||||
* Based on code named
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include <inttypes.h>
|
||||
#include <assert.h>
|
||||
#include "debug.h"
|
||||
|
||||
unsigned int compress(uint8_t * dst, const uint8_t * src, unsigned int len)
|
||||
{
|
||||
uint8_t * cur = dst;
|
||||
bool run0 = (src[0] == 0);
|
||||
uint8_t cnt = 1;
|
||||
uint8_t cnt0 = 0;
|
||||
|
||||
for (unsigned int i=1; 1; i++) {
|
||||
bool cur0 = (src[i] == 0);
|
||||
if (i==len || cur0!=run0 || cnt==0x3f || (cnt0 && cnt==0xf)) {
|
||||
if (run0) {
|
||||
assert(cnt0==0);
|
||||
if (cnt<8 && i!=len)
|
||||
cnt0 = cnt;
|
||||
else
|
||||
*cur++ = (cnt|0x40);
|
||||
}
|
||||
else {
|
||||
if (cnt0) {
|
||||
*cur++ = (0x80 | (cnt0<<4) | cnt);
|
||||
cnt0 = 0;
|
||||
}
|
||||
else {
|
||||
*cur++ = cnt;
|
||||
}
|
||||
for (int j=0; j<cnt; j++) {
|
||||
*cur++ = src[i - cnt + j];
|
||||
}
|
||||
}
|
||||
cnt = 0;
|
||||
if (i==len) break;
|
||||
run0 = cur0;
|
||||
}
|
||||
cnt++;
|
||||
}
|
||||
|
||||
return cur-dst;
|
||||
}
|
||||
|
||||
unsigned int uncompress(uint8_t * dst, const uint8_t * src, unsigned int len)
|
||||
{
|
||||
uint8_t * cur = dst;
|
||||
uint8_t zeroes = 0;
|
||||
uint8_t bRlc = 0;
|
||||
|
||||
for( ; 1; ) {
|
||||
if (zeroes > 0) {
|
||||
for (int i = 0; i < zeroes; i++) {
|
||||
*cur++ = 0;
|
||||
}
|
||||
zeroes = 0;
|
||||
}
|
||||
|
||||
if (len == 0)
|
||||
return cur-dst;
|
||||
|
||||
for (int i=0; i<bRlc; i++) {
|
||||
*cur++ = *src++;
|
||||
if (--len == 0)
|
||||
return cur-dst;
|
||||
}
|
||||
|
||||
bRlc = *src++;
|
||||
--len;
|
||||
|
||||
if (!(bRlc & 0x7f)) {
|
||||
TRACE("RLC decoding error");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (bRlc & 0x80) { // if contains high byte
|
||||
zeroes = (bRlc>>4) & 0x07;
|
||||
bRlc = bRlc & 0x0f;
|
||||
}
|
||||
else if (bRlc & 0x40) {
|
||||
zeroes = bRlc & 0x3f;
|
||||
bRlc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -58,8 +58,10 @@ void postModelLoad(bool newModel);
|
||||
#endif
|
||||
|
||||
#if defined(RAMBACKUP)
|
||||
void RamBackupWrite();
|
||||
void RamBackupRead();
|
||||
void rambackupWrite();
|
||||
bool rambackupRestore();
|
||||
unsigned int compress(uint8_t * dst, const uint8_t * src, unsigned int len);
|
||||
unsigned int uncompress(uint8_t * dst, const uint8_t * src, unsigned int len);
|
||||
#endif
|
||||
|
||||
#endif // _STORAGE_H_
|
||||
|
||||
Reference in New Issue
Block a user