rcommand.cpp improved

This commit is contained in:
Klaus K Wilting 2018-08-04 18:09:25 +02:00
parent c623de9a39
commit 0a63b444de
4 changed files with 47 additions and 6 deletions

View File

@ -226,7 +226,7 @@ function Converter(decoded, port) {
# Remote control # Remote control
The device listenes for remote control commands on LoRaWAN Port 2. The device listenes for remote control commands on LoRaWAN Port 2. Multiple commands per downlink are possible by concatenating them.
Note: all settings are stored in NVRAM and will be reloaded when device starts. To reset device to factory settings send remote command 09 02 09 00 unconfirmed(!) once. Note: all settings are stored in NVRAM and will be reloaded when device starts. To reset device to factory settings send remote command 09 02 09 00 unconfirmed(!) once.

View File

@ -40,9 +40,8 @@ lib_deps_gps =
TinyGPSPlus@>=1.0.2 TinyGPSPlus@>=1.0.2
Time@>=1.5 Time@>=1.5
build_flags = build_flags =
; we need build_flag for logging, otherwise we can't use ESP_LOGx in arduino framework
; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <--- ; ---> NOTE: For production run set DEBUG_LEVEL level to NONE! <---
; otherwise device may crash in dense environments due to serial buffer overflow ; otherwise device may leak RAM
; ;
-DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO ; -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_INFO

View File

@ -40,6 +40,9 @@ void doHomework() {
SendData(COUNTERPORT); // send data before clearing counters SendData(COUNTERPORT); // send data before clearing counters
reset_counters(); // clear macs container and reset all counters reset_counters(); // clear macs container and reset all counters
reset_salt(); // get new salt for salting hashes reset_salt(); // get new salt for salting hashes
if (esp_get_minimum_free_heap_size() <= MEM_LOW) // check again
esp_restart(); // memory leak, reset device
} }
} // doHomework() } // doHomework()

View File

@ -337,7 +337,46 @@ cmd_t table[] = {
{0x80, get_config, 0, false}, {0x81, get_status, 0, false}, {0x80, get_config, 0, false}, {0x81, get_status, 0, false},
{0x84, get_gps, 0, false}}; {0x84, get_gps, 0, false}};
const uint8_t cmdtablesize = sizeof(table) / sizeof(table[0]); // number of commands in command table const uint8_t cmdtablesize =
sizeof(table) / sizeof(table[0]); // number of commands in command table
// check and execute remote command
void rcommand(uint8_t cmd[], uint8_t cmdlength) {
if (cmdlength == 0)
return;
uint8_t foundcmd[cmdlength], cursor = 0;
bool storeflag = false;
while (cursor < cmdlength) {
int i = cmdtablesize;
while (i--) {
if (cmd[cursor] == table[i].opcode) { // lookup command in opcode table
cursor++; // strip 1 byte opcode
if ((cursor + table[i].params) <= cmdlength) {
memmove(foundcmd, cmd + cursor,
table[i].params); // strip opcode from cmd array
cursor += table[i].params;
if (table[i].store) // ceck if function needs to store configuration
storeflag = true;
table[i].func(
foundcmd); // execute assigned function with given parameters
} else
ESP_LOGI(
TAG,
"Remote command x%02X called with missing parameter(s), skipped",
table[i].opcode);
break; // exit table lookup loop, command was found
} // lookup command
} // while loop table lookup
} // while loop parsing cmd
if (storeflag)
saveConfig();
} // rcommand()
/*
// check and execute remote command // check and execute remote command
void rcommand(uint8_t cmd[], uint8_t cmdlength) { void rcommand(uint8_t cmd[], uint8_t cmdlength) {
@ -348,7 +387,6 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
cmdlength--; // minus 1 byte for opcode cmdlength--; // minus 1 byte for opcode
int i = cmdtablesize; int i = cmdtablesize;
while (i--) { while (i--) {
if ((cmd[0] == table[i].opcode) && if ((cmd[0] == table[i].opcode) &&
(table[i].params == cmdlength)) { // lookup command in opcode table (table[i].params == cmdlength)) { // lookup command in opcode table
@ -361,4 +399,5 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
} // lookup command } // lookup command
} // while } // while
} // rcommand() } // rcommand()
*/