Exemple #1
0
  /** Handles data arriving at UP port */
  protected synchronized void dataArriveAtUpPort(Object data_, drcl.comp.Port upPort_) {
    if (!(data_ instanceof TargetPacket)) {
      error(data_, "dataArriveAtUpPort()", upPort_, "unknown object");
      return;
    }

    // get most up-to-date location from SensorMobilityModel
    SensorPositionReportContract.Message msg = new SensorPositionReportContract.Message();
    msg = (SensorPositionReportContract.Message) mobilityPort.sendReceive(msg);
    double Xc = msg.getX();
    double Yc = msg.getY();
    double Zc = msg.getZ();

    /* Forward the packet received from the TargetAgent to the channel
    so that other neighboring sensors can receive it */

    System.out.println(
        "Target "
            + nid
            + ": generating signal at time "
            + getTime()
            + " loc: "
            + Xc
            + ", "
            + Yc
            + ", "
            + Zc);

    downPort.doSending(
        new SensorNodeChannelContract.Message(
            nid,
            Xc,
            Yc,
            Zc,
            Pt,
            Radius,
            new TargetPacket(((TargetPacket) data_).size, ((TargetPacket) data_).data)));
  }
Exemple #2
0
  /** Handles data arriving at Channel port */
  protected synchronized void dataArriveAtChannelPort(Object data_) {
    long s;
    if (gen == null) {
      s = SEED_RNG;
      // Uncomment the following line to get different results in every run
      // s = (long)(Math.abs(java.lang.System.currentTimeMillis()*Math.random()*100)) ;
      gen = new GaussianDistribution(NOISE_MEAN, NOISE_VAR, s);
    }

    // get most up-to-date location of the node (i.e., the receiver
    // of the message) from SensorMobilityModel
    SensorPositionReportContract.Message msg = new SensorPositionReportContract.Message();
    msg = (SensorPositionReportContract.Message) mobilityPort.sendReceive(msg);
    double Xc = msg.getX();
    double Yc = msg.getY();
    double Zc = msg.getZ();

    // extract the location of the sender from the message being received
    double Xs, Ys, Zs; // position of the sender
    SensorNodeChannelContract.Message msg2 = (SensorNodeChannelContract.Message) data_;
    Xs = msg2.getX();
    Ys = msg2.getY();
    Zs = msg2.getZ();

    // extract also the power with which the packet was sent
    double Pt_received; // Pt of the received packet
    Pt_received = msg2.getPt();

    long target_nid = msg2.getNid();

    // make up a SensorRadioPropagationContract to ask the
    // propagation model to reply with the received signal strength
    SensorRadioPropagationQueryContract.Message msg3 =
        (SensorRadioPropagationQueryContract.Message)
            propagationPort.sendReceive(
                new SensorRadioPropagationQueryContract.Message(
                    Pt_received, Xs, Ys, Zs, Xc, Yc, Zc));
    double Pr = msg3.getPr();

    if (Pr < RxThresh) {
      System.out.println(
          "SensorPhy nid=" + nid + " Packet was discarded because Pr = " + Pr + " < " + RxThresh);
    } else {
      double af = Pr; // attenuation factor
      int size = ((TargetPacket) msg2.getPkt()).size;
      TargetPacket sensorPkt = new TargetPacket(size, ((TargetPacket) msg2.getPkt()).data);
      lastNoisePower = 0.0;
      double rd;
      for (int k = 0; k < sensorPkt.size; k++) {
        sensorPkt.data[k] = sensorPkt.data[k] * af; // attenuate the signal
        rd = gen.nextDouble();
        double noise = noiseStrength * rd;
        sensorPkt.data[k] = sensorPkt.data[k] + noise;
        lastNoisePower = lastNoisePower + (noise * noise);
      } // end for

      lastNoisePower = lastNoisePower / ((double) size);

      // Forward the data packet up to the sensor agent
      toAgentPort.doSending(
          new SensorAgentPhyContract.Message(
              lastNoisePower, new TargetPacket(size, sensorPkt.data), target_nid));
    } // end else
  } // end dataArriveAtChannelPort