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

📄 mote-pc serial communication and serialforwarder - tinyos documentation wiki.htm

📁 从官方网站上下载tinyos2.0的学习指南
💻 HTM
📖 第 1 页 / 共 3 页
字号:
and lets many applications connect to it over a TCP/IP stream in order to use 
that source. For example, you can run a SerialForwarder whose packet source is 
the serial port; instead of connecting to the serial port directly, applications 
connect to the SerialForwarder, which acts as a proxy to read and write packets. 
Since applications connect to SerialForwarder over TCP/IP, applications can 
connect over the Internet. </P>
<P>SerialForwarder is the second kind of packet source. A SerialForwarder source 
has this syntax: </P><PRE>sf@HOST:PORT
</PRE>
<P>HOST and PORT are optional: they default to localhost (the local machine) and 
9002. For example, </P><PRE>sf@dark.cs.berkeley.edu:1948
</PRE>
<P>will connect to a SerialForwarder running on the computer 
dark.cs.berkeley.edu and port 1948. </P>
<P>The first step is to run a SerialForwarder; since it takes one packet source 
and exports it as an sf source, it takes a packet source parameter just like the 
other tools we've used so far: you can pass a -comm parameter, use MOTECOM, or 
just rely on the default. Close your MsgReader application so that it no longer 
uses the serial port, and run a SerialForwarder: </P><PRE>java net.tinyos.sf.SerialForwarder
</PRE>
<P>You should see a window like this pop up: </P>
<CENTER>
<P><A class=image title=Image:SerialForwarder.gif 
href="http://docs.tinyos.net/index.php/Image:SerialForwarder.gif"><IMG 
height=300 alt=Image:SerialForwarder.gif 
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/SerialForwarder.gif" 
width=500 border=0></A> </P></CENTER>
<P>Since SerialForwarder takes any packet source as its source, you can even 
string SerialForwaders along: </P><PRE>java net.tinyos.sf.SerialForwarder -port 9003 -comm sf@localhost:9002
</PRE>
<P>This command opens a second SerialForwarder, whose source is the first 
SerialForwarder. You'll see that the client count of the first one has increased 
to one. It's rare that you'd ever want to do this, but it demonstrates that in 
the message support libraries you can use a variety of packet sources. </P>
<P>Close the second SerialForwarder (the one listening on port 9003). Run 
MsgReader again, but this time tell it to connect to your SerialForwarder: </P><PRE>java net.tinyos.tools.MsgReader -comm sf@localhost:9002 BlinkToRadioMsg
</PRE>
<P>You will see the client count increment, and MsgReader will start printing 
out packets. </P><A name=Packet_Sources></A>
<H2><SPAN class=mw-headline>Packet Sources</SPAN></H2>
<P>In addition to serial ports and SerialForwarders, the TinyOS messaging 
library supports a third packet source, motes which are connected to an ethernet 
port through a Crossbow MIB 600 ethernet board. This is the full set of packet 
sources: <BR></P>
<CENTER>
<TABLE>
  <TBODY>
  <TR>
    <TD><B>Syntax</B> </TD>
    <TD><B>Source</B> </TD></TR>
  <TR>
    <TD>serial@PORT:SPEED </TD>
    <TD>Serial ports </TD></TR>
  <TR>
    <TD>sf@HOST:PORT </TD>
    <TD>SerialForwarder, TMote Connect </TD></TR>
  <TR>
    <TD>network@HOST:PORT </TD>
    <TD>MIB 600 </TD></TR></TBODY></TABLE></CENTER>
