Refactor core command structure

Refactor core command structure
This commit is contained in:
Theo Arends 2019-07-27 11:13:41 +02:00
parent ff909baa69
commit 37b1c25881
8 changed files with 1128 additions and 1027 deletions

View File

@ -392,14 +392,11 @@ struct TIME_T {
} RtcTime; } RtcTime;
struct XDRVMAILBOX { struct XDRVMAILBOX {
uint16_t valid;
uint16_t index;
uint16_t data_len;
uint16_t payload16;
int16_t payload;
bool grpflg; bool grpflg;
bool usridx; bool usridx;
int32_t payload32; uint32_t index;
uint32_t data_len;
int32_t payload;
char *topic; char *topic;
char *data; char *data;
char *command; char *command;

View File

@ -302,12 +302,12 @@ char* dtostrfd(double number, unsigned char prec, char *s)
} }
} }
char* Unescape(char* buffer, uint16_t* size) char* Unescape(char* buffer, uint32_t* size)
{ {
uint8_t* read = (uint8_t*)buffer; uint8_t* read = (uint8_t*)buffer;
uint8_t* write = (uint8_t*)buffer; uint8_t* write = (uint8_t*)buffer;
int16_t start_size = *size; int32_t start_size = *size;
int16_t end_size = *size; int32_t end_size = *size;
uint8_t che = 0; uint8_t che = 0;
// AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size); // AddLogBuffer(LOG_LEVEL_DEBUG, (uint8_t*)buffer, *size);
@ -811,7 +811,7 @@ uint32_t GetHash(const char *buffer, size_t size)
return hash; return hash;
} }
void ShowSource(int source) void ShowSource(uint32_t source)
{ {
if ((source > 0) && (source < SRC_MAX)) { if ((source > 0) && (source < SRC_MAX)) {
char stemp1[20]; char stemp1[20];

File diff suppressed because it is too large Load Diff

View File

@ -640,10 +640,9 @@ bool MqttCommand(void)
char stemp1[TOPSZ]; char stemp1[TOPSZ];
char scommand[CMDSZ]; char scommand[CMDSZ];
uint16_t index = XdrvMailbox.index; uint32_t index = XdrvMailbox.index;
uint16_t data_len = XdrvMailbox.data_len; uint32_t data_len = XdrvMailbox.data_len;
uint16_t payload16 = XdrvMailbox.payload16; int32_t payload = XdrvMailbox.payload;
int16_t payload = XdrvMailbox.payload;
bool grpflg = XdrvMailbox.grpflg; bool grpflg = XdrvMailbox.grpflg;
char *type = XdrvMailbox.topic; char *type = XdrvMailbox.topic;
char *dataBuf = XdrvMailbox.data; char *dataBuf = XdrvMailbox.data;
@ -668,8 +667,8 @@ bool MqttCommand(void)
#endif #endif
} }
else if (CMND_MQTTPORT == command_code) { else if (CMND_MQTTPORT == command_code) {
if (payload16 > 0) { if ((payload > 0) && (payload < 65536)) {
Settings.mqtt_port = (1 == payload16) ? MQTT_PORT : payload16; Settings.mqtt_port = (1 == payload) ? MQTT_PORT : payload;
restart_flag = 2; restart_flag = 2;
} }
Response_P(S_JSON_COMMAND_NVALUE, command, Settings.mqtt_port); Response_P(S_JSON_COMMAND_NVALUE, command, Settings.mqtt_port);

View File

@ -148,11 +148,8 @@ bool SerialBridgeCommand(void)
} }
} }
else if (CMND_SBAUDRATE == command_code) { else if (CMND_SBAUDRATE == command_code) {
char *p; if (XdrvMailbox.payload > 1200) {
int baud = strtol(XdrvMailbox.data, &p, 10); Settings.sbaudrate /= 1200; // Make it a valid baudrate
if (baud >= 1200) {
baud /= 1200; // Make it a valid baudrate
Settings.sbaudrate = (1 == XdrvMailbox.payload) ? SOFT_BAUDRATE / 1200 : baud;
SerialBridgeSerial->begin(Settings.sbaudrate * 1200); // Reinitialize serial port with new baud rate SerialBridgeSerial->begin(Settings.sbaudrate * 1200); // Reinitialize serial port with new baud rate
} }
Response_P(S_JSON_COMMAND_NVALUE, command, Settings.sbaudrate * 1200); Response_P(S_JSON_COMMAND_NVALUE, command, Settings.sbaudrate * 1200);

View File

@ -113,8 +113,6 @@ Decoding 14 results
0x4021ffb4: snprintf_P(char*, unsigned int, char const*, ...) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.cpp line 146 0x4021ffb4: snprintf_P(char*, unsigned int, char const*, ...) at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/pgmspace.cpp line 146
0x40201118: atol at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45 0x40201118: atol at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
0x40201128: atoi at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45 0x40201128: atoi at C:\Data2\Arduino\arduino-1.8.1-esp-2.3.0\portable\packages\esp8266\hardware\esp8266\2.3.0\cores\esp8266/core_esp8266_noniso.c line 45
0x4020fafb: CommandHandler(char*, unsigned char*, unsigned int) at R:\Arduino\Work-ESP8266\Theo\sonoff\sonoff-4\sonoff/sonoff.ino line 679 (discriminator 1)
0x4022321b: pp_attach at ?? line ?
00:00:08 MQTT: tele/sonoff/INFO3 = {"Started":"Fatal exception:28 flag:2 (EXCEPTION) epc1:0x4000bf64 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000007 depc:0x00000000"} 00:00:08 MQTT: tele/sonoff/INFO3 = {"Started":"Fatal exception:28 flag:2 (EXCEPTION) epc1:0x4000bf64 epc2:0x00000000 epc3:0x00000000 excvaddr:0x00000007 depc:0x00000000"}
*/ */

View File

@ -162,11 +162,11 @@ bool CounterCommand(void)
if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) { if ((XdrvMailbox.index > 0) && (XdrvMailbox.index <= MAX_COUNTERS)) {
if ((XdrvMailbox.data_len > 0) && (pin[GPIO_CNTR1 + XdrvMailbox.index -1] < 99)) { if ((XdrvMailbox.data_len > 0) && (pin[GPIO_CNTR1 + XdrvMailbox.index -1] < 99)) {
if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) { if ((XdrvMailbox.data[0] == '-') || (XdrvMailbox.data[0] == '+')) {
RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload32; RtcSettings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload;
Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload32; Settings.pulse_counter[XdrvMailbox.index -1] += XdrvMailbox.payload;
} else { } else {
RtcSettings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload32; RtcSettings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload;
Settings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload32; Settings.pulse_counter[XdrvMailbox.index -1] = XdrvMailbox.payload;
} }
} }
Response_P(S_JSON_COMMAND_INDEX_LVALUE, command, XdrvMailbox.index, RtcSettings.pulse_counter[XdrvMailbox.index -1]); Response_P(S_JSON_COMMAND_INDEX_LVALUE, command, XdrvMailbox.index, RtcSettings.pulse_counter[XdrvMailbox.index -1]);
@ -183,8 +183,8 @@ bool CounterCommand(void)
} }
} }
else if (CMND_COUNTERDEBOUNCE == command_code) { else if (CMND_COUNTERDEBOUNCE == command_code) {
if ((XdrvMailbox.data_len > 0) && (XdrvMailbox.payload16 < 32001)) { if ((XdrvMailbox.payload >= 0) && (XdrvMailbox.payload < 32001)) {
Settings.pulse_counter_debounce = XdrvMailbox.payload16; Settings.pulse_counter_debounce = XdrvMailbox.payload;
} }
Response_P(S_JSON_COMMAND_NVALUE, command, Settings.pulse_counter_debounce); Response_P(S_JSON_COMMAND_NVALUE, command, Settings.pulse_counter_debounce);
} }

View File

@ -393,7 +393,7 @@ bool Scd30CommandSensor()
uint16_t value = 0; uint16_t value = 0;
if (XdrvMailbox.data_len > 0) if (XdrvMailbox.data_len > 0)
{ {
value = XdrvMailbox.payload16; value = XdrvMailbox.payload;
Scd30SetCommand(command_code, value); Scd30SetCommand(command_code, value);
} }
else else