Package org.contikios.cooja.interfaces

Examples of org.contikios.cooja.interfaces.Position


      if (selectedMote.getInterfaces().getRadio() == null) {
        continue;
      }

      /* Paint transmission and interference range for selected mote */
      Position motePos = selectedMote.getInterfaces().getPosition();

      Point pixelCoord = visualizer.transformPositionToPixel(motePos);
      int x = pixelCoord.x;
      int y = pixelCoord.y;
      Radio selectedRadio = selectedMote.getInterfaces().getRadio();

      FontMetrics fm = g.getFontMetrics();
      g.setColor(Color.BLACK);

      DirectedGraphMedium radioMedium = (DirectedGraphMedium) simulation.getRadioMedium();

      /* Print transmission success probabilities */
      DestinationRadio[] dests = radioMedium.getPotentialDestinations(selectedRadio);
      if (dests == null || dests.length == 0) {
        String msg = "No edges";
        int msgWidth = fm.stringWidth(msg);
        g.setColor(Color.BLACK);
        g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
        continue;
      }
      String msg = dests.length + " edges";
      int msgWidth = fm.stringWidth(msg);
      g.setColor(Color.BLACK);
      g.drawString(msg, x - msgWidth / 2, y + 2 * Visualizer.MOTE_RADIUS + 3);
      /* Draw LQI/RSSI edges */
      for (DestinationRadio r : dests) {
        double prob = ((DGRMDestinationRadio) r).ratio;
        double rssi = ((DGRMDestinationRadio) r).signal;
        double pos_rssi = rssi + 100;
        int lqi = ((DGRMDestinationRadio) r).lqi;
        float red = (float) (1 - prob * pos_rssi / 90 * lqi / 100);
        if (red > 1) {
          red = 1;
        }
        if (red < 0) {
          red = 0;
        }
        float green = (float) (prob * pos_rssi / 90 * lqi / 100);
        if (green > 1) {
          green = 1;
        }
        if (green < 0) {
          green = 0;
        }
        if (prob == 0.0d) {
          continue;
        }
        Position pos = r.radio.getPosition();
        Point pixel = visualizer.transformPositionToPixel(pos);
        g.setColor(new Color(red, green, 0.0f));
        g.drawString("LQI:  " + lqi, (x + pixel.x) / 2, (y + pixel.y) / 2);
        g.drawString("RSSI: " + rssi, (x + pixel.x) / 2, (y + pixel.y) / 2 + g.getFontMetrics().getHeight());
        g.drawLine(x, y, pixel.x, pixel.y);
View Full Code Here


      LED leds = mote.getInterfaces().getLED();
      if (leds == null) {
        continue;
      }

      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);

      int x = pixel.x - 2*Visualizer.MOTE_RADIUS;
     
      int y = pixel.y - Visualizer.MOTE_RADIUS;
View Full Code Here

      }
      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 - Visualizer.MOTE_RADIUS);
    }
View Full Code Here

      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);
    }
