mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-26 20:26:32 +00:00
fix tcp server (#21660)
This commit is contained in:
parent
d18925897a
commit
aa380ea190
@ -2600,12 +2600,19 @@ char *isargs(char *lp, uint32_t isind) {
|
|||||||
if (glob_script_mem.si_num[isind] > MAX_SARRAY_NUM) {
|
if (glob_script_mem.si_num[isind] > MAX_SARRAY_NUM) {
|
||||||
glob_script_mem.si_num[isind] = MAX_SARRAY_NUM;
|
glob_script_mem.si_num[isind] = MAX_SARRAY_NUM;
|
||||||
}
|
}
|
||||||
|
//glob_script_mem.last_index_string[isind] = (char*)calloc(glob_script_mem.max_ssize * glob_script_mem.si_num[isind], 1);
|
||||||
|
uint32_t sasize = glob_script_mem.max_ssize * glob_script_mem.si_num[isind];
|
||||||
|
glob_script_mem.last_index_string[isind] = (char*)special_malloc(sasize);
|
||||||
|
if (glob_script_mem.last_index_string[isind]) {
|
||||||
|
memset(glob_script_mem.last_index_string[isind], 0, sasize);
|
||||||
|
for (uint32_t cnt = 0; cnt < glob_script_mem.siro_num[isind]; cnt++) {
|
||||||
|
char str[SCRIPT_MAX_SBSIZE];
|
||||||
|
GetTextIndexed(str, sizeof(str), cnt, sstart);
|
||||||
|
strlcpy(glob_script_mem.last_index_string[isind] + (cnt * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// memory error
|
||||||
|
|
||||||
glob_script_mem.last_index_string[isind] = (char*)calloc(glob_script_mem.max_ssize * glob_script_mem.si_num[isind], 1);
|
|
||||||
for (uint32_t cnt = 0; cnt < glob_script_mem.siro_num[isind]; cnt++) {
|
|
||||||
char str[SCRIPT_MAX_SBSIZE];
|
|
||||||
GetTextIndexed(str, sizeof(str), cnt, sstart);
|
|
||||||
strlcpy(glob_script_mem.last_index_string[isind] + (cnt * glob_script_mem.max_ssize), str, glob_script_mem.max_ssize);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
glob_script_mem.last_index_string[isind] = sstart;
|
glob_script_mem.last_index_string[isind] = sstart;
|
||||||
@ -3439,7 +3446,7 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||||||
FS *cfp = script_file_path(str);
|
FS *cfp = script_file_path(str);
|
||||||
while (*lp == ' ') lp++;
|
while (*lp == ' ') lp++;
|
||||||
uint8_t mode = 0;
|
uint8_t mode = 0;
|
||||||
if ((*lp == 'r') || (*lp == 'w') || (*lp == 'a')) {
|
if ((*lp == 'r') || (*lp == 'w') || (*lp == 'a') || (*lp == 'u')) {
|
||||||
switch (*lp) {
|
switch (*lp) {
|
||||||
case 'r':
|
case 'r':
|
||||||
mode = 0;
|
mode = 0;
|
||||||
@ -3450,6 +3457,12 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||||||
case 'a':
|
case 'a':
|
||||||
mode = 2;
|
mode = 2;
|
||||||
break;
|
break;
|
||||||
|
case 'u':
|
||||||
|
mode = 3;
|
||||||
|
break;
|
||||||
|
case 'U':
|
||||||
|
mode = 4;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
lp++;
|
lp++;
|
||||||
} else {
|
} else {
|
||||||
@ -3477,10 +3490,20 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||||||
#ifdef DEBUG_FS
|
#ifdef DEBUG_FS
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for write %d"), cnt);
|
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for write %d"), cnt);
|
||||||
#endif
|
#endif
|
||||||
} else {
|
} else if (mode == 2) {
|
||||||
glob_script_mem.files[cnt] = cfp->open(str,FS_FILE_APPEND);
|
glob_script_mem.files[cnt] = cfp->open(str,FS_FILE_APPEND);
|
||||||
#ifdef DEBUG_FS
|
#ifdef DEBUG_FS
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for append %d"), cnt);
|
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for append %d"), cnt);
|
||||||
|
#endif
|
||||||
|
} else if (mode == 3) {
|
||||||
|
glob_script_mem.files[cnt] = cfp->open(str, "w+");
|
||||||
|
#ifdef DEBUG_FS
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for write update %d"), cnt);
|
||||||
|
#endif
|
||||||
|
} else {
|
||||||
|
glob_script_mem.files[cnt] = cfp->open(str, "r+");
|
||||||
|
#ifdef DEBUG_FS
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("SCR: open file for read update %d"), cnt);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4744,7 +4767,8 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||||||
len = 0;
|
len = 0;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
#ifdef USE_MORITZ
|
#ifdef USE_BINPLUGINS
|
||||||
|
char *Plugin_Query(uint8_t, uint8_t);
|
||||||
if (!strncmp_XP(lp, XPSTR("mo("), 3)) {
|
if (!strncmp_XP(lp, XPSTR("mo("), 3)) {
|
||||||
TS_FLOAT fvar1;
|
TS_FLOAT fvar1;
|
||||||
lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar1, gv);
|
lp = GetNumericArgument(lp + 3, OPER_EQU, &fvar1, gv);
|
||||||
@ -4752,14 +4776,21 @@ extern void W8960_SetGain(uint8_t sel, uint16_t value);
|
|||||||
TS_FLOAT fvar2;
|
TS_FLOAT fvar2;
|
||||||
lp = GetNumericArgument(lp, OPER_EQU, &fvar2, gv);
|
lp = GetNumericArgument(lp, OPER_EQU, &fvar2, gv);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
char rbuff[64];
|
char *rbuff = Plugin_Query(fvar1, fvar2);
|
||||||
fvar = mo_getvars(fvar1, fvar2, rbuff);
|
if (rbuff) {
|
||||||
|
if (sp) strlcpy(sp, rbuff, glob_script_mem.max_ssize);
|
||||||
|
free (rbuff);
|
||||||
|
} else {
|
||||||
|
if (sp) {
|
||||||
|
strcpy_P(sp, PSTR("not found"));
|
||||||
|
}
|
||||||
|
}
|
||||||
lp++;
|
lp++;
|
||||||
if (sp) strlcpy(sp, rbuff, glob_script_mem.max_ssize);
|
|
||||||
len = 0;
|
len = 0;
|
||||||
goto strexit;
|
goto strexit;
|
||||||
}
|
}
|
||||||
#endif //USE_MORITZ
|
#endif //USE_BINPLUGINS
|
||||||
|
|
||||||
#ifdef ESP32_FAST_MUX
|
#ifdef ESP32_FAST_MUX
|
||||||
if (!strncmp_XP(lp, XPSTR("mux("), 4)) {
|
if (!strncmp_XP(lp, XPSTR("mux("), 4)) {
|
||||||
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &fvar, gv);
|
||||||
@ -6219,16 +6250,24 @@ void tmod_directModeOutput(uint32_t pin);
|
|||||||
if (!strncmp_XP(lp, XPSTR("wso("), 4)) {
|
if (!strncmp_XP(lp, XPSTR("wso("), 4)) {
|
||||||
TS_FLOAT port;
|
TS_FLOAT port;
|
||||||
lp = GetNumericArgument(lp + 4, OPER_EQU, &port, gv);
|
lp = GetNumericArgument(lp + 4, OPER_EQU, &port, gv);
|
||||||
glob_script_mem.tcp_server = new WiFiServer(port);
|
if (TasmotaGlobal.global_state.wifi_down) {
|
||||||
fvar = 0;
|
fvar = - 2;
|
||||||
if (!glob_script_mem.tcp_server) {
|
} else {
|
||||||
fvar = -1;
|
if (glob_script_mem.tcp_server) {
|
||||||
} else {
|
glob_script_mem.tcp_client.stop();
|
||||||
AddLog(LOG_LEVEL_INFO, PSTR("tcp server started"));
|
glob_script_mem.tcp_server->stop();
|
||||||
|
delete glob_script_mem.tcp_server;
|
||||||
|
}
|
||||||
|
glob_script_mem.tcp_server = new WiFiServer(port);
|
||||||
|
fvar = 0;
|
||||||
|
if (!glob_script_mem.tcp_server) {
|
||||||
|
fvar = -1;
|
||||||
|
} else {
|
||||||
|
glob_script_mem.tcp_server->begin();
|
||||||
|
glob_script_mem.tcp_server->setNoDelay(true);
|
||||||
|
AddLog(LOG_LEVEL_INFO, PSTR("tcp server started"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
glob_script_mem.tcp_server->begin();
|
|
||||||
glob_script_mem.tcp_server->setNoDelay(true);
|
|
||||||
|
|
||||||
goto nfuncexit;
|
goto nfuncexit;
|
||||||
}
|
}
|
||||||
if (!strncmp_XP(lp, XPSTR("wsc("), 4)) {
|
if (!strncmp_XP(lp, XPSTR("wsc("), 4)) {
|
||||||
@ -12055,7 +12094,6 @@ exgc:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
snprintf_P(options, SCRIPT_GC_OPTIONS_SIZE, SCRIPT_MSG_GOPT4);
|
snprintf_P(options, SCRIPT_GC_OPTIONS_SIZE, SCRIPT_MSG_GOPT4);
|
||||||
if (options) free(options);
|
|
||||||
}
|
}
|
||||||
if (tonly) {
|
if (tonly) {
|
||||||
WSContentSend_P("]);");
|
WSContentSend_P("]);");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user