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
16 #define EVENT_SIZE 4
17 #define EVENT_VARS_SIZE 2
18 #define NNDD_SIZE 2
19 #define FLAG_SIZE 1
20 #define EMPTY_BYTE 0x00
21
22 #define FAILED_INDEX 255
24 #define MERG_MEMPOS 0
25 #define MERG_MEMORY_MODEL MERG_MEMPOS+1
26 #define CAN_ID_MEMPOS MERG_MEMORY_MODEL+1
27 #define NN_MEMPOS CAN_ID_MEMPOS+1
28 #define FLAGS_MEMPOS NN_MEMPOS+NNDD_SIZE
29 #define NUM_VARS_MEMPOS FLAGS_MEMPOS+FLAG_SIZE
30 #define NUM_EVENTS_MEMPOS NUM_VARS_MEMPOS+1
31 #define NUM_EVENTS_VARS_MEMPOS NUM_EVENTS_MEMPOS+1
32 #define VARS_MEMPOS NUM_EVENTS_VARS_MEMPOS+1
33 //device numbers
34 //events with its variables
35 //#define EVENTS_MEMPOS VARS_MEMPOS+MAX_AVAIL_VARS /**Position in memory. */
36
37
42 class MergMemoryManagement
43 {
44 public:
45 MergMemoryManagement();
46 MergMemoryManagement(byte num_node_vars,byte num_events,byte num_events_vars,byte max_device_numbers);
47 virtual ~MergMemoryManagement();
49 bool hasEvents(){return (numEvents>0?true:false);};
50 bool hasEventVars(unsigned int eventIdx);
51 byte* getEvent(unsigned int index);
52 byte getVar(unsigned int index);
53 byte getEventVar(unsigned int eventIdx,unsigned int index);
54 byte *getEventVars(unsigned int eventIdx,unsigned int *len);
56 byte getNumVars(){return MAX_AVAIL_VARS;};
58 byte getNumEvents(){return numEvents;};
60 byte getNumEventVars(){return MAX_VAR_PER_EVENT;};
61
62 void eraseAllEvents();
63 void read();
64
65 unsigned int eraseEvent(unsigned int eventIdx);
66 //unsigned int eraseEvent(byte event[EVENT_SIZE]);
67 unsigned int eraseEvent(unsigned int nn,unsigned int ev);
68
69
70 void setVar(unsigned int index,byte val);
71 void setCanId(byte canId);
72 void setNodeNumber(unsigned int val); //2 bytes representation
73
74 void setDeviceNumber(unsigned int val,byte port); //2 bytes representation for dn
75 unsigned int getDeviceNumber(byte port); //2 bytes representation
76 byte getNumDeviceNumber(){return MAX_NUM_DEVICE_NUMBERS;}; //2 bytes representation
77
78
79 byte getCanId(){return can_ID;};
80 unsigned int getNodeNumber();
81
82 unsigned int setEvent(byte *event);//return the index
83 unsigned int setEvent(byte *event,unsigned int eventIdx);
84
85 unsigned int setEventVar(unsigned int eventIdx,unsigned int varIdx,byte val);
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:476
MergMemoryManagement::setEventVar
unsigned int setEventVar(unsigned int eventIdx, unsigned int varIdx, byte val)
Update the variable of an event.
Definition: MergMemoryManagement.cpp:404
MergMemoryManagement::setNodeFlag
void setNodeFlag(byte val)
Set the node mode retrieved from the flags.
Definition: MergMemoryManagement.cpp:493
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:65
MergMemoryManagement::setNodeNumber
void setNodeNumber(unsigned int val)
Set the node number.
Definition: MergMemoryManagement.cpp:436
MergMemoryManagement::getDeviceNumber
unsigned int getDeviceNumber(byte port)
Get the device number.
Definition: MergMemoryManagement.cpp:463
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:325
MergMemoryManagement::getVar
byte getVar(unsigned int index)
Return the node variable pointed by the index.
Definition: MergMemoryManagement.cpp:190
MergMemoryManagement::getEventVar
byte getEventVar(unsigned int eventIdx, unsigned int index)
Return the event variable for a specific event.
Definition: MergMemoryManagement.cpp:201
MergMemoryManagement::hasEvents
bool hasEvents()
Check if there is some learned event.
Definition: MergMemoryManagement.h:49
MergMemoryManagement::getNodeFlag
byte getNodeFlag()
Get the node mode retrieved from the flags.
Definition: MergMemoryManagement.cpp:486
MergMemoryManagement::dumpMemory
void dumpMemory()
Print all memory to serial. Used for debug.
Definition: MergMemoryManagement.cpp:500
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:176
MergMemoryManagement::setCanId
void setCanId(byte canId)
Set the can id.
Definition: MergMemoryManagement.cpp:426
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:34
MergMemoryManagement::setVar
void setVar(unsigned int index, byte val)
Set the value of a node variable.
Definition: MergMemoryManagement.cpp:387
MergMemoryManagement::getEventVars
byte * getEventVars(unsigned int eventIdx, unsigned int *len)
Get all variables of an specific event.
Definition: MergMemoryManagement.cpp:222
MergMemoryManagement::MergMemoryManagement
MergMemoryManagement()
Constructor: clear array and reads the EEPROM.
Definition: MergMemoryManagement.cpp:6
MergMemoryManagement::getNumEventVars
byte getNumEventVars()
Return the number of learned events variables.
Definition: MergMemoryManagement.h:60
MergMemoryManagement::setEvent
unsigned int setEvent(byte *event)
Put a new event in the memory and return the index.
Definition: MergMemoryManagement.cpp:92
MergMemoryManagement::read
void read()
Read all data from eprom memory and put in the internal arrays.
Definition: MergMemoryManagement.cpp:254
MergMemoryManagement::eraseAllEvents
void eraseAllEvents()
Erase all events and their variables.
Definition: MergMemoryManagement.cpp:310
MergMemoryManagement::getNumVars
byte getNumVars()
Return the number of set node variables.
Definition: MergMemoryManagement.h:56
MergMemoryManagement::setDeviceNumber
void setDeviceNumber(unsigned int val, byte port)
Set the device number.
Definition: MergMemoryManagement.cpp:449
MergMemoryManagement::getNumEvents
byte getNumEvents()
Return the number of learned events.
Definition: MergMemoryManagement.h:58
MergMemoryManagement
Definition: MergMemoryManagement.h:42
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:157