📄 nido.tex
字号:
Running LossyBuilder will, by default, generate a loss topology for a10 by 10 grid with a grid spacing of five feet (45' by 45'), and printit to standard out. It prints the loss topology in the form that \simexpects. The {\tt -i} option allows you to specify an input file of(x,y) positions, which has the format\begin{verbatim}x yx yx y ...\end{verbatim}\noindent where the coordinate system is in feet. The first (x,y) pairis the position of mote 0, the second is the position of mote 1,etc.For example,\begin{verbatim}java net.tinyos.sim.LossyBuilder -d 20 20 -s 10 -o 20x20-10.nss\end{verbatim}\noindent will output a loss topology of a 20 by 20 grid, withten foot spacing, and write it to the file ``20x20-10.nss''.\subsection{Bit Errors and Packet Errors}The forumula for calculating packet error rates ($E_{p}$) from biterror rates ($E_{b}$) for the mica RFM 40Kb stack with SecDed encodingis:\begin{eqnarray*}&&E_{p} = 1 - (S_{s} \cdot (S_{e})^{d})\\&&S_{s} = (1 - E_{b})^{9}\\&&S_{e} = (1 - E_{b})^{8} + (8 \cdot E_{b} \cdot (1 - E_{b})^{12})\\&&E_{p} = 1 - ((1 - E_{b})^{9} \cdot ((1 - E_{b})^{8} + (8 \cdot E_{b} \cdot (1 - E_{b})^{12}))^{d})\end{eqnarray*}where $S_{s}$ is the start symbol success probability, $S_{e}$ theprobability a packet byte is uncorrupted (zero or one bit errors), and$d$ is the number of bytes in the packet.The simple model can be represented in the lossy model: it is a fullyconnected graph, in which every edge has a loss probability ofzero. However, doing so requires specifying the entire graph to \sim;the simple model is an easy shortcut (and has an internalrepresentation that's more efficient).\subsection{Lossy Model Actuation}Specifying a loss topology with a file defines a static topology overan entire simulation. There are simulation situations, however, inwhich changing topologies are needed. \sim therefore allows users tomodify the loss topology at run-time. Applications can connect to \simover a TCP socket and send control messages to add, delete, or modifynetwork links. Currently, the only application that does so isTinyViz, discussed in Section~\ref{sec:tinyviz}. The TinyViz networkplugins use the same empirical model of LossyBuilder to generate linkloss rates; moving motes causes TinyViz to send the appropriatecommands to \sim.\section{ADC Models}\label{sec:adc}\begin{figure}\centering\includegraphics[width=6.5in]{fig/adc-viz.png}\caption{Setting ADC values in \tinyviz}\label{fig:adc-viz}\end{figure}\sim provides two ADC models: random and generic. The model chosen specifieshow readings taken from the ADC are generated. Whenever any channel inthe ADC is sampled in the random model, it returns a 10-bit randomvalue (the rene and mica ADCs are 10 bits).The general model also provides random values by default, but hasadded functionality. Just as external applications can actuate thelossy network model, they can also actuate the generic ADC model usingthe \sim control channel, setting the value for any ADC port on anymote. Currently, only \tinyviz, (discussed inSection~\ref{sec:tinyviz}) supports this, through the ADCplugin. Left-clicking on a mote selects it; using the ADC panel, youcan set the 10-bit value read from any of the mote's ADCports. Figure~\ref{fig:adc-viz} shows a screenshot of this \tinyvizfunctionality.\section{EEPROM}\label{sec:eeprom}\sim models the EEPROM at the line (16-byte block) level. \sim models itwith a large, memory-mapped file. By default, this file is anonymous,and disappears when a simulation ends. However, with the {\tt -ef}option, a user can specify a named file to use; this allows the EEPROMdata to persist across multiple simulation invocations.\section{\tinyviz}\label{sec:tinyviz}\tinyviz is a Java visualization and actuation environment for\sim. The main \tinyviz class is a jar file,{\tt tools/java/net/tinyos/sim/tinyviz.jar}. \tinyviz can be attachedto a running simulation. Also, \sim can be made to wait for \tinyvizto connect before it starts up, with the {\tt -gui} flag. This allowsusers to be sure that \tinyviz captures all of the events in a givensimulation.\tinyviz is not actually a visualizer; instead, it is a framework inwhich plugins can provide desired functionality. By itself, \tinyvizdoes little besides draw motes and their LEDs. However, it comes witha few example plugins, such as one that visualizes network traffic.\begin{figure}\centering\includegraphics[width=6.5in]{fig/tinyviz.png}\caption{\tinyviz connected to \sim running an object trackingapplication. The right panel shows sent radio packets, the left panelexhibits radio connectivity for \mote 15 and network traffic. Thegreen arrows and corresponding labels represent link probabilities for\mote 15, and the magenta arrows indicate packet transmission.}\label{fig:tinyviz}\end{figure}Figure~\ref{fig:tinyviz} shows a screenshot of the \tinyviz tool. Theleft window contains the simulation visualization, showing 16 \motescommunicating in an ad-hoc network. The right window is the pluginwindow; each plugin is a tab pane, with configuration controls anddata.The second element on the top bar is the {\bf Plugin} menu, foractivating or de-activating individual plugins. Inactive plugins havetheir tab panes greyed out.The third element is the layout menu, which allows you to arrangemotes in specific topologies, as well as save or restoretopologies. \tinyviz can use physical topologies to generate networktopologies by sending messages to \sim that configure networkconnectivity and the loss rate of individual links.The right side of the top bar has three buttons and a slider. \tinyvizcan slow a simulation by introducing delays when it handles eventsfrom \sim. The slider configures how long delays are. The On/Offbutton turns selected motes on and off; this can be used to reboot anetwork, or dynamically change its members. The button to the right ofthe slider starts and stops a simulation; unlike the delays, which arefor short, fixed periods, this button can be used to pause asimulation for arbitrary periods. The final button, on the far right,enables and disables a grid in the visualization area. The small textbar on the bottom of the right panel displays whether the simulationis running or paused.The \tinyviz engine uses an event-driven model, which allows easymapping between TinyOS' event-based execution and event-drivenGUIs. By itself, the application does very little; drop-in pluginsprovide user functionality. \tinyviz has an event bus, which readsevents from a simulation and publishes them to all active plugins.\subsection{\tinyviz Plugins}\label{sec:plugins}Users can write new plugins, which \tinyviz can dynamically load. Asimple event bus sits in the center of \tinyviz; simulator messagessent to \tinyviz appear as events, which any plugin can respondto. For example, when a mote transmits a packet in \sim, the simulatorsends a packet send message to \tinyviz, which generates a packet sendevent and broadcasts it on the event bus. A networking plugin canlisten for packet send events and update \tinyviz node state and drawan animation of the communication.Plugins can be dynamically registered and deregistered, whichcorrespondingly connect and disconnect the plugin from the eventbus. A plugin hears all events sent to the event bus, but individuallydecides whether to do anything in response to a specific event; thiskeeps the event bus simple, instead of having a content-specificsubscription mechanism.A plugin must be a subclass of {\tt net.tinyos.sim.Plugin}. {\ttPlugin} has the following signature:\begin{verbatim}public abstract class Plugin { public Plugin() {} public void initialize(TinyViz viz, JPanel pluginPanel) {...} public void register() {...} public void reset() { /* do nothing */} public abstract void deregister(); public abstract void draw(Graphics graphics); public abstract void handleEvent(SimEvent event);}\end{verbatim}Plugins register themselves with the \tinyviz event bus, which thennotifies them of all events coming in from TOSSIM; it is up to anindividual plugin whether to do something. The {\tt draw} method isused to draw visualizations in the left pane of the TinyViz window.\section{Using {\tt gdb}}The binary executable produced by typing {\tt make pc} in any appdirectory can be debugged using GDB. Developers of TinyOS code canstep through programs they have written, debugging deterministic,logical aspects of their code before loading programs onto motes.When accessing variables and functions in \sim under GDB, specificprefixes precede them, to distinguish variables from differentcomponents that have ths same name. The nesC compiler takes eachcomponent's fields and functions and renames them with uniqueidentifiers. This renaming for fields of a component is done by takingthe field name, and preceding it by the component name and a {\tt \$}sign. Functions are renamed by taking the name of the function andpreceding it by the name of the component it is defined in, followedby a {\tt \$} sign, followed by the interface name, followed byanother {\tt \$} sign.The maximum number of nodes that can be simulated is determined atcompile time. This value, as mentioned in section {\tt \simArchitecture} specifies the size of the array for each component'sfields during code generation of the compilation process. Whencompiling for the {\tt pc}, each declaration of a component field isfollowed by {\tt [}, the value of {\tt tossim\_num\_nodes}, and {\tt]}, where tossim\_num\_nodes is specified by the flag {\tt-fnesc-tossim\_tosnodes=} in {\tt Makerules}, or by default, set to1000. This is the way \sim simulates multiple motes. \sim keeps anarray for each variable of state, and references each mote'scorresponding state when running code for that mote.During code generation for the {\tt pc}, all references to componentfields are followed by {\tt [}, {\tt tos\_state.current\_node} and{\tt ]}, where {\tt tos\_state.current\_node} refers to the moteID ofthe mote \sim is currently executing code for.For, for example, the {\tt Counter} component has a variable named{\tt state} of type {\tt uint\_16t}. This translates to the C name{\tt Counter\$state}. When compiled for \sim, it becomes {\ttuint16\_t Counter\$state[MAX\_NODES]}. If a component has a variablethat's an array (e.g., {\tt uint8\_t buffer[8]}, it becomes an array ofarrays (e.g., {\tt uint8\_t buffer[8][MAX\_NODES]}). Laying out modulevariables in this way means that overrun and underrun bugs will havedifferent effects on real motes and in TOSSIM. On a real mote, such abug will corrupt that mote's state; in TOSSIM, it will corrupt othermotes' state.Using the application {\tt Blink} as an example, type {\tt make pc} inthe {\tt /apps/Blink/} directory to compile the application for\sim. Run {\tt gdb} on the executable produced by typing {\tt gdbbuild/pc/main.exe}. Examining {\tt BlinkM.td}, to break at thefunction Clock.fire(), type {\tt break *BlinkM\$Clock\$fire}. {\ttbreak} (or {\tt b}) specifies a breakpoint in GDB, and the {\tt *}tells the GDB command line parser to examine the entire block of textfollowing it as a single expression. It is currently necessary tospecify the {\tt *} before the function name for GDB to parse itproperly. {\tt BlinkM} denotes the component the function is definedin, and {\tt Clock} specifies the interface the function {\tt fire}belongs to.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -