[cooja] memory: Removed AddressMemory class including all references
This commit is contained in:
parent
482dab5d16
commit
44767324a5
21 changed files with 94 additions and 566 deletions
|
@ -28,15 +28,11 @@
|
|||
|
||||
package org.contikios.cooja.avrmote;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.contikios.cooja.AddressMemory;
|
||||
import avrora.arch.avr.AVRProperties;
|
||||
import avrora.core.SourceMapping;
|
||||
import avrora.core.SourceMapping.Location;
|
||||
import avrora.sim.AtmelInterpreter;
|
||||
import avrora.sim.Simulator.Watch;
|
||||
import java.util.Map;
|
||||
|
@ -45,7 +41,7 @@ import org.contikios.cooja.mote.memory.MemoryLayout;
|
|||
/**
|
||||
* @author Joakim Eriksson
|
||||
*/
|
||||
public class AvrMoteMemory implements MemoryInterface, AddressMemory {
|
||||
public class AvrMoteMemory implements MemoryInterface {
|
||||
private static Logger logger = Logger.getLogger(AvrMoteMemory.class);
|
||||
|
||||
private SourceMapping memoryMap;
|
||||
|
@ -67,109 +63,6 @@ public class AvrMoteMemory implements MemoryInterface, AddressMemory {
|
|||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getByteArray(String varName, int length)
|
||||
throws UnknownVariableException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByteValueOf(String varName) throws UnknownVariableException {
|
||||
return (byte) getValueOf(varName, 1);
|
||||
}
|
||||
|
||||
private int getValueOf(String varName, int len) throws UnknownVariableException {
|
||||
Location mem = memoryMap.getLocation(varName);
|
||||
if (mem == null) throw new UnknownVariableException("Variable does not exist: " + varName);
|
||||
|
||||
System.out.println("Variable:" + varName + " in section: " + mem.section);
|
||||
System.out.println("LMA: " + Integer.toHexString(mem.lma_addr));
|
||||
System.out.println("VMA: " + Integer.toHexString(mem.vma_addr));
|
||||
|
||||
System.out.println("Data: " + interpreter.getDataByte(mem.lma_addr & 0xfffff));
|
||||
System.out.println("Flash: " + interpreter.getFlashByte(mem.lma_addr & 0xfffff));
|
||||
int data = 0;
|
||||
if (mem.vma_addr > 0xfffff) {
|
||||
for (int i = 0; i < len; i++) {
|
||||
data = (data << 8) + (interpreter.getDataByte((mem.vma_addr & 0xfffff) + len - i - 1) & 0xff);
|
||||
System.out.println("Read byte: " + interpreter.getDataByte((mem.vma_addr & 0xfffff) + i) +
|
||||
" => " + data);
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < len; i++) {
|
||||
data = (data << 8) + interpreter.getFlashByte(mem.vma_addr + len - i - 1) & 0xff;
|
||||
}
|
||||
}
|
||||
return data;
|
||||
}
|
||||
|
||||
private void setValue(String varName, int val, int len) throws UnknownVariableException {
|
||||
Location mem = memoryMap.getLocation(varName);
|
||||
if (mem == null) throw new UnknownVariableException("Variable does not exist: " + varName);
|
||||
|
||||
int data = val;
|
||||
if (mem.vma_addr > 0xfffff) {
|
||||
// write LSB first.
|
||||
for (int i = 0; i < len; i++) {
|
||||
interpreter.writeDataByte((mem.vma_addr & 0xfffff) + i, (byte) (data & 0xff));
|
||||
System.out.println("Wrote byte: " + (data & 0xff));
|
||||
data = data >> 8;
|
||||
}
|
||||
} else {
|
||||
for (int i = 0; i < len; i++) {
|
||||
interpreter.writeFlashByte(mem.vma_addr + i, (byte) (data & 0xff));
|
||||
data = data >> 8;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntValueOf(String varName) throws UnknownVariableException {
|
||||
return getValueOf(varName, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntegerLength() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableAddress(String varName)
|
||||
throws UnknownVariableException {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVariableNames() {
|
||||
ArrayList<String> symbols = new ArrayList<String>();
|
||||
for (Iterator i = memoryMap.getIterator(); i.hasNext();) {
|
||||
symbols.add(((Location) i.next()).name);
|
||||
}
|
||||
return symbols.toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteArray(String varName, byte[] data)
|
||||
throws UnknownVariableException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteValueOf(String varName, byte newVal)
|
||||
throws UnknownVariableException {
|
||||
setValue(varName, newVal, 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntValueOf(String varName, int newVal)
|
||||
throws UnknownVariableException {
|
||||
setValue(varName, newVal, 2);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean variableExists(String varName) {
|
||||
return memoryMap.getLocation(varName) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMemory() throws MoteMemoryException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
|
|
@ -38,16 +38,15 @@ import javax.swing.JPanel;
|
|||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
||||
import avrora.sim.State;
|
||||
import avrora.sim.Simulator.Watch;
|
||||
|
||||
import org.contikios.cooja.Mote;
|
||||
import org.contikios.cooja.MoteTimeEvent;
|
||||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.TimeEvent;
|
||||
import org.contikios.cooja.avrmote.AvrMoteMemory;
|
||||
import org.contikios.cooja.avrmote.MicaZMote;
|
||||
import org.contikios.cooja.interfaces.MoteID;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface.SegmentMonitor;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
public class MicaZID extends MoteID {
|
||||
|
||||
|
@ -57,7 +56,7 @@ public class MicaZID extends MoteID {
|
|||
|
||||
private int moteID = -1; /* TODO Implement */
|
||||
|
||||
private AvrMoteMemory moteMem;
|
||||
private VarMemory moteMem;
|
||||
boolean tosID = false;
|
||||
boolean contikiID = false;
|
||||
private MicaZMote mote;
|
||||
|
@ -80,23 +79,26 @@ public class MicaZID extends MoteID {
|
|||
|
||||
public MicaZID(Mote mote) {
|
||||
this.mote = (MicaZMote) mote;
|
||||
this.moteMem = (AvrMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(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);
|
||||
int addr = (int) moteMem.getVariableAddress("node_id");
|
||||
moteMem.addVarMonitor(
|
||||
SegmentMonitor.EventType.READWRITE,
|
||||
"node_id",
|
||||
new SegmentMonitor() {
|
||||
|
||||
@Override
|
||||
public void memoryChanged(MemoryInterface memory, SegmentMonitor.EventType type, long address) {
|
||||
if (type == EventType.READ) {
|
||||
System.out.println("Read from node_id.");
|
||||
} else {
|
||||
System.out.println("Writing to node_id.");
|
||||
}
|
||||
}
|
||||
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")) {
|
||||
|
|
|
@ -33,14 +33,13 @@ import java.util.Map;
|
|||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.contikios.cooja.AddressMemory;
|
||||
import org.contikios.cooja.Mote;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface;
|
||||
import org.contikios.cooja.mote.memory.MemoryLayout;
|
||||
import se.sics.mspsim.core.MSP430;
|
||||
import se.sics.mspsim.util.MapEntry;
|
||||
|
||||
public class MspMoteMemory implements MemoryInterface, AddressMemory {
|
||||
public class MspMoteMemory implements MemoryInterface {
|
||||
private static Logger logger = Logger.getLogger(MspMoteMemory.class);
|
||||
private final ArrayList<MapEntry> mapEntries;
|
||||
|
||||
|
@ -58,145 +57,11 @@ public class MspMoteMemory implements MemoryInterface, AddressMemory {
|
|||
this.cpu = cpu;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVariableNames() {
|
||||
String[] names = new String[mapEntries.size()];
|
||||
for (int i = 0; i < mapEntries.size(); i++) {
|
||||
names[i] = mapEntries.get(i).getName();
|
||||
}
|
||||
return names;
|
||||
}
|
||||
|
||||
private MapEntry getMapEntry(String varName) throws UnknownVariableException {
|
||||
for (MapEntry entry: mapEntries) {
|
||||
if (entry.getName().equals(varName)) {
|
||||
return entry;
|
||||
}
|
||||
}
|
||||
throw new UnknownVariableException(varName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableAddress(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
return entry.getAddress();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntegerLength() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public byte[] getMemorySegment(int address, int size) {
|
||||
// int[] memInts = new int[size];
|
||||
//
|
||||
// System.arraycopy(cpu.memory, address, memInts, 0, size);
|
||||
//
|
||||
// /* Convert to byte array */
|
||||
// byte[] memBytes = new byte[size];
|
||||
// for (int i=0; i < size; i++) {
|
||||
// memBytes[i] = (byte) memInts[i];
|
||||
// }
|
||||
//
|
||||
// return memBytes;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void setMemorySegment(int address, byte[] data) {
|
||||
// /* Convert to int array */
|
||||
// int[] memInts = new int[data.length];
|
||||
// for (int i=0; i < data.length; i++) {
|
||||
// memInts[i] = data[i];
|
||||
// }
|
||||
//
|
||||
// System.arraycopy(memInts, 0, cpu.memory, address, data.length);
|
||||
// }
|
||||
|
||||
@Override
|
||||
public int getTotalSize() {
|
||||
return cpu.memory.length;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean variableExists(String varName) {
|
||||
for (MapEntry entry: mapEntries) {
|
||||
if (entry.getName().equals(varName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* TODO Check correct variable size in below methods */
|
||||
|
||||
@Override
|
||||
public int getIntValueOf(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
|
||||
int varAddr = entry.getAddress();
|
||||
byte[] varData = getMemorySegment(varAddr, 2);
|
||||
return parseInt(varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
int newValToSet = Integer.reverseBytes(newVal);
|
||||
|
||||
// Create byte array
|
||||
int pos = 0;
|
||||
|
||||
byte[] varData = new byte[2];
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF000000) >> 24);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF0000) >> 16);
|
||||
|
||||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByteValueOf(String varName) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
byte[] varData = getMemorySegment(varAddr, 1);
|
||||
|
||||
return varData[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
byte[] varData = new byte[1];
|
||||
|
||||
varData[0] = newVal;
|
||||
|
||||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
return getMemorySegment(varAddr, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
|
||||
MapEntry entry = getMapEntry(varName);
|
||||
int varAddr = entry.getAddress();
|
||||
|
||||
setMemorySegment(varAddr, data);
|
||||
}
|
||||
|
||||
// private ArrayList<MemoryCPUMonitor> cpuMonitorArray = new ArrayList<MemoryCPUMonitor>();
|
||||
|
||||
@Override
|
||||
public byte[] getMemory() throws MoteMemoryException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
|
|
@ -40,8 +40,9 @@ import org.jdom.Element;
|
|||
import org.contikios.cooja.ClassDescription;
|
||||
import org.contikios.cooja.Mote;
|
||||
import org.contikios.cooja.interfaces.Log;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
import org.contikios.cooja.mspmote.MspMote;
|
||||
import org.contikios.cooja.mspmote.MspMoteMemory;
|
||||
import se.sics.mspsim.core.Memory;
|
||||
import se.sics.mspsim.core.MemoryMonitor;
|
||||
|
||||
|
@ -64,24 +65,24 @@ public class MspDebugOutput extends Log {
|
|||
private final static String CONTIKI_POINTER = "cooja_debug_ptr";
|
||||
|
||||
private MspMote mote;
|
||||
private MspMoteMemory mem;
|
||||
private VarMemory mem;
|
||||
|
||||
private String lastLog = null;
|
||||
private MemoryMonitor memoryMonitor = null;
|
||||
|
||||
public MspDebugOutput(Mote mote) {
|
||||
this.mote = (MspMote) mote;
|
||||
this.mem = (MspMoteMemory) this.mote.getMemory();
|
||||
this.mem = new VarMemory(this.mote.getMemory());
|
||||
|
||||
if (!mem.variableExists(CONTIKI_POINTER)) {
|
||||
/* Disabled */
|
||||
return;
|
||||
}
|
||||
this.mote.getCPU().addWatchPoint(mem.getVariableAddress(CONTIKI_POINTER),
|
||||
this.mote.getCPU().addWatchPoint((int) mem.getVariableAddress(CONTIKI_POINTER),
|
||||
memoryMonitor = new MemoryMonitor.Adapter() {
|
||||
@Override
|
||||
public void notifyWriteAfter(int adr, int data, Memory.AccessMode mode) {
|
||||
String msg = extractString(mem, data);
|
||||
String msg = extractString(MspDebugOutput.this.mote.getMemory(), data);
|
||||
if (msg != null && msg.length() > 0) {
|
||||
lastLog = "DEBUG: " + msg;
|
||||
setChanged();
|
||||
|
@ -91,7 +92,7 @@ public class MspDebugOutput extends Log {
|
|||
});
|
||||
}
|
||||
|
||||
private String extractString(MspMoteMemory mem, int address) {
|
||||
private String extractString(MemoryInterface mem, int address) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
while (true) {
|
||||
byte[] data = mem.getMemorySegment(address, 8);
|
||||
|
@ -136,7 +137,7 @@ public class MspDebugOutput extends Log {
|
|||
super.removed();
|
||||
|
||||
if (memoryMonitor != null) {
|
||||
mote.getCPU().removeWatchPoint(mem.getVariableAddress(CONTIKI_POINTER), memoryMonitor);
|
||||
mote.getCPU().removeWatchPoint((int) mem.getVariableAddress(CONTIKI_POINTER), memoryMonitor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,8 +39,8 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import org.contikios.cooja.Mote;
|
||||
import org.contikios.cooja.interfaces.MoteID;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
import org.contikios.cooja.mspmote.MspMote;
|
||||
import org.contikios.cooja.mspmote.MspMoteMemory;
|
||||
import se.sics.mspsim.core.Memory;
|
||||
import se.sics.mspsim.core.MemoryMonitor;
|
||||
|
||||
|
@ -53,7 +53,7 @@ public class MspMoteID extends MoteID {
|
|||
private static Logger logger = Logger.getLogger(MspMoteID.class);
|
||||
|
||||
private MspMote mote;
|
||||
private MspMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
|
||||
private boolean writeFlashHeader = true;
|
||||
private int moteID = -1;
|
||||
|
@ -69,7 +69,7 @@ public class MspMoteID extends MoteID {
|
|||
*/
|
||||
public MspMoteID(Mote m) {
|
||||
this.mote = (MspMote) m;
|
||||
this.moteMem = (MspMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public int getMoteID() {
|
||||
|
@ -144,7 +144,7 @@ public class MspMoteID extends MoteID {
|
|||
byte[] id = new byte[2];
|
||||
id[0] = (byte) (moteID & 0xff);
|
||||
id[1] = (byte) ((moteID >> 8) & 0xff);
|
||||
moteMem.setMemorySegment(dstAddress & ~1, id);
|
||||
mote.getMemory().setMemorySegment(dstAddress & ~1, id);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -201,7 +201,7 @@ public class MspMoteID extends MoteID {
|
|||
|
||||
private void addMonitor(String variable, MemoryMonitor monitor) {
|
||||
if (moteMem.variableExists(variable)) {
|
||||
int address = moteMem.getVariableAddress(variable);
|
||||
int address = (int) moteMem.getVariableAddress(variable);
|
||||
if ((address & 1) != 0) {
|
||||
// Variable can not be a word - must be a byte
|
||||
} else {
|
||||
|
@ -213,7 +213,7 @@ public class MspMoteID extends MoteID {
|
|||
|
||||
private void removeMonitor(String variable, MemoryMonitor monitor) {
|
||||
if (moteMem.variableExists(variable)) {
|
||||
int address = moteMem.getVariableAddress(variable);
|
||||
int address = (int) moteMem.getVariableAddress(variable);
|
||||
mote.getCPU().removeWatchPoint(address, monitor);
|
||||
mote.getCPU().removeWatchPoint(address + 1, monitor);
|
||||
}
|
||||
|
|
|
@ -1,124 +0,0 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science. All rights
|
||||
* reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer. 2. Redistributions in
|
||||
* binary form must reproduce the above copyright notice, this list of
|
||||
* conditions and the following disclaimer in the documentation and/or other
|
||||
* materials provided with the distribution. 3. Neither the name of the
|
||||
* Institute nor the names of its contributors may be used to endorse or promote
|
||||
* products derived from this software without specific prior written
|
||||
* permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND ANY
|
||||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.contikios.cooja;
|
||||
|
||||
public interface AddressMemory {
|
||||
|
||||
/**
|
||||
* @return All variable names known and residing in this memory
|
||||
*/
|
||||
public String[] getVariableNames();
|
||||
|
||||
/**
|
||||
* Checks if given variable exists in memory.
|
||||
*
|
||||
* @param varName Variable name
|
||||
* @return True if variable exists, false otherwise
|
||||
*/
|
||||
public boolean variableExists(String varName);
|
||||
|
||||
/**
|
||||
* Returns address of variable with given name.
|
||||
*
|
||||
* @param varName Variable name
|
||||
* @return Variable address
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public int getVariableAddress(String varName) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Returns a value of the byte variable with the given name.
|
||||
*
|
||||
* @param varName Name of byte variable
|
||||
* @return Value of byte variable
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public byte getByteValueOf(String varName) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Set byte value of variable with given name.
|
||||
*
|
||||
* @param varName Name of byte variable
|
||||
* @param newVal New value of byte
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Returns byte array of given length and with the given name.
|
||||
*
|
||||
* @param varName Name of array
|
||||
* @param length Length of array
|
||||
* @return Data of array
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public byte[] getByteArray(String varName, int length) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Set byte array of the variable with the given name.
|
||||
*
|
||||
* @param varName Name of array
|
||||
* @param data New data of array
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public void setByteArray(String varName, byte[] data) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* @return Number of bytes in an integer
|
||||
*/
|
||||
public int getIntegerLength();
|
||||
|
||||
/**
|
||||
* Returns a value of the integer variable with the given name.
|
||||
*
|
||||
* @param varName Name of integer variable
|
||||
* @return Value of integer variable
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public int getIntValueOf(String varName) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Set integer value of variable with given name.
|
||||
*
|
||||
* @param varName Name of integer variable
|
||||
* @param newVal New integer value
|
||||
* @throws UnknownVariableException Variable does not exist
|
||||
*/
|
||||
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException;
|
||||
|
||||
/**
|
||||
* Unknown variable name exception.
|
||||
*/
|
||||
public class UnknownVariableException extends RuntimeException {
|
||||
public UnknownVariableException(String varName) {
|
||||
super("Unknown variable name: " + varName);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -46,7 +46,7 @@ import org.contikios.cooja.mote.memory.MemoryLayout;
|
|||
*
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class SectionMoteMemory implements MemoryInterface, AddressMemory {
|
||||
public class SectionMoteMemory implements MemoryInterface {
|
||||
private static Logger logger = Logger.getLogger(SectionMoteMemory.class);
|
||||
|
||||
private ArrayList<MoteMemorySection> sections = new ArrayList<MoteMemorySection>();
|
||||
|
@ -69,73 +69,16 @@ public class SectionMoteMemory implements MemoryInterface, AddressMemory {
|
|||
this.offset = offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getVariableNames() {
|
||||
return addresses.keySet().toArray(new String[0]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getVariableAddress(String varName) throws UnknownVariableException {
|
||||
/* Cooja address space */
|
||||
if (!addresses.containsKey(varName)) {
|
||||
throw new UnknownVariableException(varName);
|
||||
}
|
||||
|
||||
return addresses.get(varName).intValue() + offset;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntegerLength() {
|
||||
return 4;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMemory() {
|
||||
sections.clear();
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public byte[] getMemorySegment(int address, int size) {
|
||||
// /* Cooja address space */
|
||||
// address -= offset;
|
||||
//
|
||||
// for (MoteMemorySection section : sections) {
|
||||
// if (section.includesAddr(address)
|
||||
// && section.includesAddr(address + size - 1)) {
|
||||
// return section.getMemorySegment(address, size);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* Check if in readonly section */
|
||||
// for (MoteMemorySection section : readonlySections) {
|
||||
// if (section.includesAddr(address)
|
||||
// && section.includesAddr(address + size - 1)) {
|
||||
// return section.getMemorySegment(address, size);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return null;
|
||||
// }
|
||||
|
||||
public void setMemorySegmentNative(int address, byte[] data) {
|
||||
setMemorySegment(address+offset, data);
|
||||
}
|
||||
|
||||
// @Override
|
||||
// public void setMemorySegment(int address, byte[] data) {
|
||||
// /* Cooja address space */
|
||||
// address -= offset;
|
||||
//
|
||||
// /* TODO XXX Sections may overlap */
|
||||
// for (MoteMemorySection section : sections) {
|
||||
// if (section.includesAddr(address)
|
||||
// && section.includesAddr(address + data.length - 1)) {
|
||||
// section.setMemorySegment(address, data);
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
// sections.add(new MoteMemorySection(address, data));
|
||||
// }
|
||||
|
||||
public void setReadonlyMemorySegment(int address, byte[] data) {
|
||||
/* Cooja address space */
|
||||
|
@ -202,75 +145,6 @@ public class SectionMoteMemory implements MemoryInterface, AddressMemory {
|
|||
return sections.get(sectionNr).getData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean variableExists(String varName) {
|
||||
return addresses.containsKey(varName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIntValueOf(String varName) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
byte[] varData = getMemorySegment(varAddr, 4);
|
||||
|
||||
if (varData == null) {
|
||||
throw new UnknownVariableException(varName);
|
||||
}
|
||||
|
||||
return parseInt(varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIntValueOf(String varName, int newVal) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
|
||||
/* TODO Correct for all platforms? */
|
||||
int newValToSet = Integer.reverseBytes(newVal);
|
||||
|
||||
int pos = 0;
|
||||
|
||||
byte[] varData = new byte[4];
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF000000) >> 24);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF0000) >> 16);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF00) >> 8);
|
||||
varData[pos++] = (byte) ((newValToSet & 0xFF) >> 0);
|
||||
|
||||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte getByteValueOf(String varName) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
byte[] varData = getMemorySegment(varAddr, 1);
|
||||
|
||||
if (varData == null) {
|
||||
throw new UnknownVariableException(varName);
|
||||
}
|
||||
|
||||
return varData[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteValueOf(String varName, byte newVal) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
byte[] varData = new byte[1];
|
||||
|
||||
varData[0] = newVal;
|
||||
|
||||
setMemorySegment(varAddr, varData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getByteArray(String varName, int length) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
return getMemorySegment(varAddr, length);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setByteArray(String varName, byte[] data) throws UnknownVariableException {
|
||||
int varAddr = getVariableAddress(varName);
|
||||
setMemorySegment(varAddr, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] getMemory() throws MoteMemoryException {
|
||||
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.contikios.cooja.dialogs.CompileContiki;
|
|||
import org.contikios.cooja.dialogs.ContikiMoteCompileDialog;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
import org.contikios.cooja.util.StringUtils;
|
||||
|
||||
/**
|
||||
|
@ -505,6 +506,7 @@ public class ContikiMoteType implements MoteType {
|
|||
int offset;
|
||||
{
|
||||
SectionMoteMemory tmp = new SectionMoteMemory(addresses, 0);
|
||||
VarMemory varMem = new VarMemory(tmp);
|
||||
byte[] data = new byte[dataSectionSize];
|
||||
getCoreMemory(dataSectionAddr, dataSectionSize, data);
|
||||
tmp.setMemorySegment(dataSectionAddr, data);
|
||||
|
@ -512,7 +514,7 @@ public class ContikiMoteType implements MoteType {
|
|||
getCoreMemory(bssSectionAddr, bssSectionSize, bss);
|
||||
tmp.setMemorySegment(bssSectionAddr, bss);
|
||||
|
||||
offset = tmp.getIntValueOf("referenceVar");
|
||||
offset = varMem.getIntValueOf("referenceVar");
|
||||
logger.info(getContikiFirmwareFile().getName() +
|
||||
": offsetting Cooja mote address space: " + offset);
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ import org.contikios.cooja.SectionMoteMemory;
|
|||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.Beeper;
|
||||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Beeper mote interface.
|
||||
|
@ -70,7 +71,7 @@ import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
|||
*/
|
||||
public class ContikiBeeper extends Beeper implements ContikiMoteInterface, PolledAfterActiveTicks {
|
||||
private Mote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
private static Logger logger = Logger.getLogger(ContikiBeeper.class);
|
||||
|
||||
/**
|
||||
|
@ -83,7 +84,7 @@ public class ContikiBeeper extends Beeper implements ContikiMoteInterface, Polle
|
|||
*/
|
||||
public ContikiBeeper(Mote mote) {
|
||||
this.mote = mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public boolean isBeeping() {
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.contikios.cooja.*;
|
|||
import org.contikios.cooja.contikimote.ContikiMote;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.Button;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Button mote interface.
|
||||
|
@ -62,7 +63,7 @@ import org.contikios.cooja.interfaces.Button;
|
|||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class ContikiButton extends Button implements ContikiMoteInterface {
|
||||
private SectionMoteMemory moteMem;
|
||||
private VarMemory moteMem;
|
||||
private ContikiMote mote;
|
||||
|
||||
private static Logger logger = Logger.getLogger(ContikiButton.class);
|
||||
|
@ -76,7 +77,7 @@ public class ContikiButton extends Button implements ContikiMoteInterface {
|
|||
*/
|
||||
public ContikiButton(Mote mote) {
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -43,6 +43,7 @@ import org.jdom.Element;
|
|||
import org.contikios.cooja.*;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Contiki FileSystem (CFS) interface (such as external flash).
|
||||
|
@ -71,7 +72,7 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface, P
|
|||
|
||||
public int FILESYSTEM_SIZE = 4000; /* Configure CFS size here and in cfs-cooja.c */
|
||||
private Mote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
|
||||
private int lastRead = 0;
|
||||
private int lastWritten = 0;
|
||||
|
@ -85,7 +86,7 @@ public class ContikiCFS extends MoteInterface implements ContikiMoteInterface, P
|
|||
*/
|
||||
public ContikiCFS(Mote mote) {
|
||||
this.mote = mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -44,6 +44,7 @@ import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
|||
import org.contikios.cooja.interfaces.Clock;
|
||||
import org.contikios.cooja.interfaces.PolledAfterAllTicks;
|
||||
import org.contikios.cooja.interfaces.PolledBeforeActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Clock mote interface. Controls Contiki time.
|
||||
|
@ -71,7 +72,7 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
|||
|
||||
private Simulation simulation;
|
||||
private ContikiMote mote;
|
||||
private SectionMoteMemory moteMem;
|
||||
private VarMemory moteMem;
|
||||
|
||||
private long moteTime; /* Microseconds */
|
||||
private long timeDrift; /* Microseconds */
|
||||
|
@ -85,7 +86,7 @@ public class ContikiClock extends Clock implements ContikiMoteInterface, PolledB
|
|||
public ContikiClock(Mote mote) {
|
||||
this.simulation = mote.getSimulation();
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
timeDrift = 0;
|
||||
moteTime = 0;
|
||||
}
|
||||
|
|
|
@ -45,6 +45,7 @@ import org.jdom.Element;
|
|||
import org.contikios.cooja.*;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Contiki EEPROM interface
|
||||
|
@ -73,7 +74,7 @@ public class ContikiEEPROM extends MoteInterface implements ContikiMoteInterface
|
|||
|
||||
public int EEPROM_SIZE = 1024; /* Configure EEPROM size here and in eeprom.c. Should really be multiple of 16 */
|
||||
private Mote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
|
||||
private int lastRead = 0;
|
||||
private int lastWritten = 0;
|
||||
|
@ -87,7 +88,7 @@ public class ContikiEEPROM extends MoteInterface implements ContikiMoteInterface
|
|||
*/
|
||||
public ContikiEEPROM(Mote mote) {
|
||||
this.mote = mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -40,6 +40,7 @@ import org.contikios.cooja.*;
|
|||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.LED;
|
||||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* LEDs mote interface.
|
||||
|
@ -64,7 +65,7 @@ public class ContikiLED extends LED implements ContikiMoteInterface, PolledAfter
|
|||
private static Logger logger = Logger.getLogger(ContikiLED.class);
|
||||
|
||||
private Mote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
private byte currentLedValue = 0;
|
||||
|
||||
private static final byte LEDS_GREEN = 1;
|
||||
|
@ -91,7 +92,7 @@ public class ContikiLED extends LED implements ContikiMoteInterface, PolledAfter
|
|||
*/
|
||||
public ContikiLED(Mote mote) {
|
||||
this.mote = mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.jdom.Element;
|
|||
import org.contikios.cooja.*;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.MoteID;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Mote ID interface: 'node_id'.
|
||||
|
@ -60,7 +61,7 @@ import org.contikios.cooja.interfaces.MoteID;
|
|||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class ContikiMoteID extends MoteID implements ContikiMoteInterface {
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
private static Logger logger = Logger.getLogger(ContikiMoteID.class);
|
||||
|
||||
private int moteID = 0;
|
||||
|
@ -77,7 +78,7 @@ public class ContikiMoteID extends MoteID implements ContikiMoteInterface {
|
|||
*/
|
||||
public ContikiMoteID(Mote mote) {
|
||||
this.mote = mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -41,6 +41,7 @@ import org.contikios.cooja.SectionMoteMemory;
|
|||
import org.contikios.cooja.contikimote.ContikiMote;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.interfaces.PIR;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Passive IR sensor mote interface.
|
||||
|
@ -65,7 +66,7 @@ import org.contikios.cooja.interfaces.PIR;
|
|||
public class ContikiPIR extends PIR implements ContikiMoteInterface {
|
||||
|
||||
private ContikiMote mote;
|
||||
private SectionMoteMemory moteMem;
|
||||
private VarMemory moteMem;
|
||||
|
||||
/**
|
||||
* Creates an interface to the PIR at mote.
|
||||
|
@ -77,7 +78,7 @@ public class ContikiPIR extends PIR implements ContikiMoteInterface {
|
|||
*/
|
||||
public ContikiPIR(Mote mote) {
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.contikios.cooja.contikimote.ContikiMote;
|
|||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.dialogs.SerialUI;
|
||||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Contiki mote serial port and log interfaces.
|
||||
|
@ -68,7 +69,7 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
private static Logger logger = Logger.getLogger(ContikiRS232.class);
|
||||
|
||||
private ContikiMote mote = null;
|
||||
private SectionMoteMemory moteMem = null;
|
||||
private VarMemory moteMem = null;
|
||||
|
||||
static final int SERIAL_BUF_SIZE = 1024; /* rs232.c:40 */
|
||||
|
||||
|
@ -82,7 +83,7 @@ public class ContikiRS232 extends SerialUI implements ContikiMoteInterface, Poll
|
|||
*/
|
||||
public ContikiRS232(Mote mote) {
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -46,6 +46,7 @@ import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
|||
import org.contikios.cooja.interfaces.PolledAfterActiveTicks;
|
||||
import org.contikios.cooja.interfaces.Position;
|
||||
import org.contikios.cooja.interfaces.Radio;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
import org.contikios.cooja.radiomediums.UDGM;
|
||||
|
||||
/**
|
||||
|
@ -89,7 +90,7 @@ import org.contikios.cooja.radiomediums.UDGM;
|
|||
public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledAfterActiveTicks {
|
||||
private ContikiMote mote;
|
||||
|
||||
private SectionMoteMemory myMoteMemory;
|
||||
private VarMemory myMoteMemory;
|
||||
|
||||
private static Logger logger = Logger.getLogger(ContikiRadio.class);
|
||||
|
||||
|
@ -132,7 +133,7 @@ public class ContikiRadio extends Radio implements ContikiMoteInterface, PolledA
|
|||
ContikiRadio.class, "RADIO_TRANSMISSION_RATE_kbps");
|
||||
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.myMoteMemory = (SectionMoteMemory) mote.getMemory();
|
||||
this.myMoteMemory = new VarMemory(mote.getMemory());
|
||||
|
||||
radioOn = myMoteMemory.getByteValueOf("simRadioHWOn") == 1;
|
||||
}
|
||||
|
|
|
@ -42,6 +42,7 @@ import org.contikios.cooja.MoteInterface;
|
|||
import org.contikios.cooja.SectionMoteMemory;
|
||||
import org.contikios.cooja.contikimote.ContikiMote;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Vibration sensor mote interface.
|
||||
|
@ -67,7 +68,7 @@ import org.contikios.cooja.contikimote.ContikiMoteInterface;
|
|||
public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
|
||||
|
||||
private ContikiMote mote;
|
||||
private SectionMoteMemory moteMem;
|
||||
private VarMemory moteMem;
|
||||
|
||||
/**
|
||||
* Creates an interface to the vibration sensor at mote.
|
||||
|
@ -79,7 +80,7 @@ public class ContikiVib extends MoteInterface implements ContikiMoteInterface {
|
|||
*/
|
||||
public ContikiVib(Mote mote) {
|
||||
this.mote = (ContikiMote) mote;
|
||||
this.moteMem = (SectionMoteMemory) mote.getMemory();
|
||||
this.moteMem = new VarMemory(mote.getMemory());
|
||||
}
|
||||
|
||||
public static String[] getCoreInterfaceDependencies() {
|
||||
|
|
|
@ -68,6 +68,7 @@ import org.contikios.cooja.Cooja;
|
|||
import org.contikios.cooja.MoteType.MoteTypeCreationException;
|
||||
import org.contikios.cooja.SectionMoteMemory;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteType;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/* TODO Test common section */
|
||||
/* TODO Test readonly section */
|
||||
|
@ -944,14 +945,15 @@ public class ConfigurationWizard extends JDialog {
|
|||
javaLibrary.getMemory(relDataSectionAddr, dataSectionSize, initialDataSection);
|
||||
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
|
||||
SectionMoteMemory memory = new SectionMoteMemory(addresses, 0);
|
||||
VarMemory varMem = new VarMemory(memory);
|
||||
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
|
||||
int contikiDataCounter, contikiBSSCounter;
|
||||
|
||||
testOutput.addMessage("### Checking initial variable values: 1,0");
|
||||
contikiDataCounter = memory.getIntValueOf("var1");
|
||||
contikiBSSCounter = memory.getIntValueOf("uvar1");
|
||||
contikiDataCounter = varMem.getIntValueOf("var1");
|
||||
contikiBSSCounter = varMem.getIntValueOf("uvar1");
|
||||
int javaDataCounter = 1;
|
||||
int javaBSSCounter = 0;
|
||||
if (contikiDataCounter != javaDataCounter) {
|
||||
|
@ -975,8 +977,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
|
||||
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
contikiDataCounter = memory.getIntValueOf("var1");
|
||||
contikiBSSCounter = memory.getIntValueOf("uvar1");
|
||||
contikiDataCounter = varMem.getIntValueOf("var1");
|
||||
contikiBSSCounter = varMem.getIntValueOf("uvar1");
|
||||
if (contikiDataCounter != javaDataCounter) {
|
||||
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
|
||||
return false;
|
||||
|
@ -1004,8 +1006,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
|
||||
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
contikiDataCounter = memory.getIntValueOf("var1");
|
||||
contikiBSSCounter = memory.getIntValueOf("uvar1");
|
||||
contikiDataCounter = varMem.getIntValueOf("var1");
|
||||
contikiBSSCounter = varMem.getIntValueOf("uvar1");
|
||||
if (contikiDataCounter != javaDataCounter) {
|
||||
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
|
||||
return false;
|
||||
|
@ -1029,8 +1031,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
|
||||
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
contikiDataCounter = memory.getIntValueOf("var1");
|
||||
contikiBSSCounter = memory.getIntValueOf("uvar1");
|
||||
contikiDataCounter = varMem.getIntValueOf("var1");
|
||||
contikiBSSCounter = varMem.getIntValueOf("uvar1");
|
||||
if (contikiDataCounter != javaDataCounter) {
|
||||
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
|
||||
return false;
|
||||
|
@ -1049,8 +1051,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
javaLibrary.getMemory(relBssSectionAddr, bssSectionSize, initialBssSection);
|
||||
memory.setMemorySegment(relDataSectionAddr, initialDataSection);
|
||||
memory.setMemorySegment(relBssSectionAddr, initialBssSection);
|
||||
contikiDataCounter = memory.getIntValueOf("var1");
|
||||
contikiBSSCounter = memory.getIntValueOf("uvar1");
|
||||
contikiDataCounter = varMem.getIntValueOf("var1");
|
||||
contikiBSSCounter = varMem.getIntValueOf("uvar1");
|
||||
if (contikiDataCounter != javaDataCounter) {
|
||||
testOutput.addMessage("### Data section mismatch (" + contikiDataCounter + " != " + javaDataCounter + ")", MessageList.ERROR);
|
||||
return false;
|
||||
|
|
|
@ -44,8 +44,10 @@ import java.awt.event.KeyListener;
|
|||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.swing.BorderFactory;
|
||||
|
@ -64,7 +66,6 @@ import javax.swing.text.PlainDocument;
|
|||
|
||||
import org.jdom.Element;
|
||||
|
||||
import org.contikios.cooja.AddressMemory;
|
||||
import org.contikios.cooja.ClassDescription;
|
||||
import org.contikios.cooja.Cooja;
|
||||
import org.contikios.cooja.Mote;
|
||||
|
@ -72,7 +73,8 @@ import org.contikios.cooja.MotePlugin;
|
|||
import org.contikios.cooja.PluginType;
|
||||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.VisPlugin;
|
||||
import org.contikios.cooja.AddressMemory.UnknownVariableException;
|
||||
import org.contikios.cooja.mote.memory.UnknownVariableException;
|
||||
import org.contikios.cooja.mote.memory.VarMemory;
|
||||
|
||||
/**
|
||||
* Variable Watcher enables a user to watch mote variables during a simulation.
|
||||
|
@ -87,7 +89,7 @@ import org.contikios.cooja.AddressMemory.UnknownVariableException;
|
|||
public class VariableWatcher extends VisPlugin implements MotePlugin {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private AddressMemory moteMemory;
|
||||
private VarMemory moteMemory;
|
||||
|
||||
private final static int LABEL_WIDTH = 170;
|
||||
private final static int LABEL_HEIGHT = 15;
|
||||
|
@ -124,7 +126,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
|||
public VariableWatcher(Mote moteToView, Simulation simulation, Cooja gui) {
|
||||
super("Variable Watcher (" + moteToView + ")", gui);
|
||||
this.mote = moteToView;
|
||||
moteMemory = (AddressMemory) moteToView.getMemory();
|
||||
moteMemory = new VarMemory(moteToView.getMemory());
|
||||
|
||||
JLabel label;
|
||||
integerFormat = NumberFormat.getIntegerInstance();
|
||||
|
@ -143,8 +145,8 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
|||
varName.setEditable(true);
|
||||
varName.setSelectedItem("[enter or pick name]");
|
||||
|
||||
String[] allPotentialVarNames = moteMemory.getVariableNames();
|
||||
Arrays.sort(allPotentialVarNames);
|
||||
List<String> allPotentialVarNames = new ArrayList<>(moteMemory.getVariableNames());
|
||||
Collections.sort(allPotentialVarNames);
|
||||
for (String aVarName: allPotentialVarNames) {
|
||||
varName.addItem(aVarName);
|
||||
}
|
||||
|
@ -172,7 +174,7 @@ public class VariableWatcher extends VisPlugin implements MotePlugin {
|
|||
|
||||
varType = new JComboBox();
|
||||
varType.addItem("Byte (1 byte)"); // BYTE_INDEX = 0
|
||||
varType.addItem("Integer (" + moteMemory.getIntegerLength() + " bytes)"); // INT_INDEX = 1
|
||||
varType.addItem("Integer (" + moteToView.getMemory().getLayout().intSize + " bytes)"); // INT_INDEX = 1
|
||||
varType.addItem("Byte array (x bytes)"); // ARRAY_INDEX = 2
|
||||
varType.addItem("Char array (x bytes)"); // CHAR_ARRAY_INDEX = 3
|
||||
|
||||
|
|
Loading…
Reference in a new issue