Merge branch 'development' of github.com:arendst/Tasmota into pr_tm1638

This commit is contained in:
Ajith Vasudevan 2021-02-22 17:10:59 +05:30
commit 424d953961
2 changed files with 156 additions and 91 deletions

View File

@ -162,6 +162,7 @@ void Script_ticker4_end(void) {
#endif
#endif
extern uint8_t sml_json_enable;
#if defined(EEP_SCRIPT_SIZE) && !defined(ESP32)
@ -208,7 +209,7 @@ void alt_eeprom_readBytes(uint32_t adr, uint32_t len, uint8_t *buf) {
#define EPOCH_OFFSET 1546300800
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};
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED};
enum {SCRIPT_LOGLEVEL=1,SCRIPT_TELEPERIOD,SCRIPT_EVENT_HANDLED,SML_JSON_ENABLE};
#ifdef USE_UFILESYS
@ -2985,6 +2986,11 @@ chknext:
len = 0;
goto exit;
}
if (!strncmp(vname, "smlj", 4)) {
fvar = sml_json_enable;
tind->index = SML_JSON_ENABLE;
goto exit_settable;
}
#endif //USE_SML_M
break;
case 't':
@ -4527,6 +4533,11 @@ int16_t Run_script_sub(const char *type, int8_t tlen, struct GVARS *gv) {
case SCRIPT_EVENT_HANDLED:
glob_script_mem.event_handeled = *dfvar;
break;
#if defined(USE_SML_M) && defined (USE_SML_SCRIPT_CMD)
case SML_JSON_ENABLE:
sml_json_enable = *dfvar;
break;
#endif
}
sysv_type = 0;
}

View File

