All Downloads are FREE. Search and download functionalities are using the official Maven repository.

protelis.coord.sharedtimer.pt Maven / Gradle / Ivy

There is a newer version: 17.6.0
Show newest version
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
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy