diff --git a/lib/lib_div/ams/han_Parser.h b/lib/lib_div/ams/han_Parser.h index 2011de4cf..f90af40f2 100644 --- a/lib/lib_div/ams/han_Parser.h +++ b/lib/lib_div/ams/han_Parser.h @@ -6,7 +6,7 @@ #include "DataParsers.h" #include "DataParser.h" #include "Cosem.h" -#include "ntohll.h" +#include "ntohll_ams.h" #define BUF_SIZE_HAN (1280) diff --git a/lib/lib_div/ams/ntohll.cpp b/lib/lib_div/ams/ntohll_ams.cpp similarity index 54% rename from lib/lib_div/ams/ntohll.cpp rename to lib/lib_div/ams/ntohll_ams.cpp index 25732434d..207e3765c 100644 --- a/lib/lib_div/ams/ntohll.cpp +++ b/lib/lib_div/ams/ntohll_ams.cpp @@ -1,5 +1,5 @@ -#include "ntohll.h" +#include "ntohll_ams.h" -uint64_t ntohll(uint64_t x) { +uint64_t ntohll_ams(uint64_t x) { return (((uint64_t)ntohl((uint32_t)x)) << 32) + ntohl(x >> 32); } \ No newline at end of file diff --git a/lib/lib_div/ams/ntohll.h b/lib/lib_div/ams/ntohll_ams.h similarity index 67% rename from lib/lib_div/ams/ntohll.h rename to lib/lib_div/ams/ntohll_ams.h index 2bb1e5e09..03e30f77e 100644 --- a/lib/lib_div/ams/ntohll.h +++ b/lib/lib_div/ams/ntohll_ams.h @@ -3,6 +3,6 @@ #include "lwip/def.h" -uint64_t ntohll(uint64_t x); +uint64_t ntohll_ams(uint64_t x); #endif diff --git a/tasmota/tasmota_xsns_sensor/xsns_53_sml.ino b/tasmota/tasmota_xsns_sensor/xsns_53_sml.ino index 96e555900..9e677380f 100755 --- a/tasmota/tasmota_xsns_sensor/xsns_53_sml.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_53_sml.ino @@ -113,6 +113,15 @@ #define USE_SML_MEDIAN_FILTER #endif +// on ESP32 binary SML CRC check compile enabled by default +// adds 17936 bytes due to large crc tables +#ifdef ESP32 +#ifndef NO_USE_SML_CRC +#undef USE_SML_CRC +#define USE_SML_CRC +#endif +#endif + #ifdef USE_SML_DECRYPT #include "han_Parser.h" @@ -248,8 +257,8 @@ private: HardwareSerial *hws; }; - -void IRAM_ATTR sml_callRxRead(void *self) { ((SML_ESP32_SERIAL*)self)->rxRead(); }; +void IRAM_ATTR sml_callRxRead(void *self); +void sml_callRxRead(void *self) { ((SML_ESP32_SERIAL*)self)->rxRead(); }; SML_ESP32_SERIAL::SML_ESP32_SERIAL(uint32_t index) { uart_index = index; @@ -373,7 +382,7 @@ void SML_ESP32_SERIAL::updateBaudRate(uint32_t baud) { } // no wait mode only 8N1 (or 7X1, obis only, ignoring parity) -void IRAM_ATTR SML_ESP32_SERIAL::rxRead(void) { +void SML_ESP32_SERIAL::rxRead(void) { uint32_t diff; uint32_t level; @@ -1722,6 +1731,10 @@ void sml_shift_in(uint32_t meters, uint32_t shard) { if (mp->spos == 6 + tlen) { mp->spos = 0; memmove(&mp->sbuff[0], &mp->sbuff[6], mp->sbsiz - 6); +#ifdef MODBUS_DEBUG + AddLog(LOG_LEVEL_INFO, PSTR("meter %d, receive index >> %d"), meters, mp->index); + Hexdump(mp->sbuff, 10); +#endif SML_Decode(meters); if (mp->client) { mp->client->flush(); @@ -1737,7 +1750,7 @@ void sml_shift_in(uint32_t meters, uint32_t shard) { if (mlen > mp->sbsiz) mlen = mp->sbsiz; if (mp->spos >= mlen) { #ifdef MODBUS_DEBUG - AddLog(LOG_LEVEL_INFO, PSTR("receive index >> %d"), mp->index); + AddLog(LOG_LEVEL_INFO, PSTR("meter %d, receive index >> %d"), meters, mp->index); Hexdump(mp->sbuff, 10); #endif SML_Decode(meters); @@ -1917,11 +1930,11 @@ double sml_get_obis_value(uint8_t *data) { break; } case CosemTypeLong64Signed: { - out = ntohll(item->l64s.data); + out = ntohll_ams(item->l64s.data); break; } case CosemTypeLong64Unsigned: { - out = ntohll(item->l64u.data); + out = ntohll_ams(item->l64u.data); break; } } @@ -2317,6 +2330,13 @@ void SML_Decode(uint8_t index) { mbus_dval = *fp; mp += 8; cp += 4; + } else if (!strncmp_P(mp, PSTR("FFFFFFFF"), 8)) { + uint32_t val = (cp[0]<<0) | (cp[1]<<0) | (cp[2]<<16) | (cp[3]<<24); + float *fp = (float*)&val; + ebus_dval = *fp; + mbus_dval = *fp; + mp += 8; + cp += 4; } else if (!strncmp_P(mp, PSTR("FFffFFff"), 8)) { // reverse word float uint32_t val = (cp[1]<<0) | (cp[0]<<8) | (cp[3]<<16) | (cp[2]<<24); @@ -4662,7 +4682,7 @@ void SML_Send_Seq(uint32_t meter, char *seq) { #ifdef MODBUS_DEBUG uint8_t type = mp->type; if (!sml_globs.dump2log && (type == 'm' || type == 'M' || type == 'k')) { - AddLog(LOG_LEVEL_INFO, PSTR("transmit index >> %d"),sml_globs.mp[meter].index); + AddLog(LOG_LEVEL_INFO, PSTR("meter %d, transmit index >> %d"), meter, sml_globs.mp[meter].index); Hexdump(sbuff, slen); } #endif