mergCanBus

- Main Page
- Classes
- Files

- Class List
- Class Index
- Class Members

All Classes Functions Typedefs
Public Member Functions | List of all members
MergMemoryManagement Class Reference

`#include <MergMemoryManagement.h>`

## Public Member Functions
| MergMemoryManagement ()
| Constructor: Default constructor. Does nothing.
| MergMemoryManagement (byte num_node_vars, byte num_events, byte num_events_vars, byte max_device_numbers)
| Constructor: clear array and reads the EEPROM.
virtual | ~MergMemoryManagement ()
| Destructor: clear the allocated buffers.
bool | hasEvents ()
| Check if there is some learned event. More...
bool | hasEventVars (unsigned int eventIdx)
| Check if there event vars saved. More...
unsigned int | setEvent (byte *event)
| Put a new event in the memory and return the index. More...
unsigned int | setEvent (byte *event, unsigned int eventIdx)
| Put a new event in the memory and return its index. More...
byte * | getEvent (unsigned int index)
| Return the event pointed by the index If index out of bounds return empty event '0000'. More...
void | setVar (unsigned int index, byte val)
| Set the value of a node variable. More...
byte | getVar (unsigned int index)
| Return the node variable pointed by the index. More...
unsigned int | setEventVar (unsigned int eventIdx, unsigned int varIdx, byte val)
| Update the variable of an event. More...
byte | getEventVar (unsigned int eventIdx, unsigned int index)
| Return the event variable for a specific event. More...
byte * | getEventVars (unsigned int eventIdx, unsigned int *len)
| Get all variables of an specific event. More...
byte | getNumVars ()
| Return the number of set node variables.
byte | getNumEvents ()
| Return the number of learned events.
byte | getNumEventVars ()
| Return the number of learned events variables.
void | eraseAllEvents ()
| Erase all events and their variables.
void | read ()
| Read all data from eprom memory and put in the internal arrays. More...
unsigned int | eraseEvent (unsigned int eventIdx)
| Erase a specific event by the event index. Has to reorganize the memory: events and events vars to avoid fragmentation. More...
unsigned int | eraseEvent (unsigned int nn, unsigned int ev)
| Erase a specific event. Has to reorganize the memory: events and events vars to avoid fragmentation. More...
void | setCanId (byte canId)
| Set the can id. More...
byte | getCanId ()
| Get the can id. More...
unsigned int | getNodeNumber ()
| Get the node number. More...
void | setNodeNumber (unsigned int val)
| Set the node number. More...
void | setDeviceNumber (unsigned int val, byte port)
| Set the device number. More...
unsigned int | getDeviceNumber (byte port)
| Get the device number. More...
byte | getNumDeviceNumber ()
| Return the maximum number of supported device numbers.
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 be the node number and the last 2 the event number. More...
unsigned int | getEventIndex (unsigned int nn, unsigned int ev)
| Return the internal index of an event. More...
bool | hasEvent (byte ev1, byte ev2, byte ev3, byte ev4)
| Check if the given event is present in the memory. More...
byte | getNodeFlag ()
| Get the node mode retrieved from the flags. More...
void | setNodeFlag (byte val)
| Set the node mode retrieved from the flags. More...
void | setUpNewMemory ()
| Clear the EEPROM memory and the internal events. Should be called just in the first setup of the node and never inside a loop. May damage the EEPROM.
void | dumpMemory ()
| Print all memory to serial. Used for debug. More...

## Detailed Description

Class that handles the EEPROM and maintains the data in a RAM memory.

## Member Function Documentation

void MergMemoryManagement::dumpMemory | ( |  | ) |

Print all memory to serial. Used for debug.

Find the event variable position in memory

unsigned int MergMemoryManagement::eraseEvent | ( | unsigned int | eventIdx | ) |

Erase a specific event by the event index. Has to reorganize the memory: events and events vars to avoid fragmentation.

Parameters

  eventIdx | event index starting on 0.

unsigned int MergMemoryManagement::eraseEvent | ( | unsigned int | nn,
|  | unsigned int | ev
| ) |  |

Erase a specific event. Has to reorganize the memory: events and events vars to avoid fragmentation.

Parameters

  nn | node number (16 bits integer)
  ev | event number (16 bits integer)

byte MergMemoryManagement::getCanId | ( |  | ) |
| inline

Get the can id.

Returns
  The can id

unsigned int MergMemoryManagement::getDeviceNumber | ( | byte | port | ) |

Get the device number.

Parameters

  port | The device port.

