本文摘之我的progress report
第一,Tython是什么呢?
简单来说,Tython是一个的控制TOSSIM模拟器环境的一个工具。它可以控制TOSSIM运行时的一切参数,比如如下文所说,定义节点的位置,设定节点的无线传输模式,适用于很多的模拟场景(如移动节点,移动网关等等)。实际上Tinyviz就是采用了图像化的方式,来使用tython去设置了TOSSIM的运行参数的的界面程序。
Tython is an environment for testing and analyzing sensor network applications. Tython is itself not a program simulator -- it uses TOSSIM to model TinyOS execution. In my opinion, Tython is a java application that manages interactions with TOSSIM. For a standard TOSSIM running, it uses the default values to set up the simulation environment which are not suitable for many cases.
Tython compliments TOSSIM executions by adding a full featured scripting environment to augment the simulation. This allows users to build on top of and extend Tython to meet application specific requirements. This also significantly helps the debugging process, allowing an arbitrarily complicated experiment to be repeatedly executed on successive versions of the code.
In fact, Tython complements TinyViz's vizualization by adding a scripting interace to TOSSIM. We can see, actually, Tython is the console version of TinyViz. Like many other tools, the console versions are often more powerful than the GUI versions.
1. Run an application with -gui flag to wait for connection.
Open another window and start the SimDriver to run tython:
On the same time, the application window also showed that the connection was established.
now we can use following commands to set the position of the nodes and control the simulation of the application.
一种设置节点初始位置的方式是用moveTo(x,y)函数
The method motes[i].moveTo(x, y) is moving mote i to (x,y). The method motes[i].move(x, y) is Moving mote i (x,y) from its current position. Therefore, we can setup the position for each mote by this way even during the simulation.
The initialization for network topology can be achieved by executing a script file.
The builtin "execfile" command can be used to source a file and execute the contents as Tython commands:
>>> execfile("myscript.py")
This will read and execute the contents of the specified file. As an alternative, passing the command line argument -script to Tython will cause it to automatically source and 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 motes are moved with move/moveTo, the loss rates are calculated and TOSSIM updated. To avoid loss rates, I changed the way to set the locations of a mote with the Motes.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 given location. Analogous to moveTo().
Parameters:
x - new X coordinate
y - new Y coordinate
Aactually, setCoord(x,y) is not a direct method of class Mote; it is a method of the Mote's superclass SimObject.
public class Mote
extends SimObject
The Mote class provides access to the simulated mote objects.
Each mote that is simulated has a corresponding simulator object. These simulator objects are bound into the simcore module as the motes list. Generic methods that are available on all simulator objects are described in SimObject.
public class SimObject
extends net.tinyos.sim.script.reflect.SimReflect
The SimObject class provides internal access to simulator objects that are not motes.
New objects are obtained by calling the newSimObject() method on the Sim class.
setCurrModel(model) method is described here:
setCurModel
public void setCurModel(java.lang.String modelname)Set the radio model.
Parameters:
modelname - the name of the new model (e.g. "empirical")
It is a method of the class Radio.
public class Radio
extends net.tinyos.sim.script.reflect.SimReflect
Interface class to the radio model.
The class is bound into the simcore module as the radio global instance.
有兴趣的同学可以阅读如下文档,里面有具体的如何使用Tython的方法:
All the information about Tython commands can be found here:
C:/Program Files/UCB/cygwin/opt/tinyos-1.x/doc/tython/javadoc/index.html