NewAskSin
 All Classes Files Functions Variables Groups Pages
Classes | Public Member Functions | Friends | List of all members
EE Class Reference

Helper class for providing access to non-volatile data in the EEprom. More...

#include <EEprom.h>

Classes

struct  s_cnlTbl
 Channel Table Entry. More...
 
struct  s_devDef
 Device Definition. More...
 
struct  s_peerTbl
 Peer Device Table Entry. More...
 

Public Member Functions

uint8_t getList (uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t *buf)
 
uint8_t setList (uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t *buf)
 Write arbitrary data as list content to EEprom. More...
 
uint8_t getRegAddr (uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t addr)
 
uint32_t getHMID (void)
 
void init (void)
 
void getMasterID (void)
 
void testModul (void)
 
uint8_t isHMIDValid (uint8_t *toID)
 
uint8_t isPairValid (uint8_t *reID)
 
uint8_t isBroadCast (uint8_t *reID)
 
uint8_t getIntend (uint8_t *reId, uint8_t *toId, uint8_t *peId)
 
void clearPeers (void)
 
uint8_t isPeerValid (uint8_t *peer)
 
uint8_t countFreeSlots (uint8_t cnl)
 
uint8_t getIdxByPeer (uint8_t cnl, uint8_t *peer)
 
uint8_t getPeerByIdx (uint8_t cnl, uint8_t idx, uint8_t *peer)
 
uint8_t addPeer (uint8_t cnl, uint8_t *peer)
 
uint8_t remPeer (uint8_t cnl, uint8_t *peer)
 
uint8_t countPeerSlc (uint8_t cnl)
 
uint8_t getPeerListSlc (uint8_t cnl, uint8_t slc, uint8_t *buf)
 
uint8_t getPeerSlots (uint8_t cnl)
 
void clearRegs (void)
 
uint8_t countRegListSlc (uint8_t cnl, uint8_t lst)
 
uint8_t getRegListSlc (uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t slc, uint8_t *buf)
 
uint8_t setListArray (uint8_t cnl, uint8_t lst, uint8_t idx, uint8_t len, uint8_t *buf)
 Set individual registers of a list. More...
 
uint8_t getRegListIdx (uint8_t cnl, uint8_t lst)
 
uint8_t checkIndex (uint8_t cnl, uint8_t lst, uint8_t idx)
 

Friends

class AS
 
class RV
 
class CB
 

Detailed Description

Helper class for providing access to non-volatile data in the EEprom.

This class is used by the main AS class to handle non-volatile data stored in the EEprom and accessed in form of Registers in the context of Lists. Additionally, it maintains the peer database to validate incoming messages and help formulate outgoing messages.

Every device requires a set of definitions that define its properties and capabilities:

Todo:
Insert defDev example here.
Start Length Content
0x0000 2 magic byte
0x0002 3 HMID
0x0005 10 serial number
0x000f N_l register values (see below)
0x000f+N_l N_p peer list (see below)

Register values are stored for each possible Channel/List combination. A typical device knows exactly one List0 (Channel 0), and for each channel a combination of List1 and either List3 or List4.

For each channel, the number of possible peer devices can be specified individually. With chanX_listY_len as the number of register bytes for list Y in channel X and peers_chanX as the maximum number of peers for channel X, the memory footprint can be calculated as follows:

Channel List0 List1 List3 List4 Size Note
0 chan0_list0_len chan0_l0_len mandatory
1 chan1_list1_len peers_chan1 * chan1_list1_len mandatory
1 chan1_list3_len peers_chan1 * chan1_list3_len actor
1 chan1_list4_len peers_chan1 * chan1_list4_len sensor
2 chan2_list1_len peers_chan2 * chan1_list1_len mandatory
2 chan2_list3_len peers_chan2 * chan1_list3_len actor
2 chan2_list4_len peers_chan2 * chan1_list4_len sensor
N chanN_list1_len peers_chan2 * chan1_list1_len mandatory
N chanN_list3_len peers_chan2 * chan1_list3_len actor
N chanN_list4_len peers_chan2 * chan1_list4_len sensor
Todo:
Insert description of peerTbl here

Member Function Documentation

uint8_t EE::setList ( uint8_t  cnl,
uint8_t  lst,
uint8_t  idx,
uint8_t *  buf 
)

Write arbitrary data as list content to EEprom.

setList() can be used to set the values of all registers in a list (see Device Registers).

Parameters
cnlChannel
lstList
idxIndex of peer (0 if not applicable)
bufArray with all new list values (must match size of channel-list)
Returns
1 for success, 0 for failure

