Make a distinction between not yet opened and not working serial devices.

pull/156/head
Fredrik Öhrström 2020-09-25 16:38:40 +02:00
rodzic ecd60045d9
commit 0d9d856b6a
4 zmienionych plików z 11 dodań i 9 usunięć

Wyświetl plik

@ -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<ElectricityMeter> createEM24(WMBus *bus, MeterInfo &mi)
shared_ptr<ElectricityMeter> createEM24(MeterInfo &mi)
{
return unique_ptr<ElectricityMeter>(new MeterEM24(bus, mi));
return shared_ptr<ElectricityMeter>(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);

Wyświetl plik

@ -149,6 +149,7 @@ struct SerialDeviceImp : public SerialDevice
void fill(vector<uchar> &data) {};
int receive(vector<uchar> *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<void()> on_data_;
function<void()> 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;

Wyświetl plik

@ -44,6 +44,7 @@ struct SerialDevice
// Receive returns the number of bytes received.
virtual int receive(std::vector<uchar> *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;

Wyświetl plik

@ -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;