fixed MicaZ ID for contiki nodes by programming EEPROM

This commit is contained in:
joxe 2009-11-17 14:30:26 +00:00
parent f5ae0b9c82
commit 65a50f3d88
3 changed files with 24 additions and 8 deletions

View File

@ -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

View File

@ -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");
}

View File

@ -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);
}