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
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
7.2. Modular and Well-Structured Program Design 127<br />
the current state. These actions are either state changes or recurring computational<br />
actions within the current state. There<strong>for</strong>e, we like to think that conceptually<br />
every state uses an individual timer, though both the original NesC and<br />
the OSM implementations only use a single hardware timer <strong>for</strong> all states. The<br />
individual timers are always initialized in transitions, either when entering a<br />
new state through a transition, or after triggering a recurring action within the<br />
current state, that is, in a self transition. Table 7.2 lists the values that are used to<br />
initialize the timer in the EnviroTrack example based on the transition parameters,<br />
namely the target and source states as well as the trigger event. Using this<br />
example, we will now explain how state-bound resources are initialized in both<br />
the event-driven and the state-based programming models and then compare<br />
both approaches.<br />
Target <strong>State</strong> Source <strong>State</strong> Trigger Line No. Timeout Value<br />
NesC OSM<br />
NEW_CANDIDATE<br />
LEADER_CANDIDATE<br />
FOLLOWER<br />
MEMBER<br />
LEADER<br />
RESIGNING_LEADER<br />
FREE join 154 27 wait_random()<br />
NEW_CANDIDATE timeout[else] 106 29 wait_recruit()<br />
NEW_CANDIDATE timeout[...] 111 36<br />
MEMBER timeout 100 36<br />
MEMBER resign[...] 269 36<br />
FREE recruit OR resign 248 12<br />
LEADER_CANDIDATE leave[else] 200 12<br />
FOLLOWER recruit OR resign 256 12<br />
MEMBER leave 186 12<br />
RESIGNING_LEADER recruit OR candidate 337 12<br />
NEW_CANDIDATE recruit 279 19<br />
NEW_CANDIDATE candidat[...] 284 19<br />
LEADER_CANDIDATE recruit[...] 295 19<br />
LEADER_CANDIDATE candidate[...] 300 19<br />
FOLLOWER join 161 19<br />
MEMBER recruit 264 19<br />
LEADER recruit[...] 313 19<br />
wait_random()<br />
wait_threshold()<br />
wait_receive()<br />
LEADER_CANDIDATE timeout 120 45 wait_random()<br />
RESIGNING_LEADER join 169 46 wait_recruit()<br />
LEADER timeout 126 47 — ” —<br />
LEADER recruit[else] 317 47 — ” —<br />
LEADER resign OR candidate 325 47 — ” —<br />
RESIGNING_LEADER timeout[...] 135 56 wait_recruit()<br />
LEADER leave 209 56<br />
Table 7.2: Timeouts in the EnviroTrack group-management protocol are initialized<br />
as part of transitions and predominantly depend on the target<br />
state only. The source states and triggers of self transitions are set in<br />
italics. Line numbers refer to the source code given in Appendices B.1<br />
and B.2 (<strong>for</strong> the NesC and OSM version, respectively). The actual timeout<br />
value is expressed as the return value of a function.<br />
Original NesC Implementation<br />
In the NesC implementation of the EnviroTrack group-management protocol, a<br />
single timer is used to implement timeouts in all states using a count-down approach.<br />
The timer is switched on when the program starts and is never switched<br />
off. It fires at a regular interval that never changes. The corresponding timeout