From 82b8006c0cfe01ea2bd66167d9630a0f71e4d4c5 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Wed, 28 Oct 2009 15:58:42 +0000 Subject: [PATCH] using MoteTimeEvent instead of TimeEvent: scheduled events are automatically removed when the mote is removed --- .../cooja/mspmote/interfaces/MspMoteID.java | 45 ++++++++++--------- .../mspmote/interfaces/SkyByteRadio.java | 4 +- .../cooja/mspmote/interfaces/SkySerial.java | 5 ++- .../cooja/mspmote/interfaces/TR1001Radio.java | 7 +-- .../se/sics/cooja/interfaces/IPAddress.java | 4 +- .../se/sics/cooja/interfaces/RimeAddress.java | 4 +- 6 files changed, 38 insertions(+), 31 deletions(-) diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java index 74f9bfa56..5e79deb6f 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/MspMoteID.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MspMoteID.java,v 1.12 2009/05/26 14:31:07 fros4943 Exp $ + * $Id: MspMoteID.java,v 1.13 2009/10/28 15:58:42 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -41,6 +41,7 @@ import org.apache.log4j.Logger; import org.jdom.Element; import se.sics.cooja.Mote; +import se.sics.cooja.MoteTimeEvent; import se.sics.cooja.Simulation; import se.sics.cooja.TimeEvent; import se.sics.cooja.interfaces.MoteID; @@ -93,8 +94,8 @@ public class MspMoteID extends MoteID { * @see Mote * @see se.sics.cooja.MoteInterfaceHandler */ - public MspMoteID(Mote mote) { - this.mote = (MspMote) mote; + public MspMoteID(Mote m) { + this.mote = (MspMote) m; this.moteMem = (MspMoteMemory) mote.getMemory(); String[] variables = moteMem.getVariableNames(); @@ -118,28 +119,32 @@ public class MspMoteID extends MoteID { /*logger.debug("ID location: " + location);*/ - if (PERSISTENT_SET_ID) { - mote.getSimulation().scheduleEvent(persistentSetIDEvent, mote.getSimulation().getSimulationTime()); - } - } + final TimeEvent persistentSetIDEvent = new MoteTimeEvent(mote, 0) { + public void execute(long t) { - private TimeEvent persistentSetIDEvent = new TimeEvent(0) { - public void execute(long t) { + if (persistentSetIDCounter-- > 0) + { + setMoteID(moteID); + /*logger.info("Setting ID: " + moteID + " at " + t);*/ - if (persistentSetIDCounter-- > 0) - { - setMoteID(moteID); - /*logger.info("Setting ID: " + moteID + " at " + t);*/ - - if (t + mote.getInterfaces().getClock().getDrift() < 0) { - /* Wait until node is booting */ - mote.getSimulation().scheduleEvent(this, -mote.getInterfaces().getClock().getDrift()); - } else { - mote.getSimulation().scheduleEvent(this, t+Simulation.MILLISECOND); + if (t + mote.getInterfaces().getClock().getDrift() < 0) { + /* Wait until node is booting */ + mote.getSimulation().scheduleEvent(this, -mote.getInterfaces().getClock().getDrift()); + } else { + mote.getSimulation().scheduleEvent(this, t+Simulation.MILLISECOND); + } } } + }; + + if (PERSISTENT_SET_ID) { + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + persistentSetIDEvent.execute(MspMoteID.this.mote.getSimulation().getSimulationTime()); + }; + }); } - }; + } public int getMoteID() { if (location == ID_LOCATION.VARIABLE_NODE_ID) { diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java index e36a92244..d7251e268 100755 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkyByteRadio.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkyByteRadio.java,v 1.13 2009/10/27 10:14:35 fros4943 Exp $ + * $Id: SkyByteRadio.java,v 1.14 2009/10/28 15:58:43 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -162,7 +162,7 @@ public class SkyByteRadio extends Radio implements CustomDataRadio { private byte[] crossBufferedData = null; - private TimeEvent deliverPacketDataEvent = new TimeEvent(0) { + private TimeEvent deliverPacketDataEvent = new MoteTimeEvent(mote, 0) { public void execute(long t) { if (crossBufferedData == null) { diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java index 1b3c0d360..2b7f862a3 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/SkySerial.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: SkySerial.java,v 1.17 2009/10/27 10:14:35 fros4943 Exp $ + * $Id: SkySerial.java,v 1.18 2009/10/28 15:58:42 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -37,6 +37,7 @@ import org.apache.log4j.Logger; import se.sics.cooja.ClassDescription; import se.sics.cooja.Mote; +import se.sics.cooja.MoteTimeEvent; import se.sics.cooja.Simulation; import se.sics.cooja.TimeEvent; import se.sics.cooja.dialogs.SerialUI; @@ -136,7 +137,7 @@ public class SkySerial extends SerialUI implements SerialPort { mote.requestImmediateWakeup(); } - private TimeEvent writeDataEvent = new TimeEvent(0) { + private TimeEvent writeDataEvent = new MoteTimeEvent(mote, 0) { public void execute(long t) { tryWriteNextByte(); if (!incomingData.isEmpty()) { diff --git a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java index d18b6bf2e..d2563e649 100644 --- a/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java +++ b/tools/cooja/apps/mspsim/src/se/sics/cooja/mspmote/interfaces/TR1001Radio.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: TR1001Radio.java,v 1.14 2009/10/27 10:14:35 fros4943 Exp $ + * $Id: TR1001Radio.java,v 1.15 2009/10/28 15:58:43 fros4943 Exp $ */ package se.sics.cooja.mspmote.interfaces; @@ -49,6 +49,7 @@ import org.jdom.Element; import se.sics.cooja.ClassDescription; import se.sics.cooja.Mote; +import se.sics.cooja.MoteTimeEvent; import se.sics.cooja.RadioPacket; import se.sics.cooja.Simulation; import se.sics.cooja.TimeEvent; @@ -154,7 +155,7 @@ public class TR1001Radio extends Radio implements USARTListener, } /* Feed incoming bytes to radio "slowly" via time events */ - TimeEvent receiveCrosslevelDataEvent = new TimeEvent(0) { + TimeEvent receiveCrosslevelDataEvent = new MoteTimeEvent(mote, 0) { public void execute(long t) { /* Stop receiving data when buffer is empty */ if (byteList.isEmpty() || isInterfered) { @@ -339,7 +340,7 @@ public class TR1001Radio extends Radio implements USARTListener, return mote.getInterfaces().getPosition(); } - private TimeEvent followupTransmissionEvent = new TimeEvent(0) { + private TimeEvent followupTransmissionEvent = new MoteTimeEvent(mote, 0) { public void execute(long t) { if (isTransmitting()) { diff --git a/tools/cooja/java/se/sics/cooja/interfaces/IPAddress.java b/tools/cooja/java/se/sics/cooja/interfaces/IPAddress.java index de2c71ede..e9a5977b4 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/IPAddress.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/IPAddress.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: IPAddress.java,v 1.6 2009/05/26 14:24:21 fros4943 Exp $ + * $Id: IPAddress.java,v 1.7 2009/10/28 15:58:43 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -59,7 +59,7 @@ public class IPAddress extends MoteInterface { moteMem = (AddressMemory) mote.getMemory(); /* Detect startup IP (only zeroes) */ - TimeEvent updateWhenAddressReady = new TimeEvent(0) { + TimeEvent updateWhenAddressReady = new MoteTimeEvent(mote, 0) { public void execute(long t) { if (!isVersion4() && !isVersion6()) { return; diff --git a/tools/cooja/java/se/sics/cooja/interfaces/RimeAddress.java b/tools/cooja/java/se/sics/cooja/interfaces/RimeAddress.java index 0fae90b33..2699592eb 100644 --- a/tools/cooja/java/se/sics/cooja/interfaces/RimeAddress.java +++ b/tools/cooja/java/se/sics/cooja/interfaces/RimeAddress.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: RimeAddress.java,v 1.3 2009/05/26 14:24:21 fros4943 Exp $ + * $Id: RimeAddress.java,v 1.4 2009/10/28 15:58:43 fros4943 Exp $ */ package se.sics.cooja.interfaces; @@ -61,7 +61,7 @@ public class RimeAddress extends MoteInterface { moteMem = (AddressMemory) mote.getMemory(); /* Detect startup address (only zeroes) */ - TimeEvent updateWhenAddressReady = new TimeEvent(0) { + TimeEvent updateWhenAddressReady = new MoteTimeEvent(mote, 0) { public void execute(long t) { String addrString = getAddressString(); addrString = addrString.replace(".", "");