码迷,mamicode.com
首页 > 其他好文 > 详细

TinyOS Term & Example

时间:2019-03-27 21:29:46      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:计算   environ   some   collect   signal   nal   发送   loader   bytes   

Tern:

nesC 程序 ---- 包含若干组件(component),以后缀.nc结尾。

组件(component) ----分为模块(module) 、配置(configuration)。

模块(module) 命名以C.nc结尾。

配置(configuration)命名以AppC.nc结尾。

任务(Task)是 TinyOS 应用程序中通用的“后台”处理方式。一个任务就是一个函数,

命令(command),事件(event)以及任务(task)中都可以 提交(post)任务。一个任务可以安全地调用 command 以及 event。

在 TinyOS 中这种跨组件的优化是非常重要的, 每一个长时间运算的操作都是 Split‐phase 的。这个 Split‐phase 方法就是把函数的调用和完成变为两个单独的执行部分。

网络协议的两个基本功能:分发(Dissemination)和收集(Collection)。

分发(Dissemination)协议的目的是可靠传输数据到网络中的每一个节点,主要用于配置参数、网络查询和重编程等功能。分发操作需要有一定的鲁棒性来保证在链路临时断开以及丢包率较高等情况下的可靠性。

收集(Collection)是分发相对应的操作,目的在于从其他节点汇聚数据到基站节点。通常的做法是建立一个或多个收集树(Collection trees),这些树的根为基站节点。当一个节点需要递交数据,就将该数据沿着树的路径进行传输。


AppC.nc内容:在 implementation 关键字后面的括号内是配置的具体实现。 components 关键字后面表明 了这个配置文件所引用的组件,A-->B 表示了一种关系,其中 A 为使用方(user),而 B 为提供方(provider)。命令(command)就是接口提供方已经实现的函数。事件(event)就是需要接口使用方实现的函数。

C.nc 文件内容:定义module,及其使用的接口(interface)。使用方必须实现接口中的 event 函数。因此我们可以看到该文件中的 implement 中包含了初始化 Boot.booted,以及三个 timer 计时的 event 函数的具体实现。


BlinkToRadio程序通过消息发送自身的节点 ID 和计数器至对方,同时收到对方的消息后,解析出对方的计数器,按照这个计数器亮灯,使用单个 Timer 实现发送的频率间隔。

总是使用 CC2420radio 的 12 信道(channel):PFLAGS = ‐DCC2420_DEF_CHANNEL=12

上面 PFLAGS 的作用在于告诉 C 在预处理中 DCC2420_DEF_CHANNEL 等于 12。

除了 CC2420_DEF_CHANNEL 外,还可以设置的参数有: DEFINED_TOS_AM_ADDRESS: 组 ID (默认为 0x22) CC2420_DEF_CHANNEL: CC2420 信道(默认为 26) CC2420_DEF_RFPOWER: 1‐31 CC1K_DEF_FREQ: CC1000 频率(默认为 434.845MHz) TOSH_DATA_LENGTH: 数据包 payload 长度 (默认为 28)

 

Example

Command

motelist
# motelist  lists  all devices conntected to a PC through an FTDI USB-to- serial converter (FT232HL chip)  (see www.ftdichip.com).  This includes  the  Telos  A,   Telos B, and Tmote modules.

man tos-bsl
# tos-bsl  is  a  version of msp430-bsl modifies to support the telos and  telos B motes.

sudo tos-install-jni
# tos-install-jni install‘s TinyOS‘s JNI libraries in your Java installation. On Linux and other  similar  operating  systems

tos-locate-jre --jni tos-locate-jre --java tos-locate-jre --javac
# tos-locate-jre  locates  your  Java  installation.  It is used by other tools to decide where to install files, and is useful  for  setting  up your shell path.

tos-check-env
# tos-check-env checks that your environment is properly  configured  for TinyOS  development.  The script checks for the existence of compilers, java, environment variables, graphics tools for nesdoc, and  more,  and then  check  that  the  versions  and  settings are adequate for TinyOS development. 
## WARNING: CLASSPATH may not include ‘.‘ (tos-check-env is severly out of date and needs to be updated. You can probably safely ignore those below warnings.)

dmesg
tos-build-deluge-image  
# It is  used  by tos-deluge to construct the binary image needed by tosboot.Deluge is a reliable data dissemination protocol for large objects, such as program binaries. Together with a bootloader, Deluge provides a way to reprogram sensor motes in a network. 

tos-write-image  
# writes an XML description of an executable file to standard output, based on the contents of a compiled file and the identifying options generated by tos-ident-flags.

tos-channelgen
# tos-channelgen  computes  the  CC1000 channel  which is closest to the requested frequency. (CC1000 用于 315/433/868/915MHz SRD 频带的单片超低功率射频收发器)

tos-set-symbols  
# It is a tool to inspect and modify the initial values of variables in a binary. It is used by the TinyOS build system to set a node‘s ID and AM address

tos-serial-configure  
# It is  a tool that resets a serial port to read raw bytes. Some devices, such as terminals, require serial ports to interpret  bytes  in  some  fashion  or another.

