BeeeOn Gateway  v2020.3.1-2-g6f737dc
Platform to interconnect the IoT world
Public Member Functions | Protected Member Functions | Static Protected Member Functions
BeeeOn::JablotronDeviceManager Class Reference

JablotronDeviceManager utilizes the JablotronController to communicate with a Turris Dongle to receive reports (JablotronReport) and issue commands. It maintains pairing of individual gadgets (JablotronGadget) and provides 3 controllable (virtual) devices: PGX, PGY and Siren that can be associated with certain Jablotron devices (AC-88, JA-80L, etc.). More...

#include <JablotronDeviceManager.h>

Inheritance diagram for BeeeOn::JablotronDeviceManager:
BeeeOn::DeviceManager BeeeOn::HotplugListener BeeeOn::CommandHandler BeeeOn::CommandSender BeeeOn::DeviceStatusHandler BeeeOn::Loggable BeeeOn::StoppableRunnable

Public Member Functions

void setUnpairErasesSlot (bool erase)
 The BeeeOn unpair operation marks a device as unpaired. It can also unregister the gadget from Turris Dongle. This however makes impossible to pair the gadget back again because the Turris Dongle has no way how to discover devices around. A physical registration must be done manually in that case.
 
void setTxBackOffFactory (BackOffFactory::Ptr factory)
 Set BackOffFactory to be used while sending TX packets to set PGX, PGY or Siren. The backoff controls how many times the TX packet would be sent and how long delay to use between each two consecutive packets.
 
void setPGYEnrollGap (const Poco::Timespan &gap)
 Configure gap between two TX ENROLL packets while pairing the PGY. At least 3 seconds gap was experimentally shown to work.
 
void setEraseAllOnProbe (bool erase)
 Erase all slots registered in the dongle when connected and probed successfully.
 
void setRegisterOnProbe (const std::list< std::string > &addresses)
 Register the given list of address when the dongle is connected and probed successfully (after the potential erase).
 
void setMaxProbeAttempts (int count)
 
void setProbeTimeout (const Poco::Timespan &timeout)
 
void setIOJoinTimeout (const Poco::Timespan &timeout)
 
void setIOReadTimeout (const Poco::Timespan &timeout)
 
void setIOErrorSleep (const Poco::Timespan &delay)
 
void onAdd (const HotplugEvent &e) override
 
void onRemove (const HotplugEvent &e) override
 
void run () override
 
void stop () override
 
void handleRemoteStatus (const DevicePrefix &prefix, const std::set< DeviceID > &devices, const DeviceStatusHandler::DeviceValues &values) override
 Receive list of paired devices and reflect this in the connected dongle if any.
 
- 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
 
- 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 ()
 
- Public Member Functions inherited from BeeeOn::HotplugListener
virtual void onChange (const HotplugEvent &event)
 
virtual void onMove (const HotplugEvent &event)
 

Protected Member Functions

void handleAccept (const DeviceAcceptCommand::Ptr cmd) override
 Confirm pairing of the given device. If it is PGX, PGY or Siren, we send the TX ENROLL:1 packet(s). If pairing a gadget, we check the available slots register it unless it is already there. If the gadget has a secondary address, both of them are registered.
 
AsyncWork::Ptr startDiscovery (const Poco::Timespan &timeout) override
 Discover all slots and report gadgets that are not paired. Also, report devices PGX, PGY and Siren.
 
AsyncWork::Ptr startSearch (const Poco::Timespan &timeout, const uint64_t serialNumber) override
 Search whether the gadget of the given serialNumber is registered. If it is not and the serialNumber is valid, register it with the connected Turris Dongle. Finally, if such gadget is not paired, report it as a new device.
 
AsyncWork< std::set< DeviceID >
>::Ptr 
startUnpair (const DeviceID &id, const Poco::Timespan &timeout) override
 Unpair the given device. If it is PGX, PGY or Siren, then only the device cache is updated. When unpairing a gadget, it is unregistered from its slot if the unpairErasesSlot property is true. If the gadget has a secondary address, both of them are unregistered.
 
AsyncWork< double >::Ptr startSetValue (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout) override
 Set value of PGX, PGY or Siren. It sends the TX packet with ENROLL:0 and the appropriate states. The TX packet is sent multiple times based on the configured txBackOffFactory.
 
