mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-23 10:46:31 +00:00
Merge pull request #16106 from gemu2015/scripter_update
current cmd buffer adjustable
This commit is contained in:
commit
6f014651b6
@ -60,6 +60,11 @@ keywords if then else endif, or, and are better readable for beginners (others m
|
|||||||
#define SCRIPT_MAXSSIZE 48
|
#define SCRIPT_MAXSSIZE 48
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SCRIPT_CMDMEM
|
||||||
|
#define SCRIPT_CMDMEM 512
|
||||||
|
#endif
|
||||||
|
#define MAX_SCRIPT_CMDBUFFER 4096
|
||||||
|
|
||||||
|
|
||||||
#define SCRIPT_EOL '\n'
|
#define SCRIPT_EOL '\n'
|
||||||
#define SCRIPT_FLOAT_PRECISION 2
|
#define SCRIPT_FLOAT_PRECISION 2
|
||||||
@ -235,7 +240,7 @@ extern Renderer *renderer;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
enum {OPER_EQU=1,OPER_PLS,OPER_MIN,OPER_MUL,OPER_DIV,OPER_PLSEQU,OPER_MINEQU,OPER_MULEQU,OPER_DIVEQU,OPER_EQUEQU,OPER_NOTEQU,OPER_GRTEQU,OPER_LOWEQU,OPER_GRT,OPER_LOW,OPER_PERC,OPER_XOR,OPER_AND,OPER_OR,OPER_ANDEQU,OPER_OREQU,OPER_XOREQU,OPER_PERCEQU,OPER_SHLEQU,OPER_SHREQU,OPER_SHL,OPER_SHR};
|
enum {OPER_EQU=1,OPER_PLS,OPER_MIN,OPER_MUL,OPER_DIV,OPER_PLSEQU,OPER_MINEQU,OPER_MULEQU,OPER_DIVEQU,OPER_EQUEQU,OPER_NOTEQU,OPER_GRTEQU,OPER_LOWEQU,OPER_GRT,OPER_LOW,OPER_PERC,OPER_XOR,OPER_AND,OPER_OR,OPER_ANDEQU,OPER_OREQU,OPER_XOREQU,OPER_PERCEQU,OPER_SHLEQU,OPER_SHREQU,OPER_SHL,OPER_SHR};
|
||||||
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED,SML_JSON_ENABLE,SCRIPT_EPOFFS};
|
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED,SML_JSON_ENABLE,SCRIPT_EPOFFS,SCRIPT_CBSIZE};
|
||||||
|
|
||||||
|
|
||||||
#ifdef USE_UFILESYS
|
#ifdef USE_UFILESYS
|
||||||
@ -425,6 +430,7 @@ struct SCRIPT_MEM {
|
|||||||
uint8_t *script_pram;
|
uint8_t *script_pram;
|
||||||
uint16_t script_pram_size;
|
uint16_t script_pram_size;
|
||||||
uint8_t numvars;
|
uint8_t numvars;
|
||||||
|
uint8_t arres;
|
||||||
void *script_mem;
|
void *script_mem;
|
||||||
uint16_t script_mem_size;
|
uint16_t script_mem_size;
|
||||||
uint8_t script_dprec;
|
uint8_t script_dprec;
|
||||||
@ -438,6 +444,7 @@ struct SCRIPT_MEM {
|
|||||||
uint8_t siro_num[3];
|
uint8_t siro_num[3];
|
||||||
uint8_t sind_num;
|
uint8_t sind_num;
|
||||||
char *last_index_string[3];
|
char *last_index_string[3];
|
||||||
|
uint16_t cmdbuffer_size = SCRIPT_CMDMEM / 2;
|
||||||
|
|
||||||
#ifdef USE_SCRIPT_FATFS
|
#ifdef USE_SCRIPT_FATFS
|
||||||
File files[SFS_MAX];
|
File files[SFS_MAX];
|
||||||
@ -1325,7 +1332,6 @@ void Set_MFVal(uint8_t index, uint16_t bind, float val) {
|
|||||||
if (count == index) {
|
if (count == index) {
|
||||||
uint16_t maxind = mflp->numvals & AND_FILT_MASK;
|
uint16_t maxind = mflp->numvals & AND_FILT_MASK;
|
||||||
if (!bind) {
|
if (!bind) {
|
||||||
|
|
||||||
if (val < 0) {
|
if (val < 0) {
|
||||||
// shift whole array by value
|
// shift whole array by value
|
||||||
} else {
|
} else {
|
||||||
@ -2110,6 +2116,7 @@ char *isvar(char *lp, uint8_t *vtype, struct T_INDEX *tind, float *fp, char *sp,
|
|||||||
olen = strlen(dvnam);
|
olen = strlen(dvnam);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
glob_script_mem.arres = 0;
|
||||||
for (count = 0; count < glob_script_mem.numvars; count++) {
|
for (count = 0; count < glob_script_mem.numvars; count++) {
|
||||||
char *cp = glob_script_mem.glob_vnp + glob_script_mem.vnp_offset[count];
|
char *cp = glob_script_mem.glob_vnp + glob_script_mem.vnp_offset[count];
|
||||||
uint8_t slen = strlen(cp);
|
uint8_t slen = strlen(cp);
|
||||||
@ -2129,6 +2136,7 @@ char *isvar(char *lp, uint8_t *vtype, struct T_INDEX *tind, float *fp, char *sp,
|
|||||||
len = 1;
|
len = 1;
|
||||||
} else {
|
} else {
|
||||||
fvar = Get_MFilter(index);
|
fvar = Get_MFilter(index);
|
||||||
|
glob_script_mem.arres = 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (ja) continue;
|
if (ja) continue;
|
||||||
@ -2514,7 +2522,11 @@ chknext:
|
|||||||
goto strexit;
|
goto strexit;
|
||||||
}
|
}
|
||||||
#endif // USE_FEXTRACT
|
#endif // USE_FEXTRACT
|
||||||
|
if (!strncmp(lp, "cbs", 3)) {
|
||||||
|
fvar = glob_script_mem.cmdbuffer_size;
|
||||||
|
tind->index = SCRIPT_CBSIZE;
|
||||||
|
goto exit_settable;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
if (!strncmp(vname, "day", 3)) {
|
if (!strncmp(vname, "day", 3)) {
|
||||||
@ -6282,12 +6294,11 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
}
|
}
|
||||||
char *slp = lp;
|
char *slp = lp;
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
#define SCRIPT_CMDMEM 512
|
char *cmdmem = (char*)malloc(glob_script_mem.cmdbuffer_size * 2);
|
||||||
char *cmdmem = (char*)malloc(SCRIPT_CMDMEM);
|
|
||||||
if (cmdmem) {
|
if (cmdmem) {
|
||||||
char *cmd = cmdmem;
|
char *cmd = cmdmem;
|
||||||
uint16_t count;
|
uint16_t count;
|
||||||
for (count = 0; count<SCRIPT_CMDMEM/2-2; count++) {
|
for (count = 0; count < glob_script_mem.cmdbuffer_size-2; count++) {
|
||||||
//if (*lp=='\r' || *lp=='\n' || *lp=='}') {
|
//if (*lp=='\r' || *lp=='\n' || *lp=='}') {
|
||||||
if (!*lp || *lp=='\r' || *lp=='\n') {
|
if (!*lp || *lp=='\r' || *lp=='\n') {
|
||||||
cmd[count] = 0;
|
cmd[count] = 0;
|
||||||
@ -6297,8 +6308,8 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
}
|
}
|
||||||
//AddLog(LOG_LEVEL_INFO, tmp);
|
//AddLog(LOG_LEVEL_INFO, tmp);
|
||||||
// replace vars in cmd
|
// replace vars in cmd
|
||||||
char *tmp = cmdmem + SCRIPT_CMDMEM / 2;
|
char *tmp = cmdmem + glob_script_mem.cmdbuffer_size;
|
||||||
Replace_Cmd_Vars(cmd, 0, tmp, SCRIPT_CMDMEM / 2);
|
Replace_Cmd_Vars(cmd, 0, tmp, glob_script_mem.cmdbuffer_size);
|
||||||
//toSLog(tmp);
|
//toSLog(tmp);
|
||||||
|
|
||||||
if (!strncmp(tmp, "print", 5) || pflg) {
|
if (!strncmp(tmp, "print", 5) || pflg) {
|
||||||
@ -6371,6 +6382,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
// found variable as result
|
// found variable as result
|
||||||
globvindex = ind.index; // save destination var index here
|
globvindex = ind.index; // save destination var index here
|
||||||
if (gv) globaindex = gv->numind;
|
if (gv) globaindex = gv->numind;
|
||||||
|
else globaindex = -1;
|
||||||
uint8_t index = glob_script_mem.type[ind.index].index;
|
uint8_t index = glob_script_mem.type[ind.index].index;
|
||||||
if ((vtype&STYPE)==0) {
|
if ((vtype&STYPE)==0) {
|
||||||
// numeric result
|
// numeric result
|
||||||
@ -6381,7 +6393,6 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
} else {
|
} else {
|
||||||
sysv_type = 0;
|
sysv_type = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
dfvar = &glob_script_mem.fvars[index];
|
dfvar = &glob_script_mem.fvars[index];
|
||||||
sysv_type = 0;
|
sysv_type = 0;
|
||||||
@ -6395,6 +6406,10 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
lp = eval_sub(lp, &fvar, 0);
|
lp = eval_sub(lp, &fvar, 0);
|
||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
|
SCRIPT_SKIP_SPACES
|
||||||
|
if ( (glob_script_mem.arres > 0) && (lastop == OPER_EQU) && (*lp == '{') ) {
|
||||||
|
glob_script_mem.arres = 2;
|
||||||
|
} else {
|
||||||
char *slp = lp;
|
char *slp = lp;
|
||||||
glob_script_mem.glob_error = 0;
|
glob_script_mem.glob_error = 0;
|
||||||
//Serial.printf("Stack 1: %d\n",GetStack());
|
//Serial.printf("Stack 1: %d\n",GetStack());
|
||||||
@ -6405,6 +6420,7 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
lp = isvar(slp, &vtype, &ind, 0, cmpstr, gv);
|
lp = isvar(slp, &vtype, &ind, 0, cmpstr, gv);
|
||||||
fvar = CharToFloat(cmpstr);
|
fvar = CharToFloat(cmpstr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#ifdef SCRIPT_LM_SUB
|
#ifdef SCRIPT_LM_SUB
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -6460,10 +6476,23 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
if (glob_script_mem.type[globvindex].bits.is_filter) {
|
if (glob_script_mem.type[globvindex].bits.is_filter) {
|
||||||
if (globaindex >= 0) {
|
if (globaindex >= 0) {
|
||||||
Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar);
|
Set_MFVal(glob_script_mem.type[globvindex].index, globaindex, *dfvar);
|
||||||
|
} else {
|
||||||
|
if (glob_script_mem.arres == 2) {
|
||||||
|
// fetch var preset
|
||||||
|
lp++;
|
||||||
|
while (*lp && *lp != SCRIPT_EOL) {
|
||||||
|
if (*lp == '}') {
|
||||||
|
lp++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
lp = GetNumericArgument(lp, OPER_EQU, &fvar, gv);
|
||||||
|
Set_MFilter(glob_script_mem.type[globvindex].index, fvar);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar);
|
Set_MFilter(glob_script_mem.type[globvindex].index, *dfvar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sysv_type) {
|
if (sysv_type) {
|
||||||
switch (sysv_type) {
|
switch (sysv_type) {
|
||||||
@ -6481,6 +6510,12 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
|
|||||||
case SCRIPT_EPOFFS:
|
case SCRIPT_EPOFFS:
|
||||||
glob_script_mem.epoch_offset = *dfvar;
|
glob_script_mem.epoch_offset = *dfvar;
|
||||||
break;
|
break;
|
||||||
|
case SCRIPT_CBSIZE:
|
||||||
|
if (*dfvar > MAX_SCRIPT_CMDBUFFER) {
|
||||||
|
*dfvar = MAX_SCRIPT_CMDBUFFER;
|
||||||
|
}
|
||||||
|
glob_script_mem.cmdbuffer_size = *dfvar;
|
||||||
|
break;
|
||||||
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
|
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
|
||||||
case SML_JSON_ENABLE:
|
case SML_JSON_ENABLE:
|
||||||
sml_json_enable = *dfvar;
|
sml_json_enable = *dfvar;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user