allow mote to go to sleep due to etimers IFF contiki system was ticked

This commit is contained in:
fros4943 2007-05-19 16:56:55 +00:00
parent 8d6cd6a5b5
commit fb9728b29f
1 changed files with 10 additions and 7 deletions

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.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; package se.sics.cooja.contikimote;
@ -173,19 +173,21 @@ public class ContikiMote implements Mote {
* @param simTime Current simulation time * @param simTime Current simulation time
*/ */
public void tick(int simTime) { public void tick(int simTime) {
State currentState = getState();
// If mote is dead, do nothing at all // If mote is dead, do nothing at all
if (getState() == State.DEAD) if (currentState == State.DEAD)
return; return;
// 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 (getState() == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) { if (currentState == State.LPM && wakeUpTime > 0 && wakeUpTime <= simTime) {
setState(State.ACTIVE); setState(State.ACTIVE);
currentState = getState();
wakeUpTime = 0; wakeUpTime = 0;
} }
// If mote is active.. // If mote is active..
if (getState() == State.ACTIVE) { if (currentState == State.ACTIVE) {
// Let all active interfaces act before tick // Let all active interfaces act before tick
// Observe that each interface may put the mote to sleep at this point // Observe that each interface may put the mote to sleep at this point
myInterfaceHandler.doActiveActionsBeforeTick(); myInterfaceHandler.doActiveActionsBeforeTick();
@ -196,7 +198,8 @@ public class ContikiMote implements Mote {
// If mote is still active, complete this tick // If mote is still active, complete this tick
if (getState() == State.ACTIVE) { currentState = getState();
if (currentState == State.ACTIVE) {
// Copy mote memory to core // Copy mote memory to core
myType.setCoreMemory(myMemory); myType.setCoreMemory(myMemory);
@ -216,7 +219,7 @@ public class ContikiMote implements Mote {
myInterfaceHandler.doPassiveActionsAfterTick(); myInterfaceHandler.doPassiveActionsAfterTick();
// If mote is awake, should it go to sleep? // 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) // Check if this mote should sleep (no more pending timers or processes to poll)
int processRunValue = myMemory.getIntValueOf("simProcessRunValue"); int processRunValue = myMemory.getIntValueOf("simProcessRunValue");
int etimersPending = myMemory.getIntValueOf("simEtimerPending"); int etimersPending = myMemory.getIntValueOf("simEtimerPending");