rewriting mote interfaces for faster simulation execution.

clock interface
This commit is contained in:
fros4943 2008-10-28 09:57:48 +00:00
parent f9d2581e06
commit ae80b1a585

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2006, Swedish Institute of Computer Science. * Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -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: ContikiClock.java,v 1.3 2007/06/19 09:59:19 fros4943 Exp $ * $Id: ContikiClock.java,v 1.4 2008/10/28 09:57:48 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -38,24 +38,27 @@ import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.contikimote.ContikiMoteInterface; import se.sics.cooja.contikimote.ContikiMoteInterface;
import se.sics.cooja.interfaces.Clock; import se.sics.cooja.interfaces.Clock;
import se.sics.cooja.interfaces.PolledBeforeActiveTicks;
/** /**
* The class represents a clock and controls the core time. * Clock mote interface. Controls Contiki time.
* *
* It needs read/write access to the following core variables: * Contiki variables:
* <ul> * <ul>
* <li>int simCurrentTime * <li>int simCurrentTime
* </ul> * </ul>
* Dependency core interfaces are: *
* Core interface:
* <ul> * <ul>
* <li>clock_interface * <li>clock_interface
* </ul> * </ul>
* <p> * <p>
* This observable never updates. *
* * This observable never notifies.
* @author Fredrik Osterlind *
* @author Fredrik Österlind
*/ */
public class ContikiClock extends Clock implements ContikiMoteInterface { public class ContikiClock extends Clock implements ContikiMoteInterface, PolledBeforeActiveTicks {
private Mote mote = null; private Mote mote = null;
private SectionMoteMemory moteMem = null; private SectionMoteMemory moteMem = null;
@ -63,10 +66,8 @@ public class ContikiClock extends Clock implements ContikiMoteInterface {
private int timeDrift = 0; private int timeDrift = 0;
/** /**
* Creates a time connected to mote. * @param mote Mote
* *
* @param mote
* Mote to connect this time to.
* @see Mote * @see Mote
* @see se.sics.cooja.MoteInterfaceHandler * @see se.sics.cooja.MoteInterfaceHandler
*/ */
@ -92,15 +93,12 @@ public class ContikiClock extends Clock implements ContikiMoteInterface {
} }
public void doActionsBeforeTick() { public void doActionsBeforeTick() {
// Update core time to correspond with the simulation time /* Update time */
int moteTime = mote.getSimulation().getSimulationTime() + timeDrift; int moteTime = mote.getSimulation().getSimulationTime() + timeDrift;
if (moteTime > 0)
setTime(moteTime);
}
public void doActionsAfterTick() { if (moteTime > 0) {
// Nothing to do setTime(moteTime);
}
} }
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {