From 0d830bad59c0d2d9d105c0ac3a2cec616aebef17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Sun, 8 Aug 2021 23:07:34 +0200 Subject: [PATCH] Fix bug that caused crash when dongle was reset. --- Makefile | 4 ++-- src/serial.cc | 8 ++++++-- src/serial.h | 1 + src/util.cc | 2 +- src/wmbus_amb8465.cc | 12 +++++++++++- 5 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index fc4b23f..216ea97 100644 --- a/Makefile +++ b/Makefile @@ -47,8 +47,8 @@ ifeq "$(DEBUG)" "true" GCOV?=gcov endif else - DEBUG_FLAGS=-Os - STRIP_BINARY=$(STRIP) $(BUILD)/wmbusmeters + DEBUG_FLAGS=-Os -g + STRIP_BINARY=echo FOO GCOV=To_run_gcov_add_DEBUG=true endif diff --git a/src/serial.cc b/src/serial.cc index c57d293..adbead7 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -146,6 +146,7 @@ struct SerialDeviceImp : public SerialDevice int receive(vector *data); bool waitFor(uchar c); bool working() { return resetting_ || fd_ != -1; } + bool resetting() { return resetting_; } bool opened() { return resetting_ || fd_ != -2; } bool isClosed() { return fd_ == -1 && !resetting_; } bool readonly() { return is_stdin_ || is_file_; } @@ -958,8 +959,11 @@ void *SerialCommunicationManagerImp::eventLoop() { if (sd->opened() && sd->working() && !sd->skippingCallbacks()) { - trace("[SERIAL] select read on fd %d\n", sd->fd()); - FD_SET(sd->fd(), &readfds); + if (!sd->resetting() && sd->fd() >= 0) + { + trace("[SERIAL] select read on fd %d\n", sd->fd()); + FD_SET(sd->fd(), &readfds); + } } if (sd->opened() && !sd->working()) all_working = false; } diff --git a/src/serial.h b/src/serial.h index ba66172..cd5c7da 100644 --- a/src/serial.h +++ b/src/serial.h @@ -53,6 +53,7 @@ struct SerialDevice virtual int fd() = 0; virtual bool opened() = 0; virtual bool working() = 0; + virtual bool resetting() = 0; // The serial device is working but can lack a valid file descriptor. // Used when connecting stdin to a tty driver for testing. virtual bool readonly() = 0; // Mark this device so that it is ignored by the select/callback event loop. diff --git a/src/util.cc b/src/util.cc index a26c80c..1dd35e6 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1952,5 +1952,5 @@ size_t findBytes(vector &v, uchar a, uchar b, uchar c) } p++; } - return 0; + return (size_t)-1; } diff --git a/src/wmbus_amb8465.cc b/src/wmbus_amb8465.cc index c1e964f..795d6c4 100644 --- a/src/wmbus_amb8465.cc +++ b/src/wmbus_amb8465.cc @@ -55,6 +55,11 @@ struct ConfigAMB8465 return ids; } + bool enoughBytes(vector &bytes, size_t offset) + { + return false; + } + bool decode(vector &bytes) { size_t o = 5; @@ -612,6 +617,11 @@ AccessCheck detectAMB8465(Detected *detected, shared_ptrclose(); @@ -620,7 +630,7 @@ AccessCheck detectAMB8465(Detected *detected, shared_ptr 0) + while (skip > 0 && skip != ((size_t)-1)) { // Sometimes there seems to be a leading 00 noise byte. Skip those. response.erase(response.begin());