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

📄 the tinyos printf library - tinyos documentation wiki.htm

📁 从官方网站上下载tinyos2.0的学习指南
💻 HTM
📖 第 1 页 / 共 2 页
字号:
for detailed instructions. </P>
<P>To install the application on the mote, run the following set of commands. 
</P><PRE>cd $TOSROOT\apps\tests\TestPrintf
make telosb install bsl,/dev/ttyUSBXXX
</PRE>
<P>You will notice during the installation process that a pair of java files are 
compiled along with the TinyOS application. The first java file, 
<CODE>PrintfMsg.java</CODE>, is generated by <CODE>mig</CODE> to encapsulate a 
TinyOS <CODE>printf</CODE> message received over the serial line (for more 
information on mig and how it generates these files, please refer to the section 
entitled <A title="Mote-PC serial communication and SerialForwarder" 
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder#MIG:_generating_packet_objects">"MIG: 
generating packet objects"</A> in <A 
title="Mote-PC serial communication and SerialForwarder" 
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder">lesson 
4</A>). The second file, <CODE>PrintfClient.java</CODE> is used to read 
<CODE>printf</CODE> messages received from a mote and print them to your screen. 
</P>
<P>To see the output generated by <CODE>TestPrintf</CODE> you need to start the 
<CODE>PrintfClient</CODE> by running the following command: </P><PRE>cd $TOSROOT\apps\tests\TestPrintf
java PrintfClient -comm serial@/dev/ttyUSBXXX:telosb
</PRE>
<P>After resetting the mote, the following output should be printed to your 
screen: </P><PRE>Hi I am writing to you from my TinyOS application!!
Here is a uint8: 123
Here is a uint16: 12345
Here is a uint32: 1234567890
I am now iterating: 0
I am now iterating: 1
I am now iterating: 2
I am now iterating: 3
I am now iterating: 4
This is a really short string...
I am generating this string to have just less than 250
characters since that is the limit of the size I put on my
maximum buffer when I instantiated the PrintfC component.
Only part of this line should get printed bec
</PRE>
<P>Note that the 'tty' device (i.e. COM port) specified when starting the 
PrintfClient MUST be the one used for communicating with a mote over the serial 
line. On telos and mica motes this is the same port that the mote is programmed 
from. Other motes, such as eyesIFX, have one port dedicated to programming and 
another for communication. Just make sure you use the correct one. </P>
<P>If for some reason you do not receive the output shown above, please refer to 
<A title="Mote-PC serial communication and SerialForwarder" 
href="http://docs.tinyos.net/index.php/Mote-PC_serial_communication_and_SerialForwarder">lesson 
4</A> to verify you have done everything necessary to allow serial communication 
between your pc and the mote. Remember that when using the MIB510 programming 
board that the switch on the very front of the board must be set to the 
<B>OFF</B> position in order to send messages from the mote to the pc. </P>
<HR>

