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

#include <FitpDeviceManager.h>

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

Public Types

typedef Poco::SharedPtr
< FitpDeviceManager
Ptr
 
typedef uint32_t EDID
 
- 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 run () override
 
void stop () override
 
void loadDeviceList ()
 
void setConfigPath (const std::string &configPath)
 
void setNoiseMin (int min)
 
void setNoiseMax (int max)
 
void setBitrate (int bitrate)
 
void setBand (int band)
 
void setChannel (int channel)
 
void setPower (int power)
 
void setTxRetries (int retries)
 
void setGatewayInfo (Poco::SharedPtr< GatewayInfo > info)
 
void initFitp ()
 
EDID parseEDID (const std::vector< uint8_t > &id)
 
void processDataMsg (const std::vector< uint8_t > &data)
 
void processJoinMsg (const std::vector< uint8_t > &data)
 
- 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 ()
 

Static Public Member Functions

static DeviceID buildID (EDID edid)
 
static EDID deriveEDID (const DeviceID &id)
 

Protected Member Functions

void handleGeneric (const Command::Ptr cmd, Result::Ptr result) override
 
void doListenCommand (const GatewayListenCommand::Ptr cmd)
 
void doDeviceAcceptCommand (const DeviceAcceptCommand::Ptr cmd)
 
void doUnpairCommand (const DeviceUnpairCommand::Ptr cmd)
 
void dispatchNewDevice (FitpDevice::Ptr device)
 
- 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 handleAccept (const DeviceAcceptCommand::Ptr)
 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.
 
virtual AsyncWork::Ptr startDiscovery (const Poco::Timespan &timeout)
 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...
 
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.
 
virtual AsyncWork< std::set
< DeviceID > >::Ptr 
startUnpair (const DeviceID &id, const Poco::Timespan &timeout)
 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...
 
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...
 
virtual AsyncWork< double >::Ptr startSetValue (const DeviceID &id, const ModuleID &module, const double value, const Poco::Timespan &timeout)
 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...
 
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

Ensures initialization of FIT protocol (fitp). It is able to send NewDeviceCommand to CommandDispatcher when device attempts to pair.

It also ensures reaction to commands sent from server:

It ships measured data to Distributor.

It processes DATA and JOIN REQUEST messages.

Generally, message has the following format:

Format of application data:

Note: RSSI is obtained in FitpDeviceManager, value has 1 B.

Note: Only one instance of FitpDeviceManager is possible, because fitp library does not support more instances.

Member Function Documentation

DeviceID FitpDeviceManager::buildID ( FitpDeviceManager::EDID  edid)
static

Converts end device identifier (EDID) to device ID. EDID is array of four uint8_t values. EDID is stored in lower 32 bits of DeviceID from the index 0 to index 4. Example: 0 0 0 0 edid[0] edid[1] edid[2] edid[3]

FitpDeviceManager::EDID FitpDeviceManager::deriveEDID ( const DeviceID id)
static

Converts device ID to end device identifier (EDID).

void FitpDeviceManager::dispatchNewDevice ( FitpDevice::Ptr  device)
protected

Ensures sending of NewDeviceCommand to CommandDispatcher.

void FitpDeviceManager::doDeviceAcceptCommand ( const DeviceAcceptCommand::Ptr  cmd)
protected

Reacts to AcceptCommand. Device has to be stored in map of devices, it has to be available and it has to be unpaired. If these conditions are fulfilled, method inserts device into a map of devices, and it sets device as paired.

void FitpDeviceManager::doListenCommand ( const GatewayListenCommand::Ptr  cmd)
protected

Reacts to ListenCommand. It sends NewDeviceCommand if device is not paired or is not available.

void FitpDeviceManager::doUnpairCommand ( const DeviceUnpairCommand::Ptr  cmd)
protected

Reacts to UnpairCommand. Device has to be in map of devices, it has to be paired and available.

void FitpDeviceManager::handleGeneric ( const Command::Ptr  cmd,
Result::Ptr  result 
)
overrideprotectedvirtual

Generic implementation of the handle(). If any device manager needs to override the handle() method, it is more desirable to override handleGeneric().

Reimplemented from BeeeOn::DeviceManager.

void FitpDeviceManager::initFitp ( )

Initializes the fitp.

void FitpDeviceManager::loadDeviceList ( )

Sets devices as available and paired according to the device list sent from server and the map of devices. A device has to be in the map of devices so that it can be loaded from server.

FitpDeviceManager::EDID FitpDeviceManager::parseEDID ( const std::vector< uint8_t > &  id)

Parses EDID from received data.

void FitpDeviceManager::processDataMsg ( const std::vector< uint8_t > &  data)

Processes data message sent by device.

void FitpDeviceManager::processJoinMsg ( const std::vector< uint8_t > &  data)

Processes join request message sent by device.

void FitpDeviceManager::setBand ( int  band)

Sets band. It is possible to change band. Following values are supported:

  • 0 - band 863-870 MHz
  • 1 - band 950-960 MHz
  • 2 - band 902-915 MHz
  • 3 - band 915-928 MHz
void FitpDeviceManager::setBitrate ( int  bitrate)

Sets bitrate. It is possible to change bitrate. 0x00 - DATA_RATE_5 0x01 - DATA_RATE_10 0x02 - DATA_RATE_20 0x03 - DATA_RATE_40 0x04 - DATA_RATE_50 0x05 - DATA_RATE_66 0x06 - DATA_RATE_100 0x07 - DATA_RATE_200

void FitpDeviceManager::setChannel ( int  channel)

Sets channel. It is possible to change channel. Case 1: (band = 0 or band = 1) and (bitrate = 6 or bitrate = 7) values 0-24 are valid Case 2: otherwise values 0-31 are valid

Note: Band and bitrate have to be set before setting a channel. It is used during joining process when channel scanning is performed.

void FitpDeviceManager::setConfigPath ( const std::string &  configPath)

Sets path to the configuration file from which device table on PAN coordinator is filled. If device table is not filled, PAN coordinator is not able to react to the DATA messages from a device. If a device wants to join to the network, it sends the JOIN REQUEST message that PAN coordinator is able to receive and process. After successful joining process, this device will be stored into the device table and saved to the file.

void FitpDeviceManager::setNoiseMax ( int  max)

Sets maximum value of noise threshold. It is necessary to set so that data can be sent. Condition: max >= 0

void FitpDeviceManager::setNoiseMin ( int  min)

Sets minimum value of noise threshold. It is necessary to set so that data can be sent. Condition: min >= 0

void FitpDeviceManager::setPower ( int  power)

Sets transmission power. It is possible to change TX power. The TX power specifies the strength of the signal that device produces during data transmitting. Following values are supported: 0x00: 13 dBm 0x01: 10 dBm 0x02: 7 dBm 0x03: 4 dBm 0x04: 1 dBm 0x05: -2 dBm 0x06: -5 dBm 0x07: -8 dBm

Note: If TX power is set to 7 dBm, device is able to communicate with near devices. If TX power is set to 13 dBm, device is able to communicate with more distant devices.

void FitpDeviceManager::setTxRetries ( int  retries)

Sets count of attempts to resend a packet. Packet can be resent if devices communicate using four-way handshake. Condition: retries >= 0

void FitpDeviceManager::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: