*
* @param arguments Command arguments
* @return Reply to client (XML format)
*/
private String addEventpoint(Collection<Element> arguments) {
Simulation simulation = myGUI.getSimulation();
String type = null;
String mote = null;
String variable = null;
String time = null;
String size = null;
String triggeron = null;
String address = null;
String count = 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_TIME_NAME)) {
time = 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 if (element.getName().equals(XML_TRIGGERON_NAME)) {
triggeron = element.getText();
} else if (element.getName().equals("count")) {
count = element.getText();
} else {
return createErrorMessage("Unknown eventpoint parameter: " + element.getName());
}
}
logger.debug("Eventpoint type: " + type);
if (type == null)
return createErrorMessage("No eventpoint type specified");
// Integer variable watchpoint
if (type.equals(XML_WATCHPOINT_INT)) {
if (variable == null)
return createErrorMessage("No variable name specified");
if (variable.contains(" "))
return createErrorMessage("Variable name must not contain spaces: " + variable);
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);
}
Mote moteObject = simulation.getMote(moteNr);
MoteMemory memory = simulation.getMote(moteNr).getMemory();
if (!(memory instanceof AddressMemory))
return createErrorMessage("Can't write mote memory variables (not address memory)");
if (!((AddressMemory) memory).variableExists(variable)) {
return createErrorMessage("Variable does not exist: " + variable);
}
Eventpoint newEventpoint = new IntegerWatchpoint(moteObject, variable);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
}
// Variable watchpoint
if (type.equals(XML_WATCHPOINT_VARIABLE)) {
if (variable == null)
return createErrorMessage("No variable name specified");
if (variable.contains(" "))
return createErrorMessage("Variable name must not contain spaces: " + variable);
if (mote == null)
return createErrorMessage("No mote ID specified");
if (size == null)
return createErrorMessage("No size specified");
int sizeParsed = Integer.parseInt(size);
if (sizeParsed < 0) {
return createErrorMessage("Bad size specified: " + sizeParsed);
}
int moteNr = Integer.parseInt(mote);
if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
return createErrorMessage("Bad mote ID specified: " + moteNr);
}
Mote moteObject = simulation.getMote(moteNr);
MoteMemory memory = simulation.getMote(moteNr).getMemory();
if (!(memory instanceof AddressMemory))
return createErrorMessage("Can't write mote memory variables (not address memory)");
if (!((AddressMemory) memory).variableExists(variable)) {
return createErrorMessage("Variable does not exist: " + variable);
}
Eventpoint newEventpoint = new VariableWatchpoint(moteObject, variable, sizeParsed);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
}
// Memory area watchpoint
if (type.equals(XML_WATCHPOINT_ADDRESS)) {
if (mote == null)
return createErrorMessage("No mote ID specified");
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);
}
int moteNr = Integer.parseInt(mote);
if (moteNr < 0 || simulation.getMotesCount() <= moteNr) {
return createErrorMessage("Bad mote ID specified: " + moteNr);
}
Mote moteObject = simulation.getMote(moteNr);
MoteMemory memory = simulation.getMote(moteNr).getMemory();
Eventpoint newEventpoint = new Watchpoint(moteObject, addressParsed, sizeParsed);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
}
// Simulation timepoint
if (type.equals(XML_TIMEPOINT_SIMULATION)) {
if (time == null)
return createErrorMessage("No time specified");
int timeParsed = Integer.parseInt(time);
if (timeParsed < 0) {
return createErrorMessage("Bad time specified: " + timeParsed);
}
Eventpoint newEventpoint = new SimulationTimepoint(simulation, timeParsed);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
}
// Real timepoint
if (type.equals(XML_TIMEPOINT_REAL)) {
if (time == null)
return createErrorMessage("No time specified");
long timeParsed = Long.parseLong(time);
if (timeParsed < 0) {
return createErrorMessage("Bad time specified: " + timeParsed);
}
Eventpoint newEventpoint = new RealTimepoint(timeParsed);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
}
// Radio medium event point
if (type.equals(XML_EVENTPOINT_RADIOMEDIUM)) {
int countInt;
try {
countInt = Integer.parseInt(count);
} catch (NumberFormatException e) {
return createErrorMessage("Bad count specified: " + e);
}
if (triggeron == null || triggeron.equals("all")) {
Eventpoint newEventpoint = new RadioMediumEventpoint(simulation.getRadioMedium(), countInt);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
} else if (triggeron.equals("completed")) {
Eventpoint newEventpoint = new TransmissionRadioMediumEventpoint(simulation.getRadioMedium(), countInt);
myEvaluator.addEventpoint(newEventpoint);
return createOkMessage(newEventpoint, simulation.getSimulationTime());
} else {
return createErrorMessage("Bad trigger on parameter: " + triggeron);
}
}