-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhb_core.c
402 lines (359 loc) · 11.5 KB
/
hb_core.c
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
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#include "hb_core.h"
#include <string.h>
uint8_t hb_get_available_zone_properties_by_type(hb_machine_type_t type,
hb_zone_property_t props[HZP_COUNT]) {
switch (type) {
case HMT_WIFI:
break;
case HMT_CAMERA:
break;
case HMT_GPRS_IOT:
case HMT_GPRS:
case HMT_WIFI2: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR,
HZP_EMERGENCY,
HZP_FIRE,
HZP_DURESS,
HZP_GAS,
HZP_WATER,
HZP_REMOTE_CONTROL,
};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_NETMOD: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR,
HZP_EMERGENCY,
HZP_FIRE,
HZP_DURESS,
HZP_GAS,
HZP_WATER,
HZP_SUB_MACHINE,
HZP_REMOTE_CONTROL,
HZP_BURGLAR_HALF,
HZP_BYPASS,
HZP_DOOR_RING,
};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_LCD: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR, HZP_EMERGENCY, HZP_FIRE,
HZP_DURESS, HZP_GAS, HZP_WATER, HZP_SUB_MACHINE,
HZP_REMOTE_CONTROL, HZP_BURGLAR_HALF,
HZP_DOOR_RING, HZP_BYPASS};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_WIRED: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR,
HZP_EMERGENCY,
HZP_FIRE,
HZP_DURESS,
HZP_GAS,
HZP_WATER,
HZP_REMOTE_CONTROL,
};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_TRUE_COLOR: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR, HZP_EMERGENCY, HZP_FIRE,
HZP_DURESS, HZP_GAS, HZP_WATER, HZP_REMOTE_CONTROL,
HZP_DOOR_RING, HZP_BYPASS};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_THREE_SECTION: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR, HZP_EMERGENCY, HZP_FIRE,
HZP_DURESS, HZP_GAS, HZP_WATER, HZP_REMOTE_CONTROL,
HZP_DOOR_RING, HZP_BYPASS};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_IOT: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR, HZP_EMERGENCY, HZP_FIRE,
HZP_DURESS, HZP_GAS, HZP_WATER, HZP_REMOTE_CONTROL,
HZP_DOOR_RING, HZP_BYPASS};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_GPRS_PHONE: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR,
HZP_EMERGENCY,
HZP_FIRE,
HZP_DURESS,
HZP_GAS,
HZP_WATER,
HZP_REMOTE_CONTROL,
};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
case HMT_NB: {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER hzps[] = {
HZP_BURGLAR,
HZP_EMERGENCY,
HZP_FIRE,
HZP_DURESS,
HZP_GAS,
HZP_WATER,
HZP_DOOR_RING,
};
memcpy(props, hzps, sizeof(hzps));
return sizeof(hzps) / sizeof(hb_zone_property_t);
}
default:
return 0;
}
return 0;
}
bool hb_machine_supports_zone_property(hb_machine_type_t type, hb_zone_property_t prop) {
hb_zone_property_t ADEMCO_BUF_MEMORY_MODIFIER props[HZP_COUNT];
uint8_t count = hb_get_available_zone_properties_by_type(type, props), i;
for (i = 0; i < count; i++) {
if (props[i] == prop) {
return true;
}
}
return false;
}
uint16_t hb_get_max_zone_by_type(hb_machine_type_t type) {
switch (type) {
case HMT_GPRS_IOT:
case HMT_GPRS:
case HMT_WIRED:
case HMT_WIFI2:
return 99;
case HMT_NETMOD:
case HMT_NB:
return 999;
case HMT_LCD:
return 249;
case HMT_TRUE_COLOR:
return 68;
case HMT_THREE_SECTION:
return 191;
case HMT_IOT:
case HMT_GPRS_PHONE:
return 60;
case HMT_WIFI:
case HMT_CAMERA:
default:
return 0;
break;
}
}
bool hb_is_valid_zone_by_type(hb_machine_type_t type, uint16_t zone) {
return 0 <= zone &&
zone <= hb_get_max_zone_by_type(type);
}
bool hb_is_valid_zone_by_type_strict(hb_machine_type_t type, uint16_t zone) {
return 1 <= zone && zone <= hb_get_max_zone_by_type(type);
}
bool hb_is_machine_on_sale(hb_machine_type_t type) {
return type == HMT_GPRS_IOT ||
type == HMT_NETMOD ||
type == HMT_GPRS ||
type == HMT_IOT ||
type == HMT_LCD ||
type == HMT_WIRED ||
type == HMT_TRUE_COLOR ||
type == HMT_THREE_SECTION ||
type == HMT_GPRS_PHONE ||
type == HMT_NB ||
type == HMT_WIFI2;
}
bool hb_machine_can_arm_away(hb_machine_type_t type) {
return hb_is_machine_on_sale(type) && (type != HMT_NB);
}
bool hb_machine_can_disarm(hb_machine_type_t type) {
return hb_is_machine_on_sale(type) && (type != HMT_NB);
}
bool hb_machine_can_config(hb_machine_type_t type) {
return hb_is_machine_on_sale(type);
}
bool hb_machine_can_arm_stay(hb_machine_type_t type) {
return type == HMT_NETMOD || type == HMT_LCD;
}
bool hb_machine_can_report_signal_strength(hb_machine_type_t type) {
return type == HMT_GPRS ||
type == HMT_GPRS_IOT ||
type == HMT_IOT ||
type == HMT_LCD ||
type == HMT_TRUE_COLOR ||
type == HMT_THREE_SECTION ||
type == HMT_GPRS_PHONE ||
type == HMT_NB ||
type == HMT_WIFI2;
}
bool hb_machine_can_report_by_sms(hb_machine_type_t type) {
return type == HMT_GPRS ||
type == HMT_LCD ||
type == HMT_TRUE_COLOR ||
type == HMT_THREE_SECTION ||
type == HMT_GPRS_PHONE;
}
bool hb_machine_has_wired_zones(hb_machine_type_t type) {
return type == HMT_NETMOD ||
type == HMT_TRUE_COLOR ||
type == HMT_THREE_SECTION;
}
uint16_t hb_wired_zone_min(hb_machine_type_t type) {
switch (type) {
case HMT_NETMOD:
return 1;
case HMT_TRUE_COLOR:
return 1;
case HMT_THREE_SECTION:
return 61;
default:
return 0;
}
}
uint16_t hb_wired_zone_max(hb_machine_type_t type) {
switch (type) {
case HMT_NETMOD:
return 8;
case HMT_TRUE_COLOR:
return 8;
case HMT_THREE_SECTION:
return 68;
default:
return 0;
}
}
bool hb_machine_can_write_zone(hb_machine_type_t type) {
return type == HMT_NETMOD;
}
bool hb_machine_can_link_sub_machine(hb_machine_type_t type) {
return type == HMT_NETMOD;
}
bool hb_zone_can_report_lost(hb_zone_property_t zp) {
switch (zp) {
case HZP_BURGLAR:
case HZP_EMERGENCY:
case HZP_DURESS:
case HZP_SUB_MACHINE:
case HZP_BURGLAR_HALF:
case HZP_BYPASS:
return 1;
default:
return 0;
}
}
void hb_machine_timer_one_init(hb_machine_timer_one_t* timer) {
memset(timer, 0xFF, sizeof(*timer));
}
void hb_machine_timer_init(hb_machine_timer_t* timer) {
memset(timer->dat, 0xFF, sizeof(*timer));
}
uint8_t hb_is_valid_time_point(const hb_machine_time_point_t* tp) {
return tp &&
tp->hour < 24 &&
tp->minute < 60;
}
uint8_t hb_time_point_equal(const hb_machine_time_point_t* tp1, const hb_machine_time_point_t* tp2) {
return tp1->hour == tp2->hour && tp1->minute == tp2->minute;
}
uint8_t hb_is_valid_timer_one(const hb_machine_timer_one_t* timer) {
return timer &&
#if HB_ENABLE_TIMER_ARM_STAY
(timer->arm_what == HB_TIMER_ARM_WHAT_ARM_AWAY || timer->arm_what == HB_TIMER_ARM_WHAT_ARM_STAY) &&
#endif
hb_is_valid_time_point(&timer->arm_at) &&
hb_is_valid_time_point(&timer->disarm_at) &&
!hb_time_point_equal(&timer->arm_at, &timer->disarm_at);
}
uint8_t hb_is_valid_machine_timer(const hb_machine_timer_t* timer) {
return timer &&
hb_is_valid_timer_one(&timer->timer[0]) &&
hb_is_valid_timer_one(&timer->timer[1]);
}
#if HB_ENABLE_TO_STRING
const char* hb_machine_status_to_string(hb_machine_status_t status) {
switch (status) {
#define XX(value, name, str) \
case HMS_##name: \
return #name;
HB_MACHINE_STATUS_MAP(XX)
#undef XX
default:
return "InvalidMachineStatus";
}
}
const char* hb_machine_type_to_string(hb_machine_type_t type) {
switch (type) {
#define XX(value, name, str) \
case HMT_##name: \
return #name;
HB_MACHINE_TYPE_MAP(XX)
#undef XX
default:
return "Unknown hb_machine_type_t";
}
}
const char* hb_zone_property_to_string(hb_zone_property_t zp) {
switch (zp) {
#define XX(value, name, str) \
case HZP_##name: \
return #name;
HB_ZONE_PROPERTY_MAP(XX)
#undef XX
default:
return "InvalidZoneProperty";
}
}
#if HB_ENABLE_CHINESE
const char* hb_machine_status_to_string_chinese(hb_machine_status_t status) {
switch (status) {
#define XX(value, name, str) \
case HMS_##name: \
return str;
HB_MACHINE_STATUS_MAP(XX)
#undef XX
default:
return "无效状态";
}
}
const char* hb_machine_type_to_string_chinese(hb_machine_type_t type) {
switch (type) {
#define XX(value, name, str) \
case HMT_##name: \
return str;
HB_MACHINE_TYPE_MAP(XX)
#undef XX
default:
return "未知机型";
}
}
const char* hb_zone_property_to_string_chinese(hb_zone_property_t zp) {
switch (zp) {
#define XX(value, name, str) \
case HZP_##name: \
return str;
HB_ZONE_PROPERTY_MAP(XX)
#undef XX
default:
return "无效属性";
}
}
#endif // HB_ENABLE_CHINESE
const char* hb_get_zone_format_str(hb_machine_type_t type) {
uint16_t zone = hb_get_max_zone_by_type(type);
if (10 < zone && zone < 100)
return "%02d";
else if (zone < 1000)
return "%03d";
else
return "%d";
}
#endif // HB_ENABLE_TO_STRING