Javascript 如何使用脚本编辑器cooja模拟器从“收集”视图访问微尘信息?

Javascript 如何使用脚本编辑器cooja模拟器从“收集”视图访问微尘信息?,javascript,contiki,cooja,Javascript,Contiki,Cooja,我正在尝试编写一个脚本(Javascript)来记录收集视图工具中的远程信息,我没有找到任何教程或文档来说明如何使用脚本编辑器访问远程信息,我非常感谢您的帮助 谢谢大家! 超时(900000,log.log(“总PRR”+总PRR+“\n”); TIMEOUT(900000, log.log("Total PRR " + totalPRR + "\n")); packetsReceived= new Array(); packetsSent = ne

我正在尝试编写一个脚本(Javascript)来记录收集视图工具中的远程信息,我没有找到任何教程或文档来说明如何使用脚本编辑器访问远程信息,我非常感谢您的帮助

谢谢大家!

超时(900000,log.log(“总PRR”+总PRR+“\n”);
TIMEOUT(900000, log.log("Total PRR " + totalPRR + "\n"));

 packetsReceived= new Array();

packetsSent = new Array();

serverID = 1;

nodeCount = 6;

totalPRR = 0;

t_total = 0;

throughput = 0;

PDR=0;

data_length = 100;

Average_delay = 0;

timeReceived= new Array();

timeSent = new Array();

delay = new Array();

for(i = 0; i < ( nodeCount-1); i++) {

packetsReceived[i] = 0;

packetsSent[i] = 0;

timeReceived[i] = 0.0;

timeSent[i] = 0.0;

delay[i] = 0.0;

}

while(1) {

YIELD();

msgArray = msg.split(' ');

// log.log("string: "+msgArray+"\n");



if(msgArray[0].equals("receiver")) {

// Received packet

senderID = parseInt(msgArray[1]);

packetsReceived[senderID]++;

timeReceived[senderID] = time;

log.log("\n" + " SenderID " + senderID + " PRR " + packetsReceived[senderID] / packetsSent[senderID] + "timeReceived[senderID]" +  timeReceived[senderID] + " timeSent[senderID] " + timeSent[senderID] + "\n");

totalReceived = totalSent = 0;

totaldelay = 0;

count1 = 0;

for(i = 0; i < ( nodeCount-1); i++) 
{

    totalReceived += packetsReceived[i];

    totalSent += packetsSent[i];

    if (timeReceived[i] > 0) {

        delay[i] = timeReceived[i] - timeSent[i];

        delay[i] = delay[i] / 10000000 ;


        if (delay[i] > 0) 
        {

         

            totaldelay = totaldelay + delay[i];

            count1++;

        }

}

}

totalPRR = totalReceived / totalSent;

total_simulation_time=time;
log.log("\n"+"Total simulation time"+total_simulation_time+"\n");

throughput = (totalReceived * data_length * 8 *1000) / total_simulation_time;

log.log("\n"+"Total Received " + totalReceived + "totalSent" + totalSent + "\n");
PDR=(totalReceived / totalSent) * 100;

t_total = totalPRR * 100 ;

 

log.log("\n" + "Total Packet reception rate " + totalPRR + " Total_delay " + totaldelay + "Packet Delivery Ratio" + PDR + "\n");

log.log("\n"+ "Throughput "+throughput+"\n");

} 

else if(msgArray[0].equals("sender")) {

// Sent packet
receiverID = parseInt(msgArray[1]);


packetsSent[receiverID]++;

timeSent[receiverID] = time;

log.log( "\n" + " packetsSent[id]"  + packetsSent[receiverID]  + " timeSent[id] " + timeSent[receiverID] +  " id " + receiverID + "\n");

}



}
packetsReceived=新数组(); packetsSent=新数组(); serverID=1; nodeCount=6; 总PRR=0; t_总=0; 吞吐量=0; PDR=0; 数据长度=100; 平均延迟=0; timeReceived=新数组(); timeSent=新数组(); 延迟=新数组(); 对于(i=0;i<(nodeCount-1);i++){ packetsReceived[i]=0; packetsSent[i]=0; 接收时间[i]=0.0; timeSent[i]=0.0; 延迟[i]=0.0; } 而(1){ 收益率(); msgArray=msg.split(“”); //log.log(“字符串:“+msgArray+”\n”); if(msgArray[0]。等于(“接收方”)){ //收到的数据包 senderID=parseInt(msgArray[1]); 收到的数据包[senderID]++; 接收到的时间[senderID]=时间; log.log(“\n”+“SenderID”+SenderID+“PRR”+数据包接收[SenderID]/数据包接收[SenderID]+“timeReceived[SenderID]”+时间接收[SenderID]+“timeSent[SenderID]”+时间接收[SenderID]+”\n”); totalReceived=totalSent=0; 总延迟=0; count1=0; 对于(i=0;i<(nodeCount-1);i++) { 接收总数+=收到的包裹[i]; totalSent+=包装件[i]; 如果(接收时间[i]>0){ 延迟[i]=接收的时间[i]-timeSent[i]; 延迟[i]=延迟[i]/10000000; 如果(延迟[i]>0) { 总延迟=总延迟+延迟[i]; count1++; } } } totalPRR=totalReceived/totalSent; 总模拟时间=时间; log.log(“\n”+“总模拟时间”+总模拟时间+”\n”); 吞吐量=(总接收*数据长度*8*1000)/总模拟时间; log.log(“\n”+“接收总数”+totalReceived+“totalSent”+totalSent+”\n”); PDR=(总接收/总发送)*100; t_总计=总PRR*100; log.log(“\n”+“总数据包接收速率”+totalPRR+“总延迟”+totaldelay+“数据包交付率”+PDR+”\n”); log.log(“\n”+“吞吐量”+吞吐量+“\n”); } else if(msgArray[0]。等于(“发送方”)){ //发送包 receiverID=parseInt(Msgaray[1]); packetsSent[接收方]+; timeSent[接收方]=时间; log.log(“\n”+“packetsSent[id]”+packetsSent[receiverID]+“timeSent[id]”+timeSent[receiverID]+“id”+receiverID+“\n”); } }
我在我的项目中使用了这个脚本。这是不言自明的。但如果您有任何疑问,请询问我。

超时(900000,log.log(“总PRR”+总PRR+“\n”);
packetsReceived=新数组();
packetsSent=新数组();
serverID=1;
nodeCount=6;
总PRR=0;
t_总=0;
吞吐量=0;
PDR=0;
数据长度=100;
平均延迟=0;
timeReceived=新数组();
timeSent=新数组();
延迟=新数组();
对于(i=0;i<(nodeCount-1);i++){
packetsReceived[i]=0;
packetsSent[i]=0;
接收时间[i]=0.0;
timeSent[i]=0.0;
延迟[i]=0.0;
}
而(1){
收益率();
msgArray=msg.split(“”);
//log.log(“字符串:“+msgArray+”\n”);
if(msgArray[0]。等于(“接收方”)){
//收到的数据包
senderID=parseInt(msgArray[1]);
收到的数据包[senderID]++;
接收到的时间[senderID]=时间;
log.log(“\n”+“SenderID”+SenderID+“PRR”+数据包接收[SenderID]/数据包接收[SenderID]+“timeReceived[SenderID]”+时间接收[SenderID]+“timeSent[SenderID]”+时间接收[SenderID]+”\n”);
totalReceived=totalSent=0;
总延迟=0;
count1=0;
对于(i=0;i<(nodeCount-1);i++)
{
接收总数+=收到的包裹[i];
totalSent+=包装件[i];
如果(接收时间[i]>0){
延迟[i]=接收的时间[i]-timeSent[i];
延迟[i]=延迟[i]/10000000;
如果(延迟[i]>0)
{
总延迟=总延迟+延迟[i];
count1++;
}
}
}
totalPRR=totalReceived/totalSent;
总模拟时间=时间;
log.log(“\n”+“总模拟时间”+总模拟时间+”\n”);
吞吐量=(总接收*数据长度*8*1000)/总模拟时间;
log.log(“\n”+“接收总数”+totalReceived+“totalSent”+totalSent+”\n”);
PDR=(总接收/总发送)*100;
t_总计=总PRR*100;
log.log(“\n”+“总数据包接收速率”+totalPRR+“总延迟”+totaldelay+“数据包交付率”+PDR+”\n”);
log.log(“\n”+“吞吐量”+吞吐量+“\n”);
} 
else if(msgArray[0]。等于(“发送方”)){
//发送包
receiverID=parseInt(Msgaray[1]);
packetsSent[接收方]+;
timeSent[接收方]=时间;
log.log(“\n”+“packetsSent[id]”+packetsSent[receiverID]+“timeSent[id]”+timeSent[receiverID]+“id”+receiverID+“\n”);
}
}

我在我的项目中使用了这个脚本。这是不言自明的。但是如果您有任何疑问,请问我。

非常感谢您,先生!是否有办法将此数据保存到特定的日志文件?没有。我已手动复制粘贴读取。运行此脚本将花费太多时间。超时时间以毫秒为单位。因此,对于我的项目,它是900000秒=15分钟。对于我的程序,msgArray was receiver后跟一些字符串,这就是为什么我检查了msgArray[0].equals(“receiver”)。另一个问题:保存每个节点的totalDelay和total PRR有意义吗?或者totaldelay和PRR是否仅依赖于节点对(两个节点交换数据包)?否。它不适用于单个节点。在我的项目中,有五个节点的网络+1个RPL边界路由器。因此,nodeCount=6;在密码里。忘了说一件事。您需要在所需时间后停止模拟。就我而言,是15分钟。这次是cooja模拟时间,不是真正的时钟。非常感谢您,先生!是否有办法将此数据保存到特定的日志文件?没有。我已手动复制粘贴读取。运行此脚本将花费太多时间。超时时间以毫秒为单位。因此,对于我的项目,它是900000秒=15分钟。