6 #include <Poco/Mutex.h>
7 #include <Poco/Thread.h>
8 #include <Poco/Timespan.h>
11 #include "bluetooth/BLESmartDevice.h"
12 #include "bluetooth/HciInterface.h"
13 #include "commands/DeviceAcceptCommand.h"
14 #include "commands/DeviceSetValueCommand.h"
15 #include "core/AbstractSeeker.h"
16 #include "core/DongleDeviceManager.h"
17 #include "core/PollingKeeper.h"
18 #include "loop/StopControl.h"
19 #include "model/DeviceID.h"
20 #include "model/RefreshTime.h"
21 #include "net/MACAddress.h"
22 #include "util/AsyncWork.h"
33 static const Poco::UUID CHAR_MODEL_NUMBER;
41 typedef Poco::SharedPtr<BLESmartSeeker> Ptr;
75 void setDevicePoller(DevicePoller::Ptr poller);
76 void setScanTimeout(
const Poco::Timespan &timeout);
77 void setDeviceTimeout(
const Poco::Timespan &timeout);
78 void setRefresh(
const Poco::Timespan &refresh);
79 void setNumberOfExaminationThreads(
const int numberOfExaminationThreads);
80 void setHciManager(HciInterfaceManager::Ptr manager);
87 void handleAccept(
const DeviceAcceptCommand::Ptr cmd)
override;
91 const Poco::Timespan &timeout)
override;
96 const Poco::Timespan &timeout)
override;
109 std::vector<unsigned char> &data);
127 std::vector<BLESmartDevice::Ptr>& foundDevices,
136 const std::map<MACAddress, std::string>& devices,
137 Poco::FastMutex& foundDevicesMutex,
138 std::vector<BLESmartDevice::Ptr>& foundDevices,
147 const std::map<MACAddress, std::string>& devices,
148 Poco::FastMutex& foundDevicesMutex,
149 std::vector<BLESmartDevice::Ptr>& foundDevices,
157 void processNewDevice(BLESmartDevice::Ptr newDevice);
160 Poco::FastMutex m_devicesMutex;
161 std::map<DeviceID, BLESmartDevice::Ptr> m_devices;
162 Poco::SharedPtr<HciInterface::WatchCallback> m_watchCallback;
165 Poco::Timespan m_scanTimeout;
166 Poco::Timespan m_deviceTimeout;
168 uint32_t m_numberOfExaminationThreads;
169 HciInterfaceManager::Ptr m_hciManager;
170 HciInterface::Ptr m_hci;
void threadedExaminationOfDevices(const std::map< MACAddress, std::string > &devices, Poco::FastMutex &foundDevicesMutex, std::vector< BLESmartDevice::Ptr > &foundDevices, const StopControl &stop)
Splits the map of devices into smaller maps whose number is determined by the attribute m_numberOfExa...
Definition: BLESmartDeviceManager.cpp:352
BLESmartDevice::Ptr createDevice(const MACAddress &address) const
Creates BLE device based on its Model ID.
Definition: BLESmartDeviceManager.cpp:421
AsyncWork< double >::Ptr startSetValue(const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) override
Starts set-value operation in a technology specific way. The method is always called inside a critica...
Definition: BLESmartDeviceManager.cpp:214
Definition: FailDetector.h:8
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
void eraseAllDevices()
Clears m_devices.
Definition: BLESmartDeviceManager.cpp:158
void processAsyncData(const MACAddress &address, std::vector< unsigned char > &data)
Processes the asynchronous data of the paired device. If the message is correct it is already shipped...
Definition: BLESmartDeviceManager.cpp:239
void dongleAvailable() override
Definition: BLESmartDeviceManager.cpp:104
void notifyDongleRemoved() override
Wakes up the main thread.
Definition: BLESmartDeviceManager.cpp:130
PollingKeeper takes care of devices that are being polled. It cancels all polled devices it manages u...
Definition: PollingKeeper.h:17
Provides searching BLE devices on network in own thread.
Definition: BLESmartDeviceManager.h:39
void seekDevices(std::vector< BLESmartDevice::Ptr > &foundDevices, const StopControl &stop)
Seeks for new devices on Bluetooth LE network.
Definition: BLESmartDeviceManager.cpp:311
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
AbstractSeeker represents an asynchronous process that seeks for new devices in a certain network...
Definition: AbstractSeeker.h:25
Definition: MACAddress.h:8
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: BLESmartDeviceManager.cpp:165
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: BLESmartDeviceManager.cpp:199
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
Definition: ModuleID.h:12
Poco::Timespan duration() const
Definition: AbstractSeeker.cpp:17
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: BLESmartDeviceManager.cpp:172
std::string dongleMatch(const HotplugEvent &e) override
Recognizes compatible dongle by testing HotplugEvent property as bluetooth.BEEEON_DONGLE == bluetooth...
Definition: BLESmartDeviceManager.cpp:135
Definition: HotplugEvent.h:10
void stop() override
Definition: BLESmartDeviceManager.cpp:146
Definition: DongleDeviceManager.h:14
The class implements the work with Bluetooth Low Energy devices. Allows us to process and execute the...
Definition: BLESmartDeviceManager.h:31
bool dongleMissing() override
Erases all instances of the device.
Definition: BLESmartDeviceManager.cpp:152
void dongleFailed(const FailDetector &dongleStatus) override
Erases all instances of the device.
Definition: BLESmartDeviceManager.cpp:140
void seekPairedDevices()
Tries to find not found paired devices. Each found device is added to parametr devices and attribute ...
Definition: BLESmartDeviceManager.cpp:264
Definition: DeviceID.h:17
void examineBatchOfDevices(const std::map< MACAddress, std::string > &devices, Poco::FastMutex &foundDevicesMutex, std::vector< BLESmartDevice::Ptr > &foundDevices, const StopControl &stop)
Finds out if the given devices are supported. In the positive case, a specific instance of the device...
Definition: BLESmartDeviceManager.cpp:390