Beruflich Dokumente
Kultur Dokumente
October 2010
October 2010
1 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
2 / 51
Basics
http://www.ibr.cs.tu-bs.de/alg/winterschool/
There youll also nd material for practical lessons
October 2010
3 / 51
Session structure
Talk
October 2010
4 / 51
Sessions
Monday
Session 1: Introduction & Preliminaries (Henning Hasemann) Session 2: Wiselib Programming Basics (Tobias Baumgartner)
Tuesday
Session 3: Combining Algorithms Into Higher-Level Systems (Henning Hasemann) Session 4: Insight Into Wiselib Internals (Tobias Baumgartner)
Wednesday
Semantics Workshop (Dr. Alexandre Passant, Dr. Marcel Karnstedt, Myriam Leggieri)
October 2010
5 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
6 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
7 / 51
October 2010
8 / 51
Solution
The Wiselib
A library of about 50 algorithms, lots more to come! These are
Extensible Combineable Exchangeable
http://wiselib.org
There youll nd:
The Documentation Wiki The Wiselib Sourcecode The Bugtracker Instructions on how to download & install the Wiselib
October 2010
10 / 51
Wiselib Distributions
Testing
Under development Not necessarily tested on all platforms New things that may still change their interface Release early, release often https://svn.itm.uni-luebeck.de/wisebed/wiselib/trunk/
wiselib.testing
Stable
Tested on all supported platforms Interfaces will not change anymore https://svn.itm.uni-luebeck.de/wisebed/wiselib/trunk/
wiselib.stable
Henning Hasemann (IBR) Wiselib School 2010 October 2010 11 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
12 / 51
Platform Independence
When scientists all over the world work together, they likely use
Platform Independence
iSense iMote2 ScatterWeb MSB Tmote Sky
Hardware Jennic Operating System iSense ROM / RAM 128kB / 92kB Memory Management Dynamic Programming Language C++
Intel XScale
MSP430
MSP 430
TinyOS
Scatterweb / Contiki
Contiki / TinyOS
32MB / 32MB
48kB / 10kB
48kB / 10kB
Dynamic
Static
Dynamic
nesC
C, nesC
October 2010
14 / 51
Platform Independence
Some platforms do not provide dynamic memory And/or have limited RAM Some do not provide a C++ environment No libstdc++ So no exception handling, RTTI, virtual inheritance, etc...
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
16 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
17 / 51
Memory Management
Platform independence demands:
No malloc/free or new/delete
Constructors of global/static variables will be called before main() . . . in undened order! That can be very undesirable:
1 Radio r a d i o ; 2 S o m e A l g o r i t h m a l g o ( r a d i o ) ; // Might r e c e i v e uninitialized radio !
Provide init()/destruct() methods, call them manually Hide initialization method of system objects (Facets)
October 2010
18 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
19 / 51
Inheritance
Problem: Virtual inheritance is not portable. What would we use virtual inheritance for?
Code reuse Base class provides functionality which can be used by derived class
Still possible with non-virtual inheritance
Abstraction Dene an interface which classes can use to interact with each other
An algorithm only has to know the interface of the things its using, the
We want both!
Do it with templates!
The interface is given by a piece of documentation, called Concept An algorithm expects a template parameter for the type of the
Abstraction
Concept
Describes behaviour of components E.g. A Radio has a void send(char*) method Only documentation
Model
Actual class Implements any number of concepts E.g. A routing protocol may implement the radio concept ...so it can be used like one
October 2010
21 / 51
There are other ways to provide abstraction In C, one would usually abstract with function pointers In C++ one would use virtual inheritance
October 2010
22 / 51
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
// C typedef struct { i n t (* v a l u e ) ( v o i d ) ; } Concept ; int model value () { return 5; } C o n c e p t model = { . v a l u e = &m o d e l v a l u e } ; v o i d a l g o r i t h m ( Concept *c ) { // p o i n t e r o i n t e r u n c t i o n >p >f i n t v = c a l u e ( ) ; >v } i n t main ( i n t a r g c , c h a r ** a r g v ) { a l g o r i t h m (& model ) ; }
October 2010
23 / 51
October 2010
24 / 51
'
method
c l a s s Model { public : int value () { return 5; } }; t e m p l a t e<typename Concept P> c l a s s Algorithm { public : // r e f e r e n c e u n c t i o n >f v o i d i n i t ( C o n c e p t P& c ) { v = c . v a l u e ( ) ; } int v ; }; i n t main ( i n t a r g c , c h a r ** a r g v ) { Model m; A l g o r i t h m<Model> a ; a . i n i t (m) ; }
October 2010
25 / 51
Template-based design is space ecient! Template-based design produces fast code! Template-based design is portable!
October 2010
26 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
27 / 51
Types Of Concepts
OS Facet Concept
External Interface
Internal Interface
DS Model ...
October 2010
28 / 51
October 2010
29 / 51
Concept Organization
Lots of models Lots of concepts Models that behave similar should share concepts E.g. A routing algorithm should be usable like a radio
We want a (loose) hierarchy of concepts We want to express concept inheritance We want to have base concepts for general things
October 2010
30 / 51
Holds platform properties (like endianess, size type, etc...) Constants for return values Include at least SUCCESS and ERR UNSPEC (unspecied error) May/will include more, similar to errno Holds types of other OS Facets
October 2010
31 / 51
Concept Inheritance
1 concept RadioFacet { 2 t y p e d e f . . . OsModel ; 3 typedef . . . node id t ; 4 typedef . . . block data t ; 5 typedef . . . s i z e t ; 6 7 typedef . . . message id t ; 8 9 enum S p e c i a l N o d e I d s { 10 BROADCAST ADDRESS = . . . , 11 NULL NODE ID = ... 12 }; 13 enum R e s t r i c t i o n s { 14 MAX MESSAGE LENGTH = . . . 15 }; 16 17 int enable radio () ; 18 int disable radio () ; 19 20 i n t send ( n o d e i d t r e c e i v e r , b l o c k d a t a t *data ) ; 21 22 node id t id () ; 23 24 // . . . . 25 } ;
s i z e t len ,
October 2010
32 / 51
Base Concepts
BasicAlgorithm
+init(...): int +init(): int +destruct(): int
StateCallback
+READY +NO_VALUE +INACTIVE +register_state_callback(): int
State
+READY +NO_VALUE +INACTIVE +state(): int
Request
+typedef value_t +operator()(): value_t
Basic Algorithm Manual initialization & destruction (so the order is deneable) Request Produces values (can be polled with call-operator) State Object is not guaranteed to be able to operate all the time StateCallback Object can inform its user about state changes
Henning Hasemann (IBR) Wiselib School 2010 October 2010 33 / 51
Base Concepts
StateCallback
+READY +NO_VALUE +INACTIVE +register_state_callback(): int
State
+READY +NO_VALUE +INACTIVE +state(): int
Request
+typedef value_t +operator()(): value_t
BasicAlgorithm
+init(...): int +init(): int +destruct(): int
SensorFacet
VirtualSensor
+set_value(value:value_t): int
October 2010
34 / 51
Base Concepts
StateCallback
+READY +NO_VALUE +INACTIVE +register_state_callback(): int
State
+READY +NO_VALUE +INACTIVE +state(): int
Request
+typedef value_t +operator()(): value_t
BasicAlgorithm
+init(...): int +init(): int +destruct(): int
CallbackSensorFacet
October 2010
35 / 51
Base Concepts
StateCallback
+READY +NO_VALUE +INACTIVE +register_state_callback(): int
State
+READY +NO_VALUE +INACTIVE +state(): int
Request
+typedef value_t +operator()(): value_t
BasicAlgorithm
+init(...): int +init(): int +destruct(): int
Position
Localization
October 2010
36 / 51
Stackability
Idea: Things with similar behaviour should share a concept! Routing algorithms behave like radios
So do sensors!
Etc. . .
Benet
Say some algorithm uses a radio (i.e. transmits data) We can pass a routing algorithm instead And extend the algorithms functionality that way!
October 2010
37 / 51
Stackability
Create arbitrary complex
iSense Radio
applications
Just by plugging together algorithms
Here:
1 2 3
Physical radio by iSense AES-Encrypted node-to-node radio Routing, all packets AES-encrypted node-to-node All packets AES-encrypted node-to-node, payload ECC encrypted end-to-end
October 2010
38 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
39 / 51
Integration Demands
Wiselib components should be easily integrable into existing code We want and/or need the full power of the platform. Examples: Dynamically discover attached sensors Fine-tuned device conguration
BUT
Sometimes you want to run the same application on dierent
October 2010
40 / 51
Integration Mechanisms
Direct Integration
Retain full power of your platform Good if you have existing code Not portable
Generic Application
Write a Wiselib application class You can only access the operating system through facets But functionality will be limited to a common subset E.g. you have to write extremely portable C++ (no new/delete, RTTI, exceptions, . . . ) in order to retain portability
October 2010
41 / 51
Direct Integration
1 2 3 4 5 6 7 8 9 10 11 12 13 14
// . . . v o i d iSenseDemoApplication : : boot ( v o i d ) { o s . debug ( W i s e l i b E x a m p l e : : b o o t ) ; routing . enable () ; routing . reg recv callback< iSenseDemoApplication , &i S e n s e D e m o A p p l i c a t i o n : : r e c e i v e r o u t i n g m e s s a g e >( t h i s ) ; os . allow sleep ( f a l s e ) ; o s . a d d t a s k i n ( i s e n s e : : Time ( MILLISECONDS ) , t h i s , 0 ) ; } // . . .
October 2010
42 / 51
Generic Application
1 #i n c l u d e e x t e r n a l i n t e r f a c e / e x t e r n a l i n t e r f a c e . h 2 #i n c l u d e e x t e r n a l i n t e r f a c e / e x t e r n a l i n t e r f a c e t e s t i n g . h 3 // . . . 4 5 t y p e d e f w i s e l i b : : PCOsModel Os ; 6 c l a s s DemoApplication { 7 public : 8 v o i d i n i t ( Os : : AppMainParameter& amp ) { 9 r a d i o = & w i s e l i b : : F a c e t P r o v i d e r <Os , Os : : Radio >:: g e t f a c e t ( amp ) ; 10 d e b u g = & w i s e l i b : : F a c e t P r o v i d e r <Os , Os : : Debug >:: g e t f a c e t ( amp ) ; 11 12 algorithm . i n i t () ; 13 14 radio nable radio () ; >e 15 deb ug >debug ( I n i t i a l i z e d . \ n ) ; 16 } 17 18 private : 19 Os : : Debug : : s e l f p o i n t e r t d e b u g ; 20 Os : : R a d i o : : s e l f p o i n t e r t r a d i o ; 21 SomeAlgorithm a l g o r i t h m ; 22 } ; 23 24 w i s e l i b : : W i s e l i b A p p l i c a t i o n <Os , D e m o A p p l i c a t i o n> demo app ; 25 v o i d a p p l i c a t i o n m a i n ( Os : : AppMainParameter& amp ) { 26 demo app . i n i t ( amp ) ; 27 }
Platform selection Initialization: FacetProvider for OS facets / Manual for algorithms application main getting called by Wiselib OS adaptor
Henning Hasemann (IBR) Wiselib School 2010 October 2010 43 / 51
Outline
1
School organization Motivation A Library Of Algorithms Platform Independence Design Of The Wiselib Memory Management Abstraction With Templates Concept Architecture Integrating The Wiselib The Development Environment
October 2010
44 / 51
USB Sticks
The VM image can also be downloaded at: http://www.ibr.cs.tu-bs.de/alg/winterschool/ (Note that the bandwidth is limited)
October 2010
45 / 51
Get the supplied VM image running Log in (user: wiselib / password: wiselib) You may adjust your keyboard settings here
Henning Hasemann (IBR) Wiselib School 2010 October 2010 46 / 51
Verify you are in project session1 and are editing session1.cc Double-click on shawn (arrow) to compile for shawn Verify there are no error messages Repeat for isense
Wiselib School 2010 October 2010 47 / 51
Verify connection to node was established Go to Flash Loader Verify Trigger Programming mode is activated Select (arrow) /hands-on/session1/out/session1.bin Push Start
Wiselib School 2010 October 2010 50 / 51
Go to Serial Monitor
October 2010
51 / 51