Description
DATAPOOL()
– the constructor creates a new instance of a data pool.
Syntax
DATAPOOL( opt_can_bus, opt_bootloader_sets, os_PoolName,
ou8_nb_of_variables, opf_callBackFunction )
Parameters
SAMC21_CAN* opt_can_bus : pointer to the CAN bus object to share the data pool on (e.g. &MCAN0)
BOOTLOADER_SETTINGS_CLASS* opt_bootloader_sets : pointer to the global bootloader settings object (e.g. &BOOTLOADER_SETTING)
String os_PoolName : unique name that identifies this data pool. Must be the same on all devices that share this pool. The name must be between 8 and 32 characters long.
uint8_t ou8_nb_of_variables : number of 32 bit variables that this data pool holds. Must be the same on all devices sharing the same pool.
void* opf_callBackFunction : function pointer to a call back function that will be called when a variables is changed (by a peer). (optional) , if you do not need a callback function, then leave it away)
Returns
the new data pool.
Example Codes:
The following code example defines a data pool including an callback function that is called whenever a variable is modified by another peer.
#include "Datapool.h"
#define NB_OF_VARIABLES 3
#define POOL_NAME "A_SimplePool_V1_0"
void myCallBack(uint8_t ou8_NbOfUpdatedVariable);
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING, POOL_NAME, NB_OF_VARIABLES, myCallBack );
void setup() {
while(!Serial);
myPool.begin();
Serial.println("Enter new value of Var1");
}
int8_t s8_modVar = -1;
void loop()
{
if(Serial.peek() != -1)
{
int i_new = Serial.readStringUntil('n').toInt();
myPool.setValue( 1, (int32_t)i_new );
}
if(s8_modVar > -1)
{
Serial.println("Var"+String(s8_modVar)+": "+
String( myPool.getValue_int32(s8_modVar) ));
s8_modVar = -1;
}
}
void myCallBack(uint8_t ou8_NbOfUpdatedVariable)
{
s8_modVar = ou8_NbOfUpdatedVariable;
}
Notes and Warnings
The data pool name is a human readable string that identifies the data pool among the participating clients. The name will internally be used to create hash key ‘magic number’ that the library uses to correlate the data pools on the bus. You can use the function uint32_t u32_getMagic(); to read it.
ou8_nb_of_variables and os_PoolName are defining the data pool. Make sure that its the same on all devices sharing it!
Examples can be found in the Arduino IDE menu:
File -> Examples -> Datapool ->