-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathohs_conf.h
1140 lines (1026 loc) · 40.8 KB
/
ohs_conf.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
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
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* ohs_conf.h
*
* Created on: 26. 9. 2018
* Author: Adam
*/
#ifndef OHS_CONF_H_
#define OHS_CONF_H_
// Do some compile time checks
#if STM32_BKPRAM_ENABLE == STM32_NO_INIT
#error "In mcuconf.h STM32_BKPRAM_ENABLE must be TRUE!"
#endif
#if !STM32_LSE_ENABLED
#error "We have RTC external oscillator!"
#endif
// STM32 UID as Ethernet MAC
#define STM32_UUID ((uint32_t *)UID_BASE)
#define OHS_NAME "OHS"
#define OHS_MAJOR 1
#define OHS_MINOR 5
#define OHS_MOD 4
#define BACKUP_SRAM_SIZE 0x1000 // 4kB SRAM size
// A change on following define(s) will corrupt backup SRAM integrity.
// It will need to be setDefault.
#define ALARM_GROUPS 10 // # of groups
#define ALARM_ZONES 30 // # of zones
#define HW_ZONES 11 // # of hardware zones on gateway
#define CONTACTS_SIZE 10 // # of contacts
#define KEYS_SIZE 20 // # of keys
#define TIMER_SIZE 10 // # of timers
#define TRIGGER_SIZE 10 // # of timers
#define KEY_LENGTH 4 // sizeof(uint32_t) = size of hash
#define NAME_LENGTH 16 //
#define MIN_PASS_LNEGTH 4 // minimum password length
#define PHONE_LENGTH 14 //
#define EMAIL_LENGTH 32 //
#define URL_LENGTH 32 // URL address
#define NOT_SET "not set"
#define ALARM_PIR 2600 // (3380 = 15.2V), (2700 = 12.6V)
#define ALARM_PIR_LOW 2100
#define ALARM_PIR_HI 3200
#define ALARM_OK 1500 // (1850 = 15.2V), (1500 = 12.6V)
#define ALARM_OK_LOW 1100
#define ALARM_OK_HI 1900
#define ALARM_TAMPER 0
#define ALARM_UNBALANCED 500
#define RADIO_KEY_SIZE 17 // 16 + 1 for null termination
#define RADIO_UNIT_OFFSET 15 // Offset of radio nodes of wired nodes
#define NODE_SIZE 50 // Number of nodes
#define NODE_ADDRESS_SIZE 5
// Standard packet sizes without the packet header indication 'R' or 'S' or 'Z'
#define REG_PACKET_SIZE 21
#define SENSOR_PACKET_SIZE 6
#define ZONE_PACKET_SIZE 2
#define DUMMY_NO_VALUE 255
#define DUMMY_GROUP 15
#define AC_POWER_DELAY 60 // seconds
#define LOGGER_MSG_LENGTH 11 // Maximum size of logger message
#define LOGGER_OUTPUT_LEN 25 // How many entries to show at once
#define SIREN_MSG_LENGTH 3
// MQTT
#define MQTT_MAIN_TOPIC OHS_NAME "/"
#define MQTT_WILL_TOPIC "state"
#define MQTT_SET_TOPIC "set/"
#define MQTT_ALERT_TOPIC MQTT_MAIN_TOPIC "alert"
// MQTT Home Assistant Discovery
#define MQTT_HAD_MAIN_TOPIC "homeassistant/"
#define MQTT_HAD_CONFIG_TOPIC "config"
// Parameter checks
#if NODE_SIZE >= DUMMY_NO_VALUE
#error "NODE_SIZE is set to high!"
#endif
// Time related
#define SECONDS_PER_DAY 86400U
#define SECONDS_PER_HOUR 3600U
#define SECONDS_PER_MINUTE 60U
#define MINUTES_PER_HOUR 60U
#define RTC_LEAP_YEAR(year) ((((year) % 4 == 0) && ((year) % 100 != 0)) || ((year) % 400 == 0))
#define RTC_DAYS_IN_YEAR(x) RTC_LEAP_YEAR(x) ? 366 : 365
#define RTC_OFFSET_YEAR 1970
// Node commands
#define NODE_CMD_ACK 0
#define NODE_CMD_REGISTRATION 1
#define NODE_CMD_PING 2
#define NODE_CMD_PONG 3
#define NODE_CMD_ARMING 10
#define NODE_CMD_ALARM 11
#define NODE_CMD_AUTH_1 12
#define NODE_CMD_AUTH_2 13
#define NODE_CMD_AUTH_3 14
#define NODE_CMD_ARMED 15
#define NODE_CMD_DISARM 16
// Bit wise macros for various settings
#define GET_CONF_ZONE_ENABLED(x) ((x) & 0b1)
#define GET_CONF_ZONE_GROUP(x) ((x >> 1U) & 0b1111)
#define GET_CONF_ZONE_AUTH_TIME(x) ((x >> 5U) & 0b11)
#define GET_CONF_ZONE_ARM_HOME(x) ((x >> 7U) & 0b1)
#define GET_CONF_ZONE_OPEN_ALARM(x) ((x >> 8U) & 0b1)
#define GET_CONF_ZONE_PIR_AS_TMP(x) ((x >> 9U) & 0b1)
#define GET_CONF_ZONE_BALANCED(x) ((x >> 10U) & 0b1)
#define GET_CONF_ZONE_(x) ((x >> 11U) & 0b1)
#define GET_CONF_ZONE_MQTT_HAD(x) ((x >> 12U) & 0b1)
#define GET_CONF_ZONE_MQTT_PUB(x) ((x >> 13U) & 0b1)
#define GET_CONF_ZONE_IS_PRESENT(x) ((x >> 14U) & 0b1)
#define GET_CONF_ZONE_TYPE(x) ((x >> 15U) & 0b1)
#define SET_CONF_ZONE_ENABLED(x) x |= 1
#define SET_CONF_ZONE_GROUP(x,y) x = (((x)&(0b1111111111100001))|(((y & 0b1111) << 1U)&(0b0000000000011110)))
#define SET_CONF_ZONE_AUTH_TIME(x,y) x = (((x)&(0b1111111110011111))|(((y & 0b11) << 5U)&(0b0000000001100000)))
#define SET_CONF_ZONE_ARM_HOME(x) x |= (1 << 7U)
#define SET_CONF_ZONE_OPEN_ALARM(x) x |= (1 << 8U)
#define SET_CONF_ZONE_PIR_AS_TMP(x) x |= (1 << 9U)
#define SET_CONF_ZONE_BALANCED(x) x |= (1 << 10U)
#define SET_CONF_ZONE_(x) x |= (1 << 11U)
#define SET_CONF_ZONE_MQTT_HAD(x) x |= (1 << 12U)
#define SET_CONF_ZONE_MQTT_PUB(x) x |= (1 << 13U)
#define SET_CONF_ZONE_IS_PRESENT(x) x |= (1 << 14U)
#define SET_CONF_ZONE_TYPE(x) x |= (1 << 15U)
#define CLEAR_CONF_ZONE_ENABLED(x) x &= ~1
#define CLEAR_CONF_ZONE_ARM_HOME(x) x &= ~(1 << 7U)
#define CLEAR_CONF_ZONE_STILL_OPEN(x) x &= ~(1 << 8U)
#define CLEAR_CONF_ZONE_PIR_AS_TMP(x) x &= ~(1 << 9U)
#define CLEAR_CONF_ZONE_BALANCED(x) x &= ~(1 << 10U)
#define CLEAR_CONF_ZONE_(x) x &= ~(1 << 11U)
#define CLEAR_CONF_ZONE_MQTT_HAD(x) x &= ~(1 << 12U)
#define CLEAR_CONF_ZONE_MQTT_PUB(x) x &= ~(1 << 13U)
#define CLEAR_CONF_ZONE_IS_PRESENT(x) x &= ~(1 << 14U)
#define CLEAR_CONF_ZONE_TYPE(x) x &= ~(1 << 15U)
#define GET_CONF_GROUP_ENABLED(x) ((x) & 0b1)
#define GET_CONF_GROUP_TAMPER2(x) ((x >> 1U) & 0b1)
#define GET_CONF_GROUP_TAMPER1(x) ((x >> 2U) & 0b1)
#define GET_CONF_GROUP_PIR2(x) ((x >> 3U) & 0b1)
#define GET_CONF_GROUP_PIR1(x) ((x >> 4U) & 0b1)
#define GET_CONF_GROUP_AUTO_ARM(x) ((x >> 5U) & 0b1)
#define GET_CONF_GROUP_MQTT_HAD(x) ((x >> 6U) & 0b1)
#define GET_CONF_GROUP_MQTT(x) ((x >> 7U) & 0b1)
#define GET_CONF_GROUP_ARM_CHAIN(x) ((x >> 8U) & 0b1111)
#define GET_CONF_GROUP_DISARM_CHAIN(x) ((x >> 12U) & 0b1111)
#define SET_CONF_GROUP_ENABLED(x) x |= 1
#define SET_CONF_GROUP_TAMPER2(x) x |= (1 << 1U)
#define SET_CONF_GROUP_TAMPER1(x) x |= (1 << 2U)
#define SET_CONF_GROUP_PIR2(x) x |= (1 << 3U)
#define SET_CONF_GROUP_PIR1(x) x |= (1 << 4U)
#define SET_CONF_GROUP_AUTO_ARM(x) x |= (1 << 5U)
#define SET_CONF_GROUP_MQTT_HAD(x) x |= (1 << 6U)
#define SET_CONF_GROUP_MQTT(x) x |= (1 << 7U)
#define SET_CONF_GROUP_ARM_CHAIN(x,y) x = (((x)&(0b1111000011111111))|(((y & 0b1111) << 8U)&(0b0000111100000000)))
#define SET_CONF_GROUP_DISARM_CHAIN(x,y) x = (((x)&(0b0000111111111111))|(((y & 0b1111) << 12U)&(0b1111000000000000)))
#define CLEAR_CONF_GROUP_ENABLED(x) x &= ~1
#define CLEAR_CONF_GROUP_TAMPER2(x) x &= ~(1 << 1U)
#define CLEAR_CONF_GROUP_TAMPER1(x) x &= ~(1 << 2U)
#define CLEAR_CONF_GROUP_PIR2(x) x &= ~(1 << 3U)
#define CLEAR_CONF_GROUP_PIR1(x) x &= ~(1 << 4U)
#define CLEAR_CONF_GROUP_AUTO_ARM(x) x &= ~(1 << 5U)
#define CLEAR_CONF_GROUP_MQTT_HAD(x) x &= ~(1 << 6U)
#define CLEAR_CONF_GROUP_MQTT(x) x &= ~(1 << 7U)
#define GET_CONF_CONTACT_ENABLED(x) ((x) & 0b1)
#define GET_CONF_CONTACT_GROUP(x) ((x >> 1U) & 0b1111)
#define GET_CONF_CONTACT_IS_GLOBAL(x) ((x >> 5U) & 0b1)
#define SET_CONF_CONTACT_ENABLED(x) x |= 1
#define SET_CONF_CONTACT_GROUP(x,y) x = (((x)&(0b11100001))|(((y & 0b1111) << 1U)&(0b00011110)))
#define SET_CONF_CONTACT_IS_GLOBAL(x) x |= (1 << 5U)
#define CLEAR_CONF_CONTACT_ENABLED(x) x &= ~1
#define CLEAR_CONF_CONTACT_IS_GLOBAL(x) x &= ~(1 << 5U)
#define GET_CONF_KEY_ENABLED(x) ((x) & 0b1)
#define SET_CONF_KEY_ENABLED(x) x |= 1
#define CLEAR_CONF_KEY_ENABLED(x) x &= ~1
#define GET_CONF_SYSTEM_FLAG_RTC_LOW(x) ((x) & 0b1)
#define GET_CONF_SYSTEM_FLAG_RADIO_FREQ(x) ((x >> 1U) & 0b1)
#define SET_CONF_SYSTEM_FLAG_RTC_LOW(x) x |= 1
#define SET_CONF_SYSTEM_FLAG_RADIO_FREQ(x) x |= (1 << 1U)
#define CLEAR_CONF_SYSTEM_FLAG_RTC_LOW(x) x &= ~1
#define CLEAR_CONF_SYSTEM_FLAG_RADIO_FREQ(x) x &= ~(1 << 1U)
#define GET_CONF_TIMER_ENABLED(x) ((x) & 0b1)
#define GET_CONF_TIMER_TYPE(x) ((x >> 1U) & 0b1)
#define GET_CONF_TIMER_SU(x) ((x >> 2U) & 0b1)
#define GET_CONF_TIMER_SA(x) ((x >> 3U) & 0b1)
#define GET_CONF_TIMER_FR(x) ((x >> 4U) & 0b1)
#define GET_CONF_TIMER_TH(x) ((x >> 5U) & 0b1)
#define GET_CONF_TIMER_WE(x) ((x >> 6U) & 0b1)
#define GET_CONF_TIMER_TU(x) ((x >> 7U) & 0b1)
#define GET_CONF_TIMER_MO(x) ((x >> 8U) & 0b1)
#define GET_CONF_TIMER_RESULT(x) ((x >> 9U) & 0b1)
#define GET_CONF_TIMER_EVALUATED(x) ((x >> 10U) & 0b1) // not used
#define GET_CONF_TIMER_TRIGGERED(x) ((x >> 11U) & 0b1)
#define GET_CONF_TIMER_PERIOD_TYPE(x) ((x >> 12U) & 0b11)
#define GET_CONF_TIMER_RUN_TYPE(x) ((x >> 14U) & 0b11)
#define SET_CONF_TIMER_ENABLED(x) x |= 1
#define SET_CONF_TIMER_TYPE(x) x |= (1 << 1U)
#define SET_CONF_TIMER_SA(x) x |= (1 << 2U)
#define SET_CONF_TIMER_FR(x) x |= (1 << 3U)
#define SET_CONF_TIMER_TH(x) x |= (1 << 4U)
#define SET_CONF_TIMER_WE(x) x |= (1 << 5U)
#define SET_CONF_TIMER_TU(x) x |= (1 << 6U)
#define SET_CONF_TIMER_MO(x) x |= (1 << 7U)
#define SET_CONF_TIMER_SU(x) x |= (1 << 8U)
#define SET_CONF_TIMER_RESULT(x) x |= (1 << 9U)
#define SET_CONF_TIMER_EVALUATED(x) x |= (1 << 10U)
#define SET_CONF_TIMER_TRIGGERED(x) x |= (1 << 11U)
#define SET_CONF_TIMER_PERIOD_TYPE(x,y) x = (((x)&(0b1100111111111111))|(((y & 0b11) << 12U)&(0b0011000000000000)))
#define SET_CONF_TIMER_RUN_TYPE(x,y) x = (((x)&(0b0011111111111111))|(((y & 0b11) << 14U)&(0b1100000000000000)))
#define CLEAR_CONF_TIMER_ENABLED(x) x &= ~1
#define CLEAR_CONF_TIMER_TYPE(x) x &= ~(1 << 1U)
#define CLEAR_CONF_TIMER_SA(x) x &= ~(1 << 2U)
#define CLEAR_CONF_TIMER_FR(x) x &= ~(1 << 3U)
#define CLEAR_CONF_TIMER_TH(x) x &= ~(1 << 4U)
#define CLEAR_CONF_TIMER_WE(x) x &= ~(1 << 5U)
#define CLEAR_CONF_TIMER_TU(x) x &= ~(1 << 6U)
#define CLEAR_CONF_TIMER_MO(x) x &= ~(1 << 7U)
#define CLEAR_CONF_TIMER_SU(x) x &= ~(1 << 8U)
#define CLEAR_CONF_TIMER_RESULT(x) x &= ~(1 << 9U)
#define CLEAR_CONF_TIMER_EVALUATED(x) x &= ~(1 << 10U)
#define CLEAR_CONF_TIMER_TRIGGERED(x) x &= ~(1 << 11U)
#define GET_CONF_TRIGGER_ENABLED(x) ((x) & 0b1)
#define GET_CONF_TRIGGER_PASS_VALUE(x) ((x >> 1U) & 0b1)
#define GET_CONF_TRIGGER_PASS(x) ((x >> 2U) & 0b11)
#define GET_CONF_TRIGGER_PASSED(x) ((x >> 4U) & 0b1)
#define GET_CONF_TRIGGER_TRIGGERED(x) ((x >> 5U) & 0b1)
#define GET_CONF_TRIGGER_ALERT(x) ((x >> 6U) & 0b1)
#define GET_CONF_TRIGGER_PASS_OFF(x) ((x >> 7U) & 0b11)
#define GET_CONF_TRIGGER_RESULT(x) ((x >> 9U) & 0b1)
#define GET_CONF_TRIGGER_OFF_PERIOD(x) ((x >> 14U) & 0b11)
#define SET_CONF_TRIGGER_ENABLED(x) x |= 1
#define SET_CONF_TRIGGER_PASS_VALUE(x) x |= (1 << 1U)
#define SET_CONF_TRIGGER_PASS(x,y) x = (((x)&(0b1111111111110011))|(((y & 0b11) << 2U)&(0b0000000000001100)))
#define SET_CONF_TRIGGER_PASSED(x) x |= (1 << 4U)
#define SET_CONF_TRIGGER_TRIGGERED(x) x |= (1 << 5U)
#define SET_CONF_TRIGGER_ALERT(x) x |= (1 << 6U)
#define SET_CONF_TRIGGER_PASS_OFF(x,y) x = (((x)&(0b1111111001111111))|(((y & 0b11) << 7U)&(0b0000000110000000)))
#define SET_CONF_TRIGGER_RESULT(x) x |= (1 << 9U)
#define SET_CONF_TRIGGER_OFF_PERIOD(x,y) x = (((x)&(0b0011111111111111))|(((y & 0b11) << 14U)&(0b1100000000000000)))
#define CLEAR_CONF_TRIGGER_ENABLED(x) x &= ~1
#define CLEAR_CONF_TRIGGER_PASS_VALUE(x) x &= ~(1 << 1U)
#define CLEAR_CONF_TRIGGER_PASSED(x) x &= ~(1 << 4U)
#define CLEAR_CONF_TRIGGER_TRIGGERED(x) x &= ~(1 << 5U)
#define CLEAR_CONF_TRIGGER_ALERT(x) x &= ~(1 << 6U)
#define CLEAR_CONF_TRIGGER_RESULT(x) x &= ~(1 << 9U)
#define GET_CONF_MQTT_SUBSCRIBE(x) ((x) & 0b1)
#define GET_CONF_MQTT_HAD(x) ((x >> 1U) & 0b1)
#define GET_CONF_MQTT_ADDRESS_ERROR(x) ((x >> 8U) & 0b1)
#define GET_CONF_MQTT_CONNECT_ERROR(x) ((x >> 9U) & 0b1)
#define GET_CONF_MQTT_CONNECT_ERROR_LOG(x) ((x >> 10U) & 0b1)
#define GET_CONF_MQTT_SUBSCRIBE_ERROR(x) ((x >> 11U) & 0b1)
#define GET_CONF_MQTT_SEMAPHORE_ERROR_LOG(x) ((x >> 12U) & 0b1)
#define SET_CONF_MQTT_SUBSCRIBE(x) x |= 1
#define SET_CONF_MQTT_HAD(x) x |= (1 << 1U)
#define SET_CONF_MQTT_ADDRESS_ERROR(x) x |= (1 << 8U)
#define SET_CONF_MQTT_CONNECT_ERROR(x) x |= (1 << 9U)
#define SET_CONF_MQTT_CONNECT_ERROR_LOG(x) x |= (1 << 10U)
#define SET_CONF_MQTT_SUBSCRIBE_ERROR(x) x |= (1 << 11U)
#define SET_CONF_MQTT_SEMAPHORE_ERROR_LOG(x) x |= (1 << 12U)
#define CLEAR_CONF_MQTT_SUBSCRIBE(x) x &= ~1
#define CLEAR_CONF_MQTT_HAD(x) x &= ~(1 << 1U)
#define CLEAR_CONF_MQTT_ADDRESS_ERROR(x) x &= ~(1 << 8U)
#define CLEAR_CONF_MQTT_CONNECT_ERROR(x) x &= ~(1 << 9U)
#define CLEAR_CONF_MQTT_CONNECT_ERROR_LOG(x) x &= ~(1 << 10U)
#define CLEAR_CONF_MQTT_SUBSCRIBE_ERROR(x) x &= ~(1 << 11U)
#define CLEAR_CONF_MQTT_SEMAPHORE_ERROR_LOG(x) x &= ~(1 << 12U)
#define GET_ZONE_ALARM(x) ((x >> 1U) & 0b1)
#define GET_ZONE_ERROR(x) ((x >> 5U) & 0b1)
#define GET_ZONE_QUEUED(x) ((x >> 6U) & 0b1)
#define GET_ZONE_FULL_FIFO(x) ((x >> 7U) & 0b1)
#define SET_ZONE_ALARM(x) x |= (1 << 1U)
#define SET_ZONE_ERROR(x) x |= (1 << 5U)
#define SET_ZONE_QUEUED(x) x |= (1 << 6U)
#define SET_ZONE_FULL_FIFO(x) x |= (1 << 7U)
#define CLEAR_ZONE_ALARM(x) x &= ~(1 << 1U)
#define CLEAR_ZONE_ERROR(x) x &= ~(1 << 5U)
#define CLEAR_ZONE_QUEUED(x) x &= ~(1 << 6U)
#define CLEAR_ZONE_FULL_FIFO(x) x &= ~(1 << 7U)
#define GET_GROUP_ARMED(x) ((x) & 0b1)
#define GET_GROUP_ALARM(x) ((x >> 1U) & 0b1)
#define GET_GROUP_WAIT_AUTH(x) ((x >> 2U) & 0b1)
#define GET_GROUP_ARMED_HOME(x) ((x >> 3U) & 0b1)
#define GET_GROUP_DISABLED_FLAG(x) ((x >> 7U) & 0b1)
#define SET_GROUP_ARMED(x) x |= 1
#define SET_GROUP_ALARM(x) x |= (1 << 1U)
#define SET_GROUP_WAIT_AUTH(x) x |= (1 << 2U)
#define SET_GROUP_ARMED_HOME(x) x |= (1 << 3U)
#define SET_GROUP_DISABLED_FLAG(x) x |= (1 << 7U)
#define CLEAR_GROUP_ARMED(x) x &= ~1
#define CLEAR_GROUP_ALARM(x) x &= ~(1 << 1U)
#define CLEAR_GROUP_WAIT_AUTH(x) x &= ~(1 << 2U)
#define CLEAR_GROUP_ARMED_HOME(x) x &= ~(1 << 3U)
#define CLEAR_GROUP_DISABLED_FLAG(x) x &= ~(1 << 7U)
#define GET_NODE_ENABLED(x) ((x) & 0b1)
#define GET_NODE_GROUP(x) ((x >> 1U) & 0b1111)
#define GET_NODE_BATT_LOW(x) ((x >> 5U) & 0b1)
#define GET_NODE_MQTT(x) ((x >> 7U) & 0b1)
#define SET_NODE_ENABLED(x) x |= 1
#define SET_NODE_GROUP(x,y) x = (((x)&(0b1111111111100001))|(((y & 0b1111) << 1U)&(0b0000000000011110)))
#define SET_NODE_BATT_LOW(x) x |= (1 << 5U)
#define SET_NODE_MQTT(x) x |= (1 << 7U)
#define CLEAR_NODE_ENABLED(x) x &= ~1
#define CLEAR_NODE_BATT_LOW(x) x &= ~(1 << 5U)
#define CLEAR_NODE_MQTT(x) x &= ~(1 << 7U)
// Helper macros. Do not use in functions parameter!
#define ARRAY_SIZE(x) sizeof(x)/sizeof(x[0])
// Global vars
char tmpLog[LOGGER_MSG_LENGTH]; // Temporary logger string
// RTC related
static RTCDateTime timespec;
time_t startTime; // OHS start timestamp variable
// RTC last Vbat value
float rtcVbat;
// Ethernet
uint8_t macAddr[6];
// Arm type enum
typedef enum {
armAway = 0,
armHome
} armType_t;
// MQTT type enum
typedef enum {
typeGroup = 0,
typeZone,
typeSensor,
typeSystem
} mqttPubType_t;
// MQTT function enum
typedef enum {
functionState = 0,
functionValue,
functionName,
functionHAD
} mqttPubFunction_t;
// time_t conversion
union time_tag {
char ch[4];
time_t val;
} timeConv;
// float conversion
union float_tag {
uint8_t byte[4];
float val;
} floatConv;
// uint32_t conversion
union uint32_tag {
uint8_t byte[4];
uint32_t val;
} uint32Conv;
// Zones alarm events
#define ALARM_EVENT_FIFO_SIZE 10
typedef struct {
uint16_t zone;
char type;
} alarmEvent_t;
// Logger events
#define LOGGER_FIFO_SIZE 20
typedef struct {
time_t timestamp;
char text[LOGGER_MSG_LENGTH];
} loggerEvent_t;
// Alert events
#define ALERT_FIFO_SIZE 5
typedef struct {
char text[LOGGER_MSG_LENGTH];
uint8_t flag;
} alertEvent_t;
// Registration events
#define REG_FIFO_SIZE 10
typedef struct {
char type;
uint8_t address;
char function;
uint8_t number;
uint16_t setting;
char name[NAME_LENGTH];
uint16_t dummyAlign;
} registrationEvent_t;
// Sensor events
#define SENSOR_FIFO_SIZE 10
typedef struct {
uint8_t address; // = 0;
char function; // = ' ';
uint8_t number; // = 0;
float value; // = 0.0;
} sensorEvent_t;
// Trigger events
#define TRIGGER_FIFO_SIZE 20 // To accommodate various sources like zones, groups, sensors
typedef struct {
char type; // = 'S';
uint8_t address; // = 0;
char function; // = ' ';
uint8_t number; // = 0;
float value; // = 0.0;
} triggerEvent_t;
// MQTT events
#define MQTT_FIFO_SIZE 20 // To accommodate various sources like zones, groups, sensors
typedef struct {
mqttPubType_t type; // Group, Sensor, Zone, System
uint8_t number; // index
mqttPubFunction_t function; // Name, Value, State, Arm state
uint8_t extra; // Extra values
} mqttEvent_t;
// TCL callback
typedef void (*script_cb_t) (char *result);
void script_cb(script_cb_t ptrFunc(char *result), char *result) {
ptrFunc(result);
}
// Script events
#define SCRIPT_FIFO_SIZE 5
typedef struct {
char *cmdP;
uint8_t flags;
void *callback;
void **result;
} scriptEvent_t;
// Script ll
struct scriptLL_t{
char *name;
char *cmd;
struct scriptLL_t *next;
};
struct scriptLL_t *scriptLL = NULL; // Holds LL
struct scriptLL_t *scriptp = NULL; // Used as temp pointer
// Alerts
typedef struct {
char name[6];
} alertType_t;
// Logger keeps info about this as bit flags of uint8_t, maximum number of alert types is 8 bits(uint8_t).
const alertType_t alertType[] = {
// 1234567890
{ "SMS" },
{ "Page" },
{ "Email" },
{ "MQTT" }
};
// Check alertType size
typedef char check_alertType[ARRAY_SIZE(alertType) <= 8 ? 1 : -1];
// Logger message text to match alert, maximum number of alerts is number of bits in uint32_t
const char alertDef[][3] = {
"SS", "SX", "SB", "SA", "SR",
"GS", "GD", "GA",
"ZP", "ZT", "ZO",
"AA", "AH", "AD", "AU", "AF",
"D"
};
// Check alertDef size
typedef char check_alertDef[ARRAY_SIZE(alertDef) <= 32 ? 1 : -1];
/*
* Mailboxes
*/
static msg_t alarmEvent_mb_buffer[ALARM_EVENT_FIFO_SIZE];
static MAILBOX_DECL(alarmEvent_mb, alarmEvent_mb_buffer, ALARM_EVENT_FIFO_SIZE);
static msg_t logger_mb_buffer[LOGGER_FIFO_SIZE];
static MAILBOX_DECL(logger_mb, logger_mb_buffer, LOGGER_FIFO_SIZE);
static msg_t registration_mb_buffer[REG_FIFO_SIZE];
static MAILBOX_DECL(registration_mb, registration_mb_buffer, REG_FIFO_SIZE);
static msg_t sensor_mb_buffer[SENSOR_FIFO_SIZE];
static MAILBOX_DECL(sensor_mb, sensor_mb_buffer, SENSOR_FIFO_SIZE);
static msg_t alert_mb_buffer[ALERT_FIFO_SIZE];
static MAILBOX_DECL(alert_mb, alert_mb_buffer, ALERT_FIFO_SIZE);
static msg_t script_mb_buffer[SCRIPT_FIFO_SIZE];
static MAILBOX_DECL(script_mb, script_mb_buffer, SCRIPT_FIFO_SIZE);
static msg_t trigger_mb_buffer[TRIGGER_FIFO_SIZE];
static MAILBOX_DECL(trigger_mb, trigger_mb_buffer, TRIGGER_FIFO_SIZE);
static msg_t mqtt_mb_buffer[MQTT_FIFO_SIZE];
static MAILBOX_DECL(mqtt_mb, mqtt_mb_buffer, MQTT_FIFO_SIZE);
/*
* Pools
*/
static alarmEvent_t alarmEvent_pool_queue[ALARM_EVENT_FIFO_SIZE];
static MEMORYPOOL_DECL(alarmEvent_pool, sizeof(alarmEvent_t), PORT_NATURAL_ALIGN, NULL);
static loggerEvent_t logger_pool_queue[LOGGER_FIFO_SIZE];
static MEMORYPOOL_DECL(logger_pool, sizeof(loggerEvent_t), PORT_NATURAL_ALIGN, NULL);
static registrationEvent_t registration_pool_queue[REG_FIFO_SIZE];
static MEMORYPOOL_DECL(registration_pool, sizeof(registrationEvent_t), PORT_NATURAL_ALIGN, NULL);
static sensorEvent_t sensor_pool_queue[SENSOR_FIFO_SIZE];
static MEMORYPOOL_DECL(sensor_pool, sizeof(sensorEvent_t), PORT_NATURAL_ALIGN, NULL);
static alertEvent_t alert_pool_queue[ALERT_FIFO_SIZE];
static MEMORYPOOL_DECL(alert_pool, sizeof(alertEvent_t), PORT_NATURAL_ALIGN, NULL);
static scriptEvent_t script_pool_queue[SCRIPT_FIFO_SIZE];
static MEMORYPOOL_DECL(script_pool, sizeof(scriptEvent_t), PORT_NATURAL_ALIGN, NULL);
static sensorEvent_t trigger_pool_queue[TRIGGER_FIFO_SIZE];
static MEMORYPOOL_DECL(trigger_pool, sizeof(triggerEvent_t), PORT_NATURAL_ALIGN, NULL);
static mqttEvent_t mqtt_pool_queue[MQTT_FIFO_SIZE];
static MEMORYPOOL_DECL(mqtt_pool, sizeof(mqttEvent_t), PORT_NATURAL_ALIGN, NULL);
// Triggers
typedef struct {
// |- Off time: 0 Seconds, 01 Minutes,
// ||- 10 Hours, 11 Days
// |||-
// ||||-
// |||||-
// ||||||-
// |||||||- Script evaluated
// ||||||||- Pass off 00 no , 01 yes , 10 timer
// |||||||| |-
// |||||||| ||- Logging enabled
// |||||||| |||- Is triggered
// |||||||| ||||- Passed
// |||||||| |||||- Pass once / pass always
// |||||||| ||||||- Pass
// |||||||| |||||||- Pass value or constant
// |||||||| ||||||||- Enabled
// 54321098 76543210
uint16_t setting; //0b000000000 << 8 | B00000000;
uint8_t address; //
char type; //
char function; //
uint8_t number; //
uint8_t condition; // triggerCondition
float value; //
float constantOn; //
float constantOff; //
uint8_t toAddress; //
char toFunction; //
uint8_t toNumber; //
uint8_t offTime; //
uint32_t nextOff; //
char name[NAME_LENGTH];
char evalScript[NAME_LENGTH];
float hysteresis; //
} trigger_t;
const char triggerCondition[][4] = {
"any", "=" , "<>", "<", ">"
};
const char triggerPassOffType[][6] = {
"no", "yes", "timer"
};
const char triggerPassType[][5] = {
"no", "yes", "once"
};
const char groupState[][11] = {
// 12345678901234567890
"disarmed",
"armed away",
"armed home"
};
const char zoneState[][7] = {
// 1234567890
"OK",
"alarm",
"tamper"
};
// Timers
typedef struct {
// |- Run type: 0 Seconds, 01 Minutes,
// ||- 10 Hours, 11 Days
// |||- Period type: 0 Seconds, 01 Minutes,
// ||||- 10 Hours, 11 Days
// |||||- Triggered
// ||||||- Script evaluated
// |||||||- Script result
// ||||||||- Monday
// |||||||| |- Tuesday
// |||||||| ||- Wednesday
// |||||||| |||- Thursday
// |||||||| ||||- Friday
// |||||||| |||||- Saturday
// |||||||| ||||||- Sunday
// |||||||| |||||||- Calendar / Period
// |||||||| ||||||||- Enabled
// 54321098 76543210
uint16_t setting; //B00000000 << 8 | B00000000;
uint8_t periodTime; // period interval
uint16_t startTime; // for calendar timer in minutes 0 - 1440
uint8_t runTime; // runtime interval
float constantOn; // value to pass
float constantOff; // value to pass
uint8_t toAddress;
char toFunction;
uint8_t toNumber;
uint32_t nextOn;
uint32_t nextOff;
char name[NAME_LENGTH];
char evalScript[NAME_LENGTH];
} calendar_t; // timer_t used by ChibiOS
// MQTT struct
typedef struct {
char address[URL_LENGTH];
char user[NAME_LENGTH];
char password[NAME_LENGTH];
uint16_t port;
uint16_t setting;
} mqtt_conf_t;
// Zone struct
typedef struct {
char name[NAME_LENGTH];
uint16_t setting;
uint8_t address;
} zone_conf_t;
// Group struct
typedef struct {
char name[NAME_LENGTH];
uint16_t setting;
} group_conf_t;
// Contact struct
typedef struct {
char name[NAME_LENGTH];
char phone[PHONE_LENGTH];
char email[EMAIL_LENGTH];
uint8_t setting;
} contact_conf_t;
// Key struct
typedef struct {
uint32_t value;
uint8_t setting;
uint8_t contact;
} key_conf_t;
// Configuration struct
typedef struct {
uint8_t versionMajor;
uint8_t versionMinor;
uint16_t logOffset; // FRAM position
uint8_t armDelay; // 0.25 seconds
uint8_t autoArm; // minutes
uint8_t openAlarm; // minutes
char dateTimeFormat[NAME_LENGTH];
// TODO OHS Dynamic zones should not be stored in conf? Or just clear IS PRESENT flag on start.
uint16_t zone[ALARM_ZONES];
char zoneName[ALARM_ZONES][NAME_LENGTH];
uint8_t zoneAddress[ALARM_ZONES-HW_ZONES]; // Only for remote zone address
group_conf_t group[ALARM_GROUPS];
contact_conf_t contact[CONTACTS_SIZE];
key_conf_t key[KEYS_SIZE];
uint32_t dummy[3];
char SNTPAddress[URL_LENGTH];
uint8_t timeStdWeekNum;//First, Second, Third, Fourth, or Last week of the month
uint8_t timeStdDow; //day of week, 1=Sun, 2=Mon, ... 7=Sat
uint8_t timeStdMonth; //1=Jan, 2=Feb, ... 12=Dec
uint8_t timeStdHour; //0-23
int16_t timeStdOffset; //offset from UTC in minutes
uint8_t timeDstWeekNum;//First, Second, Third, Fourth, or Last week of the month
uint8_t timeDstDow; //day of week, 1=Sun, 2=Mon, ... 7=Sat
uint8_t timeDstMonth; //1=Jan, 2=Feb, ... 12=Dec
uint8_t timeDstHour; //0-23
int16_t timeDstOffset; //offset from UTC in minutes
char SMTPAddress[URL_LENGTH];
uint16_t SMTPPort;
char SMTPUser[EMAIL_LENGTH];
char SMTPPassword[NAME_LENGTH];
char user[NAME_LENGTH];
char password[NAME_LENGTH];
uint8_t tclSetting; // TCL flags
uint16_t tclIteration; // Number of allowed loops
uint8_t systemFlags;
calendar_t timer[TIMER_SIZE];
trigger_t trigger[TRIGGER_SIZE];
char radioKey[RADIO_KEY_SIZE];
mqtt_conf_t mqtt;
uint32_t alert[ARRAY_SIZE(alertType)];
} config_t;
config_t conf __attribute__((section(".ram4")));
// Check conf size fits to backup SRAM
typedef char check_conf[sizeof(conf) <= BACKUP_SRAM_SIZE ? 1 : -1];
// Group runtime variables
typedef struct {
uint8_t setting;
uint8_t armDelay;
} group_t;
group_t group[ALARM_GROUPS] __attribute__((section(".ram4")));
// Check group size fits to backup SRAM
typedef char check_group[sizeof(group) <= STM32_RTC_STORAGE_SIZE ? 1 : -1];
// Zone runtime variables
typedef struct {
time_t lastPIR;
time_t lastOK;
char lastEvent;
uint8_t setting;
char eventSent; // Cache lastEvent to release stress from triggers, MQTT, ...
} zone_t;
zone_t zone[ALARM_ZONES] __attribute__((section(".ram4")));
// Flags runtime variables
/*
typedef struct {
uint16_t flags;
} flags_t;
flags_t flags;
*/
// Dynamic nodes
typedef struct {
uint8_t address; //= 0;
char type; //= 'K/S/I';
char function;//= ' ';
uint8_t number; //= 0;
float value; // = 0;
time_t lastOK; // = 0;
void *queue; //
// |- MQTT publish
// ||- MQTT HAD
// |||- Battery low flag, for battery type node
// |||||||- Group number
// |||||||- 0 .. 15
// |||||||-
// |||||||-
// ||||||||- Enabled
// 76543210
uint16_t setting;// = B00011110; // 2 bytes to store also zone setting
char name[NAME_LENGTH]; // = "";
} node_t;
node_t node[NODE_SIZE] __attribute__((section(".ram4")));
/*
* Initialize node runtime struct
*/
void initRuntimeNodes(void){
for(uint8_t i = 0; i < NODE_SIZE; i++) {
node[i].address = 0;
node[i].function = '\0';
node[i].lastOK = 0;
node[i].name[0] = '\0';
node[i].number = 0;
node[i].queue = NULL;
node[i].setting = 0b00011110;
node[i].type = '\0';
node[i].value = 0;
}
}
/*
* Initialize group runtime struct
*/
void initRuntimeGroups(void){
for(uint8_t i = 0; i < ALARM_GROUPS; i++) {
// |- Disabled group log once flag
// ||- Free
// |||- Free
// ||||- Free
// |||||- Armed Home
// ||||||- Waiting for authorization
// |||||||- Alarm
// ||||||||- Armed
// 76543210
group[i].setting = 0b00000000;
group[i].armDelay = 0;
}
}
/*
* Initialize zone runtime struct
*/
void initRuntimeZones(void){
for(uint8_t i = 0; i < ALARM_ZONES; i++) {
zone[i].lastPIR = startTime;
zone[i].lastOK = startTime;
zone[i].lastEvent = 'N';
zone[i].eventSent = 'N';
// |- Full FIFO queue flag
// ||- Message queue
// |||- Error flag, for remote zone
// ||||- Free
// |||||- Free
// ||||||- Free
// |||||||- Alarm
// ||||||||- Free
// 76543210
zone[i].setting = 0b00000000;
// Force disconnected and OK to all remote zones
if (i >= HW_ZONES) {
CLEAR_CONF_ZONE_IS_PRESENT(conf.zone[i]);
conf.zoneAddress[i - HW_ZONES] = 0;
zone[i].lastEvent = 'O';
}
}
}
/*
* Write to backup SRAM
*/
uint16_t writeToBkpSRAM(uint8_t *data, uint16_t size, uint16_t offset){
osalDbgAssert(((size + offset) < BACKUP_SRAM_SIZE), "BkpSRAM out of region");
uint16_t i = 0;
uint8_t *baseAddress = (uint8_t *) BKPSRAM_BASE;
for(i = 0; i < size; i++) {
*(baseAddress + offset + i) = *(data + i);
}
return i;
}
/*
* Read from backup SRAM
*/
uint16_t readFromBkpSRAM(uint8_t *data, uint16_t size, uint16_t offset){
osalDbgAssert(((size + offset) < BACKUP_SRAM_SIZE), "BkpSRAM out of region");
uint16_t i = 0;
uint8_t *baseAddress = (uint8_t *) BKPSRAM_BASE;
for(i = 0; i < size; i++) {
*(data + i) = *(baseAddress + offset + i);
}
return i;
}
/*
* Write to backup RTC
*/
uint8_t writeToBkpRTC(uint8_t *data, uint8_t size, uint8_t offset){
osalDbgAssert(((size + offset) < STM32_RTC_STORAGE_SIZE), "BkpRTC out of region");
osalDbgAssert(!(offset % 4), "BkpRTC misaligned"); // Offset is not aligned to to unint32_t registers
uint8_t i = 0;
volatile uint32_t *RTCBaseAddress = &(RTC->BKP0R);
uint32_t tmp = 0;
for(i = 0; i < size; i++) {
tmp |= (*(data + i) << ((i % 4)*8));
if (((i % 4) == 3) || ((i + 1) == size)) {
*(RTCBaseAddress + offset + (i/4)) = tmp;
tmp = 0;
}
}
return i;
}
/*
* Read from backup RTC
*/
uint8_t readFromBkpRTC(uint8_t *data, uint8_t size, uint8_t offset){
osalDbgAssert(((size + offset) < STM32_RTC_STORAGE_SIZE), "BkpRTC out of region");
osalDbgAssert(!(offset % 4), "BkpRTC misaligned"); // Offset is not aligned to to unint32_t registers
uint8_t i = 0;
volatile uint32_t *RTCBaseAddress = &(RTC->BKP0R);
uint32_t tmp = 0;
for(i = 0; i < size; i++) {
if ((i % 4) == 0) { tmp = *(RTCBaseAddress + offset + (i/4)); }
*(data + i) = (tmp >> ((i % 4)*8)) & 0xFF;
}
return i;
}
/*
* Set conf struct default values
*/
void setConfDefault(void){
conf.versionMajor = OHS_MAJOR;
conf.versionMinor = OHS_MINOR;
conf.logOffset = 0;
conf.armDelay = 80;
conf.autoArm = 20;
conf.openAlarm = 20;
strcpy(conf.dateTimeFormat, "%T %a %d.%m.%Y");
for(uint8_t i = 0; i < ALARM_ZONES; i++) {
// Zones setup
// |- HW type Digital 0/ Analog 1
// ||- Present - connected
// |||- MQTT publish
// ||||- MQTT HAD // - was Remote zone
// |||||- Free - was Battery powered zone, they don't send OK, only PIR or Tamper.
// ||||||- Logical type balanced 1/ unbalanced 0. Only Analog zones can be balanced.
// |||||||- PIR as Tamper
// ||||||||- Still open alarm
// |||||||| |- Arm Home zone
// |||||||| |||- Auth time
// |||||||| |||- 0-3x the default time
// |||||||| |||||||- Group number
// |||||||| |||||||- 0 .. 15
// |||||||| |||||||-
// |||||||| |||||||-
// |||||||| ||||||||- Enabled
// 54321098 76543210
switch(i){
case 0 ... 9:
conf.zone[i] = 0b11000100 << 8 | 0b00011110; // Analog sensor
break;
case 10 :
conf.zone[i] = 0b01000010 << 8 | 0b00011110; // BOX Tamper
break;
default:
conf.zone[i] = 0b00000000 << 8 | 0b00011110; // Other zones
conf.zoneAddress[i-HW_ZONES] = 0;
break;
}
memset(&conf.zoneName[i][0], 0x00, NAME_LENGTH);
}
// Let's name special BOX contacts
strcpy(conf.zoneName[10], "Box tamper");
for(uint8_t i = 0; i < ALARM_GROUPS; i++) {
// ||||- disarm chain
// ||||
// ||||
// ||||
// ||||||||- arm chain
// ||||||||
// ||||||||
// ||||||||
// |||||||| |- MQTT publish
// |||||||| ||- Free
// |||||||| |||- Auto arm
// |||||||| ||||- PIR signal output 1
// |||||||| |||||- PIR signal output 2
// |||||||| ||||||- Tamper signal output 1
// |||||||| |||||||- Tamper signal output 2
// |||||||| ||||||||- Enabled
// 54321098 76543210
conf.group[i].setting = 0b11111111 << 8 | 0b00000000;
//strcpy(conf.groupName[i], NOT_SET);
memset(&conf.group[i].name[0], 0x00, NAME_LENGTH);
}
for(uint8_t i = 0; i < CONTACTS_SIZE; i++) {
// group 16 and disabled
conf.contact[i].setting = 0b00011110;
memset(&conf.contact[i].name[0], 0x00, NAME_LENGTH);
memset(&conf.contact[i].phone[0], 0x00, PHONE_LENGTH);
memset(&conf.contact[i].email[0], 0x00, EMAIL_LENGTH);
}
for(uint8_t i = 0; i < KEYS_SIZE; i++) {
// disabled
conf.key[i].setting = 0b00000000;
conf.key[i].value = 0xFFFFFFFF; // Set key value to FF
conf.key[i].contact = DUMMY_NO_VALUE;
}
for(uint8_t i = 0; i < ARRAY_SIZE(alertType); i++) {
conf.alert[i] = 0;
}
strcpy(conf.SNTPAddress, "time.google.com");
conf.timeStdWeekNum = 0; //First, Second, Third, Fourth, or Last week of the month