mirror of https://github.com/arendst/Tasmota.git
Merge pull request #8501 from gemu2015/scripter-fix
fix scripter unishox error
This commit is contained in:
commit
1edc02b64f
|
@ -52,7 +52,9 @@ keywords if then else endif, or, and are better readable for beginners (others m
|
||||||
#endif
|
#endif
|
||||||
#define MAXNVARS MAXVARS-MAXSVARS
|
#define MAXNVARS MAXVARS-MAXSVARS
|
||||||
|
|
||||||
|
#ifndef MAXFILT
|
||||||
#define MAXFILT 5
|
#define MAXFILT 5
|
||||||
|
#endif
|
||||||
#define SCRIPT_SVARSIZE 20
|
#define SCRIPT_SVARSIZE 20
|
||||||
#define SCRIPT_MAXSSIZE 48
|
#define SCRIPT_MAXSSIZE 48
|
||||||
#define SCRIPT_EOL '\n'
|
#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 EncodeLightId(uint8_t relay_id);
|
||||||
uint32_t DecodeLightId(uint32_t hue_id);
|
uint32_t DecodeLightId(uint32_t hue_id);
|
||||||
|
|
||||||
|
#ifdef USE_SCRIPT_COMPRESSION
|
||||||
#include <unishox.h>
|
#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)
|
#if defined(ESP32) && defined(ESP32_SCRIPT_SIZE) && !defined(USE_24C256) && !defined(USE_SCRIPT_FATFS)
|
||||||
#include "FS.h"
|
#include "FS.h"
|
||||||
#include "SPIFFS.h"
|
#include "SPIFFS.h"
|
||||||
|
@ -1757,7 +1768,7 @@ chknext:
|
||||||
lp=GetNumericResult(lp,OPER_EQU,&fvar2,0);
|
lp=GetNumericResult(lp,OPER_EQU,&fvar2,0);
|
||||||
lp++;
|
lp++;
|
||||||
//fvar=pow(fvar1,fvar2);
|
//fvar=pow(fvar1,fvar2);
|
||||||
fvar=FastPrecisePow(fvar1,fvar2);
|
fvar=FastPrecisePowf(fvar1,fvar2);
|
||||||
len=0;
|
len=0;
|
||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
|
@ -3966,24 +3977,24 @@ void ScriptSaveSettings(void) {
|
||||||
glob_script_mem.script_mem_size=0;
|
glob_script_mem.script_mem_size=0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef USE_SCRIPT_COMPRESSION
|
||||||
#ifndef UNISHOXRSIZE
|
|
||||||
#define UNISHOXRSIZE 2560
|
|
||||||
#endif
|
|
||||||
#ifdef USE_RULES_COMPRESSION
|
|
||||||
#ifndef USE_24C256
|
#ifndef USE_24C256
|
||||||
#ifndef USE_SCRIPT_FATFS
|
#ifndef USE_SCRIPT_FATFS
|
||||||
#ifndef ESP32_SCRIPT_SIZE
|
#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) {
|
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 {
|
} else {
|
||||||
AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed);
|
AddLog_P2(LOG_LEVEL_INFO, PSTR("script compress error: %d"), len_compressed);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif // USE_RULES_COMPRESSION
|
#endif // USE_SCRIPT_COMPRESSION
|
||||||
|
|
||||||
if (bitRead(Settings.rule_enabled, 0)) {
|
if (bitRead(Settings.rule_enabled, 0)) {
|
||||||
int16_t res=Init_Scripter();
|
int16_t res=Init_Scripter();
|
||||||
|
@ -4912,6 +4923,10 @@ 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_GOPT3[] PROGMEM =
|
||||||
|
"title:'%s',vAxes:{0:{maxValue:%d},1:{maxValue:%d}},series:{0:{targetAxisIndex:0},1:{targetAxisIndex:1}}";
|
||||||
|
|
||||||
|
|
||||||
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";
|
||||||
|
|
||||||
|
@ -5223,14 +5238,27 @@ void ScriptWebShow(char mc) {
|
||||||
lp=GetStringResult(lp,OPER_EQU,header,0);
|
lp=GetStringResult(lp,OPER_EQU,header,0);
|
||||||
SCRIPT_SKIP_SPACES
|
SCRIPT_SKIP_SPACES
|
||||||
|
|
||||||
char options[128];
|
char options[256];
|
||||||
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT1,header);
|
snprintf_P(options,sizeof(options),SCRIPT_MSG_GOPT1,header);
|
||||||
|
//uint32_t slen=sizeof(SCRIPT_MSG_GOPT1)+strlen(header);
|
||||||
|
|
||||||
const char *type;
|
const char *type;
|
||||||
if (*lp!=')') {
|
if (*lp!=')') {
|
||||||
switch (*lp) {
|
switch (*lp) {
|
||||||
case 'l':
|
case 'l':
|
||||||
type=PSTR("LineChart");
|
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;
|
break;
|
||||||
case 'b':
|
case 'b':
|
||||||
type=PSTR("BarChart");
|
type=PSTR("BarChart");
|
||||||
|
@ -5255,6 +5283,7 @@ void ScriptWebShow(char mc) {
|
||||||
} else {
|
} else {
|
||||||
type=PSTR("ColumnChart");
|
type=PSTR("ColumnChart");
|
||||||
}
|
}
|
||||||
|
lp++;
|
||||||
|
|
||||||
WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex);
|
WSContentSend_PD(SCRIPT_MSG_GTABLEb,options,type,chartindex);
|
||||||
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 Xdrv10(uint8_t function)
|
||||||
{
|
{
|
||||||
bool result = false;
|
bool result = false;
|
||||||
|
char *sprt;
|
||||||
|
|
||||||
switch (function) {
|
switch (function) {
|
||||||
case FUNC_PRE_INIT:
|
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=(uint8_t*)Settings.script_pram[0];
|
||||||
glob_script_mem.script_pram_size=PMEM_SIZE;
|
glob_script_mem.script_pram_size=PMEM_SIZE;
|
||||||
|
|
||||||
#ifdef USE_RULES_COMPRESSION
|
#ifdef USE_SCRIPT_COMPRESSION
|
||||||
#ifndef USE_24C256
|
#ifndef USE_24C256
|
||||||
#ifndef USE_SCRIPT_FATFS
|
#ifndef USE_SCRIPT_FATFS
|
||||||
#ifndef ESP32_SCRIPT_SIZE
|
#ifndef ESP32_SCRIPT_SIZE
|
||||||
glob_script_mem.script_ram=(char*)calloc(UNISHOXRSIZE+8,1);
|
int32_t len_decompressed;
|
||||||
if (!glob_script_mem.script_ram) { break; }
|
sprt=(char*)calloc(UNISHOXRSIZE+8,1);
|
||||||
unishox_decompress(Settings.rules[0], strlen(Settings.rules[0]), glob_script_mem.script_ram, UNISHOXRSIZE);
|
if (!sprt) { break; }
|
||||||
|
glob_script_mem.script_ram=sprt;
|
||||||
glob_script_mem.script_size=UNISHOXRSIZE;
|
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
|
||||||
#endif
|
#endif
|
||||||
#endif // USE_RULES_COMPRESSION
|
#endif // USE_SCRIPT_COMPRESSION
|
||||||
|
|
||||||
#ifdef USE_BUTTON_EVENT
|
#ifdef USE_BUTTON_EVENT
|
||||||
for (uint32_t cnt=0;cnt<MAX_KEYS;cnt++) {
|
for (uint32_t cnt=0;cnt<MAX_KEYS;cnt++) {
|
||||||
|
|
Loading…
Reference in New Issue