diff --git a/tools/cooja/java/se/sics/cooja/AddressMemory.java b/tools/cooja/java/se/sics/cooja/AddressMemory.java new file mode 100644 index 000000000..d6f1a82f7 --- /dev/null +++ b/tools/cooja/java/se/sics/cooja/AddressMemory.java @@ -0,0 +1,115 @@ +/* + * 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. + * + * $Id: AddressMemory.java,v 1.1 2007/02/02 11:02:14 fros4943 Exp $ + */ + +package se.sics.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 Address of given variable, or -1 + */ + public int getVariableAddress(String varName); + + /** + * Returns a value of the byte variable with the given name. + * + * @param varName + * Name of byte variable + * @return Value of byte variable + */ + public byte getByteValueOf(String varName); + + /** + * Set byte value of variable with given name. + * + * @param varName + * Name of byte variable + * @param newVal + * New value to set + */ + public void setByteValueOf(String varName, byte newVal); + + /** + * 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 + */ + public byte[] getByteArray(String varName, int length); + + /** + * Set byte array of the variable with the given name. + * + * @param varName + * Name of array + * @param data + * New data of array + */ + public void setByteArray(String varName, byte[] data); + + /** + * Returns a value of the integer variable with the given name. + * + * @param varName + * Name of integer variable + * @return Value of integer variable + */ + public int getIntValueOf(String varName); + + /** + * Set integer value of variable with given name. + * + * @param varName + * Name of integer variable + * @param newVal + * New value to set + */ + public void setIntValueOf(String varName, int newVal); + +} diff --git a/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java b/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java index ed5c30635..216c40a10 100644 --- a/tools/cooja/java/se/sics/cooja/SectionMoteMemory.java +++ b/tools/cooja/java/se/sics/cooja/SectionMoteMemory.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: SectionMoteMemory.java,v 1.4 2007/01/10 14:57:42 fros4943 Exp $ + * $Id: SectionMoteMemory.java,v 1.5 2007/02/02 11:02:15 fros4943 Exp $ */ package se.sics.cooja; @@ -46,7 +46,7 @@ import se.sics.cooja.MoteMemory; * * @author Fredrik Osterlind */ -public class SectionMoteMemory implements MoteMemory { +public class SectionMoteMemory implements MoteMemory, AddressMemory { private static Logger logger = Logger.getLogger(SectionMoteMemory.class); private Vector sections = new Vector(); @@ -64,9 +64,6 @@ public class SectionMoteMemory implements MoteMemory { this.variableAddresses = variableAddresses; } - /** - * @return All variable names known and residing in this memory - */ public String[] getVariableNames() { String[] names = new String[variableAddresses.size()]; Enumeration nameEnum = variableAddresses.keys(); @@ -76,11 +73,6 @@ public class SectionMoteMemory implements MoteMemory { return names; } - /** - * @param varName - * Variable name - * @return Address of given variable, or -1 - */ public int getVariableAddress(String varName) { if (!variableAddresses.containsKey(varName)) return -1; @@ -207,13 +199,10 @@ public class SectionMoteMemory implements MoteMemory { return sections.elementAt(sectionNr).getData(); } - /** - * Returns a value of the integer variable with the given name. - * - * @param varName - * Name of integer variable - * @return Value of integer variable - */ + public boolean variableExists(String varName) { + return variableAddresses.containsKey(varName); + } + public int getIntValueOf(String varName) { // Get start address of variable if (!variableAddresses.containsKey(varName)) @@ -235,14 +224,6 @@ public class SectionMoteMemory implements MoteMemory { return retVal; } - /** - * Set integer value of variable with given name. - * - * @param varName - * Name of integer variable - * @param newVal - * New value to set - */ public void setIntValueOf(String varName, int newVal) { // Get start address of variable if (!variableAddresses.containsKey(varName)) @@ -264,13 +245,6 @@ public class SectionMoteMemory implements MoteMemory { setMemorySegment(varAddr, varData); } - /** - * Returns a value of the byte variable with the given name. - * - * @param varName - * Name of byte variable - * @return Value of byte variable - */ public byte getByteValueOf(String varName) { // Get start address of variable if (!variableAddresses.containsKey(varName)) @@ -282,14 +256,6 @@ public class SectionMoteMemory implements MoteMemory { return varData[0]; } - /** - * Set byte value of variable with given name. - * - * @param varName - * Name of byte variable - * @param newVal - * New value to set - */ public void setByteValueOf(String varName, byte newVal) { // Get start address of variable if (!variableAddresses.containsKey(varName)) @@ -303,15 +269,6 @@ public class SectionMoteMemory implements MoteMemory { setMemorySegment(varAddr, varData); } - /** - * 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 - */ public byte[] getByteArray(String varName, int length) { // Get start address of variable if (!variableAddresses.containsKey(varName)) @@ -322,14 +279,6 @@ public class SectionMoteMemory implements MoteMemory { return getMemorySegment(varAddr, length); } - /** - * Set byte array of the variable with the given name. - * - * @param varName - * Name of array - * @param data - * New data of array - */ public void setByteArray(String varName, byte[] data) { // Get start address of variable if (!variableAddresses.containsKey(varName)) diff --git a/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java b/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java index f85a07054..8094b7f00 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java +++ b/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: VariableWatcher.java,v 1.3 2007/01/09 09:49:24 fros4943 Exp $ + * $Id: VariableWatcher.java,v 1.4 2007/02/02 11:02:16 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -55,7 +55,7 @@ import se.sics.cooja.*; public class VariableWatcher extends VisPlugin { private static final long serialVersionUID = 1L; - private SectionMoteMemory moteMemory; + private AddressMemory moteMemory; private final static int LABEL_WIDTH = 170; private final static int LABEL_HEIGHT = 15; @@ -82,7 +82,10 @@ public class VariableWatcher extends VisPlugin { public VariableWatcher(Mote moteToView, Simulation simulation, GUI gui) { super("Variable Watcher (" + moteToView + ")", gui); - moteMemory = (SectionMoteMemory) moteToView.getMemory(); + System.out.println("?!!"); + + moteMemory = (AddressMemory) moteToView.getMemory(); + System.out.println("?!!"); JLabel label; integerFormat = NumberFormat.getIntegerInstance();