⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matlab.html

📁 tinyos中文手册,是根据tinyos系统自带手册翻译过来的,虽然质量不好,但是对英文不强的人还是有用的
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<html><title>TinyOS Tutorial Lesson 8: Data logging application</title></head><body bgcolor="#f8f8ff" link="#005BB7" vlink="#005BB7"><table border=0 hspace=4 cellspacing=2 width="100%" cellpadding=3><tr bgcolor="#e0e0ff"><td width="100%"><font face="tahoma,arial,helvetica"><b><big><big>Using Matlab with TinyOS</big></big></b><p>Last updated 21 Sept 2002</font></td></tr></table><p> This tutorial explains how to interact with a mote or sensor network using Matlab. There are three parts to the tutorial, but the second two are for advanced users.&nbsp; You can focus on the first section, but before you begin, make sure you <a href="#Setting up your Matlab/Java environment">set up</a> your Matlab environment to work with TinyOS.<ol>  <li>The first section explains how to connect to your network to send and   receive packets.</li>  <li>The second part shows you how to use the TinyOS Java tools from Matlab.</li>  <li>The third section explains how to get data out of your Java tools and into your Matlab environment.&nbsp; </li>  </ol><table border=0 hspace=4 cellspacing=2 width="100%" cellpadding=3><tr bgcolor="#e0e0ff"><td width="100%"><b><font face="arial,helvetica">Connecting to the Mote Network</font></b></td></tr></table><h3>Connecting to a port</h3><p>All you need to do is use the connect command.&nbsp; For example:</p><blockquote>  <blockquote><p><b><font face="Courier New">connect('COM1');<br>connect('localhost:9000');</font></b></p>  </blockquote></blockquote><h3>Sending a message to the network</h3><p>First, you need to instantiate a message, which should be a subclass of the net.tinyos.message.Message class.&nbsp; In general, one can use the MIG tool to generate these classes directly from the NesC code (use net.tinyos.oscope.OscopeResetMsg an example).</p><blockquote>  <blockquote><p><b><font face="Courier New">msg=net.tinyos.oscope.OscopeResetMsg<br>send(1, msg)</font></b></p>  </blockquote></blockquote><p>If you have an Oscilloscope mote with moteID 1 and a generic base attached to COM1 or localhost:9000, the Oscilloscope will reset.</p><h3>Receiving messages from the network</h3><p>You need to instantiate a message of the type you want to receive.&nbsp; You also need to create a function that takes two parameters: an address and a message. (Look at tools/matlab/util/printMsg.m as an example).&nbsp; Then, type the following</p><blockquote>  <blockquote><p><b><font face="Courier New">omsg = net.tinyos.oscope.OscopeMsg<br>receive('printMsg', msg);</font></b></p>  </blockquote></blockquote><p>Whenever a message of type msg is received, the printMsg function will be called with the message passed to it as a parameter.&nbsp; Typing the above command right now will cause all OscopeMsg messages to be passed to the printMsg function, which prints them to the screen.&nbsp; If you have an Oscilloscopemote attached to COM1 or localhost:9000, the messages will start appearing on the screen.</p><p>Notice that both the send and receive commands take a port, e.g. COM1 or localhost:9000, as optional third arguments.&nbsp; When this argument is passed, the connect function does not need to be used.&nbsp; Furthermore, the send and receive commands are limited to the ports specified.</p><table border=0 hspace=4 cellspacing=2 width="100%" cellpadding=3><tr bgcolor="#e0e0ff"><td width="100%"><b><font face="arial,helvetica">Using the Java tools from Matlab</font></b></td></tr></table><p>In this part of the tutorial we see how to use Matlab simply as a Java interpreter from which we can use the TinyOS Java tools.&nbsp; There are two parts:</p>  <ol>    <li>An overview of how to use Java from Matlab in general</li>    <li>An example in which we use the Oscilloscope application (i.e.    <a href="lesson6.html">Lesson 6</a>)</li>  </ol><h3><b><font size="4">Overview of the Matlab/Java interface</font></b></h3><p>The following table provides an overview of the Matlab syntax for using Java.&nbsp; It is essentially the same as Java syntax except that there is no &quot;new&quot; operator and functions with no arguments do not terminate with empty parenthesis&nbsp; &quot;( )&quot;.&nbsp; Type these commands into your Matlab command window to see what they do.</p>  <table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="80%" id="AutoNumber1">    <tr>      <td width="100%" align="center" colspan="2" bgcolor="#E0E0FF">Overview of       Matlab syntax for using Java objects</td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Instantiate an Object</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p align="left"><font face="Courier New">f = java.awt.Frame<br>          f = java.awt.Frame(&quot;My Frame&quot;)</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Call a function</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p align="left"><font face="Courier New">f.show<br>          f.resize(500,500)<br>          f.hide</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Call a static function</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote><p align="left"><font face="Courier New">java.awt.Frame.getFrames</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Access public member variable</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p><font face="Courier New">f.WIDTH</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Introsection: class name</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p><font face="Courier New">classname = class(f)</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Introspection: methods</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p><font face="Courier New">methods java.awt.Frame<br>          methods java.awt.Frame -full<br>          methodsview java.awt.Frame</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Introspection: variables</p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p><font face="Courier New">fields(f)</font></p>        </blockquote>      </blockquote>      </td>    </tr>    <tr>      <td width="39%" align="left">      <blockquote>        <p>Import </p>      </blockquote>      </td>      <td width="61%">      <blockquote>        <blockquote>          <p><font face="Courier New">import java.awt.*</font></p>        </blockquote>      </blockquote>      </td>    </tr>  </table><p>Conversion of function parameters and return values are taken care of automatically.&nbsp; Essentially, all primitive types, including strings and arrays, are automatically converted and are passed by value.&nbsp; Java objects are left as Java objects and are passed by reference.&nbsp; Using Java from Matlab is completely supported by Mathworks and is well documented in the the &quot;Matlab/Java interface&quot; section of the Matlab help files.&nbsp; </p><h3>Example: Using Oscilloscope</h3><p>Here, we see an example of using Java tools from Matlab.&nbsp; Before beginning, be sure that </p><ol>  <li>The net.tinyos.oscope Java classes are compiled, including OscopeMsg.java   and OscopeResetMsg.java</li>  <li>A mote  has been programmed with the OscilloscopeRF application  </li>  <li>A GenericBase mote is   plugged into your serial port</li></ol><p>Now, go to your matlab command window.&nbsp; The following two commands will call the static <font face="Courier New">main()</font> functions of the SerialForwarder and Oscilloscope classes. We pass command-line arguments directly to 'main( )' as follows.</p><blockquote>  <blockquote><p><font face="Courier New"><b>net.tinyos.sf.SerialForward.main({'-comm','COM1'})<br>net.tinyos.oscope.oscilloscope.main({'125'})</b></font></p>  </blockquote></blockquote><p>This starts the two applications.&nbsp; After the first command, you should see a SerialForwarder GUI appear and say that it connected to COM1 and is waiting for clients.&nbsp; <font size="1"><a href="../../tools/matlab/doc/tutorial/SerialForwarderProblems.html">What if this didn't happen?</a></font>&nbsp; Then the second command will create the oscilloscope client that will connect to the SerialForwarder, receive packets from it, and plot them on the screen.&nbsp; <font size="1"><a href="file:///E:/My%20Documents/tinyos-1.x/tools/matlab/doc/tutorial/OscilloscopeProblems.html">What if this didn't happen?</a></font>&nbsp;  </p><p>Now, let's inject a message to our Mote.&nbsp; The following commands will  </p>  <ol>    <li>Instantiate a moteIF object and pass parameters to its constructor     telling it to connect to localhost:9000 and listen to group ID 125</li>    <li>Instantiate an &quot;OscopeResetMsg&quot;</li>    <li>Inject that message to our OscilloscopeRF mote, where XX is the node ID of     that mote.&nbsp; </li>  </ol>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -