From fb9728b29fbb318698693259a35460470111c922 Mon Sep 17 00:00:00 2001 From: fros4943 Date: Sat, 19 May 2007 16:56:55 +0000 Subject: [PATCH] allow mote to go to sleep due to etimers IFF contiki system was ticked --- .../se/sics/cooja/contikimote/ContikiMote.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMote.java b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMote.java index 3a83cfc66..e5f66c7e4 100644 --- a/tools/cooja/java/se/sics/cooja/contikimote/ContikiMote.java +++ b/tools/cooja/java/se/sics/cooja/contikimote/ContikiMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: ContikiMote.java,v 1.4 2007/01/09 10:08:02 fros4943 Exp $ + * $Id: ContikiMote.java,v 1.5 2007/05/19 16:56:55 fros4943 Exp $ */ package se.sics.cooja.contikimote; @@ -173,19 +173,21 @@ public class ContikiMote implements Mote { * @param simTime Current simulation time */ public void tick(int simTime) { - + State currentState = getState(); + // If mote is dead, do nothing at all - if (getState() == State.DEAD) + if (currentState == State.DEAD) return; // If mote is sleeping and has a wake up time, should it wake up now? - if (getState() == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) { + if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) { setState(State.ACTIVE); + currentState = getState(); wakeUpTime = 0; } // If mote is active.. - if (getState() == State.ACTIVE) { + if (currentState == State.ACTIVE) { // Let all active interfaces act before tick // Observe that each interface may put the mote to sleep at this point myInterfaceHandler.doActiveActionsBeforeTick(); @@ -196,7 +198,8 @@ public class ContikiMote implements Mote { // If mote is still active, complete this tick - if (getState() == State.ACTIVE) { + currentState = getState(); + if (currentState == State.ACTIVE) { // Copy mote memory to core myType.setCoreMemory(myMemory); @@ -216,7 +219,7 @@ public class ContikiMote implements Mote { myInterfaceHandler.doPassiveActionsAfterTick(); // If mote is awake, should it go to sleep? - if (getState() == State.ACTIVE) { + if (currentState == State.ACTIVE) { // Check if this mote should sleep (no more pending timers or processes to poll) int processRunValue = myMemory.getIntValueOf("simProcessRunValue"); int etimersPending = myMemory.getIntValueOf("simEtimerPending");