From 2352d7d7431e6116f902cc62d8d0c0fb80867b6c Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 3 Jan 2021 21:52:55 +0100 Subject: [PATCH 1/3] add ENS compile warning if no BLE --- src/corona.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/corona.cpp b/src/corona.cpp index a8dd85a4..bd20fb17 100644 --- a/src/corona.cpp +++ b/src/corona.cpp @@ -5,6 +5,10 @@ // (c) by Kaspar Metz // modified for use in the Paxcounter by AQ +#if (COUNT_ENS) && !(BLECOUNTER) +#warning ENS-Counter needs Bluetooth, but Bluetooth compile option is disabled +#endif + #if (COUNT_ENS) // Local logging tag From 59e38762969d198b95b4f6bb932068cbef0bbeb8 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Sun, 3 Jan 2021 22:40:49 +0100 Subject: [PATCH 2/3] rcommand.cpp: code sanitization --- src/rcommand.cpp | 58 ++++++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 1f36b113..9181cdd2 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -379,42 +379,41 @@ void set_saveconfig(uint8_t val[]) { saveConfig(false); }; -// assign previously defined functions to set of numeric remote commands -// format: {opcode, function, number of function arguments} -static const cmd_t table[] = { - {0x01, set_rssi, 1}, {0x02, set_countmode, 1}, - {0x03, set_gps, 1}, {0x04, set_display, 1}, - {0x05, set_loradr, 1}, {0x06, set_lorapower, 1}, - {0x07, set_loraadr, 1}, {0x08, set_screensaver, 1}, - {0x09, set_reset, 1}, {0x0a, set_sendcycle, 1}, - {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, - {0x0d, set_macfilter, 1}, {0x0e, set_blescan, 1}, - {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, - {0x11, set_monitor, 1}, {0x12, set_beacon, 7}, - {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, - {0x15, set_bme, 1}, {0x16, set_batt, 1}, - {0x17, set_wifiscan, 1}, {0x18, set_enscount, 1}, - {0x19, set_sleepcycle, 1}, {0x20, set_loadconfig, 0}, - {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, - {0x81, get_status, 0}, {0x83, get_batt, 0}, - {0x84, get_gps, 0}, {0x85, get_bme, 0}, - {0x86, get_time, 0}, {0x87, set_time, 0}, - {0x99, set_flush, 0}}; - -static const uint8_t cmdtablesize = - sizeof(table) / sizeof(table[0]); // number of commands in command table - // check and execute remote command void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) { + // assign previously defined functions to set of numeric remote commands + // format: {opcode, function, number of function arguments} + + const cmd_t table[] = { + {0x01, set_rssi, 1}, {0x02, set_countmode, 1}, + {0x03, set_gps, 1}, {0x04, set_display, 1}, + {0x05, set_loradr, 1}, {0x06, set_lorapower, 1}, + {0x07, set_loraadr, 1}, {0x08, set_screensaver, 1}, + {0x09, set_reset, 1}, {0x0a, set_sendcycle, 1}, + {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, + {0x0d, set_macfilter, 1}, {0x0e, set_blescan, 1}, + {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, + {0x11, set_monitor, 1}, {0x12, set_beacon, 7}, + {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, + {0x15, set_bme, 1}, {0x16, set_batt, 1}, + {0x17, set_wifiscan, 1}, {0x18, set_enscount, 1}, + {0x19, set_sleepcycle, 1}, {0x20, set_loadconfig, 0}, + {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, + {0x81, get_status, 0}, {0x83, get_batt, 0}, + {0x84, get_gps, 0}, {0x85, get_bme, 0}, + {0x86, get_time, 0}, {0x87, set_time, 0}, + {0x99, set_flush, 0}}; + if (cmdlength == 0) return; uint8_t foundcmd[cmdlength], cursor = 0; + int i = + sizeof(table) / sizeof(table[0]); // number of commands in command table while (cursor < cmdlength) { - int i = cmdtablesize; while (i--) { if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table cursor++; // strip 1 byte opcode @@ -429,9 +428,10 @@ void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) { "Remote command x%02X called with missing parameter(s), " "skipped", table[i].opcode); - break; // command found -> exit table lookup loop - } // end of command validation - } // end of command table lookup loop + break; // command found -> exit table lookup loop + } // end of command validation + } // end of command table lookup loop + if (i < 0) { // command not found -> exit parser ESP_LOGI(TAG, "Unknown remote command x%02X, ignored", cmd[cursor]); break; From 3d6af69c0b41a0ca626586bed5b8156119f82be7 Mon Sep 17 00:00:00 2001 From: cyberman54 Date: Thu, 7 Jan 2021 10:37:55 +0100 Subject: [PATCH 3/3] repair broken rcommand processing --- include/rcommand.h | 1 - src/rcommand.cpp | 52 ++++++++++++++++++++++++---------------------- 2 files changed, 27 insertions(+), 26 deletions(-) diff --git a/include/rcommand.h b/include/rcommand.h index 696a23d2..8149d668 100644 --- a/include/rcommand.h +++ b/include/rcommand.h @@ -25,7 +25,6 @@ typedef struct { const uint8_t opcode; void (*func)(uint8_t[]); const uint8_t params; - const bool store; } cmd_t; // Struct for remote command processing queue diff --git a/src/rcommand.cpp b/src/rcommand.cpp index 9181cdd2..d39ba1f3 100644 --- a/src/rcommand.cpp +++ b/src/rcommand.cpp @@ -379,41 +379,43 @@ void set_saveconfig(uint8_t val[]) { saveConfig(false); }; +// assign previously defined functions to set of numeric remote commands +// format: {opcode, function, number of function arguments} + +static const cmd_t table[] = { + {0x01, set_rssi, 1}, {0x02, set_countmode, 1}, + {0x03, set_gps, 1}, {0x04, set_display, 1}, + {0x05, set_loradr, 1}, {0x06, set_lorapower, 1}, + {0x07, set_loraadr, 1}, {0x08, set_screensaver, 1}, + {0x09, set_reset, 1}, {0x0a, set_sendcycle, 1}, + {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, + {0x0d, set_macfilter, 1}, {0x0e, set_blescan, 1}, + {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, + {0x11, set_monitor, 1}, {0x12, set_beacon, 7}, + {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, + {0x15, set_bme, 1}, {0x16, set_batt, 1}, + {0x17, set_wifiscan, 1}, {0x18, set_enscount, 1}, + {0x19, set_sleepcycle, 1}, {0x20, set_loadconfig, 0}, + {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, + {0x81, get_status, 0}, {0x83, get_batt, 0}, + {0x84, get_gps, 0}, {0x85, get_bme, 0}, + {0x86, get_time, 0}, {0x87, set_time, 0}, + {0x99, set_flush, 0}}; + +static const uint8_t cmdtablesize = + sizeof(table) / sizeof(table[0]); // number of commands in command table + // check and execute remote command void rcmd_execute(const uint8_t cmd[], const uint8_t cmdlength) { - // assign previously defined functions to set of numeric remote commands - // format: {opcode, function, number of function arguments} - - const cmd_t table[] = { - {0x01, set_rssi, 1}, {0x02, set_countmode, 1}, - {0x03, set_gps, 1}, {0x04, set_display, 1}, - {0x05, set_loradr, 1}, {0x06, set_lorapower, 1}, - {0x07, set_loraadr, 1}, {0x08, set_screensaver, 1}, - {0x09, set_reset, 1}, {0x0a, set_sendcycle, 1}, - {0x0b, set_wifichancycle, 1}, {0x0c, set_blescantime, 1}, - {0x0d, set_macfilter, 1}, {0x0e, set_blescan, 1}, - {0x0f, set_wifiant, 1}, {0x10, set_rgblum, 1}, - {0x11, set_monitor, 1}, {0x12, set_beacon, 7}, - {0x13, set_sensor, 2}, {0x14, set_payloadmask, 1}, - {0x15, set_bme, 1}, {0x16, set_batt, 1}, - {0x17, set_wifiscan, 1}, {0x18, set_enscount, 1}, - {0x19, set_sleepcycle, 1}, {0x20, set_loadconfig, 0}, - {0x21, set_saveconfig, 0}, {0x80, get_config, 0}, - {0x81, get_status, 0}, {0x83, get_batt, 0}, - {0x84, get_gps, 0}, {0x85, get_bme, 0}, - {0x86, get_time, 0}, {0x87, set_time, 0}, - {0x99, set_flush, 0}}; - if (cmdlength == 0) return; uint8_t foundcmd[cmdlength], cursor = 0; - int i = - sizeof(table) / sizeof(table[0]); // number of commands in command table while (cursor < cmdlength) { + int i = cmdtablesize; while (i--) { if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table cursor++; // strip 1 byte opcode