zoukankan      html  css  js  c++  java
  • 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.

    =======================================================================
    中文名:高洪臣
    英文名:Gordon Scott
    E-mail:gaohongchen01@163.com
    =======================================================================
  • 相关阅读:
    Centos7安装Tomcat
    Centos7安装Java8
    NumPy
    面试题(2020)前端HTTP浏览器相关面试题
    面试题(2020)Vue面试题汇总
    面试题(2020)微信小程序常见面试题
    QuantLib 金融计算——案例之主成分久期(PCD)
    QuantLib 金融计算——案例之 KRD、Fisher-Weil 久期及久期的解释能力
    QuantLib 金融计算——一个使用 ActualActual 时需要注意的陷阱
    python selenium list index out of range
  • 原文地址:https://www.cnblogs.com/gaohongchen01/p/3726795.html
Copyright © 2011-2022 走看看