Skip to content

Commit

Permalink
Merge pull request #11184 from gemu2015/sml_update
Browse files Browse the repository at this point in the history
smp update
  • Loading branch information
arendst committed Mar 2, 2021
2 parents 4fb5554 + 56f922a commit 185c46e
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions tasmota/xsns_53_sml.ino
Original file line number Diff line number Diff line change
Expand Up @@ -822,8 +822,12 @@ uint8_t Serial_peek() {
return meter_ss[num-1]->peek();
}

uint8_t sml_logindex;
char log_data[128];
#ifndef SML_DUMP_SIZE
#define SML_DUMP_SIZE 128
#endif

uint16_t sml_logindex;
char log_data[SML_DUMP_SIZE];

#define SML_EBUS_SKIP_SYNC_DUMPS

Expand Down Expand Up @@ -884,8 +888,8 @@ void Dump2log(void) {
char c = SML_SREAD&0x7f;
if (c == '\n' || c == '\r') {
if (sml_logindex > 2) {
AddLogData(LOG_LEVEL_INFO, log_data);
log_data[sml_logindex] = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
log_data[0] = ':';
log_data[1] = ' ';
sml_logindex = 2;
Expand All @@ -903,6 +907,7 @@ void Dump2log(void) {
while (SML_SAVAILABLE) {
c = SML_SREAD;
if (c == VBUS_SYNC) {
log_data[sml_logindex] = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
log_data[0] = ':';
log_data[1] = ' ';
Expand All @@ -922,6 +927,7 @@ void Dump2log(void) {
p = SML_SPEAK;
if (p != EBUS_SYNC && sml_logindex > 5) {
// new packet, plot last one
log_data[sml_logindex] = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
strcpy(&log_data[0], ": aa ");
sml_logindex = 5;
Expand All @@ -939,6 +945,7 @@ void Dump2log(void) {
while (SML_SAVAILABLE) {
c = SML_SREAD;
if (c == SML_SYNC) {
log_data[sml_logindex] = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
log_data[0] = ':';
log_data[1] = ' ';
Expand All @@ -962,6 +969,7 @@ void Dump2log(void) {
}
}
if (sml_logindex > 2) {
log_data[sml_logindex] = 0;
AddLogData(LOG_LEVEL_INFO, log_data);
}
}
Expand Down Expand Up @@ -1472,6 +1480,7 @@ void SML_Decode(uint8_t index) {
double fac = CharToDouble((char*)mp);
meter_vars[vindex] /= fac;
SML_Immediate_MQTT((const char*)mp, vindex, mindex);
dvalid[vindex] = 1;
// get sfac
} else if (*mp=='d') {
// calc deltas d ind 10 (eg every 10 secs)
Expand All @@ -1489,7 +1498,16 @@ void SML_Decode(uint8_t index) {
dtimes[dindex] = millis();
double vdiff = meter_vars[ind - 1] - dvalues[dindex];
dvalues[dindex] = meter_vars[ind - 1];
meter_vars[vindex] = (double)360000.0 * vdiff / ((double)dtime / 10000.0);
double dres = (double)360000.0 * vdiff / ((double)dtime / 10000.0);
#ifdef USE_SML_MEDIAN_FILTER
if (meter_desc_p[mindex].flag & 16) {
meter_vars[vindex] = sml_median(&sml_mf[vindex], dres);
} else {
meter_vars[vindex] = dres;
}
#else
meter_vars[vindex] = dres;
#endif

mp=strchr(mp,'@');
if (mp) {
Expand All @@ -1499,6 +1517,7 @@ void SML_Decode(uint8_t index) {
SML_Immediate_MQTT((const char*)mp, vindex, mindex);
}
}
dvalid[vindex] = 1;
dindex++;
}
} else if (*mp == 'h') {
Expand Down Expand Up @@ -1731,6 +1750,7 @@ void SML_Decode(uint8_t index) {
}
if (found) {
// matches, get value
dvalid[vindex] = 1;
mp++;
#ifdef ED300L
g_mindex=mindex;
Expand Down Expand Up @@ -1838,7 +1858,6 @@ void SML_Decode(uint8_t index) {
SML_Immediate_MQTT((const char*)mp, vindex, mindex);
}
}
dvalid[vindex] = 1;
//AddLog(LOG_LEVEL_INFO, PSTR("set valid in line %d"), vindex);
}
nextsect:
Expand Down

0 comments on commit 185c46e

Please sign in to comment.