2

我正在根据相邻节点之间的距离为水下通信网络实现路由协议。我创建了一个代理并编写了一个脚本来使用测距代理查找相邻节点之间的距离,但出现错误

没有这样的属性:范围为类:。

我会附上我写的脚本。

  1. 3-node-network_test.groovy :这是一个模拟脚本,我在其中部署了 3 个节点。节点 1 是接收节点,将在其中执行测距代理和接收脚本。节点 2 和 3 正在运行“测距代理”和“node_agent”。
  2. sink.groovy:将通过广播信标来初始化信标过程。
  3. node_agent:它从接收器接收信标并识别到接收器的距离。在这里,我编写了脚本来查找下沉距离:

完整的脚本。如何在unetstack中找到距离?

3-node-network_test.groovy:

//! Simulation: Simple 3-node network
import org.arl.fjage.*


// run the simulation forever
simulate {
  node '1', remote: 1101, address: 1, location: [ 0.km, 0.km, -15.m], shell: true, stack: {container ->
    container.add 'ranging', new org.arl.unet.phy.Ranging()   
    container.shell.addInitrc "${script.parent}/sink.groovy"
  }
  node '2', remote: 1102, address: 2, location: [ 1.km, 0.km, -15.m], shell: 5102, stack: {container ->
    container.add 'ranging', new org.arl.unet.phy.Ranging();
    //container.shell.addInitrc "${script.parent}/sink.groovy"
    container.add 'node_agent', new node_agent();
  }
  node '3', remote: 1103, address: 3, location: [-1.km, 0.km, -15.m], shell: 5103, stack: { container ->
    container.add 'ranging', new org.arl.unet.phy.Ranging()
    container.add 'node_agent', new node_agent();    
  }
}

Sink.groovy:

import org.arl.unet.*
import org.arl.unet.phy.*
import org.arl.unet.mac.*
//import org.arl.unet.nodeinfo.NodeInfo
import org.arl.unet.PDU 
import org.arl.fjage.*
import static org.arl.unet.Services.*
import static org.arl.unet.phy.Physical.*
import org.arl.unet.phy.Ranging.*


int hc = 0, ad;
float neighbor_dist;
float rang

subscribe phy;
send = { count = 1 ->

    println ''' BROADCASTING '''
    count.times {

          phy << new DatagramReq(to: Address.BROADCAST, protocol: Protocol.MAC, data: [node.address, hc, 0]);

        }

}

node_agent.groovy:

import org.arl.fjage.Message
import org.arl.unet.*
import org.arl.unet.net.Router
import org.arl.unet.phy.*
import org.arl.unet.mac.*
import org.arl.fjage.RealTimePlatform
import org.arl.unet.nodeinfo.NodeInfo
import org.arl.fjage.*
import org.arl.unet.phy.Ranging.*
import org.arl.unet.phy.RangeNtf.*
import org.arl.unet.phy.RangeReq 


class node_agent extends UnetAgent {
  int neighbor, addr;
    float neighbor_distance;

    void startup() 
    {

      def phy = agentForService Services.PHYSICAL;
      subscribe topic(phy);

      def rang = agentForService Services.RANGING;
      subscribe topic(rang);

      def nodeInfo = agentForService Services.NODE_INFO;
      addr = nodeInfo.address;

    }

    void processMessage(Message msg) {

    if (msg instanceof DatagramNtf && msg.protocol == Protocol.MAC)
    {     
      neighbor = msg.from;
      println " BEACON RECEIVED FROM:" +neighbor
      ranging<< new RangeReq(to: neighbor);   

      }

    else if (msg instanceof RangeNtf )
    {   

        float neighbor_distance = msg.getRange();
        println " Distance between node "+addr + " and neighbor" +neighbor+ "is" + neighbor_dis

    }  // End of if*/
    else {

    }
   }  //End of process message
}
4

1 回答 1

1

RangeReq需要将其发送给测距代理。您可以使用agentForService Services.RANGING. 由于无论如何您都在查找它startup(),因此您可以将其存储在一个属性中并稍后使用它来请求范围。就像是:

def ranging

void startup() 
{
         :
      ranging = agentForService Services.RANGING;
         :
}

void processMessage(Message msg)
{
      if (msg instanceof DatagramNtf && msg.protocol == Protocol.MAC)
      {     
        neighbor = msg.from;
        println " BEACON RECEIVED FROM:" +neighbor
        ranging << new RangeReq(to: neighbor);
      }
      else if (msg instanceof RangeNtf )
      {   
        float neighbor_distance = msg.getRange();
           :
     }
   }
}
于 2019-04-17T10:51:58.190 回答