std::string hotplugMatch (const HotplugEvent &e)
 Recognizes compatible dongle by testing HotplugEvent property as tty.BEEEON_DONGLE == jablotron.
 
void newDevice (const DeviceID &id, const std::string &name, const std::list< ModuleType > &types, const RefreshTime &refreshTime)
 Dispatch information about the new device.
 
void acceptGadget (const DeviceID &id)
 Accept gadget device to be paired.
 
void enrollTX ()
 Enroll PGX, PGY or Siren.
 
void registerGadget (std::set< unsigned int > &freeSlots, const uint32_t address, const Poco::Timespan &timeout)
 Unregister gadget from tis slot.
 
void unregisterGadget (const DeviceID &id, const Poco::Timespan &timeout)
 Unregister gadget from tis slot.
 
void shipReport (const JablotronReport &report)
 Report the asynchronous message via DeviceManager::ship().
 
std::vector< JablotronGadgetreadGadgets (const Poco::Timespan &timeout)
 Read all slots from the controller and return registered gadgets. Certain gadgets might be unresolved (their info would be invalid).
 
void scanSlots (std::set< uint32_t > &registered, std::set< unsigned int > &freeSlots, std::set< unsigned int > &unknownSlots)
 Scan all slots and detect all registered gadgets, free (empty) slots and slots having unknown (unsupported) gadgets.
 
void initDongle ()
 Initialize the newly connected dongle. Apply the eraseAllOnProbe and registerOnProbe settings.
 
void syncSlots ()
 Scan slots and synchronize with pairing cache. The devices that are paired in device cache and missing in the dongle configuration are paired. If there is not enough space, the registered slots with non-paired devices are overwritten.
 
- 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...
 
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)
 

Static Protected Member Functions

static DeviceID buildID (uint32_t address)
 
static uint32_t extractAddress (const DeviceID &id)
 
static DeviceID pgxID ()
 
static DeviceID pgyID ()
 
static DeviceID sirenID ()
 
static void sleep (const Poco::Timespan &delay)
 Sleep for at least the given delay and not less.
 
- 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)
 

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
 
- Protected Attributes inherited from BeeeOn::DeviceManager
StopControl m_stopControl
 

Detailed Description

JablotronDeviceManager utilizes the JablotronController to communicate with a Turris Dongle to receive reports (JablotronReport) and issue commands. It maintains pairing of individual gadgets (JablotronGadget) and provides 3 controllable (virtual) devices: PGX, PGY and Siren that can be associated with certain Jablotron devices (AC-88, JA-80L, etc.).

Certain gadgets (RC-86K) can be dual - having 2 addresses. Such gadgets are treated as a single device with primary and secondary address. The primary address is used for device ID generation. Both addresses are registered, checked and unregistered from slots.

The Turris Dongle cannot discover devices. It only lists devices registered with itself. Thus, to add a new device, it must be registered either physically or by sending device-accept command with the appropriate device ID. Because of this, the unpair operation does not unregister gadgets from slots as default (this can be changed by property unpairErasesSlot).

The PGX, PGY and Siren are paired differently. Everytime when the device-accept is received from any of them, the enroll is send. If the target device is in the appropriate learning mode, it would react on the control change requests. Unpairing for PGX, PGY and Siren does nothing but affecting the BeeeOn device pairing cache. The PGY is enrolled by sending 2 TX ENROLL:1 packets with an appropriate gap. The gap is configurable (pgyEnrollGap) but it should be at least few seconds to work properly.

Member Function Documentation

DeviceID JablotronDeviceManager::buildID ( uint32_t  address)
staticprotected

Generate device ID based on the address. If the given address comes from a secondary gadget, it is first converted to primary address.

uint32_t JablotronDeviceManager::extractAddress ( const DeviceID id)
staticprotected
Returns
gadget address from the given id
void JablotronDeviceManager::setIOErrorSleep ( const Poco::Timespan &  delay)
void JablotronDeviceManager::setIOJoinTimeout ( const Poco::Timespan &  timeout)
void JablotronDeviceManager::setIOReadTimeout ( const Poco::Timespan &  timeout)
void JablotronDeviceManager::setMaxProbeAttempts ( int  count)
void JablotronDeviceManager::setProbeTimeout ( const Poco::Timespan &  timeout)
void JablotronDeviceManager::stop ( )
overridevirtual

A generic stop implementation to be used by most DeviceManager implementations.

Reimplemented from BeeeOn::DeviceManager.


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