powermeter refactor: SML lib: replace double by float
avoid additional conversions and avoid double for the fact that calculations on type double are implemented in software, whereas float is handled in hardware on ESP32.
This commit is contained in:
parent
6108d24795
commit
75c07c17f2
@ -27,7 +27,7 @@ private:
|
||||
|
||||
typedef struct {
|
||||
uint8_t const OBIS[6];
|
||||
void (*decoder)(double&);
|
||||
void (*decoder)(float&);
|
||||
float* target;
|
||||
char const* name;
|
||||
} OBISHandler;
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<std::mutex> l(_mutex);
|
||||
*handler.target = helper;
|
||||
gotUpdate();
|
||||
|
||||
if (!_verboseLogging) { continue; }
|
||||
MessageOutput.printf("[PowerMeterSml] decoded %s to %.2f\r\n",
|
||||
handler.name, helper);
|
||||
std::lock_guard<std::mutex> l(_mutex);
|
||||
handler.decoder(*handler.target);
|
||||
|
||||
if (_verboseLogging) {
|
||||
MessageOutput.printf("[PowerMeterSml] decoded %s to %.2f\r\n",
|
||||
handler.name, *handler.target);
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user