Merge pull request #8540 from gemu2015/scripter-fix

fix some bugs, some refactoring
This commit is contained in:
Theo Arends 2020-05-25 15:59:26 +02:00 committed by GitHub
commit c47558839d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1993,12 +1993,13 @@ chknext:
goto exit; goto exit;
} }
#endif #endif
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD) #if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
if (!strncmp(vname,"sml[",4)) { if (!strncmp(vname,"sml[",4)) {
lp+=4; lp+=4;
lp=GetNumericResult(lp,OPER_EQU,&fvar,0); lp=GetNumericResult(lp,OPER_EQU,&fvar,0);
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
fvar=SML_GetVal[fvar]; fvar=SML_GetVal(fvar);
lp++; lp++;
len=0; len=0;
goto exit; goto exit;
@ -2786,6 +2787,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
if (tasm_cmd_activ && tlen>0) return 0; if (tasm_cmd_activ && tlen>0) return 0;
uint8_t vtype=0,sindex,xflg,floop=0,globvindex,fromscriptcmd=0; uint8_t vtype=0,sindex,xflg,floop=0,globvindex,fromscriptcmd=0;
char *lp_next;
int8_t globaindex; int8_t globaindex;
struct T_INDEX ind; struct T_INDEX ind;
uint8_t operand,lastop,numeric=1,if_state[IF_NEST],if_exe[IF_NEST],if_result[IF_NEST],and_or,ifstck=0; uint8_t operand,lastop,numeric=1,if_state[IF_NEST],if_exe[IF_NEST],if_result[IF_NEST],and_or,ifstck=0;
@ -2925,6 +2927,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
// simple implementation, zero loop count not supported // simple implementation, zero loop count not supported
lp+=3; lp+=3;
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
lp_next=0;
lp=isvar(lp,&vtype,&ind,0,0,0); lp=isvar(lp,&vtype,&ind,0,0,0);
if ((vtype!=VAR_NV) && (vtype&STYPE)==0) { if ((vtype!=VAR_NV) && (vtype&STYPE)==0) {
// numeric var // numeric var
@ -2947,7 +2950,10 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
// error // error
toLogEOL("for error",lp); toLogEOL("for error",lp);
} }
} else if (!strncmp(lp,"next",4) && floop>0) { } else if (!strncmp(lp,"next",4)) {
lp+=4;
lp_next=lp;
if (floop>0) {
// for next loop // for next loop
*cv_count+=cv_inc; *cv_count+=cv_inc;
if (floop==1) { if (floop==1) {
@ -2966,6 +2972,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
} }
} }
} }
}
if (!strncmp(lp,"switch",6)) { if (!strncmp(lp,"switch",6)) {
lp+=6; lp+=6;
@ -3022,13 +3029,15 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
#endif #endif
if (!strncmp(lp,"break",5)) { if (!strncmp(lp,"break",5)) {
if (floop) { lp+=5;
if (floop && lp_next) {
// should break loop // should break loop
lp=lp_next;
floop=0; floop=0;
} else { } else {
section=0; section=0;
} }
break; goto next_line;
} else if (!strncmp(lp,"dp",2) && isdigit(*(lp+2))) { } else if (!strncmp(lp,"dp",2) && isdigit(*(lp+2))) {
lp+=2; lp+=2;
// number precision // number precision
@ -3357,6 +3366,7 @@ int16_t Run_Scripter(const char *type, int8_t tlen, char *js) {
goto next_line; goto next_line;
} }
} else { } else {
//Serial.printf(">> decode %s\n",lp );
// decode line // decode line
if (*lp=='>' && tlen==1) { if (*lp=='>' && tlen==1) {
// called from cmdline // called from cmdline
@ -4998,6 +5008,9 @@ const char SCRIPT_MSG_GTABLEb[] PROGMEM =
const char SCRIPT_MSG_GOPT1[] PROGMEM = const char SCRIPT_MSG_GOPT1[] PROGMEM =
"title:'%s',isStacked:false"; "title:'%s',isStacked:false";
const char SCRIPT_MSG_GAUGEOPT[] PROGMEM =
"max:%d,redFrom:%d,redTo:%d,yellowFrom:%d,yellowTo:%d";
const char SCRIPT_MSG_GOPT2[] PROGMEM = const char SCRIPT_MSG_GOPT2[] PROGMEM =
"showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc"; "showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc";
@ -5029,7 +5042,8 @@ uint8 entries=0;
while (anum<MAX_GARRAY) { while (anum<MAX_GARRAY) {
if (*lp==')' || *lp==0) break; if (*lp==')' || *lp==0) break;
char *lp1=lp; char *lp1=lp;
lp=isvar(lp,&vtype,&ind,0,0,0); float sysvar;
lp=isvar(lp,&vtype,&ind,&sysvar,0,0);
if (vtype!=VAR_NV) { if (vtype!=VAR_NV) {
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
uint8_t index=glob_script_mem.type[ind.index].index; uint8_t index=glob_script_mem.type[ind.index].index;
@ -5047,6 +5061,11 @@ uint8 entries=0;
arrays[anum]=fa; arrays[anum]=fa;
anum++; anum++;
} }
} else {
// single numeric
arrays[anum]=&glob_script_mem.fvars[index];
anum++;
entries=1;
} }
} else { } else {
lp=lp1; lp=lp1;
@ -5054,6 +5073,7 @@ uint8 entries=0;
} }
} }
} }
//Serial.printf(">> %d - %d - %d\n",anum,entries,(uint32_t)*arrays[0]);
*ranum=anum; *ranum=anum;
*rentries=entries; *rentries=entries;
return lp; return lp;
@ -5089,8 +5109,7 @@ uint32_t cnt;
void ScriptWebShow(char mc) { void ScriptWebShow(char mc) {
uint8_t web_script=Run_Scripter(">W",-2,0); uint8_t web_script=Run_Scripter(">W",-2,0);
if (web_script==99) { if (web_script==99) {
char line[128]; char tmp[256];
char tmp[128];
uint8_t optflg=0; uint8_t optflg=0;
uint8_t chartindex=1; uint8_t chartindex=1;
uint8_t google_libs=0; uint8_t google_libs=0;
@ -5104,26 +5123,16 @@ void ScriptWebShow(char mc) {
} }
if (*lp!=';') { if (*lp!=';') {
// send this line to web // send this line to web
memcpy(line,lp,sizeof(line)); Replace_Cmd_Vars(lp,1,tmp,sizeof(tmp));
line[sizeof(line)-1]=0; char *lin=tmp;
char *cp=line; if (!mc && (*lin!='$')) {
for (uint32_t i=0; i<sizeof(line); i++) { // normal web section
if (!*cp || *cp=='\n' || *cp=='\r') {
*cp=0;
break;
}
cp++;
}
char *lin=line;
if (!mc && (*lin!='&')) {
if (*lin=='@') { if (*lin=='@') {
lin++; lin++;
optflg=1; optflg=1;
} else { } else {
optflg=0; optflg=0;
} }
// check for input elements // check for input elements
if (!strncmp(lin,"sl(",3)) { if (!strncmp(lin,"sl(",3)) {
// insert slider sl(min max var left mid right) // insert slider sl(min max var left mid right)
@ -5155,7 +5164,6 @@ void ScriptWebShow(char mc) {
WSContentSend_PD(SCRIPT_MSG_SLIDER,left,mid,right,(uint32_t)min,(uint32_t)max,(uint32_t)val,vname); WSContentSend_PD(SCRIPT_MSG_SLIDER,left,mid,right,(uint32_t)min,(uint32_t)max,(uint32_t)val,vname);
} else if (!strncmp(lin,"ck(",3)) { } else if (!strncmp(lin,"ck(",3)) {
char *lp=lin+3; char *lp=lin+3;
char *slp=lp; char *slp=lp;
@ -5233,6 +5241,7 @@ void ScriptWebShow(char mc) {
} }
if (optflg) WSContentSend_PD(SCRIPT_MSG_BUT_STOP_TBL); if (optflg) WSContentSend_PD(SCRIPT_MSG_BUT_STOP_TBL);
else WSContentSend_PD(SCRIPT_MSG_BUT_STOP); else WSContentSend_PD(SCRIPT_MSG_BUT_STOP);
} else if (!strncmp(lin,"tx(",3)) { } else if (!strncmp(lin,"tx(",3)) {
char *lp=lin+3; char *lp=lin+3;
char *slp=lp; char *slp=lp;
@ -5274,25 +5283,28 @@ void ScriptWebShow(char mc) {
dtostrfd(max,4,maxstr); dtostrfd(max,4,maxstr);
dtostrfd(step,4,stepstr); dtostrfd(step,4,stepstr);
WSContentSend_PD(SCRIPT_MSG_NUMINP,label,minstr,maxstr,stepstr,vstr,vname); WSContentSend_PD(SCRIPT_MSG_NUMINP,label,minstr,maxstr,stepstr,vstr,vname);
} else { } else {
Replace_Cmd_Vars(lin,0,tmp,sizeof(tmp));
if (optflg) { if (optflg) {
WSContentSend_PD(PSTR("<div>%s</div>"),tmp); WSContentSend_PD(PSTR("<div>%s</div>"),tmp);
} else { } else {
WSContentSend_PD(PSTR("{s}%s{e}"),tmp); WSContentSend_PD(PSTR("{s}%s{e}"),tmp);
} }
} }
// end standard web interface
} else { } else {
// main section interface
if (*lin==mc) { if (*lin==mc) {
#ifdef USE_GOOGLE_CHARTS #ifdef USE_GOOGLE_CHARTS
lin++; lin++;
char *lp;
if (!strncmp(lin,"gc(",3)) { if (!strncmp(lin,"gc(",3)) {
// get google table // get google table
lp=lin+3; lp=lin+3;
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
const char *type; const char *type;
const char *func; const char *func;
char options[256]; char options[312];
uint8_t nanum=MAX_GARRAY; uint8_t nanum=MAX_GARRAY;
uint8_t y2f=0; uint8_t y2f=0;
char ctype; char ctype;
@ -5377,18 +5389,9 @@ void ScriptWebShow(char mc) {
char label[SCRIPT_MAXSSIZE]; char label[SCRIPT_MAXSSIZE];
lp=GetStringResult(lp,OPER_EQU,label,0); lp=GetStringResult(lp,OPER_EQU,label,0);
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
char *lblp=label;
for (uint32_t ind=0; ind<anum; ind++) { for (uint32_t ind=0; ind<anum; ind++) {
char lbl[16]; char lbl[16];
strncpy(lbl,lblp,sizeof(lbl)); GetTextIndexed(lbl, sizeof(lbl), ind, label);
for (uint32_t i=0; i<strlen(lblp); i++) {
if (lblp[i]=='|') {
lbl[i]=0;
lblp+=i+1;
break;
}
lbl[i]=lblp[i];
}
for (uint32_t cnt=0; cnt<entries; cnt+=2) { for (uint32_t cnt=0; cnt<entries; cnt+=2) {
WSContentSend_PD("['%s',",lbl); WSContentSend_PD("['%s',",lbl);
float *fp=arrays[ind]; float *fp=arrays[ind];
@ -5414,19 +5417,20 @@ void ScriptWebShow(char mc) {
char label[SCRIPT_MAXSSIZE]; char label[SCRIPT_MAXSSIZE];
lp=GetStringResult(lp,OPER_EQU,label,0); lp=GetStringResult(lp,OPER_EQU,label,0);
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
char *lblp=label;
int8_t todflg=-1;
if (!strncmp(label,"cnt",3)) {
todflg=atoi(&label[3]);
}
for (uint32_t cnt=0; cnt<entries; cnt++) { for (uint32_t cnt=0; cnt<entries; cnt++) {
WSContentSend_PD("['"); WSContentSend_PD("['");
char lbl[16]; char lbl[16];
strncpy(lbl,lblp,sizeof(lbl)); if (todflg>=0) {
for (uint32_t i=0; i<strlen(lblp); i++) { sprintf(lbl,"%d",todflg);
if (lblp[i]=='|') { todflg++;
lbl[i]=0; } else {
lblp+=i+1; GetTextIndexed(lbl, sizeof(lbl), cnt, label);
break;
}
lbl[i]=lblp[i];
} }
WSContentSend_PD(lbl); WSContentSend_PD(lbl);
WSContentSend_PD("',"); WSContentSend_PD("',");
@ -5466,17 +5470,31 @@ void ScriptWebShow(char mc) {
SCRIPT_SKIP_SPACES SCRIPT_SKIP_SPACES
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT3,header,(uint32_t)max1,(uint32_t)max2,func); snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT3,header,(uint32_t)max1,(uint32_t)max2,func);
} }
if (ctype=='g') {
float yellowFrom;
lp=GetNumericResult(lp,OPER_EQU,&yellowFrom,0);
SCRIPT_SKIP_SPACES
float redFrom;
lp=GetNumericResult(lp,OPER_EQU,&redFrom,0);
SCRIPT_SKIP_SPACES
float maxValue;
lp=GetNumericResult(lp,OPER_EQU,&maxValue,0);
SCRIPT_SKIP_SPACES
float redTo=maxValue;
float yellowTo=redFrom;
snprintf_P(options,sizeof(options),SCRIPT_MSG_GAUGEOPT,(uint32_t)maxValue,(uint32_t)redFrom,(uint32_t)redTo,
(uint32_t)yellowFrom,(uint32_t)yellowTo);
}
} }
WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex); WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex);
chartindex++; chartindex++;
} else { } else {
Replace_Cmd_Vars(lin,0,tmp,sizeof(tmp)); WSContentSend_PD(PSTR("%s"),lin);
WSContentSend_PD(PSTR("%s"),tmp);
} }
#else #else
} else { } else {
Replace_Cmd_Vars(lin,0,tmp,sizeof(tmp)); // WSContentSend_PD(PSTR("%s"),lin);
WSContentSend_PD(PSTR("%s"),tmp);
#endif //USE_GOOGLE_CHARTS #endif //USE_GOOGLE_CHARTS
} }
} }
@ -5809,7 +5827,7 @@ bool Xdrv10(uint8_t function)
#ifdef USE_SCRIPT_WEB_DISPLAY #ifdef USE_SCRIPT_WEB_DISPLAY
case FUNC_WEB_ADD_MAIN_BUTTON: case FUNC_WEB_ADD_MAIN_BUTTON:
if (bitRead(Settings.rule_enabled, 0)) { if (bitRead(Settings.rule_enabled, 0)) {
ScriptWebShow('&'); ScriptWebShow('$');
} }
break; break;
#endif // USE_SCRIPT_WEB_DISPLAY #endif // USE_SCRIPT_WEB_DISPLAY