fixed mote id for micaz

This commit is contained in:
joxe 2009-11-17 14:09:02 +00:00
parent 445d6b6a72
commit f5ae0b9c82
3 changed files with 125 additions and 39 deletions

View file

@ -24,7 +24,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* *
* $Id: AvrMoteMemory.java,v 1.2 2009/11/13 09:50:25 joxe Exp $ * $Id: AvrMoteMemory.java,v 1.3 2009/11/17 14:09:02 joxe Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
@ -40,6 +40,8 @@ import avrora.arch.avr.AVRProperties;
import avrora.core.SourceMapping; import avrora.core.SourceMapping;
import avrora.core.SourceMapping.Location; import avrora.core.SourceMapping.Location;
import avrora.sim.AtmelInterpreter; import avrora.sim.AtmelInterpreter;
import avrora.sim.State;
import avrora.sim.Simulator.Watch;
/** /**
* @author Joakim Eriksson * @author Joakim Eriksson
*/ */
@ -55,6 +57,10 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
this.interpreter = interpreter; this.interpreter = interpreter;
this.avrProperties = avrProperties; this.avrProperties = avrProperties;
} }
public void insertWatch(Watch w, int address) {
interpreter.getSimulator().insertWatch(w, address);
}
public void clearMemory() { public void clearMemory() {
logger.fatal("not implemented"); logger.fatal("not implemented");

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: MicaZMote.java,v 1.10 2009/11/12 12:49:34 joxe Exp $ * $Id: MicaZMote.java,v 1.11 2009/11/17 14:09:02 joxe Exp $
*/ */
package se.sics.cooja.avrmote; package se.sics.cooja.avrmote;
@ -45,11 +45,9 @@ import se.sics.cooja.MoteMemory;
import se.sics.cooja.MoteType; import se.sics.cooja.MoteType;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.motes.AbstractEmulatedMote; import se.sics.cooja.motes.AbstractEmulatedMote;
import se.sics.cooja.mspmote.MspMoteMemory;
import avrora.arch.avr.AVRProperties; import avrora.arch.avr.AVRProperties;
import avrora.core.LoadableProgram; import avrora.core.LoadableProgram;
import avrora.sim.AtmelInterpreter; import avrora.sim.AtmelInterpreter;
import avrora.sim.Interpreter;
import avrora.sim.Simulator; import avrora.sim.Simulator;
import avrora.sim.State; import avrora.sim.State;
import avrora.sim.mcu.Microcontroller; import avrora.sim.mcu.Microcontroller;
@ -165,6 +163,7 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote {
/* called when moteID is updated */ /* called when moteID is updated */
public void idUpdated(int newID) { public void idUpdated(int newID) {
} }
public MoteType getType() { public MoteType getType() {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, Swedish Institute of Computer Science. * Copyright (c) 2009, 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: MicaZID.java,v 1.1 2009/09/17 10:45:13 fros4943 Exp $ * $Id: MicaZID.java,v 1.2 2009/11/17 14:09:03 joxe Exp $
*/ */
package se.sics.cooja.avrmote.interfaces; package se.sics.cooja.avrmote.interfaces;
@ -39,54 +39,135 @@ import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import avrora.sim.State;
import avrora.sim.Simulator.Watch;
import se.sics.cooja.Mote; import se.sics.cooja.Mote;
import se.sics.cooja.MoteTimeEvent;
import se.sics.cooja.Simulation;
import se.sics.cooja.TimeEvent;
import se.sics.cooja.avrmote.AvrMoteMemory;
import se.sics.cooja.interfaces.MoteID; import se.sics.cooja.interfaces.MoteID;
public class MicaZID extends MoteID { public class MicaZID extends MoteID {
private static Logger logger = Logger.getLogger(MicaZID.class);
private int moteID = -1; /* TODO Implement */ private static final boolean PERSISTENT_SET_ID = true;
public MicaZID(Mote mote) { private static Logger logger = Logger.getLogger(MicaZID.class);
}
public int getMoteID() { private int moteID = -1; /* TODO Implement */
return moteID;
}
public void setMoteID(int newID) { private AvrMoteMemory moteMem;
moteID = newID; boolean tosID = false;
} boolean contikiID = false;
private Mote mote;
private int persistentSetIDCounter = 1000;
public JPanel getInterfaceVisualizer() { TimeEvent persistentSetIDEvent = new MoteTimeEvent(mote, 0) {
return null; public void execute(long t) {
} if (persistentSetIDCounter-- > 0) {
setMoteID(moteID);
if (t + mote.getInterfaces().getClock().getDrift() < 0) {
/* Wait until node is booting */
mote.getSimulation().scheduleEvent(this, -mote.getInterfaces().getClock().getDrift());
} else {
mote.getSimulation().scheduleEvent(this, t + Simulation.MILLISECOND / 16);
}
}
}
};
public void releaseInterfaceVisualizer(JPanel panel) {
}
public double energyConsumption() { public MicaZID(Mote mote) {
return 0; this.mote = mote;
} this.moteMem = (AvrMoteMemory) mote.getMemory();
public Collection<Element> getConfigXML() { if (moteMem.variableExists("node_id")) {
Vector<Element> config = new Vector<Element>(); contikiID = true;
Element element;
// Infinite boolean int addr = moteMem.getVariableAddress("node_id");
element = new Element("id"); moteMem.insertWatch(new Watch() {
element.setText(Integer.toString(getMoteID())); public void fireAfterRead(State arg0, int arg1, byte arg2) {
config.add(element); System.out.println("Read from node_id: " + arg2);
}
public void fireAfterWrite(State arg0, int arg1, byte arg2) {
}
public void fireBeforeRead(State arg0, int arg1) {
}
public void fireBeforeWrite(State arg0, int arg1, byte arg2) {
System.out.println("Writing to node_id: " + arg2);
}}, addr);
}
return config; if (moteMem.variableExists("TOS_NODE_ID")) {
} tosID = true;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
for (Element element : configXML) { if (PERSISTENT_SET_ID) {
if (element.getName().equals("id")) { mote.getSimulation().invokeSimulationThread(new Runnable() {
setMoteID(Integer.parseInt(element.getText())); public void run() {
} persistentSetIDEvent.execute(MicaZID.this.mote.getSimulation().getSimulationTime());
};
});
}
} }
}
public int getMoteID() {
if (contikiID) {
return moteMem.getIntValueOf("node_id");
}
if (tosID) {
return moteMem.getIntValueOf("TOS_NODE_ID");
}
return moteID;
}
public void setMoteID(int newID) {
moteID = newID;
if (contikiID) {
System.out.println("Setting node id: " + newID);
moteMem.setIntValueOf("node_id", newID);
}
if (tosID) {
moteMem.setIntValueOf("TOS_NODE_ID", newID);
moteMem.setIntValueOf("ActiveMessageAddressC$addr", newID);
}
setChanged();
notifyObservers();
return;
}
public JPanel getInterfaceVisualizer() {
return null;
}
public void releaseInterfaceVisualizer(JPanel panel) {
}
public double energyConsumption() {
return 0;
}
public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>();
Element element;
// Infinite boolean
element = new Element("id");
element.setText(Integer.toString(getMoteID()));
config.add(element);
return config;
}
public void setConfigXML(Collection<Element> configXML, boolean visAvailable) {
for (Element element : configXML) {
if (element.getName().equals("id")) {
setMoteID(Integer.parseInt(element.getText()));
}
}
}
} }