<P>In the <CODE>network</CODE> packet source, the default MIB 600 port is 10002. 
The Moteiv TMote Connect appliance is a SerialForwarder packet source. </P><A 
name=The_tool_side></A>
<H2><SPAN class=mw-headline>The tool side</SPAN></H2>
<P>Code for the Java messaging toolchain lives in two java packages: 
<CODE>net.tinyos.message</CODE> and <CODE>net.tinyos.packet</CODE>. The 
<CODE>packet</CODE> package contains all of the code for packet sources and 
their protocols: it is what reads and writes bytes. The <CODE>message</CODE> 
package is what turns streams of bytes into meaningful messages and provides 
packet source independent classes for communicating with motes. </P>
<P>The key class for sending and receiving packets is <CODE>MoteIF</CODE>. It 
has methods for registering packet listeners (callbacks when a packet arrives) 
and sending packets. The tools <CODE>MsgReader</CODE>, <CODE>Listen</CODE>, and 
<CODE>Send</CODE> are good places to start to learn how to get Java applications 
to communicate with motes. </P>
<P>There is also support for python and C. </P><A 
name=Sending_a_packet_to_the_serial_port_in_TinyOS></A>
<H1><SPAN class=mw-headline>Sending a packet to the serial port in 
TinyOS</SPAN></H1>
<P>Sending an AM packet to the serial port in TinyOS is very much like sending 
it to the radio. A component uses the AMSend interface, calls 
<CODE>AMSend.send</CODE>, and handles <CODE>AMSend.sendDone</CODE>. The serial 
stack will send it over the serial port regardless of the AM address specified. 
</P>
<P>The TinyOS serial stack follows the same programming model as the radio 
stack. There is a <CODE>SerialActiveMessageC</CODE> for turning the stack on and 
off (mote processors often cannot enter their lowest power state while the 
serial stack is on), and generic components for sending and receiving packets. 
As the serial stack is a dedicated link, however, it does not provide a snooping 
interface, and it does not filter based on the destination address of the 
packet. These are the serial communication components and their radio analogues: 
</P>
<CENTER>
<TABLE cellSpacing=4 cellPadding=2>
  <TBODY>
  <TR align=middle>
    <TD bgColor=#d0d0d0><B>Serial</B> </TD>
    <TD bgColor=#d0d0ff><B>Radio</B> </TD></TR>
  <TR>
    <TD bgColor=#d0d0d0>SerialActiveMessageC </TD>
    <TD bgColor=#d0d0ff>ActiveMessageC </TD></TR>
  <TR>
    <TD bgColor=#d0d0d0>SerialAMSenderC </TD>
    <TD bgColor=#d0d0ff>AMSenderC </TD></TR>
  <TR>
    <TD bgColor=#d0d0d0>SerialAMReceiverC </TD>
    <TD bgColor=#d0d0ff>AMReceiverC </TD></TR></TBODY></TABLE></CENTER>
<P>Because serial AM communication has the same interfaces as radio AM 
communication, you can in most situations use them interchangably. For example, 
to make BlinkToRadio send packets to the serial port rather than the radio, all 
you have to do is change the BlinkToRadioAppC configuration: </P>
<CENTER>
<TABLE>
  <TBODY>
  <TR>
    <TD><B>Radio</B> </TD>
    <TD><B>Serial</B> </TD></TR>
  <TR>
    <TD><PRE>  components ActiveMessageC;
  components new AMSenderC(AM_BLINKTORADIOMSG);

  BlinkToRadioC.AMSend -&gt; AMSenderC;
  BlinkToRadioC.AMControl -&gt; ActiveMessageC;
</PRE></TD>
    <TD><PRE>  components SerialActiveMessageC;
  components new SerialAMSenderC(AM_BLINKTORADIOMSG);

  BlinkToRadioC.AMSend -&gt; SerialAMSenderC;
  BlinkToRadioC.AMControl -&gt; SerialActiveMessageC;
</PRE></TD></TR></TBODY></TABLE></CENTER>
<HR>

<P>Now, rather than have BlinkToRadio send packets which a BaseStation recieves 
and forwards to the serial port, the application will send them directly to a 
serial port. Connect a MsgReader to test that this is happening. Note that the 
binary code and data size has changed significantly, as nesC has included the 
serial stack rather than the radio stack. </P><A name=Related_Documentation></A>
<H1><SPAN class=mw-headline>Related Documentation</SPAN></H1>
<UL>
  <LI><A class="external text" 
  title=http://www.tinyos.net/tinyos-2.x/doc/html/tep113.html 
  href="http://www.tinyos.net/tinyos-2.x/doc/html/tep113.html" rel=nofollow>TEP 
  113: Serial Communication</A> 
  <LI><CODE>mig</CODE> man page 
  <LI><CODE>ncg</CODE> man page 
  <LI>javadoc documentation for the net.tinyos.packet and net.tinyos.message 
  packages </LI></UL>
