rcommand.cpp improved
This commit is contained in:
parent
c623de9a39
commit
0a63b444de
@ -226,7 +226,7 @@ function Converter(decoded, port) {
|
||||
|
||||
# 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.
|
||||
|
||||
|
@ -40,9 +40,8 @@ lib_deps_gps =
|
||||
TinyGPSPlus@>=1.0.2
|
||||
Time@>=1.5
|
||||
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! <---
|
||||
; 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_INFO
|
||||
|
@ -40,6 +40,9 @@ void doHomework() {
|
||||
SendData(COUNTERPORT); // send data before clearing counters
|
||||
reset_counters(); // clear macs container and reset all counters
|
||||
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()
|
||||
|
||||
|
@ -337,7 +337,46 @@ cmd_t table[] = {
|
||||
{0x80, get_config, 0, false}, {0x81, get_status, 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
|
||||
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
|
||||
|
||||
int i = cmdtablesize;
|
||||
|
||||
while (i--) {
|
||||
if ((cmd[0] == table[i].opcode) &&
|
||||
(table[i].params == cmdlength)) { // lookup command in opcode table
|
||||
@ -362,3 +400,4 @@ void rcommand(uint8_t cmd[], uint8_t cmdlength) {
|
||||
} // while
|
||||
|
||||
} // rcommand()
|
||||
*/
|
Loading…
Reference in New Issue
Block a user