1 tinyos hands-on session. 2 goals 1. install tinyos 2. layout of tinyos-2.x 3. write two...

58
1 TinyOS Hands-on Session

Upload: jasper-prestridge

Post on 15-Dec-2015

226 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

1

TinyOSHands-on Session

Page 2: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

2

Goals1.Install TinyOS

2.Layout of tinyos-2.x

3.Write two applications(A) DisseminationDemoClient(B) CollectionsDemoClient

2

Page 3: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

3

Options• LiveCD

– XubunTOS– Customized Ubuntu 8.10 LiveCD

• Native– Linux

– .rpm packages– .deb packages

– Windows: Cygwin + .rpm packages– MacOS X

– stow– macports

3

Recommended

Today

Page 4: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

4

Other Options• VMware

– Jetos– based on JeOS (Ubuntu Server 8.04)– optimized for ssh access– very small: 190MB compressed

– Lenny– based on Debian 5.0 “Lenny”– graphical interface using XFCE– bigger: 300MB compressed

– XubunTOS

4

Page 5: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

5

Components•NesC: nesc_*.deb

•Cross compiler– binutils: msp430-binutils-tinyos_*.deb

– gcc: msp430-gcc-tinyos_*.deb– libc: msp430-libc-tinyos_*.deb– gdb (optional)

•Deputy: deputy-tinyos_*.deb5

Page 6: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

6

Environment

6

export TOSROOT=$HOME/local/src/tinyos-2.xexport TOSDIR=$TOSROOT/tosexport MAKERULES=$TOSROOT/support/make/Makerules

export CLASSPATH=$TOSROOT/support/sdk/java/tinyos.jar:.export PYTHONPATH=$TOSROOT/support/sdk/python

Page 7: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

7

Architectures• AVR

– mica2, mica2dot– micaz– btnode– IRIS

• ARM– imote2

7

• MSP430– telosb, sky– shimmer– eyesIFX– tinynode– epic

• 8051– CC2430– CC1110/CC1111

Page 8: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

8

Layout

8

+ tinyos-2.x + apps + docs + support + tools + tos

Page 9: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

9

Layout

9

+ apps + Blink + Null + RadioCountToLeds + MultihopOscilloscope + tests + ... + ...+ docs+ support+ tools+ tos

Page 10: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

10

Layout

10

+ apps+ docs + html + pdf + txt + ...+ support+ tools+ tos

Page 11: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

11

Layout

11

+ apps+ docs+ support + make - Makerules + avr/ + msp/ + ... + sdk+ tools+ tos

Page 12: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

12

Layout

12

+ apps+ docs+ support + make + sdk + c + cpp + java + python+ tools+ tos

Page 13: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

13

Layout

13

+ support + sdk + c + blip + sf + cpp + sf + java - tinyos.jar + python + tinyos - tos.py

Page 14: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

14

Layout

14

+ apps+ docs+ support+ tools+ tos + chips + interfaces + lib + platforms + sensorboards + systems + types

Page 15: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

15

Layout

15

+ tos + chips + atm128 + msp430 + pxa27x + cc2420 + cc1000 + at45db + stm25p + sht11 + ...

Page 16: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

16

Layout

16

+ tos + chips + interfaces - Boot.nc - SplitControl.nc - StdControl.nc - ... + lib + platforms + sensorboards + systems + types

Page 17: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

17

Layout

17

+ tos + lib + net + printf + timer + tosthreads + serial - SerialActiveMessageC.nc - SerialAMSenderC.nc - SerialAMReceiverC.nc - ... + ...

Page 18: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

18

Layout

18

+ tos + lib + net + ctp + 4bitle + drip + Deluge + dip + blip + ...

Page 19: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

19

Layout

19

+ tos + systems - AMReceiverC.nc - AMSenderC.nc - MainC.nc - LedsC.nc - TimerMilliC.nc - ...

Page 20: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

20

Layout

20

+ tos + chips + interfaces + lib + platforms + sensorboards + systems + types - TinyError.h - messssage.h - ...

Page 21: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

21

Applications

DisseminationDemo

CollectionDemo

Page 22: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

22

DisseminationDemo

22

Page 23: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

23

DisseminationDemo

• DisseminationDemoClient– start the radio– start Drip– when a new value is received print its contents

• DisseminationDemoServer– start the radio– start Drip– start a periodic timer– on each firing or the timer increment a counter and disseminate it

23

Page 24: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

24

DisseminationDemoClient

24

