bugfix rcommand.cpp
This commit is contained in:
parent
3f9b4efc46
commit
d7a1922b95
@ -8,7 +8,7 @@
|
|||||||
#include <esp32-hal-log.h>
|
#include <esp32-hal-log.h>
|
||||||
|
|
||||||
// attn: increment version after modifications to configData_t truct!
|
// attn: increment version after modifications to configData_t truct!
|
||||||
#define PROGVERSION "1.4.0" // use max 10 chars here!
|
#define PROGVERSION "1.4.1" // use max 10 chars here!
|
||||||
#define PROGNAME "PAXCNT"
|
#define PROGNAME "PAXCNT"
|
||||||
|
|
||||||
// std::set for unified array functions
|
// std::set for unified array functions
|
||||||
|
28
src/main.cpp
28
src/main.cpp
@ -27,7 +27,6 @@ licenses. Refer to LICENSE.txt file in repository for more details.
|
|||||||
#include "globals.h"
|
#include "globals.h"
|
||||||
#include "main.h"
|
#include "main.h"
|
||||||
|
|
||||||
|
|
||||||
configData_t cfg; // struct holds current device configuration
|
configData_t cfg; // struct holds current device configuration
|
||||||
char display_line6[16], display_line7[16]; // display buffers
|
char display_line6[16], display_line7[16]; // display buffers
|
||||||
uint8_t channel = 0; // channel rotation counter
|
uint8_t channel = 0; // channel rotation counter
|
||||||
@ -60,7 +59,7 @@ static const char TAG[] = "main";
|
|||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
char features[64] = "";
|
char features[100] = "";
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
@ -108,8 +107,12 @@ void setup() {
|
|||||||
// read settings from NVRAM
|
// read settings from NVRAM
|
||||||
loadConfig(); // includes initialize if necessary
|
loadConfig(); // includes initialize if necessary
|
||||||
|
|
||||||
|
#ifdef VENDORFILTER
|
||||||
|
strcat_P(features, " OUIFLT");
|
||||||
|
#endif
|
||||||
|
|
||||||
// initialize LoRa
|
// initialize LoRa
|
||||||
#if HAS_LORA
|
#ifdef HAS_LORA
|
||||||
strcat_P(features, " LORA");
|
strcat_P(features, " LORA");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -205,13 +208,13 @@ void setup() {
|
|||||||
|
|
||||||
// show payload encoder
|
// show payload encoder
|
||||||
#if PAYLOAD_ENCODER == 1
|
#if PAYLOAD_ENCODER == 1
|
||||||
strcat_P(features, " PAYLOAD_PLAIN");
|
strcat_P(features, " PLAIN");
|
||||||
#elif PAYLOAD_ENCODER == 2
|
#elif PAYLOAD_ENCODER == 2
|
||||||
strcat_P(features, " PAYLOAD_PACKED");
|
strcat_P(features, " PACKED");
|
||||||
#elif PAYLOAD_ENCODER == 3
|
#elif PAYLOAD_ENCODER == 3
|
||||||
strcat_P(features, " PAYLOAD_LPP_DYN");
|
strcat_P(features, " LPPDYN");
|
||||||
#elif PAYLOAD_ENCODER == 4
|
#elif PAYLOAD_ENCODER == 4
|
||||||
strcat_P(features, " PAYLOAD_LPP_PKD");
|
strcat_P(features, " LPPPKD");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// show compiled features
|
// show compiled features
|
||||||
@ -264,12 +267,12 @@ void setup() {
|
|||||||
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
ESP_LOGI(TAG, "Starting Wifi task on core 0");
|
||||||
wifi_sniffer_init();
|
wifi_sniffer_init();
|
||||||
// initialize salt value using esp_random() called by random() in
|
// initialize salt value using esp_random() called by random() in
|
||||||
// arduino-esp32 core note: do this *after* wifi has started, since function
|
// arduino-esp32 core. Note: do this *after* wifi has started, since function
|
||||||
// gets it's seed from RF noise
|
// gets it's seed from RF noise
|
||||||
reset_salt(); // get new 16bit for salting hashes
|
reset_salt(); // get new 16bit for salting hashes
|
||||||
xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1,
|
xTaskCreatePinnedToCore(wifi_channel_loop, "wifiloop", 2048, (void *)1, 1,
|
||||||
NULL, 0);
|
NULL, 0);
|
||||||
} // setup
|
} // setup()
|
||||||
|
|
||||||
/* end Arduino SETUP
|
/* end Arduino SETUP
|
||||||
* ------------------------------------------------------------ */
|
* ------------------------------------------------------------ */
|
||||||
@ -294,13 +297,14 @@ void loop() {
|
|||||||
updateDisplay();
|
updateDisplay();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// check housekeeping cycle and to homework if expired
|
// check housekeeping cycle and if expired do homework
|
||||||
checkHousekeeping();
|
checkHousekeeping();
|
||||||
// check send cycle and send payload if cycle is expired
|
// check send cycle and send payload if cycle is expired
|
||||||
sendPayload();
|
sendPayload();
|
||||||
vTaskDelay(1 / portTICK_PERIOD_MS); // reset watchdog
|
// reset watchdog
|
||||||
|
vTaskDelay(1 / portTICK_PERIOD_MS);
|
||||||
|
|
||||||
} // end of infinite main loop
|
} // loop()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* end Arduino main loop
|
/* end Arduino main loop
|
||||||
|
@ -63,9 +63,8 @@ void set_reset(uint8_t val[]) {
|
|||||||
case 0: // restart device
|
case 0: // restart device
|
||||||
ESP_LOGI(TAG, "Remote command: restart device");
|
ESP_LOGI(TAG, "Remote command: restart device");
|
||||||
sprintf(display_line6, "Reset pending");
|
sprintf(display_line6, "Reset pending");
|
||||||
vTaskDelay(
|
vTaskDelay(10000 / portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa
|
||||||
10000 /
|
// downlink to server
|
||||||
portTICK_PERIOD_MS); // wait for LMIC to confirm LoRa downlink to server
|
|
||||||
esp_restart();
|
esp_restart();
|
||||||
break;
|
break;
|
||||||
case 1: // reset MAC counter
|
case 1: // reset MAC counter
|
||||||
@ -79,6 +78,8 @@ void set_reset(uint8_t val[]) {
|
|||||||
sprintf(display_line6, "Factory reset");
|
sprintf(display_line6, "Factory reset");
|
||||||
eraseConfig();
|
eraseConfig();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
ESP_LOGW(TAG, "Remote command: reset called with invalid parameter(s)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,7 +93,7 @@ void set_sendcycle(uint8_t val[]) {
|
|||||||
// update send cycle interrupt
|
// update send cycle interrupt
|
||||||
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
|
timerAlarmWrite(sendCycle, cfg.sendcycle * 2 * 10000, true);
|
||||||
// reload interrupt after each trigger of channel switch cycle
|
// reload interrupt after each trigger of channel switch cycle
|
||||||
ESP_LOGI(TAG, "Remote command: set payload send cycle to %d seconds",
|
ESP_LOGI(TAG, "Remote command: set send cycle to %d seconds",
|
||||||
cfg.sendcycle * 2);
|
cfg.sendcycle * 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -129,10 +130,14 @@ void set_countmode(uint8_t val[]) {
|
|||||||
cfg.countermode = 1;
|
cfg.countermode = 1;
|
||||||
ESP_LOGI(TAG, "Remote command: set counter mode to cumulative");
|
ESP_LOGI(TAG, "Remote command: set counter mode to cumulative");
|
||||||
break;
|
break;
|
||||||
default: // cyclic confirmed
|
case 2: // cyclic confirmed
|
||||||
cfg.countermode = 2;
|
cfg.countermode = 2;
|
||||||
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic confirmed");
|
ESP_LOGI(TAG, "Remote command: set counter mode to cyclic confirmed");
|
||||||
break;
|
break;
|
||||||
|
default: // invalid parameter
|
||||||
|
ESP_LOGW(
|
||||||
|
TAG,
|
||||||
|
"Remote command: set counter mode called with invalid parameter(s)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -170,18 +175,15 @@ void set_gps(uint8_t val[]) {
|
|||||||
default:
|
default:
|
||||||
cfg.gpsmode = 0;
|
cfg.gpsmode = 0;
|
||||||
break;
|
break;
|
||||||
}
|
};
|
||||||
};
|
}
|
||||||
|
|
||||||
void set_beacon(uint8_t val[]) {
|
void set_beacon(uint8_t val[]) {
|
||||||
if (sizeof(*val) / sizeof(val[0]) == 7) {
|
|
||||||
uint8_t id = val[0]; // use first parameter as beacon storage id
|
uint8_t id = val[0]; // use first parameter as beacon storage id
|
||||||
memmove(val, val + 1, 6); // strip off storage id
|
memmove(val, val + 1, 6); // strip off storage id
|
||||||
beacons[id] = macConvert(val); // store beacon MAC in array
|
beacons[id] = macConvert(val); // store beacon MAC in array
|
||||||
ESP_LOGI(TAG, "Remote command: set beacon ID#%d", id);
|
ESP_LOGI(TAG, "Remote command: set beacon ID#%d", id);
|
||||||
printKey("MAC", val, 6, false); // show beacon MAC
|
printKey("MAC", val, 6, false); // show beacon MAC
|
||||||
} else
|
|
||||||
ESP_LOGW(TAG, "Remote command: set beacon called with invalid parameters");
|
|
||||||
};
|
};
|
||||||
|
|
||||||
void set_monitor(uint8_t val[]) {
|
void set_monitor(uint8_t val[]) {
|
||||||
@ -319,46 +321,43 @@ void get_gps(uint8_t val[]) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// assign previously defined functions to set of numeric remote commands
|
// assign previously defined functions to set of numeric remote commands
|
||||||
// format: opcode, function, flag (1 = do make settings persistent / 0 = don't)
|
// format: opcode, function, #bytes params,
|
||||||
|
// flag (1 = do make settings persistent / 0 = don't)
|
||||||
//
|
//
|
||||||
cmd_t table[] = {{0x01, set_rssi, true}, {0x02, set_countmode, true},
|
cmd_t table[] = {
|
||||||
{0x03, set_gps, true}, {0x04, set_display, true},
|
{0x01, set_rssi, 1, true}, {0x02, set_countmode, 1, true},
|
||||||
{0x05, set_lorasf, true}, {0x06, set_lorapower, true},
|
{0x03, set_gps, 1, true}, {0x04, set_display, 1, true},
|
||||||
{0x07, set_loraadr, true}, {0x08, set_screensaver, true},
|
{0x05, set_lorasf, 1, true}, {0x06, set_lorapower, 1, true},
|
||||||
{0x09, set_reset, false}, {0x0a, set_sendcycle, true},
|
{0x07, set_loraadr, 1, true}, {0x08, set_screensaver, 1, true},
|
||||||
{0x0b, set_wifichancycle, true}, {0x0c, set_blescantime, true},
|
{0x09, set_reset, 1, false}, {0x0a, set_sendcycle, 1, true},
|
||||||
{0x0d, set_vendorfilter, false}, {0x0e, set_blescan, true},
|
{0x0b, set_wifichancycle, 1, true}, {0x0c, set_blescantime, 1, true},
|
||||||
{0x0f, set_wifiant, true}, {0x10, set_rgblum, true},
|
{0x0d, set_vendorfilter, 1, false}, {0x0e, set_blescan, 1, true},
|
||||||
{0x11, set_monitor, true}, {0x12, set_beacon, false},
|
{0x0f, set_wifiant, 1, true}, {0x10, set_rgblum, 1, true},
|
||||||
{0x80, get_config, false}, {0x81, get_status, false},
|
{0x11, set_monitor, 1, true}, {0x12, set_beacon, 7, false},
|
||||||
{0x84, get_gps, false}};
|
{0x80, get_config, 0, false}, {0x81, get_status, 0, false},
|
||||||
|
{0x84, get_gps, 0, false}};
|
||||||
|
|
||||||
// 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) {
|
||||||
|
|
||||||
if (cmdlength == 0)
|
if (cmdlength == 0)
|
||||||
return;
|
return;
|
||||||
|
else
|
||||||
|
cmdlength--; // minus 1 byte for opcode
|
||||||
|
|
||||||
int i =
|
int i =
|
||||||
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
sizeof(table) / sizeof(table[0]); // number of commands in command table
|
||||||
bool store_flag = false;
|
|
||||||
|
|
||||||
while (i--) {
|
while (i--) {
|
||||||
if (cmd[0] == table[i].opcode) { // lookup command in opcode table
|
if ((cmd[0] == table[i].opcode) &&
|
||||||
if (cmdlength) {
|
(table[i].params == cmdlength)) { // lookup command in opcode table
|
||||||
memmove(cmd, cmd + 1,
|
memmove(cmd, cmd + 1,
|
||||||
cmdlength - 1); // cutout opcode from parameter array
|
cmdlength); // strip opcode
|
||||||
table[i].func(cmd); // execute assigned function with given parameters
|
table[i].func(cmd); // execute assigned function with given parameters
|
||||||
} else
|
if (table[i].store) // ceck if function needs to store configuration
|
||||||
table[i].func(0); // execute assigned function with dummy as parameter
|
saveConfig();
|
||||||
if (table[i].store) // ceck if function needs to store configuration after
|
break; // exit while loop, command was found
|
||||||
// execution
|
} // lookup command
|
||||||
store_flag =
|
} // while
|
||||||
true; // set save flag if function needs to store configuration
|
|
||||||
break; // exit check loop, since command was found
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (store_flag)
|
|
||||||
saveConfig(); // if save flag is set: store new configuration in NVS to make
|
|
||||||
// it persistent
|
|
||||||
} // rcommand()
|
} // rcommand()
|
@ -10,6 +10,7 @@
|
|||||||
typedef struct {
|
typedef struct {
|
||||||
const uint8_t opcode;
|
const uint8_t opcode;
|
||||||
void (*func)(uint8_t []);
|
void (*func)(uint8_t []);
|
||||||
|
uint8_t params;
|
||||||
const bool store;
|
const bool store;
|
||||||
} cmd_t;
|
} cmd_t;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user