Waspmote Stack EEPROM
The class WaspStackEEPROM has been developed to allow saving frames into the EEPROM memory instead of the SD card.
There two types of stack configuration:
LIFO stack (last input, first output). This means that when we extract data, the most recently stored information will be provided first.
FIFO stack (first input, first output). In this case, data is extracted in the same order as they were inserted inside the stack.
The user may find it interesting for storing, for example, frames which could not be delivered: if even after several retries, the communication was not successful, we can store data in the stack in order to send it next time Waspmote wakes up.
Another use would be to store frames which we want to send in the future; this is great for decreasing the use of the communication module, and saving battery.
A complete example of the functions: www.development.libelium.com/ut-06-stack-eeprom-basic-operation
Waspmote Files
WaspStackEEPROM.h ; WaspStackEEPROM.cpp
Constructor
To start using the Waspmote StackEEPROM library, an object from class WaspStackEEPROM must be created. This object, called stack
, is created inside the Waspmote StackEEPROM library.
When calling this constructor, the block_size
variable is initialized to BLOCK_SIZE
constant. Also, _mode
variable is set to the default stack mode LIFO_MODE
.
Pre-Defined Constants
There are some constants defined in 'WaspStackEEPROM.h' used to limit the stack area and the size of each block inside the stack.
START_STACK
→ First position of the stack into the EEPROM. Must be greater than 1023.
END_STACK
→ Last position of the stack into the EEPROM. Max value is 4095.
BLOCK_SIZE
→ It fixes the size of each block inside the EEPROM. Max value is 255.
Initializing the stack
This function cleans the stack area writing 0xFF in each memory position. Also, it initializes the stack counter to 0 and the Front Pointer and Back Pointer of the stack. It is possible to choose the stack mode as input: LIFO_MODE
or FIFO_MODE
. By default, LIFO configuration is used. It returns \'1\' if success and \'0\' if error.
Example of use:
It returns nothing.
Initializing the block size
Before using the stack it\'s mandatory to initialize the block size. With the function initBlockSize()
, the user can define the block size. By default, the block size has the value of BLOCK_SIZE
constant. It returns nothing. Each block includes one byte to indicate the length of the data and the rest of the block can be used for data.
Example of use:
Push
To store a block of data into the stack, the push()
function must be used. The size of the block must be lower than block_size
. The required are: a vector of data to store and the vector length. The vector of data must be uint8_t type.
It returns:
\'1\' on success
\'0\' error writing
\'2\' is full
\'3\' block size small.
Example of use:
Pop
The pop()
function extracts a block of data previously stored into the stack. The function requires a pointer to a vector to store the extracted data.
It returns:
\'0\' if empty
\'1\' error reading
\'2\' if error updating the new pointer
Positive value, except 1 or 2, means the number of bytes read
Example of use:
Last updated