added write to memory from COOJA + fixed byte ordering
This commit is contained in:
parent
9b20f11cd8
commit
add9d2a387
|
@ -24,7 +24,7 @@
|
||||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: AvrMoteMemory.java,v 1.1 2009/11/12 12:49:34 joxe Exp $
|
* $Id: AvrMoteMemory.java,v 1.2 2009/11/13 09:50:25 joxe Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.avrmote;
|
package se.sics.cooja.avrmote;
|
||||||
|
@ -95,18 +95,38 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
|
||||||
int data = 0;
|
int data = 0;
|
||||||
if (mem.vma_addr > 0xfffff) {
|
if (mem.vma_addr > 0xfffff) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
data = (data << 8) + (interpreter.getDataByte((mem.vma_addr & 0xfffff) + i) & 0xff);
|
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) +
|
System.out.println("Read byte: " + interpreter.getDataByte((mem.vma_addr & 0xfffff) + i) +
|
||||||
" => " + data);
|
" => " + data);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
data = (data << 8) + interpreter.getFlashByte(mem.vma_addr + i) & 0xff;
|
data = (data << 8) + interpreter.getFlashByte(mem.vma_addr + len - i - 1) & 0xff;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return data;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public int getIntValueOf(String varName) throws UnknownVariableException {
|
public int getIntValueOf(String varName) throws UnknownVariableException {
|
||||||
return getValueOf(varName, 2);
|
return getValueOf(varName, 2);
|
||||||
}
|
}
|
||||||
|
@ -134,13 +154,15 @@ public class AvrMoteMemory implements MoteMemory, AddressMemory {
|
||||||
|
|
||||||
public void setByteValueOf(String varName, byte newVal)
|
public void setByteValueOf(String varName, byte newVal)
|
||||||
throws UnknownVariableException {
|
throws UnknownVariableException {
|
||||||
|
setValue(varName, newVal, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIntValueOf(String varName, int newVal)
|
public void setIntValueOf(String varName, int newVal)
|
||||||
throws UnknownVariableException {
|
throws UnknownVariableException {
|
||||||
|
setValue(varName, newVal, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean variableExists(String varName) {
|
public boolean variableExists(String varName) {
|
||||||
return false;
|
return memoryMap.getLocation(varName) != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue