diff --git a/src/meter_em24.cc b/src/meter_em24.cc index ae9bd4f..55f2af3 100644 --- a/src/meter_em24.cc +++ b/src/meter_em24.cc @@ -39,7 +39,7 @@ constexpr uint8_t ERROR_CODE_FREQUENCY_OUT_OF_RANGE=0x40; struct MeterEM24 : public virtual ElectricityMeter, public virtual MeterCommonImplementation { - MeterEM24(WMBus *bus, MeterInfo &mi); + MeterEM24(MeterInfo &mi); double totalEnergyConsumption(Unit u); double totalEnergyProduction(Unit u); @@ -64,13 +64,13 @@ private: uint8_t error_codes_ {}; }; -unique_ptr createEM24(WMBus *bus, MeterInfo &mi) +shared_ptr createEM24(MeterInfo &mi) { - return unique_ptr(new MeterEM24(bus, mi)); + return shared_ptr(new MeterEM24(mi)); } -MeterEM24::MeterEM24(WMBus *bus, MeterInfo &mi) : - MeterCommonImplementation(bus, mi, MeterType::EM24) +MeterEM24::MeterEM24(MeterInfo &mi) : + MeterCommonImplementation(mi, MeterType::EM24) { setExpectedELLSecurityMode(ELLSecurityMode::AES_CTR); @@ -173,7 +173,7 @@ void MeterEM24::processContent(Telegram *t) // 75 vife (Cold / Warm Temperature Limit 10^-2 Celsius) extractDVdouble(&t->values, "04FB8275", &offset, &total_reactive_energy_consumption_kvarh_); t->addMoreExplanation(offset, " total reactive power (%f kvarh)", total_reactive_energy_consumption_kvarh_); - + // 04 dif (32 Bit Integer/Binary Instantaneous value) // 85 vif (Energy 10² Wh) // 3C vife (backward flow) @@ -187,7 +187,7 @@ void MeterEM24::processContent(Telegram *t) // 3C vife (Reserved) extractDVdouble(&t->values, "04FB82F53C", &offset, &total_reactive_energy_production_kvarh_); t->addMoreExplanation(offset, " total reactive power (%f kvarh)", total_reactive_energy_production_kvarh_); - + // 01 dif (8 Bit Integer/Binary Instantaneous value) // FD vif (Second extension of VIF-codes) // 17 vife (Error flags (binary)) diff --git a/src/serial.cc b/src/serial.cc index abc5d47..de821e3 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -149,6 +149,7 @@ struct SerialDeviceImp : public SerialDevice void fill(vector &data) {}; int receive(vector *data); bool working() { return fd_ != -1; } + bool opened() { return fd_ != -2; } bool readonly() { return is_stdin_ || is_file_; } void expectAscii() { expecting_ascii_ = true; } @@ -174,7 +175,7 @@ protected: function on_data_; function on_disappear_; - int fd_ = -1; + int fd_ = -2; // -2 not yet opened, -1 not working bool expecting_ascii_ {}; // If true, print using safeString instead if bin2hex bool is_file_ = false; bool is_stdin_ = false; diff --git a/src/serial.h b/src/serial.h index 7fcc2ee..6d739b9 100644 --- a/src/serial.h +++ b/src/serial.h @@ -44,6 +44,7 @@ struct SerialDevice // Receive returns the number of bytes received. virtual int receive(std::vector *data) = 0; virtual int fd() = 0; + virtual bool opened() = 0; virtual bool working() = 0; // Used when connecting stdin to a tty driver for testing. virtual bool readonly() = 0; diff --git a/src/wmbus.cc b/src/wmbus.cc index 493fea6..5c1e057 100644 --- a/src/wmbus.cc +++ b/src/wmbus.cc @@ -3345,7 +3345,7 @@ bool WMBusCommonImplementation::reset() bool resetting = false; if (serial()) { - if (serial()->working()) + if (serial()->opened() && serial()->working()) { // This is a reset, not an init. Close the serial device. resetting = true;