Merge pull request #10181 from gemu2015/sub_cmd_fix-

fix script_sub_command
This commit is contained in:
Theo Arends 2020-12-19 08:52:30 +01:00 committed by GitHub
commit 2f17da8199
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 14 deletions

View File

@ -5846,24 +5846,26 @@ bool Script_SubCmd(void) {
if (!bitRead(Settings.rule_enabled, 0)) return false; if (!bitRead(Settings.rule_enabled, 0)) return false;
if (tasm_cmd_activ) return false; if (tasm_cmd_activ) return false;
//AddLog_P(LOG_LEVEL_INFO,PSTR(">> %s, %s, %d, %d "),XdrvMailbox.topic, XdrvMailbox.data, XdrvMailbox.payload, XdrvMailbox.index);
char command[CMDSZ]; char command[CMDSZ];
strlcpy(command, XdrvMailbox.topic, CMDSZ); strlcpy(command, XdrvMailbox.topic, CMDSZ);
uint32_t pl = XdrvMailbox.payload; if (XdrvMailbox.index > 1) {
char pld[64]; char ind[2];
strlcpy(pld, XdrvMailbox.data, sizeof(pld)); ind[0] = XdrvMailbox.index | 0x30;
ind[1] = 0;
strcat(command, ind);
}
int32_t pl = XdrvMailbox.payload;
char cmdbuff[128]; char cmdbuff[128];
char *cp = cmdbuff; char *cp = cmdbuff;
*cp++ = '#'; *cp++ = '#';
strcpy(cp, XdrvMailbox.topic); strcpy(cp, command);
uint8_t tlen = strlen(XdrvMailbox.topic); uint8_t tlen = strlen(command);
cp += tlen; cp += tlen;
if (XdrvMailbox.index > 0) { if (XdrvMailbox.data_len>0) {
*cp++ = XdrvMailbox.index | 0x30;
tlen++;
}
if ((XdrvMailbox.payload>0) || (XdrvMailbox.data_len>0)) {
*cp++ = '('; *cp++ = '(';
strncpy(cp, XdrvMailbox.data,XdrvMailbox.data_len); strncpy(cp, XdrvMailbox.data,XdrvMailbox.data_len);
cp += XdrvMailbox.data_len; cp += XdrvMailbox.data_len;
@ -5873,12 +5875,16 @@ bool Script_SubCmd(void) {
//toLog(cmdbuff); //toLog(cmdbuff);
uint32_t res = Run_Scripter(cmdbuff, tlen + 1, 0); uint32_t res = Run_Scripter(cmdbuff, tlen + 1, 0);
//AddLog_P(LOG_LEVEL_INFO,">>%d",res); //AddLog_P(LOG_LEVEL_INFO,">>%d",res);
if (res) return false; if (res) {
return false;
}
else { else {
if (pl>=0) { cp=XdrvMailbox.data;
Response_P(S_JSON_COMMAND_NVALUE, command, pl); while (*cp==' ') cp++;
if (isdigit(*cp) || *cp=='-') {
Response_P(S_JSON_COMMAND_NVALUE, command, XdrvMailbox.payload);
} else { } else {
Response_P(S_JSON_COMMAND_SVALUE, command, pld); Response_P(S_JSON_COMMAND_SVALUE, command, XdrvMailbox.data);
} }
} }
return true; return true;