<P>Go ahead and open up <CODE>TestPrintfC</CODE> to see how this output is being 
generated. </P>
<P>Upon receiving the booted event, the <CODE>Printf</CODE> service is started 
via a call to <CODE>PrintfControl.start()</CODE> </P><PRE>event void Boot.booted() {
  call PrintfControl.start();
}
</PRE>
<P>Once the <CODE>Printf</CODE> service has been started, a 
<CODE>PrintfControl.startDone()</CODE> event is generated. In the body of this 
event the first four lines of output are generated by making successive calls to 
<CODE>printf</CODE> and then flushing the buffer they are stored in. </P><PRE>event void PrintfControl.startDone(error_t error) {
  printf("Hi I am writing to you from my TinyOS application!!\n");
  printf("Here is a uint8:&nbsp;%u\n", dummyVar1);
  printf("Here is a uint16:&nbsp;%u\n", dummyVar2);
  printf("Here is a uint32:&nbsp;%ld\n", dummyVar3);
  call PrintfFlush.flush();
}
</PRE>
<P>Once these first four lines have been flushed out, the 
<CODE>PrintfFlush.flushDone()</CODE> event is signaled. The body of this event 
first prints the next 5 lines in a loop, followed by the last five lines. 
Finally, once all lines have been printed, the <CODE>Printf</CODE> service is 
stopped via a call to <CODE>PrintfControl.stop()</CODE>. </P><PRE>event void PrintfFlush.flushDone(error_t error) {
  if(counter &lt; NUM_TIMES_TO_PRINT) {
    printf("I am now iterating:&nbsp;%d\n", counter);
    call PrintfFlush.flush();
  }
  else if(counter == NUM_TIMES_TO_PRINT) {
    printf("This is a really short string...\n");
    printf("I am generating this string to have just less <FONT color=red>...</FONT>
    printf("Only part of this line should get printed bec <FONT color=red>...</FONT>
    call PrintfFlush.flush();
  }
  else call PrintfControl.stop();
  counter++;
}
</PRE>
<P>Notice that the last line of output is cut short before being fully printed. 
If you actually read the line printed above it you can see why. The buffer used 
to store TinyOS <CODE>printf</CODE> messages before they are flushed is by 
default limited to 250 bytes. If you try and print more characters than this 
before flushing, then only the first 250 characters will actually be printed. 
This buffer size is configurable, however, by specifying the proper CFLAGS 
option in your Makefile. </P><PRE>CFLAGS += -DPRINTF_BUFFER_SIZE=XXX
</PRE>
<P>Once the the <CODE>Printf</CODE> service has been stopped, the 
<CODE>PrintfControl.stopDone()</CODE> event is signaled and Led 2 is turned on 
to signify that the application has terminated. </P><PRE>event void PrintfControl.stopDone(error_t error) {
  counter = 0;
  call Leds.led2Toggle();
  printf("This should not be printed...");
  call PrintfFlush.flush();
} 
</PRE>
<P>Notice that the call to <CODE>printf()</CODE> inside the body of the 
<CODE>PrintfControl.stopDone()</CODE> event never produces any output. This is 
because the <CODE>Printf</CODE> service has been stopped before this command is 
called. </P><A name=Conclusion></A>
<H1><SPAN class=mw-headline>Conclusion</SPAN></H1>
<P>A few points are worthy of note before jumping in and writing your own 
applications that use the functionality provided by the <CODE>printf</CODE> 
library. </P>
<OL>
  <LI>In order to use the <CODE>printf</CODE> library, the 
  <CODE>tos/lib/printf</CODE> directory must be in your include path. The 
  easiest way to include it is by adding the following line directly within the 
  Makefile of your top level application: <PRE>CFLAGS += -I$(TOSDIR)/lib/printf 
</PRE>
  <LI>Remember that changing the <CODE>printf</CODE> buffer size is done 
  similarly: <PRE>CFLAGS += -DPRINTF_BUFFER_SIZE=XXX
</PRE>
  <LI>You MUST be sure to #include <CODE>"printf.h"</CODE> header file in every 
  component in which you would like to call the <CODE>printf()</CODE> command. 
  Failure to do so will result in obscure error messages making it difficult to 
  identify the problem. </LI></OL>
<P>Hopefully you now have everything you need to get going with the TinyOS 
<CODE>printf</CODE> library. All questions (or comments) about the use of this 
library should be directed to <A class="external text" 
title=mailto:tinyos-help@millennium.berkeley.edu 
href="mailto:tinyos-help@millennium.berkeley.edu" rel=nofollow>tinyos-help</A> 
mailing list. </P>
<P>Enjoy!! </P>
<P><BR></P>
<HR>

<CENTER>
<P>&lt; <B><A title="TinyOS Tutorials" 
href="http://docs.tinyos.net/index.php/TinyOS_Tutorials#Building_a_simple_but_full-featured_application">Previous 
Lesson</A></B> | <B><A title="" 
href="http://docs.tinyos.net/index.php/The_TinyOS_printf_Library#_Overview">Top</A></B> 
| <B><A title="Writing Low-Power Applications" 
href="http://docs.tinyos.net/index.php/Writing_Low-Power_Applications">Next 
Lesson</A> &gt;</B> </P></CENTER><!-- Saved in parser cache with key tinyosdocs:pcache:idhash:20-0!1!0!!en!2!edit=0 and timestamp 20080401133246 -->
<DIV class=printfooter>Retrieved from "<A 
href="http://docs.tinyos.net/index.php/The_TinyOS_printf_Library">http://docs.tinyos.net/index.php/The_TinyOS_printf_Library</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/The_TinyOS_printf_Library">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:The_TinyOS_printf_Library&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=The_TinyOS_printf_Library&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=The_TinyOS_printf_Library&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=The_TinyOS_printf_Library">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/The_TinyOS_printf_Library">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/The_TinyOS_printf_Library">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=The_TinyOS_printf_Library&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=The_TinyOS_printf_Library&amp;oldid=813">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="The TinyOS printf Library - TinyOS Documentation Wiki.files/poweredby_mediawiki_88x31.png"></A></DIV>
<UL id=f-list>
  <LI id=lastmod>This page was last modified 23:12, 25 February 2008. 
  <LI id=viewcount>This page has been accessed 445 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.277 secs. --></BODY></HTML>

⌨️ 快捷键说明

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