Merge pull request #8501 from gemu2015/scripter-fix

fix scripter unishox error
This commit is contained in:
Theo Arends 2020-05-21 08:36:39 +02:00 committed by GitHub
commit 1edc02b64f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 49 additions and 15 deletions

View File

@ -52,7 +52,9 @@ keywords if then else endif, or, and are better readable for beginners (others m
#endif
#define MAXNVARS MAXVARS-MAXSVARS
#ifndef MAXFILT
#define MAXFILT 5
#endif
#define SCRIPT_SVARSIZE 20
#define SCRIPT_MAXSSIZE 48
#define SCRIPT_EOL '\n'
@ -66,8 +68,17 @@ keywords if then else endif, or, and are better readable for beginners (others m
uint32_t EncodeLightId(uint8_t relay_id);
uint32_t DecodeLightId(uint32_t hue_id);
#ifdef USE_SCRIPT_COMPRESSION
#include <unishox.h>
Unishox compressor; // singleton
#define SCRIPT_COMPRESS compressor.unishox_compress
#define SCRIPT_DECOMPRESS compressor.unishox_decompress
#ifndef UNISHOXRSIZE
#define UNISHOXRSIZE 2560
#endif
#endif // USE_SCRIPT_COMPRESSION
#if defined(ESP32) && defined(ESP32_SCRIPT_SIZE) && !defined(USE_24C256) && !defined(USE_SCRIPT_FATFS)
#include "FS.h"
#include "SPIFFS.h"
@ -1757,7 +1768,7 @@ chknext:
lp=GetNumericResult(lp,OPER_EQU,&fvar2,0);
lp++;
//fvar=pow(fvar1,fvar2);
fvar=FastPrecisePow(fvar1,fvar2);
fvar=FastPrecisePowf(fvar1,fvar2);
len=0;
goto exit;
}
@ -3966,24 +3977,24 @@ void ScriptSaveSettings(void) {
glob_script_mem.script_mem_size=0;
}
#ifndef UNISHOXRSIZE
#define UNISHOXRSIZE 2560
#endif
#ifdef USE_RULES_COMPRESSION
#ifdef USE_SCRIPT_COMPRESSION
#ifndef USE_24C256
#ifndef USE_SCRIPT_FATFS
#ifndef ESP32_SCRIPT_SIZE
uint32_t len_compressed = unishox_compress(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram), Settings.rules[0], UNISHOXRSIZE);
//AddLog_P2(LOG_LEVEL_INFO,PSTR("in string: %s len = %d"),glob_script_mem.script_ram,strlen(glob_script_mem.script_ram));
uint32_t len_compressed = SCRIPT_COMPRESS(glob_script_mem.script_ram, strlen(glob_script_mem.script_ram)+1, Settings.rules[0], MAX_SCRIPT_SIZE-1);
Settings.rules[0][len_compressed] = 0;
if (len_compressed > 0) {
AddLog_P2(LOG_LEVEL_INFO,PSTR("compressed to %d"),len_compressed * 100 / strlen(glob_script_mem.script_ram));
AddLog_P2(LOG_LEVEL_INFO,PSTR("script compressed to %d %%"),len_compressed * 100 / strlen(glob_script_mem.script_ram));
} else {
AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed);
}
#endif
#endif
#endif
#endif // USE_RULES_COMPRESSION
#endif // USE_SCRIPT_COMPRESSION
if (bitRead(Settings.rule_enabled, 0)) {
int16_t res=Init_Scripter();
@ -4912,6 +4923,10 @@ const char SCRIPT_MSG_GTABLEb[] PROGMEM =
const char SCRIPT_MSG_GOPT1[] PROGMEM =
"title:'%s',isStacked:false";
const char SCRIPT_MSG_GOPT3[] PROGMEM =
"title:'%s',vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}";
const char SCRIPT_MSG_GOPT2[] PROGMEM =
"showRowNumber:true,sort:'disable',allowHtml:true,width:'100%%',height:'100%%',cssClassNames:cssc";
@ -5223,14 +5238,27 @@ void ScriptWebShow(char mc) {
lp=GetStringResult(lp,OPER_EQU,header,0);
SCRIPT_SKIP_SPACES
char options[128];
char options[256];
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT1,header);
//uint32_t slen=sizeof(SCRIPT_MSG_GOPT1)+strlen(header);
const char *type;
if (*lp!=')') {
switch (*lp) {
case 'l':
type=PSTR("LineChart");
if (*(lp+1)=='2') {
// 2 y axes variant
lp+=2;
SCRIPT_SKIP_SPACES
float max1;
lp=GetNumericResult(lp,OPER_EQU,&max1,0);
SCRIPT_SKIP_SPACES
float max2;
lp=GetNumericResult(lp,OPER_EQU,&max2,0);
SCRIPT_SKIP_SPACES
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT3,header,(uint32_t)max1,(uint32_t)max2);
}
break;
case 'b':
type=PSTR("BarChart");
@ -5255,6 +5283,7 @@ void ScriptWebShow(char mc) {
} else {
type=PSTR("ColumnChart");
}
lp++;
WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex);
chartindex++;
@ -5423,6 +5452,7 @@ uint32_t scripter_create_task(uint32_t num, uint32_t time, uint32_t core) {
bool Xdrv10(uint8_t function)
{
bool result = false;
char *sprt;
switch (function) {
case FUNC_PRE_INIT:
@ -5434,18 +5464,22 @@ bool Xdrv10(uint8_t function)
glob_script_mem.script_pram=(uint8_t*)Settings.script_pram[0];
glob_script_mem.script_pram_size=PMEM_SIZE;
#ifdef USE_RULES_COMPRESSION
#ifdef USE_SCRIPT_COMPRESSION
#ifndef USE_24C256
#ifndef USE_SCRIPT_FATFS
#ifndef ESP32_SCRIPT_SIZE
glob_script_mem.script_ram=(char*)calloc(UNISHOXRSIZE+8,1);
if (!glob_script_mem.script_ram) { break; }
unishox_decompress(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, UNISHOXRSIZE);
int32_t len_decompressed;
sprt=(char*)calloc(UNISHOXRSIZE+8,1);
if (!sprt) { break; }
glob_script_mem.script_ram=sprt;
glob_script_mem.script_size=UNISHOXRSIZE;
len_decompressed = SCRIPT_DECOMPRESS(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, glob_script_mem.script_size);
glob_script_mem.script_ram[len_decompressed]=0;
//AddLog_P2(LOG_LEVEL_INFO, PSTR("decompressed script len %d"),len_decompressed);
#endif
#endif
#endif
#endif // USE_RULES_COMPRESSION
#endif // USE_SCRIPT_COMPRESSION
#ifdef USE_BUTTON_EVENT
for (uint32_t cnt=0;cnt<MAX_KEYS;cnt++) {