From 856843763599dea17938f1b819e2423e6ec6d7b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fredrik=20=C3=96hrstr=C3=B6m?= Date: Fri, 25 Sep 2020 22:27:34 +0200 Subject: [PATCH] Partially removed reopenafter. --- src/main.cc | 10 +--------- src/serial.cc | 30 +++--------------------------- src/serial.h | 5 ++--- src/testinternals.cc | 4 ++-- tests/config4/etc/wmbusmeters.conf | 1 - wmbusmeters.1 | 2 -- 6 files changed, 8 insertions(+), 44 deletions(-) diff --git a/src/main.cc b/src/main.cc index 2cde3dc..609ea50 100644 --- a/src/main.cc +++ b/src/main.cc @@ -217,10 +217,6 @@ shared_ptr createWMBusDeviceFrom(Detected *detected, Configuration *confi break; case DEVICE_RFMRX2: verbose("(rfmrx2) on %s\n", detected->device.file.c_str()); - if (config->reopenafter == 0) - { - manager->setReopenAfter(600); // Close and reopen the fd, because of some bug in the device. - } wmbus = openRawTTY(detected->device.file, 38400, manager, serial_override); break; case DEVICE_RTLWMBUS: @@ -727,10 +723,6 @@ void logStartInformation(Configuration *config) verbose("(config) wmbusmeters will exit after %d seconds\n", config->exitafter); } - if (config->reopenafter != 0) { - verbose("(config) wmbusmeters close/open the wmbus dongle fd after every %d seconds\n", config->reopenafter); - } - if (config->meterfiles) { verbose("(config) store meter files in: \"%s\"\n", config->meterfiles_dir.c_str()); } @@ -785,7 +777,7 @@ bool start(Configuration *config) logStartInformation(config); // Create the manager monitoring all filedescriptors and invoking callbacks. - serial_manager_ = createSerialCommunicationManager(config->exitafter, config->reopenafter); + serial_manager_ = createSerialCommunicationManager(config->exitafter, true); // If our software unexpectedly exits, then stop the manager, to try // to achive a nice shutdown. onExit(call(serial_manager_.get(),stop)); diff --git a/src/serial.cc b/src/serial.cc index 81e3899..0d1b5be 100644 --- a/src/serial.cc +++ b/src/serial.cc @@ -67,7 +67,7 @@ struct Timer struct SerialCommunicationManagerImp : public SerialCommunicationManager { - SerialCommunicationManagerImp(time_t exit_after_seconds, time_t reopen_after_seconds, bool start_event_loop); + SerialCommunicationManagerImp(time_t exit_after_seconds, bool start_event_loop); ~SerialCommunicationManagerImp(); shared_ptr createSerialDeviceTTY(string dev, int baud_rate); @@ -331,6 +331,7 @@ void SerialDeviceTTY::close() void SerialDeviceTTY::checkIfShouldReopen() { + assert(0); if (fd_ != -1 && reopen_after_ > 0) { time_t curr = time(NULL); @@ -354,19 +355,6 @@ void SerialDeviceTTY::checkIfShouldReopen() } } -/* -void SerialDeviceTTY::forceReopen() -{ - debug("(serialtty) forced reopen and reset!\n", diff); - ::flock(fd_, LOCK_UN); - ::close(fd_); - fd_ = openSerialTTY(device_.c_str(), baud_rate_); - if (fd_ == -1) - { - error("Could not re-open %s with %d baud N81\n", device_.c_str(), baud_rate_); - } -} -*/ bool SerialDeviceTTY::send(vector &data) { LOCK_WRITE_SERIAL(send); @@ -676,7 +664,6 @@ struct SerialDeviceSimulator : public SerialDeviceImp }; SerialCommunicationManagerImp::SerialCommunicationManagerImp(time_t exit_after_seconds, - time_t reopen_after_seconds, bool start_event_loop) { running_ = true; @@ -691,7 +678,7 @@ SerialCommunicationManagerImp::SerialCommunicationManagerImp(time_t exit_after_s wakeMeUpOnSigChld(getEventLoopThread()); start_time_ = time(NULL); exit_after_seconds_ = exit_after_seconds; - reopen_after_seconds_ = reopen_after_seconds; + reopen_after_seconds_ = 0; } shared_ptr SerialCommunicationManagerImp::createSerialDeviceTTY(string device, @@ -936,15 +923,6 @@ void *SerialCommunicationManagerImp::timerLoop() } executeTimerCallbacks(); - - { - LOCK_SERIAL_DEVICES(check_for_reopens); - - for (shared_ptr &sd : serial_devices_) - { - sd->checkIfShouldReopen(); - } - } } return NULL; } @@ -1070,11 +1048,9 @@ void *SerialCommunicationManagerImp::eventLoop() } shared_ptr createSerialCommunicationManager(time_t exit_after_seconds, - time_t reopen_after_seconds, bool start_event_loop) { return shared_ptr(new SerialCommunicationManagerImp(exit_after_seconds, - reopen_after_seconds, start_event_loop)); } diff --git a/src/serial.h b/src/serial.h index 0c637b4..ada2c97 100644 --- a/src/serial.h +++ b/src/serial.h @@ -106,8 +106,7 @@ struct SerialCommunicationManager virtual ~SerialCommunicationManager(); }; -shared_ptr createSerialCommunicationManager(time_t exit_after_seconds = 0, - time_t reopen_after_seconds = 0, - bool start_event_loop = true); +shared_ptr createSerialCommunicationManager(time_t exit_after_seconds, + bool start_event_loop); #endif diff --git a/src/testinternals.cc b/src/testinternals.cc index 5786925..34c22a7 100644 --- a/src/testinternals.cc +++ b/src/testinternals.cc @@ -215,7 +215,7 @@ int test_dvparser() int test_test() { - shared_ptr manager = createSerialCommunicationManager(0, 0, false); + shared_ptr manager = createSerialCommunicationManager(0, false); shared_ptr serial1 = manager->createSerialDeviceSimulator(); @@ -228,7 +228,7 @@ int test_test() int test_linkmodes() { LinkModeCalculationResult lmcr; - auto manager = createSerialCommunicationManager(0, 0, false); + auto manager = createSerialCommunicationManager(0, false); auto serial1 = manager->createSerialDeviceSimulator(); auto serial2 = manager->createSerialDeviceSimulator(); diff --git a/tests/config4/etc/wmbusmeters.conf b/tests/config4/etc/wmbusmeters.conf index 56a2fb3..2de847f 100644 --- a/tests/config4/etc/wmbusmeters.conf +++ b/tests/config4/etc/wmbusmeters.conf @@ -3,4 +3,3 @@ device=simulations/simulation_conversionsadded.txt logtelegrams=false format=json addconversions=GJ,L,F -reopenafter=1h \ No newline at end of file diff --git a/wmbusmeters.1 b/wmbusmeters.1 index 4e45993..6e6d415 100644 --- a/wmbusmeters.1 +++ b/wmbusmeters.1 @@ -65,8 +65,6 @@ mqtt_publish) sent to a REST API (eg curl) or store it in a database \fB\--oneshot\fR wait for an update from each meter, then quit -\fB\--reopenafter=\fR