A State-Based Programming Model for Wireless Sensor Networks
A State-Based Programming Model for Wireless Sensor Networks
A State-Based Programming Model for Wireless Sensor Networks
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
7 <strong>State</strong>-based <strong>Programming</strong> in<br />
Practice<br />
The thesis <strong>for</strong>mulated in the introduction of this dissertation was that the statebased<br />
programming model incurs as little overhead as the event-based model,<br />
yet allows to program more memory efficiently and allows to specify programs<br />
more structured and more modular compared to event-driven programs. In the<br />
following sections we will support this thesis.<br />
Be<strong>for</strong>e turning to concrete examples, we present an intuitive approach to motivate<br />
our claim in Sect. 7.1. We explain how event-driven programs can be<br />
<strong>for</strong>mulated as trivial OSM programs containing a single state only. Clearly, such<br />
programs do not exhibit the benefits of state-based programming. However, the<br />
initially trivial programs are easily refined, increasing their structure, modularity,<br />
and memory efficiency. Such refined programs, on the other hand, cannot be<br />
translated back in the event-driven model without loosing such benefits again.<br />
In Sect. 7.2 we show how the structure and modularity of sensor-node programs<br />
benefits from OSM using a concrete example from the literature. We will<br />
compare the reimplementation of a large part of the EnviroTrack middleware in<br />
OSM and compare it to the original NesC implementation. We will compare the<br />
two implementations with respect to state management, accidental concurrency,<br />
and state-bound resource initialization. We show that with OSM manual state<br />
management can be removed entirely in favor of an explicit, high-level state notation.<br />
As a result the programs are much more concise. In our example, we<br />
show that the size of the OSM re-implementation is reduced by 31% (measured<br />
in lines of code) with respect to the original nesC implementation.<br />
In Sect. 7.3 we will illustrate how OSM can increase the memory efficiency of<br />
programs compared to event-driven programs. Concretely, we will show how<br />
state variables foster the reuse of memory <strong>for</strong> temporary data structures using<br />
a small example. The memory savings achievable by using state variables very<br />
much depend on the program structure. While very high memory savings can<br />
be achieved in theory, we expect savings of 10 to 25% in real-world programs.<br />
Sect. 7.4 summarizes this chapter.<br />
7.1 An Intuitive Motivation<br />
Traditional event-based programs can be <strong>for</strong>mulated in OSM as depicted in<br />
Fig. 7.1. There is a single state S0, which has attached all global variables vari<br />
of the event-based program. For each possible event ej there is a self transition<br />
with an associated action outj(), which has access to ej and to all state variables<br />
of S0. Hence, OSM can be considered a natural extension of event-based programming.