MainC ActiveMessageC DisseminationC DisseminatorC

DisseminationDemoClientC

Boot SplitControl StdControl DisseminationValue

<nx_uint32_t>

Page 25: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

25

DisseminationDemoClient

•Interfaces– Boot– StdControl– SplitControl– DisseminationValue<t>

25

•Components– MainC– ActiveMessageC– DisseminationC– DisseminatorC

Page 26: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

26

tos/interfaces/Boot.nc

26

interface Boot { event void booted();}

Page 27: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

27

tos/interfaces/StdControl.nc

27

interface StdControl{ command error_t start(); command error_t stop();}

Page 28: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

28

tos/interfaces/SplitControl.nc

28

interface SplitControl{ command error_t start(); event void startDone(error_t error); command error_t stop(); event void stopDone(error_t error);}

Page 29: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

29

tos/lib/net/DisseminationValue.nc

29

interface DisseminationValue<t> { command const t* get(); command void set(const t*); event void changed();}

Page 30: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

30

tos/system/MainC.nc

30

configuration MainC { provides interface Boot; uses interface Init as SoftwareInit;}

implementation { ...}

Page 31: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

31

tos/platforms/telosa/ActiveMessageC.nc

31

configuration ActiveMessageC { provides { interface SplitControl; ... }}

implementation { ...}

Page 32: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

32

tos/lib/net/drip/DisseminationC.nc

32

configuration DisseminationC { provides interface StdControl;}

implementation { ...}

Page 33: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

33

tos/lib/net/drip/DisseminatorC.nc

33

generic configuration DisseminatorC(typedef t, uint16_t key) { provides interface DisseminationValue<t>; provides interface DisseminationUpdate<t>;}

implementation { ...}

Page 34: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

34

Makefile

34

COMPONENT=DisseminationDemoClientAppC

CFLAGS += -I%T/lib/netCFLAGS += -I%T/lib/net/dripCFLAGS += -I%T/lib/printf

include $(MAKERULES)

Page 35: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

35

Commands

35

$ make telosb

$ make telosb install,42

$ tos-dump.py serial@/dev/ttyUSB0:115200

Page 36: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

36

Summary

36

tos/interfaces/Boot.nctos/interfaces/StdControl.nctos/interfaces/SplitControl.nc

tos/system/MainC.nctos/platforms/telosa/ActiveMessageC.nctos/lib/net/drip/DisseminationC.nctos/lib/net/drip/DisseminatorC.nc

Page 37: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

37

DisseminationDemoClientAppC.nc

configuration DisseminationDemoClientAppC { }

implementation

{

components MainC;

components DisseminationC;

components new DisseminatorC(nx_uint32_t, 2009);

components DisseminationDemoClientC;

components ActiveMessageC;

DisseminationDemoClientC.Boot -> MainC;

DisseminationDemoClientC.DisseminationStdControl -> DisseminationC;

DisseminationDemoClientC.DisseminationValue -> DisseminatorC;

DisseminationDemoClientC.RadioSplitControl -> ActiveMessageC;

}

37

Page 38: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

38

DisseminationDemoClientC.nc

module DisseminationDemoClientC{ uses { interface Boot; interface DisseminationValue<nx_uint32_t>; interface StdControl as DisseminationStdControl; interface SplitControl as RadioSplitControl; }}

implementation{ nx_uint32_t counter;

event void Boot.booted() { call RadioSplitControl.start(); }

...

}

38

Page 39: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

39

DisseminationDemoClientC.nc

module DisseminationDemoClientC{ ...}

implementation{

...

event void RadioSplitControl.startDone(error_t error) { call DisseminationStdControl.start(); }

event void DisseminationValue.changed() { printf("R: %lu\n", *(call DisseminationValue.get())); printfflush(); }

event void RadioSplitControl.stopDone(error_t error) { }}

39

Page 40: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

40

http://docs.tinyos.net/index.php/Ipsn2009-tutorial

40

Page 41: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

41

CollectionDemo

41

Page 42: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

42

CollectionDemo• CollectionDemoClient

– start the radio– start CTP– start a periodic timer– on each firing or the timer increment a counter and sent it over CTP

• CollectionDemoServer– start the radio– start CTP– when a new value is received print its contents

42

Page 43: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

43

CollectionDemoClient

43

MainC ActiveMessageC CollectionC CollectionSenderC

CollectionDemoClientC

Boot SplitControl StdControl Send

TimerMilliC

Timer<TMilli>

