time deviation for MSP based nodes
This commit is contained in:
parent
1c4a6f701e
commit
97da226255
@ -78,6 +78,8 @@ import se.sics.mspsim.util.MapEntry;
|
|||||||
import se.sics.mspsim.util.MapTable;
|
import se.sics.mspsim.util.MapTable;
|
||||||
import se.sics.mspsim.profiler.SimpleProfiler;
|
import se.sics.mspsim.profiler.SimpleProfiler;
|
||||||
|
|
||||||
|
import org.contikios.cooja.mspmote.interfaces.MspClock;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Fredrik Osterlind
|
* @author Fredrik Osterlind
|
||||||
*/
|
*/
|
||||||
@ -313,6 +315,21 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||||||
throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t);
|
throw new RuntimeException("Bad event ordering: " + lastExecute + " < " + t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* time deviation skip if ahead*/
|
||||||
|
double rtime = ((MspClock) (myMoteInterfaceHandler.getClock()))
|
||||||
|
.getReferenceTime();
|
||||||
|
double deviation = ((MspClock) myMoteInterfaceHandler.getClock())
|
||||||
|
.getDeviation();
|
||||||
|
long drift = myMoteInterfaceHandler.getClock().getDrift();
|
||||||
|
if (Math.round(rtime) < (t + drift)) {
|
||||||
|
lastExecute = t;
|
||||||
|
nextExecute = t + duration;
|
||||||
|
((MspClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
|
||||||
|
+ duration + (deviation * duration));
|
||||||
|
scheduleNextWakeup(nextExecute);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Execute MSPSim-based mote */
|
/* Execute MSPSim-based mote */
|
||||||
/* TODO Try-catch overhead */
|
/* TODO Try-catch overhead */
|
||||||
try {
|
try {
|
||||||
@ -333,6 +350,10 @@ public abstract class MspMote extends AbstractEmulatedMote implements Mote, Watc
|
|||||||
/*logger.debug(t + ": Schedule next wakeup at " + nextExecute);*/
|
/*logger.debug(t + ": Schedule next wakeup at " + nextExecute);*/
|
||||||
scheduleNextWakeup(nextExecute);
|
scheduleNextWakeup(nextExecute);
|
||||||
|
|
||||||
|
/* time deviation book keeping */
|
||||||
|
((MspClock) (myMoteInterfaceHandler.getClock())).setReferenceTime(rtime
|
||||||
|
+ deviation * (nextExecute - lastExecute));
|
||||||
|
|
||||||
if (stopNextInstruction) {
|
if (stopNextInstruction) {
|
||||||
stopNextInstruction = false;
|
stopNextInstruction = false;
|
||||||
throw new RuntimeException("MSPSim requested simulation stop");
|
throw new RuntimeException("MSPSim requested simulation stop");
|
||||||
|
@ -52,11 +52,13 @@ public class MspClock extends Clock {
|
|||||||
private Simulation simulation;
|
private Simulation simulation;
|
||||||
|
|
||||||
private long timeDrift; /* Microseconds */
|
private long timeDrift; /* Microseconds */
|
||||||
|
private double referenceTime; /* Microseconds */
|
||||||
private double deviation;
|
private double deviation;
|
||||||
|
|
||||||
public MspClock(Mote mote) {
|
public MspClock(Mote mote) {
|
||||||
simulation = mote.getSimulation();
|
simulation = mote.getSimulation();
|
||||||
deviation = 1.0;
|
referenceTime = 0.0;
|
||||||
|
deviation = 0.999;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(long newTime) {
|
public void setTime(long newTime) {
|
||||||
@ -75,8 +77,16 @@ public class MspClock extends Clock {
|
|||||||
return timeDrift;
|
return timeDrift;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setReferenceTime(double referenceTime) {
|
||||||
|
this.referenceTime = referenceTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double getReferenceTime() {
|
||||||
|
return referenceTime;
|
||||||
|
}
|
||||||
|
|
||||||
public void setDeviation(double deviation) {
|
public void setDeviation(double deviation) {
|
||||||
assert deviation>0.0;
|
assert (deviation>0.0) && (deviation<=1.0);
|
||||||
this.deviation = deviation;
|
this.deviation = deviation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user