Übung zu Drahtlose Kommunikation. 10. Übung 14.01.2012



Similar documents
Laboratorio di Sistemi Wireless 21 Maggio 2012

TinyOS 2.0: A wireless sensor network operating system

TinyOS Programming. Philip Levis and David Gay

How To Test In Tinyos With Unit Test (Forum) On A Microsoft Microsoft Computer (Forums) On An Ipa (Forms) On Your Computer Or Microsoft Macbook (Forims) On The Network (For

message t Abstract 1. Introduction Note TEP: 111 Core Working Group TinyOS-Version: 2.x

Chapter 13 Embedded Operating Systems

Mutual Exclusion using Monitors

Wireless Sensor Networks: Motes, NesC, and TinyOS

Field Software Updates Using TPMS LF An example using the Low Frequency radio (LFR) for wireless software updating

Chapter 6: Operating System in Sensors

Security of MICA*-based / ZigBee Wireless Sensor Networks

Application Note: AN00121 Using XMOS TCP/IP Library for UDP-based Networking

Comparison of Operating Systems TinyOS and Contiki

Towards Lightweight Logging and Replay of Embedded, Distributed Systems

Software Design Patterns For TinyOS

Decomposition into Parts. Software Engineering, Lecture 4. Data and Function Cohesion. Allocation of Functions and Data. Component Interfaces

XMOS Programming Guide

Using Protothreads for Sensor Node Programming

ADL User Guide for Open AT V4.10

TinySDN: Enabling TinyOS to Software-Defined Wireless Sensor Networks

APPLICATION NOTE. Atmel AT02607: Wireless Product Development Using Atmel Studio and ASF. Atmel MCU Wireless. Description.

System Architecture and Operating Systems

RIOT-Lab. How to use RIOT in the IoT-Lab. Oliver "Oleg" Hahm. November 7, 2014 INRIA. O. Hahm (INRIA) RIOT-Lab November 7, / 29

Software Design Patterns for TinyOS

REMOTE TEMPERATURE AND HUMIDITY MONITORING SYSTEM USING WIRELESS SENSOR NETWORKS

Marionette: Using RPC for Interactive Development and Debugging of Wireless Embedded Networks

Design and Implementation of MansOS: a Wireless Sensor Network Operating System

An Implementation Of Multiprocessor Linux

An Incomplete C++ Primer. University of Wyoming MA 5310

MeshBee Open Source ZigBee RF Module CookBook

Xenomai: integration and qualification of a real time operating system ARMadeus Systems

Freescale MQX USB Device User Guide

Software Design Patterns for TinyOS

How to design and implement firmware for embedded systems

Design Document. Offline Charging Server (Offline CS ) Version i -

Data Networks Project 2: Design Document for Intra-Domain Routing Protocols

Copyright 2014, Oracle and/or its affiliates. All rights reserved.

Contiki Programming Course: Hands-On Session Notes

Last Class: OS and Computer Architecture. Last Class: OS and Computer Architecture

POSIX. RTOSes Part I. POSIX Versions. POSIX Versions (2)

SSC - Concurrency and Multi-threading Java multithreading programming - Synchronisation (I)

Freescale Semiconductor, I

How To Use A Wireless Sensor Network Operating System With A Non-Expert Knowledge

Designing and Embodiment of Software that Creates Middle Ware for Resource Management in Embedded System

TLM-2.0 in Action: An Example-based Approach to Transaction-level Modeling and the New World of Model Interoperability

TinyOS: An Operating System for Sensor Networks

UM1734 User manual. STM32Cube USB device library. Introduction

1 Abstract Data Types Information Hiding

VxWorks Guest OS Programmer's Guide for Hypervisor 1.1, 6.8. VxWorks GUEST OS PROGRAMMER'S GUIDE FOR HYPERVISOR

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Design of WSN-Based Remote Monitoring System for Environmental Parameters in Substation

Top 10 Bug-Killing Coding Standard Rules

Implementing and testing tftp

Operating Systems for Wireless Sensor Networks: A Survey

MPLAB Harmony System Service Libraries Help

Chapter 6, The Operating System Machine Level

Going Linux on Massive Multicore

How To Build A Wireless Mcd (Sdr) From Scratch With A Microsd (Sdy) And A Wireless Microsdy (Mcd) (Sdie) (For Microsdie And Awn) (Md)

Embedded Programming in C/C++: Lesson-1: Programming Elements and Programming in C

Microcontrollers Deserve Protection Too

Technical Training Module ( 30 Days)

Chapter 2: OS Overview

Linux Driver Devices. Why, When, Which, How?

REAL TIME OPERATING SYSTEM PROGRAMMING-II: II: Windows CE, OSEK and Real time Linux. Lesson-12: Real Time Linux

Real Time Programming: Concepts

Device Driver Best Practices in Windows Embedded Compact 7. Douglas Boling Boling Consulting Inc.

Secure data aggregation in mobile sink wireless sensor networks

Course Project Documentation

C Programming. for Embedded Microcontrollers. Warwick A. Smith. Postbus 11. Elektor International Media BV. 6114ZG Susteren The Netherlands

Chapter 2 System Structures

CS161: Operating Systems

A Transport Protocol for Multimedia Wireless Sensor Networks

V850E2/ML4 APPLICATION NOTE. Performance Evaluation Software. Abstract. Products. R01AN1228EJ0100 Rev Aug. 24, 2012

Operating System Structures

Sproxies on theScale of the WSAN Cloud

Encryption Wrapper. on OSX

SEMS: The SIP Express Media Server. FRAFOS GmbH

Master's thesis. Two years. Datateknik Computer Science

How To Understand The Power Of The Internet

obems - open source Building energy Management System T4 Sustainability Ltd

How To Port A Program To Dynamic C (C) (C-Based) (Program) (For A Non Portable Program) (Un Portable) (Permanent) (Non Portable) C-Based (Programs) (Powerpoint)

A NOVEL RESOURCE EFFICIENT DMMS APPROACH

A Survey of Parallel Processing in Linux

EECE 276 Embedded Systems

Embedded Software Development with MPS

Transcription:

Übung zu Drahtlose Kommunikation 10. Übung 14.01.2012

TinyOS is an operating system designed to target limited-resource sensor network nodes TinyOS 0.4, 0.6 (2000-2001) TinyOS 1.0 (2002): first nesc version TinyOS 1.1 (2003): reliability improvements, many new services TinyOS 2.0 (2006): complete rewrite, improved design, portability, reliability and documentation TinyOS and its application are implemented in nesc, a C dialect: nesc 1.0 (2002): Component-based programming nesc 1.1 (2003): Concurrency support nesc 1.2 (2005): Generic components, external types 2

TinyOS in a nutshell System runs a single application OS services can be tailored to the application s needs These OS services include timers, radio, serial port, A/D conversion, sensing, storage, multihop collection and dissemination, Application and services are built as a set of interacting components (as opposed to threads) using a strictly non-blocking execution model event-driven execution, most service requests are split-phase Implementation based on a set of OS abstractions tasks, atomic with respect to each other; interrupt handlers resource sharing and virtualisation, power management hardware abstraction architecture 3

nesc in a seashell Tmote Sky & Tiny OS C dialect Component based all interaction via interfaces connections ( wiring ) specified at compile-time generic components, interfaces for code reuse, simpler programming External types to simplify interoperable networking Reduced expressivity no dynamic allocation no function pointers Supports TinyOS s concurrency model must declare code that can run in interrupts atomic statements to deal with data accessed by interrupts data race detection to detect (some) concurrency bugs 4

Überprüfen der Systemumgebung: Tmote Sky & Tiny OS $ tos-check-env $ printenv MAKERULES /opt/tinyos-2.x/support/make/makerules $ motelist wcu@wcu-desktop:~$ motelist Reference Device Description ---------- ---------------- --------------------------------------------- M4AMMD4W /dev/ttyusb0 Moteiv tmote sky wcu@wcu-desktop:~$ 5

Tiny OS - einfaches Programm Ein einfaches Programm: C-Beispiel: test.c int main () { gcc o test test.c return 0; 1) Configuration file SimpleAppC.nc configuration SimpleAppC{ implementation{ components SimpleC, MainC; SimpleC.Boot -> MainC.Boot; 2) Component file SimpleC.nc module SimpleC{ uses interface Boot; implementation{ event void Boot.booted() { //The entry point of the program 3) Makefile COMPONENT=SimpleAppC include $(MAKERULES) make telosb 6

Tiny OS einfaches Programm $ motelist wcu@wcu-desktop:~$ motelist Reference Device Description ---------- ---------------- --------------------------------------------- M4AMMD4W /dev/ttyusb0 Moteiv tmote sky wcu@wcu-desktop:~$ $ make telosb reinstall bsl,/dev/ttyusb0 7

$ cd tinyos-2.x/apps $ mkdir BlinkToRadio File: BlinkToRadioC.nc #include <Timer.h> #include "BlinkToRadio.h" module BlinkToRadioC { uses interface Boot; uses interface Leds; uses interface Timer<TMilli> as Timer0; implementation { uint16_t counter = 0; event void Boot.booted() { call Timer0.startPeriodic(TIMER_PERIOD_MILLI); event void Timer0.fired() { counter++; call Leds.set(counter); http://docs.tinyos.net/tinywiki/index.php/mote-mote_radio_communication 8

File: BlinkToRadioAppC.nc #include <Timer.h> #include "BlinkToRadio.h" configuration BlinkToRadioAppC { implementation { components MainC; components LedsC; components BlinkToRadioC as App; components new TimerMilliC() as Timer0; App.Boot -> MainC; App.Leds -> LedsC; App.Timer0 -> Timer0; 9

File: BlinkToRadio.h #ifndef BLINKTORADIO_H #define BLINKTORADIO_H enum { #endif TIMER_PERIOD_MILLI = 250 ; File: Makefile COMPONENT=BlinkToRadioAppC include $(MAKERULES) 10

Defining a Message Structure File: BlinkToRadio.h #ifndef BLINKTORADIO_H #define BLINKTORADIO_H enum { TIMER_PERIOD_MILLI = 250 ; typedef nx_struct BlinkToRadioMsg { nx_uint16_t nodeid; nx_uint16_t counter; BlinkToRadioMsg; #endif 11

Sending a Message 1) Identify the interfaces (and components) that provide access to the radio and allow us to manipulate the message_t type. 2) Update the module block in the BlinkToRadioC.nc by adding uses statements for the interfaces we need: File: BlinkToRadioC.nc module BlinkToRadioC { uses interface Boot; uses interface Leds; uses interface Timer<TMilli> as Timer0; uses interface Packet; uses interface AMPacket; uses interface AMSend; uses interface SplitControl as AMControl; 12

Sending a Message 3) Declare any new variables and add any needed initialization code. File: BlinkToRadioC.nc implementation { bool busy = FALSE; message_t pkt; uint16_t counter = 0; event void Boot.booted() { call Timer0.startPeriodic(TIMER_PERIOD_MILLI); event void Timer0.fired() { counter++; call Leds.set(counter); 13

Sending a Message 3) Declare any new variables and add any needed initialization code. File: BlinkToRadioC.nc implementation { bool busy = FALSE; message_t pkt; uint16_t counter = 0; event void Timer0.fired() { counter++; call Leds.set(counter); event void Boot.booted() { call AMControl.start(); event void AMControl.startDone(error_t err) { if (err == SUCCESS) { call Timer0.startPeriodic(TIMER_PERIOD_MILLI); else { call AMControl.start(); event void AMControl.stopDone(error_t err) { 14

Sending a Message 4. Add any program logic and calls to the used interfaces we need for our application. File: BlinkToRadioC.nc implementation { event void Timer0.fired() { counter++; call Leds.set(counter); if (!busy) { BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)( call Packet.getPayload(&pkt, sizeof (BlinkToRadioMsg)) ); btrpkt->nodeid = TOS_NODE_ID; btrpkt->counter = counter; if (call AMSend.send(AM_BROADCAST_ADDR, &pkt, sizeof(blinktoradiomsg)) == SUCCESS) { busy = TRUE; 15

Sending a Message 5. Implement any (non-initialization) events specified in the interfaces we plan on using. File: BlinkToRadioC.nc implementation { /** * Signaled in response to an accepted send request. msg is * the message buffer sent, and error indicates whether * the send was successful. * * @param msg the packet which was submitted as a send request * @param error SUCCESS if it was sent successfully, FAIL if it was not, * ECANCEL if it was cancelled * @see send * @see cancel */ event void senddone(message_t* msg, error_t error); event void AMSend.sendDone(message_t* msg, error_t error) { if (&pkt == msg) { busy = FALSE; 16

Sending a Message 6. Update the implementation block of the application configuration file by adding a components statement for each component used that provides one of the interfaces chosen earlier. File: BlinkToRadioAppC.nc implementation {... components ActiveMessageC; components new AMSenderC(AM_BLINKTORADIO);... File: BlinkToRadio.h... enum {... AM_BLINKTORADIO = 6, TIMER_PERIOD_MILLI = 250 ; 17

Sending a Message 7. Wire the the interfaces used by the application to the components which provide those interfaces. File: BlinkToRadioAppC.nc implementation {... App.Packet -> AMSenderC; App.AMPacket -> AMSenderC; App.AMSend -> AMSenderC; App.AMControl -> ActiveMessageC;... 18

Receiving a Message over the Radio Tmote Sky & Tiny OS 1. Identify the interfaces (and components) that provide access to the radio and allow us to manipulate the message_t type. We will use the Receive interface to receive packets. 2. Update the module block in the BlinkToRadioC.nc by adding uses statements for the interfaces we need: File: BlinkToRadioC.nc module BlinkToRadioC {... uses interface Receive; 3. Declare any new variables and add any needed initialization code. We will not require any new variables to receive and process messages from the radio. 4. Add any program logic and calls to the used interfaces we need for our application. Message reception is an event-driven process so we do not need to call any commands on the Receive. 19

Receiving a Message over the Radio Tmote Sky & Tiny OS 5. Implemement any (non-initialization) events specified in the interfaces we plan on using. We need to implement the Receive.receive event handler: event message_t* Receive.receive(message_t* msg, void* payload, uint8_t len) { if (len == sizeof(blinktoradiomsg)) { return msg; BlinkToRadioMsg* btrpkt = (BlinkToRadioMsg*)payload; call Leds.set(btrpkt->counter); 6. Update the implementation block of the application configuration file by adding a components statement for each component used that provides one of the interfaces chosen earlier. implementation {...... components new AMReceiverC(AM_BLINKTORADIO); 20

Receiving a Message over the Radio Tmote Sky & Tiny OS 7. Wire the the interfaces used by the application to the components which provide those interfaces. File: BlinkToRadioAppC. implementation {... App.Receive -> AMReceiverC; 21

Receiving a Message over the Radio 8. Test your application! Tmote Sky & Tiny OS $ motelist $ make telosb install bsl,/dev/ttyusb0 $ make telosb reinstall bsl,/dev/tty/usb1 22