Time deviation support for Mica Motes

This commit is contained in:
Andreas Löscher 2015-02-26 16:51:57 +01:00
parent efbd170733
commit cb6759c0a9
2 changed files with 38 additions and 9 deletions

View file

@ -44,6 +44,7 @@ import org.contikios.cooja.MoteType;
import org.contikios.cooja.Simulation;
import org.contikios.cooja.mote.memory.MemoryInterface;
import org.contikios.cooja.motes.AbstractEmulatedMote;
import avrora.arch.avr.AVRProperties;
import avrora.core.LoadableProgram;
import avrora.sim.AtmelInterpreter;
@ -54,6 +55,8 @@ import avrora.sim.mcu.EEPROM;
import avrora.sim.platform.MicaZ;
import avrora.sim.platform.PlatformFactory;
import org.contikios.cooja.avrmote.interfaces.MicaClock;
/**
* @author Joakim Eriksson, Fredrik Osterlind
*/
@ -197,12 +200,29 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
/* TODO Poll mote interfaces? */
/* time deviation skip if ahead*/
double rtime = ((MicaClock) (myMoteInterfaceHandler.getClock()))
.getReferenceTime();
double deviation = ((MicaClock) myMoteInterfaceHandler.getClock())
.getDeviation();
long drift = myMoteInterfaceHandler.getClock().getDrift();
if (Math.round(rtime) < (t + drift)) {
((MicaClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
+ Simulation.MILLISECOND + (deviation * Simulation.MILLISECOND));
scheduleNextWakeup(t + Simulation.MILLISECOND);
return;
}
/* Execute one millisecond */
cyclesUntil += NR_CYCLES_PER_MSEC;
while (cyclesExecuted < cyclesUntil) {
cyclesExecuted += interpreter.step();
}
/* time deviation book keeping */
((MicaClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
+ (deviation * Simulation.MILLISECOND));
/* TODO Poll mote interfaces? */
/* Schedule wakeup every millisecond */

View file

@ -54,6 +54,7 @@ public class MicaClock extends Clock {
private MicaZMote myMote;
private long timeDrift; /* Microseconds */
private double referenceTime; /* Microseconds */
private double deviation;
public MicaClock(Mote mote) {
@ -70,6 +71,15 @@ public class MicaClock extends Clock {
return simulation.getSimulationTime() + timeDrift;
}
public double getDeviation() {
return deviation;
}
public void setDeviation(double deviation) {
assert (deviation>0.0) && (deviation<=1.0);
this.deviation = deviation;
}
public void setDrift(long drift) {
timeDrift = drift;
}
@ -78,6 +88,14 @@ public class MicaClock extends Clock {
return timeDrift;
}
public void setReferenceTime(double referenceTime) {
this.referenceTime = referenceTime;
}
public double getReferenceTime() {
return referenceTime;
}
public JPanel getInterfaceVisualizer() {
return null;
}
@ -91,13 +109,4 @@ public class MicaClock extends Clock {
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
}
public double getDeviation() {
return deviation;
}
public void setDeviation(double deviation) {
assert deviation > 0.0;
this.deviation = deviation;
}
}