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
• 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
person
event
Base Station
vehicle
event
mapping
object type: VEHICLE
object ID: vehicle01
object type: PERSON
object ID: person01
attribute: location
attribute: location
method:
report location to the
base station every 5
seconds
method:
turn on a nearby microphone if current location
is less than 1 mile away
from the base station
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 Type: Person
Context Label
Context Label
Tracking
Objects
Aggregate
State
Variables
Tracking
Objects
Network Abstraction Layer
Aggregate
State
Variables
External
Entity
Contexts and Objects
• Contexts: Encapsulate entity state and tracking objects
• Tracking objects: Perform entity-specific computation,
communication and sensing
Attached
Tracking
Objects
Programmer’s
View
Context
State
Entity
History
ID
Communication

Objects may export methods for remote invocation
Attached
Tracking
Objects
Attached
Tracking
Objects
Context
Programmer’s
View
State
Context
Attaching Objects
begin object reporter
begin context tracker
send (state, home);
sense: magnetic() + motion();
end
state: location = avg (position,3,2); begin object mic
end
turn-on microphone
send (sound, home);
Attach
end
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
Middleware APIs
• Group Management
–
–
–
–
–
Create
Terminate
Merge
Join/Leave
Assign function
• Track target
• Classify target
• Map temperature region
– Consensus
Group Management
IR Camera
Group Management
IR Camera
Examples: Tracking and
Map Regions
Base Station
Group Management - API
– Create_Group(name,function,criterion,atleast,acc
–
–
–
–
–
–
–
–
uracy) - 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 reconfigurations
API for Other Services
•
•
•
•
•
•
Naming
Directory
Location
Monitor
Configure
…
Virtual Machine - Mate
24 Instruction Programs
Code capsules
Mate VM
(interprets)
TinyOS
Each instruction
executes as task
(slow)
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
Propagation Example
Node Enters the Network
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
Code capsules
3
- Sound alarm
1 - Write to flash
Mate VM
(interprets)
TinyOS
Instructions
Understood by
Mate
User defined
1 2 3 4
Mate Architecture

2
3
gets/sets
PC
Operand
Stack
Return
Stack
Receive
•
1
Events
Send
0
Code
Clock timer
•Message reception
•Message send
Subroutines
Clock

Stack based architecture
 Operand stack
 Return address stack
Three events/execution
contexts:
Code Example(1)
• Display Counter to LED
gets
pushc 1
add
copy
sets
pushc 7
and
putled
halt
#
#
#
#
#
#
#
#
#
Push heap variable on stack
Push 1 on stack
Pop twice, add, push result
Copy top of stack
Pop, set heap
Push 0x0007 onto stack
Take bottom 3 bits of value
Pop, set LEDs to bit pattern
Code Example(2)
• Sense and Send
pushc 1
sense
pushm
clear
add
send
halt
#
#
#
#
#
#
#
Light is sensor 1
Push light reading on stack
Push message buffer on stack
Clear message buffer
Append reading to buffer
Send message using built-in
ad-hoc routing system
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
Heterogeneous
Battlefield
Networks
Industrial
Networks
Networks with
Sensors and Actuators
Building
Vehicle
Networks
(HNSAs)
Networks
Body
Networks
Motivating Applications
Home
Home Application 1:
Musical Tracking
Home Application 2:
Alarm System
Motivating Applications
Forest
Home
Forest Application 1:
Temperature
Monitoring2:
Forest Application
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:
Road
Wild Animal & Automobile Protection
MESSAGE
System Architecture
Programming
Station
Internet
Server
Local
Transport
Protocol
Nodes
Server
Local
Transport
Protocol
Nodes
System Architecture
Programming
Station
Internet
Server
Server
Local
Transport
Protocol
Local
Transport
Protocol
Nodes
Information about
Services, Interfaces
Location
Nodes
System Architecture
High level
Programming
Language
Programming
Station
EXE
Internet
High Level
Virtual Machine
Server
Server
Local
Transport
Protocol
Local
Transport
Protocol
Nodes
Low Level
Virtual Machine
High Level
Virtual Machine
Nodes
Low Level
Virtual Machine
System Architecture
Programming
Station
Internet
Server
Local
Transport
Protocol
Nodes
Server
Responsible for
Resource management
User access rights
Local
Transport
Protocol
Nodes
System Architecture
Programming
Station
Omnix Physical
Network
Server
Local
Transport
Protocol
The Physicalnet
Internet
Server
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
Questions
• What would have made your life easier
in doing the programming assignments?
• What makes it easier to get the system
to work?
– Debugging tools
• Initially (in programming environment)
• On real platform
Summary
• Very active area
– It must be
• Solutions can have large impact
– Applications programmers rather than
system experts
• Standard?
– Analogy to real-time computing and
programming languages?
• WSN-Java?
Descargar

No Slide Title