\section{Wiselib}
The \definition{Wiselib}\cite{wiselib} is a C++\index{C++} algorithm library for
sensor networks, containing for example algorithms for routing, localization and
time synchronization, and is strongly focused on portability and cross-platform
development. In particular, it allows the user to develop applications that run
on different hardware platforms without the need to change the code, and it
strongly uses C++ templates to achieve that feature. Amongst the supported
platforms are diverse sensor node platforms, like iSense, Contiki and TinyOS,
but there are as well implementations for the diverse x86-compatible Personal
Computer platforms, and the Shawn sensor network simulator.

\subsection{Architecture}
\paragraph{Concepts and Models}
Wiselib makes strong uses of \definition{concepts} and \definition{models} as
central design objects. Concepts serve as an informal description of interfaces,
only existent in documentation, defining expected parameters and types. Models
however implement these interfaces in C++ code while fulfilling their
specification. The Wiselib algorithms can in turn rely on the concepts as a
generic specification, and take models as template parameters to use their
functionality, so a function call will be immediately resolved to a specific
model at compile time without the need for an additional function call as it is
the case with virtual inheritance. Furthermore, this also allows usage on
platforms which do not have support for C++, as the bytecode generated by the
compiler does not include C++ specific extensions (no virtual function tables,
and templates are resolved at compile time) and can be linked against any
Standard C Library.

This makes cross-platform development easily possible. For example, to implement
a routing algorithm, one can rely on the concept of a Radio to send and receive
data packets, without needing to implement code specific to the used radio
hardware. The users of that routing algorithm can now choose which radio model
they want to use, according to their needs and the underlying hardware, provided
that their radio model also implements the same Radio concept that the routing
algorithm uses.

\begin{figure}
  \centering
  \includegraphics[width=.8\textwidth]{images/Wiselib-Arch.pdf}
  \caption{Wiselib architecture\label{fig:wiselib-arch}}
\end{figure}
Besides algorithms, and basic concepts and models, the Wiselib also consists of
two other main parts: the internal interface and the external interface (see
Figure \ref{fig:wiselib-arch}).

\paragraph{External Interface}
The \definition{External Interface} provides access to the underlying \ac{OS},
like iSense, Contiki, Shawn\ldots and defines concepts like a Radio or a Timer.
Thus, the concepts are as generic as possible to match all supported operating
systems and provide a light-weight abstraction to the underlying \ac{OS}. These
concepts sometimes extend the generic concepts, for example there is a TxRadio
which has the ability to set the transmission power on the radio. The models
(for example an iSenseRadioModel or a ShawnTimerModel) implement these concepts
on the specific operating system, and can be passed around as template
parameters.

\paragraph{Internal Interface}
The \definition{Internal Interface} defines concepts and models for data
structures that can be used in algorithms. This allows to specialize for
restricted platforms; for instance a wireless sensor node without dynamic memory
management can use a static implementation of lists and other containers,
whereas a full-grown desktop can use the dynamic implementation provided by the
C++ \ac{STL}. For this purpose, the Wiselib also contains the
\ignoreoutput{\ac{pSTL}}\definition{\acl{pSTL}} (\acs{pSTL}) which implements a
subset of the \ac{STL} without the use of dynamic memory allocation.

\paragraph{Stackability}
Another central design principle used in the Wiselib is
\definition{stackability}, which describes the possibility to stack
implementations of the same concept, thereby building a layered structure. For
example, one could stack a cryptography algorithm on top of a radio model, which
both implement the Radio concept. In this case, the cryptography layer doesn't
have to know anything at all about the underlying implementation, as long as it
can use the Radio concept of the underlying layer. And it can even provide the
same interface to a possibly higher layer in order to provide transparent packet
de- and encryption over the radio.

\subsection{Roomba Control}
Even more interesting is the fact that the Wiselib includes code to control an
iRobot Roomba\index{Roomba} over a serial interface, and getting access to its
internal sensor data, using the \acl{ROI}\index{\acl{ROI}} mentioned earlier.
For this purpose, it defines two concepts for Robot Motion:

\paragraph{TurnWalkMotion concept}\index{TurnWalkMotion (concept)}
Concept of a simple robot that can turn and walk straight, without time
awareness
\begin{description}
  \item Types:
    \begin{description}
      \item[\code{velocity\_t}] Type for velocity measurement
      \item[\code{angular\_velocity\_t}] Type for angular velocity measurement
    \end{description}
  \item \todo{clearpage?} Methods:
    \begin{description}
      \item[\code{int turn(angular\_velocity\_t)}] turn the robot with a
        constant angular velocity
      \item[\code{int move (velocity\_t)}] move the robot straight with a
        constant velocity
      \item[\code{int stop()}] stop the robot
      \item[\code{int wait\_for\_stop()}] hold the execution until the robot has
        stopped
    \end{description}
\end{description}

\paragraph{Odometer concept}\index{Odometer (concept)}
Concept of a class tracking motions over time. Whenever the object turns, or
moves, internal counters will adjust their guessing of the objects traveled
distance and current orientation.
\begin{description}
  \item Types:
    \begin{description}
      \item[\code{angle\_t}] Type for angle measurement
      \item[\code{distance\_t}] Type for distance measurement
    \end{description}
  \item Methods:
    \begin{description}
      \item[\code{angle\_t angle()}] return the current angle
      \item[\code{int reset\_angle()}] reset the angle of the object
      \item[\code{distance\_t distance()}] return the current distance
      \item[\code{int reset\_distance()}] reset the distance of the object
      \item[\code{int register\_state\_callback (T *obj)}] register a callback
        that gets called when the state changes
      \item[\code{int unregister\_state\_callback (int)}] unregister a
        previously registered callback
      \item[\code{int state()}] return the current state
    \end{description}
\end{description}

\paragraph{Implementation}

\todo{cite Wisebed book chapter on Roomba code}
\todo{which roomba sensors were used?}