<CENTER>
<P>&lt; <B><A title="Mote-mote radio communication" 
href="http://docs.tinyos.net/index.php/Mote-mote_radio_communication">Previous 
Lesson</A></B> | <B><A title="Mote-PC serial communication and SerialForwarder" 
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#Packet_sources_and_TestSerial">Top</A></B> 
| <B><A title=Sensing href="http://docs.tinyos.net/index.php/Sensing">Next 
Lesson</A> &gt;</B> </P></CENTER><A name=CLASSPATH_and_Java_classes></A>
<H1><SPAN class=mw-headline>CLASSPATH and Java classes</SPAN></H1>
<P>Note that the CLASSPATH variable points to <TT>tinyos.jar</TT>. This means 
that when Java looks for classes to load, it looks in tinyos.jar rather than the 
Java directories in <TT>support/sdk/java</TT>. Therefore, if you change and 
recompile the Java classes, you will not see the changes, as Java will only look 
at the jar file. To regenerate the jar from the Java code, go to 
<TT>support/sdk/java</TT> and type <TT>make tinyos.jar</TT>. </P><!-- Saved in parser cache with key tinyosdocs:pcache:idhash:10-0!1!0!!en!2!edit=0 and timestamp 20080401155141 -->
<DIV class=printfooter>Retrieved from "<A 
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder">http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder</A>"</DIV><!-- end content -->
<DIV class=visualClear></DIV></DIV></DIV></DIV>
<DIV id=column-one>
<DIV class=portlet id=p-cactions>
<H5>Views</H5>
<DIV class=pBody>
<UL>
  <LI class=selected id=ca-nstab-main><A title="View the content page [c]" 
  accessKey=c 
  href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder">Article</A> 

  <LI class=new id=ca-talk><A title="Discussion about the content page [t]" 
  accessKey=t 
  href="http://docs.tinyos.net/index.php?title=Talk:Mote-PC_serial_communication_and_SerialForwarder&amp;action=edit">Discussion</A> 

  <LI id=ca-viewsource><A 
  title="This page is protected. You can view its source. [e]" accessKey=e 
  href="http://docs.tinyos.net/index.php?title=Mote-PC_serial_communication_and_SerialForwarder&amp;action=edit">View 
  source</A> 
  <LI id=ca-history><A title="Past versions of this page. [h]" accessKey=h 
  href="http://docs.tinyos.net/index.php?title=Mote-PC_serial_communication_and_SerialForwarder&amp;action=history">History</A> 
  </LI></UL></DIV></DIV>
<DIV class=portlet id=p-personal>
<H5>Personal tools</H5>
<DIV class=pBody>
<UL>
  <LI id=pt-login><A 
  title="You are encouraged to log in, it is not mandatory however. [o]" 
  accessKey=o 
  href="http://docs.tinyos.net/index.php?title=Special:Userlogin&amp;returnto=Mote-PC_serial_communication_and_SerialForwarder">Log 
  in / create account</A> </LI></UL></DIV></DIV>
<DIV class=portlet id=p-logo><A title="Visit the Main Page [z]" 
style="BACKGROUND-IMAGE: url(/images/tos-jwall-small.jpg)" accessKey=z 
href="http://docs.tinyos.net/index.php/Main_Page"></A></DIV>
<SCRIPT type=text/javascript> if (window.isMSIE55) fixalpha(); </SCRIPT>

