JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
JAVA-BASED REAL-TIME PROGRAMMING
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
4. Exercises and Labs<br />
}<br />
}<br />
super(mach , speed , tempController , waterController , spinController);<br />
/**<br />
* This method contains the actual code for the washing program. Executed<br />
* when the start() method is called.<br />
*/<br />
protected void wash() throws InterruptedException {<br />
}<br />
// Switch of temp regulation<br />
myTempController.putEvent(new TemperatureEvent(this ,<br />
TemperatureEvent.TEMP_IDLE ,<br />
0.0));<br />
// Switch off spin<br />
mySpinController.putEvent(new SpinEvent(this , SpinEvent.SPIN_OFF));<br />
// Drain<br />
myWaterController.putEvent(new WaterEvent(this ,<br />
WaterEvent.WATER_DRAIN ,<br />
0.0));<br />
mailbox.doFetch(); // Wait for Ack<br />
// Set water regulation to idle => drain pump stops<br />
myWaterController.putEvent(new WaterEvent(this ,<br />
WaterEvent.WATER_IDLE ,<br />
0.0));<br />
// Unlock<br />
myMachine.setLock(false);<br />
Example controller<br />
All controllers are be implemented as periodic threads. Note the usage of the<br />
simulation speed parameter to adjust the period. The perform method will<br />
be called periodically. It is important that you do not implement any lengthy<br />
actions or block/sleep in this method.<br />
public class WaterController extends PeriodicThread {<br />
// TODO: add suitable attributes<br />
}<br />
Messages<br />
public WaterController(AbstractWashingMachine mach , double speed) {<br />
super((long) (3000/ speed)); // TODO: replace with suitable period<br />
}<br />
public void perform() {<br />
// TODO: check if there are any messages in the mailbox (tryFetch).<br />
// Take action depending on the last received message.<br />
}<br />
The washing program communicates with the controllers through messages.<br />
Subclasses of the main message (RTEvent) class suitable for the washing<br />
130 2012-08-29 16:05