return createErrorMessage("No mote ID specified");
int moteNr = Integer.parseInt(mote);
if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
return createErrorMessage("Bad mote ID specified: " + moteNr);
}
MoteMemory memory = simulation.getMote(moteNr).getMemory();
// Write integer variable
if (type.equals("int")) {
if (variable == null)
return createErrorMessage("No variable name specified");
if (variable.contains(" "))
return createErrorMessage("Variable name must not contain spaces: " + variable);
if (!(memory instanceof AddressMemory))
return createErrorMessage("Can't read mote memory variables (not address memory)");
if (!((AddressMemory) memory).variableExists(variable)) {
return createErrorMessage("Variable does not exist: " + variable);
}
if (value == null)
return createErrorMessage("No value specified");
if (value.contains(" "))
return createErrorMessage("Integer value must not contain spaces: " + value);
int val;
try {
val = Integer.parseInt(value);
} catch (NumberFormatException e) {
return createErrorMessage("Bad integer value specified: " + e);
}
((AddressMemory) memory).setIntValueOf(variable, val);
return XML_OK;
} else if (type.equals("variable")) {
if (variable == null)
return createErrorMessage("No variable name specified");
if (variable.contains(" "))
return createErrorMessage("Variable name must not contain spaces: " + variable);
if (!(memory instanceof AddressMemory))
return createErrorMessage("Can't read mote memory variables (not address memory)");
if (!((AddressMemory) memory).variableExists(variable)) {
return createErrorMessage("Variable does not exist: " + variable);
}
if (size == null)
return createErrorMessage("No size specified");
int sizeParsed = Integer.parseInt(size);
if (sizeParsed < 0) {
return createErrorMessage("Bad size specified: " + sizeParsed);
}
if (value == null)
return createErrorMessage("No value specified");
String[] bytesParsed = value.split(" ");
if (bytesParsed.length != sizeParsed)
return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);
byte[] val = new byte[bytesParsed.length];
for (int i=0; i < sizeParsed; i++) {
val[i] = Byte.parseByte(bytesParsed[i]);
}
((AddressMemory) memory).setByteArray(variable, val);
return XML_OK;
} else if (type.equals("address")) {
if (size == null)
return createErrorMessage("No size specified");
int sizeParsed = Integer.parseInt(size);
if (sizeParsed < 0) {
return createErrorMessage("Bad size specified: " + sizeParsed);
}
int addressParsed = Integer.parseInt(address);
if (addressParsed < 0) {
return createErrorMessage("Bad start address specified: " + addressParsed);
}
if (value == null)
return createErrorMessage("No value specified");
String[] bytesParsed = value.split(" ");
if (bytesParsed.length != sizeParsed)
return createErrorMessage("Number of bytes and specified size does not match: " + bytesParsed.length + "!=" + sizeParsed);
byte[] val = new byte[bytesParsed.length];
for (int i=0; i < sizeParsed; i++) {
val[i] = Byte.parseByte(bytesParsed[i]);
}
memory.setMemorySegment(addressParsed, val);
return XML_OK;
}
return createErrorMessage("Bad write memory type specified: " + type);
}