BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
IQRFDeviceManager.h
1 #pragma once
2 
3 #include <set>
4 #include <string>
5 
6 #include <Poco/AtomicCounter.h>
7 #include <Poco/SharedPtr.h>
8 #include <Poco/Util/Timer.h>
9 
10 #include "core/DongleDeviceManager.h"
11 #include "core/PollingKeeper.h"
12 #include "commands/DeviceAcceptCommand.h"
13 #include "commands/DeviceUnpairCommand.h"
14 #include "commands/GatewayListenCommand.h"
15 #include "iqrf/DPAMessage.h"
16 #include "iqrf/DPAProtocol.h"
17 #include "iqrf/IQRFDevice.h"
18 #include "iqrf/IQRFEventFirer.h"
19 #include "iqrf/IQRFListener.h"
20 #include "iqrf/IQRFMqttConnector.h"
21 #include "model/RefreshTime.h"
22 
23 namespace BeeeOn {
24 
33 public:
35 
39  void registerDPAProtocol(DPAProtocol::Ptr protocol);
40 
44  void setReceiveTimeout(const Poco::Timespan &timeout);
45 
50  void setRefreshTime(const Poco::Timespan &refresh);
51 
56  void setRefreshTimePeripheralInfo(const Poco::Timespan &refresh);
57 
62  void setIQRFDevicesRetryTimeout(const Poco::Timespan &timeout);
63 
68  void setCoordinatorReset(const std::string & reset);
69 
70  void setMqttConnector(IQRFMqttConnector::Ptr connector);
71  void setDevicePoller(DevicePoller::Ptr poller);
72 
73  void setEventsExecutor(AsyncExecutor::Ptr executor);
74  void registerListener(IQRFListener::Ptr listener);
75 
80  std::string dongleMatch(const HotplugEvent &e) override;
81  void dongleAvailable() override;
82  void stop() override;
83 
84 protected:
85  void handleAccept(const DeviceAcceptCommand::Ptr cmd) override;
86  AsyncWork<>::Ptr startDiscovery(const Poco::Timespan &timeout) override;
88  const DeviceID &id,
89  const Poco::Timespan &timeout) override;
90 
95  void notifyDongleRemoved() override;
96  void dongleFailed(const FailDetector &dongleStatus);
97 
98  void eraseAllDevices();
99 
100 
101 private:
105  std::set<uint8_t> obtainBondedNodes(const Poco::Timespan &methodTimeout);
106  std::set<uint8_t> obtainNonSynchronizedNodes(
107  const std::set<uint8_t> &bondedNodes);
108 
114  void syncBondedNodes(const Poco::Timespan &methodTimeout);
115 
120  std::string supportedProtocolsToString() const;
121 
125  void newDevice(IQRFDevice::Ptr dev);
126 
134  DPAProtocol::Ptr detectNodeProtocol(
135  DPAMessage::NetworkAddress node,
136  const Poco::Timespan &maxMethodTimeout);
137 
152  std::map<DeviceID, IQRFDevice::Ptr> obtainDeviceInfo(
153  const Poco::Timespan &methodTimeout,
154  const std::set<uint8_t> &nodes);
155 
162  IQRFDevice::Ptr tryObtainDeviceInfo(
163  DPAMessage::NetworkAddress node,
164  const Poco::Timespan &methodTimeout);
165 
173  IQRFDevice::Ptr bondNewDevice(
174  const Poco::Timespan &timeout);
175 
180  void coordinatorResetProcess();
181 
182 private:
183  Poco::FastMutex m_lock;
184  std::vector<DPAProtocol::Ptr> m_dpaProtocols;
185  std::map<DeviceID, IQRFDevice::Ptr> m_devices;
186  PollingKeeper m_pollingKeeper;
187 
188  IQRFMqttConnector::Ptr m_connector;
189  RefreshTime m_refreshTime;
190  RefreshTime m_refreshTimePeripheralInfo;
191  bool m_coordinatorReset;
192  Poco::Timespan m_receiveTimeout;
193  Poco::Timespan m_devicesRetryTimeout;
194  Poco::AtomicCounter m_bondingMode;
195 
196  IQRFEventFirer m_eventFirer;
197 };
198 
199 }
void registerDPAProtocol(DPAProtocol::Ptr protocol)
Registration of supported protocols.
Definition: IQRFDeviceManager.cpp:71
Definition: FailDetector.h:8
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
AsyncWork::Ptr startDiscovery(const Poco::Timespan &timeout) override
Starts device discovery process in a technology-specific way. This method is always called inside a c...
Definition: IQRFDeviceManager.cpp:467
void dongleFailed(const FailDetector &dongleStatus)
Definition: IQRFDeviceManager.cpp:649
Definition: IQRFEventFirer.h:19
void handleAccept(const DeviceAcceptCommand::Ptr cmd) override
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we ne...
Definition: IQRFDeviceManager.cpp:419
void setRefreshTimePeripheralInfo(const Poco::Timespan &refresh)
Refresh time between obtaining peripheral info (battery, RSSI) from IQRF devices. ...
Definition: IQRFDeviceManager.cpp:98
PollingKeeper takes care of devices that are being polled. It cancels all polled devices it manages u...
Definition: PollingKeeper.h:17
std::string dongleMatch(const HotplugEvent &e) override
Recognizes compatible dongle by testing HotplugEvent property as iqrf.BEEEON_DONGLE = iqrf...
Definition: IQRFDeviceManager.cpp:150
AsyncWork is an interface allowing to wait until an asynchronous operation finishes. It is also possible to force-stop it by calling cancel().
Definition: AsyncWork.h:21
void setRefreshTime(const Poco::Timespan &refresh)
Refresh time between obtaining of measured values from IQRF devices.
Definition: IQRFDeviceManager.cpp:87
IQRFDeviceManager implements work with IQRF devices. IQRF Daemon (third party application) is used fo...
Definition: IQRFDeviceManager.h:32
void stop() override
Definition: IQRFDeviceManager.cpp:144
AsyncWork< std::set< DeviceID > >::Ptr startUnpair(const DeviceID &id, const Poco::Timespan &timeout) override
Starts device unpair process in a technology-specific way. This method is always called inside a crit...
Definition: IQRFDeviceManager.cpp:501
Definition: HotplugEvent.h:10
void setCoordinatorReset(const std::string &reset)
If this parameter is set to true (bool value in decimal or string notation), coordinator is reset...
Definition: IQRFDeviceManager.cpp:119
void notifyDongleRemoved() override
List of tasks is cleared for each device, that is in m_devices and each device is removed from the li...
Definition: IQRFDeviceManager.cpp:644
void dongleAvailable() override
Definition: IQRFDeviceManager.cpp:167
Definition: DongleDeviceManager.h:14
void setReceiveTimeout(const Poco::Timespan &timeout)
The time during which response should be received.
Definition: IQRFDeviceManager.cpp:76
void setIQRFDevicesRetryTimeout(const Poco::Timespan &timeout)
Sets the timeout of waiting for next attempt to communicate with IQRF devices. Timeout must be at lea...
Definition: IQRFDeviceManager.cpp:109
Definition: DeviceID.h:17