[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.
This commit is contained in:
Enrico Joerns 2014-08-28 13:02:43 +02:00
parent 2a0ccf2c6b
commit 77ab9359dd
2 changed files with 28 additions and 4 deletions

View File

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

View File

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