1

我编写了一个代理来计算两个节点之间的距离,但是在其中一个节点上部署代理时,出现以下错误:

漏洞!源单元“Script26.groovy”中的“语义分析”阶段异常 查找 node_agent 导致编译失败。此调用不应该进行任何编译。

我使用了命令 container.add 'myagent' , new node_agent()

以下是代码片段。

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

println '''
3-node network
--------------
'''

platform = RealTimePlatform

// run the simulation forever
simulate {
  
  node '1', address: 101, location: [ 0.km, 0.km, -15.m], web:8081,api: 1101, shell: true, stack: "$home/etc/setup"
  node '2', address: 102, location: [ 0.km, 1.km, -15.m], web:8082,api: 1102, shell: 5101, stack: "$home/etc/setup"
  node '3', address: 103, location: [-1.km, 0.km, -15.m], web:8083,api: 1103, shell: 5102, stack: "$home/etc/setup"
  
  node 'B', address: 104, location: [ 1.km, 0.km, -15.m], web:8084,api: 1104, shell: 5103, stack: "$home/etc/setup"

}

node_agent.groovy 放置在 classes 文件夹中

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 addr;
    float neighbor_distance;

    void startup() 
    {

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

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

      def nodeInfo = agentForService Services.NODE_INFO;
      addr = nodeInfo.address;
      
      ranging<< new RangeReq(to: host('3')); 
      
    }

    void processMessage(Message msg) {

    if (msg instanceof RangeNtf )
    {   
        float neighbor_distance = msg.getRange();
        println " Distance between node "+addr + " and neighbor 3 is" + neighbor_distance;
    }  
   }  
}
4

1 回答 1

3

在 UnetStack 3.2.0 中,RangeNtf该类(和其他测距相关类)已移至org.arl.unet.localization包中。请参阅https://unetstack.net/javadoc/3.2/org/arl/unet/localization/RangeNtf.html。所以你的进口不正确。

一般来说,如本文所述(正如 Jay Patel 在上面的评论中指出的那样),找到此类问题的方法是手动编译 Groovy 代理:

$ groovy -cp lib/unet-framework-3.2.0.jar:lib/fjage-1.8.0.jar:lib/unet-basic-3.2.0.jar classes/node_agent.groovy
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
unet/classes/node_agent.groovy: 11: unable to resolve class org.arl.unet.phy.RangeReq
 @ line 11, column 1.
   import org.arl.unet.phy.RangeReq
   ^

/Users/mandar/Projects/unet/node_agent.groovy: 36: unable to resolve class RangeNtf
 @ line 36, column 24.
       if (msg instanceof RangeNtf )
                          ^

2 errors
于 2021-01-24T05:40:17.617 回答