forked from trilu2000/NewAskSin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDummy.cpp.old
112 lines (98 loc) · 5.25 KB
/
Dummy.cpp.old
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
//- -----------------------------------------------------------------------------------------------------------------------
// AskSin driver implementation
// 2013-08-03 <[email protected]> Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
//- -----------------------------------------------------------------------------------------------------------------------
//- AskSin dummy class ----------------------------------------------------------------------------------------------------
//- with a lot of support from martin876 at FHEM forum
//- -----------------------------------------------------------------------------------------------------------------------
//#define DM_DBG // debug message flag
#include "Dummy.h"
//-------------------------------------------------------------------------------------------------------------------------
//- mandatory functions for every new module to communicate within HM protocol stack -
//-------------------------------------------------------------------------------------------------------------------------
void Dummy::setToggle(void) {
// setToggle will be addressed by config button in mode 2 by a short key press
// here we can toggle the status of the actor
#ifdef DM_DBG
dbg << F("sT\n");
#endif
}
void Dummy::configCngEvent(void) {
// it's only for information purpose while something in the channel config was changed (List0/1 or List3/4)
#ifdef DM_DBG
dbg << F("CCE, lst1: ") << pHex(((uint8_t*)&lstCnl), sizeof(s_lstCnl)) << '\n';
#endif
}
void Dummy::pairSetEvent(uint8_t *data, uint8_t len) {
// we received a message from master to set a new value, typical you will find three bytes in data
// 1st byte = value; 2nd byte = ramp time; 3rd byte = duration time;
// after setting the new value we have to send an enhanced ACK (<- 0E E7 80 02 1F B7 4A 63 19 63 01 01 C8 00 54)
#ifdef DM_DBG
dbg << F("PSE, value:") << pHexB(data[0]);
if (len > 1) dbg << F(", rampTime: ") << pHexB(data[1]);
if (len > 2) dbg << F(", duraTime: ") << pHexB(data[2]);
dbg << '\n';
#endif
hm->sendACK_STATUS(regCnl, data[0], modDUL);
}
void Dummy::pairStatusReq(void) {
// we received a status request, appropriate answer is an InfoActuatorStatus message
#ifdef DM_DBG
dbg << F("PSR\n");
#endif
hm->sendINFO_ACTUATOR_STATUS(regCnl, modStat, modDUL);
}
void Dummy::peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len) {
// we received a peer event, in type you will find the marker if it was a switch(3E), remote(40) or sensor(41) event
// appropriate answer is an ACK
#ifdef DM_DBG
dbg << F("PME, type: ") << pHexB(type) << F(", data: ") << pHex(data, len) << '\n';
#endif
if ((type == 0x3e) || (type == 0x40) || (type == 0x41)) {
hm->sendACK_STATUS(regCnl, modStat, modDUL);
} else {
hm->sendACK();
}
}
void Dummy::poll(void) {
// just polling, as the function name said
}
//-------------------------------------------------------------------------------------------------------------------------
//- predefined, no reason to touch -
//-------------------------------------------------------------------------------------------------------------------------
void Dummy::regInHM(uint8_t cnl, uint8_t lst, AS *instPtr) {
hm = instPtr; // set pointer to the HM module
hm->rg.regInAS(cnl, lst, s_mod_dlgt(this,&Dummy::hmEventCol), (uint8_t*)&lstCnl,(uint8_t*)&lstPeer);
regCnl = cnl; // stores the channel we are responsible fore
}
void Dummy::hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len) {
// dbg << "by3:" << by3 << " by10:" << by10 << " d:" << pHex(data, len) << '\n'; _delay_ms(100);
if ((by3 == 0x00) && (by10 == 0x00)) poll();
else if ((by3 == 0x00) && (by10 == 0x01)) setToggle();
else if ((by3 == 0x01) && (by11 == 0x06)) configCngEvent();
else if ((by3 == 0x11) && (by10 == 0x02)) pairSetEvent(data, len);
else if ((by3 == 0x01) && (by11 == 0x0E)) pairStatusReq();
else if ((by3 == 0x01) && (by11 == 0x01)) peerAddEvent(data, len);
else if (by3 >= 0x3E) peerMsgEvent(by3, data, len);
else return;
}
void Dummy::peerAddEvent(uint8_t *data, uint8_t len) {
// we received an peer add event, which means, there was a peer added in this respective channel
// 1st byte and 2nd byte shows the peer channel, 3rd and 4th byte gives the peer index
// no need for sending an answer, but we could set default data to the respective list3/4
#ifdef DM_DBG
dbg << F("peerAddEvent: pCnl1: ") << pHexB(data[0]) << F(", pCnl2: ") << pHexB(data[1]) << F(", pIdx1: ") << pHexB(data[2]) << F(", pIdx2: ") << pHexB(data[3]) << '\n';
#endif
if ((data[0]) && (data[1])) { // dual peer add
if (data[0]%2) { // odd
//hm->setListFromModule(regCnl,data[2],(uint8_t*)peerOdd,sizeof(peerOdd));
//hm->setListFromModule(regCnl,data[3],(uint8_t*)peerEven,sizeof(peerEven));
} else { // even
//hm->setListFromModule(regCnl,data[2],(uint8_t*)peerEven,sizeof(peerEven));
//hm->setListFromModule(regCnl,data[3],(uint8_t*)peerOdd,sizeof(peerOdd));
}
} else { // single peer add
//if (data[0]) hm->setListFromModule(regCnl,data[2],(uint8_t*)peerSingle,sizeof(peerSingle));
//if (data[1]) hm->setListFromModule(regCnl,data[3],(uint8_t*)peerSingle,sizeof(peerSingle));
}
}