6 #include <Poco/Event.h>
7 #include <Poco/Mutex.h>
8 #include <Poco/Nullable.h>
9 #include <Poco/RunnableAdapter.h>
10 #include <Poco/SharedPtr.h>
11 #include <Poco/Thread.h>
12 #include <Poco/Timespan.h>
14 #include "io/SerialPort.h"
15 #include "jablotron/JablotronReport.h"
16 #include "loop/StopControl.h"
17 #include "util/Joiner.h"
18 #include "util/Loggable.h"
77 void probe(
const std::string &dev);
84 void release(
const std::string &dev);
106 const Poco::Timespan &timeout);
116 const Poco::Timespan &timeout);
125 const Poco::Timespan &timeout);
132 void eraseSlots(
const Poco::Timespan &timeout);
146 const Poco::Timespan &timeout);
153 void sendEnroll(
const Poco::Timespan &timeout);
168 std::string
command(
const std::string &request,
169 const Poco::Timespan &timeout);
183 void stopIO(
const std::string &dev);
240 void writePort(
const std::string &request);
241 std::string readPort(
const Poco::Timespan &timeout);
245 std::queue<std::string> m_responses;
246 Poco::Event m_requestEvent;
247 std::queue<JablotronReport> m_reports;
248 Poco::Event m_pollEvent;
250 size_t m_maxProbeAttempts;
251 Poco::Timespan m_probeTimeout;
252 Poco::Timespan m_ioJoinTimeout;
253 Poco::Timespan m_ioReadTimeout;
254 Poco::Timespan m_ioErrorSleep;
256 Poco::SharedPtr<Poco::Thread> m_ioThread;
257 Poco::SharedPtr<Joiner> m_joiner;
258 Poco::RunnableAdapter<JablotronController> m_ioLoop;
261 Poco::FastMutex m_lock;
262 Poco::FastMutex m_requestLock;
void release(const std::string &dev)
Release the serial port and stop the I/O thread if running. If the argument dev does not match the cu...
Definition: JablotronController.cpp:133
Report with data coming from a sensor. Each report comes in format [AAAAAAAA] TYPE PAYLOAD...
Definition: JablotronReport.h:13
void setIOReadTimeout(const Poco::Timespan &timeout)
Configure timeout to use while reading from the serial port inside the I/O loop. The value can be neg...
Definition: JablotronController.cpp:99
void unregisterSlot(unsigned int i, const Poco::Timespan &timeout)
Unregister the given slot.
Definition: JablotronController.cpp:233
void handleOkError(const std::string &response) const
Check whether the response is "OK" or "ERROR".
Definition: JablotronController.cpp:260
std::string command(const std::string &request, const Poco::Timespan &timeout)
Issue a command and return its result unless the timeout exceeds.
Definition: JablotronController.cpp:271
JablotronReport pollReport(const Poco::Timespan &timeout)
Poll for reports coming from Jablotron sensors. If the timeout exceeds, an invalid report is returned...
Definition: JablotronController.cpp:327
bool receivedVersion(const std::string &response)
Parse the response to be the version string.
Definition: JablotronController.cpp:502
void sendEnroll(const Poco::Timespan &timeout)
Send enroll packet with PGX, PGY and ALARM as 0 and no beeping.
Definition: JablotronController.cpp:255
void stopIO(const std::string &dev)
Stop the I/O thread is any and if the argument dev matches the currently used serial port...
Definition: JablotronController.cpp:169
void readAndProcess()
Read the serial port and process all received messages in order.
Definition: JablotronController.cpp:409
void startIO()
Start the I/O thread without any checks and clear any thread-related status.
Definition: JablotronController.cpp:153
void setIOErrorSleep(const Poco::Timespan &delay)
Set time interval to sleep for when there is an I/O error. It reduces the number of logged error mess...
Definition: JablotronController.cpp:107
std::string popResponse()
Pop the most recent received response. All older responses are dropped because only 1 command can be ...
Definition: JablotronController.cpp:313
void eraseSlots(const Poco::Timespan &timeout)
Unregister all slots at once.
Definition: JablotronController.cpp:240
StopControl implements the stop mechanism generically.
Definition: StopControl.h:12
void processMessage(const std::string &message)
Process the given message. The call recognizes 2 kinds of messages: reports from sensors and other (u...
Definition: JablotronController.cpp:370
void setIOJoinTimeout(const Poco::Timespan &timeout)
Configure join timeout when waiting for the I/O thread to finish.
Definition: JablotronController.cpp:91
Definition: Loggable.h:19
Definition: SerialPort.h:9
Poco::Nullable< uint32_t > readSlot(unsigned int i, const Poco::Timespan &timeout)
Read address of the given slot.
Definition: JablotronController.cpp:188
void sendTX(bool x, bool y, bool alarm, Beep beep, const Poco::Timespan &timeout)
Send status packet with PGX and PGY set to either 1 or 0 accodring to the given values. Alarm is disabled and beeping set to FAST.
Definition: JablotronController.cpp:245
void registerSlot(unsigned int i, uint32_t address, const Poco::Timespan &timeout)
Register the given slot with the given address.
Definition: JablotronController.cpp:225
JablotronController provides access to the Turris Dongle that is connected via a serial port...
Definition: JablotronController.h:27
JablotronReport popReport()
Pop the oldest report from the associated queue. If the queue is empty, it returns an invalid report...
Definition: JablotronController.cpp:350
void probe(const std::string &dev)
Probe the given serial port (e.g. "/dev/ttyUSB0") and if it proves to be a Jablotron control station...
Definition: JablotronController.cpp:115
void ioLoop()
The entry into the I/O thread loop. It periodically calls readAndProcess() and checks whether a stop ...
Definition: JablotronController.cpp:434
void setMaxProbeAttempts(int count)
Configure number of attempts to initiate communication with the serial port connected to a Turris Don...
Definition: JablotronController.cpp:75
void probePort(const std::string &dev)
Probe the given port and test whether it is an appropriate Turris Dongle. Any obsolete messages in th...
Definition: JablotronController.cpp:463
void setProbeTimeout(const Poco::Timespan &timeout)
Configure timeout to wait for response from Turris Dongle while probing it.
Definition: JablotronController.cpp:83
void dispose()
Release the serial port and stop the I/O thread if running.
Definition: JablotronController.cpp:143