NewAskSin
 All Classes Files Functions Variables Groups Pages
AS.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 protocol functions ---------------------------------------------------------------------------------------------
6 //- with a lot of support from martin876 at FHEM forum
7 //- -----------------------------------------------------------------------------------------------------------------------
8 
9 #ifndef _NAS_H
10 #define _NAS_H
11 
12 #include "HAL.h"
13 #include "CC1101.h"
14 #include "EEprom.h"
15 #include "Send.h"
16 #include "Receive.h"
17 #include "Registrar.h"
18 #include "ConfButton.h"
19 #include "StatusLed.h"
20 #include "Power.h"
21 #include "Battery.h"
22 #include "Version.h"
23 
39 class AS {
40  friend class SN;
41  friend class RV;
42  friend class RG;
43  friend class PW;
44 
45  public: //---------------------------------------------------------------------------------------------------------
46  EE ee;
47  SN sn;
48  RG rg;
50  LD ld;
51  PW pw;
52  CC cc;
53  BT bt;
54 
55  protected: //---------------------------------------------------------------------------------------------------------
56  private: //---------------------------------------------------------------------------------------------------------
57 
58  //CC cc; ///< load communication module
59  RV rv;
60 
62  struct s_confFlag { // - remember that we are in config mode, for config start message receive
63  uint8_t active :1; //< indicates status, 1 if config mode is active
64  uint8_t cnl; //< channel
65  uint8_t lst; //< list
66  uint8_t idx; //< peer index
67  } cFlag;
68 
69  struct s_stcSlice { // - send peers or reg in slices, store for send slice function
70  uint8_t active :1; // indicates status of poll routine, 1 is active
71  uint8_t peer :1; // is it a peer list message
72  uint8_t reg2 :1; // or a register send
73  uint8_t reg3 :1; // not implemented at the moment
74  uint8_t totSlc; // amount of necessary slices to send content
75  uint8_t curSlc; // counter for slices which are already send
76  uint8_t cnl; // indicates channel
77  uint8_t lst; // the respective list
78  uint8_t idx; // the peer index
79  uint8_t mCnt; // the message counter
80  uint8_t toID[3]; // to whom to send
81  } stcSlice;
82 
83  struct s_stcPeer {
84  uint8_t active :1; // indicates status of poll routine, 1 is active
85  uint8_t rnd :3; // send retries
86  uint8_t burst :1; // burst flag for send function
87  uint8_t bidi :1; // ack required
88  uint8_t mTyp; // message type to build the right message
89  uint8_t *pL; // pointer to payload
90  uint8_t lenPL; // length of payload
91  uint8_t cnl; // which channel is the sender
92  uint8_t curIdx; // current peer slots
93  uint8_t maxIdx; // amount of peer slots
94  uint8_t slt[8]; // slot measure, all filled in a first step, if ACK was received, one is taken away by slot
95  } stcPeer;
96 
97  struct s_l4_0x01 {
98  uint8_t peerNeedsBurst :1; // 0x01, s:0, e:1
99  uint8_t :6; //
100  uint8_t expectAES :1; // 0x01, s:7, e:8
101  } l4_0x01;
102 
103  uint8_t pairActive :1;
104 
105  public: //---------------------------------------------------------------------------------------------------------
106  AS();
107 
113  void init(void);
114 
122  void poll(void);
123 
124  // - send functions --------------------------------
125  void sendDEVICE_INFO(void);
126  void sendACK(void);
127  void sendACK_STATUS(uint8_t cnl, uint8_t stat, uint8_t dul);
128  void sendNACK(void);
129  void sendNACK_TARGET_INVALID(void);
130  void sendINFO_ACTUATOR_STATUS(uint8_t cnl, uint8_t stat, uint8_t cng);
131  void sendINFO_TEMP(void);
132  void sendHAVE_DATA(void);
133  void sendSWITCH(void);
134  void sendTimeStamp(void);
135  void sendREMOTE(uint8_t cnl, uint8_t burst, uint8_t *pL);
136  void sendSensor_event(uint8_t cnl, uint8_t burst, uint8_t *pL);
137  void sendSensorData(void);
138  void sendClimateEvent(void);
139  void sendSetTeamTemp(void);
140  void sendWeatherEvent(void);
141  void send_generic_event(uint8_t cnl, uint8_t burst, uint8_t mTyp, uint8_t len, uint8_t *pL);
142 
143  private: //---------------------------------------------------------------------------------------------------------
144 
145  // - poll functions --------------------------------
146  void sendSliceList(void); // scheduler to send config messages, peers and regs
147  void sendPeerMsg(void); // scheduler for peer messages
148  void prepPeerMsg(uint8_t *xPeer, uint8_t retr);
149 
150  // - receive functions -----------------------------
151  void recvMessage(void);
152 
153  // - send functions --------------------------------
154  void sendINFO_SERIAL(void);
155  void sendINFO_PEER_LIST(uint8_t len);
156  void sendINFO_PARAM_RESPONSE_PAIRS(uint8_t len);
157  void sendINFO_PARAM_RESPONSE_SEQ(uint8_t len);
158  void sendINFO_PARAMETER_CHANGE(void);
159 
160 
161  protected: //---------------------------------------------------------------------------------------------------------
162  // - homematic specific functions ------------------
163  void decode(uint8_t *buf); // decodes the message
164  void encode(uint8_t *buf); // encodes the message
165  void explainMessage(uint8_t *buf); // explains message content, part of debug functions
166 
167  // - some helpers ----------------------------------
168 
169 
170 };
171 extern AS hm;
172 
200 class waitTimer {
201 
202  private: //---------------------------------------------------------------------------------------------------------
203  uint8_t armed;
204  uint32_t checkTime;
205  uint32_t startTime;
206 
207  public: //---------------------------------------------------------------------------------------------------------
208  uint8_t done(void);
209  void set(uint32_t ms);
210  uint32_t remain(void);
211 };
212 
213 
214 
215 uint32_t byteTimeCvt(uint8_t tTime);
216 uint32_t intTimeCvt(uint16_t iTime);
217 
218 #endif
219 
CB confButton
config button
Definition: AS.h:49
LD ld
status led
Definition: AS.h:50
Main class for implementation of the AskSin protocol stack. Every device needs exactly one instance o...
Definition: AS.h:39
RG rg
user module registrar
Definition: AS.h:48
EE ee
eeprom module
Definition: AS.h:46
void init(void)
Initialize the AS module.
Definition: AS.cpp:20
void send_generic_event(uint8_t cnl, uint8_t burst, uint8_t mTyp, uint8_t len, uint8_t *pL)
Send an event with arbitrary payload.
Definition: AS.cpp:304
Definition: StatusLed.h:69
Definition: Registrar.h:20
Class for the handling the configuration key of the device Right now there are three possible scenari...
Definition: ConfButton.h:54
Definition: Battery.h:15
Timer class for non-blocking delays.
Definition: AS.h:200
void set(uint32_t ms)
Start the timer.
Definition: AS.cpp:1165
Definition: CC1101.h:15
PW pw
power management
Definition: AS.h:51
Definition: Send.h:16
Helper class for providing access to non-volatile data in the EEprom.
Definition: EEprom.h:92
uint8_t done(void)
Query if the timer has expired.
Definition: AS.cpp:1152
uint32_t remain(void)
Query the remaing time until the timer is done.
Definition: AS.cpp:1178
Definition: Receive.h:16
SN sn
send module
Definition: AS.h:47
Definition: Power.h:21
CC cc
load communication module
Definition: AS.h:52
void poll(void)
Poll routine for regular operation.
Definition: AS.cpp:44