kopia lustrzana https://github.com/weetmuts/wmbusmeters
Detection loop is working.
rodzic
b1fce2769a
commit
1653aea0b2
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
|||
# Copyright (C) 2017-2019 Fredrik Öhrström
|
||||
# Copyright (C) 2017-2020 Fredrik Öhrström
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
|
10
src/main.cc
10
src/main.cc
|
@ -266,7 +266,7 @@ unique_ptr<WMBus> createWMBusDeviceFrom(Detected *detected, Configuration *confi
|
|||
break;
|
||||
}
|
||||
case DEVICE_UNKNOWN:
|
||||
warning("No wmbus device found! Exiting!\n");
|
||||
verbose("(main) internal error! cannot create an unknown device! exiting!\n");
|
||||
if (config->daemon) {
|
||||
// If starting as a daemon, wait a bit so that systemd have time to catch up.
|
||||
sleep(1);
|
||||
|
@ -408,7 +408,7 @@ void detectAndConfigureWMBusDevices(Configuration *config, SerialCommunicationMa
|
|||
{
|
||||
if (!printed_warning_)
|
||||
{
|
||||
info("(main) no wmbus devices detected.\n");
|
||||
info("(main) no wmbus device detected, waiting for a device to be plugged in.\n");
|
||||
printed_warning_ = true;
|
||||
}
|
||||
}
|
||||
|
@ -522,11 +522,11 @@ bool start(Configuration *config)
|
|||
|
||||
if (devices_.size() == 0)
|
||||
{
|
||||
info("(main) no wmbus devices detected.\n");
|
||||
info("(main) no wmbus device detected, waiting for a device to be plugged in.\n");
|
||||
}
|
||||
|
||||
// Every 2 seconds, perform the exact same call again and again.
|
||||
manager_->startRegularCallback("device_detector",
|
||||
// Every 2 seconds detect any plugged in or removed wmbus devices.
|
||||
manager_->startRegularCallback("HOT_PLUG_DETECTOR",
|
||||
2,
|
||||
[&](){
|
||||
detectAndConfigureWMBusDevices(config, manager_.get(), &devices_);
|
||||
|
|
|
@ -77,6 +77,7 @@ struct SerialCommunicationManagerImp : public SerialCommunicationManager
|
|||
|
||||
void listenTo(SerialDevice *sd, function<void()> cb);
|
||||
void onDisappear(SerialDevice *sd, function<void()> cb);
|
||||
void expectDevicesToWork();
|
||||
void stop();
|
||||
void startEventLoop();
|
||||
void waitForStop();
|
||||
|
@ -711,6 +712,12 @@ void SerialCommunicationManagerImp::onDisappear(SerialDevice *sd, function<void(
|
|||
si->on_disappear_ = cb;
|
||||
}
|
||||
|
||||
void SerialCommunicationManagerImp::expectDevicesToWork()
|
||||
{
|
||||
debug("(serial) expecting devices to work\n");
|
||||
expect_devices_to_work_ = true;
|
||||
}
|
||||
|
||||
void SerialCommunicationManagerImp::stop()
|
||||
{
|
||||
// Notify the main waitForStop thread that we are stopped!
|
||||
|
|
|
@ -78,6 +78,10 @@ struct SerialCommunicationManager
|
|||
virtual void listenTo(SerialDevice *sd, function<void()> cb) = 0;
|
||||
// Invoke cb callback when the serial device has disappeared!
|
||||
virtual void onDisappear(SerialDevice *sd, function<void()> cb) = 0;
|
||||
// Normally the communication mananager runs for ever.
|
||||
// But if you expect configured devices to work, then
|
||||
// the manager will exit when there are no working devices.
|
||||
virtual void expectDevicesToWork() = 0;
|
||||
virtual void stop() = 0;
|
||||
virtual void startEventLoop() = 0;
|
||||
virtual void waitForStop() = 0;
|
||||
|
|
|
@ -3342,7 +3342,8 @@ bool Telegram::findFormatBytesFromKnownMeterSignatures(vector<uchar> *format_byt
|
|||
|
||||
WMBusCommonImplementation::~WMBusCommonImplementation()
|
||||
{
|
||||
info("(wmbus) deleted %s\n", toString(type()));
|
||||
manager_->stopRegularCallback(regular_cb_id_);
|
||||
debug("(wmbus) deleted %s\n", toString(type()));
|
||||
}
|
||||
|
||||
WMBusCommonImplementation::WMBusCommonImplementation(WMBusDeviceType t,
|
||||
|
@ -3358,7 +3359,8 @@ WMBusCommonImplementation::WMBusCommonImplementation(WMBusDeviceType t,
|
|||
|
||||
// Invoke the check status once per minute. Unless internal testing, then it is every 2 seconds.
|
||||
int default_timer = isInternalTestingEnabled() ? CHECKSTATUS_TIMER_INTERNAL_TESTING : CHECKSTATUS_TIMER;
|
||||
manager_->startRegularCallback(toString(t), default_timer, call(this,checkStatus));
|
||||
string alarm_id = "CHECK_STATUS "+string(toString(t))+":"+serial_->device();
|
||||
regular_cb_id_ = manager_->startRegularCallback(alarm_id, default_timer, call(this,checkStatus));
|
||||
}
|
||||
|
||||
WMBusDeviceType WMBusCommonImplementation::type()
|
||||
|
|
|
@ -97,7 +97,7 @@ unique_ptr<WMBus> openIM871A(string device, SerialCommunicationManager *manager,
|
|||
}
|
||||
|
||||
WMBusIM871A::WMBusIM871A(unique_ptr<SerialDevice> serial, SerialCommunicationManager *manager) :
|
||||
WMBusCommonImplementation(DEVICE_IM871A, manager,std::move(serial))
|
||||
WMBusCommonImplementation(DEVICE_IM871A, manager, std::move(serial))
|
||||
{
|
||||
sem_init(&command_wait_, 0, 0);
|
||||
manager_->listenTo(this->serial(),call(this,processSerialData));
|
||||
|
|
|
@ -71,6 +71,8 @@ struct WMBusCommonImplementation : public virtual WMBus
|
|||
bool link_modes_configured_ {};
|
||||
LinkModeSet link_modes_ {};
|
||||
|
||||
int regular_cb_id_;
|
||||
|
||||
unique_ptr<SerialDevice> serial_;
|
||||
};
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue