using MoteTimeEvent instead of TimeEvent: scheduled events are automatically removed when the mote is removed

This commit is contained in:
fros4943 2009-10-28 15:58:42 +00:00
parent 281639c779
commit 82b8006c0c
6 changed files with 38 additions and 31 deletions

View file

@ -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) {

View file

@ -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) {

View file

@ -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()) {

View file

@ -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()) {

View file

@ -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;

View file

@ -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(".", "");