Merge pull request #13958 from gemu2015/sml_update

sml update
This commit is contained in:
Theo Arends 2021-12-08 17:19:48 +01:00 committed by GitHub
commit 56db8ed749
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 64 additions and 12 deletions

View File

@ -1555,6 +1555,12 @@ void SML_Decode(uint8_t index) {
double vdiff = meter_vars[ind - 1] - dvalues[dindex]; double vdiff = meter_vars[ind - 1] - dvalues[dindex];
dvalues[dindex] = meter_vars[ind - 1]; dvalues[dindex] = meter_vars[ind - 1];
double dres = (double)360000.0 * vdiff / ((double)dtime / 10000.0); double dres = (double)360000.0 * vdiff / ((double)dtime / 10000.0);
dvalid[vindex] += 1;
if (dvalid[vindex] >= 2) {
// differece is only valid after 2. calculation
dvalid[vindex] = 2;
#ifdef USE_SML_MEDIAN_FILTER #ifdef USE_SML_MEDIAN_FILTER
if (meter_desc_p[mindex].flag & 16) { if (meter_desc_p[mindex].flag & 16) {
meter_vars[vindex] = sml_median(&sml_mf[vindex], dres); meter_vars[vindex] = sml_median(&sml_mf[vindex], dres);
@ -1564,7 +1570,7 @@ void SML_Decode(uint8_t index) {
#else #else
meter_vars[vindex] = dres; meter_vars[vindex] = dres;
#endif #endif
}
mp=strchr(mp,'@'); mp=strchr(mp,'@');
if (mp) { if (mp) {
mp++; mp++;
@ -1573,7 +1579,7 @@ void SML_Decode(uint8_t index) {
SML_Immediate_MQTT((const char*)mp, vindex, mindex); SML_Immediate_MQTT((const char*)mp, vindex, mindex);
} }
} }
dvalid[vindex] = 1; //dvalid[vindex] = 1;
dindex++; dindex++;
} }
} else if (*mp == 'h') { } else if (*mp == 'h') {
@ -2212,7 +2218,9 @@ uint8_t *script_meter;
#ifdef SML_REPLACE_VARS #ifdef SML_REPLACE_VARS
#ifndef SML_SRCBSIZE
#define SML_SRCBSIZE 256 #define SML_SRCBSIZE 256
#endif
uint32_t SML_getlinelen(char *lp) { uint32_t SML_getlinelen(char *lp) {
uint32_t cnt; uint32_t cnt;
@ -2404,10 +2412,53 @@ dddef_exit:
script_meter_desc[index].tsecs = strtol(lp, &lp, 10); script_meter_desc[index].tsecs = strtol(lp, &lp, 10);
if (*lp == ',') { if (*lp == ',') {
lp++; lp++;
char txbuff[256]; #if 1
// look ahead
uint16_t txlen = 0;
uint16_t tx_entries = 1;
char *txp = lp;
while (*txp) {
if (*txp == ',') tx_entries++;
if (*txp == SCRIPT_EOL) {
if (tx_entries > 1) {
if (*(txp - 1) != ',' ) {
break;
}
// line ends with ,
} else {
// single entry
break;
}
}
txp++;
txlen++;
}
if (txlen) {
script_meter_desc[index].txmem = (char*)calloc(txlen + 2, 1);
if (script_meter_desc[index].txmem) {
// now copy send blocks
char *txp = lp;
uint16_t tind = 0;
for (uint32_t cnt = 0; cnt < txlen; cnt++) {
if (*txp == SCRIPT_EOL) {
txp++;
} else {
script_meter_desc[index].txmem[tind] = *txp++;
tind++;
}
}
}
//AddLog(LOG_LEVEL_INFO, PSTR(">>> %s - %d"), script_meter_desc[index].txmem, txlen);
script_meter_desc[index].index = 0;
script_meter_desc[index].max_index = tx_entries;
sml_send_blocks++;
lp += txlen;
}
#else
char txbuff[SML_SRCBSIZE];
uint32_t txlen = 0, tx_entries = 1; uint32_t txlen = 0, tx_entries = 1;
for (uint32_t cnt = 0; cnt < sizeof(txbuff); cnt++) { for (uint32_t cnt = 0; cnt < sizeof(txbuff); cnt++) {
if (*lp == SCRIPT_EOL) { if (*lp == SCRIPT_EOL && *(lp - 1) != ',' ) {
txbuff[cnt] = 0; txbuff[cnt] = 0;
txlen = cnt; txlen = cnt;
break; break;
@ -2424,6 +2475,7 @@ dddef_exit:
script_meter_desc[index].max_index = tx_entries; script_meter_desc[index].max_index = tx_entries;
sml_send_blocks++; sml_send_blocks++;
} }
#endif
} }
} }
if (*lp == SCRIPT_EOL) lp--; if (*lp == SCRIPT_EOL) lp--;