NewAskSin
 All Classes Files Functions Variables Groups Pages
Relay.h
1 //- -----------------------------------------------------------------------------------------------------------------------
2 // AskSin driver implementation
3 // 2013-08-03 <trilu@gmx.de> Creative Commons - http://creativecommons.org/licenses/by-nc-sa/3.0/de/
4 //- -----------------------------------------------------------------------------------------------------------------------
5 //- AskSin relay class ----------------------------------------------------------------------------------------------------
6 //- with a lot of support from martin876 at FHEM forum
7 //- -----------------------------------------------------------------------------------------------------------------------
8 
9 #ifndef _RELAY_H
10 #define _RELAY_H
11 
12 #include "AS.h"
13 #include "HAL.h"
14 
15 // default settings for list3 or list4
16 const uint8_t peerOdd[] = { // cnl 2, 4, 6
17  // Default actor dual 1: 02:00 03:00 04:32 05:64 06:00 07:FF 08:00 09:FF 0A:01
18  // 0B:64 0C:66 82:00 83:00 84:32 85:64 86:00 87:FF 88:00 89:FF 8A:21 8B:64 8C:66
19  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x64, 0x66,
20  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x21, 0x64, 0x66
21 };
22 const uint8_t peerEven[] = { // cnl 1, 3, 5
23  // Default actor dual 2: 02:00 03:00 04:32 05:64 06:00 07:FF 08:00 09:FF 0A:01
24  // 0B:13 0C:33 82:00 83:00 84:32 85:64 86:00 87:FF 88:00 89:FF 8A:21 8B:13 8C:33
25  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x13, 0x33,
26  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x21, 0x13, 0x33
27 };
28 const uint8_t peerSingle[] = {
29  // Default actor single: 02:00 03:00 04:32 05:64 06:00 07:FF 08:00 09:FF 0A:01
30  // 0B:14 0C:63 82:00 83:00 84:32 85:64 86:00 87:FF 88:00 89:FF 8A:21 8B:14 8C:63
31  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x01, 0x14, 0x63,
32  0x00, 0x00, 0x32, 0x64, 0x00, 0xFF, 0x00, 0xFF, 0x21, 0x14, 0x63,
33 };
34 
35 
36 class Relay {
37  //- user code here ------------------------------------------------------------------------------------------------------
38  public://----------------------------------------------------------------------------------------------------------------
39  protected://-------------------------------------------------------------------------------------------------------------
40  private://---------------------------------------------------------------------------------------------------------------
41  struct s_lstCnl {
42  // 0x08,
43  uint8_t sign :1; // 0x08, s:0, e:1
44  uint8_t :7; //
45  } lstCnl;
46 
47  struct s_lstPeer {
48  // 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,
49  uint8_t shCtDlyOn :4; // 0x02, s:0, e:4
50  uint8_t shCtDlyOff :4; // 0x02, s:4, e:8
51  uint8_t shCtOn :4; // 0x03, s:0, e:4
52  uint8_t shCtOff :4; // 0x03, s:4, e:8
53  uint8_t shCtValLo; // 0x04, s:0, e:0
54  uint8_t shCtValHi; // 0x05, s:0, e:0
55  uint8_t shOnDly; // 0x06, s:0, e:0
56  uint8_t shOnTime; // 0x07, s:0, e:0
57  uint8_t shOffDly; // 0x08, s:0, e:0
58  uint8_t shOffTime; // 0x09, s:0, e:0
59  uint8_t shActionType :2; // 0x0a, s:0, e:2
60  uint8_t :4; //
61  uint8_t shOffTimeMode :1; // 0x0a, s:6, e:7
62  uint8_t shOnTimeMode :1; // 0x0a, s:7, e:8
63  uint8_t shSwJtOn :4; // 0x0b, s:0, e:4
64  uint8_t shSwJtOff :4; // 0x0b, s:4, e:8
65  uint8_t shSwJtDlyOn :4; // 0x0c, s:0, e:4
66  uint8_t shSwJtDlyOff :4; // 0x0c, s:4, e:8
67  uint8_t lgCtDlyOn :4; // 0x82, s:0, e:4
68  uint8_t lgCtDlyOff :4; // 0x82, s:4, e:8
69  uint8_t lgCtOn :4; // 0x83, s:0, e:4
70  uint8_t lgCtOff :4; // 0x83, s:4, e:8
71  uint8_t lgCtValLo; // 0x84, s:0, e:0
72  uint8_t lgCtValHi; // 0x85, s:0, e:0
73  uint8_t lgOnDly; // 0x86, s:0, e:0
74  uint8_t lgOnTime; // 0x87, s:0, e:0
75  uint8_t lgOffDly; // 0x88, s:0, e:0
76  uint8_t lgOffTime; // 0x89, s:0, e:0
77  uint8_t lgActionType :2; // 0x8a, s:0, e:2
78  uint8_t :3; //
79  uint8_t lgMultiExec :1; // 0x8a, s:5, e:6
80  uint8_t lgOffTimeMode :1; // 0x8a, s:6, e:7
81  uint8_t lgOnTimeMode :1; // 0x8a, s:7, e:8
82  uint8_t lgSwJtOn :4; // 0x8b, s:0, e:4
83  uint8_t lgSwJtOff :4; // 0x8b, s:4, e:8
84  uint8_t lgSwJtDlyOn :4; // 0x8c, s:0, e:4
85  uint8_t lgSwJtDlyOff :4; // 0x8c, s:4, e:8
86  } lstPeer;
87 
88  struct s_l3 {
89  // 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,
90  uint8_t ctDlyOn :4; // 0x02, 0x82, s:0, e:4
91  uint8_t ctDlyOff :4; // 0x02, 0x82, s:4, e:8
92  uint8_t ctOn :4; // 0x03, 0x83, s:0, e:4
93  uint8_t ctOff :4; // 0x03, 0x83, s:4, e:8
94  uint8_t ctValLo; // 0x04, 0x84, s:0, e:0
95  uint8_t ctValHi; // 0x05, 0x85, s:0, e:0
96  uint8_t onDly; // 0x06, 0x86, s:0, e:0
97  uint8_t onTime; // 0x07, 0x87, s:0, e:0
98  uint8_t offDly; // 0x08, 0x88, s:0, e:0
99  uint8_t offTime; // 0x09, 0x89, s:0, e:0
100  uint8_t actionType :2; // 0x0a, 0x8a, s:0, e:2
101  uint8_t :3; //
102  uint8_t multiExec :1; // 0x8a, s:5, e:6
103  uint8_t offTimeMode :1; // 0x0a, 0x8a, s:6, e:7
104  uint8_t onTimeMode :1; // 0x0a, 0x8a, s:7, e:8
105  uint8_t jtOn :4; // 0x0b, 0x8b, s:0, e:4
106  uint8_t jtOff :4; // 0x0b, 0x8b, s:4, e:8
107  uint8_t jtDlyOn :4; // 0x0c, 0x8c, s:0, e:4
108  uint8_t jtDlyOff :4; // 0x0c, 0x8c, s:4, e:8
109  } *l3;
110 
111 
112  public://----------------------------------------------------------------------------------------------------------------
113  //- user defined functions ----------------------------------------------------------------------------------------------
114 
115  void (*fInit)(void); // pointer to init function in main sketch
116  void (*fSwitch)(uint8_t); // pointer to switch function in main sketch
117 
118  waitTimer delayTmr; // delay timer for relay
119 
120  uint8_t cnt; // message counter for type 40 message
121  uint8_t curStat:4, nxtStat:4; // current state and next state
122 
123  waitTimer msgTmr; // message timer for sending status
124  uint16_t msgDelay; // delay for sending initial status
125  uint8_t sendStat :2; // indicator for sendStatus function
126 
127  uint8_t tr11 :1; // trigger 11 active
128  uint8_t tr11Value; // trigger 11 set value
129  uint16_t rampTme, duraTme; // time store for trigger 11
130 
131  uint8_t setStat; // status to set on the Relay channel
132 
133  void config(void Init(), void Switch(uint8_t)); // handover for jump addresses
134 
135  void trigger11(uint8_t value, uint8_t *rampTime, uint8_t *duraTime); // what happens while a trigger11 message arrive
136  void trigger40(uint8_t msgLng, uint8_t msgCnt); // same for peer messages
137  void trigger41(uint8_t msgBLL, uint8_t msgCnt, uint8_t msgVal); // same for sensor messages
138 
139  void adjRly(void); // setting of relay status
140  void sendStatus(void); // help function to send status messages
141 
142  void rlyPoll(void); // polling function
143 
144 
145  //- mandatory functions for every new module to communicate within AS protocol stack ------------------------------------
146  uint8_t modStat; // module status byte, needed for list3 modules to answer status requests
147  uint8_t modDUL; // module down up low battery byte
148  uint8_t regCnl; // holds the channel for the module
149 
150  AS *hm; // pointer to HM class instance
151 
152  void setToggle(void); // toggle the module initiated by config button
153  void configCngEvent(void); // list1 on registered channel had changed
154  void pairSetEvent(uint8_t *data, uint8_t len); // pair message to specific channel, handover information for value, ramp time and so on
155  void pairStatusReq(void); // event on status request
156  void peerMsgEvent(uint8_t type, uint8_t *data, uint8_t len); // peer message was received on the registered channel, handover the message bytes and length
157 
158  void poll(void); // poll function, driven by HM loop
159 
160  //- predefined, no reason to touch ------------------------------------------------------------------------------------
161  void regInHM(uint8_t cnl, uint8_t lst, AS *instPtr); // register this module in HM on the specific channel
162  void hmEventCol(uint8_t by3, uint8_t by10, uint8_t by11, uint8_t *data, uint8_t len);// call back address for HM for informing on events
163  void peerAddEvent(uint8_t *data, uint8_t len); // peer was added to the specific channel, 1st and 2nd byte shows peer channel, third and fourth byte shows peer index
164 };
165 
166 #endif
Main class for implementation of the AskSin protocol stack. Every device needs exactly one instance o...
Definition: AS.h:39
Timer class for non-blocking delays.
Definition: AS.h:200
Definition: Relay.h:36