Support in the mote clock interface for time deviation

This commit is contained in:
Andreas Löscher 2015-02-26 13:17:33 +01:00
parent 2059be3a43
commit ff4aee68bd
4 changed files with 50 additions and 1 deletions

View File

@ -54,10 +54,12 @@ public class MicaClock extends Clock {
private MicaZMote myMote; private MicaZMote myMote;
private long timeDrift; /* Microseconds */ private long timeDrift; /* Microseconds */
private double deviation;
public MicaClock(Mote mote) { public MicaClock(Mote mote) {
simulation = mote.getSimulation(); simulation = mote.getSimulation();
myMote = (MicaZMote) mote; myMote = (MicaZMote) mote;
deviation = 1.0;
} }
public void setTime(long newTime) { public void setTime(long newTime) {
@ -90,4 +92,12 @@ public class MicaClock extends Clock {
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) { 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;
}
} }

View File

@ -52,9 +52,11 @@ public class MspClock extends Clock {
private Simulation simulation; private Simulation simulation;
private long timeDrift; /* Microseconds */ private long timeDrift; /* Microseconds */
private double deviation;
public MspClock(Mote mote) { public MspClock(Mote mote) {
simulation = mote.getSimulation(); simulation = mote.getSimulation();
deviation = 1.0;
} }
public void setTime(long newTime) { public void setTime(long newTime) {
@ -73,6 +75,15 @@ public class MspClock extends Clock {
return timeDrift; return timeDrift;
} }
public void setDeviation(double deviation) {
assert deviation>0.0;
this.deviation = deviation;
}
public double getDeviation() {
return deviation;
}
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
/* TODO Show current CPU speed */ /* TODO Show current CPU speed */
return null; return null;

View File

@ -76,6 +76,7 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
private long moteTime; /* Microseconds */ private long moteTime; /* Microseconds */
private long timeDrift; /* Microseconds */ private long timeDrift; /* Microseconds */
private double deviation;
/** /**
* @param mote Mote * @param mote Mote
@ -89,6 +90,7 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
this.moteMem = new VarMemory(mote.getMemory()); this.moteMem = new VarMemory(mote.getMemory());
timeDrift = 0; timeDrift = 0;
moteTime = 0; moteTime = 0;
deviation = 1.0;
} }
public static String[] getCoreInterfaceDependencies() { public static String[] getCoreInterfaceDependencies() {
@ -114,6 +116,15 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
public long getTime() { public long getTime() {
return moteTime; return moteTime;
} }
public void setDeviation(double deviation) {
assert deviation>0.0;
this.deviation = deviation;
}
public double getDeviation() {
return deviation;
}
public void doActionsBeforeTick() { public void doActionsBeforeTick() {
/* Update time */ /* Update time */
@ -161,5 +172,4 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) { public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
} }
} }

View File

@ -39,6 +39,7 @@ import org.contikios.cooja.*;
* This observable never notifies. * This observable never notifies.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
* Andreas Löscher
*/ */
@ClassDescription("Clock") @ClassDescription("Clock")
public abstract class Clock extends MoteInterface { public abstract class Clock extends MoteInterface {
@ -76,4 +77,21 @@ public abstract class Clock extends MoteInterface {
*/ */
public abstract long getDrift(); public abstract long getDrift();
/**
* The clock deviation is a factor that represents with how much speed the
* mote progresses through the simulation in relation to the simulation speed.
*
* A value of 1.0 results in the mote beeing simulated with the same speed
* as the simulation. A value of 0.5 results in the mote beeing simulation
* at half of the simulation speed.
*
* @param deviation Deviation factor
*/
public abstract void setDeviation(double deviation);
/**
* Get deviation factor
*/
public abstract double getDeviation();
} }