-
Notifications
You must be signed in to change notification settings - Fork 1
/
JablotronModule.h
274 lines (232 loc) · 6.42 KB
/
JablotronModule.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/**
* @file JablotronModule.h
* @Author BeeeOn team - Peter Tisovcik <[email protected]>
* @date August, 2016
* @brief The class implements the work with Jablotron dongle. Reading value
* from the device and stored in the Vector devList, parsing the
* input string from serial port and transmission of value to the
* server. AC88 allows reading the last value from the server.
* Turris Dongle documentation: https://www.turris.cz/gadgets/manual .
*/
#ifndef JABLOTRON_MODULE_H
#define JABLOTRON_MODULE_H
#include <Poco/StringTokenizer.h>
#include "ModuleADT.h"
#include "SerialControl.h"
extern bool quit_global_flag;
const euid_t JABLOTRON_PREFIX = 0x0900000000000000;
typedef uint32_t jablotron_sn;
struct TJablotron {
int serialNumber;
std::string deviceName;
jablotron_sn deviceID;
std::string serialMessage;
};
class Aggregator;
class JablotronModule : public ModuleADT {
public:
JablotronModule(IOTMessage _msg, std::shared_ptr <Aggregator> _agg);
bool isJablotronModule(euid_t euid);
void parseCmdFromServer(const Command& cmd) override;
enum DeviceList {
AC88 = 8,
JA80L = 9,
TP82N = 10,
JA83M = 11,
JA81M = 18,
JA82SH = 19,
JA83P = 20,
JA85ST = 21,
RC86K = 22,
};
private:
struct AC88_ModuleID {
enum {
SENSOR_STATE = 0,
};
};
struct JA85ST_ModuleID {
enum {
FIRE_SENSOR = 0,
FIRE_SENSOR_ALARM,
FIRE_SENSOR_ERROR,
BATTERY_STATE,
};
};
struct JA83P_JA82SH_ModuleID {
enum {
SENSOR = 0,
SENSOR_ALARM,
BATTERY_STATE,
};
};
struct JA81M_JA83M_ModuleID {
enum {
DOOR_CONTACT = 0,
DOOR_CONTACT_ALARM,
BATTERY_STATE,
};
};
struct RC86K_ModuleID {
enum {
REMOTE_CONTROL = 0,
REMOTE_CONTROL_ALARM,
BATTERY_STATE,
};
};
struct TP82N_ModuleID {
enum {
CURRENT_ROOM_TEMPERATURE = 0,
REQUESTD_ROOM_TEMPERATURE,
BATTERY_STATE,
};
};
struct SENSOR_VALUE {
enum {
UNKNOWN_VALUE = 0,
STATE_ON,
STATE_OFF,
};
};
struct FIRE_SENSOR_VALUE {
enum {
STATE_OFF = 0,
STATE_ON,
};
};
Poco::Mutex _mutex;
IOTMessage msg;
Device sensorEvent;
std::string serialDeviceJablotron;
std::vector<jablotron_sn> devList;
/*
* Field X - output X
* Slot which contains the state of the first AC-88 device
*/
short pgx = 0;
/*
* Field Y - output Y
* Slot which contains the state of the second AC-88 device
*/
short pgy = 0;
std::unique_ptr<SerialControl> serial;
bool event;
void threadFunction() override;
bool isJablotronDevice(jablotron_sn sn);
/**
* @brief Method for requesting last value of specific module from server
* @param euid Device identifiers to set
* @return if value has valid data
*/
bool obtainActuatorState(euid_t euid);
/**
* @brief It sends data from devices to server
* @param &jablotron_msg Device identifiers to set
* @param &token String contain the value
* @return if value has valid data
*/
bool sendMessageToServer(TJablotron& jablotron_msg, Poco::StringTokenizer& token);
/*
* It checks message it was read successfully
* @param &jablotron_msg Struct contain jablotron data
* @param &token String will be divided according spaces
*/
bool parseSerialMessage(TJablotron& jablotron_msg, Poco::StringTokenizer& token);
/*
* Parse a value which was read from usb dongle and send to server
* @param &jablotron_msg Struct contains jablotron data
* @param &token String will be diveded according spaces
*
*/
bool parseMessageFromDevice(const TJablotron& jablotron_msg, Poco::StringTokenizer& token);
/*
* It sets a value which was read from TP-82N
* @param &serialMessage String contain the substring which was read from usb dongle
* @param &data String contains a temperature
* which can appear outdoor or indoor
*/
void parseMessageFromTP82N(const std::string& serialMessage, const std::string& data);
/*
* It sets a value which was read from RC-86K
* @param &data String contains the values from the sensor
*/
void parseMessageFromRC86K(const std::string& data);
/*
* It sets a value which was read from JA-81M and JA-83M
* @param &data String contains the values from the sensor
*/
void parseMessageFromJA81M_JA83M(const Poco::StringTokenizer& token);
/*
* It sets a value which was read from JA-83P and JA-82SH
* @param &token String contains the values from the sensor
*/
void parseMessageFromJA83P_JA82SH(const Poco::StringTokenizer& token);
/*
* It sets a value which was read from JA-85ST
* @param &token String contains the values from the sensor
*/
void parseMessageFromJA85ST(const Poco::StringTokenizer& token);
/**
* @brief It converts string value to float
* @param &msg String contains a float value
* @return Float sensor value
*/
float getValue(const std::string& msg) const;
/**
* @brief Convert jablotron state to BeeOn state
* @param &data String contains state value from sensor
* @param reverse If true/false state is replaced
* @return Float state value
*/
float convert(const std::string& data, bool reverse = true) const;
/**
* @brief Convert Jablotron battery state to BeeOn value
* for example 0 => 0%, 1=>100%
* @param String value of battery
* @return Battery value
*/
int getBatteryStatus(const std::string& msg) const;
/**
* @brief Loading of registered devices from the Turris Dongle
* @return if it has been loaded successfully
*/
bool loadRegDevices();
/**
* @brief It checks if the Turris Dongle is connected.
* @param &loadDevices If devices has been loaded successfully or unsuccessful
* @return If it has been loaded succesfully and connected or if
* it could not load the device
*/
bool loadJablotronDevices(bool &loadDevices);
/**
* @brief It locates the device ID
* @param sn The serial number of device
* @return Device ID
*/
int getDeviceID(jablotron_sn sn) const;
/**
* @brief It locates the serial number of device
* @param euid Device EUID
* @return Serial number of device
*/
jablotron_sn getDeviceSN(euid_t euid) const;
/**
* @brief It converts serial number of device to Device EUID
* @param sn The serial number of device
* @return Device EUID
*/
euid_t getEUID(jablotron_sn sn) const;
/**
* @brief It sendings data to the Turris Dongle according
* to the Jablotron protocol
* @param &msg Sending data
*/
void retransmissionPacket(const std::string& msg) const;
/**
* @brief It sets the value of the switch
* @param euid Device EUID
* @param sw Switch value
*/
void setSwitch(euid_t euid, short sw);
};
#endif