rewriting mote interfaces for faster simulation execution.

node id interface
This commit is contained in:
fros4943 2008-10-28 11:11:52 +00:00
parent 86c3ea9bc8
commit 24308b8915

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: ContikiMoteID.java,v 1.3 2007/01/12 10:43:19 fros4943 Exp $ * $Id: ContikiMoteID.java,v 1.4 2008/10/28 11:11:52 fros4943 Exp $
*/ */
package se.sics.cooja.contikimote.interfaces; package se.sics.cooja.contikimote.interfaces;
@ -41,42 +41,41 @@ import se.sics.cooja.contikimote.ContikiMoteInterface;
import se.sics.cooja.interfaces.MoteID; import se.sics.cooja.interfaces.MoteID;
/** /**
* Ths class represents a mote ID number. * Mote ID interface: 'node_id'.
* *
* It needs write access to the following core variables: * Contiki variables:
* <ul> * <ul>
* <li>int simMoteID * <li>int simMoteID
* <li>char simMoteIDChanged * <li>char simMoteIDChanged
* </ul> * </ul>
* When the mote id is set or changed, the random generator will also be seeded *
* with this id (core function random_init()). * This interface also seeds the Contiki random generator: 'random_init()'.
* <p> *
* Dependency core interfaces are: * Core interface:
* <ul> * <ul>
* <li>moteid_interface * <li>moteid_interface
* </ul> * </ul>
* This observable notifies observers when the mote ID is set or changed. *
* * This observable notifies observers when the mote ID is set or altered.
* @author Fredrik Osterlind *
* @author Fredrik Österlind
*/ */
public class ContikiMoteID extends MoteID implements ContikiMoteInterface { public class ContikiMoteID extends MoteID implements ContikiMoteInterface {
private SectionMoteMemory moteMem = null; private SectionMoteMemory moteMem = null;
private static Logger logger = Logger.getLogger(ContikiMoteID.class); private static Logger logger = Logger.getLogger(ContikiMoteID.class);
private boolean setMoteID;
int moteID = 0; private int moteID = 0;
/** /**
* Creates an interface to the mote ID at mote. * Creates an interface to the mote ID at mote.
* *
* @param mote * @param mote Mote
* Mote ID's mote.
* @see Mote * @see Mote
* @see se.sics.cooja.MoteInterfaceHandler * @see se.sics.cooja.MoteInterfaceHandler
*/ */
public ContikiMoteID(Mote mote) { public ContikiMoteID(Mote mote) {
this.moteMem = (SectionMoteMemory) mote.getMemory(); this.moteMem = (SectionMoteMemory) mote.getMemory();
setMoteID = false;
} }
public static String[] getCoreInterfaceDependencies() { public static String[] getCoreInterfaceDependencies() {
@ -88,27 +87,14 @@ public class ContikiMoteID extends MoteID implements ContikiMoteInterface {
} }
public void setMoteID(int newID) { public void setMoteID(int newID) {
setMoteID = true;
moteID = newID; moteID = newID;
moteMem.setIntValueOf("simMoteID", moteID);
moteMem.setByteValueOf("simMoteIDChanged", (byte) 1);
setChanged(); setChanged();
notifyObservers(); notifyObservers();
} }
public void doActionsBeforeTick() {
if (setMoteID) {
setMoteID = false;
moteMem.setIntValueOf("simMoteID", moteID);
moteMem.setByteValueOf("simMoteIDChanged", (byte) 1);
setChanged();
notifyObservers();
}
}
public void doActionsAfterTick() {
// Nothing to do
}
public JPanel getInterfaceVisualizer() { public JPanel getInterfaceVisualizer() {
JPanel panel = new JPanel(); JPanel panel = new JPanel();
final JLabel idLabel = new JLabel(); final JLabel idLabel = new JLabel();