BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Data Structures | Public Types | Public Member Functions | Protected Member Functions
BeeeOn::ZWaveDeviceManager Class Reference

ZWaveDeviceManager implements the logical layer on top of the ZWaveNetwork interface. It adapts the Z-Wave specifics to the BeeeOn system with the help of ZWaveMapperRegistry::Mapper. More...

#include <ZWaveDeviceManager.h>

Inheritance diagram for BeeeOn::ZWaveDeviceManager:
BeeeOn::DeviceManager BeeeOn::CommandHandler BeeeOn::CommandSender BeeeOn::DeviceStatusHandler BeeeOn::Loggable BeeeOn::StoppableRunnable

Data Structures

class  Device
 High-level representation of a Z-Wave device. It enriches the ZWaveNode for information needed by the manager and the BeeeOn system. This means especially the Mapper instance. More...
 

Public Types

typedef std::map< DeviceID,
Device
DeviceMap
 
typedef std::map
< ZWaveNode::Identity,
DeviceMap::iterator > 
ZWaveNodeMap
 
- 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 Member Functions

void setNetwork (ZWaveNetwork::Ptr network)
 Configure ZWaveNetwork to be used by this manager.
 
void setRegistry (ZWaveMapperRegistry::Ptr registry)
 Set registry that are able to resolve the Z-Wave devices specific features.
 
void setDispatchDuration (const Poco::Timespan &duration)
 Set maximal time window in which new devices are reported since the start of the inclusion mode. More...
 
void setPollTimeout (const Poco::Timespan &timeout)
 Set poll timeout of the main loop polling the configured ZWaveNetwork instance.
 
void run () override
 Run the loop that receives events from the configured ZWaveNetwork instance. The loop receives information about sensor data, new nodes, nodes removals, discovery, etc.
 
void stop () override
 Stop the polling loop.
 
- 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)
 
AnswerQueueanswerQueue ()
 

Protected Member Functions

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 &duration) 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 dispatchUnpaired ()
 Dispatch all registered devices that are not paired to the remote server.
 
void dispatchDevice (const Device &device, bool enabled=true)
 Dispatch the given device to the remote server. More...
 
std::set< DeviceIDrecentlyUnpaired ()
 Access cached device IDs of the Z-Wave nodes removed by the recent unpair process. The call clears that cache. More...
 
void processValue (const ZWaveNode::Value &value)
 Process a Z-Wave value received from the Z-Wave network. If there is a paired device for that value and there is a conversion available for that value, the value is shipped via Distributor. More...
 
void newNode (const ZWaveNode &node, bool dispatch)
 If the given node is fully resolvable (we can determine its Mapper instance), it is registered as a new Device and dispatched as a new device. Otherwise, such node is ignored.
 
void newNodeUnlocked (const ZWaveNode &node, bool dispatch)
 
void updateNode (const ZWaveNode &node, bool dispatch)
 If the given node is already registered, update information about it and if it is not paired, dispatch it as a new device (or updated device). If the node is not registered, the newNode() is called instead. More...
 
void removeNode (const ZWaveNode &node)
 The given node is considered to be unpaired, its cached data is deleted.
 
void registerDevice (const Device &device)
 Register a device to be available for the BeeeOn system. The device must have a resolved mapper. Pairing status is irrelevant for this method and not affected.
 
Device unregisterDevice (ZWaveNodeMap::iterator it)
 Unregister the device pointed to by the iterator from being available to the BeeeOn system. Pairing status is irrelevant for this method and not affected. More...
 
void stopInclusion ()
 Helper method to stop the Z-Wave inclusion mode.
 
void stopRemoveNode ()
 Helper method to stop the Z-Wave node removal mode.
 
- Protected Member Functions inherited from BeeeOn::DeviceManager
std::set< DeviceIDwaitRemoteStatus (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< DeviceIDhandleUnpair (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
 
CancellableSetcancellable ()
 
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

- 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
 

Detailed Description

ZWaveDeviceManager implements the logical layer on top of the ZWaveNetwork interface. It adapts the Z-Wave specifics to the BeeeOn system with the help of ZWaveMapperRegistry::Mapper.

The Z-Wave provides a dynamic discovery progress where it is possible to ask the discovered devices for their specifics modules. This process can however be time consuming. It can have multiple steps:

  1. Discover new Z-Wave node.
  2. Get few details like vendor ID, product ID.
  3. Probe features of the Z-Wave node.

The steps 1 and 2 are usually fast enough, however, the step 3 can take more than a minute. Each Z-Wave node, to be operational, must recognized by a ZWaveMapperRegistry and a specific Mapper instance must be assigned to it. Certain Mapper implementions can work just after the step 2, other might need the step 3 to complete.

A Z-Wave node is considered as working when a Mapper is resolved for it. If no Mapper is resolved such Z-Wave node is dropped until an update of its details comes from the underlying ZWaveNetwork.

Member Function Documentation

void ZWaveDeviceManager::dispatchDevice ( const Device device,
bool  enabled = true 
)
protected

Dispatch the given device to the remote server.

If the device is dispatchable (it is not paired nor it is a controller) it is not shipped.

If the given parameter enabled is false, no dispatching would occur as we assume that discovery mode is disabled at that moment. The purpose of the enabled is that we are likely to first check whether the device is dispatchable and than to check whether discovery is allowed.

void ZWaveDeviceManager::processValue ( const ZWaveNode::Value value)
protected

Process a Z-Wave value received from the Z-Wave network. If there is a paired device for that value and there is a conversion available for that value, the value is shipped via Distributor.

The method processes also values that are not to be shipped, like the refresh time.

set< DeviceID > ZWaveDeviceManager::recentlyUnpaired ( )
protected

Access cached device IDs of the Z-Wave nodes removed by the recent unpair process. The call clears that cache.

The method startUnpair() initiates the Z-Wave node removal process. While in progress, the main loop would recieve information about Z-Wave nodes being removed from the Z-Wave network. The devices are stored in a temporary cache that can be accessed by this method.

The temporary cache is to be used only during the unpair process.

void ZWaveDeviceManager::setDispatchDuration ( const Poco::Timespan &  duration)

Set maximal time window in which new devices are reported since the start of the inclusion mode.

The dispatch time usually needs to be longer than the listen duration as received from the server because the node discovery is sometimes very slow.

AsyncWork::Ptr ZWaveDeviceManager::startDiscovery ( const Poco::Timespan &  timeout)
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.

AsyncWork< double >::Ptr ZWaveDeviceManager::startSetValue ( const DeviceID id,
const ModuleID module,
const double  value,
const Poco::Timespan &  timeout 
)
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.

AsyncWork< set< DeviceID > >::Ptr ZWaveDeviceManager::startUnpair ( const DeviceID id,
const Poco::Timespan &  timeout 
)
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.

ZWaveDeviceManager::Device ZWaveDeviceManager::unregisterDevice ( ZWaveNodeMap::iterator  it)
protected

Unregister the device pointed to by the iterator from being available to the BeeeOn system. Pairing status is irrelevant for this method and not affected.

Returns
shallow copy of the removed device
void ZWaveDeviceManager::updateNode ( const ZWaveNode node,
bool  dispatch 
)
protected

If the given node is already registered, update information about it and if it is not paired, dispatch it as a new device (or updated device). If the node is not registered, the newNode() is called instead.

See Also
newNode()

The documentation for this class was generated from the following files: