From bca8104a86ab995fa7041330b4c01b36eae66c5b Mon Sep 17 00:00:00 2001 From: nifi Date: Thu, 14 Jan 2010 19:06:14 +0000 Subject: [PATCH] Updated scheduling for user triggered events --- .../contikimote/interfaces/ContikiPIR.java | 26 ++++++++--------- .../contikimote/interfaces/ContikiVib.java | 28 +++++++++---------- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiPIR.java b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiPIR.java index ed49838ec..ce5926b04 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiPIR.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiPIR.java @@ -26,18 +26,19 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiPIR.java,v 1.8 2009/10/27 10:11:17 fros4943 Exp $ + * $Id: ContikiPIR.java,v 1.9 2010/01/14 19:06:14 nifi Exp $ */ package se.sics.cooja.contikimote.interfaces; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.Collection; -import javax.swing.*; -import org.apache.log4j.Logger; +import javax.swing.JButton; +import javax.swing.JPanel; import org.jdom.Element; - -import se.sics.cooja.*; +import se.sics.cooja.Mote; +import se.sics.cooja.SectionMoteMemory; import se.sics.cooja.contikimote.ContikiMote; import se.sics.cooja.contikimote.ContikiMoteInterface; import se.sics.cooja.interfaces.PIR; @@ -63,7 +64,6 @@ import se.sics.cooja.interfaces.PIR; * @author Fredrik Osterlind */ public class ContikiPIR extends PIR implements ContikiMoteInterface { - private static Logger logger = Logger.getLogger(ContikiPIR.class); /** * Approximate energy consumption of an active PIR sensor. ESB measured energy @@ -106,15 +106,13 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface { * Simulates a change in the PIR sensor. */ public void triggerChange() { - mote.getSimulation().scheduleEvent(pirEvent, mote.getSimulation().getSimulationTime()); + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + doTriggerChange(); + } + }); } - private TimeEvent pirEvent = new MoteTimeEvent(mote, 0) { - public void execute(long t) { - doTriggerChange(); - } - }; - public void doTriggerChange() { if (moteMem.getByteValueOf("simPirIsActive") == 1) { moteMem.setByteValueOf("simPirChanged", (byte) 1); diff --git a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiVib.java b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiVib.java index d2fe0aac5..e9e1bf87c 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiVib.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/interfaces/ContikiVib.java @@ -26,18 +26,21 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiVib.java,v 1.8 2009/10/27 10:11:17 fros4943 Exp $ + * $Id: ContikiVib.java,v 1.9 2010/01/14 19:06:14 nifi Exp $ */ package se.sics.cooja.contikimote.interfaces; -import java.awt.event.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; import java.util.Collection; -import javax.swing.*; -import org.apache.log4j.Logger; +import javax.swing.JButton; +import javax.swing.JPanel; import org.jdom.Element; - -import se.sics.cooja.*; +import se.sics.cooja.ClassDescription; +import se.sics.cooja.Mote; +import se.sics.cooja.MoteInterface; +import se.sics.cooja.SectionMoteMemory; import se.sics.cooja.contikimote.ContikiMote; import se.sics.cooja.contikimote.ContikiMoteInterface; @@ -63,7 +66,6 @@ import se.sics.cooja.contikimote.ContikiMoteInterface; */ @ClassDescription("Vibration sensor") public class ContikiVib extends MoteInterface implements ContikiMoteInterface { - private static Logger logger = Logger.getLogger(ContikiVib.class); /** * Approximate energy consumption of an active vibration sensor. ESB measured @@ -106,15 +108,13 @@ public class ContikiVib extends MoteInterface implements ContikiMoteInterface { * Simulates a change in the vibration sensor. */ public void triggerChange() { - mote.getSimulation().scheduleEvent(vibrateEvent, mote.getSimulation().getSimulationTime()); + mote.getSimulation().invokeSimulationThread(new Runnable() { + public void run() { + doTriggerChange(); + } + }); } - private TimeEvent vibrateEvent = new MoteTimeEvent(mote, 0) { - public void execute(long t) { - doTriggerChange(); - } - }; - public void doTriggerChange() { if (moteMem.getByteValueOf("simVibIsActive") == 1) { moteMem.setByteValueOf("simVibChanged", (byte) 1);