⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xmlcommandhandler.java

📁 Contiki是一个开源
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
      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);      }    }    return createErrorMessage("Bad eventpoint type specified: " + type);  }  /**   * Handle configure GUI command.   *    * @param arguments Command arguments   * @return Reply to client (XML format)   */  private String configureGUI(Collection<Element> arguments) {    String visible = null;    for (Element element : arguments) {      if (element.getName().equals(XML_VISIBLE_NAME)) {        visible = element.getText();      } else {        return createErrorMessage("Unknown GUI configure parameter: " + element.getName());      }    }        boolean shouldBeVisible = Boolean.parseBoolean(visible);    if (myGUI.isVisualized() != shouldBeVisible) {      myGUI.setVisualized(shouldBeVisible);    }    return XML_OK;  }  /**   * Handle delete eventpoint command.   *    * @param arguments Command arguments   * @return Reply to client (XML format)   */  private String deleteEventpoint(Collection<Element> arguments) {    String id = null;    for (Element element : arguments) {      if (element.getName().equals(XML_ID_NAME)) {        id = element.getText();      } else {        return createErrorMessage("Unknown eventpoint parameter: " + element.getName());      }    }    int idInt;    try {      idInt = Integer.parseInt(id);    } catch (NumberFormatException e) {      return createErrorMessage("Bad eventpoint ID specified: " + e);    }    Eventpoint eventpoint = myEvaluator.getEventpoint(idInt);    if (eventpoint == null)      return createErrorMessage("No eventpoint with ID " + idInt + " exists");    myEvaluator.deleteEventpoint(idInt);    return XML_OK;  }  /**   * Handle kill nodes command.   *    * @param arguments Command arguments   * @return Reply to client (XML format)   */  private String killNodes(Collection<Element> arguments) {    String lowId = null;    String highId = null;    for (Element element : arguments) {      if (element.getName().equals("lowmote")) {        lowId = element.getText();      } else if (element.getName().equals("highmote")) {        highId = element.getText();      } else {        return createErrorMessage("Unknown eventpoint parameter: " + element.getName());      }    }    int lowIdInt;    int highIdInt;    try {      lowIdInt = Integer.parseInt(lowId);      highIdInt = Integer.parseInt(highId);    } catch (NumberFormatException e) {      return createErrorMessage("Bad mote interval specified: " + e);    }    if (lowIdInt > highIdInt)      return createErrorMessage("Bad mote interval specified: Low ID must be <= than high ID");          if (lowIdInt < 0)      return createErrorMessage("Bad mote interval specified: Low ID >= 0");          if (myGUI.getSimulation() == null)      return createErrorMessage("No simulation exists");          if (myGUI.getSimulation().getMotesCount() < highIdInt)      return createErrorMessage("Bad mote interval specified: Only " + myGUI.getSimulation().getMotesCount() + " motes exist");    for (int pos=lowIdInt; pos <= highIdInt; pos++) {      Mote mote = myGUI.getSimulation().getMote(pos);      mote.setState(State.DEAD);    }    return XML_OK;  }  /**   * Handle get info command.   *    * @param arguments Command arguments   * @return Reply to client (XML format)   */  private String getInfo(Collection<Element> arguments) {    Simulation simulation = myGUI.getSimulation();    String type = null;    String mote = null;    String variable = 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 {        return createErrorMessage("Unknown info parameter: " + element.getName());      }    }    if (type.equals("motestate")) {      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);      }      State state = simulation.getMote(moteNr).getState();      if (state == State.DEAD)        return XML_OK_START + 0 + XML_OK_END;      return XML_OK_START + 1 + XML_OK_END;    } else if (type.equals("time")) {      return XML_OK_START + myGUI.getSimulation().getSimulationTime() + XML_OK_END;    } else if (type.equals(XML_MOTECOUNT_NAME)) {      return XML_OK_START + myGUI.getSimulation().getMotesCount() + XML_OK_END;    } else if (type.equals("var_address")) {      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 read mote memory variable address (not address memory)");      if (!((AddressMemory) memory).variableExists(variable)) {        return createErrorMessage("Variable does not exist: " + variable);      }      int address = ((AddressMemory) memory).getVariableAddress(variable);      return XML_OK_START + address + XML_OK_END;    }    return createErrorMessage("Unknown type: " + type);  }  /**   * Handle custom command.   *    * @param arguments Command arguments   * @return Reply to client (XML format)   */  private String handleCustomCommand(Collection<Element> arguments) {    Simulation simulation = myGUI.getSimulation();    String action = null;    int id = -1;    int visible = -1;    int hide = -1;    for (Element element : arguments) {      if (element.getName().equals("action")) {        action = element.getText();      } else if (element.getName().equals("id")) {        String idString = element.getText();        id = Integer.parseInt(idString);      } else if (element.getName().equals("hide")) {        String hideString = element.getText();        hide = Integer.parseInt(hideString);      } else if (element.getName().equals("visible")) {        String visibleString = element.getText();        visible = Integer.parseInt(visibleString);      } else {        return createErrorMessage("Unknown info parameter: " + element.getName());      }    }        if (action.equals("CLICK_SINK")) {      simulation.getMote(0).getInterfaces().getButton().clickButton();      return XML_OK;    }    if (action.equals("SHOW_FIRE")) {      if (!simulation.getGUI().isVisualized())        return XML_OK;      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();      try {        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");        Class[] parameterTypes = new Class[1];        parameterTypes[0] = Boolean.TYPE;        Method method = pluginClass.getMethod("showFire", parameterTypes);        Object[] parameterArguments = new Object[1];        parameterArguments[0] = new Boolean(visible==1?true:false);        for (JInternalFrame plugin: allPlugins) {          if (plugin.getClass() == pluginClass) {            method.invoke(plugin, parameterArguments);          }        }      } catch (Exception e) {        return createErrorMessage("Exception: " + e.getMessage());      }      return XML_OK;    }    if (action.equals("RESET_COLORS")) {      if (!simulation.getGUI().isVisualized())        return XML_OK;      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();      try {        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");        Class[] parameterTypes = new Class[0];        Method method = pluginClass.getMethod("resetColors", parameterTypes);        Object[] parameterArguments = new Object[0];        for (JInternalFrame plugin: allPlugins) {          if (plugin.getClass() == pluginClass) {            method.invoke(plugin, parameterArguments);          }        }      } catch (Exception e) {        return createErrorMessage("Exception: " + e.getMessage());      }      return XML_OK;    }    if (action.equals("SHOW_TRUCK")) {      if (!simulation.getGUI().isVisualized())        return XML_OK;      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();      try {        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");        if (hide == 0) {          Class[] parameterTypes = new Class[0];          Method method = pluginClass.getMethod("showTruck", parameterTypes);          Object[] parameterArguments = new Object[0];          for (JInternalFrame plugin: allPlugins) {            if (plugin.getClass() == pluginClass) {              method.invoke(plugin, parameterArguments);            }          }        } else {          Class[] parameterTypes = new Class[0];          Method method = pluginClass.getMethod("hideTruck", parameterTypes);          Object[] parameterArguments = new Object[0];          for (JInternalFrame plugin: allPlugins) {            if (plugin.getClass() == pluginClass) {              method.invoke(plugin, parameterArguments);            }          }        }      } catch (Exception e) {        return createErrorMessage("Exception: " + e.getMessage());      }      return XML_OK;    }    if (action.equals("INDICATE_MOTE")) {      if (!simulation.getGUI().isVisualized())        return XML_OK;      JInternalFrame[] allPlugins = simulation.getGUI().getDesktopPane().getAllFrames();      try {        Class<Visualizer2D> pluginClass = (Class<Visualizer2D>) simulation.getGUI().tryLoadClass(this, Visualizer2D.class, "se.sics.runes.RunesVis");        Class[] parameterTypes = new Class[1];        parameterTypes[0] = Integer.TYPE;        Method method = pluginClass.getMethod("indicateMote", parameterTypes);        Object[] parameterArguments = new Object[1];        parameterArguments[0] = new Integer(id);        for (JInternalFrame plugin: allPlugins) {          if (plugin.getClass() == pluginClass) {            method.invoke(plugin, parameterArguments);          }        }      } catch (Exception e) {        return createErrorMessage("Exception: " + e.getMessage());      }      return XML_OK;    }    return createErrorMessage("Unknown action: " + action);  }  /**   * Handle clear eventpoints command.   *    * @return Reply to client (XML format)   */  private String clearEventpoints() {    myEvaluator.clearAllEventpoints();    return XML_OK;  }    public static String createErrorMessage(String message) {    return XML_ERROR_START + message + XML_ERROR_END;  }  public static String createInfoMessage(String message) {    return XML_INFO_START + message + XML_INFO_END;  }    public static String createOkMessage(Eventpoint eventpoint, int time) {    return XML_OK_START + eventpoint.getID() + XML_OK_END;  }    public static String createEventpointMessage(EventpointEvaluator evaluator) {    return XML_EVENTPOINT_START +    evaluator.getLastTriggeredEventpointID() +    XML_INFO_START +     evaluator.getTriggeredEventpoint().getMessage() +    XML_INFO_END +     XML_EVENTPOINT_END;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -