NewAskSin
 All Classes Files Functions Variables Groups Pages
EEprom.h
Go to the documentation of this file.
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 eeprom functions -----------------------------------------------------------------------------------------------
6 //- with a lot of support from martin876 at FHEM forum
7 //- -----------------------------------------------------------------------------------------------------------------------
8 
9 #ifndef _EE_H
10 #define _EE_H
11 
12 #include "HAL.h"
13 #define maxMsgLen 16 // define max message length in byte
14 
27 extern void everyTimeStart(void); // add this function in register.h to setup default values every start
28 
37 extern void firstTimeStart(void); // only on first start of the device
38 
39 //- class definition ------------------------------------------------------------------------------------------------------
92 class EE {
93  friend class AS;
94  friend class RV;
95  friend class CB;
96 
97  public: //---------------------------------------------------------------------------------------------------------
98 
115  struct s_cnlTbl { // channel table holds all information regarding channels and lists
116  const uint8_t cnl;
117  const uint8_t lst;
118  const uint8_t sIdx;
119  const uint8_t sLen;
120  const uint16_t pAddr;
121  };
122 
141  struct s_peerTbl { // peer table holds information were to find peers in eeprom
142  const uint8_t cnl;
143  const uint8_t pMax;
144  const uint16_t pAddr;
145  };
146 
158  struct s_devDef { // device definition table
159  const uint8_t cnlNbr;
160  const uint8_t lstNbr;
161  const uint8_t *devIdnt;
162  const uint8_t *cnlAddr;
163  };
164 
165  protected: //---------------------------------------------------------------------------------------------------------
166  private: //---------------------------------------------------------------------------------------------------------
167 
168  public: //---------------------------------------------------------------------------------------------------------
169  uint8_t getList(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t *buf); // get a complete list in to a given buffer
170  uint8_t setList(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t *buf); // set a complete list to the eeprom
171  uint8_t getRegAddr(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t addr); // ok, gets a single register value
172  uint32_t getHMID(void); // get HMID as 32 bit integer
173 
174  protected: //---------------------------------------------------------------------------------------------------------
175  public: //--------------------------------------------------------------------------------------------------------
176  //private: //---------------------------------------------------------------------------------------------------------
177  EE(); // class constructor
178  void init(void);
179  void getMasterID(void);
180  void testModul(void); // prints register.h definition on console
181  uint8_t isHMIDValid(uint8_t *toID); // ok, check if a valid pair was given
182  uint8_t isPairValid(uint8_t *reID); // ok, check if a valid pair was given
183  uint8_t isBroadCast(uint8_t *reID);
184  uint8_t getIntend(uint8_t *reId, uint8_t *toId, uint8_t *peId);
185 
186  // peer functions
187  void clearPeers(void); // ok, clears complete peer database
188  uint8_t isPeerValid (uint8_t *peer); // ok, checks if a valid peer was given
189 
190  uint8_t countFreeSlots(uint8_t cnl); // ok, counts the free peer slots of a channel
191  uint8_t getIdxByPeer(uint8_t cnl, uint8_t *peer); // ok, find the index of the respective peer
192  uint8_t getPeerByIdx(uint8_t cnl, uint8_t idx, uint8_t *peer); // ok, returns the respective peer of the given index
193  uint8_t addPeer(uint8_t cnl, uint8_t *peer); // ok, writes a peer in the database on first free slot
194  uint8_t remPeer(uint8_t cnl, uint8_t *peer); // ok, writes a zero to the respective slot
195  uint8_t countPeerSlc(uint8_t cnl); // ok, count the slices for function getPeerListSlc
196  uint8_t getPeerListSlc(uint8_t cnl, uint8_t slc, uint8_t *buf); // ok, returns the whole peer database as a string
197  uint8_t getPeerSlots(uint8_t cnl); // ok, returns max peers per channel
198 
199  // register functions
200  void clearRegs(void); // ok, clears register space
201 
202  uint8_t countRegListSlc(uint8_t cnl, uint8_t lst); // ok, counts the slices for a complete regs transmition
203  uint8_t getRegListSlc(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t slc, uint8_t *buf);// ok, generates answer to a channel/list request
204  uint8_t setListArray(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t len, uint8_t *buf);// ok, set registers from a string
205 
206  //uint8_t getListForMsg3(uint8_t cnl, uint8_t lst, uint8_t *peer, uint8_t *buf);
207  //void getCnlListByPeerIdx(uint8_t cnl, uint8_t peerIdx);
208  //void setListFromModule(uint8_t cnl, uint8_t peerIdx, uint8_t *data, uint8_t len);
209 
210  uint8_t getRegListIdx(uint8_t cnl, uint8_t lst); // ok, returns the respective line of cnlTbl
211  uint8_t checkIndex(uint8_t cnl, uint8_t lst, uint8_t idx);
212 };
213 
220 extern EE::s_cnlTbl cnlTbl[]; // initial register.h
221 
228 extern EE::s_peerTbl peerTbl[]; // initial register.h
229 
236 extern EE::s_devDef devDef; // initial register.h
237 
252 extern uint8_t MAID[];
253 
264 extern uint8_t HMID[];
265 
273 extern uint8_t HMSR[];
274 
275 
276 //- some helpers ----------------------------------------------------------------------------------------------------------
277 uint16_t crc16(uint16_t crc, uint8_t a); // crc function
278 uint8_t compArray(void *p1, void *p2, uint8_t len); // compare two byte arrays
279 uint8_t isEmpty(void *p1, uint8_t len); // check if a byte array is empty
280 
281 #endif
282 
uint8_t MAID[]
Global definition of master HM-ID (paired central).
Definition: EEprom.cpp:12
const uint8_t cnl
Channel.
Definition: EEprom.h:142
const uint16_t pAddr
Address of configuration data in EEprom memory.
Definition: EEprom.h:144
Main class for implementation of the AskSin protocol stack. Every device needs exactly one instance o...
Definition: AS.h:39
uint8_t setList(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t *buf)
Write arbitrary data as list content to EEprom.
Definition: EEprom.cpp:79
Peer Device Table Entry.
Definition: EEprom.h:141
Class for the handling the configuration key of the device Right now there are three possible scenari...
Definition: ConfButton.h:54
const uint8_t lst
List within the channel.
Definition: EEprom.h:117
void firstTimeStart(void)
Callback for actions after EEprom deletion.
const uint8_t * devIdnt
Pointer to device identifier.
Definition: EEprom.h:161
const uint8_t cnl
Channel.
Definition: EEprom.h:116
const uint8_t sLen
Number of registers.
Definition: EEprom.h:119
const uint8_t pMax
Maximum number of peer devices.
Definition: EEprom.h:143
EE::s_cnlTbl cnlTbl[]
Global device register channel table definition. Must be declared in user space.
Device Definition.
Definition: EEprom.h:158
EE::s_devDef devDef
Global device definition. Must be declared in user space.
uint8_t setListArray(uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t len, uint8_t *buf)
Set individual registers of a list.
Definition: EEprom.cpp:568
const uint16_t pAddr
Address of first byte in EEprom memory.
Definition: EEprom.h:120
const uint8_t sIdx
Index of first entry in channel slice address definition.
Definition: EEprom.h:118
uint8_t HMID[]
Global definition of device HM-ID. Must be declared in user space.
const uint8_t * cnlAddr
Pointer to the channel slice address definition.
Definition: EEprom.h:162
Helper class for providing access to non-volatile data in the EEprom.
Definition: EEprom.h:92
EE::s_peerTbl peerTbl[]
Global peer table definition. Must be declared in user space.
const uint8_t cnlNbr
Number of channels.
Definition: EEprom.h:159
uint8_t HMSR[]
Global definition of device serial number. Must be declared in user space.
Channel Table Entry.
Definition: EEprom.h:115
const uint8_t lstNbr
Number of lists.
Definition: EEprom.h:160
Definition: Receive.h:16
void everyTimeStart(void)
Callback for actions after bootup.