Beispiel #1
0
  /**
   * Transmit the specified token to the specified receiver with the specified properties. If
   * <i>propagationSpeed</i> is less than Infinity, then this results in a call to fireAt() of the
   * director for each receiver that is in range. The token is not actually transmitted to the
   * receiver until the corresponding invocation of fire() occurs. The time delay is equal to
   * distance/<i>propagationSpeed</i>. See the class comments for the assumptions that make this
   * correct.
   *
   * <p>If the <i>lossProbability</i> is zero, (the default) then the specified receiver will
   * receive the token if it has room. If <i>lossProbability</i> is greater than zero, the token
   * will be lost with the specified probability, independently for each receiver in range. Note
   * that in this base class, a port is in range if it refers to this channel by name and is at the
   * right place in the hierarchy. This base class makes no use of the properties argument. But
   * derived classes may limit the range or otherwise change transmission properties using this
   * argument.
   *
   * @param token The token to transmit, or null to clear the specified receiver.
   * @param sender The sending port.
   * @param receiver The receiver to which to transmit.
   * @param properties The transmit properties (ignored in this base class).
   * @exception IllegalActionException If the token cannot be converted or if the token argument is
   *     null and the destination receiver does not support clear.
   */
  protected void _transmitTo(
      Token token, WirelessIOPort sender, WirelessReceiver receiver, RecordToken properties)
      throws IllegalActionException {
    double speed = ((DoubleToken) propagationSpeed.getToken()).doubleValue();

    if (speed == Double.POSITIVE_INFINITY) {
      super._transmitTo(token, sender, receiver, properties);
    } else {
      Director director = getDirector();

      // FIXME: This isn't right because the receiver
      // may have moved during propagation.  Maybe
      // register a ValueListener to the _location attributes
      // of the receiver actors, and continually recalculate
      // the correct arrival time for the message each time the
      // receiver location changes.  Even so, this will be
      // an approximation, and needs to be fully characterized.
      // Also, the receiver needs to be in range at the
      // conclusion of the propagation, whereas this method is
      // called only if the receiver is in range at the
      // initiation of the transmission.
      WirelessIOPort destination = (WirelessIOPort) receiver.getContainer();
      double distance = _distanceBetween(sender, destination);
      Time time = director.getModelTime().add(distance / speed);

      if (_receptions == null) {
        _receptions = new HashMap();
      }

      Double timeDouble = Double.valueOf(time.getDoubleValue());
      Reception reception = new Reception();
      reception.token = token;
      reception.sender = sender;
      reception.receiver = receiver;
      reception.properties = properties;
      _receptions.put(timeDouble, reception);

      _fireAt(time);
    }
  }
Beispiel #2
0
 private void jButton3ActionPerformed(
     java.awt.event.ActionEvent evt) { // GEN-FIRST:event_jButton3ActionPerformed
   String from = Gfrom.getText();
   String to = Gto.getText();
   String sujet = Gsujet.getText();
   String msg = Gmessage.getText();
   if (from.isEmpty()) {
     JOptionPane.showMessageDialog(this, "Le destinateur n'est pas valide");
   }
   if (to.isEmpty()) {
     JOptionPane.showMessageDialog(this, "Le destinataire n'est pas valide");
   }
   if (sujet.isEmpty()) {
     JOptionPane.showMessageDialog(this, "Le sujet n'est pas valide");
   }
   message.setFrom(from);
   message.setTo(to);
   message.setSujet(sujet);
   message.setMessage(msg);
   Reception reception = new Reception(parent, true, message);
   reception.setVisible(true);
 } // GEN-LAST:event_jButton3ActionPerformed
Beispiel #3
0
  /**
   * If a new message is available at the inputs, record it in the list indexed with the time that
   * the message shall be completed, and loop through the list to check whether there is collision.
   * If the current time matches one of the times that we have previously recorded as the completion
   * time for a transmission, then output the received message to the <i>received</i> output port if
   * it is not lost to a collision; otherwise, output it to the <i>collided</i> output port.
   *
   * @exception IllegalActionException If an error occurs reading or writing inputs or outputs.
   */
  public void fire() throws IllegalActionException {
    super.fire();

    Time currentTime = getDirector().getModelTime();

    if (_debugging) {
      _debug("---------------------------------");
      _debug("Current time is: " + currentTime);
    }

    if (message.hasToken(0) && power.hasToken(0) && duration.hasToken(0)) {
      double powerValue = ((DoubleToken) power.get(0)).doubleValue();

      if (_debugging) {
        _debug("Received message with power: " + powerValue);
      }

      if (powerValue < _powerThreshold) {
        // The signal it too weak to be detected, simply drop it.
        message.get(0);
        duration.get(0);

        if (_debugging) {
          _debug("Message power is below threshold. Ignoring.");
        }
      } else {
        // Record the reception.
        Reception reception = new Reception();
        reception.data = message.get(0);
        reception.power = powerValue;
        reception.arrivalTime = currentTime.getDoubleValue();
        reception.collided = false;
        reception.duration = ((DoubleToken) duration.get(0)).doubleValue();

        if (_debugging) {
          _debug("Message is above threshold and has duration: " + reception.duration);
        }

        // Update the total power density.
        _totalPower = _totalPower + reception.power;

        // Put the new reception into the list of prior receptions.
        Time time = currentTime.add(reception.duration);
        reception.expiration = time.getDoubleValue();

        _receptions.add(reception);

        // Schedule this actor to be fired at the end of
        // the duration of the message.
        _fireAt(time);
      }
    }

    // Loop through the prior receptions (and the new one)
    // to mark whether a message is collided according to the new total
    // power density. Also, any prior receptions that are now
    // expiring are sent to one of the two outputs.
    Iterator priorReceptions = _receptions.listIterator();

    while (priorReceptions.hasNext()) {
      Reception priorReception = (Reception) priorReceptions.next();

      if (_debugging) {
        _debug("Checking reception with arrival time: " + priorReception.arrivalTime);
      }

      // If the reception is now expiring, send it to one of the two
      // output ports.
      if (priorReception.expiration == currentTime.getDoubleValue()) {
        if (_debugging) {
          _debug(
              "Current time matches expiration "
                  + "time of a prior message that arrived at: "
                  + priorReception.arrivalTime);
        }

        // The time matches a pending reception.
        priorReceptions.remove();

        // Update the total power.
        _totalPower = _totalPower - priorReception.power;

        // Quantization errors may take this negative. Do not allow.
        if (_totalPower < 0.0) {
          _totalPower = 0.0;
        }

        if (!priorReception.collided) {
          received.send(0, priorReception.data);

          if (_debugging) {
            _debug("Message has been received: " + priorReception.data);
          }
        } else {
          collided.send(0, priorReception.data);

          if (_debugging) {
            _debug("Message has been lost: " + priorReception.data);
          }
        }

        continue;
      }

      // Check the snr to see whether to mark this prior reception
      // collided.
      double powerWithoutThisOne = _totalPower - priorReception.power;

      // Quantization errors may make this negative.
      if (powerWithoutThisOne < 0.0) {
        powerWithoutThisOne = 0.0;
      }

      double snr = priorReception.power / powerWithoutThisOne;

      if (!priorReception.collided && (snr <= _SNRThresholdInDB)) {
        priorReception.collided = true;

        if (_debugging) {
          _debug(
              "Message now has a collision. SNR is: " + snr + ". Total power is: " + _totalPower);
        }
      }
    }
  }