示例#1
0
  public void paintAfterMotes(Graphics g) {
    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.BLACK);

    Mote[] motes = simulation.getMotes();
    for (Mote mote : motes) {
      String msg = getMoteString(mote);
      if (msg == null) {
        continue;
      }
      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);
      int msgWidth = fm.stringWidth(msg);
      g.drawString(msg, pixel.x - msgWidth / 2, pixel.y + 2 * Visualizer.MOTE_RADIUS + 3);
    }
  }
示例#2
0
 private static String getMoteString(Mote mote) {
   if (!(mote instanceof MspMote)) {
     return null;
   }
   try {
     DebugInfo debugInfo =
         ((MspMoteType) mote.getType())
             .getELF()
             .getDebugInfo(((MspMote) mote).getCPU().reg[MSP430.PC]);
     if (debugInfo == null) {
       return null;
     }
     return debugInfo.getFile() + ":" + debugInfo.getLine();
   } catch (Exception e) {
     return "?";
   }
 }
示例#3
0
  public void simulationFinishedLoading() {
    if (delayedConfiguration == null) {
      return;
    }

    super.simulationFinishedLoading();

    boolean oldConfig = false;
    for (Element element : delayedConfiguration) {
      if (element.getName().equals("edge")) {
        @SuppressWarnings("unchecked")
        Collection<Element> edgeConfig = element.getChildren();
        Radio source = null;
        DGRMDestinationRadio dest = null;
        for (Element edgeElement : edgeConfig) {
          if (edgeElement.getName().equals("src")) {
            oldConfig = true;

            /* Old config: lookup source mote */
            for (Mote m : simulation.getMotes()) {
              if (m.toString().equals(edgeElement.getText())) {
                logger.info(
                    "Old config: mapping '" + edgeElement.getText() + "' to node " + m.getID());
                source = m.getInterfaces().getRadio();
                break;
              }
            }
          } else if (edgeElement.getName().equals("source")) {
            source =
                simulation
                    .getMoteWithID(Integer.parseInt(edgeElement.getText()))
                    .getInterfaces()
                    .getRadio();
          } else if (oldConfig && edgeElement.getName().equals("ratio")) {
            /* Old config: parse link ratio */
            double ratio = Double.parseDouble(edgeElement.getText());
            dest.ratio = ratio;
          } else if (edgeElement.getName().equals("dest")) {
            if (oldConfig) {
              /* Old config: create simple destination link */
              Radio destRadio = null;
              for (Mote m : simulation.getMotes()) {
                if (m.toString().equals(edgeElement.getText())) {
                  logger.info(
                      "Old config: mapping '" + edgeElement.getText() + "' to node " + m.getID());
                  destRadio = m.getInterfaces().getRadio();
                  break;
                }
              }
              dest = new DGRMDestinationRadio(destRadio);
            } else {
              String destClassName = edgeElement.getText().trim();
              if (destClassName == null || destClassName.isEmpty()) {
                continue;
              }
              /* Backwards compatibility: se.sics -> org.contikios */
              destClassName = destClassName.replaceFirst("^se\\.sics", "org.contikios");

              Class<? extends DGRMDestinationRadio> destClass =
                  simulation
                      .getCooja()
                      .tryLoadClass(this, DGRMDestinationRadio.class, destClassName);
              if (destClass == null) {
                throw new RuntimeException("Could not load class: " + destClassName);
              }
              try {
                dest = destClass.newInstance();
                @SuppressWarnings("unchecked")
                List<Element> children = edgeElement.getChildren();
                dest.setConfigXML(children, simulation);
              } catch (Exception e) {
                throw (RuntimeException)
                    new RuntimeException("Unknown class: " + destClassName).initCause(e);
              }
            }
          }
        }
        if (source == null || dest == null) {
          logger.fatal("Failed loading DGRM links, aborting");
          return;
        } else {
          addEdge(new Edge(source, dest));
        }
      }
    }
    requestEdgeAnalysis();
    delayedConfiguration = null;
  }
示例#4
0
 /**
  * Calculates distance from associated mote to another mote.
  *
  * @param m Another mote
  * @return Distance
  */
 public double getDistanceTo(Mote m) {
   return getDistanceTo(m.getInterfaces().getPosition());
 }