From 77ab9359ddb711b84a14a8d89709af748aed13ae Mon Sep 17 00:00:00 2001 From: Enrico Joerns Date: Thu, 28 Aug 2014 13:02:43 +0200 Subject: [PATCH] [cooja] Memory: Added get/setByteArray functions to Memory access class Provides a cleaner interface to access memory as VarMemory already contains variable name based get/setByteArray functions. --- .../contikios/cooja/mote/memory/Memory.java | 23 +++++++++++++++++++ .../cooja/mote/memory/VarMemory.java | 9 ++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/cooja/java/org/contikios/cooja/mote/memory/Memory.java b/tools/cooja/java/org/contikios/cooja/mote/memory/Memory.java index 4f405a07c..f98632179 100644 --- a/tools/cooja/java/org/contikios/cooja/mote/memory/Memory.java +++ b/tools/cooja/java/org/contikios/cooja/mote/memory/Memory.java @@ -151,6 +151,18 @@ public abstract class Memory { return MemoryBuffer.wrap(memIntf.getLayout(), memIntf.getMemorySegment(addr, memIntf.getLayout().addrSize)).getAddr(); } + /** + * Read byte array starting at given address. + * + * @param addr Start address to read from + * @param length Numbe of bytes to read + * @return byte array read from location assigned to variable name + */ + public byte[] getByteArray(long addr, int length) + throws UnknownVariableException { + return memIntf.getMemorySegment(addr, length); + } + // -- Set fixed size types /** * Write 8 bit integer to address. @@ -253,4 +265,15 @@ public abstract class Memory { memIntf.setMemorySegment(addr, MemoryBuffer.wrap(memIntf.getLayout(), new byte[memIntf.getLayout().addrSize]).putAddr(value).getBytes()); } + /** + * Write byte array starting at given address. + * + * @param addr Start address to write to + * @param data data to write + */ + public void setByteArray(long addr, byte[] data) + throws UnknownVariableException { + memIntf.setMemorySegment(addr, data); + } + } diff --git a/tools/cooja/java/org/contikios/cooja/mote/memory/VarMemory.java b/tools/cooja/java/org/contikios/cooja/mote/memory/VarMemory.java index 2559fe2f1..ad782c8d7 100644 --- a/tools/cooja/java/org/contikios/cooja/mote/memory/VarMemory.java +++ b/tools/cooja/java/org/contikios/cooja/mote/memory/VarMemory.java @@ -243,7 +243,7 @@ public class VarMemory extends Memory { */ public byte[] getByteArray(String varName, int length) throws UnknownVariableException { - return memIntf.getMemorySegment(getVariable(varName).addr, length); + return getByteArray(getVariable(varName).addr, length); } /** @@ -349,13 +349,14 @@ public class VarMemory extends Memory { } /** + * Write byte array starting at location associated with this variable name. * - * @param varName - * @param data + * @param varName Variable name + * @param data data to write */ public void setByteArray(String varName, byte[] data) throws UnknownVariableException { - memIntf.setMemorySegment(getVariable(varName).addr, data); + setByteArray(getVariable(varName).addr, data); } /**