Merge pull request #8910 from gemu2015/gcc-fixes

some gcc fixes, sml read
This commit is contained in:
Theo Arends 2020-07-15 09:57:48 +02:00 committed by GitHub
commit 07ca4dde23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 5 deletions

View File

@ -36,6 +36,8 @@ uint8_t wr_redir=0;
uint8_t *buffer; uint8_t *buffer;
#define register
#define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str); #define SPRINT(A) char str[32];sprintf(str,"val: %d ",A);Serial.println((char*)str);
#define OLED_FONT_WIDTH 6 #define OLED_FONT_WIDTH 6

View File

@ -1237,6 +1237,7 @@ uint32_t match_vars(char *dvnam, float **fp, char **sp, uint32_t *ind) {
} }
#endif #endif
// vtype => ff=nothing found, fe=constant number,fd = constant string else bit 7 => 80 = string, 0 = number // vtype => ff=nothing found, fe=constant number,fd = constant string else bit 7 => 80 = string, 0 = number
// no flash strings here for performance reasons!!! // no flash strings here for performance reasons!!!
char *isvar(char *lp, uint8_t *vtype,struct T_INDEX *tind,float *fp,char *sp,JsonObject *jo) { char *isvar(char *lp, uint8_t *vtype,struct T_INDEX *tind,float *fp,char *sp,JsonObject *jo) {
@ -1486,6 +1487,14 @@ chknext:
goto exit; goto exit;
} }
#endif #endif
if (!strncmp(vname,"asc(",4)) {
char str[SCRIPT_MAXSSIZE];
lp=GetStringResult(lp+4,OPER_EQU,str,0);
fvar=str[0];
lp++;
len=0;
goto exit;
}
break; break;
case 'b': case 'b':
@ -1975,6 +1984,14 @@ chknext:
} }
goto strexit; goto strexit;
} }
if (!strncmp(vname,"hd(",3)) {
char str[SCRIPT_MAXSSIZE];
lp=GetStringResult(lp+3,OPER_EQU,str,0);
fvar=strtol(str,NULL,16);
lp++;
len=0;
goto exit;
}
#ifdef USE_LIGHT #ifdef USE_LIGHT
//#ifdef USE_WS2812 //#ifdef USE_WS2812
if (!strncmp(vname,"hsvrgb(",7)) { if (!strncmp(vname,"hsvrgb(",7)) {
@ -2505,6 +2522,15 @@ chknext:
char str[SCRIPT_MAXSSIZE]; char str[SCRIPT_MAXSSIZE];
lp=GetStringResult(lp,OPER_EQU,str,0); lp=GetStringResult(lp,OPER_EQU,str,0);
fvar=SML_Write(fvar1,str); fvar=SML_Write(fvar1,str);
} else if (fvar2==2) {
char str[SCRIPT_MAXSSIZE];
str[0]=0;
fvar=SML_Read(fvar1,str,SCRIPT_MAXSSIZE);
if (sp) strlcpy(sp,str,glob_script_mem.max_ssize);
lp++;
len=0;
goto strexit;
} else { } else {
#ifdef ED300L #ifdef ED300L
fvar=SML_Status(fvar1); fvar=SML_Status(fvar1);
@ -2914,7 +2940,7 @@ char *GetStringResult(char *lp,uint8_t lastop,char *cp,JsonObject *jo) {
strlcpy(str,str1,sizeof(str)); strlcpy(str,str1,sizeof(str));
break; break;
case OPER_PLS: case OPER_PLS:
strncat(str,str1,sizeof(str)); strncat(str,str1,sizeof(str)-strlen(str1));
break; break;
} }
slp=lp; slp=lp;
@ -2939,6 +2965,7 @@ char *GetStringResult(char *lp,uint8_t lastop,char *cp,JsonObject *jo) {
return lp; return lp;
} }
} }
return lp;
} }
char *GetNumericResult(char *lp,uint8_t lastop,float *fp,JsonObject *jo) { char *GetNumericResult(char *lp,uint8_t lastop,float *fp,JsonObject *jo) {
@ -6408,6 +6435,7 @@ void ScriptJsonAppend(void) {
bool RulesProcessEvent(char *json_event) { bool RulesProcessEvent(char *json_event) {
if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">E",2,json_event); if (bitRead(Settings.rule_enabled, 0)) Run_Scripter(">E",2,json_event);
return true;
} }
#ifdef ESP32 #ifdef ESP32

View File

@ -467,7 +467,9 @@ TasmotaSerial *meter_ss[MAX_METERS];
#endif #endif
// serial buffers, may be made larger depending on telegram lenght // serial buffers, may be made larger depending on telegram lenght
#ifndef SML_BSIZ
#define SML_BSIZ 48 #define SML_BSIZ 48
#endif
uint8_t smltbuf[MAX_METERS][SML_BSIZ]; uint8_t smltbuf[MAX_METERS][SML_BSIZ];
// meter nr as string // meter nr as string
@ -1186,7 +1188,7 @@ void sml_empty_receiver(uint32_t meters) {
void sml_shift_in(uint32_t meters,uint32_t shard) { void sml_shift_in(uint32_t meters,uint32_t shard) {
uint32_t count; uint32_t count;
if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m' && meter_desc_p[meters].type!='M' && meter_desc_p[meters].type!='p') { if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m' && meter_desc_p[meters].type!='M' && meter_desc_p[meters].type!='p' && meter_desc_p[meters].type!='R') {
// shift in // shift in
for (count=0; count<SML_BSIZ-1; count++) { for (count=0; count<SML_BSIZ-1; count++) {
smltbuf[meters][count]=smltbuf[meters][count+1]; smltbuf[meters][count]=smltbuf[meters][count+1];
@ -1217,7 +1219,14 @@ void sml_shift_in(uint32_t meters,uint32_t shard) {
sml_empty_receiver(meters); sml_empty_receiver(meters);
meter_spos[meters]=0; meter_spos[meters]=0;
} }
} else { } else if (meter_desc_p[meters].type=='R') {
smltbuf[meters][meter_spos[meters]] = iob;
meter_spos[meters]++;
if (meter_spos[meters]>=SML_BSIZ) {
meter_spos[meters]=0;
}
}
else {
if (iob==EBUS_SYNC) { if (iob==EBUS_SYNC) {
// should be end of telegramm // should be end of telegramm
// QQ,ZZ,PB,SB,NN ..... CRC, ACK SYNC // QQ,ZZ,PB,SB,NN ..... CRC, ACK SYNC
@ -1243,7 +1252,7 @@ void sml_shift_in(uint32_t meters,uint32_t shard) {
} }
} }
sb_counter++; sb_counter++;
if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m' && meter_desc_p[meters].type!='M' && meter_desc_p[meters].type!='p') SML_Decode(meters); if (meter_desc_p[meters].type!='e' && meter_desc_p[meters].type!='m' && meter_desc_p[meters].type!='M' && meter_desc_p[meters].type!='p' && meter_desc_p[meters].type!='R') SML_Decode(meters);
} }
@ -1271,6 +1280,7 @@ void SML_Decode(uint8_t index) {
delay(0); delay(0);
while (mp != NULL) { while (mp != NULL) {
// check list of defines // check list of defines
if (*mp==0) break;
// new section // new section
mindex=((*mp)&7)-1; mindex=((*mp)&7)-1;
@ -1648,6 +1658,7 @@ void SML_Show(boolean json) {
int8_t lastmind=((*mp)&7)-1; int8_t lastmind=((*mp)&7)-1;
if (lastmind<0 || lastmind>=meters_used) lastmind=0; if (lastmind<0 || lastmind>=meters_used) lastmind=0;
while (mp != NULL) { while (mp != NULL) {
if (*mp==0) break;
// setup sections // setup sections
mindex=((*mp)&7)-1; mindex=((*mp)&7)-1;
if (mindex<0 || mindex>=meters_used) mindex=0; if (mindex<0 || mindex>=meters_used) mindex=0;
@ -2151,7 +2162,7 @@ init10:
} else { } else {
// serial input, init // serial input, init
#ifdef SPECIAL_SS #ifdef SPECIAL_SS
if (meter_desc_p[meters].type=='m' || meter_desc_p[meters].type=='M' || meter_desc_p[meters].type=='p') { if (meter_desc_p[meters].type=='m' || meter_desc_p[meters].type=='M' || meter_desc_p[meters].type=='p' || meter_desc_p[meters].type=='R') {
meter_ss[meters] = new TasmotaSerial(meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin,1,0,TMSBSIZ); meter_ss[meters] = new TasmotaSerial(meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin,1,0,TMSBSIZ);
} else { } else {
meter_ss[meters] = new TasmotaSerial(meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin,1,1,TMSBSIZ); meter_ss[meters] = new TasmotaSerial(meter_desc_p[meters].srcpin,meter_desc_p[meters].trxpin,1,1,TMSBSIZ);
@ -2201,6 +2212,12 @@ uint32_t SML_SetBaud(uint32_t meter, uint32_t br) {
#ifdef ESP32 #ifdef ESP32
meter_ss[meter]->flush(); meter_ss[meter]->flush();
meter_ss[meter]->updateBaudRate(br); meter_ss[meter]->updateBaudRate(br);
/*
if (meter_desc_p[meter].type=='M') {
meter_ss[meter]->begin(br,SERIAL_8E1,meter_desc_p[meter].srcpin,meter_desc_p[meter].trxpin);
} else {
meter_ss[meter]->begin(br,SERIAL_8N1,meter_desc_p[meter].srcpin,meter_desc_p[meter].trxpin);
}*/
#else #else
if (meter_ss[meter]->begin(br)) { if (meter_ss[meter]->begin(br)) {
meter_ss[meter]->flush(); meter_ss[meter]->flush();
@ -2233,6 +2250,37 @@ uint32_t SML_Write(uint32_t meter,char *hstr) {
return 1; return 1;
} }
uint32_t SML_Read(int32_t meter,char *str, uint32_t slen) {
uint8_t hflg=0;
if (meter<0) {
meter=abs(meter);
hflg=1;
}
if (meter<1 || meter>meters_used) return 0;
meter--;
if (!meter_ss[meter]) return 0;
if (!meter_spos[meter]) {
return 0;
}
smltbuf[meter][meter_spos[meter]]=0;
if (!hflg) {
strlcpy(str,(char*)&smltbuf[meter][0],slen);
} else {
uint32_t index=0;
for (uint32_t cnt=0; cnt<meter_spos[meter]; cnt++) {
sprintf(str,"%02x",smltbuf[meter][cnt]);
str+=2;
index+=2;
if (index>=slen-2) break;
}
}
meter_spos[meter]=0;
return 1;
}
float SML_GetVal(uint32_t index) { float SML_GetVal(uint32_t index) {
if (index<1 && index>SML_MAX_VARS) { index = 1;} if (index<1 && index>SML_MAX_VARS) { index = 1;}
return meter_vars[index-1]; return meter_vars[index-1];