View Full Code Here

            logger.fatal("Could not create positioner");
            return;
          }

          for (int i = 0; i < newMotes.size(); i++) {
            Position newPosition = newMotes.get(i).getInterfaces().getPosition();
            if (newPosition != null) {
              double[] newPositionArray = positioner.getNextPosition();
              if (newPositionArray.length >= 3) {
                newPosition.setCoordinates(newPositionArray[0],
                    newPositionArray[1], newPositionArray[2]);
              } else if (newPositionArray.length >= 2) {
                newPosition.setCoordinates(newPositionArray[0],
                    newPositionArray[1], 0);
              } else if (newPositionArray.length >= 1) {
                newPosition.setCoordinates(newPositionArray[0], 0, 0);
              } else {
                newPosition.setCoordinates(0, 0, 0);
              }
            }
          }

          /* Set unique mote id's for all new motes
View Full Code Here

      if (selectedMote.getInterfaces().getRadio() == null) {
        continue;
      }

      /* Paint transmission and interference range for selected mote */
      Position motePos = selectedMote.getInterfaces().getPosition();

      Point pixelCoord = visualizer.transformPositionToPixel(motePos);
      int x = pixelCoord.x;
      int y = pixelCoord.y;

      // Fetch current output power indicator (scale with as percent)
      Radio selectedRadio = selectedMote.getInterfaces().getRadio();
      double moteInterferenceRange
              = radioMedium.INTERFERENCE_RANGE
              * ((double) selectedRadio.getCurrentOutputPowerIndicator()
              / (double) selectedRadio.getOutputPowerIndicatorMax());
      double moteTransmissionRange
              = radioMedium.TRANSMITTING_RANGE
              * ((double) selectedRadio.getCurrentOutputPowerIndicator()
              / (double) selectedRadio.getOutputPowerIndicatorMax());

      Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
      Point translatedInterference
              = visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
      Point translatedTransmission
              = visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
      Point translatedInterferenceMax
              = visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
      Point translatedTransmissionMax
              = visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);

      translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
      translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
      translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
      translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
      translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
      translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
      translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
      translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);

      /* Interference range */
      intRangeArea.add(new Area(new Ellipse2D.Double(
              x - translatedInterference.x,
              y - translatedInterference.y,
              2 * translatedInterference.x,
              2 * translatedInterference.y)));

      /* Interference range (MAX) */
      trxRangeArea.add(new Area(new Ellipse2D.Double(
              x - translatedTransmission.x,
              y - translatedTransmission.y,
              2 * translatedTransmission.x,
              2 * translatedTransmission.y)));

      intRangeMaxArea.add(new Area(new Ellipse2D.Double(
              x - translatedInterferenceMax.x,
              y - translatedInterferenceMax.y,
              2 * translatedInterferenceMax.x,
              2 * translatedInterferenceMax.y)));

      /* Transmission range (MAX) */
      trxRangeMaxArea.add(new Area(new Ellipse2D.Double(
              x - translatedTransmissionMax.x,
              y - translatedTransmissionMax.y,
              2 * translatedTransmissionMax.x,
              2 * translatedTransmissionMax.y)));

    }

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(COLOR_INT);
    g2d.fill(intRangeArea);
    g.setColor(Color.GRAY);
    g2d.draw(intRangeMaxArea);

    g.setColor(COLOR_TX);
    g2d.fill(trxRangeArea);
    g.setColor(Color.GRAY);
    g2d.draw(trxRangeMaxArea);

    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.BLACK);

    /* Print transmission success probabilities only if single mote is selected */
    if (selectedMotes.size() == 1) {
      Mote selectedMote = selectedMotes.toArray(new Mote[0])[0];
      Radio selectedRadio = selectedMote.getInterfaces().getRadio();
      for (Mote m : simulation.getMotes()) {
        if (m == selectedMote) {
          continue;
        }
        double prob
                = ((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
        if (prob == 0.0d) {
          continue;
        }
        String msg = (((int) (1000 * prob)) / 10.0) + "%";
        Position pos = m.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);
      }
    }
View Full Code Here

    g.setColor(Color.BLACK);

    /* Paint position coordinates right of motes */
    Mote[] allMotes = simulation.getMotes();
    for (Mote mote: allMotes) {
      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);

      String msg = "";
      String posString;
      String[] parts;

      /* X */
      posString = String.valueOf(pos.getXCoordinate()) + "000";
      parts = posString.split("\\.");
      if (parts[0].length() >= 4) {
        msg += parts[0];
      } else {
        msg += posString.substring(0, 5);
      }
     
      /* Y */
      msg += ", ";
      posString = String.valueOf(pos.getYCoordinate()) + "000";
      parts = posString.split("\\.");
      if (parts[0].length() >= 4) {
        msg += parts[0];
      } else {
        msg += posString.substring(0, 5);
      }

      /* Z */
      if (pos.getZCoordinate() != 0) {
        msg += ", ";
        posString = String.valueOf(pos.getZCoordinate()) + "000";
        parts = posString.split("\\.");
        if (parts[0].length() >= 4) {
          msg += parts[0];
        } else {
          msg += posString.substring(0, 5);
View Full Code Here

      String[] as = getAttributesStrings(mote);
      if (as == null) {
        continue;
      }
     
      Position pos = mote.getInterfaces().getPosition();
      Point pixel = visualizer.transformPositionToPixel(pos);

      int y = pixel.y + 2*Visualizer.MOTE_RADIUS + 3;
      for (String a: as) {
        if (a.startsWith("color=")) {
View Full Code Here

      if (selectedMote.getInterfaces().getRadio() == null) {
        continue;
      }

      /* Paint transmission and interference range for selected mote */
      Position motePos = selectedMote.getInterfaces().getPosition();

      Point pixelCoord = visualizer.transformPositionToPixel(motePos);
      int x = pixelCoord.x;
      int y = pixelCoord.y;

      // Fetch current output power indicator (scale with as percent)
      Radio selectedRadio = selectedMote.getInterfaces().getRadio();
      double moteInterferenceRange
              = radioMedium.INTERFERENCE_RANGE
              * ((double) selectedRadio.getCurrentOutputPowerIndicator()
              / (double) selectedRadio.getOutputPowerIndicatorMax());
      double moteTransmissionRange
              = radioMedium.TRANSMITTING_RANGE
              * ((double) selectedRadio.getCurrentOutputPowerIndicator()
              / (double) selectedRadio.getOutputPowerIndicatorMax());

      Point translatedZero = visualizer.transformPositionToPixel(0.0, 0.0, 0.0);
      Point translatedInterference
              = visualizer.transformPositionToPixel(moteInterferenceRange, moteInterferenceRange, 0.0);
      Point translatedTransmission
              = visualizer.transformPositionToPixel(moteTransmissionRange, moteTransmissionRange, 0.0);
      Point translatedInterferenceMax
              = visualizer.transformPositionToPixel(radioMedium.INTERFERENCE_RANGE, radioMedium.INTERFERENCE_RANGE, 0.0);
      Point translatedTransmissionMax
              = visualizer.transformPositionToPixel(radioMedium.TRANSMITTING_RANGE, radioMedium.TRANSMITTING_RANGE, 0.0);

      translatedInterference.x = Math.abs(translatedInterference.x - translatedZero.x);
      translatedInterference.y = Math.abs(translatedInterference.y - translatedZero.y);
      translatedTransmission.x = Math.abs(translatedTransmission.x - translatedZero.x);
      translatedTransmission.y = Math.abs(translatedTransmission.y - translatedZero.y);
      translatedInterferenceMax.x = Math.abs(translatedInterferenceMax.x - translatedZero.x);
      translatedInterferenceMax.y = Math.abs(translatedInterferenceMax.y - translatedZero.y);
      translatedTransmissionMax.x = Math.abs(translatedTransmissionMax.x - translatedZero.x);
      translatedTransmissionMax.y = Math.abs(translatedTransmissionMax.y - translatedZero.y);

      /* Interference range */
      intRangeArea.add(new Area(new Ellipse2D.Double(
              x - translatedInterference.x,
              y - translatedInterference.y,
              2 * translatedInterference.x,
              2 * translatedInterference.y)));

      /* Interference range (MAX) */
      trxRangeArea.add(new Area(new Ellipse2D.Double(
              x - translatedTransmission.x,
              y - translatedTransmission.y,
              2 * translatedTransmission.x,
              2 * translatedTransmission.y)));

      intRangeMaxArea.add(new Area(new Ellipse2D.Double(
              x - translatedInterferenceMax.x,
              y - translatedInterferenceMax.y,
              2 * translatedInterferenceMax.x,
              2 * translatedInterferenceMax.y)));

      /* Transmission range (MAX) */
      trxRangeMaxArea.add(new Area(new Ellipse2D.Double(
              x - translatedTransmissionMax.x,
              y - translatedTransmissionMax.y,
              2 * translatedTransmissionMax.x,
              2 * translatedTransmissionMax.y)));

    }

    Graphics2D g2d = (Graphics2D) g;

    g2d.setColor(COLOR_INT);
    g2d.fill(intRangeArea);
    g.setColor(Color.GRAY);
    g2d.draw(intRangeMaxArea);

    g.setColor(COLOR_TX);
    g2d.fill(trxRangeArea);
    g.setColor(Color.GRAY);
    g2d.draw(trxRangeMaxArea);

    FontMetrics fm = g.getFontMetrics();
    g.setColor(Color.BLACK);

    /* Print transmission success probabilities only if single mote is selected */
    if (selectedMotes.size() == 1) {
      Mote selectedMote = selectedMotes.toArray(new Mote[0])[0];
      Radio selectedRadio = selectedMote.getInterfaces().getRadio();
      for (Mote m : simulation.getMotes()) {
        if (m == selectedMote) {
          continue;
        }
        double prob
                = ((UDGM) simulation.getRadioMedium()).getSuccessProbability(selectedRadio, m.getInterfaces().getRadio());
        if (prob == 0.0d) {
          continue;
        }
        String msg = (((int) (1000 * prob)) / 10.0) + "%";
        Position pos = m.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);
      }
    }
View Full Code Here

      }
    };
    simulation.getEventCentral().addMoteCountListener(newMotesListener = new MoteCountListener() {
      @Override
      public void moteWasAdded(Mote mote) {
        Position pos = mote.getInterfaces().getPosition();
        if (pos != null) {
          pos.addObserver(posObserver);
          SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
              resetViewport = 1;
              repaint();
            }
          });
        }
      }

      @Override
      public void moteWasRemoved(Mote mote) {
        Position pos = mote.getInterfaces().getPosition();
        if (pos != null) {
          pos.deleteObserver(posObserver);
          repaint();
        }
      }
    });
    for (Mote mote : simulation.getMotes()) {
      Position pos = mote.getInterfaces().getPosition();
      if (pos != null) {
        pos.addObserver(posObserver);
      }
    }

    /* Observe mote highlights */
    gui.addMoteHighlightObserver(moteHighligtObserver = new Observer() {
View Full Code Here

TOP

Related Classes of org.contikios.cooja.interfaces.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.