protelis.coord.sharedtimer.pt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of protelis-lang Show documentation
Show all versions of protelis-lang Show documentation
Essential libraries for the Protelis language
module protelis:coord:sharedtimer
import protelis:state:time
/*
* Returns an int, representing the current clock
*/
public def sharedTimer(period, dt) {
share (clock, nbrClock <- 0) {
let clockPerceived = maxHood(nbrClock);
if (clockPerceived <= clock) {
/*
* I'm currently as fast as the fastest device in the neighborhood,
* so keep on counting time
*/
clock + if (cyclicTimerWithDecay(period, dt)) { 1 } else { 0 }
} else {
/*
* Someone else's faster, take his time, and restart counting
*/
clockPerceived
}
}
}