Page 44: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

44

CollectionDemoClient

•Interfaces– Boot– StdControl– SplitControl– Send– Timer<TMilli>

44

•Components– MainC– ActiveMessageC– CollectionC– CollectionSenderC– TimerMilliC

Page 45: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

45

CollectionDemoClient

•Interfaces– Boot– StdControl– SplitControl– Send– Timer<TMilli>

45

•Components– MainC– ActiveMessageC– CollectionC– CollectionSenderC– TimerMilliC

Page 46: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

46

tos/interfaces/Send.nc

46

interface Send { command error_t send(message_t* msg, uint8_t len); event void sendDone(message_t* msg, error_t error); command uint8_t maxPayloadLength(); command void* getPayload(message_t* msg, uint8_t len);

command error_t cancel(message_t* msg);}

Page 47: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

47

tos/lib/net/ctp/CollectionC.nc

47

configuration CollectionC { provides { interface StdControl; ... }}

implementation { ...}

Page 48: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

48

tos/lib/net/ctp/CollectionSenderC.nc

48

generic configurationCollectionSenderC(collection_id_t collectid) { provides { interface Send; interface Packet; }}

implementation { ...}

Page 49: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

49

tos/system/TimerMilliC.nc

49

generic configuration TimerMilliC() { provides interface Timer<TMilli>;}

implementation { ...}

Page 50: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

50

Makefile

50

COMPONENT=CollectionDemoClientAppC

CFLAGS += -I%T/lib/netCFLAGS += -I%T/lib/net/ctpCFLAGS += -I%T/lib/net/4bitleCFLAGS += -I%T/lib/printf

include $(MAKERULES)

Page 51: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

51

Summary

51

tos/interfaces/Boot.nctos/interfaces/StdControl.nctos/interfaces/SplitControl.nctos/interfaces/Send.nctos/lib/timer/Timer.nc

tos/system/MainC.nctos/system/TimerMilliC.nctos/platforms/telosa/ActiveMessageC.nctos/lib/net/ctp/CollectionC.nctos/lib/net/ctp/CollectionSenderC.nc

Page 52: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

52

CollectionDemoClientAppC.nc

configuration CollectionDemoClientAppC { }

implementation

{

components MainC;

components ActiveMessageC;

components CollectionC;

components new CollectionSenderC(16);

components new TimerMilliC() as Timer;

components CollectionDemoClientC;

CollectionDemoClientC.Boot -> MainC;

CollectionDemoClientC.RadioSplitControl -> ActiveMessageC;

CollectionDemoClientC.CollectionStdControl -> CollectionC;

CollectionDemoClientC.Send -> CollectionSenderC;

CollectionDemoClientC.Timer -> Timer;

}

52

Page 53: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

53

CollectionDemoClientC.nc

module CollectionDemoClientC{ uses { interface Boot; interface SplitControl as RadioSplitControl; interface StdControl as CollectionStdControl; interface Send; interface Timer<TMilli>; }}

implementation{ message_t smsg;

typedef nx_struct { nx_uint8_t string[8]; nx_uint16_t counter; } name_t; name_t *name;

...}

53

Page 54: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

54

CollectionDemoClientC.nc

module CollectionDemoClientC{ ...}

implementation{

...

event void Boot.booted() { name = call Send.getPayload(&smsg, sizeof(name_t)); strcpy((char*)name->string, "name"); name->counter = 0; call RadioSplitControl.start(); }

...

}

54

Page 55: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

55

CollectionDemoClientC.nc

module CollectionDemoClientC{ ...}

implementation{

...

event void RadioSplitControl.startDone(error_t error) { call CollectionStdControl.start(); call Timer.startPeriodic(1024); }

...

}

55

Page 56: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

56

CollectionDemoClientC.nc

module CollectionDemoClientC{ ...}

implementation{

...

event void Timer.fired() { error_t error; name->counter++; error = call Send.send(&smsg, sizeof(name_t)); printf("S: %d %d\n", name->counter, error); printfflush(); }

event void Send.sendDone(message_t* msg, error_t error) { } event void RadioSplitControl.stopDone(error_t error) { }}

56

Page 57: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

57

http://docs.tinyos.net/index.php/Ipsn2009-tutorial

57

Page 58: 1 TinyOS Hands-on Session. 2 Goals 1. Install TinyOS 2. Layout of tinyos-2.x 3. Write two applications (A) DisseminationDemoClient (B) CollectionsDemoClient

58

The End.

58