Add RTL_433_REDUCE_STACK_USE to reduce size of bitbuffers (#1863)

- introduce RTL_433_REDUCE_STACK_USE which, when defined, drastically reduces the size of bitrow_t, thus saving lots of stack space.
This commit is contained in:
obones
2021-11-12 17:34:43 +01:00
committed by GitHub
parent 7dbeb5c268
commit 04cbdbcbf0
3 changed files with 14 additions and 5 deletions

View File

@@ -15,8 +15,14 @@
#include <stdint.h>
// NOTE: Wireless mbus protocol needs at least ((256+16*2+3)*12)/8 => 437 bytes
// which fits even if RTL_433_REDUCE_STACK_USE is defined because of row spilling
#ifdef RTL_433_REDUCE_STACK_USE
#define BITBUF_COLS 40 // Number of bytes in a column
#define BITBUF_ROWS 25
#else
#define BITBUF_COLS 128 // Number of bytes in a column
#define BITBUF_ROWS 50
#endif
#define BITBUF_MAX_PRINT_BITS 50 // Maximum number of bits to print (in addition to hex values)
typedef uint8_t bitrow_t[BITBUF_COLS];

View File

@@ -100,7 +100,7 @@ static int lacrossews_callback(r_device *decoder, bitbuffer_t *bitbuffer)
float temp_c, wind_dir, wind_spd, rain_mm;
data_t *data;
for (row = 0; row < BITBUF_ROWS; row++) {
for (row = 0; row < bitbuffer->num_rows; row++) {
// break out the message nybbles into separate bytes
if (lacrossews_detect(decoder, bitbuffer->bb[row], msg_nybbles, bitbuffer->bits_per_row[row]) <= 0)
continue; // DECODE_ABORT_EARLY

View File

@@ -568,6 +568,9 @@ static int oregon_scientific_v2_1_decode(r_device *decoder, bitbuffer_t *bitbuff
return 0;
}
// ceil( (335 + 11) / 8 )
#define EXPECTED_NUM_BYTES 44
static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer)
{
uint8_t *b = bitbuffer->bb[0];
@@ -583,7 +586,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
return DECODE_ABORT_EARLY;
}
unsigned char msg[BITBUF_COLS] = {0};
unsigned char msg[EXPECTED_NUM_BYTES] = {0};
int msg_pos = 0;
int msg_len = 0;
@@ -627,7 +630,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
msg_len = bitbuffer->bits_per_row[0] - alt_pos;
}
if (msg_len == 0)
if (msg_len == 0 || msg_len > (int)sizeof(msg) * 8)
return DECODE_ABORT_EARLY;
bitbuffer_extract_bytes(bitbuffer, 0, msg_pos, msg, msg_len);
@@ -759,7 +762,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
else if (msg[0] == 0x26) { // Owl CM180 readings
msg[0] = msg[0] & 0x0f;
int valid = validate_os_checksum(decoder, msg, 23);
for (int k = 0; k < BITBUF_COLS; k++) { // Reverse nibbles
for (int k = 0; k < EXPECTED_NUM_BYTES; k++) { // Reverse nibbles
msg[k] = (msg[k] & 0xF0) >> 4 | (msg[k] & 0x0F) << 4;
}
// TODO: should we return if valid == 0?
@@ -791,7 +794,7 @@ static int oregon_scientific_v3_decode(r_device *decoder, bitbuffer_t *bitbuffer
msg[0] = msg[0] & 0x0f;
// to be done
// int valid = validate_os_checksum(decoder, msg, 23);
for (int k = 0; k < BITBUF_COLS; k++) { // Reverse nibbles
for (int k = 0; k < EXPECTED_NUM_BYTES; k++) { // Reverse nibbles
msg[k] = (msg[k] & 0xF0) >> 4 | (msg[k] & 0x0F) << 4;
}
// TODO: should we return if valid == 0?