diff --git a/include/PowerMeterSml.h b/include/PowerMeterSml.h index e006f69f..fa6a3215 100644 --- a/include/PowerMeterSml.h +++ b/include/PowerMeterSml.h @@ -27,7 +27,7 @@ private: typedef struct { uint8_t const OBIS[6]; - void (*decoder)(double&); + void (*decoder)(float&); float* target; char const* name; } OBISHandler; diff --git a/lib/SMLParser/sml.cpp b/lib/SMLParser/sml.cpp index 7a378f63..f1892594 100644 --- a/lib/SMLParser/sml.cpp +++ b/lib/SMLParser/sml.cpp @@ -317,7 +317,7 @@ void smlOBISManufacturer(unsigned char *str, int maxSize) } } -void smlPow(double &val, signed char &scaler) +void smlPow(float &val, signed char &scaler) { if (scaler < 0) { while (scaler++) { @@ -372,7 +372,7 @@ void smlOBISByUnit(long long int &val, signed char &scaler, sml_units_t unit) } } -void smlOBISWh(double &wh) +void smlOBISWh(float &wh) { long long int val; smlOBISByUnit(val, sc, SML_WATT_HOUR); @@ -380,7 +380,7 @@ void smlOBISWh(double &wh) smlPow(wh, sc); } -void smlOBISW(double &w) +void smlOBISW(float &w) { long long int val; smlOBISByUnit(val, sc, SML_WATT); @@ -388,7 +388,7 @@ void smlOBISW(double &w) smlPow(w, sc); } -void smlOBISVolt(double &v) +void smlOBISVolt(float &v) { long long int val; smlOBISByUnit(val, sc, SML_VOLT); @@ -396,7 +396,7 @@ void smlOBISVolt(double &v) smlPow(v, sc); } -void smlOBISAmpere(double &a) +void smlOBISAmpere(float &a) { long long int val; smlOBISByUnit(val, sc, SML_AMPERE); diff --git a/lib/SMLParser/sml.h b/lib/SMLParser/sml.h index ac6405df..b837adda 100644 --- a/lib/SMLParser/sml.h +++ b/lib/SMLParser/sml.h @@ -97,10 +97,9 @@ bool smlOBISCheck(const unsigned char *obis); void smlOBISManufacturer(unsigned char *str, int maxSize); void smlOBISByUnit(long long int &wh, signed char &scaler, sml_units_t unit); -// Be aware that double on Arduino UNO is just 32 bit -void smlOBISWh(double &wh); -void smlOBISW(double &w); -void smlOBISVolt(double &v); -void smlOBISAmpere(double &a); +void smlOBISWh(float &wh); +void smlOBISW(float &w); +void smlOBISVolt(float &v); +void smlOBISAmpere(float &a); #endif diff --git a/src/PowerMeterSml.cpp b/src/PowerMeterSml.cpp index f3d619b8..0c2f6893 100644 --- a/src/PowerMeterSml.cpp +++ b/src/PowerMeterSml.cpp @@ -22,16 +22,15 @@ void PowerMeterSml::processSmlByte(uint8_t byte) for (auto& handler: smlHandlerList) { if (!smlOBISCheck(handler.OBIS)) { continue; } - double helper; - handler.decoder(helper); - - std::lock_guard l(_mutex); - *handler.target = helper; gotUpdate(); - if (!_verboseLogging) { continue; } - MessageOutput.printf("[PowerMeterSml] decoded %s to %.2f\r\n", - handler.name, helper); + std::lock_guard l(_mutex); + handler.decoder(*handler.target); + + if (_verboseLogging) { + MessageOutput.printf("[PowerMeterSml] decoded %s to %.2f\r\n", + handler.name, *handler.target); + } } break; default: