TinyOS实例介绍

实验中设置的TinyOS参数

Channel 17, Central Frequency=2435MHz
Payload length = 28bytes,pkt len=36bytes
transmission_rate=250kbps, duration = 1.152ms
The length of a CC2420 packet is [18,133]bytes, the range of valid on-air time is [576, 4256]μs under the standard rate of 250kbit/s
The MPI of adjacent unicast packets is 10ms by default settings in TinyOS-2.1.2, (from ZiSense)

TinyOS更改定时器精度

locate Timer.nc
# /home/user/src/tinyos-release-tinyos_2_1_2/tos/lib/timer/Timer.nc
cd /home/user/src/tinyos-release-tinyos_2_1_2/tos/lib/timer
vim Timer.nc
# lots of Interface that provided by Timer<precision_tag>
vim Timer.h
# <precision_tag> can be TSecond;TMilli;T32khz;TMicro

这意味着在BlinkC.nc的module中可通过uses interface Timer<TMicro> as Timer 从而使得计时器定时精度从默认的毫秒级改为微秒级

telosb platform取消backoff

cd tos/chip/cc2420/csma
sudo vim CC2420CsmaP.nc

/cca
# 将变量 ccaOn = TRUE 改成 FALSE

TinyOS例程说明(telosb通信节点)

Ref:TinyOS Tutorials

- 示波器(Oscilloscope)的使用: BaseStation & Sensor Testing

Oscilloscope is an application that let's you visualize sensor readings on the PC. Every node that has Oscilloscope installed periodically samples the default sensor via (DemoSensorC) and broadcasts a message with 10 accumulated readings over the radio. A node running the BaseStation application will forward these messages to the PC using the serial communication.

即一个节点需要跑BaseStation程序发送消息给PC,另一个节点安装Oscilloscope程序周期性采样传感器并广播出去。

Each node is represented by a line of different color , The x-axis is the packet counter number and the y-axis is the sensor reading.

# 启动 Serial Forwarder 以允许多个程序访问串口读取的数据包
java net.tinyos.sf.SerialForwarder -comm serial@/dev/ttyUSB0:telosb
# 进入并运行java程序
cd <tinyos code directory>/apps/Oscilloscope/java
make
./run

- 节点端到端的通信实例:Mote-mote radio communication

cd <tinyos code directory>/apps/BlinkToRadio
make telosb
make telosb reinstall bsl,/dev/ttyUSB0
# both motes should be blinking their LEDs

- 节点端作基站与电脑通信: Mote-PC serial communication and SerialForwarder

# install Blink in one mote
cd <tinyos code directory>/apps/BlinkToRadio
make telosb
make telosb reinstall bsl,/dev/ttyUSB0
# second mote
cd <tinyos code directory>/apps/BaseStation 
make telosb
make telosb reinstall bsl,/dev/ttyUSB1
# 读取telosb节点数据(telosb: 115200 baud)
java net.tinyos.tools.Listen -comm serial@/dev/ttyUSB0:telosb

- RSSI Demo

/apps/tutorials/RssiDemo

运行代码:

make telosb
make telosb reinstall bsl,/dev/ttyUSB0
make
java RssiDemo -comm serial@/dev/ttyUSB1:telosb

Ref: https://hujunyu1222.github.io/2015/08/01/2015-08-01-tinyOSnote1/

//在XXXAppC.nc中添加
components CC2420ActiveMessageC as CC2420Reader;
XXX.CC2420Packet = CC2420Reader;
//在XXXC.nc中,uses内添加
interface CC2420Packet;
//在XXXC.nc中,例如在Receive.receive()通过接口提供的get.Rssi(msg)函数获得RSSI。
int_8 rssi;
rssi = call CC2420Packet.getRssi(msg);

获取的RSSi值是16进制的,要将其转换为dBm, 需要
1.将得到的16进制数换算为10进制。
2.将这个10进制数 减去256
3.最后,计算出的RSSI 有45的偏移量,所以最后得到的数值需要 减去 45。

[/tests/cc2420/RssiToSerial]

Ref: https://hujunyu1222.github.io/2015/08/05/2015-08-12-tinyOSnote3/

原始读数转换为dBm:

//我们设原始获得的数据是val
dBm = (int8_t) (((val - 0x7F) & 0xFF) -45);
//简单的换算
temp = int(val,16)     //将val转换为10进制数
dBm = temp -127 -45;   //再将10进制数减去127,然后再减去45(cc2420手册中说的偏移量45)

RSSi Samples noise floor

posted @ 2019-07-27 17:10  WindyZ  阅读(1172)  评论(0编辑  收藏  举报