mergCanBus

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
MergMemoryManagement.h
1 #ifndef MERGMEMORYMANAGEMENT_H
2 #define MERGMEMORYMANAGEMENT_H
3
4 #include <Arduino.h>
5 #include <EEPROM.h>
6
7 #define EVENT_SIZE 4
8 #define EVENT_VARS_SIZE 2
9 #define NNDD_SIZE 2
10 #define FLAG_SIZE 1
11 #define EMPTY_BYTE 0x00
12
13 #define FAILED_INDEX 255
15 #define MERG_MEMPOS 0
16 #define MERG_MEMORY_MODEL MERG_MEMPOS+1
17 #define CAN_ID_MEMPOS MERG_MEMORY_MODEL+1
18 #define NN_MEMPOS CAN_ID_MEMPOS+1
19 #define FLAGS_MEMPOS NN_MEMPOS+NNDD_SIZE
20 #define NUM_VARS_MEMPOS FLAGS_MEMPOS+FLAG_SIZE
21 #define NUM_EVENTS_MEMPOS NUM_VARS_MEMPOS+1
22 #define NUM_EVENTS_VARS_MEMPOS NUM_EVENTS_MEMPOS+1
23 #define VARS_MEMPOS NUM_EVENTS_VARS_MEMPOS+1
24 //device numbers
25 //events with its variables
26 //#define EVENTS_MEMPOS VARS_MEMPOS+MAX_AVAIL_VARS /**Position in memory. */
27
28
33 class MergMemoryManagement
34 {
35 public:
36 MergMemoryManagement();
37 MergMemoryManagement(byte num_node_vars,byte num_events,byte num_events_vars,byte max_device_numbers);
38 virtual ~MergMemoryManagement();
42 bool hasEvents(){return (numEvents>0?true:false);};
46 bool hasEventVars(unsigned int eventIdx);
47
48 unsigned int setEvent(byte *event);//return the index
49 unsigned int setEvent(byte *event,unsigned int eventIdx);
50 byte* getEvent(unsigned int index);
51
52 void setVar(unsigned int index,byte val);
53 byte getVar(unsigned int index);
54
55 unsigned int setEventVar(unsigned int eventIdx,unsigned int varIdx,byte val);
56 byte getEventVar(unsigned int eventIdx,unsigned int index);
57 byte *getEventVars(unsigned int eventIdx,unsigned int *len);
58
60 byte getNumVars(){return MAX_AVAIL_VARS;};
62 byte getNumEvents(){return numEvents;};
64 byte getNumEventVars(){return MAX_VAR_PER_EVENT;};
65
66 void eraseAllEvents();
67 void read();
68
69 unsigned int eraseEvent(unsigned int eventIdx);
70 //unsigned int eraseEvent(byte event[EVENT_SIZE]);
71 unsigned int eraseEvent(unsigned int nn,unsigned int ev);
72
73 void setCanId(byte canId);
77 byte getCanId(){return can_ID;};
78
79 unsigned int getNodeNumber();
80 void setNodeNumber(unsigned int val); //2 bytes representation
81
82 void setDeviceNumber(unsigned int val,byte port); //2 bytes representation for dn
83 unsigned int getDeviceNumber(byte port); //2 bytes representation
85 byte getNumDeviceNumber(){return MAX_NUM_DEVICE_NUMBERS;}; //2 bytes representation
86
87 unsigned int getEventIndex(byte ev1,byte ev2,byte ev3,byte ev4);
88 unsigned int getEventIndex(unsigned int nn,unsigned int ev);
89 bool hasEvent(byte ev1,byte ev2,byte ev3,byte ev4);
90
91 byte getNodeFlag();
92 void setNodeFlag(byte val);
93
94 void setUpNewMemory();
95 void dumpMemory();
96
97 protected:
98
99 private:
100 byte *return_eventVars; //used to return all the variables of an event
101 byte can_ID;
102 byte nn[NNDD_SIZE];
103 byte numEvents;
104 byte numDeviceNumbers;
105 byte MAX_AVAIL_VARS;
106 byte MAX_NUM_EVENTS;
107 byte MAX_VAR_PER_EVENT;
108 //int MAX_EVENTS_VAR_BUFFER;= MAX_NUM_EVENTS*MAX_VAR_PER_EVENT; /** Total amount of events variables that can be stored. Each var has 2 bytes. first is the index, second is the value */
109 byte MAX_NUM_DEVICE_NUMBERS;
110 int EVENTS_MEMPOS;
111 byte DN_MEMPOS;
113 //specify the memory model. it is like a module id identification. if the memory model is not equal to the eeprom it creates one. basic it reorganizes the
114 //the events and events vars
115 byte event[EVENT_SIZE]; //used to return this instead of a pointer to events array
116 byte flags;
117 void clear();
118 unsigned int temp; //used to avoid new memory allocation
119 byte nodeVariablesSize; //max supported number of node variables
120 byte eventVarsPerEvent; //number of supported vars per event
121 byte amountSuportedEvents; //number of supported events
122 unsigned int resolveEvVarArrayPos(byte evidx,byte varidx);
123 unsigned int incEventPos(unsigned int val);
124 unsigned int resolveEventPos(byte evidx);
125 void copyEvent(unsigned int fromIndex,unsigned int toIndex);
126
127 void write();
128 };
129
130 #endif // MERGMEMORYMANAGEMENT_H
MergMemoryManagement::getNodeNumber
unsigned int getNodeNumber()
Get the node number.
Definition: MergMemoryManagement.cpp:481
MergMemoryManagement::setEventVar
unsigned int setEventVar(unsigned int eventIdx, unsigned int varIdx, byte val)
Update the variable of an event.
Definition: MergMemoryManagement.cpp:408
MergMemoryManagement::setNodeFlag
void setNodeFlag(byte val)
Set the node mode retrieved from the flags.
Definition: MergMemoryManagement.cpp:498
MergMemoryManagement::hasEventVars
bool hasEventVars(unsigned int eventIdx)
Check if there event vars saved.
MergMemoryManagement::getEvent
byte * getEvent(unsigned int index)
Return the event pointed by the index If index out of bounds return empty event '0000'.
Definition: MergMemoryManagement.cpp:69
MergMemoryManagement::setNodeNumber
void setNodeNumber(unsigned int val)
Set the node number.
Definition: MergMemoryManagement.cpp:440
MergMemoryManagement::getDeviceNumber
unsigned int getDeviceNumber(byte port)
Get the device number.
Definition: MergMemoryManagement.cpp:468
MergMemoryManagement::eraseEvent
unsigned int eraseEvent(unsigned int eventIdx)
Erase a specific event by the event index. Has to reorganize the memory: events and events vars to av...
Definition: MergMemoryManagement.cpp:329
MergMemoryManagement::getVar
byte getVar(unsigned int index)
Return the node variable pointed by the index.
Definition: MergMemoryManagement.cpp:194
MergMemoryManagement::getEventVar
byte getEventVar(unsigned int eventIdx, unsigned int index)
Return the event variable for a specific event.
Definition: MergMemoryManagement.cpp:205
MergMemoryManagement::hasEvents
bool hasEvents()
Check if there is some learned event.
Definition: MergMemoryManagement.h:42
MergMemoryManagement::getNodeFlag
byte getNodeFlag()
Get the node mode retrieved from the flags.
Definition: MergMemoryManagement.cpp:491
MergMemoryManagement::dumpMemory
void dumpMemory()
Print all memory to serial. Used for debug.
Definition: MergMemoryManagement.cpp:505
MergMemoryManagement::hasEvent
bool hasEvent(byte ev1, byte ev2, byte ev3, byte ev4)
Check if the given event is present in the memory.
Definition: MergMemoryManagement.cpp:180
MergMemoryManagement::~MergMemoryManagement
virtual ~MergMemoryManagement()
Destructor: clear the allocated buffers.
Definition: MergMemoryManagement.cpp:30
MergMemoryManagement::getNumDeviceNumber
byte getNumDeviceNumber()
Return the maximum number of supported device numbers.
Definition: MergMemoryManagement.h:85
MergMemoryManagement::setCanId
void setCanId(byte canId)
Set the can id.
Definition: MergMemoryManagement.cpp:430
MergMemoryManagement::getCanId
byte getCanId()
Get the can id.
Definition: MergMemoryManagement.h:77
MergMemoryManagement::setUpNewMemory
void setUpNewMemory()
Clear the EEPROM memory and the internal events. Should be called just in the first setup of the node...
Definition: MergMemoryManagement.cpp:38
MergMemoryManagement::setVar
void setVar(unsigned int index, byte val)
Set the value of a node variable.
Definition: MergMemoryManagement.cpp:391
MergMemoryManagement::getEventVars
byte * getEventVars(unsigned int eventIdx, unsigned int *len)
Get all variables of an specific event.
Definition: MergMemoryManagement.cpp:226
MergMemoryManagement::MergMemoryManagement
MergMemoryManagement()
Constructor: Default constructor. Does nothing.
Definition: MergMemoryManagement.cpp:6
MergMemoryManagement::getNumEventVars
byte getNumEventVars()
Return the number of learned events variables.
Definition: MergMemoryManagement.h:64
MergMemoryManagement::setEvent
unsigned int setEvent(byte *event)
Put a new event in the memory and return the index.
Definition: MergMemoryManagement.cpp:96
MergMemoryManagement::read
void read()
Read all data from eprom memory and put in the internal arrays.
Definition: MergMemoryManagement.cpp:258
MergMemoryManagement::eraseAllEvents
void eraseAllEvents()
Erase all events and their variables.
Definition: MergMemoryManagement.cpp:314
MergMemoryManagement::getNumVars
byte getNumVars()
Return the number of set node variables.
Definition: MergMemoryManagement.h:60
MergMemoryManagement::setDeviceNumber
void setDeviceNumber(unsigned int val, byte port)
Set the device number.
Definition: MergMemoryManagement.cpp:453
MergMemoryManagement::getNumEvents
byte getNumEvents()
Return the number of learned events.
Definition: MergMemoryManagement.h:62
MergMemoryManagement
Definition: MergMemoryManagement.h:33
MergMemoryManagement::getEventIndex
unsigned int getEventIndex(byte ev1, byte ev2, byte ev3, byte ev4)
Return the internal index of an event using 4 bytes as parameters. The first 2 bytes are supposed to ...
Definition: MergMemoryManagement.cpp:161