我编写了一个代理来计算两个节点之间的距离,但是在其中一个节点上部署代理时,出现以下错误:
漏洞!源单元“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;
}
}
}