コード例 #1
0
  // Recalculate the loss rate for the pair of motes based on their
  // distance and the current model
  public void updateLossRate(MoteSimObject moteSender, MoteSimObject moteReceiver) {
    double distance = moteSender.getDistance(moteReceiver);
    double prob = curModel.getPacketLossRate(distance, this.scalingFactor);

    debug.out.println(
        "RADIOMODEL: "
            + moteSender
            + "->"
            + moteReceiver
            + " dist "
            + distance
            + " scale "
            + scalingFactor
            + " prob "
            + prob);

    long scaledBitLossRate = (long) (curModel.getBitLossRate(prob) * 10000);

    debug.out.println(
        "RADIOMODEL: sampleLossRate "
            + "[moteSender "
            + moteSender
            + "] 1"
            + "[moteReceiver "
            + moteReceiver
            + "] "
            + "[packetLossRate "
            + prob
            + "] "
            + "[scaledBitLossRate "
            + scaledBitLossRate
            + "]");

    connectivityGraph.put(graphKey(moteSender, moteReceiver), new Double(prob));

    if (autoPublish) {
      publishLossRate(moteSender, moteReceiver, prob);
    }
  }
コード例 #2
0
  // Send the loss rate for the pair of motes to the simulator
  public void publishLossRate(MoteSimObject moteSender, MoteSimObject moteReceiver, double prob) {
    try {
      int senderID = moteSender.getID();
      int receiverID = moteReceiver.getID();

      debug.err.println(
          "RADIOMODEL: publishing rate [" + senderID + "->" + receiverID + "]: " + prob);

      long scaledBitLossRate = (long) (curModel.getBitLossRate(prob) * 10000);
      SetLinkProbCommand cmd =
          new SetLinkProbCommand((short) senderID, 0L, (short) receiverID, scaledBitLossRate);
      simComm.sendCommand(cmd);
    } catch (java.io.IOException ioe) {
      System.err.println("RADIOMODEL: Cannot send command: " + ioe);
    }
  }