VLCB
Loading...
Searching...
No Matches
Configuration.h
Go to the documentation of this file.
1// Copyright (C) Sven Rosvall (sven@rosvall.ie)
2// This file is part of VLCB-Arduino project on https://github.com/SvenRosvall/VLCB-Arduino
3// Licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
4// The full licence can be found at: http://creativecommons.org/licenses/by-nc-sa/4.0/
5
6#pragma once
7
8#include "Storage.h"
9#include "Parameters.h"
10#include "vlcbdefs.hpp"
11
12namespace VLCB
13{
14
15// in-memory hash table
16static const byte EE_HASH_BYTES = 4;
17static const byte HASH_LENGTH = 128;
18
28
34
35//
37//
38
40{
41public:
43 Configuration(Storage * theStorage);
44 void begin();
45
46 byte findExistingEvent(unsigned int nn, unsigned int en, byte startIndex = 0) const;
47 byte findEventSpace() const;
48 byte findExistingEventByEv(byte evnum, byte evval) const;
49
50 void printEvHashTable(bool raw);
51 byte getEvTableEntry(byte tindex) const;
52 byte numEvents() const;
53 void updateEvHashEntry(byte idx);
54 void clearEvHashTable();
55 byte getEventEVval(byte idx, byte evnum) const;
56 void writeEventEV(byte idx, byte evnum, byte evval);
57
58 byte readNV(byte idx) const;
59 void writeNV(byte idx, byte val);
60
61 bool isEventSlotInUse(byte eventIndex) const;
62 void readEvent(byte idx, byte tarr[EE_HASH_BYTES]) const;
63 void writeEvent(byte eventIndex, unsigned int nn, unsigned int en);
64 void writeEvent(byte index, const byte data[EE_HASH_BYTES]);
65 void cleareventEEPROM(byte index);
66 void resetModule();
67 void commitToEEPROM();
68
69 void setCANID(byte canid);
71 void setModuleNormalMode(unsigned int nodeNumber);
72 void setHeartbeat(bool beat);
73 void setNodeNum(unsigned int nn);
74 void setEventAck(bool ea);
75 void setFcuCompatability(bool fcu);
76
77 void setModuleId(byte manu, byte moduleId);
78 void setVersion(char maj, char min, char beta);
79
80 void setResetFlag();
81 void clearResetFlag();
82 bool isResetFlagSet();
83
84 void setName(const char *mname);
85 const char *getModuleName() const { return _mname; }
86
87 byte getNumNodeVariables() const;
88 byte getNumEvents() const;
89 byte getNumEVs() const;
90
91 void setNumNodeVariables(int n);
92 void setNumEvents(int n);
93 void setNumEVs(int n);
94
95 bool getFlag(VlcbParamFlags flag);
96 void setFlag(VlcbParamFlags flag);
97 void clearFlag(VlcbParamFlags flag);
98
99 unsigned char getParam(VlcbParams p);
101
103 unsigned int EE_EVENTS_START = 0; // Value calculated in begin() unless set by user.
104 byte EE_BYTES_PER_EVENT; // Value calculated in begin()
105 unsigned int EE_FREE_BASE; // Value calculated in begin()
106 unsigned int EE_USER_BYTES = 0; // Specified by user in setup for ESP processors.
107
111 byte CANID;
113 unsigned int nodeNum;
114
115 // These functions shouldn't be here. But keep them for now.
116 unsigned int freeSRAM();
117 void reboot();
118
119 static void setTwoBytes(byte *target, unsigned int value);
120 static unsigned int getTwoBytes(const byte *bytes);
121 static bool nnenEquals(const byte lhs[EE_HASH_BYTES], const byte rhs[EE_HASH_BYTES]);
122 static const char * modeString(VlcbModeParams mode);
123
124private:
125 Storage * storage;
126 const char *_mname;
127 Parameters _mparams;
128
129 void setModuleMode(VlcbModeParams m);
130 byte makeHash(byte tarr[EE_HASH_BYTES]) const;
131 void makeEvHashTable();
132
133 void loadNVs();
134
135 unsigned int getEVAddress(byte idx, byte evnum) const;
136
137 byte *evhashtbl;
138};
139
140}
unsigned char getParam(VlcbParams p)
Definition Configuration.cpp:712
void setModuleUninitializedMode()
Definition Configuration.cpp:78
void setResetFlag()
Definition Configuration.cpp:630
void cleareventEEPROM(byte index)
clear an event from the table
Definition Configuration.cpp:455
static bool nnenEquals(const byte lhs[EE_HASH_BYTES], const byte rhs[EE_HASH_BYTES])
Definition Configuration.cpp:661
void setNumEVs(int n)
Definition Configuration.cpp:692
void printEvHashTable(bool raw)
print the event hash table
Definition Configuration.cpp:352
byte getNumEvents() const
Definition Configuration.cpp:671
void resetModule()
reset the module to factory defaults
Definition Configuration.cpp:570
void setName(const char *mname)
Definition Configuration.cpp:645
unsigned int EE_FREE_BASE
Definition Configuration.h:105
unsigned int freeSRAM()
get free RAM
Definition Configuration.cpp:546
void setCANID(byte canid)
store the CANID
Definition Configuration.cpp:138
byte findEventSpace() const
find the first empty EEPROM event slot - the hash table entry == 0
Definition Configuration.cpp:191
static void setTwoBytes(byte *target, unsigned int value)
Definition Configuration.cpp:650
unsigned int nodeNum
Definition Configuration.h:113
byte CANID
Definition Configuration.h:111
bool getFlag(VlcbParamFlags flag)
Definition Configuration.cpp:707
void setVersion(char maj, char min, char beta)
Definition Configuration.cpp:722
Parameters & getParams()
Definition Configuration.cpp:717
void setModuleNormalMode(unsigned int nodeNumber)
Definition Configuration.cpp:85
byte readNV(byte idx) const
Definition Configuration.cpp:413
void readEvent(byte idx, byte tarr[EE_HASH_BYTES]) const
return an existing EEPROM event as a 4-byte array – NN + EN
Definition Configuration.cpp:250
void setFcuCompatability(bool fcu)
Definition Configuration.cpp:127
byte getEventEVval(byte idx, byte evnum) const
return an event variable (EV) value given the event table index and EV number
Definition Configuration.cpp:271
void setModuleId(byte manu, byte moduleId)
Definition Configuration.cpp:727
const char * getModuleName() const
Definition Configuration.h:85
bool isEventSlotInUse(byte eventIndex) const
Definition Configuration.cpp:241
unsigned int EE_NVS_START
Definition Configuration.h:102
byte findExistingEvent(unsigned int nn, unsigned int en, byte startIndex=0) const
lookup an event by node number and event number, using the hash table
Definition Configuration.cpp:157
void writeNV(byte idx, byte val)
Definition Configuration.cpp:422
void writeEventEV(byte idx, byte evnum, byte evval)
write an event variable
Definition Configuration.cpp:279
void setFlag(VlcbParamFlags flag)
Definition Configuration.cpp:697
void setEventAck(bool ea)
Definition Configuration.cpp:119
void updateEvHashEntry(byte idx)
update a single hash table entry – after a learn or unlearn
Definition Configuration.cpp:303
void begin()
initialise and set default values
Definition Configuration.cpp:53
VlcbModeParams currentMode
Definition Configuration.h:112
Configuration()
ctor
Definition Configuration.cpp:40
void setNumNodeVariables(int n)
Definition Configuration.cpp:681
unsigned int EE_USER_BYTES
Definition Configuration.h:106
void clearEvHashTable()
clear the hash table
Definition Configuration.cpp:338
unsigned int EE_EVENTS_START
Definition Configuration.h:103
bool isResetFlagSet()
Definition Configuration.cpp:640
void reboot()
Definition Configuration.cpp:484
void writeEvent(byte eventIndex, unsigned int nn, unsigned int en)
generic EEPROM access methods
Definition Configuration.cpp:435
byte getNumEVs() const
Definition Configuration.cpp:676
void commitToEEPROM()
Definition Configuration.cpp:465
static const char * modeString(VlcbModeParams mode)
Definition Configuration.cpp:324
byte EE_BYTES_PER_EVENT
Definition Configuration.h:104
bool eventAck
Definition Configuration.h:109
void setNodeNum(unsigned int nn)
store the node number
Definition Configuration.cpp:147
void clearResetFlag()
Definition Configuration.cpp:635
byte getEvTableEntry(byte tindex) const
return a single hash table entry by index
Definition Configuration.cpp:397
byte findExistingEventByEv(byte evnum, byte evval) const
Definition Configuration.cpp:207
bool fcuCompatible
Definition Configuration.h:110
void setHeartbeat(bool beat)
Definition Configuration.cpp:111
byte numEvents() const
return the number of stored events
Definition Configuration.cpp:379
void clearFlag(VlcbParamFlags flag)
Definition Configuration.cpp:702
static unsigned int getTwoBytes(const byte *bytes)
Definition Configuration.cpp:656
byte getNumNodeVariables() const
Definition Configuration.cpp:666
void setNumEvents(int n)
Definition Configuration.cpp:687
bool heartbeat
Definition Configuration.h:108
Definition Parameters.h:16
Interface for persistent storage. Used by Configuration class.
Definition Storage.h:15
Definition AbstractEventTeachingService.cpp:13
FlagBits
Definition Configuration.h:29
@ EVENT_ACK_BIT
Definition Configuration.h:31
@ HEARTBEAT_BIT
Definition Configuration.h:30
@ FCU_COMPATIBLE_BIT
Definition Configuration.h:32
EepromLocations
Definition Configuration.h:19
@ LOCATION_FLAGS
Definition Configuration.h:24
@ LOCATION_CANID
Definition Configuration.h:21
@ LOCATION_NODE_NUMBER_LOW
Definition Configuration.h:23
@ LOCATION_MODE
Definition Configuration.h:20
@ LOCATION_RESET_FLAG
Definition Configuration.h:25
@ LOCATION_NODE_NUMBER_HIGH
Definition Configuration.h:22
@ LOCATION_RESERVED_SIZE
Definition Configuration.h:26
VlcbParams
Definition vlcbdefs.hpp:507
VlcbModeParams
Definition vlcbdefs.hpp:562
VlcbParamFlags
Definition vlcbdefs.hpp:544