This repository has been archived by the owner on Apr 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
AS.cpp
1196 lines (990 loc) · 50.3 KB
/
AS.cpp
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
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin driver implementation
// 2013-08-03 <[email protected]> Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
//- AskSin protocol functions ---------------------------------------------------------------------------------------------
//- with a lot of support from martin876 at FHEM forum
//- -----------------------------------------------------------------------------------------------------------------------
#define AS_DBG
#define RV_DBG_EX
#include "AS.h"
waitTimer cnfTmr; // config timer functionality
waitTimer pairTmr; // pair timer functionality
// public: //---------------------------------------------------------------------------------------------------------
AS::AS() {
}
void AS::init(void) {
#ifdef AS_DBG // only if cc debug is set
dbgStart(); // serial setup
dbg << F("AS.\n"); // ...and some information
#endif
initLeds(); // initialize the leds
initConfKey(); // initialize the port for getting config key interrupts
ee.init(); // eeprom init
cc.init(); // init the rf module
sn.init(this); // send module
rv.init(this); // receive module
rg.init(this); // module registrar
confButton.init(this); // config button
pw.init(this); // power management
bt.init(this); // battery check
initMillis(); // start the millis counter
// everything is setuped, enable RF functionality
enableGDO0Int(); // enable interrupt to get a signal while receiving data
}
void AS::poll(void) {
// check if something received
if (ccGetGDO0()) { // check if something was received
cc.rcvData(rv.buf); // copy the data into the receiver module
if (rv.hasData) decode(rv.buf); // decode the string
}
// handle send and receive buffer
if (rv.hasData) rv.poll(); // check if there is something in the received buffer
if (sn.active) sn.poll(); // check if there is something to send
// handle the slice send functions
if (stcSlice.active) sendSliceList(); // poll the slice list send function
if (stcPeer.active) sendPeerMsg(); // poll the peer message sender
// time out the config flag
if (cFlag.active) { // check only if we are still in config mode
if (cnfTmr.done()) cFlag.active = 0; // when timer is done, set config flag to inactive
}
// time out the pairing timer
if (pairActive) {
if (pairTmr.done()) {
pairActive = 0;
isEmpty(MAID, 3)? ld.set(pair_err) : ld.set(pair_suc);
}
}
// regular polls
rg.poll(); // poll the channel module handler
confButton.poll(); // poll the config button
ld.poll(); // poll the led's
bt.poll(); // poll the battery check
// check if we could go to standby
pw.poll(); // poll the power management
// some sanity poll routines
}
// - send functions --------------------------------
void AS::sendDEVICE_INFO(void) {
// description --------------------------------------------------------
// reID toID fw type serial class pCnlA pCnlB unknown
// l> 1A 94 84 00 1F B7 4A 01 02 04 15 00 6C 4B 45 51 30 32 33 37 33 39 36 10 41 01 00
// do something with the information ----------------------------------
uint8_t xCnt;
if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x0A)) xCnt = rv.mBdy.mLen; // send counter - is it an answer or a initial message
else xCnt = sn.msgCnt++;
sn.mBdy.mLen = 0x1a;
sn.mBdy.mCnt = xCnt;
sn.mBdy.mFlg.CFG = 0;
sn.mBdy.mFlg.BIDI = (isEmpty(MAID,3))?0:1;
sn.mBdy.mTyp = 0x00;
memcpy(sn.mBdy.reID,HMID,3);
memcpy(sn.mBdy.toID,MAID,3);
memcpy_P(sn.buf+10,devDef.devIdnt,3);
memcpy(sn.buf+13,HMSR,10);
memcpy_P(sn.buf+23,devDef.devIdnt+3,4);
sn.active = 1; // fire the message
pairActive = 1; // set pairing flag
pairTmr.set(20000);
ld.set(pairing); // and visualize the status
// --------------------------------------------------------------------
}
void AS::sendACK(void) {
// description --------------------------------------------------------
// reID toID ACK
// l> 0A 24 80 02 1F B7 4A 63 19 63 00
// do something with the information ----------------------------------
if (!rv.mBdy.mFlg.BIDI) return; // overcome the problem to answer from a user class on repeated key press
sn.mBdy.mLen = 0x0a;
sn.mBdy.mCnt = rv.mBdy.mCnt;
sn.mBdy.mTyp = 0x02;
memcpy(sn.mBdy.reID, HMID, 3);
memcpy(sn.mBdy.toID, rv.mBdy.reID, 3);
sn.mBdy.by10 = 0x00;
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendACK_STATUS(uint8_t cnl, uint8_t stat, uint8_t dul) {
// description --------------------------------------------------------
// l> 0B 12 A4 40 23 70 EC 1E 7A AD 01 02
// reID toID ACK Cnl Stat DUL RSSI
// l> 0F 12 80 02 1E 7A AD 23 70 EC 01 01 BE 20 27 CC - dimmer
// l> 0E 5C 80 02 1F B7 4A 63 19 63 01 01 C8 00 42 - pcb relay
//
// b> 0F 13 84 10 1E 7A AD 00 00 00 06 01 00 00 80 00
// - DUL = Down 0x20, UP 0x10, LowBat 0x80
// do something with the information ----------------------------------
if (!rv.mBdy.mFlg.BIDI) return; // overcome the problem to answer from a user class on repeated key press
sn.mBdy.mLen = 0x0e;
sn.mBdy.mCnt = rv.mBdy.mCnt;
sn.mBdy.mFlg.BIDI = 0;
sn.mBdy.mTyp = 0x02;
memcpy(sn.mBdy.reID, HMID, 3);
memcpy(sn.mBdy.toID, rv.mBdy.reID, 3);
sn.mBdy.by10 = 0x01;
sn.mBdy.by11 = cnl;
sn.mBdy.pyLd[0] = stat;
sn.mBdy.pyLd[1] = dul | (bt.getStatus() << 7);
sn.mBdy.pyLd[2] = cc.rssi;
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendNACK(void) {
// description --------------------------------------------------------
// reID toID NACK
// l> 0A 24 80 02 1F B7 4A 63 19 63 80
// do something with the information ----------------------------------
sn.mBdy.mLen = 0x0a;
sn.mBdy.mCnt = rv.mBdy.mLen;
sn.mBdy.mTyp = 0x02;
memcpy(sn.mBdy.reID,HMID,3);
memcpy(sn.mBdy.toID,rv.mBdy.reID,3);
sn.mBdy.by10 = 0x80;
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendNACK_TARGET_INVALID(void) {
// description --------------------------------------------------------
// reID toID ACK
// l> 0A 24 80 02 1F B7 4A 63 19 63 84
// do something with the information ----------------------------------
sn.mBdy.mLen = 0x0a;
sn.mBdy.mCnt = rv.mBdy.mLen;
sn.mBdy.mTyp = 0x02;
memcpy(sn.mBdy.reID,HMID,3);
memcpy(sn.mBdy.toID,rv.mBdy.reID,3);
sn.mBdy.by10 = 0x84;
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendINFO_ACTUATOR_STATUS(uint8_t cnl, uint8_t stat, uint8_t cng) {
// description --------------------------------------------------------
// l> 0B 40 B0 01 63 19 63 1F B7 4A 01 0E (148552)
// reID toID cnl stat cng RSSI
// l> 0E 40 A4 10 1F B7 4A 63 19 63 06 01 00 00 48 (148679)
// l> 0A 40 80 02 63 19 63 1F B7 4A 00 (148804)
// do something with the information ----------------------------------
sn.mBdy.mLen = 0x0e;
if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x0e)) {
sn.mBdy.mCnt = rv.mBdy.mCnt;
} else {
sn.mBdy.mCnt = sn.msgCnt++;
}
sn.mBdy.mFlg.BIDI = (isEmpty(MAID,3))?0:1;
sn.mBdy.mTyp = 0x10;
memcpy(sn.mBdy.reID, HMID, 3);
memcpy(sn.mBdy.toID, MAID, 3);
sn.mBdy.by10 = 0x06;
sn.mBdy.by11 = cnl;
sn.mBdy.pyLd[0] = stat;
sn.mBdy.pyLd[1] = cng; // | (bt.getStatus() << 7);
sn.mBdy.pyLd[2] = cc.rssi;
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendINFO_TEMP(void) {
//"10;p01=0A" => { txt => "INFO_TEMP", params => {
//SET => '2,4,$val=(hex($val)>>10)&0x3F',
//ACT => '2,4,$val=hex($val)&0x3FF',
//ERR => "6,2",
//VALVE => "6,2",
//MODE => "6,2" } },
// --------------------------------------------------------------------
}
void AS::sendHAVE_DATA(void) {
//"12" => { txt => "HAVE_DATA"},
// --------------------------------------------------------------------
}
void AS::sendSWITCH(void) {
//"3E" => { txt => "SWITCH" , params => {
//DST => "00,6",
//UNKNOWN => "06,2",
//CHANNEL => "08,2",
//COUNTER => "10,2", } },
// --------------------------------------------------------------------
}
void AS::sendTimeStamp(void) {
//"3F" => { txt => "TimeStamp" , params => {
//UNKNOWN => "00,4",
//TIME => "04,2", } },
// --------------------------------------------------------------------
}
void AS::sendREMOTE(uint8_t cnl, uint8_t burst, uint8_t *pL) {
// description --------------------------------------------------------
// reID toID BLL Cnt
// l> 0B 0A A4 40 23 70 EC 1E 7A AD 02 01
// l> 0F 0A 80 02 1E 7A AD 23 70 EC 01 01 14 10 32 A4
// l> 0B 0B B0 40 23 70 EC 1F B7 4A 02 01
// l> 0E 0B 80 02 1F B7 4A 23 70 EC 01 01 C8 80 21
// l> 0F 0B A4 10 1E 7A AD 63 19 63 06 01 C8 00 80 C8
// l> 0A 0B 80 02 63 19 63 1E 7A AD 00
// do something with the information ----------------------------------
// BUTTON = bit 0 - 5
// LONG = bit 6
// LOWBAT = bit 7
stcPeer.pL = pL;
stcPeer.lenPL = 2;
stcPeer.cnl = cnl;
stcPeer.burst = burst;
stcPeer.bidi = 1; // depends on BLL, long didn't need ack
stcPeer.mTyp = 0x40;
stcPeer.active = 1;
// --------------------------------------------------------------------
}
void AS::sendSensor_event(uint8_t cnl, uint8_t burst, uint8_t *pL) {
// description --------------------------------------------------------
// reID toID BLL Cnt Val
// l> 0C 0A A4 41 23 70 EC 1E 7A AD 02 01 200
// do something with the information ----------------------------------
//"41" => { txt => "Sensor_event", params => {
// BUTTON = bit 0 - 5
// LONG = bit 6
// LOWBAT = bit 7
stcPeer.pL = pL;
stcPeer.lenPL = 3;
stcPeer.cnl = cnl;
stcPeer.burst = burst;
//stcPeer.bidi = 1; // depends on BLL, long didn't need ack
stcPeer.bidi = (isEmpty(MAID,3))?0:1;
stcPeer.mTyp = 0x41;
stcPeer.active = 1;
// --------------------------------------------------------------------
}
/**
* @brief Send an event with arbitrary payload
*
* Take care when sending generic events, since there are no consistency
* checks if the specified event type and payload make any sense. Rather use
* predefined special send methods.
*
* @param cnl The channel
* @param burst Set to 1 for burst mode, or 0
* @param mTyp Event frame type
* @param len Length of payload in bytes, not more than 16
* @param pL pointer to first byte of payload
*
* @attention The payload length may not exceed 16 bytes. If a greater value
* for len is given, it is limited to 16 to prevent HM-CFG-LAN (v0.961) to crash.
*/
void AS::send_generic_event(uint8_t cnl, uint8_t burst, uint8_t mTyp, uint8_t len, uint8_t *pL) {
// description --------------------------------------------------------
// reID toID BLL Cnt Val
// l> 0C 0A A4 41 23 70 EC 1E 7A AD 02 01 200
// do something with the information ----------------------------------
if (len>16) {
#ifdef AS_DBG
dbg << "AS::send_generic_event("<<cnl<<","<<burst<<",0x"<<_HEX(&mTyp,1)<<","<<len<<",...): payload exceeds maximum length of 16\n";
#endif
len= 16;
}
stcPeer.pL = pL;
stcPeer.lenPL = len+1;
stcPeer.cnl = cnl;
stcPeer.burst = burst;
stcPeer.bidi = 1; // depends on BLL, long didn't need ack
stcPeer.bidi = (isEmpty(MAID,3))?0:1;
stcPeer.mTyp = mTyp;
stcPeer.active = 1;
// --------------------------------------------------------------------
}
void AS::sendSensorData(void) {
//"53" => { txt => "SensorData" , params => {
//CMD => "00,2",
//Fld1=> "02,2",
//Val1=> '04,4,$val=(hex($val))',
//Fld2=> "08,2",
//Val2=> '10,4,$val=(hex($val))',
//Fld3=> "14,2",
//Val3=> '16,4,$val=(hex($val))',
//Fld4=> "20,2",
//Val4=> '24,4,$val=(hex($val))'} },
// --------------------------------------------------------------------
}
void AS::sendClimateEvent(void) {
//"58" => { txt => "ClimateEvent", params => {
//CMD => "00,2",
//ValvePos => '02,2,$val=(hex($val))', } },
// --------------------------------------------------------------------
}
void AS::sendSetTeamTemp(void) {
//"59" => { txt => "setTeamTemp" , params => {
//CMD => "00,2",
//desTemp => '02,2,$val=((hex($val)>>2) /2)',
//mode => '02,2,$val=(hex($val) & 0x3)',} },
// --------------------------------------------------------------------
}
void AS::sendWeatherEvent(void) {
//"70" => { txt => "WeatherEvent", params => {
//TEMP => '00,4,$val=((hex($val)&0x3FFF)/10)*((hex($val)&0x4000)?-1:1)',
//HUM => '04,2,$val=(hex($val))', } },
// --------------------------------------------------------------------
}
// private: //---------------------------------------------------------------------------------------------------------
// - poll functions --------------------------------
void AS::sendSliceList(void) {
if (sn.active) return; // check if send function has a free slot, otherwise return
uint8_t cnt;
if (stcSlice.peer) { // INFO_PEER_LIST
cnt = ee.getPeerListSlc(stcSlice.cnl, stcSlice.curSlc, sn.buf+11); // get the slice and the amount of bytes
sendINFO_PEER_LIST(cnt); // create the body
stcSlice.curSlc++; // increase slice counter
//dbg << "peer slc: " << _HEX(sn.buf,sn.buf[0]+1) << '\n'; // write to send buffer
} else if (stcSlice.reg2) { // INFO_PARAM_RESPONSE_PAIRS
cnt = ee.getRegListSlc(stcSlice.cnl, stcSlice.lst, stcSlice.idx, stcSlice.curSlc, sn.buf+11); // get the slice and the amount of bytes
//dbg << "cnt: " << cnt << '\n';
sendINFO_PARAM_RESPONSE_PAIRS(cnt);
stcSlice.curSlc++; // increase slice counter
//dbg << "reg2 slc: " << _HEX(sn.buf,sn.buf[0]+1) << '\n'; // write to send buffer
} else if (stcSlice.reg3) { // INFO_PARAM_RESPONSE_SEQ
}
if (stcSlice.curSlc == stcSlice.totSlc) { // if everything is send, we could empty the struct
memset((void*)&stcSlice, 0, 10); // by memset
//dbg << "end: " << stcSlice.active << stcSlice.peer << stcSlice.reg2 << stcSlice.reg3 << '\n';
}
}
void AS::sendPeerMsg(void) {
uint8_t maxRetries;
if (stcPeer.bidi) maxRetries = 3;
else maxRetries = 1;
if (sn.active) return; // check if send function has a free slot, otherwise return
// first run, prepare amount of slots
if (!stcPeer.maxIdx) {
stcPeer.maxIdx = ee.getPeerSlots(stcPeer.cnl); // get amount of messages of peer channel
if (stcPeer.maxIdx == ee.countFreeSlots(stcPeer.cnl) ) { // check if at least one peer exist in db, otherwise send to master and stop function
prepPeerMsg(MAID, maxRetries);
sn.msgCnt++; // increase the send message counter
memset((void*)&stcPeer, 0, sizeof(s_stcPeer)); // clean out and return
return;
}
}
// all slots of channel processed, start next round or end processing
if (stcPeer.curIdx >= stcPeer.maxIdx) { // check if all peer slots are done
stcPeer.rnd++; // increase the round counter
if ((stcPeer.rnd >= maxRetries) || (isEmpty(stcPeer.slt,8))) { // all rounds done or all peers reached
//dbg << "through\n";
sn.msgCnt++; // increase the send message counter
memset((void*)&stcPeer, 0, sizeof(s_stcPeer)); // clean out and return
} else { // start next round
//dbg << "next round\n";
stcPeer.curIdx = 0;
}
return;
} else if ((stcPeer.curIdx) && (!sn.timeOut)) { // peer index is >0, first round done and no timeout
uint8_t idx = stcPeer.curIdx-1;
stcPeer.slt[idx >> 3] &= ~(1 << (idx & 0x07)); // clear bit, because message got an ACK
}
// set respective bit to check if ACK was received
if (!stcPeer.rnd) stcPeer.slt[stcPeer.curIdx >> 3] |= (1<<(stcPeer.curIdx & 0x07)); // set bit in slt table // clear bit in slt and increase counter
// exit while bit is not set
if (!stcPeer.slt[stcPeer.curIdx >> 3] & (1<<(stcPeer.curIdx & 0x07))) {
stcPeer.curIdx++; // increase counter for next time
return;
}
uint8_t tPeer[4]; // get the respective peer
ee.getPeerByIdx(stcPeer.cnl, stcPeer.curIdx, tPeer);
#ifdef AS_DBG
dbg << "a: " << stcPeer.curIdx << " m " << stcPeer.maxIdx << '\n';
#endif
if (isEmpty(tPeer,4)) { // if peer is 0, set done bit in slt and skip
stcPeer.slt[stcPeer.curIdx >> 3] &= ~(1<<(stcPeer.curIdx & 0x07)); // remember empty peer in slt table // clear bit in slt and increase counter
stcPeer.curIdx++; // increase counter for next time
return; // wait for next round
}
// if we are here, there is something to send
//dbg << "cnl:" << stcPeer.cnl << " cIdx:" << stcPeer.curIdx << " mIdx:" << stcPeer.maxIdx << " slt:" << _HEX(stcPeer.slt,8) << '\n';
// todo: get the respective list4 entries and take care while sending the message
// peerNeedsBurst =>{a=> 1.0,s=>0.1,l=>4,min=>0 ,max=>1 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"peer expects burst",lit=>{off=>0,on=>1}},
// expectAES =>{a=> 1.7,s=>0.1,l=>4,min=>0 ,max=>1 ,c=>'lit' ,f=>'' ,u=>'' ,d=>1,t=>"expect AES" ,lit=>{off=>0,on=>1}},
// fillLvlUpThr =>{a=> 4.0,s=>1 ,l=>4,min=>0 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,d=>1,t=>"fill level upper threshold"},
// fillLvlLoThr =>{a=> 5.0,s=>1 ,l=>4,min=>0 ,max=>255 ,c=>'' ,f=>'' ,u=>'' ,d=>1,t=>"fill level lower threshold"},
l4_0x01 = *(s_l4_0x01*)ee.getRegAddr(stcPeer.cnl, 4, stcPeer.curIdx, 0x01);
prepPeerMsg(tPeer, 1);
if (!sn.mBdy.mFlg.BIDI)
stcPeer.slt[stcPeer.curIdx >> 3] &= ~(1<<(stcPeer.curIdx & 0x07)); // clear bit, because it is a message without need to be repeated
stcPeer.curIdx++; // increase counter for next time
}
void AS::prepPeerMsg(uint8_t *xPeer, uint8_t retr) {
// description --------------------------------------------------------
// len cnt flg typ reID toID pl
// l> 0B 0A A4 40 23 70 EC 1E 7A AD 02 01
// description --------------------------------------------------------
// reID toID BLL Cnt Val
// l> 0C 0A A4 41 23 70 EC 1E 7A AD 02 01 200
// do something with the information ----------------------------------
//"41" => { txt => "Sensor_event", params => {
// BUTTON = bit 0 - 5
// LONG = bit 6
// LOWBAT = bit 7
sn.mBdy.mLen = stcPeer.lenPL +9; // set message length
sn.mBdy.mCnt = sn.msgCnt; // set message counter
sn.mBdy.mFlg.CFG = 1; sn.mBdy.mFlg.BIDI = stcPeer.bidi; // message flag
sn.mBdy.mFlg.BURST = l4_0x01.peerNeedsBurst;
sn.mBdy.mTyp = stcPeer.mTyp; // message type
//uint8_t t1[] = {0x23,0x70,0xD8};
//memcpy(sn.mBdy.reID, t1, 3); // sender id
memcpy(sn.mBdy.reID, HMID, 3); // sender id
memcpy(sn.mBdy.toID, xPeer, 3); // receiver id
sn.mBdy.by10 = stcPeer.cnl;
sn.mBdy.by10 |= (bt.getStatus() << 7); // battery bit
memcpy(sn.buf+11, stcPeer.pL, stcPeer.lenPL); // payload
sn.maxRetr = retr; // send only one time
sn.active = 1; // make send active
}
// - receive functions -----------------------------
void AS::recvMessage(void) {
uint8_t by10 = rv.mBdy.by10 -1;
uint8_t cnl1 = cFlag.cnl-1;
// check which type of message was received
if (rv.mBdy.mTyp == 0x00) { // DEVICE_INFO
// description --------------------------------------------------------
//
//
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x01)) { // CONFIG_PEER_ADD
// description --------------------------------------------------------
// Cnl PeerID PeerCnl_A PeerCnl_B
// l> 10 55 A0 01 63 19 63 01 02 04 01 01 1F A6 5C 06 05
// do something with the information ----------------------------------
ee.remPeer(rv.mBdy.by10, rv.buf+12); // first call remPeer to avoid doubles
uint8_t ret = ee.addPeer(rv.mBdy.by10, rv.buf+12); // send to addPeer function
// let module registrations know of the change
if ((ret) && (modTbl[by10].cnl)) {
modTbl[by10].mDlgt(rv.mBdy.mTyp, rv.mBdy.by10, rv.mBdy.by11, rv.buf+15, 4);
}
if ((ret) && (rv.ackRq)) sendACK(); // send appropriate answer
else if (rv.ackRq) sendNACK();
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x02)) { // CONFIG_PEER_REMOVE
// description --------------------------------------------------------
// Cnl PeerID PeerCnl_A PeerCnl_B
// l> 10 55 A0 01 63 19 63 01 02 04 01 02 1F A6 5C 06 05
// do something with the information ----------------------------------
uint8_t ret = ee.remPeer(rv.mBdy.by10,rv.buf+12); // call the remPeer function
if (rv.ackRq) sendACK(); // send appropriate answer
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x03)) { // CONFIG_PEER_LIST_REQ
// description --------------------------------------------------------
// Cnl
// l> 0B 05 A0 01 63 19 63 01 02 04 01 03
// do something with the information ----------------------------------
stcSlice.totSlc = ee.countPeerSlc(rv.mBdy.by10); // how many slices are need
stcSlice.mCnt = rv.mBdy.mCnt; // remember the message count
memcpy(stcSlice.toID, rv.mBdy.reID, 3);
stcSlice.cnl = rv.mBdy.by10; // send input to the send peer function
stcSlice.peer = 1; // set the type of answer
stcSlice.active = 1; // start the send function
// answer will send from sendsList(void)
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x04)) { // CONFIG_PARAM_REQ
// description --------------------------------------------------------
// Cnl PeerID PeerCnl ParmLst
// l> 10 04 A0 01 63 19 63 01 02 04 01 04 00 00 00 00 01
// do something with the information ----------------------------------
if ((rv.buf[16] == 3) || (rv.buf[16] == 4)) { // only list 3 and list 4 needs an peer id and idx
stcSlice.idx = ee.getIdxByPeer(rv.mBdy.by10, rv.buf+12); // get peer index
} else stcSlice.idx = 0; // otherwise peer index is 0
stcSlice.totSlc = ee.countRegListSlc(rv.mBdy.by10, rv.buf[16]); // how many slices are need
stcSlice.mCnt = rv.mBdy.mCnt; // remember the message count
memcpy(stcSlice.toID, rv.mBdy.reID, 3);
stcSlice.cnl = rv.mBdy.by10; // send input to the send peer function
stcSlice.lst = rv.buf[16]; // send input to the send peer function
stcSlice.reg2 = 1; // set the type of answer
#ifdef AS_DBG
dbg << "cnl: " << rv.mBdy.by10 << " s: " << stcSlice.idx << '\n';
dbg << "totSlc: " << stcSlice.totSlc << '\n';
#endif
if ((stcSlice.idx != 0xff) && (stcSlice.totSlc > 0)) stcSlice.active = 1; // only send register content if something is to send // start the send function
else memset((void*)&stcSlice, 0, 10); // otherwise empty variable
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x05)) { // CONFIG_START
// description --------------------------------------------------------
// Cnl PeerID PeerCnl ParmLst
// l> 10 01 A0 01 63 19 63 01 02 04 00 05 00 00 00 00 00
// do something with the information ----------------------------------
cFlag.cnl = rv.mBdy.by10; // fill structure to remember where to write
cFlag.lst = rv.buf[16];
if ((cFlag.lst == 3) || (cFlag.lst == 4)) cFlag.idx = ee.getIdxByPeer(rv.mBdy.by10, rv.buf+12);
else cFlag.idx = 0;
if (cFlag.idx != 0xff) {
cFlag.active = 1; // set active if there is no error on index
cnfTmr.set(20000); // set timeout time, will be checked in poll function
// todo: set message id flag to config in send module
}
if (rv.ackRq) sendACK(); // send appropriate answer
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x06)) { // CONFIG_END
// description --------------------------------------------------------
// Cnl
// l> 0B 01 A0 01 63 19 63 01 02 04 00 06
// do something with the information ----------------------------------
cFlag.active = 0; // set inactive
if ((cFlag.cnl == 0) && (cFlag.idx == 0)) ee.getMasterID();
// remove message id flag to config in send module
if ((cFlag.cnl > 0) && (modTbl[cnl1].cnl)) {
// check if a new list1 was written and reload, no need for reload list3/4 because they will be loaded on an peer event
if (cFlag.lst == 1) ee.getList(cFlag.cnl, 1, cFlag.idx, modTbl[cnl1].lstCnl); // load list1 in the respective buffer
modTbl[cnl1].mDlgt(0x01, 0, 0x06, NULL, 0); // inform the module of the change
}
if (rv.ackRq) sendACK(); // send appropriate answer
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x08)) { // CONFIG_WRITE_INDEX
// description --------------------------------------------------------
// Cnl Data
// l> 13 02 A0 01 63 19 63 01 02 04 00 08 02 01 0A 63 0B 19 0C 63
// do something with the information ----------------------------------
if ((cFlag.active) && (cFlag.cnl == rv.mBdy.by10)) { // check if we are in config mode and if the channel fit
ee.setListArray(cFlag.cnl, cFlag.lst, cFlag.idx, rv.buf[0]+1-11, rv.buf+12); // write the string to eeprom
if ((cFlag.cnl == 0) && (cFlag.lst == 0)) { // check if we got somewhere in the string a 0x0a, as indicator for a new masterid
uint8_t maIdFlag = 0;
for (uint8_t i = 0; i < (rv.buf[0]+1-11); i+=2) {
if (rv.buf[12+i] == 0x0a) maIdFlag = 1;
#ifdef AS_DBG
dbg << "x" << i << " :" << _HEXB(rv.buf[12+i]) << '\n';
#endif
}
if (maIdFlag) {
ee.getMasterID();
#ifdef AS_DBG
dbg << "new masterid\n" << '\n';
#endif
}
}
}
if (rv.ackRq) sendACK(); // send appropriate answer
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x09)) { // CONFIG_SERIAL_REQ
// description --------------------------------------------------------
//
// l> 0B 77 A0 01 63 19 63 01 02 04 00 09
// do something with the information ----------------------------------
sendINFO_SERIAL(); // jump to create the answer
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x0A)) { // PAIR_SERIAL
// description --------------------------------------------------------
// serial
// b> 15 93 B4 01 63 19 63 00 00 00 01 0A 4B 45 51 30 32 33 37 33 39 36
// do something with the information ----------------------------------
if (compArray(rv.buf+12,HMSR,10)) sendDEVICE_INFO(); // compare serial and send device info
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x01) && (rv.mBdy.by11 == 0x0E)) { // CONFIG_STATUS_REQUEST
// description --------------------------------------------------------
// reID toID cnl
// l> 0B 40 B0 01 63 19 63 1F B7 4A 01 0E (148552)
// l> 0E 40 A4 10 1F B7 4A 63 19 63 06 01 00 00 48 (148679)
// l> 0A 40 80 02 63 19 63 1F B7 4A 00 (148804)
// do something with the information ----------------------------------
// check if a module is registered and send the information, otherwise report an empty status
if (modTbl[by10].cnl) {
modTbl[by10].mDlgt(rv.mBdy.mTyp, rv.mBdy.by10, rv.mBdy.by11, rv.mBdy.pyLd, rv.mBdy.mLen-11);
} else {
sendINFO_ACTUATOR_STATUS(rv.mBdy.by10, 0, 0);
}
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x00)) { // ACK
// description --------------------------------------------------------
//
// l> 0A 05 80 02 63 19 63 01 02 04 00
// do something with the information ----------------------------------
if ((sn.active) && (rv.mBdy.mCnt == sn.lastMsgCnt)) sn.retrCnt = 0xff; // was an ACK to an active message, message counter is similar - set retrCnt to 255
//dbg << "act:" << sn.active << " rC:" << rv.mBdy.mLen << " sC:" << sn.lastMsgCnt << " cntr:" << sn.retrCnt << '\n';
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x01)) { // ACK_STATUS
// description --------------------------------------------------------
// <- 0B 08 B4 40 23 70 D8 1F B7 4A 02 08
// cnl stat DUL RSSI
// l> 0E 08 80 02 1F B7 4A 23 70 D8 01 01 C8 80 27
// do something with the information ----------------------------------
// DUL = UP 10, DOWN 20, LOWBAT 80
if ((sn.active) && (rv.mBdy.mLen == sn.lastMsgCnt)) sn.retrCnt = 0xff; // was an ACK to an active message, message counter is similar - set retrCnt to 255
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x02)) { // ACK2
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x04)) { // ACK_PROC
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
//Para1 => "02,4",
//Para2 => "06,4",
//Para3 => "10,4",
//Para4 => "14,2",}}, # remote?
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x80)) { // NACK
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// for test
static uint8_t x2[2];
x2[0] = 0x02;
x2[1] += 1;
sendREMOTE(1,1,x2);
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x02) && (rv.mBdy.by10 == 0x84)) { // NACK_TARGET_INVALID
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x02)) { // SET
// description --------------------------------------------------------
// cnl stat ramp dura
// l> 0E 5E B0 11 63 19 63 1F B7 4A 02 01 C8 00 00 00 00
// l> 0E 5E 80 02 1F B7 4A 63 19 63 01 01 C8 80 41
// do something with the information ----------------------------------
if (modTbl[rv.mBdy.by11-1].cnl) {
modTbl[rv.mBdy.by11-1].mDlgt(rv.mBdy.mTyp, rv.mBdy.by10, rv.mBdy.by11, rv.buf+12, rv.mBdy.mLen-11);
}
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x03)) { // STOP_CHANGE
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x04) && (rv.mBdy.by11 == 0x00)) { // RESET
// description --------------------------------------------------------
//
// l> 0B 1C B0 11 63 19 63 1F B7 4A 04 00 (234116)
// l> 0E 1C 80 02 1F B7 4A 63 19 63 01 01 00 80 14 (234243)
// do something with the information ----------------------------------
ee.clearPeers();
ee.clearRegs();
ee.getMasterID();
ld.set(defect);
uint8_t xI = ee.getRegListIdx(1,3);
if (rv.ackRq) {
if (xI == 0xff) sendACK();
else sendACK_STATUS(0, 0, 0);
}
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x80)) { // LED
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x81) && (rv.mBdy.by11 == 0x00)) { // LEDALL
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x81)) { // LEVEL
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if ((rv.mBdy.mTyp == 0x11) && (rv.mBdy.by10 == 0x82)) { // SLEEPMODE
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if (rv.mBdy.mTyp == 0x12) { // HAVE_DATA
// description --------------------------------------------------------
//
// b>
// do something with the information ----------------------------------
// --------------------------------------------------------------------
} else if (rv.mBdy.mTyp >= 0x3E) { // 3E SWITCH, 3F TIMESTAMP, 40 REMOTE, 41 SENSOR_EVENT, 53 SENSOR_DATA, 58 CLIMATE_EVENT, 70 WEATHER_EVENT
// description --------------------------------------------------------
// from to cnl cnt
// p> 0B 2D B4 40 23 70 D8 01 02 05 06 05 - Remote
// do something with the information ----------------------------------
// from to dst na cnl cnt
// m> 0F 18 B0 3E FD 24 BE 01 02 05 23 70 D8 40 06 00 - Switch
//"3E" => { txt => "SWITCH" , params => {
// DST => "00,6",
// UNKNOWN => "06,2",
// CHANNEL => "08,2",
// COUNTER => "10,2", } },
uint8_t cnl = 0, pIdx, tmp;
// check if we have the peer in the database to get the channel
if ((rv.mBdy.mTyp == 0x3E) && (rv.mBdy.mLen == 0x0f)) {
tmp = rv.buf[13]; // save byte13, because we will replace it
rv.buf[13] = rv.buf[14]; // copy the channel byte to the peer
cnl = ee.isPeerValid(rv.buf+10); // check with the right part of the string
if (cnl) pIdx = ee.getIdxByPeer(cnl, rv.buf+10); // get the index of the respective peer in the channel store
rv.buf[13] = tmp; // get it back
} else {
cnl = ee.isPeerValid(rv.peerId);
if (cnl) pIdx = ee.getIdxByPeer(cnl, rv.peerId); // get the index of the respective peer in the channel store
}
//dbg << "cnl: " << cnl << " pIdx: " << pIdx << " mTyp: " << _HEXB(rv.mBdy.mTyp) << " by10: " << _HEXB(rv.mBdy.by10) << " by11: " << _HEXB(rv.mBdy.by11) << " data: " << _HEX((rv.buf+10),(rv.mBdy.mLen-9)) << '\n'; _delay_ms(100);
if (cnl == 0) return;
// check if a module is registered and send the information, otherwise report an empty status
if (modTbl[cnl-1].cnl) {
//dbg << "pIdx:" << pIdx << ", cnl:" << cnl << '\n';
ee.getList(cnl, modTbl[cnl-1].lst, pIdx, modTbl[cnl-1].lstPeer); // get list3 or list4 loaded into the user module
// call the user module
modTbl[cnl-1].mDlgt(rv.mBdy.mTyp, rv.mBdy.by10, rv.mBdy.by11, rv.buf+10, rv.mBdy.mLen-9);
} else {
sendACK();
}
// --------------------------------------------------------------------
}
}
// - send functions --------------------------------
void AS::sendINFO_SERIAL(void) {
// description --------------------------------------------------------
// l> 0B 77 A0 01 63 19 63 1E 7A AD 00 09
// reID toID by10 serial
// l> 14 77 80 10 1E 7A AD 63 19 63 00 4A 45 51 30 37 33 31 39 30 35
// do something with the information ----------------------------------
sn.mBdy.mLen = 0x14;
sn.mBdy.mCnt = rv.mBdy.mLen;
sn.mBdy.mTyp = 0x10;
memcpy(sn.mBdy.reID,HMID,3);
memcpy(sn.mBdy.toID,rv.mBdy.reID,3);
sn.mBdy.by10 = 0x00;
memcpy(sn.buf+11,HMSR,10);
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendINFO_PEER_LIST(uint8_t len) {
// description --------------------------------------------------------
// l> 0B 44 A0 01 63 19 63 1F B7 4A 01 03
// reID toID by10 peer1 peer2
// l> 1A 44 A0 10 1F B7 4A 63 19 63 01 22 66 08 02 22 66 08 01 22 66 08 04 22 66 08 03
//
// l> 0A 44 80 02 63 19 63 1F B7 4A 00
// l> 1A 45 A0 10 1F B7 4A 63 19 63 01 24 88 2D 01 24 88 2D 02 24 88 2D 03 24 88 2D 04
// l> 0A 45 80 02 63 19 63 1F B7 4A 00
// l> 1A 46 A0 10 1F B7 4A 63 19 63 01 23 70 D8 02 23 70 D8 01 23 70 D8 04 23 70 D8 03
// l> 0A 46 80 02 63 19 63 1F B7 4A 00
// l> 1A 47 A0 10 1F B7 4A 63 19 63 01 23 70 D8 06 23 70 D8 05 22 6C 12 02 22 6C 12 01
// l> 0A 47 80 02 63 19 63 1F B7 4A 00
// l> 1A 48 A0 10 1F B7 4A 63 19 63 01 23 70 EC 02 23 70 EC 01 23 70 EC 04 23 70 EC 03
// l> 0A 48 80 02 63 19 63 1F B7 4A 00
// l> 16 49 A0 10 1F B7 4A 63 19 63 01 23 70 EC 06 23 70 EC 05 00 00 00 00
// l> 0A 49 80 02 63 19 63 1F B7 4A 00
// do something with the information ----------------------------------
sn.mBdy.mLen = len + 10;
sn.mBdy.mCnt = stcSlice.mCnt++;
sn.mBdy.mFlg.BIDI = 1;
sn.mBdy.mTyp = 0x10;
memcpy(sn.mBdy.reID, HMID, 3);
memcpy(sn.mBdy.toID, stcSlice.toID, 3);
sn.mBdy.by10 = 0x01; //stcSlice.cnl;
//dbg << "x: " << _HEX(sn.buf, sn.mBdy.mLen+1) << '\n';
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendINFO_PARAM_RESPONSE_PAIRS(uint8_t len) {
// description --------------------------------------------------------
// l> 10 79 B0 01 63 19 63 01 02 04 00 04 00 00 00 00 00
// reID toID by10 reg data reg data
// l> 16 79 A0 10 01 02 04 63 19 63 02 02 01 05 40 0A 63 0B 19 0C 63 12 69
//
// l> 0A 79 80 02 63 19 63 01 02 04 00
// l> 0C 7A A0 10 01 02 04 63 19 63 02 00 00
// l> 0A 7A 80 02 63 19 63 01 02 04 00
// do something with the information ----------------------------------
sn.mBdy.mLen = 10+len;
sn.mBdy.mCnt = stcSlice.mCnt++;
sn.mBdy.mFlg.BIDI = 1;
sn.mBdy.mTyp = 0x10;
memcpy(sn.mBdy.reID, HMID, 3);
memcpy(sn.mBdy.toID, stcSlice.toID, 3);
sn.mBdy.by10 = (len < 3)?0x03:0x02; // on end of the message we send a 0x03 message for homegear only
sn.active = 1; // fire the message
// --------------------------------------------------------------------
}
void AS::sendINFO_PARAM_RESPONSE_SEQ(uint8_t len) {
// description --------------------------------------------------------
// l> 10 90 A0 01 63 19 63 01 02 04 01 04 24 88 2D 03 03
// reID toID by10 Offset Data
// l> 16 90 A0 10 01 02 04 63 19 63 03 02 00 00 32 64 00 FF 00 FF 01 13 33
//
// l> 0A 90 80 02 63 19 63 01 02 04 00
// l> 16 91 A0 10 01 02 04 63 19 63 03 82 00 00 32 64 00 FF 00 FF 21 13 33
// l> 0A 91 80 02 63 19 63 01 02 04 00
// l> 0C 92 A0 10 01 02 04 63 19 63 03 00 00
// l> 0A 92 80 02 63 19 63 01 02 04 00
// do something with the information ----------------------------------
// --------------------------------------------------------------------
}
void AS::sendINFO_PARAMETER_CHANGE(void) {
//"10;p01=04" => { txt => "INFO_PARAMETER_CHANGE", params => {
//CHANNEL => "2,2",
//PEER => '4,8,$val=CUL_HM_id2Name($val)',
//PARAM_LIST => "12,2",
//DATA => '14,,$val =~ s/(..)(..)/ $1:$2/g', } },
// --------------------------------------------------------------------
}
// - homematic specific functions ------------------
void AS::decode(uint8_t *buf) {
uint8_t prev = buf[1];
buf[1] = (~buf[1]) ^ 0x89;
uint8_t i, t;
for (i=2; i<buf[0]; i++) {
t = buf[i];
buf[i] = (prev + 0xdc) ^ buf[i];
prev = t;
}
buf[i] ^= buf[2];
}
void AS::encode(uint8_t *buf) {
buf[1] = (~buf[1]) ^ 0x89;
uint8_t buf2 = buf[2];
uint8_t prev = buf[1];
uint8_t i;
for (i=2; i<buf[0]; i++) {
prev = (prev + 0xdc) ^ buf[i];
buf[i] = prev;
}
buf[i] ^= buf2;
}