From 29e118c4f85bafaca39852e933e8cc24d0d0b6fd Mon Sep 17 00:00:00 2001 From: vad7 Date: Tue, 4 Apr 2023 11:16:56 +0300 Subject: [PATCH] fix --- Distr/nrf24batch/CO2_mini.txt | 4 ++-- nrf24batch.c | 40 ++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Distr/nrf24batch/CO2_mini.txt b/Distr/nrf24batch/CO2_mini.txt index bc5dbb00665..9aaa05db059 100644 --- a/Distr/nrf24batch/CO2_mini.txt +++ b/Distr/nrf24batch/CO2_mini.txt @@ -45,7 +45,7 @@ R: CO2 threshold*2=5,,0xC2 W: CO2 threshold=,5,0x82 R: CO2 correct*2=7,,0xC2 -W: CO2 correct=,7,0x82 +W: CO2 correct*2=,7,0x82 R: FanLSB[10]=i:9# W: FanLSB=,i:9 @@ -66,7 +66,7 @@ S: LED=,0,0x40 SBatch: LED On: LED=1 SBatch: LED Off: LED=0 -RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;Send pause;Flags +RBatch: Settings: ID;RxAddr;Ch;Send period;CO2 threshold;CO2 correct;FanLSB;nRF RETR;Transmit pause;Flags WBatch: Default: RxAddr=0xCF;Ch=122;Send period=30;CO2 threshold=1000;CO2 correct=0;FanLSB={0xC1,0,0,0,0,0,0,0};nRF RETR=0x3;Transmit pause=1;Flags=0;Reset WBatch: CO2: CO2 threshold=1000;CO2 correct=0 diff --git a/nrf24batch.c b/nrf24batch.c index ee692698040..76655ca9e61 100644 --- a/nrf24batch.c +++ b/nrf24batch.c @@ -481,11 +481,12 @@ bool nrf24_read_newpacket() { if(size == 0) furi_string_cat_printf(str, "%c", (char)var); else { char hex[9]; - snprintf(hex, sizeof(hex), "%lX", var); + hex[0] = '\0'; + add_to_str_hex_bytes(hex, (uint8_t*)&var, size); if((cmd_array && cmd_array_hex) || furi_string_end_with_str(str, "0x")) furi_string_cat_str(str, hex); else { if(var >= 0 && var <= 9) furi_string_cat_printf(str, "%ld", var); - else furi_string_cat_printf(str, "%ld (%s)", var, hex + (var < 0 ? 8 - size * 2 : 0)); + else furi_string_cat_printf(str, "%ld (%s)", var, hex); } } if(cmd_array) { @@ -970,23 +971,24 @@ static void save_batch(void) if(p2 && *(p2-1) != '*') { // skip string if(*(p2-1) == ']') { // array char *p3 = strchr(p, '['); - if(p3 == NULL) p3 = p2; - stream_write(file_stream, (uint8_t*)p, p3 - p); - stream_write_cstring(file_stream, "={"); - p = (p2 += 2); - do { - while(is_digit(p2, true) || *p2 == 'x') p2++; - stream_write(file_stream, (uint8_t*)p, p2 - p); - char c = *p2; - if(c == '\0') break; - if(c != ',') { - p2 = strchr(p2, ','); - if(p2 == NULL) break; - } - stream_write_char(file_stream, ','); - p = ++p2; - } while(1); - stream_write_char(file_stream, '}'); + if(p3) { + stream_write(file_stream, (uint8_t*)p, p3 - p - (*(p3-2) == '*' ? 2 : 0)); + stream_write_cstring(file_stream, "={"); + p = (p2 += 2); + do { + while(is_digit(p2, true) || *p2 == 'x') p2++; + stream_write(file_stream, (uint8_t*)p, p2 - p); + char c = *p2; + if(c == '\0') break; + if(c != ',') { + p2 = strchr(p2, ','); + if(p2 == NULL) break; + } + stream_write_char(file_stream, ','); + p = ++p2; + } while(1); + stream_write_char(file_stream, '}'); + } } else { stream_write(file_stream, (uint8_t*)p, p2 - p - (*(p2-2) == '*' ? 2 : 0)); stream_write_char(file_stream, '=');