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.

转载于:https://www.cnblogs.com/gaohongchen01/p/3726795.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值