tos-serial-debug 
# print the raw bytes read from a serial port

tos-decode-flid flid-file flid
# By default, a mote that encounters a safety violation repeatedly blinks a failure code (also called flid, or fault-location identifier) on its LEDs.  tos-decode-flid can be used to  turn this code into a readable error message.The flid file is placed into the application‘s build directory and is named flids.txt.

tos-dump.py -h
# /usr/bin/tos-dump.py serial@/dev/ttyUSB0:57600

tos-ident-flags 
# generate compile-time flags identifying a program build

tos-mote-key  
# manages  TinySec keys. TinySec is an encryption system for mica and mica2 motes

tos-mviz
# tos-mviz  launches  MViz,  the TinyOS network visualizer. MViz is a replacement for the Surge application of earlier TinyOS versions.

tos-ramsize
# This  tool  disassembles an elf file for AVR-based TinyOS platforms and estimates the maximum  extent of its call stack.

tos-storage-pxa27xp30 
# reads a user specification describing the layout of storage volumes on an embedded P30 flash in the  Intel  Xscale  PXA27X  series  processor,  and  generates  code describing  that  layout for use by the TinyOS 2.0 storage subsystem.

 

Problems

motelist
# No devices found.

http://tinyos-help.10906.n7.nabble.com/Motelist-and-MicaZ-td3473.html

Use ‘dmesg‘ command to find which port is your mote connected to and then install your application on the micaz using the usual ‘make‘ command.

lsusb
dmesg | tail

https://askubuntu.com/questions/910152/ubuntu-16-04-using-a-serial-terminal-with-a-ftdi-chip-usb-virtual-comport

The FTDI chip should be supported out-of-the box. Just connect the device and it will be available.

USB serials (like the FTDI chip) appear as /dev/ttyUSB* when they are connected.

make telosb help
make telosb reinstall bsl,/dev/ttyUSB0
# AttributeError: ‘Serial‘ object has no attribute ‘setBaudrate‘

https://stackoverflow.com/questions/34602168/dronekit-failed-to-connect-to-dev-tty-usbmodem1411-serial-object-has-no-at

(failed) pip install "pySerial>=2.0,<=2.9999"

You don‘t need FTDI drivers in Linux, it‘s built into the kernel. The dmesg output tells you it‘s working, so chances are either the software isn‘t or it‘s a permission issue. The port will be at /dev/ttyUSB0, and your user needs to be a member of the "dialout" group in order to use it.

https://github.com/mavlink/mavlink/issues/498

Modify the code piece

self.port.setBaudrate(baudrate)

with

self.port.baudrate = baudrate

 

Simple Example:

  1. a header file Simple.h, use enum to define constant

  2. a Configuration file SimpleAppC.nc :two components in this program: your component called SimpleC and the Main component MainC. The MainC component provides the Boot.booted signal which essentially is the entry point of the application. 描述工程整体结构的文件

  3. the Component file SimpleC.nc. This has definition (implementation) of the component SimpleC. 有一个 event void Boot.booted(); 程序就是从 Boot.booted()函数开始运行的

  4. if a component uses an interface, it can call the interface‘s commands and must implement handlers for its events.These interface are located in tos/interface

  5. Makefile: 编译器是 ncc(类似 gcc)

  6. Run

    $make telosb reinstall,3 bsl,6。reinstall 表示不需要再次编译,直接将可执行程序 装载到设备中。若 reinstall 换成 install 的话,还要进行一次上面的编译操作,很慢。install/reinstall 后加加逗号,再加数字,表示给节点进行的编号。这个编号被传到程序中是一个常量 TOS_NODE_ID。之后空格再加 bsl,数字 表示加载到指定设备中,数字表示该设备的 COM 号减 1。如果计算机只连接了一个节点的话,我们可以省略指定设备的环节,直接$make telosb reinstall,3 将节点编号为 3 即可

  7. Error

    In file included from SimpleAppC.nc:4: SimpleC.nc:1: syntax error before {‘ SimpleC.nc:5: syntax error before{‘ In component SimpleAppC‘: SimpleAppC.nc:6: cannot findBoot‘ /home/labuser/src/tinyos-release-tinyos-2_1_2/support/make/msp/msp.rules:107: recipe for target ‘exe0‘ failed make: *** [exe0] Error 1

  8. Solution

    Replace All Code like this

    configuration SimpleAppC{
    }
    

    with

    configuration SimpleAppC
    {
    }
    

 

TinyOS Toolchain

http://tinyos.stanford.edu/tinyos-wiki/index.php/TinyOS_Toolchain

Describes the details of the TinyOS toolchain, including the build system, how to create your own Makefile, and how to find out more information on the various tools included with TinyOS.

Mote-mote radio communication

http://tinyos.stanford.edu/tinyos-wiki/index.php/Mote-mote_radio_communication

Introduces the TinyOS communication model. There is an exercise that illustrates sending and receiving messages.

TinyOS Term & Example

标签:计算   environ   some   collect   signal   nal   发送   loader   bytes   

原文地址:https://www.cnblogs.com/WindyZ/p/10610304.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!