@ -49,8 +49,9 @@
#define SPECIAL_SS
#endif
#undef TMSBSIZ
#ifndef TMSBSIZ
#define TMSBSIZ 256
#endif
// addresses a bug in meter DWS74
//#define DWS74_BUG
@ -469,7 +470,7 @@ uint8_t dvalid[SML_MAX_VARS];
struct METER_DESC const *meter_desc_p;
const uint8_t *meter_p;
uint8_t meter_spos[MAX_METERS];
uint16_t meter_spos[MAX_METERS];
// software serial pointers
#ifdef ESP8266
@ -820,13 +821,12 @@ uint8_t Serial_peek() {
}
uint8_t sml_logindex;
char log_data[128];
void Dump2log(void) {
int16_t index=0,hcnt=0;
uint32_t d_lastms;
uint8_t dchars[16];
char log_data[128];
//if (!SML_SAVAILABLE) return;
@ -1258,7 +1258,7 @@ void sml_shift_in(uint32_t meters,uint32_t shard) {
// QQ,ZZ,PB,SB,NN ..... CRC, ACK SYNC
if (meter_spos[meters]>4+5) {
// get telegramm lenght
uint8_t tlen=smltbuf[meters][4]+5;
uint16_t tlen=smltbuf[meters][4]+5;
// test crc
if (smltbuf[meters][tlen]=ebus_CalculateCRC(smltbuf[meters],tlen)) {
ebus_esc(smltbuf[meters],tlen);
@ -1548,15 +1548,17 @@ void SML_Decode(uint8_t index) {
#endif
if (*mp == '#') {
// get string value
getstr:
mp++;
if (meter_desc_p[mindex].type == 'o') {
for (uint8_t p=0; p<METER_ID_SIZE; p++) {
uint32_t p;
for (p = 0; p < METER_ID_SIZE - 2; p++) {
if (*cp == *mp) {
meter_id[mindex][p] = 0;
break;
}
meter_id[mindex][p] = *cp++;
}
meter_id[mindex][p] = 0;
} else {
sml_getvalue(cp,mindex);
}
@ -1567,12 +1569,26 @@ void SML_Decode(uint8_t index) {
if (meter_desc_p[mindex].type=='o' || meter_desc_p[mindex].type=='c') {
if (*mp == '(') {
mp++;
// skip this bracket
char *bp = strchr((char*)cp, '(');
if (bp) {
cp = (uint8_t*) (bp + 1);
// skip this number of brackets
uint8_t toskip = strtol((char*)mp,(char**)&mp, 10);
mp++;
char *lcp = (char*)cp;
if (toskip) {
char *bp = (char*)cp;
for (uint32_t cnt = 0; cnt < toskip; cnt++) {
bp = strchr(bp, '(');
if (!bp) {
break;
}
dval=CharToDouble((char*)cp);
bp++;
lcp = bp;
}
}
if (*mp=='#') {
cp = (uint8_t*)lcp;
goto getstr;
}
dval=CharToDouble((char*)lcp);
} else {
dval=CharToDouble((char*)cp);
}
@ -1623,13 +1639,14 @@ void SML_Decode(uint8_t index) {
#else
meter_vars[vindex]=dval;
#endif
dvalid[vindex] = 1;
//AddLog_P(LOG_LEVEL_INFO, PSTR(">> %s"),mp);
// get scaling factor
double fac=CharToDouble((char*)mp);
meter_vars[vindex]/=fac;
SML_Immediate_MQTT((const char*)mp,vindex,mindex);
}
dvalid[vindex] = 1;
}
}
nextsect:
@ -1737,10 +1754,20 @@ void SML_Show(boolean json) {
cp=strchr(mp,'@');
if (cp) {
cp++;
tststr:
if (*cp=='#') {
// meter id
sprintf(tpowstr,"\"%s\"",&meter_id[mindex][0]);
mid=1;
} else if (*cp=='(') {
if (meter_desc_p[mindex].type=='o') {
cp++;
strtol((char*)cp,(char**)&cp, 10);
cp++;
goto tststr;
} else {
mid=0;
}
} else {
mid=0;
}
@ -1992,6 +2019,7 @@ void SML_Init(void) {
uint16_t index = 0;
uint8_t section = 0;
uint8_t srcpin = 0;
uint8_t dec_line = 0;
char *lp = glob_script_mem.scriptptr;
sml_send_blocks = 0;
while (lp) {
@ -2021,7 +2049,10 @@ void SML_Init(void) {
lp++;
index = *lp&7;
lp += 2;
if (index<1 || index>meters_used) goto next_line;
if (index < 1 || index > meters_used) {
AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!"));
goto next_line;
}
index--;
srcpin = strtol(lp,&lp,10);
if (Gpio_used(srcpin)) {
@ -2107,7 +2138,18 @@ dddef_exit:
// add meters line -1,1-0:1.8.0*255(@10000,H2OIN,cbm,COUNTER,4|
if (*lp1 == '-') lp1++;
uint8_t mnum = strtol(lp1, 0, 10);
if (mnum<1 || mnum>meters_used) goto next_line;
if (mnum < 1 || mnum > meters_used) {
AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!"));
goto next_line;
}
// 1,=h—————————————
if (strncmp(lp1 + 1, ",=h", 3)) {
dec_line++;
if (dec_line >= SML_MAX_VARS) {
AddLog(LOG_LEVEL_INFO, PSTR("too many decode lines: %d !"), dec_line);
goto next_line;
}
}
while (1) {
if (*lp1 == 0) {
*tp++ = '|';
@ -2125,7 +2167,18 @@ dddef_exit:
// add meters line -1,1-0:1.8.0*255(@10000,H2OIN,cbm,COUNTER,4|
if (*lp == '-') lp++;
uint8_t mnum = strtol(lp,0,10);
if (mnum<1 || mnum>meters_used) goto next_line;
if (mnum < 1 || mnum > meters_used) {
AddLog(LOG_LEVEL_INFO, PSTR("illegal meter number!"));
goto next_line;
}
if (strncmp(lp + 1, ",=h", 3)) {
dec_line++;
if (dec_line >= SML_MAX_VARS) {
AddLog(LOG_LEVEL_INFO, PSTR("too many decode lines: %d !"), dec_line);
goto next_line;
}
}
while (1) {
if (*lp == SCRIPT_EOL) {
if (*(tp-1) != '|') *tp++ = '|';
@ -2135,6 +2188,7 @@ dddef_exit:
index++;
if (index >= METER_DEF_SIZE) break;
}
}
#endif