mirror of https://github.com/arendst/Tasmota.git
Merge pull request #6826 from andrethomas/tasmota_slave
TasmotaSlave: Rework commands
This commit is contained in:
commit
d50cc3dfdf
|
@ -461,7 +461,7 @@ void TasmotaSlave_Init(void)
|
||||||
TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_START), buffer, sizeof(buffer));
|
TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_START), buffer, sizeof(buffer));
|
||||||
uint8_t len = TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_END), buffer, sizeof(buffer));
|
uint8_t len = TasmotaSlave_Serial->readBytesUntil(char(PARAM_DATA_END), buffer, sizeof(buffer));
|
||||||
memcpy(&TSlaveSettings, &buffer, sizeof(TSlaveSettings));
|
memcpy(&TSlaveSettings, &buffer, sizeof(TSlaveSettings));
|
||||||
if (20191101 <= TSlaveSettings.features_version) {
|
if (20191101 == TSlaveSettings.features_version) {
|
||||||
TSlave.type = true;
|
TSlave.type = true;
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Version %u"), TSlaveSettings.features_version);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("Tasmota Slave Version %u"), TSlaveSettings.features_version);
|
||||||
}
|
}
|
||||||
|
@ -493,46 +493,34 @@ void TasmotaSlave_sendCmnd(uint8_t cmnd, uint8_t param)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char kTasmotaSlaveCommands[] PROGMEM = "|" // No prefix
|
#define D_PRFX_SLAVE "Slave"
|
||||||
"Slave" ;
|
#define D_CMND_SLAVE_RESET "Reset"
|
||||||
|
#define D_CMND_SLAVE_SEND "Send"
|
||||||
|
|
||||||
|
const char kTasmotaSlaveCommands[] PROGMEM = D_PRFX_SLAVE "|"
|
||||||
|
D_CMND_SLAVE_RESET "|" D_CMND_SLAVE_SEND;
|
||||||
|
|
||||||
void (* const TasmotaSlaveCommand[])(void) PROGMEM = {
|
void (* const TasmotaSlaveCommand[])(void) PROGMEM = {
|
||||||
&CmndTasmotaSlave };
|
&CmndTasmotaSlaveReset, &CmndTasmotaSlaveSend };
|
||||||
|
|
||||||
void CmndTasmotaSlave(void)
|
void CmndTasmotaSlaveReset(void)
|
||||||
{
|
{
|
||||||
if (XdrvMailbox.data_len > 0) {
|
|
||||||
uint8_t paramcount = 1;
|
|
||||||
for (uint8_t idx = 0; idx < strlen(XdrvMailbox.data); idx++) {
|
|
||||||
if ((' ' == XdrvMailbox.data[idx]) || (',' == XdrvMailbox.data[idx])) {
|
|
||||||
XdrvMailbox.data[idx] = ','; // Make it a comma irrespective whether its a space or a comma
|
|
||||||
paramcount++;
|
|
||||||
}
|
|
||||||
UpperCase(XdrvMailbox.data,XdrvMailbox.data);
|
|
||||||
|
|
||||||
char sub_string[XdrvMailbox.data_len];
|
|
||||||
|
|
||||||
if (1 == paramcount) { // Single parameter commands
|
|
||||||
if (!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 1), "RESET")) {
|
|
||||||
TasmotaSlave_Reset();
|
TasmotaSlave_Reset();
|
||||||
TSlave.type = false; // Force redetection
|
TSlave.type = false; // Force redetection
|
||||||
TSlave.waitstate = 7; // give it at least 3 seconds to restart from bootloader
|
TSlave.waitstate = 7; // give it at least 3 seconds to restart from bootloader
|
||||||
}
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
if (2 == paramcount) { // Double parameter commands
|
|
||||||
if ((!strcmp(subStr(sub_string, XdrvMailbox.data, ",", 1), "SEND")) && (TSlaveSettings.features.func_slave_send)) {
|
void CmndTasmotaSlaveSend(void)
|
||||||
char tmp[XdrvMailbox.data_len];
|
{
|
||||||
sprintf(tmp, "%s", subStr(sub_string, XdrvMailbox.data, ",", 2));
|
if (0 < XdrvMailbox.data_len) {
|
||||||
TasmotaSlave_sendCmnd(CMND_SLAVE_SEND, strlen(tmp));
|
TasmotaSlave_sendCmnd(CMND_SLAVE_SEND, XdrvMailbox.data_len);
|
||||||
TasmotaSlave_Serial->write(char(PARAM_DATA_START));
|
TasmotaSlave_Serial->write(char(PARAM_DATA_START));
|
||||||
for (uint8_t ci = 0; ci < strlen(tmp); ci++) {
|
for (uint8_t idx = 0; idx < XdrvMailbox.data_len; idx++) {
|
||||||
TasmotaSlave_Serial->write(tmp[ci]);
|
TasmotaSlave_Serial->write(XdrvMailbox.data[idx]);
|
||||||
}
|
}
|
||||||
TasmotaSlave_Serial->write(char(PARAM_DATA_END));
|
TasmotaSlave_Serial->write(char(PARAM_DATA_END));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResponseCmndDone();
|
ResponseCmndDone();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue