520 likes | 692 Views
Programming Abstractions in Wireless Sensor Networks. Professor Jack Stankovic Department of Computer Science University of Virginia. Importance. Raise the level of abstraction Move out of the domain of HW and embedded systems programmer
E N D
Programming AbstractionsinWireless Sensor Networks Professor Jack Stankovic Department of Computer Science University of Virginia
Importance • Raise the level of abstraction • Move out of the domain of HW and embedded systems programmer • Amplify the applications addressed – programmed by domain experts • More reliable • One of the most important areas of research to make WSN widely used
Context System Development Environment Analysis/Tools Use of System SQL/Queries Actual Programming Applications prog. Systems prog.
Programming Models (9) • Environmental (domain specific -> tracking, monitoring environment, medical…) • EnviroSuite • Data/Database Centric - Queries • SQL, TinyBD, Cougar • Statistical and range queries • Middleware APIs and Services • Group Management, Token machine language (Regiment), Milan (QoS based), Agilla • Support for other models • Components • Database • Event • Agent
Programming Models (9) • Components • nesC • Virtual Machines • Mate • Functional Macro-programming • Regiment (regions, streams) • (Mobile) Scripts • SensorWare • Extend TCL interpreter with support for commands such as query, send, wait, replicate, … • Provides execution environment for Scripts • Events • Publish/subscribe • DSWare, SNEDL, Impala
Programming Models (9) • Networks of Networks • Across the Internet
Abstractions • Program as a whole – not individual nodes • Hide details (which ones, expose what) • Single node decisions • Asynchrony • Race conditions • False alarms • Retries • Physical details (e.g., location, sensor characteristics, …) • Faults • Scale • Storage locations
Environmental Paradigm • Current Paradigms • Single node abstractions • Explicit interactions between nodes • Read sensor data; fuse data; move data • Set actuators • Environmental Paradigm • Reflect the physical world directly • Virtual world of entities (fire, people, vehicles, pesticide, velocity, location, areas, …)
EnviroSuite • Way to think • Events – measurable environmental activities • Events mapped to programming objects • Computation is attached to these objects • Report location, compute velocity, … • Library provides protocols for sensor data processing, object maintenance, inter-object coordination, aggregation mechanisms, etc.
EnviroSuite event-object VEHICLE { object_creation_condition = ferrous object && background sound object_resolution = 6; // minimal distance between // two events object_function = report.Location; object_function = report.Speed; } This statement is supported by drivers in a library: ferrous object && background sound
Level of Knowledge Required • Ferrous object • Which signal processing module? • What parameter specifications need to be made? • We are programming in an application that interacts with the environment – how divorced from that fact can the programmer be?
Programming Model Context Type: Car Context Label Context Type: Person Context Label Tracking Objects Tracking Objects Aggregate State Variables Aggregate State Variables External Entity Network Abstraction Layer
Contexts and Objects • Contexts: Encapsulate entity state and tracking objects • Tracking objects: Perform entity-specific computation, communication and sensing Attached Tracking Objects Context State Programmer’s View Entity History ID
Communication • Objects may export methods for remote invocation Attached Tracking Objects Attached Tracking Objects Context Context State Programmer’s View
Attaching Objects begin contexttracker sense: magnetic() + motion(); state: location = avg (position,3,2); end begin objectreporter send (state, home); end begin objectmic turn-on microphone send (sound, home); end Attach Statee( ) = average position Programmer’s View Entity History Members ID Leader Sensee( ) = TRUE
Summary • Program in C++ or Java – like language • Library supports domain specific abstractions • E.g., Java Swing supports programming GUIs • Pre-compiler maps programming abstractions to underlying “system” • E.g., could map to nesC and TinyOS
Middleware APIs • Group Management • Create • Terminate • Merge • Join/Leave • Assign function • Track target • Classify target • Map temperature region • Consensus
Group Management IR Camera Leader Follower Member Node
Group Management IR Camera Leader Follower Member Node
Examples: Tracking andMap Regions Base Station
Group Management - API • Create_Group(name,function,criterion,atleast,accuracy) - implicit and explicit • Destroy_Group(name) • Join() • Leave() • Merge() • Move_COG() • Expand() -- to gain sensing confidence • Shrink() -- to save power • Commit(grp_ID) - to synchronize group re-configurations
API for Other Services • Naming • Directory • Location • Monitor • Configure • …
Virtual Machine - Mate 24 Instruction Programs Each instruction executes as task (slow) Code capsules Mate VM (interprets) TinyOS
Code Capsules • One capsule = 24 instructions • Fits into single TOS packet • Energy efficient • Atomic reception • Code Capsule • Type and version information • Types: send, receive, timer, subroutine • Larger programs – use several capsules
Value • Re-programmability • Re-task a network • Parameter adjustment • Self-replication • One of the special instructions on the VM is forward (which supports a viral-like infection of the entire network) • Incremental addition of new nodes
Instruction Set • One byte per instruction • Three classes: basic, s-type, x-type • basic: arithmetic, halting, LED operation • s-type: messaging system • x-type: pushc, blez • 8 instructions reserved for users to define • Instruction polymorphism • Example: add(data, message, sensing)
User Defined Instructions 24 Instruction Programs 1 3 Instructions Understood by Mate User defined Code capsules Mate VM (interprets) - Sound alarm TinyOS 3 1 2 3 4 - Write to flash 1
Mate Architecture • Stack based architecture • Operand stack • Return address stack • Three events/execution contexts: • Clock timer • Message reception • Message send
Code Example(1) • Display Counter to LED
Code Example(2) • Sense and Send
TinyOS Sense and Send event result_t Timer.fired() { if (state == IDLE && call Photo.sense()) {state = SENSE;} return SUCCESS; } event result_t Photo.dataReady(uint16_t data) { if (state == SENSE) { packet->reading = data; if (call SendMsg.send(packet, sizeof(DataBuf)) { state = SENDING; } else {state = IDLE;} } return SUCCESS; } event result_t SendMsg.sendDone(TOS_MsgPtr msg) { if (state == SENDING) {state = IDLE;} return SUCCESS; }
Component Breakdown • 7286 bytes code, 603 bytes RAM
Summary • Layer of software that can interpret programs • Easy to download new programs • Power of VM will relate to ease of programming • E.g., Java versus Mate
Networks of Networks Road and Street Networks Environmental Networks Industrial Networks Heterogeneous Networks with Sensors and Actuators (HNSAs) Battlefield Networks Building Networks Vehicle Networks Body Networks
Motivating Applications Home Home Application 1: Musical Tracking Home Application 2: Alarm System
Motivating Applications Forest Home Forest Application 1: Temperature Monitoring Forest Application 2: Animal Tracking
Motivating Applications Forest Home Road Application 1: Traffic Monitoring Road Application 2: Traffic Law Enforcement Road MESSAGE
Motivating Applications Forest Home Road Cross Network Application 1: Protection Against Wild Animals
Motivating Applications Forest Home Cross Network Application 2: Wild Animal & Automobile Protection Road MESSAGE
System Architecture Programming Station Internet Server Server Local Transport Protocol Local Transport Protocol Nodes Nodes
System Architecture Programming Station Internet Server Server Local Transport Protocol Local Transport Protocol Nodes Nodes Information about Services, Interfaces Location
System Architecture High level Programming Language Programming Station EXE Internet High Level Virtual Machine High Level Virtual Machine Server Server Local Transport Protocol Local Transport Protocol Nodes Nodes Low Level Virtual Machine Low Level Virtual Machine
System Architecture Programming Station Internet Server Server Local Transport Protocol Local Transport Protocol Responsible for Resource management User access rights Nodes Nodes
System Architecture Programming Station The Physicalnet Omnix Physical Network Internet Server Server Local Transport Protocol Local Transport Protocol Nodes Nodes Omnix Physical Network
Summary • Future Problem • Java-like language with different levels of VMs
Questions • What should a programmer see? • New language • New middleware • Services • Components • Abstract models • All the above • None of the above