📄 lesson5.html
字号:
for testing the Calamari localization service -- but many of them are generallyuseful.<p>Plugins can be selectively enabled or disabled, depending on what informationyou are interested in seeing during the simulation. You select pluginsfrom the <tt>Plugins</tt> menu. When a plugin is enabled, its correspondingtab in the right-hand control panel window is active, which may have additionalinformation and controls provided by that plugin. Plugins are designedto be independent of each other so you can enable or disable any groupof plugins you like.<p>The main plugins you are likely to use are:<ul><li><b>Debug messages:</b> Shows a window with all of the debug messages generatedby the simulation. You can select debug messages just from the selectedgroup of motes, and also highlight messages that match a certain pattern.Note that the set of debug messages you see are controlled by the valueof the <tt>DBG</tt> environment variable, just as they are when runningTOSSIM in a stand-alone setting. So, if you only want to see debug messagesof type <tt>DBG_USR1</tt> and<tt>DBG_AM</tt>, start up TinyViz with:</li><center><table BORDER=0 CELLSPACING=2 CELLPADDING=3 WIDTH="80%" hspace="4" ><tr BGCOLOR="#E0E0E0"><td WIDTH="100%"><pre><tt>DBG=usr1,am tinyviz -run build/pc/main.exe 30</tt></pre></td></tr></table></center><li><b>Set breakpoint:</b> Allows you to set a breakpoint, which will pausethe simulation when some condition is met. Right now, the possible conditionsare (a) a substring match on a debug message, or (b) a match on the contentsof a sent radio message. Multiple breakpoints can be set and they can beenabled or disabled by selecting them in the breakpoints list.</li><li><b>ADC readings:</b> Shows the most recent value of each ADC channel nextto each mote.</li><li><b>Sent radio packets:</b> Shows a window with all sent radio packets,much like the <b>Debug messages</b> plugin. Note that the<b>Debug messages</b>plugin also shows this information.</li><li><b>Radio links:</b> Graphically displays radio message activity. When amote broadcasts a message, a blue circle will be drawn around it. Whena mote sends a message to another mote, a directed arrow will be drawnbetween the two motes. Note that this shows all message transmissions,regardless of whether they are successful; if a mote attempts to send amessage but it is corrupted or lost, the arrow will still be drawn.</li><li><b>Set location:</b> Makes the virtual location of each mote availableto that mote through the <tt>Location</tt> interface, found in<tt><a href="../../apps/TestTinyViz/Location.nc">apps/TestTinyViz/Location.nc</a></tt>.This is accomplished by setting the value of three "fake" ADC channels(one each for X, Y, and Z coordinates) on each mote, which the <tt>FakeLocation</tt>component reads to determine the mote's virtual location. This is meantto act as a stand-in for a real localization service when simulating TinyOSapps.</li><li><b>Radio model</b>: Sets the bit error rate between motes according totheir location and various models of radio connectivity. Enabling thisplugin allows you to use realistic connectivity models in your simulations.There are two built-in models: "Empirical" (based on an outdoor trace ofpacket connectivity with the RFM1000 radios) and "Fixed radius" (all moteswithin a given fixed distance of each other have perfect connectivity,and no connectivity to other motes). Setting the "scaling factor" in thecontrol panel simply scales the distance parameter of the model. <b>Increasing</b>the scaling factor will <b>decrease</b> the connectivity range of the chosenmodel. By selecting a mote in the display you can see its connectivityto other motes -- the number shown next to each edge is the probabilityof a packet getting through. Changing the scaling factor and clicking "updatemodel" will update the model parameters, as will moving motes around inthe display.</li></ul><b>Layout</b><p>Layout of the motes is controlled by the <tt>Layout</tt> menu, whichgives you several options including random, grid-based, or a "grid+random"(grid-based but with a random perturbation) layout. You can also save andload layouts from a file. The location of the motes on the display is usedin two ways. First, it is used to determine radio connectivity, when the<tt>RadioModelPlugin</tt>is enabled. Second, it is used to set the virtual location of the motes,when using the <tt>LocationPlugin</tt>.<p><b>Trying it out</b><p>OK, now we're ready to try out the various features.<ol><li>Startup TinyViz with <tt>DBG=usr1, tinyviz -run build/pc/main.exe 30</tt>if it is not already running.</li><li>Select the <b>Debug messages</b>, <b>Radio links</b>, and <b>Set breakpoint</b>plugins from the Plugins menu, and resume the simulation by clicking thepause/play button.</li><li>Clicking on the <b>Debug messages</b> tab in the control panel will showyou all of the debug messages generated by the simulation. Click on a givenmote (say, mote 3) then click "Selected motes only" to restrict the displayto just that mote.</li><li>Type a phrase (for example, "Received") in the box at the bottom of thecontrol panel, then click "Highlight". This will highlight all messagesmatching the chosen string - very useful for visually scanning for "interesting"messages.</li><li>Pause the simulation, then click on the "Set breakpoint" tab. Pull downthe bar at the top of the control panel (which says "Current breakpoints")and choose "Add debug message breakpoint". In the "Message contains" box,type "Received message", then click "Enable breakpoint". This will adda new breakpoint that pauses the simulation whenever a matching debug messageis printed. Click on the pause/play button to resume the simulation. Verysoon afterwards, the simulation will pause and the control panel at thebottom of the screen will print something like</li><pre>Breakpoint 0 fired: Debug message: [24] DebugMsgEvent [24: TestTinyVizM: Received message from 13]</pre>which simply means that this debug message triggered the breakpoint. Clickingthe play button again will resume the simulation, causing the breakpointto be hit again.<li>Select "Current breakpoints" from the bar at the top of the control panel.Disable the breakpoint by clicking on it in the breakpoints list, thenclick "Disable breakpoint".</li><li>Select the <b>Radio model</b> plugin from the Plugins menu and click onthe "Radio model" tab in the control panel, then pick "Fixed radius (100.0)"from the list of radio models. Drag the mouse across the mote display toselect all motes; you will see a very densely-connected mesh, indicatingthat nearly every mote has connectivity with all others, due to the largeradius of the radio model. Type "4" in the "Distance scaling factor" box,then click "Update model". The radio model will be updated -- which maytake some time -- and the resulting connectivity mesh will be much moresparse.</li><br> <p> <p>Note that once you restart the simulation, nodes that can no longercommunicate (due to no connectivity) will still be sending messages toeach other; this is because the <tt>TestTinyViz</tt> application accumulatesa list of nodes to send messages to, but changing the underlying connectivitymodel does not modify this list. <i>However,</i> if you watch the debugmessages from each node, you will notice that nodes are only <b>receiving</b>messages from those nodes they are connected to, as you would expect.</ol><b>AutoRun - Scripting TOSSIM runs</b><p>The TinyViz <b>AutoRun</b> feature allows you to "script" the configurationand execution of a TinyOS simulation, by setting parameters in a file thatcontrols TinyViz. This allows you to automatically enable plugins, setbreakpoints, run multiple simulations, log data to files, and execute commandsboth before and after each simulation runs. This is useful when you areusing TinyViz as an analysis tool.<p>Look at the file <tt><a href="../../apps/TestTinyViz/sample.autorun">apps/TestTinyViz/sample.autorun</a></tt>in the <tt>TestTinyViz</tt> directory. The autorun file specifies one ormore simulations to run; a simulation stops either when a specified numberof simulated seconds have elapsed (the "<tt>numsec</tt>" option), whena substring match on a debug message occurs (the "<tt>stopstring</tt>"option), or when the simulation exits itself (e.g., a crash or deliberatecall to <tt>exit()</tt>). The parameters for each simulation are separatedby a blank line. When a parameter is set in the file for one simulation,it will carry forward for subsequent simulations in the file, saving youfrom having to re-specify parameters for each run.<p>Here is the sample file:<center><table BORDER=0 CELLSPACING=2 CELLPADDING=3 WIDTH="80%" hspace="4" ><tr BGCOLOR="#E0E0E0"><td WIDTH="100%"><pre><tt># This is a sample TinyViz autorun file. To use it, run# tinyviz -autorun sample.autorun# Set the layoutlayout gridrandom# Enable some pluginsplugin DebugMsgPluginplugin RadioLinkPluginplugin RadioModelPlugin# Total number of simulated seconds to runnumsec 20# Name of the executable fileexecutable build/pc/main.exe# DBG messages to includedbg usr1# The radio model and scaling factor to useradiomodel disc100radioscaling 5# Number of motesnummotes 10# Command to run before startingprecmd echo "This is a command that will run before the simulation"# File to log all DBG messages tologfile logfile-20.txt# The blank line above indicates that we are starting another simulation# This time run with a different number of motesnummotes 30logfile logfile-30.txt</tt></pre></td></tr></table></center><p>The AutoRun file specifies two simulations, one with 20 motes and anotherwith 30. All debug messages are logged to two different logfiles. We enablea few different plugins (specified by the Java class names as they arefound in <tt>tools/java/net/tinyos/sim/plugins</tt>.<p>To run the simulations with this autorun file, just type:<center><table BORDER=0 CELLSPACING=2 CELLPADDING=3 WIDTH="80%" hspace="4" ><tr BGCOLOR="#E0E0E0"><td WIDTH="100%"><pre><tt>tinyviz -autorun sample.autorun</tt></pre></td></tr></table></center><p>TinyViz starts up, enables and configures the appropriate plugins, andautomatically runs each simulation for 10 simulated seconds, then exits.You can set up AutoRun to run a series of simulations and then go to lunch-- the data will be waiting for you in your logfiles when you get back.<p>AutoRun supports a number of features not shown here -- just look atthe <tt>arConfig</tt> class in the<tt><a href="../../tools/java/net/tinyos/sim/AutoRun.java">tools/java/net/tinyos/sim/AutoRun.java</a></tt>sourcefile. Note that all options specified in the file that aren't used by AutoRunitself, however they made available to plugins. So, for example, the <tt>radiomodel</tt>option is interpreted by the<tt>RadioModelPlugin</tt> to configure theradio model. You can write your own plugins that are configured throughAutoRun in this way.<p><b>Writing TinyViz plugins</b><p>By far the most useful feature of TinyViz is the ability to write yourown plugins to interact with the simulation. Writing plugins is beyondthe scope of this document, but we wanted to give you a couple of pointerson where to start. Look at <tt><a href="../../tools/java/net/tinyos/sim/plugins/RadioLinkPlugin.java">tools/java/net/tinyos/sim/plugins/RadioLinkPlugin.java</a></tt>fora simple, well-documented plugin implementation. Essentially, plugins mustprovide a method that receives events from the TOSSIM simulation and theTinyViz framework. Plugins react to events by changing internal state,updating the display, or possibly sending commands back into the simulation.TinyViz delivers events to plugins for initialization, debug messages,radio messages, a change in the location of a mote (e.g., when the usermoves it), and when new motes join the simulation. Plugins provide additionalmethods that are called when the plugin is enabled or disabled, as wellas when the mote window is redrawn.<p>Using <tt>RadioLinkPlugin.java</tt> as an example, it is straightforwardto write your own plugins. Currently, all plugins must be located in the<tt>plugins</tt>subdirectory of the TinyViz directory. (In the future we will add supportfor a "plugin path"). Note that when you modify a plugin you need to recompilethe <tt>tinyviz.jar</tt> file by typing<tt>make </tt>in the main TinyVizdirectory (tools/java/net/tinyos/sim); just typing <tt>make</tt> in theplugins directory is not adequate.<br> <table BORDER=0 CELLSPACING=2 CELLPADDING=3 WIDTH="100%" hspace="4" ><tr BGCOLOR="#E0E0FF"><td WIDTH="100%"><b><nobr><font face="arial,helvetica">Further Use</font></nobr></b></td></tr></table><p>This tutorial only covers some of the functionality and usefulness ofTOSSIM; for example, as TOSSIM simulates the TinyOS networking stack atbit granularity, radio models can simulate some of the difficult issuesthat arise. Similarly, one can test and debug low-level protocols (suchas start symbol detection) in addition to application components and routingprotocols. The <a href="../nido.pdf">TOSSIM System Description</a> goesinto greater details on these capabilities and presents some informationon TOSSIM's implementation.<p><b><a href="lesson4.html">< Previous Lesson</a></b> |<b><a href="lesson6.html">NextLesson ></a></b> | <b><a href="index.html">Top</a></b></body></html><!-- LocalWords: TinyOS nesC nc async norace BlinkM FooM ncc SingleTimer Leds --><!-- LocalWords: LedsC StdControl tos init TimerC redOn redOff uint redToggle --><!-- LocalWords: metadata html nesdoc gcc exe avr objcopy srec uisp mib dprog --><!-- LocalWords: towards dapa xff ThinkPad dlpt Makelocal micasb Wshadow DDEF --><!-- LocalWords: finline fnesc cfile lm Atmel ATmega nesC's nesc SenseM rdata --><!-- LocalWords: ADCControl SounderControl dataReady getData rcombine someval --><!-- LocalWords: ADControl fooControl barControl MyTimer uniqueCount basicsb --><!-- LocalWords: sensorboard Makerules sensorboards SenseTask taskname INTMSG --><!-- LocalWords: SenseTaskM putdata processData CntToLedsAndRfm RfmToLeds Msg --><!-- LocalWords: CntToRfmAndLeds IntToLeds IntToRfm IntOutput outputComplete --><!-- LocalWords: IntToRfmM GenericComm SendMsg bool struct IntMsg src BCAST --><!-- LocalWords: ADDR sizeof TOSH sendDone GenricComm AMStandard RfmToInt pc --><!-- LocalWords: UARTNoCRCPacket RadioCRCPacket ActiveMessage RfmToIntM xfff --><!-- LocalWords: ReceiveIntMsg ReceiveMsg MsgPtr addr SenseToRfm TOSSIM DBG --><!-- LocalWords: TinyViz ffff crc usr dbg const printf prepended bitmask gdb --><!-- LocalWords: ledsOn gdbinit plugin API TestTinyViz cd tinyviz plugins RFM --><!-- LocalWords: FakeLocation RadioModelPlugin LocationPlugin afterwards disc --><!-- LocalWords: DebugMsgEvent TestTinyVizM AutoRun autorun numsec stopstring --><!-- LocalWords: gridrandom DebugMsgPlugin RadioLinkPlugin radiomodel precmd --><!-- LocalWords: radioscaling nummotes logfile txt logfiles arConfig TOSSIM's -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -