Fork me on GitHub

Tinyos学习笔记(二)

1、TinyOS communication tools

  • java serialApp -comm serial@/dev/ttyUSB0:telosb
  • java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb
  • java net.tinyos.tools.MsgReader serialMsgApp -comm serial@/dev/ttyUSB0:telos
  • java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB0:telosb
  • java net.tinyos.sf.SerialForwarder -comm sf@localhost:9002
  • java net.tinyos.sf.SerialForwarder -port 9003 -comm sf@localhost:9002
  • java net.tinyos.tools.PrintfClient -comm serial@/dev/ttyUSB0:telosb

  Most TinyOS communication tools take an optional -comm parameter, which allows you to specify the packet source as a string. 

   

  

  (1) Listen tool

  The Java tool Listen is a basic packet sniffer: it prints out the binary contents of any packet it hears.

  

  One problem with Listen is that it just dumps binary data: a user has to be able to read the bytes and parse them into a given packet format.

  (2) MsgReader

  use a Java message class to print out the messages.

  Rather than parse packet formats manually, you can use the mig (Message Interface Generator) tool to build a Java, Python, or C interface to the message structure. Given a sequence of bytes, the MIG-generated code will automatically parse each of the fields in the packet, and it provides a set of standard accessors and mutators for printing out received packets or generating new ones.

  The core code you have to add to Makefile is as follows:

BUILD_EXTRA_DEPS+=SenseMsg.class

CLEAN_EXTRA = *.class SenseMsg.java

SenseMsg.class:SenseMsg.java
    javac SenseMsg.java

SenseMsg.java:
    mig java -target=null -java-classname=SenseMsg sense.h SenseMsg -o $@

  One part of the TinyOS communication toolchain requires being able to figure out which AM types correspond to what kinds of packets. To determine this, for a packet type named X, mig looks for a constant of the form AM_X. If you get the message:xxx does not have an AM type - ignored,you have to change the packet type(the arguments to AMSenderC and AMReceiverC),like AM_X.Then,manually remove the old .java and .class files.Recompile the application, and you should see no warning. Install it on a mote.

  e.g.:output like this:  

           

  (3) SerialForwarder

  Most generally, the SerialForwarder program opens a packet source 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.

  SerialForwarder is the second kind of packet source.

  A SerialForwarder source has this syntax:sf@HOST:PORT

  (4) PrintfClient

  After starting the service, calls to the standard c-style printf command are made to print various strings of text over the serial line. The output can be displayed using the PrintfClient.

  To use the tool successfully,you have to add "CFLAGS += -I$(TOSDIR)/lib/printf" to Makefile and "#include "printf"" to xxxC.nc file.To chang the printf buffer size,you can add "CFLAGS += -DPRINTF_BUFFER_SIZE=XXX" to Makefile.

2、Sending an AM packet to the serial port in TinyOS

  The TinyOS serial stack follows the same programming model as the radio stack. There is a SerialActiveMessageC 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.

              

  Serial AM communication has the same interfaces as radio AM communication.

posted @ 2014-05-13 23:40  晨光iABC  阅读(574)  评论(0编辑  收藏  举报