6 #include <Poco/Mutex.h>
8 #include "commands/DeviceAcceptCommand.h"
9 #include "commands/DeviceSetValueCommand.h"
10 #include "commands/DeviceUnpairCommand.h"
11 #include "commands/GatewayListenCommand.h"
12 #include "core/DeviceManager.h"
13 #include "hotplug/HotplugListener.h"
14 #include "jablotron/JablotronController.h"
15 #include "jablotron/JablotronGadget.h"
16 #include "jablotron/JablotronReport.h"
17 #include "model/ModuleType.h"
18 #include "model/RefreshTime.h"
19 #include "util/BackOff.h"
118 void stop()
override;
126 const std::set<DeviceID> &devices,
127 const DeviceStatusHandler::DeviceValues &values)
override;
137 void handleAccept(
const DeviceAcceptCommand::Ptr cmd)
override;
151 const Poco::Timespan &timeout,
152 const uint64_t serialNumber)
override;
162 const Poco::Timespan &timeout)
override;
173 const Poco::Timespan &timeout)
override;
186 const std::string &name,
187 const std::list<ModuleType> &types,
204 std::set<unsigned int> &freeSlots,
205 const uint32_t address,
206 const Poco::Timespan &timeout);
223 std::vector<JablotronGadget>
readGadgets(
const Poco::Timespan &timeout);
230 std::set<uint32_t> ®istered,
231 std::set<unsigned int> &freeSlots,
232 std::set<unsigned int> &unknownSlots);
267 static void sleep(
const Poco::Timespan &delay);
270 bool m_unpairErasesSlot;
271 BackOffFactory::Ptr m_txBackOffFactory;
272 Poco::Timespan m_pgyEnrollGap;
273 bool m_eraseAllOnProbe;
274 std::list<uint32_t> m_registerOnProbe;
279 JablotronController::Beep m_beep;
280 Poco::FastMutex m_lock;
Report with data coming from a sensor. Each report comes in format [AAAAAAAA] TYPE PAYLOAD...
Definition: JablotronReport.h:13
RefreshTime represents time of refreshing values from sensors. E.g. sensors are polled periodically o...
Definition: RefreshTime.h:24
void enrollTX()
Enroll PGX, PGY or Siren.
Definition: JablotronDeviceManager.cpp:519
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...
Definition: JablotronDeviceManager.cpp:711
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)...
Definition: JablotronDeviceManager.cpp:524
void syncSlots()
Scan slots and synchronize with pairing cache. The devices that are paired in device cache and missin...
Definition: JablotronDeviceManager.cpp:378
void setIOErrorSleep(const Poco::Timespan &delay)
Definition: JablotronDeviceManager.cpp:155
void shipReport(const JablotronReport &report)
Report the asynchronous message via DeviceManager::ship().
Definition: JablotronDeviceManager.cpp:446
void setPGYEnrollGap(const Poco::Timespan &gap)
Configure gap between two TX ENROLL packets while pairing the PGY. At least 3 seconds gap was experim...
Definition: JablotronDeviceManager.cpp:110
Definition: HotplugListener.h:9
JablotronDeviceManager utilizes the JablotronController to communicate with a Turris Dongle to receiv...
Definition: JablotronDeviceManager.h:49
void setRegisterOnProbe(const std::list< std::string > &addresses)
Register the given list of address when the dongle is connected and probed successfully (after the po...
Definition: JablotronDeviceManager.cpp:123
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.
Definition: JablotronDeviceManager.cpp:266
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
static DeviceID buildID(uint32_t address)
Definition: JablotronDeviceManager.cpp:160
static uint32_t extractAddress(const DeviceID &id)
Definition: JablotronDeviceManager.cpp:167
void setEraseAllOnProbe(bool erase)
Erase all slots registered in the dongle when connected and probed successfully.
Definition: JablotronDeviceManager.cpp:118
void setMaxProbeAttempts(int count)
Definition: JablotronDeviceManager.cpp:135
Definition: ModuleID.h:12
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 ...
Definition: JablotronDeviceManager.cpp:605
void unregisterGadget(const DeviceID &id, const Poco::Timespan &timeout)
Unregister gadget from tis slot.
Definition: JablotronDeviceManager.cpp:649
void setIOJoinTimeout(const Poco::Timespan &timeout)
Definition: JablotronDeviceManager.cpp:145
void newDevice(const DeviceID &id, const std::string &name, const std::list< ModuleType > &types, const RefreshTime &refreshTime)
Dispatch information about the new device.
Definition: JablotronDeviceManager.cpp:543
Definition: DeviceManager.h:48
Definition: HotplugEvent.h:10
std::string hotplugMatch(const HotplugEvent &e)
Recognizes compatible dongle by testing HotplugEvent property as tty.BEEEON_DONGLE == jablotron...
Definition: JablotronDeviceManager.cpp:210
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.
Definition: JablotronDeviceManager.cpp:558
void setUnpairErasesSlot(bool erase)
The BeeeOn unpair operation marks a device as unpaired. It can also unregister the gadget from Turris...
Definition: JablotronDeviceManager.cpp:100
static void sleep(const Poco::Timespan &delay)
Sleep for at least the given delay and not less.
Definition: JablotronDeviceManager.cpp:172
void setIOReadTimeout(const Poco::Timespan &timeout)
Definition: JablotronDeviceManager.cpp:150
JablotronController provides access to the Turris Dongle that is connected via a serial port...
Definition: JablotronController.h:27
void initDongle()
Initialize the newly connected dongle. Apply the eraseAllOnProbe and registerOnProbe settings...
Definition: JablotronDeviceManager.cpp:343
void setProbeTimeout(const Poco::Timespan &timeout)
Definition: JablotronDeviceManager.cpp:140
std::vector< JablotronGadget > readGadgets(const Poco::Timespan &timeout)
Read all slots from the controller and return registered gadgets. Certain gadgets might be unresolved...
Definition: JablotronDeviceManager.cpp:277
void acceptGadget(const DeviceID &id)
Accept gadget device to be paired.
Definition: JablotronDeviceManager.cpp:491
void stop() override
Definition: JablotronDeviceManager.cpp:259
void registerGadget(std::set< unsigned int > &freeSlots, const uint32_t address, const Poco::Timespan &timeout)
Unregister gadget from tis slot.
Definition: JablotronDeviceManager.cpp:470
Definition: DeviceID.h:17
void scanSlots(std::set< uint32_t > ®istered, 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 (unsupp...
Definition: JablotronDeviceManager.cpp:312
void setTxBackOffFactory(BackOffFactory::Ptr factory)
Set BackOffFactory to be used while sending TX packets to set PGX, PGY or Siren. The backoff controls...
Definition: JablotronDeviceManager.cpp:105
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...
Definition: JablotronDeviceManager.cpp:686
DevicePrefix prefix() const override
Definition: DeviceManager.cpp:33