From 65a50f3d88fa1b77807c4c8b53cdc62811a434de Mon Sep 17 00:00:00 2001 From: joxe Date: Tue, 17 Nov 2009 14:30:26 +0000 Subject: [PATCH] fixed MicaZ ID for contiki nodes by programming EEPROM --- .../se/sics/cooja/avrmote/AvrMoteMemory.java | 3 +-- .../src/se/sics/cooja/avrmote/MicaZMote.java | 18 +++++++++++++++--- .../sics/cooja/avrmote/interfaces/MicaZID.java | 11 ++++++++--- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/AvrMoteMemory.java b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/AvrMoteMemory.java index 270034823..891ebacd8 100644 --- a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/AvrMoteMemory.java +++ b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/AvrMoteMemory.java @@ -24,7 +24,7 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * - * $Id: AvrMoteMemory.java,v 1.3 2009/11/17 14:09:02 joxe Exp $ + * $Id: AvrMoteMemory.java,v 1.4 2009/11/17 14:30:26 joxe Exp $ */ package se.sics.cooja.avrmote; @@ -40,7 +40,6 @@ import avrora.arch.avr.AVRProperties; import avrora.core.SourceMapping; import avrora.core.SourceMapping.Location; import avrora.sim.AtmelInterpreter; -import avrora.sim.State; import avrora.sim.Simulator.Watch; /** * @author Joakim Eriksson diff --git a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMote.java b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMote.java index 6fa8e935f..3bf397c1e 100755 --- a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMote.java +++ b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/MicaZMote.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MicaZMote.java,v 1.11 2009/11/17 14:09:02 joxe Exp $ + * $Id: MicaZMote.java,v 1.12 2009/11/17 14:30:26 joxe Exp $ */ package se.sics.cooja.avrmote; @@ -50,8 +50,11 @@ import avrora.core.LoadableProgram; import avrora.sim.AtmelInterpreter; import avrora.sim.Simulator; import avrora.sim.State; +import avrora.sim.mcu.AtmelMicrocontroller; +import avrora.sim.mcu.EEPROM; import avrora.sim.mcu.Microcontroller; import avrora.sim.platform.MicaZ; +import avrora.sim.platform.Platform; import avrora.sim.platform.PlatformFactory; /** @@ -65,7 +68,7 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote { private Simulation mySimulation = null; private MoteInterfaceHandler myMoteInterfaceHandler; - private Microcontroller myCpu = null; + private AtmelMicrocontroller myCpu = null; private MicaZ micaZ = null; private LoadableProgram program = null; private AtmelInterpreter interpreter = null; @@ -73,6 +76,8 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote { private AVRProperties avrProperties = null; private MicaZMoteType myMoteType = null; + private EEPROM eeprom = null; + /* Stack monitoring variables */ private boolean stopNextInstruction = false; @@ -145,7 +150,9 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote { program.load(); PlatformFactory factory = new MicaZ.Factory(); micaZ = (MicaZ) factory.newPlatform(1, program.getProgram()); - myCpu = micaZ.getMicrocontroller(); + myCpu = (AtmelMicrocontroller) micaZ.getMicrocontroller(); + eeprom = (EEPROM) myCpu.getDevice("eeprom"); + avrProperties = (AVRProperties) myCpu.getProperties(); Simulator sim = myCpu.getSimulator(); interpreter = (AtmelInterpreter) sim.getInterpreter(); @@ -153,6 +160,11 @@ public class MicaZMote extends AbstractEmulatedMote implements Mote { myMemory = new AvrMoteMemory(program.getProgram().getSourceMapping(), avrProperties, interpreter); } + public void setEEPROM(int address, int i) { + byte[] eedata = eeprom.getContent(); + eedata[address] = (byte) i; + } + public void setState(State newState) { logger.warn("MicaZ motes can't change state"); } diff --git a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZID.java b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZID.java index ffe70e5a7..290700d0a 100644 --- a/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZID.java +++ b/tools/cooja/apps/avrora/src/se/sics/cooja/avrmote/interfaces/MicaZID.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MicaZID.java,v 1.2 2009/11/17 14:09:03 joxe Exp $ + * $Id: MicaZID.java,v 1.3 2009/11/17 14:30:26 joxe Exp $ */ package se.sics.cooja.avrmote.interfaces; @@ -47,6 +47,7 @@ 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.avrmote.MicaZMote; import se.sics.cooja.interfaces.MoteID; public class MicaZID extends MoteID { @@ -60,7 +61,7 @@ public class MicaZID extends MoteID { private AvrMoteMemory moteMem; boolean tosID = false; boolean contikiID = false; - private Mote mote; + private MicaZMote mote; private int persistentSetIDCounter = 1000; TimeEvent persistentSetIDEvent = new MoteTimeEvent(mote, 0) { @@ -79,7 +80,7 @@ public class MicaZID extends MoteID { public MicaZID(Mote mote) { - this.mote = mote; + this.mote = (MicaZMote) mote; this.moteMem = (AvrMoteMemory) mote.getMemory(); if (moteMem.variableExists("node_id")) { @@ -127,6 +128,10 @@ public class MicaZID extends MoteID { public void setMoteID(int newID) { moteID = newID; if (contikiID) { + mote.setEEPROM(0, 0xad); + mote.setEEPROM(1, 0xde); + mote.setEEPROM(2, newID); + mote.setEEPROM(3, newID >> 8); System.out.println("Setting node id: " + newID); moteMem.setIntValueOf("node_id", newID); }