Description
setDistribution() / setDistributionAll()
– controls the send-behaviour of the variable.
Syntax
myPool.setDistribution( ou8_variable_index, ou8_behaviour
, u16_interval_ms)
;myPool.setDistributionAll( ou8_behaviour
, u16_interval_ms)
;
Parameters
uint8_t ou8_variable_index: the number (index) of the variable of interest.
uint8_t ou8_behaviour: the new behaviour of the variable:
– DP_SEND_NEVER
never distribute the value of this variable (e.g. we’re only passively listening)
– DP_SEND_ON_CHANGE
send the variable on the bus whenever we change its value (default)
– DP_SEND_ON_INTERVAL
send the variable in intervals [1….65535 ms] (variable first needs to be set to start the interval)
– DP_SEND_ON_INTERVAL_AND_CHANGE
send the variable on change and in intervals
optional:
uint16_t u16_interval_ms: the interval time in [1 … 65535 ms] that this variable shall be sent on the CAN bus.
Returns
uint8_t 0: OK
1: ERROR an argument is out of range
2: ERROR pool is not initialised yet (->begin())
Example Codes:
The following code example distributes the variable values on the CAN bus to the other peers (e.g. CAN2SER Datapool monitor)
#include "Datapool.h"
// Definition of the datapool:
#define NB_OF_VARIABLES 4
#define POOL_NAME "MachineDP_V123"
DATAPOOL myPool( &MCAN0, &BOOTLOADER_SETTING, POOL_NAME, NB_OF_VARIABLES );
void setup()
{
myPool.begin();
myPool.setValue(0, (float) 5.33); // set var0 - float value
myPool.setValue(1, 2, 0xAA); // set var1 - data byte 2
myPool.setValue(2, (uint32_t) 123); // set var2 - unsigned int
myPool.setValue(3, (int32_t) -234); // set var3 - signed int
myPool.setDistribution(1, DP_SEND_ON_INTERVAL, 300); // send var1 every 300 ms
myPool.setDistribution(2, DP_SEND_ON_INTERVAL, 1000); // send var2 every 1 sec
}
void loop()
{
}
Notes and Warnings
Be aware that by default all variables values (once initialised) will be sent out to all other peers whenever a ‘new’ peer appears on the bus. This could have the effect that variables that’s value is not “produced” by the particular dice device, might still be shared and declared valid by the remaining devices.
An example would be a data pool with a variable that stands for the dig. input of dice-1. dice-2 would receive the value of the variable from dice-1 if the input goes high. Now if dice-1 is switched off, and dice-3 comes into the network, then dice-1 would share this ‘high’-value to dice-3 even so dice-1 (the producer of this information) is not longer available. In such case the setting DP_SEND_NEVER might be a good option for the variable on all dices but dice-1.
Examples can be found in the Arduino IDE menu:
File -> Examples -> Datapool ->