tick method returns true if mote can be ticked again immediately

This commit is contained in:
fros4943 2008-03-31 15:22:41 +00:00
parent 7579904492
commit 43ef84ad85
4 changed files with 93 additions and 83 deletions

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* Institute nor the names of its contributors may be used to endorse or promote * Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written * products derived from this software without specific prior written
* permission. * permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -23,8 +23,8 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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: Mote.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ * $Id: Mote.java,v 1.5 2008/03/31 15:22:42 fros4943 Exp $
*/ */
package se.sics.cooja; package se.sics.cooja;
@ -35,17 +35,17 @@ import org.jdom.Element;
/** /**
* A simulated mote. * A simulated mote.
* *
* A mote is always in some state, describing the status of the CPU etc. Motes * A mote is always in some state, describing the status of the CPU etc. Motes
* in different states may be handled differently by for example the simulation * in different states may be handled differently by for example the simulation
* loop and plugins. * loop and plugins.
* *
* All motes must also have an interface handler, a mote type and a mote memory. * All motes must also have an interface handler, a mote type and a mote memory.
* *
* @see se.sics.cooja.MoteInterfaceHandler * @see se.sics.cooja.MoteInterfaceHandler
* @see se.sics.cooja.MoteMemory * @see se.sics.cooja.MoteMemory
* @see se.sics.cooja.MoteType * @see se.sics.cooja.MoteType
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public interface Mote { public interface Mote {
@ -65,7 +65,7 @@ public interface Mote {
/** /**
* Tries to change state to given argument. A dead mote can typically not * Tries to change state to given argument. A dead mote can typically not
* change state, while a sleeping or active mote can. * change state, while a sleeping or active mote can.
* *
* @param newState * @param newState
* New state of mote. * New state of mote.
*/ */
@ -78,7 +78,7 @@ public interface Mote {
/** /**
* Adds new state observer. This observer is notified if mote changes state. * Adds new state observer. This observer is notified if mote changes state.
* *
* @see #deleteStateObserver(Observer) * @see #deleteStateObserver(Observer)
* @param newObserver * @param newObserver
* New observer * New observer
@ -87,7 +87,7 @@ public interface Mote {
/** /**
* Delete existing state observer. * Delete existing state observer.
* *
* @see #addStateObserver(Observer) * @see #addStateObserver(Observer)
* @param newObserver * @param newObserver
* Registered state observer * Registered state observer
@ -96,7 +96,7 @@ public interface Mote {
/** /**
* Returns the interface handler of this mote. * Returns the interface handler of this mote.
* *
* @see #setInterfaces(MoteInterfaceHandler) * @see #setInterfaces(MoteInterfaceHandler)
* @return Mote interface handler * @return Mote interface handler
*/ */
@ -104,7 +104,7 @@ public interface Mote {
/** /**
* Sets the interface handler of this mote. * Sets the interface handler of this mote.
* *
* @param moteInterfaceHandler * @param moteInterfaceHandler
* New interface handler * New interface handler
* @see #getInterfaces() * @see #getInterfaces()
@ -113,7 +113,7 @@ public interface Mote {
/** /**
* Returns the memory of this mote. * Returns the memory of this mote.
* *
* @see #setMemory(MoteMemory) * @see #setMemory(MoteMemory)
* @return Mote memory * @return Mote memory
*/ */
@ -121,7 +121,7 @@ public interface Mote {
/** /**
* Sets the memory of this mote. * Sets the memory of this mote.
* *
* @see #getMemory() * @see #getMemory()
* @param memory * @param memory
* Mote memory * Mote memory
@ -130,7 +130,7 @@ public interface Mote {
/** /**
* Returns mote type. * Returns mote type.
* *
* @see #setType(MoteType) * @see #setType(MoteType)
* @return Mote type * @return Mote type
*/ */
@ -138,7 +138,7 @@ public interface Mote {
/** /**
* Sets mote type to given argument. * Sets mote type to given argument.
* *
* @see #getType() * @see #getType()
* @param type * @param type
* New type * New type
@ -147,7 +147,7 @@ public interface Mote {
/** /**
* Returns simulation which holds this mote. * Returns simulation which holds this mote.
* *
* @see #setSimulation(Simulation) * @see #setSimulation(Simulation)
* @return Simulation * @return Simulation
*/ */
@ -155,7 +155,7 @@ public interface Mote {
/** /**
* Sets the simulation which holds this mote. * Sets the simulation which holds this mote.
* *
* @see #getSimulation() * @see #getSimulation()
* @param simulation * @param simulation
* Simulation * Simulation
@ -164,21 +164,22 @@ public interface Mote {
/** /**
* Ticks this mote and increases any internal time to given argument. * Ticks this mote and increases any internal time to given argument.
* *
* Each mote implementation may handle calls to this method differently, but * Each mote implementation may handle calls to this method differently, but
* typically the simulated mote should at least handle one event. * typically the simulated mote should at least handle one event.
* *
* This method is responsible for updating the mote interfaces, the memory and * This method is responsible for updating the mote interfaces, the memory and
* the mote state. * the mote state.
* *
* A call to this method typically polls all interfaces, activates the memory, * A call to this method typically polls all interfaces, activates the memory,
* lets the underlying mote software handle one event, fetches the updated * lets the underlying mote software handle one event, fetches the updated
* memory and finally polls all interfaces again. * memory and finally polls all interfaces again.
* *
* @param simTime * @param simTime
* New simulation time * New simulation time
* @return True is mote accepts another immediate tick
*/ */
public void tick(int simTime); public boolean tick(int simTime);
/** /**
* Returns XML elements representing the current config of this mote. This is * Returns XML elements representing the current config of this mote. This is
@ -186,7 +187,7 @@ public interface Mote {
* file. For example a mote may return the configs of all its interfaces. This * file. For example a mote may return the configs of all its interfaces. This
* method should however not return state specific information such as the * method should however not return state specific information such as the
* mote state. (All nodes are restarted when loading a simulation.) * mote state. (All nodes are restarted when loading a simulation.)
* *
* @see #setConfigXML(Simulation, Collection, boolean) * @see #setConfigXML(Simulation, Collection, boolean)
* @return XML elements representing the current mote config * @return XML elements representing the current mote config
*/ */
@ -194,12 +195,12 @@ public interface Mote {
/** /**
* Sets the current mote config depending on the given XML elements. * Sets the current mote config depending on the given XML elements.
* *
* @param simulation * @param simulation
* Simulation holding this mote * Simulation holding this mote
* @param configXML * @param configXML
* Config XML elements * Config XML elements
* *
* @see #getConfigXML() * @see #getConfigXML()
*/ */
public abstract boolean setConfigXML(Simulation simulation, public abstract boolean setConfigXML(Simulation simulation,

View file

@ -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: ContikiMote.java,v 1.6 2007/07/13 09:08:24 fros4943 Exp $ * $Id: ContikiMote.java,v 1.7 2008/03/31 15:22:43 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
@ -42,15 +42,15 @@ import se.sics.cooja.*;
* a loaded shared library and JNI. * a loaded shared library and JNI.
* It contains a section mote memory, a mote interface handler and a * It contains a section mote memory, a mote interface handler and a
* Contiki mote type. * Contiki mote type.
* *
* The mote type is responsible for the connection to the loaded * The mote type is responsible for the connection to the loaded
* Contiki system. * Contiki system.
* *
* When ticked a Contiki mote polls all interfaces, copies the mote * When ticked a Contiki mote polls all interfaces, copies the mote
* memory to the core, lets the Contiki system handle one event, * memory to the core, lets the Contiki system handle one event,
* fetches the updated memory and finally polls all interfaces again. * fetches the updated memory and finally polls all interfaces again.
* The mote state is also updated during a mote tick. * The mote state is also updated during a mote tick.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class ContikiMote implements Mote { public class ContikiMote implements Mote {
@ -75,21 +75,21 @@ public class ContikiMote implements Mote {
} }
private StateObservable stateObservable = new StateObservable(); private StateObservable stateObservable = new StateObservable();
/** /**
* Creates a new uninitialized Contiki mote. * Creates a new uninitialized Contiki mote.
* *
* This mote needs at least a type, a memory, a mote interface handler * This mote needs at least a type, a memory, a mote interface handler
* and to be connected to a simulation. * and to be connected to a simulation.
*/ */
public ContikiMote() { public ContikiMote() {
} }
/** /**
* Creates a new mote of given type. * Creates a new mote of given type.
* Both the initial mote memory and the interface handler * Both the initial mote memory and the interface handler
* are supplied from the mote type. * are supplied from the mote type.
* *
* @param moteType Mote type * @param moteType Mote type
* @param sim Mote's simulation * @param sim Mote's simulation
*/ */
@ -97,8 +97,8 @@ public class ContikiMote implements Mote {
this.mySim = sim; this.mySim = sim;
this.myType = moteType; this.myType = moteType;
this.myMemory = moteType.createInitialMemory(); this.myMemory = moteType.createInitialMemory();
this.myInterfaceHandler = new MoteInterfaceHandler((Mote) this, moteType.getMoteInterfaces()); this.myInterfaceHandler = new MoteInterfaceHandler(this, moteType.getMoteInterfaces());
myState = State.ACTIVE; myState = State.ACTIVE;
} }
@ -116,7 +116,7 @@ public class ContikiMote implements Mote {
myState = newState; myState = newState;
stateObservable.stateChanged(); stateObservable.stateChanged();
} }
if (myState == State.DEAD) { if (myState == State.DEAD) {
mySim.getRadioMedium().unregisterMote(this, mySim); mySim.getRadioMedium().unregisterMote(this, mySim);
} }
@ -133,11 +133,11 @@ public class ContikiMote implements Mote {
public void deleteStateObserver(Observer newObserver) { public void deleteStateObserver(Observer newObserver) {
stateObservable.deleteObserver(newObserver); stateObservable.deleteObserver(newObserver);
} }
public MoteInterfaceHandler getInterfaces() { public MoteInterfaceHandler getInterfaces() {
return myInterfaceHandler; return myInterfaceHandler;
} }
public void setInterfaces(MoteInterfaceHandler newInterfaces) { public void setInterfaces(MoteInterfaceHandler newInterfaces) {
myInterfaceHandler = newInterfaces; myInterfaceHandler = newInterfaces;
} }
@ -176,12 +176,13 @@ public class ContikiMote implements Mote {
* *
* @param simTime Current simulation time * @param simTime Current simulation time
*/ */
public void tick(int simTime) { public boolean tick(int simTime) {
State currentState = getState(); State currentState = getState();
// If mote is dead, do nothing at all // If mote is dead, do nothing at all
if (currentState == State.DEAD) if (currentState == State.DEAD) {
return; return false;
}
// If mote is sleeping and has a wake up time, should it wake up now? // If mote is sleeping and has a wake up time, should it wake up now?
if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) { if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) {
@ -204,7 +205,7 @@ public class ContikiMote implements Mote {
// If mote is still active, complete this tick // If mote is still active, complete this tick
currentState = getState(); currentState = getState();
if (currentState == State.ACTIVE) { if (currentState == State.ACTIVE) {
// Copy mote memory to core // Copy mote memory to core
myType.setCoreMemory(myMemory); myType.setCoreMemory(myMemory);
@ -228,18 +229,20 @@ public class ContikiMote implements Mote {
int processRunValue = myMemory.getIntValueOf("simProcessRunValue"); int processRunValue = myMemory.getIntValueOf("simProcessRunValue");
int etimersPending = myMemory.getIntValueOf("simEtimerPending"); int etimersPending = myMemory.getIntValueOf("simEtimerPending");
int nextExpirationTime = myMemory.getIntValueOf("simNextExpirationTime"); int nextExpirationTime = myMemory.getIntValueOf("simNextExpirationTime");
if (processRunValue == 0 && etimersPending == 0) { if (processRunValue == 0 && etimersPending == 0) {
setState(State.LPM); setState(State.LPM);
wakeUpTime = 0; wakeUpTime = 0;
} }
if (processRunValue == 0 && etimersPending == 1 && nextExpirationTime > 0) { if (processRunValue == 0 && etimersPending == 1 && nextExpirationTime > 0) {
setState(State.LPM); setState(State.LPM);
wakeUpTime = nextExpirationTime; wakeUpTime = nextExpirationTime;
} }
} }
return false;
} }
/** /**
@ -250,9 +253,9 @@ public class ContikiMote implements Mote {
*/ */
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>(); Vector<Element> config = new Vector<Element>();
Element element; Element element;
// Mote type identifier // Mote type identifier
element = new Element("motetype_identifier"); element = new Element("motetype_identifier");
element.setText(getType().getIdentifier()); element.setText(getType().getIdentifier());
@ -269,7 +272,7 @@ public class ContikiMote implements Mote {
config.add(element); config.add(element);
} }
} }
// Passive interface configs (if any) // Passive interface configs (if any)
for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) { for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) {
element = new Element("interface_config"); element = new Element("interface_config");
@ -281,47 +284,49 @@ public class ContikiMote implements Mote {
config.add(element); config.add(element);
} }
} }
return config; return config;
} }
public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) { public boolean setConfigXML(Simulation simulation, Collection<Element> configXML, boolean visAvailable) {
mySim = simulation; mySim = simulation;
myState = State.ACTIVE; myState = State.ACTIVE;
for (Element element: configXML) { for (Element element: configXML) {
String name = element.getName(); String name = element.getName();
if (name.equals("motetype_identifier")) { if (name.equals("motetype_identifier")) {
myType = (ContikiMoteType) simulation.getMoteType(element.getText()); myType = (ContikiMoteType) simulation.getMoteType(element.getText());
myMemory = myType.createInitialMemory(); myMemory = myType.createInitialMemory();
myInterfaceHandler = new MoteInterfaceHandler((Mote) this, myType.getMoteInterfaces()); myInterfaceHandler = new MoteInterfaceHandler(this, myType.getMoteInterfaces());
} else if (name.equals("interface_config")) { } else if (name.equals("interface_config")) {
Class<? extends MoteInterface> moteInterfaceClass = Class<? extends MoteInterface> moteInterfaceClass =
simulation.getGUI().tryLoadClass(this, MoteInterface.class, element.getText().trim()); simulation.getGUI().tryLoadClass(this, MoteInterface.class, element.getText().trim());
if (moteInterfaceClass == null) { if (moteInterfaceClass == null) {
logger.fatal("Could not load mote interface class: " + element.getText().trim()); logger.fatal("Could not load mote interface class: " + element.getText().trim());
return false; return false;
} }
MoteInterface moteInterface = myInterfaceHandler.getInterfaceOfType(moteInterfaceClass); MoteInterface moteInterface = myInterfaceHandler.getInterfaceOfType(moteInterfaceClass);
if (moteInterface != null) if (moteInterface != null) {
moteInterface.setConfigXML(element.getChildren(), visAvailable); moteInterface.setConfigXML(element.getChildren(), visAvailable);
else } else {
logger.warn("Can't restore configuration for non-existing interface: " + moteInterfaceClass.getName()); logger.warn("Can't restore configuration for non-existing interface: " + moteInterfaceClass.getName());
}
} }
} }
return true; return true;
} }
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { if (getInterfaces().getMoteID() != null) {
return "Contiki Mote, ID=" + getInterfaces().getMoteID().getMoteID(); return "Contiki Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else } else {
return "Contiki Mote, ID=null"; return "Contiki Mote, ID=null";
}
} }
} }

