Professional Documents
Culture Documents
TinyOS Programming
TinyOS Programming
• Introduction
• TinyOS Programming
• Power Issues
• Multi-hop routing (Surge)
• In-network reprogramming (XNP)
• TinyDB/TinySQL/TASK
• TinyOS Virtual Machine
TinyOS Installation
• TinyOS can be downloaded from
http://webs.cs.berkeley.edu/tos/
C:\tinyos\cygwin\opt\tinyos-1.x
Reprogram the
mote
Review of TinyOS Components
• A TinyOS program is composed of
components
Component Declares the type of component
(module or configuration), and the
interfaces, commands, and events
Interface it uses and provides.
interface SendMsg {
// send a message
command result_t send(uint16_t address, uint8_t length, TOS_MsgPtr msg);
•
// an event indicating the previous message was sent
event result_t sendDone(TOS_MsgPtr msg, result_t success);
}
– Receiver:
Application
Buffer incoming Signal provides free
message in a application with buffer to store
free buffer new message next message
Group IDs and Addresses
• Nodes can only communicate with other nodes
in the same group ID
– Group ID is an 8 bit value specified in
<tos>/apps/Makelocal
– DEFAULT_LOCAL_GROUP=0x01
• A node’s address is a 16-bit value specified by
the make command
– make install.<id> mica2
– <id> may be any 16-bit value except:
• 0x007E - reserved for UART (TOS_UART_ADDR)
• 0xFFFF - reserved for broadcast (TOS_BCAST_ADDR)
TOS Active Messages
typedef struct TOS_Msg {
• TOS uses active // the following are transmitted
messages as defined in uint16_t addr;
uint8_t type;
<tos>\system\types\AM.h uint8_t group;
• Message is “active” uint8_t length;
int8_t data[TOSH_DATA_LENGTH];
because it contains the uint16_t crc;
destination address, // the following are not transmitted
uint16_t strength;
group ID, and type uint8_t ack;
(handler ID) uint16_t time;
uint8_t sendSecurityMode;
• TOSH_DATA_LENGTH = uint8_t receiveSecurityMode;
29 bytes } TOS_Msg;
Tos_Msg[AM=47] signal[48]
signal[47] signal[49]
GenericComm GenericComm
AMStandard AMStandard
signal receive(*Msg_Buffer)
AM
Receiver
Component
return *Msg_Buffer
configuration Oscilloscope { }
implementation {
components Main, OscilloscopeM, GenericComm as Comm, …;
…
OscilloscopeM.DataMsg -> Comm.SendMsg[AM_OSCOPEMSG];
}
configuration Oscilloscope { }
implementation {
components Main, OscilloscopeM, UARTComm as Comm, ….;
…
OscilloscopeM.ResetCounterMsg ->
Comm.ReceiveMsg[AM_OSCOPERESETMSG];
}
Sending Data to a Laptop
• A mote attached to the programming board can send
data through the UART port to the laptop
• There are several applications that bridge between the
wireless network and UART port
– <tos>/apps/TOSBase – forwards messages with correct
GroupID
– <tos>/apps/TransparentBase – ignores GroupID
– <tos>/apps/GenericBase – legacy support
• LED status:
– Green = good packet received and forwarded to UART
– Yellow = bad packet received (failed CRC)
– Red = transmitted message from UART
Displaying Received Data
• Java application: net.tinyos.tools.Listen
– Located in <tos>/tools/java/
– Relies on MOTECOM environment variable
• Export MOTECOM=serial@COM9:57600
TOSBase
apps/OscilloscopeRF
Java Applications
• Class net.tinyos.message.MoteIF interfaces
with the SerialPortForwarder TCP port
– It uses net.tinyos.message.Message objects
containing the message data
import net.tinyos.message.*;
This must extend
import net.tinyos.util.*;
net.tinyos.message.Message,
generated using
public class MyJavaApp {
/usr/local/bin/mig
int group_id = 1;
public MyJavaApp() {
try {
MoteIF mote = new MoteIF(PrintStreamMessenger.err, group_id);
mote.send(new OscopeMsg());
} catch (Exception e) {}
}
}
MIG
• Message Interface Generator
– Generates a Java class representing a TOS message
– Located in /usr/local/bin This is the generator as defined in
/usr/local/lib/ncc/gen*.pm
– Usage:
mig –java-classname=[classname] java [filename.h] [struct name] > outputFile
includes ADC;
includes sensorboard; // this defines the user names for the ports
interface ADC {
async command result_t getData();
async command result_t getContinuousData(); Split phase
async event result_t dataReady(uint16_t data);
}
Sensor Components
module SenseLightToLogM {
• Sensor components provides interface StdControl;
usually provide uses {
StdControl in addition to interface StdControl as PhotoControl;
ADC }
}
– Be sure to initialize them Implementation { …
before trying to take command result_t StdControl.init() {
measurements!! return rcombine(call PhotoControl.init(),
• Same goes with call Leds.init());
GenericComm }
command result_t StdControl.start() {
– Initializing it turns on the
return call PhotoControl.start();
power
}
command result_t StdControl.stop() {
return call PhotoControl.stop();
}…
}
Debugging Tips
• Join and/or search TOS mailing lists
– http://webs.cs.berkeley.edu/tos/support.html
• Update TOS
– Download latest CVS snapshot from
http://webs.cs.berkeley.edu/tos/download.html
and patch TOS (be sure to backup /opt)
• Develop apps in a private directory
– (e.g., <tos>/broken)
• Debug with LEDs
to
<tos>/tos/interfaces