Returns
  The node number (16 bit integer).

byte * MergMemoryManagement::getEvent | ( | unsigned int | index | ) |

Return the event pointed by the index If index out of bounds return empty event '0000'.

Returns
  4 bytes

unsigned int MergMemoryManagement::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 be the node number and the last 2 the event number.

Returns
  event index starting on 0.

unsigned int MergMemoryManagement::getEventIndex | ( | unsigned int | nn,
|  | unsigned int | ev
| ) |  |

Return the internal index of an event.

Parameters

  nn | Node number (16 bit integer)
  ev | Event number (16 bit integer)

Returns
  event index starting on 0.

byte MergMemoryManagement::getEventVar | ( | unsigned int | eventIdx,
|  | unsigned int | index
| ) |  |

Return the event variable for a specific event.

Returns
  FAILED_INDEX if index out of bounds

byte * MergMemoryManagement::getEventVars | ( | unsigned int | eventIdx,
|  | unsigned int * | len
| ) |  |

Get all variables of an specific event.

Parameters

  eventIdx | is the event index starting on 0.
  len | indicates how many variables

byte MergMemoryManagement::getNodeFlag | ( |  | ) |

Get the node mode retrieved from the flags.

Returns
  0 if SLIM, 1 if FLIM

unsigned int MergMemoryManagement::getNodeNumber | ( |  | ) |

Get the node number.

Returns
  The node number (16 bit integer).

byte MergMemoryManagement::getVar | ( | unsigned int | index | ) |

Return the node variable pointed by the index.

Returns
  FAILED_INDEX if index is out of bounds

bool MergMemoryManagement::hasEvent | ( | byte | ev1,
|  | byte | ev2,
|  | byte | ev3,
|  | byte | ev4
| ) |  |

Check if the given event is present in the memory.

Returns
  Return true if the event is present in memory, else return false.

bool MergMemoryManagement::hasEvents | ( |  | ) |
| inline

Check if there is some learned event.

Returns
  True if the number of events is bigger than 0, else false.

bool MergMemoryManagement::hasEventVars | ( | unsigned int | eventIdx | ) |

Check if there event vars saved.

Returns
  True if the number of events vars is bigger than 0, else false.

void MergMemoryManagement::read | ( |  | ) |

Read all data from eprom memory and put in the internal arrays.

Returns
  Memory organization 512 bytes is the max value for simple arduino byte=value;explanation 0xaa ; indicates that it is a merg arduino memory storage can_id;store the can_id hh Node number;high byte from node number ll Node number;low byte from node number flags hh device number;high byte from node number ll device number;low byte from node number amount of node variables amount of learned events amount of learned event variables 20 bytes for node variables 120 bytes for 30 learned events 150 bytes for learned event variables. 2 bytes for each variable. 1st is the event number index. the index is the position of the event in the memory range from 1 to 30

void MergMemoryManagement::setCanId | ( | byte | canId | ) |

Set the can id.

Parameters

  canId | The can id

void MergMemoryManagement::setDeviceNumber | ( | unsigned int | val,
|  | byte | port
| ) |  |

Set the device number.

Parameters

  val | The node number (16 bit integer).

unsigned int MergMemoryManagement::setEvent | ( | byte * | event | ) |

Put a new event in the memory and return the index.

Returns
  event index starting with 0.

unsigned int MergMemoryManagement::setEvent | ( | byte * | event,
|  | unsigned int | index
| ) |  |

Put a new event in the memory and return its index.

Parameters

  event | 4 bytes event
  index | event index starting in 0.

unsigned int MergMemoryManagement::setEventVar | ( | unsigned int | eventIdx,
|  | unsigned int | varIdx,
|  | byte | val
| ) |  |

Update the variable of an event.

Parameters

  eventIdx | Event index starting on 0.
  varIdx | Variable index starting on 0.
  val | Value of the variable.

Returns
  if success return the varIdx. if not return varIdx+1

void MergMemoryManagement::setNodeFlag | ( | byte | val | ) |

Set the node mode retrieved from the flags.

Parameters

  mode | 0 if SLIM, 1 if FLIM

void MergMemoryManagement::setNodeNumber | ( | unsigned int | val | ) |

Set the node number.

Parameters

  val | The node number (16 bit integer).

void MergMemoryManagement::setVar | ( | unsigned int | index,
|  | byte | val
| ) |  |

Set the value of a node variable.

Parameters

  index | variable index
  val | variable value

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

- MergMemoryManagement.h
- MergMemoryManagement.cpp