CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
CIS 542 Embedded Systems Programming – Summer 2013 Lecture ...
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
33<br />
34<br />
35<br />
36<br />
37<br />
38<br />
39<br />
40<br />
41<br />
42<br />
43<br />
44<br />
45<br />
46<br />
47<br />
48<br />
49<br />
50<br />
51<br />
52<br />
53<br />
54<br />
55<br />
}<br />
state = disarmed;<br />
disarm_system();<br />
}<br />
else {<br />
state = alarm_sounding;<br />
sound_alarm();<br />
}<br />
break;<br />
}<br />
break;<br />
case alarm_sounding:<br />
switch (signal) {<br />
case quiet:<br />
if (password_correct()) {<br />
state = armed;<br />
arm_system();<br />
}<br />
break;<br />
}<br />
break;<br />
}<br />
Alternatively, we could make “state = armed” the first statement in the “arm_system” function, but you<br />
could conceivably have a situation in which a function is called in two different states, so you<br />
shouldn't bind the state and the functionality too much.<br />
Testing<br />
Let's look at another example. It's the cruise control system for a car. Here's the specification:<br />
• if the driver chooses to accelerate, the speed increases by 10, unless that would put the speed<br />
over 100, in which case it doesn't change<br />
• if the driver chooses to break, the speed decreases by 10; if that would put the speed below 0,<br />
the speed becomes 0<br />
• if the speed is 0, the car stops