View file

@ -1,7 +1,7 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights * Copyright (c) 2006, Swedish Institute of Computer Science. All rights
* reserved. * reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met: * modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, * 1. Redistributions of source code must retain the above copyright notice,
@ -12,7 +12,7 @@
* Institute nor the names of its contributors may be used to endorse or promote * Institute nor the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written * products derived from this software without specific prior written
* permission. * permission.
* *
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
@ -23,8 +23,8 @@
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (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: DisturberMote.java,v 1.2 2007/01/09 10:01:14 fros4943 Exp $ * $Id: DisturberMote.java,v 1.3 2008/03/31 15:22:42 fros4943 Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
@ -42,7 +42,7 @@ import se.sics.cooja.motes.DisturberRadio;
* A disturber mote is a purely Java-based mote. It is used to disturb * A disturber mote is a purely Java-based mote. It is used to disturb
* transmission of other nodes on a certain channel (currently this is * transmission of other nodes on a certain channel (currently this is
* hard-coded in the DisturberRadio. * hard-coded in the DisturberRadio.
* *
* @author Fredrik Osterlind, Thiemo Voigt * @author Fredrik Osterlind, Thiemo Voigt
*/ */
public class DisturberMote implements Mote { public class DisturberMote implements Mote {
@ -70,7 +70,7 @@ public class DisturberMote implements Mote {
/** /**
* Creates a new dummy mote of the given type in the given simulation. An * Creates a new dummy mote of the given type in the given simulation. An
* empty mote memory and a position interface is added to this mote. * empty mote memory and a position interface is added to this mote.
* *
* @param moteType * @param moteType
* Mote type * Mote type
* @param sim * @param sim
@ -141,11 +141,12 @@ public class DisturberMote implements Mote {
this.mySim = simulation; this.mySim = simulation;
} }
public void tick(int simTime) { public boolean tick(int simTime) {
myInterfaceHandler.doPassiveActionsBeforeTick(); myInterfaceHandler.doPassiveActionsBeforeTick();
myInterfaceHandler.doActiveActionsBeforeTick(); myInterfaceHandler.doActiveActionsBeforeTick();
myInterfaceHandler.doActiveActionsAfterTick(); myInterfaceHandler.doActiveActionsAfterTick();
myInterfaceHandler.doPassiveActionsAfterTick(); myInterfaceHandler.doPassiveActionsAfterTick();
return false;
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
@ -173,7 +174,7 @@ public class DisturberMote implements Mote {
config.add(element); config.add(element);
} }
} }
// Passive interface configs (if any) // Passive interface configs (if any)
for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) { for (MoteInterface moteInterface: getInterfaces().getAllPassiveInterfaces()) {
element = new Element("interface_config"); element = new Element("interface_config");
@ -201,7 +202,7 @@ public class DisturberMote implements Mote {
myDisturberRadio = new DisturberRadio(this); myDisturberRadio = new DisturberRadio(this);
myInterfaceHandler.addActiveInterface(myDisturberRadio); myInterfaceHandler.addActiveInterface(myDisturberRadio);
for (Element element : configXML) { for (Element element : configXML) {
String name = element.getName(); String name = element.getName();
@ -228,8 +229,9 @@ public class DisturberMote implements Mote {
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { if (getInterfaces().getMoteID() != null) {
return "Disturber Mote, ID=" + getInterfaces().getMoteID().getMoteID(); return "Disturber Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else } else {
return "Disturber Mote, ID=null"; return "Disturber Mote, ID=null";
}
} }
} }

View file

@ -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: DummyMote.java,v 1.3 2007/01/09 10:01:14 fros4943 Exp $ * $Id: DummyMote.java,v 1.4 2008/03/31 15:22:41 fros4943 Exp $
*/ */
package se.sics.cooja.motes; package se.sics.cooja.motes;
@ -46,17 +46,17 @@ import se.sics.cooja.interfaces.Position;
/** /**
* A dummy mote is a purely Java-based mote, and can be used as an example of * A dummy mote is a purely Java-based mote, and can be used as an example of
* how to implement motes other than the usual Contiki mote. * how to implement motes other than the usual Contiki mote.
* *
* The dummy mote uses an empty section mote memory without any variable * The dummy mote uses an empty section mote memory without any variable
* mappings. * mappings.
* *
* The mote interface handler has a position interface, added when the mote is * The mote interface handler has a position interface, added when the mote is
* constructed. * constructed.
* *
* When the dummy mote is ticked all (one!) interfaces are polled and a random * When the dummy mote is ticked all (one!) interfaces are polled and a random
* variable decides if the position should be changed. The node never leaves the * variable decides if the position should be changed. The node never leaves the
* active state. * active state.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
public class DummyMote implements Mote { public class DummyMote implements Mote {
@ -79,7 +79,7 @@ public class DummyMote implements Mote {
/** /**
* Creates a new dummy mote of the given type in the given simulation. An * Creates a new dummy mote of the given type in the given simulation. An
* empty mote memory and a position interface is added to this mote. * empty mote memory and a position interface is added to this mote.
* *
* @param moteType * @param moteType
* Mote type * Mote type
* @param sim * @param sim
@ -146,7 +146,7 @@ public class DummyMote implements Mote {
this.mySim = simulation; this.mySim = simulation;
} }
public void tick(int simTime) { public boolean tick(int simTime) {
// Perform some dummy task // Perform some dummy task
if (myRandom.nextDouble() > 0.9) { if (myRandom.nextDouble() > 0.9) {
@ -157,6 +157,7 @@ public class DummyMote implements Mote {
+ myRandom.nextDouble() - 0.5, myPosition.getZCoordinate() + myRandom.nextDouble() - 0.5, myPosition.getZCoordinate()
+ myRandom.nextDouble() - 0.5); + myRandom.nextDouble() - 0.5);
} }
return false;
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
@ -215,8 +216,9 @@ public class DummyMote implements Mote {
public String toString() { public String toString() {
if (getInterfaces().getMoteID() != null) { if (getInterfaces().getMoteID() != null) {
return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID(); return "Dummy Mote, ID=" + getInterfaces().getMoteID().getMoteID();
} else } else {
return "Dummy Mote, ID=null"; return "Dummy Mote, ID=null";
}
} }
} }