第13篇 Tython (教程lesson 5)

来源:互联网 发布:装修效果图制作软件 编辑:程序博客网 时间:2024/05/16 08:10

 

本文摘之我的progress report

第一,Tython是什么呢?

简单来说,Tython是一个的控制TOSSIM模拟器环境的一个工具。它可以控制TOSSIM运行时的一切参数,比如如下文所说,定义节点的位置,设定节点的无线传输模式,适用于很多的模拟场景(如移动节点,移动网关等等)。实际上Tinyviz就是采用了图像化的方式,来使用tython去设置了TOSSIM的运行参数的的界面程序。

 

Tython is an environment for testing andanalyzing sensor network applications. Tython is itself not a program simulator-- it uses TOSSIM to model TinyOS execution. In my opinion, Tython is a java applicationthat manages interactions with TOSSIM. For a standard TOSSIM running, it usesthe default values to set up the simulation environment which are not suitablefor many cases.

 

Tython compliments TOSSIM executions by addinga full featured scripting environment to augment the simulation. This allowsusers to build on top of and extend Tython to meet application specificrequirements. This also significantly helps the debugging process, allowing anarbitrarily complicated experiment to be repeatedly executed on successiveversions of the code.

 

In fact, Tython complements TinyViz'svizualization by adding a scripting interace to TOSSIM. We can see, actually,Tython is the console version of TinyViz. Like many other tools, the consoleversions are often more powerful than the GUI versions.

The first step to use tython is connect to TOSSIM:

1. Runan application with -gui flag to wait for connection.

 

 

Open another window and start the SimDriver torun tython:

 

On the same time, the application window alsoshowed that the connection was established.

 

now we can use following commands to set theposition of the nodes and control the simulation of the application.

一种设置节点初始位置的方式是用moveTox,y)函数

The method motes[i].moveTo(x, y) is moving motei to (x,y). The method motes[i].move(x, y) is Moving mote i (x,y) from itscurrent position. Therefore, we can setup the position for each mote by thisway even during the simulation.

 

The initialization for network topology can beachieved by executing a script file.

The builtin"execfile" command can be used to source a file and execute thecontents as Tython commands:

>>> execfile("myscript.py")

This will readand execute the contents of the specified file. As an alternative, passing thecommand line argument -script to Tython will cause it to automatically sourceand execute the named script file. For example:

java net.tinyos.sim.SimDriver -script "myscript.py"
 

tinyos2.0当中,使用TOSSIM的方式就是通过写这种类似的Tython!!! 所以如果要转到tinyos2.0的学习中,Tython脚本是不得不学习的!

 

However, the Tython manual says that when motesare moved with move/moveTo, the loss rates are calculated and TOSSIM updated. To avoidloss rates, I changed the way to set the locations of a mote with theMotes.setCoord(x, y) command. The radio model can be set with the Radio.setCurrModel(model)command. Model can be "disc10", "disc100","disc1000", or "empirical".

 

setCoord(x,y) method is described here:

public void setCoord(double x, double y)

Set the mote in virtual space to the givenlocation. Analogous to moveTo().

Parameters:

x - new X coordinate

y - new Y coordinate

Aactually, setCoord(x,y) is not a direct methodof class Mote; it is a method of the Mote's superclass SimObject.

 

public class Mote

extends SimObject

The Mote class provides access to the simulatedmote objects.

 

Each mote that is simulated has a correspondingsimulator object. These simulator objects are bound into the simcore module asthe motes list. Generic methods that are available on all simulator objects aredescribed in SimObject.

 

public class SimObject

extendsnet.tinyos.sim.script.reflect.SimReflect

The SimObject class provides internal access tosimulator objects that are not motes.

New objects are obtained by calling thenewSimObject() method on the Sim class.

setCurrModel(model) method is described here:

setCurModel

public void setCurModel(java.lang.String modelname)Setthe radio model.

Parameters:

modelname - the name of the new model (e.g."empirical")

It is a method of the class Radio.

public class Radio

extendsnet.tinyos.sim.script.reflect.SimReflect

Interface class to the radio model.

The class is bound into the simcore module asthe radio global instance.

 

有兴趣的同学可以阅读如下文档,里面有具体的如何使用Tython的方法:

All the information about Tython commands canbe found here:

C:/ProgramFiles/UCB/cygwin/opt/tinyos-1.x/doc/tython/javadoc/index.html


 

原创粉丝点击