The specified channel, list and index are used to identify the eeprom section to write to (see EEprom memory layout).

If a valid eeprom section can be identified, the content of buf will be written to the associated EEprom memory section.

Note
Use setListArray() to write to individual registers rather than the complete list.

In a simple example, the channel slice address definition for List0 is:

const uint8_t cnlAddr[] PROGMEM = {
0x02, 0x05, 0x0a, 0x0b, 0x0c, 0x14, 0x24, 0x25, 0x26, 0x27, // sIdx 0x00, 10 bytes for Channel0/List0
0x01, // sIdx 0x0a, 1 byte for Channel1/List4
}; // 11 byte
// cnl, lst, sIdx, sLen, pAddr;
{ 0, 0, 0x00, 10, 0x000f }, // Channel0/List0, 10 bytes at sIdx 0x00, Addr 0x000f
{ 1, 4, 0x0a, 1, 0x0019 }, // Channel1/List4, 1 byte at sIdx 0x0a, Addr 0x0019
};

In order to write the contents of list0 (10 bytes) to the EEprom, we simply use:

const uint8_t list0defaults[] = {
0x01, // 0x02, led-mode on
0x00, // 0x05,
0x00,0x00,0x00, // 0x0a, Master-ID, leave at 000000 to allow for pairing
0x00, // 0x14,
0x02,0x01 // 0x24, measureInterval = 513sec = 0x0201
0x03, // 0x26, pwmStableDelay = 3sec = 0x03
0x05 // 0x27, pwmStableDelta = 2.5% = 0x05
};
hm.ee.setListArray(0,0,0,sizeof(list0defaults),list0defaults);

Note how registers with data types bigger than one byte use consecutive addresses for the required number of bytes.

Commonly, it is good practice to keep the declaration of the register contents close to that of the channel slice address definition to simplify book-keeping during development.

See Also
setListArray(), firstTimeStart()
uint8_t EE::setListArray ( uint8_t  cnl,
uint8_t  lst,
uint8_t  idx,
uint8_t  len,
uint8_t *  buf 
)

Set individual registers of a list.

setListArray can be used to set indivual registers of a list (see Device Registers). Any number of registers defined for a list by the respective channel slice address definition can we written with a new value.

Parameters
cnlChannel
lstList
idxIndex of peer (0 if not applicable)
lenArray length (must be a multiple of 2)
bufArray with pairs of REGNUM:VALUE
Returns
1 for success, 0 for failure

The specified channel, list and index are used to identify the eeprom section to write to (see EEprom memory layout).

If a valid eeprom section is identified, each REGNUM:VALUE pair in the array for validity and write will be used to write VALUE as the new content of register REGNUM in the specified List.

Note
Use setList() to write to the complete list rather than individual registers.

In a simple example, the channel slice address definition for List0 is:

const uint8_t cnlAddr[] PROGMEM = {
0x02, 0x05, 0x0a, 0x0b, 0x0c, 0x14, 0x24, 0x25, 0x26, 0x27, // sIdx 0x00, 10 bytes for Channel0/List0
0x01, // sIdx 0x0a, 1 byte for Channel1/List4
}; // 11 byte

docs/snippets/register-h-cnlTbl.cpp

const uint8_t cnlAddr[] PROGMEM = {
0x02, 0x05, 0x0a, 0x0b, 0x0c, 0x14, 0x24, 0x25, 0x26, 0x27, // sIdx 0x00, 10 bytes for Channel0/List0
0x01, // sIdx 0x0a, 1 byte for Channel1/List4
}; // 11 byte
EE::s_cnlTbl cnlTbl[] = {
// cnl, lst, sIdx, sLen, pAddr;
{ 0, 0, 0x00, 10, 0x000f }, // Channel0/List0, 10 bytes at sIdx 0x00, Addr 0x000f
{ 1, 4, 0x0a, 1, 0x0019 }, // Channel1/List4, 1 byte at sIdx 0x0a, Addr 0x0019
};

In order to write the contents for only a few of the registers of List0 to the EEprom, we simply use:

const uint8_t list0defaults[] = {
0x01, 0x01, // led-mode on
0x24, 0x02, // measureInterval = 513sec = 0x0201
0x25, 0x01,
0x26, 0x03, // pwmStableDelay = 3sec = 0x03
0x27, 0x05 // pwmStableDelta = 2.5% = 0x05
};
hm.ee.setListArray(0,0,0,sizeof(list0defaults),list0defaults);
Todo:
Add references to related methods

The documentation for this class was generated from the following files: