Cyber-Physical Programming

Slides:



Advertisements
Similar presentations
How to use TinyOS Jason Hill Rob Szewczyk Alec Woo David Culler An event based execution environment for Networked Sensors.
Advertisements

A System Architecture for Tiny Networked Devices
1 Tomás Sánchez López July 9, 2004 Real-time & Embedded Systems Laboratory TinyOS … in deep.
NesC Prepared for the Multimedia Networks Group University of Virginia.
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
Application Fundamentals Android Development. Announcements Posting in D2L Tutorials.
Overview: Chapter 7  Sensor node platforms must contend with many issues  Energy consumption  Sensing environment  Networking  Real-time constraints.
1 Lab4 Objectives  Learn to read light sensor data from sensor board  Learn to transmit a message containing the sensed data  through Mote serial port.
Mote Programming. 如何 compile 程式  make [re]install. : desired device address : target platform  install vs. reinstall install : compile the application.
Threads, SMP, and Microkernels Chapter 4. Process Resource ownership - process is allocated a virtual address space to hold the process image Scheduling/execution-
TinyOS Introduction Advanced Computer Networks. TinyOS Outline  Introduction to the Architecture of TinyOS and nesC  Component Model –Components, interfaces,
Chapter 13 Embedded Systems Patricia Roy Manatee Community College, Venice, FL ©2008, Prentice Hall Operating Systems: Internals and Design Principles,
Towards System Architecture for Tiny Networked Devices David Culler U.C. Berkeley Wireless hoo-hah 5/30/2000.
Contiki A Lightweight and Flexible Operating System for Tiny Networked Sensors Presented by: Jeremy Schiff.
TinyOS Tutorial Communication Networks I Wenyuan Xu Fall 2006.
How to Code on TinyOS Xufei Mao Advisor: Dr. Xiang-yang Li CS Dept. IIT.
7/13/2007AIIT Summer Course - D#1 Wireless Embedded Systems and Networking Lab Day 5: Part 1: TinyOS Programming on Open Source Distribution Jaein Jeong.
Programming Motes A TinyOS and TOSSIM Tutorial By: Brent Rood.
1 TinyOS Network Communication Computer Network Programming Wenyuan Xu Fall 2007.
Development of a Mica2 Mote Sensor Network Cliff Macklin Bill Ehrbar December 8, 2004 University of Colorado, Colorado Springs.
2008EECS Embedded Network Programming nesC, TinyOS, Networking, Microcontrollers Jonathan Hui University of California, Berkeley.
1 EE249 Discussion System Architecture Directions for Networked Sensors (J. Hill, et al) Presented By: Sarah Bergbreiter EE249 Discussion Section October.
NesC: 1.1 Bumps and Future Directions David Gay, Intel Research, Berkeley (and the nesC and TinyOS teams)
1 Lab 3 Objectives  Case study: “Hello world” program on motes  Write you first program on mote.
TinyOS Tutorial Based on Wenyuan Xu’s slides ( NetsF06/Comnet_TinyOS_Tutorial_xwy.ppt)
1 Software Development Infrastructure for Sensor Networks  Operating systems ( TinyOS )  Resource (device) management  Basic primitives  Protocols.
TinyOS Tutorial Jianping Wang (merge several tutorials found online)
1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using XServe to display the sensor data message on.
@2011 Mihail L. Sichitiu1 Android Introduction Platform Overview.
April 15, 2005TinyOS: A Component Based OSPage 1 of 27 TinyOS A Component-Based Operating System for Networked Embedded Systems Tom Bush Graduate College.
1 TinyOS Computer Network Programming Wenyuan Xu Fall 2007.
TinyOS 1/2 Onsystech Sangjae Han.
Mobile Application Development using Android Lecture 2.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
10/10/2015 E.R.Edwards 10/10/2015 Staffordshire University School of Computing Introduction to Android Overview of Android System Android Components Component.
HW2: Q&A Oct. 02, Lab Machine TinyOS is installed in one machine (531AB). But, you have to bring your kit. There is a sign up sheet. Please sign.
Wireless Sensor Networks MOTE-KITS TinyOS Crossbow UC Berkeley.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Light Sense Lab. Read data from light(photo diode) sensor, display using oscilloscope.
Dhanshree Nimje Smita Khartad
System Architecture Directions for Networked Sensors Jason Hill, Robert Szewczyk, Alec Woo, Seth Hollar, David Culler, Kris Pister Presented by Yang Zhao.
Lab 3 Introduction to TinyOS and nesC How to debug programs at PC Examples –Blink Timer –Blink –Hellow World Reference: 1.x/doc/tutorial/lesson1.html.
Simulation of Distributed Application and Protocols using TOSSIM Valliappan Annamalai.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 TinyOS & NesC.
Part 2 TinyOS and nesC Programming Selected slides from:
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Wireless MAC Practice (MAC I)
Main Issues Three major issues that we are concerned with in sensor networks are – Clustering Routing and Security To be considered against the backdrop.
Xiong Junjie Node-level debugging based on finite state machine in wireless sensor networks.
WSN Software Platforms - concepts Vinod Kulathumani Lecture uses some slides from tutorials prepared by authors of these platforms.
Lab 3, Part 2 Selected slides from: Wireless Sensor Networks Hardware/Software Tiny OS & NesC Programming borrowed from Turgay Korkmaz.
TinyOS Sandeep Gupta. Operating System (OS) What is an OS? Main functions  Process management  Memory management  Resource management Traditional OSs.
Services Background operating component without a visual interface Running in the background indefinitely Differently from Activity, Service in Android.
System Architecture Directions for Networked Sensors.
HANBACK ELECTRONICS CO., LTD. 저자권 보호됨 Lab1: LED Control ZigbeX mote has Red, Yellow, Green LED. This lab using LED control component provided by TinyOS.
Based on slides from Andreas Larsson Table from CY Chong, SP Kumar, BA Hamilton - Proceedings of the IEEE, 2003.
Blink Blink.nc configuration Blink { } implementation { components Main, BlinkM, SingleTimer, LedsC; Main.StdControl -> BlinkM.StdControl; Main.StdControl.
Feb 2007WSN Training: XMesh Enabled Sensor App1 Lab 5 Objectives  Use XMesh multi-hop networking service to send sensing data to a base station  Using.
Nguyen Thi Thanh Nha HMCL by Roelof Kemp, Nicholas Palmer, Thilo Kielmann, and Henri Bal MOBICASE 2010, LNICST 2012 Cuckoo: A Computation Offloading Framework.
Why does it need? [USN] ( 주 ) 한백전자 Background Wireless Sensor Network (WSN)  Relationship between Sensor and WSN Individual sensors are very limited.
The Ingredients of Android Applications. A simple application in a process In a classical programming environment, the OS would load the program code.
Software Architecture of Sensors. Hardware - Sensor Nodes Sensing: sensor --a transducer that converts a physical, chemical, or biological parameter into.
TinyOS Sandeep Gupta. TinyOS basics TinyOS is  Single tasking OS  Interrupt driven Written using a Component based language A set of components put.
Tinyos Introduction to Programming Pritee Parwekar.
Implementing Context Aware Applications Class 5. Agenda Review of TinyOS execution model Tutorial on TinyOS Code walk through Code quiz Assignment 2.
Simulation of Distributed Application and Protocols using TOSSIM
Android Mobile Application Development
An Introduction to nesC
Embedded Operating Systems
SenseToRfm SenseToInt.Timer -> TimerC; configuration SenseToRfm {
Modeling Event-Based Systems in Ptolemy II EE249 Project Status Report
Presentation transcript:

Cyber-Physical Programming

Interacting With The Physical World Physical Systems Embedded Sensing and Actuation Wireless Sensor Network Cyber-Physical Systems (CPS) 2

CPS System Model Computing Requirements Reliability Accuracy Computing System Physical System Continuous physical process Computing Requirements Reliability Accuracy Throughput Security Safety Physical Requirements Safety Energy efficiency Low carbon footprint Multi-dimensional Partial Differential Equations Discrete Control Algorithm Actuator Sensor Dynamic contexts Unintended Side Effects Random Processes Discrete Control Algorithm Talk about CPSes Software failure issues Characterizing interactions Fast simulations Dynamic contexts Theoretical gurantees Cyber-Physical Interactions (CPI) Spatio-Temporal Aggregate Effects Dynamic Contexts Systems with context driven spatio-temporal, aggregate effects are cyber-physical systems (CPS)

Sensor Programming

What is TinyOS? An operation system An open-source development environment Not an operation system for general purpose, it is designed for wireless embedded sensor network. Official website: http://www.tinyos.net/ Programming language: NesC (an extension of C) It features a component-based architecture. Supported platforms include Linux, Windows 2000/XP with Cygwin.

Characteristics of Network Sensors Small physical size and low power consumption Concurrency-intensive operation multiple flows, not wait-command-respond Limited Physical Parallelism and Controller Hierarchy primitive direct-to-device interface Diversity in Design and Usage application specific, not general purpose huge device variation => efficient modularity => migration across HW/SW boundary Robust Operation numerous, unattended, critical => narrow interfaces sensors actuators network storage

A Operating System for Tiny Devices? Main Concept HURRY UP AND SLEEP!! Sleep as often as possible to save power provide framework for concurrency and modularity Commands, events, tasks interleaving flows, events - never poll, never block Separation of construction and composition Programs are built out of components Libraries and components are written in nesC. Applications are too -- just additional components composed with the OS components Each component is specified by an interface Provides “hooks” for wiring components together Components are statically wired together based on their interfaces Increases runtime efficiency

TinyOS Architecture HPL: Hardware Presentation Layer Hardware Platform 1 Hardware Platform 2 Hardware Platform 3 HPL 1 HPL 2 HPL 3 HAL 1 HAL 2 HAL 3 HIL 1 HIL 2 HIL 3 Generic Hardware Interface Platform Specific Applications Cross Platform Applications HPL: Hardware Presentation Layer HAL: Hardware Adaptation Layer HIL: Hardware Interface Layer

Hardware Presentation Layer Start and stop commands for the powering up and down the hardware device, get and set commands to read and write the registers associated with the hardware, commands for enabling and disabling interrupts generated by the hardware, service routines for the interrupts often called event handlers, and customized functions for operating on flags specific to a given hardware component.

Hardware Adaptation Layer The HAL layer of abstraction lies above the HPL layer which further abstracts the basic interfaces provided by HPL for a hardware to task specic interfaces. For example, if two sensors provide the same Universal asynchronous receiver/ transmitter (UART) interface then, HAL groups them into one.

Hardware Interface Layer HIL is a higher level of abstraction than HAL. It takes the interfaces provided by the HAL and represents them as application specific functionalities. For example, a HIL can take a sensor and timer component and build a new component that allows interface to periodically query the sensor.

Programming TinyOs A component provides and uses interfaces. A interface defines a logically related set of commands and events. Components implement the events they use and the commands they provide: There are two types of components in nesC: Modules. It implements application code. Configurations. It assemble other components together, called wiring A component does not care if another component is a module or configuration A component may be composed of other components via configurations Component Commands Events Use Can call Must implement Provide Can signal

Component Syntax - Module A component specifies a set of interfaces by which it is connected to other components provides a set of interfaces to others uses a set of interfaces provided by others module ForwarderM { provides { interface StdControl; } uses { interface StdControl as CommControl; interface ReceiveMsg; interface SendMsg; interface Leds; implementation { …// code implementing all provided commands and used events ForwarderM StdControl ReceiveMsg provides uses CommControl SendMsg Leds

Component Syntax - Configuration configuration Forwarder { } implementation { components Main, LedsC; components GenericComm as Comm; components ForwarderM; Main.StdControl -> ForwarderM.StdControl; ForwarderM.CommControl -> Comm; ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; ForwarderM.Leds -> LedsC; } Component Selection Wiring the Components together ForwarderM StdControl ReceiveMsg provides uses CommControl SendMsg Leds Main LedsC GenericComm Forwarder

Configuration Wires A configuration can bind an interface user to a provider using -> or <- User.interface -> Provider.interface Provider.interface <- User.interface Bounce responsibilities using = User1.interface = User2.interface Provider1.interface = Provider2.interface The interface may be implicit if there is no ambiguity e.g., User.interface -> Provider 

Interface Syntax- interface StdControl Look in <tos>/tos/interfaces/StdControl.nc Multiple components may provide and use this interface Every component should provide this interface This is good programming technique, it is not a language specification interface StdControl { // Initialize the component and its subcomponents. command result_t init(); // Start the component and its subcomponents. command result_t start(); // Stop the component and pertinent subcomponents command result_t stop(); }

Interface Syntax- interface SendMsg Look in <tos>/tos/interfaces/SendMsg.nc Includes both command and event. Split the task of sending a message into two parts, send and sendDone. includes AM; // includes AM.h located in <tos>\tos\types\ 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); }

Component implementation module ForwarderM { //interface declaration } implementation { command result_t StdControl.init() { call CommControl.init(); call Leds.init(); return SUCCESS; command result_t StdControl.start() {…} command result_t StdControl.stop() {…} event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; Command implementation (interface provided) Event implementation (interface used)

TinyOS Commands and Events { ... status = call CmdName(args) } command CmdName(args) { ... return status; } event EvtName)(args) { ... return status; } { ... status = signal EvtName(args) }

TinyOs Concurrency Model TinyOS executes only one program consisting of a set of components. Two type threads: Task Hardware event handler Tasks: Time flexible Longer background processing jobs Atomic with respect to other tasks (single threaded) Preempted by event Hardware event handlers Time critical Shorter duration (hand off to task if need be) Interrupts task and other hardware handler. Last-in first-out semantics (no priority among events) executed in response to a hardware interrupt

Tasks Provide concurrency internal to a component longer running operations Scheduling: Currently simple FIFO scheduler Bounded number of pending tasks When idle, shuts down node except clock Uses non-blocking task queue data structure Simple event-driven structure + control over complete application/system graph instead of complex task priorities and IPC { ... post TaskName(); } task void TaskName { ... }

TinyOS Execution Contexts Hardware Interrupts events commands Tasks Events generated by interrupts preempt tasks Tasks do not preempt tasks Both essential process state transitions

Event-Driven Sensor Access Pattern command result_t StdControl.start() { return call Timer.start(TIMER_REPEAT, 200); } event result_t Timer.fired() { return call sensor.getData(); event result_t sensor.dataReady(uint16_t data) { display(data) return SUCCESS; SENSE Timer Photo LED clock event handler initiates data collection sensor signals data ready event data event handler calls output command device sleeps or handles other activity while waiting conservative send/ack at component boundary

Inter-Node Communication General idea: Sender: Receiver: Determine when message buffer can be reused Fill message buffer with data Specify Recipients Pass buffer to OS OS obtains free buffer to store next message OS Buffers incoming message in a free buffer Signal application with new message

TOS Active Messages Message is “active” because it contains the destination address, group ID, and type. ‘group’: group IDs create a virtual network an 8 bit value specified in <tos>/apps/Makelocal The address is a 16-bit value specified by “make” – make install.<id> mica2 “length” specifies the size of the message . “crc” is the check sum typedef struct TOS_Msg { // the following are transmitted uint16_t addr; uint8_t type; uint8_t group; uint8_t length; int8_t data[TOSH_DATA_LENGTH]; uint16_t crc; // the following are not transmitted uint16_t strength; uint8_t ack; uint16_t time; uint8_t sendSecurityMode; uint8_t receiveSecurityMode; } TOS_Msg; Preamble Header (5) Payload (29) CRC (2) Sync

TOS Active Messages (continue)

Sending a message Define the message format includes Int16Msg; module ForwarderM { //interface declaration } implementation { event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; destination length Define the message format Define a unique active message number How does TOS know the AM number? struct Int16Msg { uint16_t val; }; enum { AM_INTMSG = 47 File: Int16Msg.h configuration Forwarder { } implementation { … ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; }

Receiving a message Define the message format includes Int16Msg; module ForwarderM { //interface declaration } implementation { event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m) { call Leds.yellowToggle(); call SendMsg.send(TOS_BCAST_ADDR, sizeof(IntMsg), m); return m; event result_t SendMsg.sendDone(TOS_MsgPtr msg, bool success) { call Leds.greenToggle(); return success; Message received Define the message format Define a unique active message number How does TOS know the AM number? struct Int16Msg { uint16_t val; }; enum { AM_INTMSG = 47 File: Int16Msg.h configuration Forwarder { } implementation { … ForwarderM.SendMsg -> Comm.SendMsg[AM_INTMSG]; ForwarderM.ReceiveMsg -> Comm.ReceiveMsg[AM_INTMSG]; }

Further Reading TinyECC Go through the on-line tutorial: http://discovery.csc.ncsu.edu/software/TinyECC/ Go through the on-line tutorial: http://www.tinyos.net/tinyos-1.x/doc/tutorial/index.html Search the help archive: http://www.tinyos.net/scoop/special/support#mailing-lists NesC language reference manual: http://www.tinyos.net/tinyos-1.x/doc/nesc/ref.pdf Getting started guide http://www.xbow.com/Support/Support_pdf_files/Getting_Started_Guide.pdf Hardware manual: http://www.xbow.com/Support/Support_pdf_files/MPR-MIB_Series_Users_Manual.pdf

Install TinyOS and the ‘make’ Download http://www.tinyos.net/download.html Directory Structure /apps /Blink /Forwarder /contrib /doc /tools /java /tos /interfaces /lib /platform /mica /mica2 /mica2dot /sensorboard /micasb /system /types From within the application’s directory: make (re)install.<node id> <platform> <node id> is an integer between 0 and 255 <platform> may be mica2, mica2dot, or all Example: make install.0 mica2 make pc Generates an executable that can be run a pc for

Build Tool Chain Convert NesC into C and compile to exec Modify exec with platform-specific options Set the mote ID Reprogram the mote

Android Overview

Android Architecture

Application Components Activities Services Broadcast Receivers Content Providers Intents Activities and Tasks Process and Threads Remote Procedure Calls

Activities An activity presents a visual user interface for one focused endeavor the user can undertake. Activity is implemented as a subclass of the Activity base class. The visual content of the window is provided by a hierarchy of views. objects derived from the base View class. A view hierarchy is placed within an activity's window by the Activity.setContentView() method.

Activity example Activity definition Create Method callback – For init Button view inside the Activity

Activity Lifecycle An activity has essentially three states Active or Running Paused Stopped Activity Lifetime Entire Lifetime [onCreate() to onDestroy()] Visible Lifetime [onStart() to onStop()] Foreground Lifetime [onResume() to onPause()] An implementation of any activity lifecycle method should always first call the superclass version

Activity Lifecycle

Services A Service does not have a visual interface and runs in the background. Each service extends the Service base class. It's possible to connect to an ongoing service and communicate it through the interface exposed by that service. Services run in the main thread of the application process. Examples Network Downloads Playing Music TCP/UDP Server

Service example Service definition Message handler queue Create Method callback – For init

Service Lifecycle A service can be used in two ways Service Lifetime startService() – stopService() bindService() – unbindService() Service Lifetime Entire Lifetime [onCreate() to onDestroy()] Active Lifetime [onStart()] The onCreate() and onDestroy() methods are called for all services. onStart() is called only for services started by startService().

Service Lifecycle

Broadcast Receivers A broadcast receiver receive and react to broadcast announcements. All receivers extend the BroadcastReceiver base class. Many broadcasts originate in system code. Broadcast receivers do not display a user interface but they can start an activity or alert user.

Broadcast receiver Lifecycle A broadcast receiver has single callback method onReceive() The lifetime of a broadcast receiver is only during the execution of onReceive() method. A process with an active broadcast receiver is protected from being killed.

Broadcast receiver example Broadcast receiver definition Callback on Broadcast receive

Content Providers A content provider makes a specific set of the application's data available to other applications. It’s the only way to transfer data between applications in Android (no shared files, shared memory, pipes, etc.) All content providers extends the ContentProvider base class. Content Providers are accessed through ContentResolver object. Content Providers and Content Resolvers enable inter-process communication (IPC)

Content Provider Example Create database and run transactions on it

Intents Intents are Asynchronous messages used to convey a request or message. An intent is an object of Intent class that holds the content of the message. Activities, Services and Broadcast Receivers are activated through Intents. Intent can contain Component name Action Data Category Extras Flags

Intent Examples Intent to start Activity Intent to start Service Intent to start Broadcast listener

Configurable Architectural Model Specification Health-Dev Sensor code Configurable Architectural Model Specification Model Parser Code Generator Download Smart phone code Code Database

Trustworthy Data Manager (TDM) A middleware to provide critical interfaces to MMA. Intercepts inter-app and external device communication and Dynamically checks S3 requirements Mobile OS App 1 App 2 App3 TDM Runtime Requirements Validator Figure showing the databases and model current status Safety Simulator Security Simulator Sustainability Simulator Current System State Requirements Database Sensors Actuator Cloud

Reference “Programming TinyOS”, David Culler, Phil Levis, Rob Szewczyk, Joe Polastre University of California, BerkeleyIntel Research Berkeley “TinyOS Tutorial”, Chien-Liang Fok, http://www.princeton.edu/~wolf/EECS579/imotes/tos_tutorial.pdf “Computer Networks”, Badri Nath http://www.cs.rutgers.edu/dataman/552dir/notes/week2-one.pdf