mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-11 03:29:51 +00:00
set drift method as standard for all clock interfaces
This commit is contained in:
parent
fb9b800c53
commit
dfc0199cbd
@ -24,7 +24,7 @@
|
|||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: Simulation.java,v 1.17 2007/08/21 08:51:33 fros4943 Exp $
|
* $Id: Simulation.java,v 1.18 2007/10/03 14:20:57 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja;
|
package se.sics.cooja;
|
||||||
@ -33,8 +33,6 @@ import java.util.*;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.*;
|
import org.jdom.*;
|
||||||
|
|
||||||
import se.sics.cooja.contikimote.ContikiMote;
|
|
||||||
import se.sics.cooja.contikimote.interfaces.ContikiClock;
|
|
||||||
import se.sics.cooja.dialogs.*;
|
import se.sics.cooja.dialogs.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -161,8 +159,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
|
|
||||||
// Select next mote subset (persistent)
|
// Select next mote subset (persistent)
|
||||||
currentTickListIndex++;
|
currentTickListIndex++;
|
||||||
if (currentTickListIndex >= nrTickLists)
|
if (currentTickListIndex >= nrTickLists) {
|
||||||
currentTickListIndex = 0;
|
currentTickListIndex = 0;
|
||||||
|
}
|
||||||
|
|
||||||
// Increase simulation time
|
// Increase simulation time
|
||||||
currentSimulationTime += tickTime;
|
currentSimulationTime += tickTime;
|
||||||
@ -171,8 +170,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
tickObservable.allTicksPerformed();
|
tickObservable.allTicksPerformed();
|
||||||
|
|
||||||
// Sleep
|
// Sleep
|
||||||
if (delayTime > 0)
|
if (delayTime > 0) {
|
||||||
Thread.sleep(delayTime);
|
Thread.sleep(delayTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (stopSimulation) {
|
if (stopSimulation) {
|
||||||
// We should only tick once (and we just did), so abort now
|
// We should only tick once (and we just did), so abort now
|
||||||
@ -239,7 +239,7 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
thread.interrupt();
|
thread.interrupt();
|
||||||
|
|
||||||
// Wait until simulation stops
|
// Wait until simulation stops
|
||||||
if (Thread.currentThread() != thread)
|
if (Thread.currentThread() != thread) {
|
||||||
while (thread != null && thread.isAlive()) {
|
while (thread != null && thread.isAlive()) {
|
||||||
try {
|
try {
|
||||||
Thread.sleep(10);
|
Thread.sleep(10);
|
||||||
@ -248,6 +248,7 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts simulation if stopped, ticks all motes once, and finally stops
|
* Starts simulation if stopped, ticks all motes once, and finally stops
|
||||||
@ -366,8 +367,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
element.setText(currentRadioMedium.getClass().getName());
|
element.setText(currentRadioMedium.getClass().getName());
|
||||||
|
|
||||||
Collection radioMediumXML = currentRadioMedium.getConfigXML();
|
Collection radioMediumXML = currentRadioMedium.getConfigXML();
|
||||||
if (radioMediumXML != null)
|
if (radioMediumXML != null) {
|
||||||
element.addContent(radioMediumXML);
|
element.addContent(radioMediumXML);
|
||||||
|
}
|
||||||
config.add(element);
|
config.add(element);
|
||||||
|
|
||||||
// Mote types
|
// Mote types
|
||||||
@ -376,8 +378,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
element.setText(moteType.getClass().getName());
|
element.setText(moteType.getClass().getName());
|
||||||
|
|
||||||
Collection moteTypeXML = moteType.getConfigXML();
|
Collection moteTypeXML = moteType.getConfigXML();
|
||||||
if (moteTypeXML != null)
|
if (moteTypeXML != null) {
|
||||||
element.addContent(moteTypeXML);
|
element.addContent(moteTypeXML);
|
||||||
|
}
|
||||||
config.add(element);
|
config.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,8 +390,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
element.setText(mote.getClass().getName());
|
element.setText(mote.getClass().getName());
|
||||||
|
|
||||||
Collection moteXML = mote.getConfigXML();
|
Collection moteXML = mote.getConfigXML();
|
||||||
if (moteXML != null)
|
if (moteXML != null) {
|
||||||
element.addContent(moteXML);
|
element.addContent(moteXML);
|
||||||
|
}
|
||||||
config.add(element);
|
config.add(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -543,8 +547,9 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
stopSimulation();
|
stopSimulation();
|
||||||
motes.remove(mote);
|
motes.remove(mote);
|
||||||
startSimulation();
|
startSimulation();
|
||||||
} else
|
} else {
|
||||||
motes.remove(mote);
|
motes.remove(mote);
|
||||||
|
}
|
||||||
|
|
||||||
currentRadioMedium.unregisterMote(mote, this);
|
currentRadioMedium.unregisterMote(mote, this);
|
||||||
this.setChanged();
|
this.setChanged();
|
||||||
@ -562,11 +567,12 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
stopSimulation();
|
stopSimulation();
|
||||||
motes.add(mote);
|
motes.add(mote);
|
||||||
startSimulation();
|
startSimulation();
|
||||||
} else
|
} else {
|
||||||
motes.add(mote);
|
motes.add(mote);
|
||||||
|
}
|
||||||
|
|
||||||
if (maxMoteStartupDelay > 0 && mote instanceof ContikiMote) {
|
if (maxMoteStartupDelay > 0 && mote.getInterfaces().getClock() != null) {
|
||||||
((ContikiClock) mote.getInterfaces().getClock()).setDrift(-delayMotesRandom.nextInt(maxMoteStartupDelay));
|
mote.getInterfaces().getClock().setDrift(-delayMotesRandom.nextInt(maxMoteStartupDelay));
|
||||||
}
|
}
|
||||||
|
|
||||||
currentRadioMedium.registerMote(mote, this);
|
currentRadioMedium.registerMote(mote, this);
|
||||||
@ -612,9 +618,10 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public MoteType getMoteType(String identifier) {
|
public MoteType getMoteType(String identifier) {
|
||||||
for (MoteType moteType : getMoteTypes()) {
|
for (MoteType moteType : getMoteTypes()) {
|
||||||
if (moteType.getIdentifier().equals(identifier))
|
if (moteType.getIdentifier().equals(identifier)) {
|
||||||
return moteType;
|
return moteType;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -700,9 +707,11 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
*/
|
*/
|
||||||
public void setRadioMedium(RadioMedium radioMedium) {
|
public void setRadioMedium(RadioMedium radioMedium) {
|
||||||
// Remove current radio medium from observing motes
|
// Remove current radio medium from observing motes
|
||||||
if (currentRadioMedium != null)
|
if (currentRadioMedium != null) {
|
||||||
for (int i = 0; i < motes.size(); i++)
|
for (int i = 0; i < motes.size(); i++) {
|
||||||
currentRadioMedium.unregisterMote(motes.get(i), this);
|
currentRadioMedium.unregisterMote(motes.get(i), this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Change current radio medium to new one
|
// Change current radio medium to new one
|
||||||
if (radioMedium == null) {
|
if (radioMedium == null) {
|
||||||
@ -712,9 +721,10 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
this.currentRadioMedium = radioMedium;
|
this.currentRadioMedium = radioMedium;
|
||||||
|
|
||||||
// Add all current motes to the new radio medium
|
// Add all current motes to the new radio medium
|
||||||
for (int i = 0; i < motes.size(); i++)
|
for (int i = 0; i < motes.size(); i++) {
|
||||||
currentRadioMedium.registerMote(motes.get(i), this);
|
currentRadioMedium.registerMote(motes.get(i), this);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get currently used radio medium.
|
* Get currently used radio medium.
|
||||||
@ -742,7 +752,7 @@ public class Simulation extends Observable implements Runnable {
|
|||||||
* @return Current tick time (seconds)
|
* @return Current tick time (seconds)
|
||||||
*/
|
*/
|
||||||
public double getTickTimeInSeconds() {
|
public double getTickTimeInSeconds() {
|
||||||
return ((double) tickTime) / 1000.0;
|
return (tickTime) / 1000.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -26,7 +26,7 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: Clock.java,v 1.1 2006/08/21 12:12:59 fros4943 Exp $
|
* $Id: Clock.java,v 1.2 2007/10/03 14:20:57 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
@ -57,4 +57,11 @@ public abstract class Clock extends MoteInterface {
|
|||||||
*/
|
*/
|
||||||
public abstract int getTime();
|
public abstract int getTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set time drift.
|
||||||
|
*
|
||||||
|
* @param timeDrift Time drift
|
||||||
|
*/
|
||||||
|
public abstract void setDrift(int timeDrift);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user