Skip to content

Commit 768d754

Browse files
committed
Cleanup lzss libraries and rename to lzssEncode inside SBU_LoadLZSS
1 parent b05f4bc commit 768d754

File tree

7 files changed

+2041
-2142
lines changed

7 files changed

+2041
-2142
lines changed

libraries/SBU/examples/SBU_LoadLZSS/SBU_LoadLZSS.ino

+2-12
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
#include <MKRNB.h>
22
#include <SBU.h>
3-
#include <FlashStorage.h>
43

5-
#include "lzss.h"
6-
7-
FlashClass mcu_flash;
4+
#include "lzssEncode.h"
85

96
static char const BINARY[] =
107
{
@@ -17,7 +14,7 @@ static char const CHECK_FILE[] =
1714
};
1815

1916
static constexpr char CHECK_FILE_NAME[] = "UPDATE.OK";
20-
constexpr char UPDATE_FILE_NAME[] = "UPDATE.BIN.LZSS";
17+
const char * UPDATE_FILE_NAME_LZSS = "UPDATE.BIN.LZSS";
2118

2219
NBFileUtils fileUtils;
2320
bool update_available = false;
@@ -42,13 +39,6 @@ void setup() {
4239
Serial.println(bytes_to_write);
4340

4441
Serial.print("Encoding \"BINARY.H\" into \"UPDATE.BIN.LZSS\" and writing it into the Sara-R410M module ... ");
45-
46-
/*
47-
* Set the lzss parameter in the following way:
48-
* - 0, false : you want to perform a LZSS encoding (.H -> .LZSS)
49-
* - SKETCH_START, true: you want to perform a LZSS decoding (.LZSS -> .H)
50-
*/
51-
lzss_init(0, false);
5242

5343
//Encode into .lzss and write to the Sara modem
5444
int bytes_written = lzss_encode(BINARY, bytes_to_write);

libraries/SBU/examples/SBU_LoadLZSS/lzss.cpp libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.cpp

+9-41
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
INCLUDE
33
**************************************************************************************/
44

5-
#include "lzss.h"
5+
#include "lzssEncode.h"
66

77
#include <stdlib.h>
88
#include <stdint.h>
99

1010
#include <MKRNB.h>
11-
#include <FlashStorage.h>
1211

1312
/**************************************************************************************
1413
DEFINE
@@ -30,58 +29,30 @@
3029
**************************************************************************************/
3130

3231
extern NBFileUtils fileUtils;
33-
extern FlashClass mcu_flash;
3432
extern const char * UPDATE_FILE_NAME_LZSS;
3533

36-
static uint32_t SKETCH_START = 0;
37-
static uint32_t LZSS_FILE_SIZE = 0;
38-
3934
int bit_buffer = 0, bit_mask = 128;
40-
unsigned long codecount = 0, textcount = 0;
35+
unsigned long textcount = 0;
4136
unsigned char buffer[N * 2];
4237

4338
static char write_buf[FPUTC_BUF_SIZE];
4439
static size_t write_buf_num_bytes = 0;
4540
static size_t bytes_written_fputc = 0;
46-
static size_t bytes_written_flash = 0;
47-
static uint32_t flash_addr = 0;
4841

49-
bool fromLZSStoBIN = true;
5042
bool append = false;
5143
bool endOfFile = false;
5244

5345
/**************************************************************************************
5446
PUBLIC FUNCTIONS
5547
**************************************************************************************/
5648

57-
void lzss_init(uint32_t const sketch_start, bool LZSStoBIN)
58-
{
59-
fromLZSStoBIN = LZSStoBIN;
60-
if (LZSStoBIN) {
61-
SKETCH_START = sketch_start;
62-
flash_addr = sketch_start;
63-
LZSS_FILE_SIZE = fileUtils.listFile("UPDATE.BIN.LZSS");
64-
}
65-
}
66-
6749
void lzss_flush()
6850
{
6951
bytes_written_fputc += write_buf_num_bytes;
7052

71-
if (fromLZSStoBIN) {
72-
/* Only write to the flash once we've surpassed
73-
* the SBU in the update binary.
74-
*/
75-
if (bytes_written_fputc > (SKETCH_START - 0x2000))
76-
{
77-
mcu_flash.write((void*)flash_addr, write_buf, write_buf_num_bytes);
78-
flash_addr += write_buf_num_bytes;
79-
}
80-
} else {
81-
fileUtils.downloadFile("UPDATE.BIN.LZSS", write_buf, write_buf_num_bytes, append);
82-
append = true;
83-
}
84-
53+
fileUtils.downloadFile(UPDATE_FILE_NAME_LZSS, write_buf, write_buf_num_bytes, append); //UPDATE.BIN.LZSS
54+
append = true;
55+
8556
write_buf_num_bytes = 0;
8657
}
8758

@@ -91,16 +62,15 @@ void lzss_flush()
9162

9263
void lzss_fputc(int const c)
9364
{
94-
/* Buffer the decompressed data into a buffer so
65+
/* Buffer the compressed data into a buffer so
9566
* we can perform block writes and don't need to
96-
* write every byte singly on the flash (which
97-
* wouldn't be possible anyway).
67+
* write every byte singly on the modem
9868
*/
9969
write_buf[write_buf_num_bytes] = static_cast<char>(c);
10070
write_buf_num_bytes++;
10171

102-
/* The write buffer is full of decompressed
103-
* data, write it to the flash now.
72+
/* The write buffer is full of compressed
73+
* data, write it to the modem now.
10474
*/
10575
if (write_buf_num_bytes == FPUTC_BUF_SIZE || endOfFile)
10676
lzss_flush();
@@ -130,9 +100,7 @@ void putbit0(void)
130100
void flush_bit_buffer(void)
131101
{
132102
if (bit_mask != 128) {
133-
//if (fputc(bit_buffer, outfile) == EOF) error();
134103
lzss_fputc(bit_buffer);
135-
codecount++;
136104
}
137105
}
138106

libraries/SBU/examples/SBU_LoadLZSS/lzss.h libraries/SBU/examples/SBU_LoadLZSS/lzssEncode.h

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
FUNCTION DEFINITION
1212
**************************************************************************************/
1313

14-
void lzss_init(uint32_t const sketch_start, bool LZSStoBIN);
1514
void lzss_flush();
1615
int lzss_encode(const char buf_in[], uint32_t size);
1716

libraries/SBU/extras/SBUBoot/SBUBoot.ino

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ int main()
6565
/* Initialize the lzss module with the data which
6666
* it requires.
6767
*/
68-
lzss_init((uint32_t)SKETCH_START, true);
68+
lzss_init((uint32_t)SKETCH_START);
6969
/* During the process of decoding UPDATE.BIN.LZSS
7070
* is decompressed and stored as UPDATE.BIN.
7171
*/

libraries/SBU/extras/SBUBoot/lzss.cpp

+13-25
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ static uint32_t SKETCH_START = 0;
3737
static uint32_t LZSS_FILE_SIZE = 0;
3838

3939
int bit_buffer = 0, bit_mask = 128;
40-
unsigned long codecount = 0, textcount = 0;
4140
unsigned char buffer[N * 2];
4241

4342
static char write_buf[FPUTC_BUF_SIZE];
@@ -46,40 +45,29 @@ static size_t bytes_written_fputc = 0;
4645
static size_t bytes_written_flash = 0;
4746
static uint32_t flash_addr = 0;
4847

49-
bool fromLZSStoBIN = true;
50-
bool append = false;
51-
5248
/**************************************************************************************
5349
PUBLIC FUNCTIONS
5450
**************************************************************************************/
5551

56-
void lzss_init(uint32_t const sketch_start, bool LZSStoBIN)
52+
void lzss_init(uint32_t const sketch_start)
5753
{
58-
fromLZSStoBIN = LZSStoBIN;
59-
if (LZSStoBIN) {
60-
SKETCH_START = sketch_start;
61-
flash_addr = sketch_start;
62-
LZSS_FILE_SIZE = fileUtils.listFile("UPDATE.BIN.LZSS");
63-
}
54+
SKETCH_START = sketch_start;
55+
flash_addr = sketch_start;
56+
LZSS_FILE_SIZE = fileUtils.listFile(UPDATE_FILE_NAME_LZSS);
6457
}
6558

6659
void lzss_flush()
6760
{
6861
bytes_written_fputc += write_buf_num_bytes;
6962

70-
if (fromLZSStoBIN) {
71-
/* Only write to the flash once we've surpassed
72-
* the SBU in the update binary.
73-
*/
74-
if (bytes_written_fputc > (SKETCH_START - 0x2000))
75-
{
76-
mcu_flash.write((void*)flash_addr, write_buf, write_buf_num_bytes);
77-
flash_addr += write_buf_num_bytes;
78-
}
79-
} else {
80-
fileUtils.downloadFile("UPDATE.BIN.LZSS", write_buf, write_buf_num_bytes, append);
81-
append = true;
82-
}
63+
/* Only write to the flash once we've surpassed
64+
* the SBU in the update binary.
65+
*/
66+
if (bytes_written_fputc > (SKETCH_START - 0x2000))
67+
{
68+
mcu_flash.write((void*)flash_addr, write_buf, write_buf_num_bytes);
69+
flash_addr += write_buf_num_bytes;
70+
}
8371

8472
write_buf_num_bytes = 0;
8573
}
@@ -228,4 +216,4 @@ void lzss_decode(void)
228216
}
229217
}
230218
}
231-
}
219+
}

libraries/SBU/extras/SBUBoot/lzss.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
FUNCTION DEFINITION
1212
**************************************************************************************/
1313

14-
void lzss_init(uint32_t const sketch_start, bool LZSStoBIN);
14+
void lzss_init(uint32_t const sketch_start);
1515
void lzss_decode();
1616
void lzss_flush();
1717

0 commit comments

Comments
 (0)