<DIV class=portlet id=p-navigation>
<H5>Navigation</H5>
<DIV class=pBody>
<UL>
  <LI id=n-mainpage><A title="Visit the Main Page [z]" accessKey=z 
  href="http://docs.tinyos.net/index.php/Main_Page">Main Page</A> 
  <LI id=n-portal><A 
  title="About the project, what you can do, where to find things" 
  href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Community_Portal">Community 
  portal</A> 
  <LI id=n-currentevents><A 
  title="Find background information on current events" 
  href="http://docs.tinyos.net/index.php/Current_events">Current events</A> 
  <LI id=n-recentchanges><A title="The list of recent changes in the wiki. [r]" 
  accessKey=r 
  href="http://docs.tinyos.net/index.php/Special:Recentchanges">Recent 
  changes</A> 
  <LI id=n-randompage><A title="Load a random page [x]" accessKey=x 
  href="http://docs.tinyos.net/index.php/Special:Random">Random page</A> 
  <LI id=n-help><A title="The place to find out." 
  href="http://docs.tinyos.net/index.php/Help:Contents">Help</A> 
  <LI id=n-sitesupport><A title="Support us" 
  href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Site_support">Donations</A> 
  </LI></UL></DIV></DIV>
<DIV class=portlet id=p-search>
<H5><LABEL for=searchInput>Search</LABEL></H5>
<DIV class=pBody id=searchBody>
<FORM id=searchform action=/index.php/Special:Search>
<DIV><INPUT id=searchInput title="Search TinyOS Documentation Wiki [f]" 
accessKey=f name=search> <INPUT class=searchButton id=searchGoButton type=submit value=Go name=go>&nbsp; <INPUT class=searchButton id=mw-searchButton type=submit value=Search name=fulltext> 
</DIV></FORM></DIV></DIV>
<DIV class=portlet id=p-tb>
<H5>Toolbox</H5>
<DIV class=pBody>
<UL>
  <LI id=t-whatlinkshere><A title="List of all wiki pages that link here [j]" 
  accessKey=j 
  href="http://docs.tinyos.net/index.php/Special:Whatlinkshere/Mote-PC_serial_communication_and_SerialForwarder">What 
  links here</A> 
  <LI id=t-recentchangeslinked><A 
  title="Recent changes in pages linked from this page [k]" accessKey=k 
  href="http://docs.tinyos.net/index.php/Special:Recentchangeslinked/Mote-PC_serial_communication_and_SerialForwarder">Related 
  changes</A> 
  <LI id=t-upload><A title="Upload images or media files [u]" accessKey=u 
  href="http://docs.tinyos.net/index.php/Special:Upload">Upload file</A> 
  <LI id=t-specialpages><A title="List of all special pages [q]" accessKey=q 
  href="http://docs.tinyos.net/index.php/Special:Specialpages">Special pages</A> 

  <LI id=t-print><A title="Printable version of this page [p]" accessKey=p 
  href="http://docs.tinyos.net/index.php?title=Mote-PC_serial_communication_and_SerialForwarder&amp;printable=yes">Printable 
  version</A> 
  <LI id=t-permalink><A title="Permanent link to this version of the page" 
  href="http://docs.tinyos.net/index.php?title=Mote-PC_serial_communication_and_SerialForwarder&amp;oldid=273">Permanent 
  link</A> </LI></UL></DIV></DIV></DIV><!-- end of the left (by default at least) column -->
<DIV class=visualClear></DIV>
<DIV id=footer>
<DIV id=f-poweredbyico><A href="http://www.mediawiki.org/"><IMG 
alt="Powered by MediaWiki" 
src="Mote-PC serial communication and SerialForwarder - TinyOS Documentation Wiki.files/poweredby_mediawiki_88x31.png"></A></DIV>
<UL id=f-list>
  <LI id=lastmod>This page was last modified 16:23, 28 December 2007. 
  <LI id=viewcount>This page has been accessed 1,956 times. 
  <LI id=privacy><A title="TinyOS Documentation Wiki:Privacy policy" 
  href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:Privacy_policy">Privacy 
  policy</A> 
  <LI id=about><A title="TinyOS Documentation Wiki:About" 
  href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:About">About 
  TinyOS Documentation Wiki</A> 
  <LI id=disclaimer><A title="TinyOS Documentation Wiki:General disclaimer" 
  href="http://docs.tinyos.net/index.php/TinyOS_Documentation_Wiki:General_disclaimer">Disclaimers</A> 
  </LI></UL></DIV>
<SCRIPT type=text/javascript>if (window.runOnloadHook) runOnloadHook();</SCRIPT>
</DIV><!-- Served in 0.327 secs. --></BODY></HTML>

⌨️ 快捷键说明

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