BeeeOn Gateway
v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
|
The class implements the work with Bluetooth Low Energy devices. Allows us to process and execute the commands from server and gather data from the devices. More...
#include <BLESmartDeviceManager.h>
Data Structures | |
class | BLESmartSeeker |
Provides searching BLE devices on network in own thread. More... | |
Public Member Functions | |
void | dongleAvailable () override |
std::string | dongleMatch (const HotplugEvent &e) override |
Recognizes compatible dongle by testing HotplugEvent property as bluetooth.BEEEON_DONGLE == bluetooth . | |
void | dongleFailed (const FailDetector &dongleStatus) override |
Erases all instances of the device. | |
bool | dongleMissing () override |
Erases all instances of the device. | |
void | stop () override |
void | setDevicePoller (DevicePoller::Ptr poller) |
void | setScanTimeout (const Poco::Timespan &timeout) |
void | setDeviceTimeout (const Poco::Timespan &timeout) |
void | setRefresh (const Poco::Timespan &refresh) |
void | setNumberOfExaminationThreads (const int numberOfExaminationThreads) |
void | setHciManager (HciInterfaceManager::Ptr manager) |
Public Member Functions inherited from BeeeOn::DongleDeviceManager | |
DongleDeviceManager (const DevicePrefix &prefix, const std::initializer_list< std::type_index > &acceptable={}) | |
void | run () override |
void | stop () override |
void | onAdd (const HotplugEvent &e) override |
void | onRemove (const HotplugEvent &e) override |
void | setAttemptsCount (const int count) |
void | setRetryTimeout (const Poco::Timespan &timeout) |
Public Member Functions inherited from BeeeOn::DeviceManager | |
DeviceManager (const DevicePrefix &prefix, const std::initializer_list< std::type_index > &acceptable={}) | |
DevicePrefix | prefix () const override |
void | setDeviceCache (DeviceCache::Ptr cache) |
void | setDistributor (Poco::SharedPtr< Distributor > distributor) |
bool | accept (const Command::Ptr cmd) override |
void | handle (Command::Ptr cmd, Answer::Ptr answer) override |
void | handleRemoteStatus (const DevicePrefix &prefix, const std::set< DeviceID > &devices, const DeviceStatusHandler::DeviceValues &values) override |
Called when devices from a remote server are fetched and so the pairing status of them can be reconsidered. The default implementation just updates the device cache appropriately. | |
Public Member Functions inherited from BeeeOn::CommandSender | |
void | setCommandDispatcher (CommandDispatcher *dispatcher) |
void | dispatch (Poco::AutoPtr< Command > cmd, Poco::AutoPtr< Answer > answer) |
void | dispatch (Poco::AutoPtr< Command > cmd) |
AnswerQueue & | answerQueue () |
Public Member Functions inherited from BeeeOn::HotplugListener | |
virtual void | onChange (const HotplugEvent &event) |
virtual void | onMove (const HotplugEvent &event) |
Static Public Attributes | |
static const Poco::UUID | CHAR_MODEL_NUMBER = UUID("00002a24-0000-1000-8000-00805f9b34fb") |
Protected Member Functions | |
void | notifyDongleRemoved () override |
Wakes up the main thread. | |
void | handleAccept (const DeviceAcceptCommand::Ptr cmd) override |
Generic handler of the DeviceAcceptCommand. It might be helpful to override this method in case we need to make some technology-specific check of the device to be accepted. The default implementation simply marks the given device as paired. | |
AsyncWork::Ptr | startDiscovery (const Poco::Timespan &timeout) override |
Starts device discovery process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
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 critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
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 critical section and so its implementation does not have to be thread-save nor reentrant (unless it cooperates with other threads itself). More... | |
void | eraseAllDevices () |
Clears m_devices. | |
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 to server. | |
void | seekPairedDevices () |
Tries to find not found paired devices. Each found device is added to parametr devices and attribute m_devices. | |
void | seekDevices (std::vector< BLESmartDevice::Ptr > &foundDevices, const StopControl &stop) |
Seeks for new devices on Bluetooth LE network. More... | |
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_numberOfExaminationThreads. These maps of devices are then examines in the seperated threads. | |
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 is created for it. | |
BLESmartDevice::Ptr | createDevice (const MACAddress &address) const |
Creates BLE device based on its Model ID. | |
void | processNewDevice (BLESmartDevice::Ptr newDevice) |
Protected Member Functions inherited from BeeeOn::DongleDeviceManager | |
std::string | dongleName (bool failWhenMissing=true) const |
Poco::Event & | event () |
Protected Member Functions inherited from BeeeOn::DeviceManager | |
std::set< DeviceID > | waitRemoteStatus (const Poco::Timespan &timeout) |
Wait until the remote status is delivered or timeout exceeds. DO NOT USE this method, it is intended as a transition mechanism from calling of the deprecated method deviceList(). More... | |
virtual void | handleGeneric (const Command::Ptr cmd, Result::Ptr result) |
void | handleListen (const GatewayListenCommand::Ptr cmd) |
Implements handling of the listen command in a generic way. The method ensures that only 1 thread can execute the discovery process at a time. More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const Poco::Net::IPAddress &address) |
Start searching a device by IP address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const MACAddress &address) |
Start searching a device by MAC address in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
virtual AsyncWork::Ptr | startSearch (const Poco::Timespan &timeout, const uint64_t serialNumber) |
Start searching a device by serial number in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself). More... | |
void | handleSearch (const DeviceSearchCommand::Ptr cmd) |
Implements handling of the search command in a generic way. The method ensures that only 1 thread can exactly the search process at a time. It is also mutual exclusive to the discovery process. | |
std::set< DeviceID > | handleUnpair (const DeviceUnpairCommand::Ptr cmd) |
Implements handling of the unpair command in a generic way. The method ensures that only 1 thread can execute the unpair process at a time. More... | |
AsyncWork< double >::Ptr | startSetValueByMode (const DeviceID &id, const ModuleID &module, const double value, const OpMode &mode, const Poco::Timespan &timeout) |
Call an implementation of startSetValue() based on the given operation mode. | |
virtual AsyncWork< double >::Ptr | startSetValueTryHarder (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) |
Default implementation just calls startSetValue(). | |
virtual AsyncWork< double >::Ptr | startSetValueRepeatOnFail (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) |
Default implementation calls startSetValue() again if a Poco::IOException is thrown until timeout exceeds. However, due to asynchronous behaviour, this way of repeating on fail might be inappropriate. | |
void | handleSetValue (const DeviceSetValueCommand::Ptr cmd) |
Implements handling of the set-value command in a generic way. The method ensures that only 1 thread can execute set-value process at a time. If the set-value operation succeeds, it ships the set value. More... | |
void | ship (const SensorData &sensorData) |
DeviceCache::Ptr | deviceCache () const |
CancellableSet & | cancellable () |
Poco::Timespan | checkDelayedOperation (const std::string &opname, const Poco::Clock &started, const Poco::Timespan &duration) const |
When starting an asynchronous operation, it might happen we sleep too long on a lock because the previous operation did not finished yet. This method performs such checks and also tests for global stop request. If everything is in order it just fixes the duration by the time elapsed by waiting. Otherwise, it throws an exception. More... | |
bool | manageUntilFinished (const std::string &opname, AnyAsyncWork::Ptr work, const Poco::Timespan &timeout) |
Manage an AsyncWork after it is started. If it does not finish in the given timeout, it is cancelled explicitly. More... | |
Protected Member Functions inherited from BeeeOn::Loggable | |
void | setupLogger (Poco::Logger *logger=0) const |
Poco::Logger & | logger () const |
Loggable (const ClassInfo &info) | |
Loggable (const std::type_info &info) | |
Additional Inherited Members | |
Public Types inherited from BeeeOn::DeviceManager | |
typedef Poco::SharedPtr < DeviceManager > | Ptr |
Public Types inherited from BeeeOn::DeviceStatusHandler | |
typedef Poco::SharedPtr < DeviceStatusHandler > | Ptr |
typedef std::map< DeviceID, std::map< ModuleID, double > > | DeviceValues |
Public Types inherited from BeeeOn::StoppableRunnable | |
typedef Poco::SharedPtr < StoppableRunnable > | Ptr |
Public Types inherited from BeeeOn::HotplugListener | |
typedef Poco::SharedPtr < HotplugListener > | Ptr |
Protected Types inherited from BeeeOn::StoppableRunnable | |
typedef Poco::SharedPtr < StoppableRunnable > | Ptr |
Static Protected Member Functions inherited from BeeeOn::Loggable | |
static Poco::Logger & | forMethod (const char *name) |
static Poco::Logger & | forClass (const ClassInfo &info) |
static Poco::Logger & | forClass (const std::type_info &info) |
template<typename T > | |
static Poco::Logger & | forInstance (const T *i) |
static void | configureSimple (Poco::Logger &logger, const std::string &level) |
static void | logException (Poco::Logger &logger, const Poco::Message::Priority priority, const Poco::Exception &e, const char *file, size_t line) |
Protected Attributes inherited from BeeeOn::DeviceManager | |
StopControl | m_stopControl |
The class implements the work with Bluetooth Low Energy devices. Allows us to process and execute the commands from server and gather data from the devices.
|
overridevirtual |
The main execution loop that is to be run while the appropriate dongle is available. When the dongle is disconnected during the execution, the method must throw an exception (a good choice is Poco::IOException).
When the method returns normally, the DongleDeviceManager finishes its main loop and exits the thread.
Implements BeeeOn::DongleDeviceManager.
|
protected |
Seeks for new devices on Bluetooth LE network.
The process of identification device consists of two steps. In the first step, it is determined wheter the device name is in set of names of potentially supported device. If so, then the model id of device is obtained according to which the device is identified.
|
overrideprotectedvirtual |
Starts device discovery process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The purpose of this call is to initialize and start the discovery process which might be a non-blocking operation. The caller uses the provided AsyncWork<> instance to wait until it finishes or to cancel it earlier if needed.
Reimplemented from BeeeOn::DeviceManager.
|
overrideprotectedvirtual |
Starts set-value operation in a technology specific way. The method is always called inside a critical section and so its implementation does not have to be thread-save nor reentrant (unless it cooperates with other threads itself).
The set-value process might a be a non-blocking operation. The value set by the set-value is expected as a result of the returned AsyncWork instance.
Reimplemented from BeeeOn::DeviceManager.
|
overrideprotectedvirtual |
Starts device unpair process in a technology-specific way. This method is always called inside a critical section and so its implementation does not have to be thread-safe nor reentrant (unless it cooperates with other threads itself).
The unpairing process might be a non-blocking operation. The unpaired devices are provided via the result of the returned AsyncWork instance.
Reimplemented from BeeeOn::DeviceManager.
|
overridevirtual |
Stop the runnable. The call should not block.
Implements BeeeOn::StoppableRunnable.