better impl of ebus negative values

This commit is contained in:
gemu2015 2021-02-11 08:47:48 +01:00
parent d193c740fa
commit d29a9f4d55
1 changed files with 9 additions and 18 deletions

View File

@ -1419,9 +1419,8 @@ void SML_Decode(uint8_t index) {
} }
} else { } else {
// compare value // compare value
uint8_t found=1, use_uval = 1; uint8_t found=1;
uint32_t ebus_uval=99; double ebus_dval=99;
float ebus_dval;
float mbus_dval=99; float mbus_dval=99;
while (*mp!='@') { while (*mp!='@') {
if (meter_desc_p[mindex].type=='o' || meter_desc_p[mindex].type=='c') { if (meter_desc_p[mindex].type=='o' || meter_desc_p[mindex].type=='c') {
@ -1445,19 +1444,18 @@ void SML_Decode(uint8_t index) {
cp++; cp++;
} else if (!strncmp(mp,"UUuuUUuu",8)) { } else if (!strncmp(mp,"UUuuUUuu",8)) {
uint32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0); uint32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0);
ebus_uval=val; ebus_dval=val;
mbus_dval=val; mbus_dval=val;
mp+=8; mp+=8;
cp+=4; cp+=4;
} else if (*mp=='U' && *(mp+1)=='U' && *(mp+2)=='u' && *(mp+3)=='u'){ } else if (*mp=='U' && *(mp+1)=='U' && *(mp+2)=='u' && *(mp+3)=='u'){
uint16_t val = cp[1]|(cp[0]<<8); uint16_t val = cp[1]|(cp[0]<<8);
mbus_dval=val; mbus_dval=val;
ebus_uval=val; ebus_dval=val;
mp+=4; mp+=4;
cp+=2; cp+=2;
} else if (!strncmp(mp,"SSssSSss",8)) { } else if (!strncmp(mp,"SSssSSss",8)) {
int32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0); int32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0);
use_uval = 0;
ebus_dval=val; ebus_dval=val;
mbus_dval=val; mbus_dval=val;
mp+=8; mp+=8;
@ -1465,25 +1463,23 @@ void SML_Decode(uint8_t index) {
} else if (*mp=='u' && *(mp+1)=='u' && *(mp+2)=='U' && *(mp+3)=='U'){ } else if (*mp=='u' && *(mp+1)=='u' && *(mp+2)=='U' && *(mp+3)=='U'){
uint16_t val = cp[0]|(cp[1]<<8); uint16_t val = cp[0]|(cp[1]<<8);
mbus_dval=val; mbus_dval=val;
ebus_uval=val; ebus_dval=val;
mp+=4; mp+=4;
cp+=2; cp+=2;
} else if (*mp=='u' && *(mp+1)=='u') { } else if (*mp=='u' && *(mp+1)=='u') {
uint8_t val = *cp++; uint8_t val = *cp++;
mbus_dval=val; mbus_dval=val;
ebus_uval=val; ebus_dval=val;
mp+=2; mp+=2;
} else if (*mp=='s' && *(mp+1)=='s' && *(mp+2)=='S' && *(mp+3)=='S') { } else if (*mp=='s' && *(mp+1)=='s' && *(mp+2)=='S' && *(mp+3)=='S') {
int16_t val = *cp|(*(cp+1)<<8); int16_t val = *cp|(*(cp+1)<<8);
mbus_dval=val; mbus_dval=val;
use_uval = 0;
ebus_dval=val; ebus_dval=val;
mp+=4; mp+=4;
cp+=2; cp+=2;
} else if (*mp=='S' && *(mp+1)=='S' && *(mp+2)=='s' && *(mp+3)=='s') { } else if (*mp=='S' && *(mp+1)=='S' && *(mp+2)=='s' && *(mp+3)=='s') {
int16_t val = cp[1]|(cp[0]<<8); int16_t val = cp[1]|(cp[0]<<8);
mbus_dval=val; mbus_dval=val;
use_uval = 0;
ebus_dval=val; ebus_dval=val;
mp+=4; mp+=4;
cp+=2; cp+=2;
@ -1491,14 +1487,12 @@ void SML_Decode(uint8_t index) {
else if (*mp=='s' && *(mp+1)=='s') { else if (*mp=='s' && *(mp+1)=='s') {
int8_t val = *cp++; int8_t val = *cp++;
mbus_dval=val; mbus_dval=val;
use_uval = 0;
ebus_dval=val; ebus_dval=val;
mp+=2; mp+=2;
} }
else if (!strncmp(mp,"ffffffff",8)) { else if (!strncmp(mp,"ffffffff",8)) {
uint32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0); uint32_t val= (cp[0]<<24)|(cp[1]<<16)|(cp[2]<<8)|(cp[3]<<0);
float *fp=(float*)&val; float *fp=(float*)&val;
use_uval = 0;
ebus_dval=*fp; ebus_dval=*fp;
mbus_dval=*fp; mbus_dval=*fp;
mp+=8; mp+=8;
@ -1508,7 +1502,6 @@ void SML_Decode(uint8_t index) {
// reverse word float // reverse word float
uint32_t val= (cp[1]<<0)|(cp[0]<<8)|(cp[3]<<16)|(cp[2]<<24); uint32_t val= (cp[1]<<0)|(cp[0]<<8)|(cp[3]<<16)|(cp[2]<<24);
float *fp=(float*)&val; float *fp=(float*)&val;
use_uval = 0;
ebus_dval=*fp; ebus_dval=*fp;
mbus_dval=*fp; mbus_dval=*fp;
mp+=8; mp+=8;
@ -1588,9 +1581,9 @@ void SML_Decode(uint8_t index) {
// ebus pzem or mbus or raw // ebus pzem or mbus or raw
if (*mp=='b') { if (*mp=='b') {
mp++; mp++;
uint8_t shift=*mp&7; uint8_t shift = *mp&7;
ebus_uval>>=shift; ebus_dval = (uint32_t)ebus_dval>>shift;
ebus_uval&=1; ebus_dval = (uint32_t)ebus_dval&1;
mp+=2; mp+=2;
} }
if (*mp=='i') { if (*mp=='i') {
@ -1613,8 +1606,6 @@ void SML_Decode(uint8_t index) {
uint8_t crc = SML_PzemCrc(&smltbuf[mindex][0],6); uint8_t crc = SML_PzemCrc(&smltbuf[mindex][0],6);
if (crc!=smltbuf[mindex][6]) goto nextsect; if (crc!=smltbuf[mindex][6]) goto nextsect;
dval=mbus_dval; dval=mbus_dval;
} else if (use_uval) {
dval=ebus_uval;
} else { } else {
dval=ebus_dval; dval=ebus_dval;
} }