2
2
INCLUDE
3
3
**************************************************************************************/
4
4
5
- #include " lzss .h"
5
+ #include " lzssEncode .h"
6
6
7
7
#include < stdlib.h>
8
8
#include < stdint.h>
9
9
10
10
#include < MKRNB.h>
11
- #include < FlashStorage.h>
12
11
13
12
/* *************************************************************************************
14
13
DEFINE
30
29
**************************************************************************************/
31
30
32
31
extern NBFileUtils fileUtils;
33
- extern FlashClass mcu_flash;
34
32
extern const char * UPDATE_FILE_NAME_LZSS;
35
33
36
- static uint32_t SKETCH_START = 0 ;
37
- static uint32_t LZSS_FILE_SIZE = 0 ;
38
-
39
34
int bit_buffer = 0 , bit_mask = 128 ;
40
- unsigned long codecount = 0 , textcount = 0 ;
35
+ unsigned long textcount = 0 ;
41
36
unsigned char buffer[N * 2 ];
42
37
43
38
static char write_buf[FPUTC_BUF_SIZE];
44
39
static size_t write_buf_num_bytes = 0 ;
45
40
static size_t bytes_written_fputc = 0 ;
46
- static size_t bytes_written_flash = 0 ;
47
- static uint32_t flash_addr = 0 ;
48
41
49
- bool fromLZSStoBIN = true ;
50
42
bool append = false ;
51
43
bool endOfFile = false ;
52
44
53
45
/* *************************************************************************************
54
46
PUBLIC FUNCTIONS
55
47
**************************************************************************************/
56
48
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
-
67
49
void lzss_flush ()
68
50
{
69
51
bytes_written_fputc += write_buf_num_bytes;
70
52
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
+
85
56
write_buf_num_bytes = 0 ;
86
57
}
87
58
@@ -91,16 +62,15 @@ void lzss_flush()
91
62
92
63
void lzss_fputc (int const c)
93
64
{
94
- /* Buffer the decompressed data into a buffer so
65
+ /* Buffer the compressed data into a buffer so
95
66
* 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
98
68
*/
99
69
write_buf[write_buf_num_bytes] = static_cast <char >(c);
100
70
write_buf_num_bytes++;
101
71
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.
104
74
*/
105
75
if (write_buf_num_bytes == FPUTC_BUF_SIZE || endOfFile)
106
76
lzss_flush ();
@@ -130,9 +100,7 @@ void putbit0(void)
130
100
void flush_bit_buffer (void )
131
101
{
132
102
if (bit_mask != 128 ) {
133
- // if (fputc(bit_buffer, outfile) == EOF) error();
134
103
lzss_fputc (bit_buffer);
135
- codecount++;
136
104
}
137
105
}
138
106
0 commit comments