*
* @param arguments Command arguments
* @return Reply to client (XML format)
*/
private String readMemory(Collection<Element> arguments) {
Simulation simulation = myGUI.getSimulation();
String type = null;
String mote = null;
String variable = null;
String size = null;
String address = null;
for (Element element : arguments) {
if (element.getName().equals(XML_TYPE_NAME)) {
type = element.getText();
} else if (element.getName().equals(XML_MOTE_NAME)) {
mote = element.getText();
} else if (element.getName().equals(XML_VARIABLE_NAME)) {
variable = element.getText();
} else if (element.getName().equals(XML_SIZE_NAME)) {
size = element.getText();
} else if (element.getName().equals(XML_ADDRESS_NAME)) {
address = element.getText();
} else {
return createErrorMessage("Unknown read memory parameter: " + element.getName());
}
}
if (type == null)
return createErrorMessage("No read memory type specified");
if (mote == null)
return createErrorMessage("No mote specified");
if (mote == null)
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();
// Read integer variable
if (type.equals("int")) {
if (variable == null)
return createErrorMessage("No variable name specified");