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
*/ */
@ -56,6 +58,10 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
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,24 +39,106 @@ 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 final boolean PERSISTENT_SET_ID = true;
private static Logger logger = Logger.getLogger(MicaZID.class); private static Logger logger = Logger.getLogger(MicaZID.class);
private int moteID = -1; /* TODO Implement */ private int moteID = -1; /* TODO Implement */
private AvrMoteMemory moteMem;
boolean tosID = false;
boolean contikiID = false;
private Mote mote;
private int persistentSetIDCounter = 1000;
TimeEvent persistentSetIDEvent = new MoteTimeEvent(mote, 0) {
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 MicaZID(Mote mote) { public MicaZID(Mote mote) {
this.mote = mote;
this.moteMem = (AvrMoteMemory) mote.getMemory();
if (moteMem.variableExists("node_id")) {
contikiID = true;
int addr = moteMem.getVariableAddress("node_id");
moteMem.insertWatch(new Watch() {
public void fireAfterRead(State arg0, int arg1, byte arg2) {
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);
}
if (moteMem.variableExists("TOS_NODE_ID")) {
tosID = true;
}
if (PERSISTENT_SET_ID) {
mote.getSimulation().invokeSimulationThread(new Runnable() {
public void run() {
persistentSetIDEvent.execute(MicaZID.this.mote.getSimulation().getSimulationTime());
};
});
}
} }
public int getMoteID() { public int getMoteID() {
if (contikiID) {
return moteMem.getIntValueOf("node_id");
}
if (tosID) {
return moteMem.getIntValueOf("TOS_NODE_ID");
}
return moteID; return moteID;
} }
public void setMoteID(int newID) { public void setMoteID(int newID) {
moteID = 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() { public JPanel getInterfaceVisualizer() {
return null; return null;
@ -88,5 +170,4 @@ public class MicaZID extends MoteID {
} }
} }
} }
} }