Package se.sics.cooja.interfaces

Examples of se.sics.cooja.interfaces.Radio


      moteLEDs.addObserver(observer);
      activeMoteObservers.add(new MoteObservation(mote, moteLEDs, observer));
    }

    /* Radio HW, RXTX */
    final Radio moteRadio = mote.getInterfaces().getRadio();
    if (moteRadio != null) {
      RadioHWEvent startupHW = new RadioHWEvent(
          simulation.getSimulationTime(), moteRadio.isRadioOn());
      if (radioChannels) {
        startupHW.channel = moteRadio.getChannel();
      }
      moteEvents.addRadioHW(startupHW);
      RadioRXTXEvent startupRXTX = new RadioRXTXEvent(
          simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
      moteEvents.addRadioRXTX(startupRXTX);
      Observer observer = new Observer() {
        int lastChannel = -1;
        public void update(Observable o, Object arg) {
          /* Radio HW events */
          if (radioChannels && moteRadio.getLastEvent() == RadioEvent.UNKNOWN) {
            int nowChannel = moteRadio.getChannel();
            if (nowChannel == lastChannel) {
              return;
            }
            lastChannel = nowChannel;

            RadioHWEvent ev = new RadioHWEvent(
                simulation.getSimulationTime(), moteRadio.isRadioOn());
            if (radioChannels) {
              ev.channel = moteRadio.getChannel();
            }

            moteEvents.addRadioHW(ev);

            if (executionDetails && mote instanceof AbstractEmulatedMote) {
              String details = ((AbstractEmulatedMote) mote).getExecutionDetails();
              if (details != null) {
                details = "<br>" + details.replace("\n", "<br>");
                ev.details = details;
              }
            }
            return;
          }

          if (moteRadio.getLastEvent() == RadioEvent.HW_ON ||
              moteRadio.getLastEvent() == RadioEvent.HW_OFF) {
            RadioHWEvent ev = new RadioHWEvent(
                simulation.getSimulationTime(), moteRadio.isRadioOn());
            if (radioChannels) {
              ev.channel = moteRadio.getChannel();
            }

            moteEvents.addRadioHW(ev);

            if (executionDetails && mote instanceof AbstractEmulatedMote) {
              String details = ((AbstractEmulatedMote) mote).getExecutionDetails();
              if (details != null) {
                details = "<br>" + details.replace("\n", "<br>");
                ev.details = details;
              }
            }
            return;
          }

          /* Radio RXTX events */
          RadioEvent radioEv = moteRadio.getLastEvent();
          if (radioEv == RadioEvent.TRANSMISSION_STARTED ||
              radioEv == RadioEvent.TRANSMISSION_FINISHED ||
              radioEv == RadioEvent.RECEPTION_STARTED ||
              radioEv == RadioEvent.RECEPTION_INTERFERED ||
              radioEv == RadioEvent.RECEPTION_FINISHED) {

            RadioRXTXEvent ev;
            /* Override events, instead show state */
            if (moteRadio.isTransmitting()) {
              ev = new RadioRXTXEvent(
                  simulation.getSimulationTime(), RXTXRadioEvent.TRANSMITTING);
            } else if (!moteRadio.isRadioOn()) {
              ev = new RadioRXTXEvent(
                  simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
            } else if (moteRadio.isInterfered()) {
              ev = new RadioRXTXEvent(
                  simulation.getSimulationTime(), RXTXRadioEvent.INTERFERED);
            } else if (moteRadio.isReceiving()) {
              ev = new RadioRXTXEvent(
                  simulation.getSimulationTime(), RXTXRadioEvent.RECEIVING);
            } else {
              ev = new RadioRXTXEvent(
                  simulation.getSimulationTime(), RXTXRadioEvent.IDLE);
            }

            moteEvents.addRadioRXTX(ev);

            if (executionDetails && mote instanceof AbstractEmulatedMote) {
              String details = ((AbstractEmulatedMote) mote).getExecutionDetails();
              if (details != null) {
                details = "<br>" + details.replace("\n", "<br>");
                ev.details = details;
              }
            }

            return;
          }

        }
      };

      moteRadio.addObserver(observer);
      activeMoteObservers.add(new MoteObservation(mote, moteRadio, observer));
    }

    /* XXX Experimental: Watchpoints */
    if (mote instanceof WatchpointMote) {
View Full Code Here


          return false;
        }

        if (col == COLUMN_TO) {
          /* Highlight all destinations */
          Radio dests[] = connections.get(row).connection.getDestinations();
          for (Radio dest: dests) {
            gui.signalMoteHighlight(dest.getMote());
          }
          return false;
        }
View Full Code Here

    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 =
View Full Code Here

      int source = Integer.parseInt(arr[INDEX_SRC]);
      m = simulation.getMoteWithID(source);
      if (m == null) {
        throw new RuntimeException("No simulation mote with ID " + source);
      }
      Radio sourceRadio = m.getInterfaces().getRadio();
      int dst = Integer.parseInt(arr[INDEX_DST]);
      m = simulation.getMoteWithID(dst);
      if (m == null) {
        throw new RuntimeException("No simulation mote with ID " + dst);
      }
View Full Code Here

      return;
    }
    for (RadioConnectionArrow connArrow : historyCopy) {
      float colorHistoryIndex = (float)connArrow.getAge() / (float)connArrow.getMaxAge();
      g.setColor(new Color(colorHistoryIndex, colorHistoryIndex, 1.0f));
      Radio source = connArrow.getConnection().getSource();
      Point sourcePoint = visualizer.transformPositionToPixel(source.getPosition());
      for (Radio destRadio : connArrow.getConnection().getDestinations()) {
        Position destPos = destRadio.getPosition();
        Point destPoint = visualizer.transformPositionToPixel(destPos);
        drawArrow(g, sourcePoint.x, sourcePoint.y, destPoint.x, destPoint.y, 8);
      }
View Full Code Here

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

    }

    /* Loop through all potential destinations */
    Position senderPos = sender.getPosition();
    for (DestinationRadio dest: potentialDestinations) {
      Radio recv = dest.radio;

      /* Fail if radios are on different (but configured) channels */
      if (sender.getChannel() >= 0 &&
          recv.getChannel() >= 0 &&
          sender.getChannel() != recv.getChannel()) {
        continue;
      }
      Position recvPos = recv.getPosition();

      /* Fail if radio is turned off */
//      if (!recv.isReceiverOn()) {
//        /* Special case: allow connection if source is Contiki radio,
//         * and destination is something else (byte radio).
//         * Allows cross-level communication with power-saving MACs. */
//        if (sender instanceof ContikiRadio &&
//            !(recv instanceof ContikiRadio)) {
//          /*logger.info("Special case: creating connection to turned off radio");*/
//        } else {
//          recv.interfereAnyReception();
//          continue;
//        }
//      }

      double distance = senderPos.getDistanceTo(recvPos);
      if (distance <= moteTransmissionRange) {
        /* Within transmission range */

        if (!recv.isRadioOn()) {
          newConnection.addInterfered(recv);
          recv.interfereAnyReception();
        } else if (recv.isInterfered()) {
          /* Was interfered: keep interfering */
          newConnection.addInterfered(recv);
        } else if (recv.isTransmitting()) {
          newConnection.addInterfered(recv);
        } else if (recv.isReceiving() ||
            (random.nextDouble() > getRxSuccessProbability(sender, recv))) {
          /* Was receiving, or reception failed: start interfering */
          newConnection.addInterfered(recv);
          recv.interfereAnyReception();

          /* Interfere receiver in all other active radio connections */
          for (RadioConnection conn : getActiveConnections()) {
            if (conn.isDestination(recv)) {
              conn.addInterfered(recv);
            }
          }

        } else {
          /* Success: radio starts receiving */
          newConnection.addDestination(recv);
        }
      } else if (distance <= moteInterferenceRange) {
        /* Within interference range */
        newConnection.addInterfered(recv);
        recv.interfereAnyReception();
      }
    }

    return newConnection;
  }
View Full Code Here

    /* Convert to arrays */
    Hashtable<Radio,DestinationRadio[]> arrTable =  new Hashtable<Radio,DestinationRadio[]>();
    Enumeration<Radio> sources = listTable.keys();
    while (sources.hasMoreElements()) {
      Radio source = sources.nextElement();
      DestinationRadio[] arr = listTable.get(source).toArray(new DestinationRadio[0]);
      arrTable.put(source, arr);
    }

    this.edgesTable = arrTable;
View Full Code Here

    boolean oldConfig = false;
    for (Element element : delayedConfiguration) {
      if (element.getName().equals("edge")) {
        Collection<Element> edgeConfig = element.getChildren();
        Radio source = null;
        DestinationRadio 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());
            ((DGRMDestinationRadio)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;
View Full Code Here

TOP

Related Classes of se.sics.cooja.interfaces.Radio

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.