06.08.2013 Views

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

JAVA-BASED REAL-TIME PROGRAMMING

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

}<br />

4.2. Exercise 2 – Lab 1 preparation<br />

// The AlarmClock thread is started by the simulator. No<br />

// need to start it by yourself , if you do you will get<br />

// an IllegalThreadStateException. The implementation<br />

// below is a simple alarmclock thread that beeps upon<br />

// each keypress. To be modified in the lab. A recommendation<br />

// is to use this thread to start up your system similar<br />

// to RTsemBuffer in exercise 1.<br />

public void run() {<br />

while (true) {<br />

sem.take();<br />

output.doAlarm();<br />

}<br />

}<br />

Looking inside the simulator for a moment, what is happening at startup is<br />

that the simulator creates an instance of your AlarmClock class and starts a<br />

new thread on the resulting object. The new thread starts executing in the<br />

AlarmClock.run() method.<br />

Simulator excerpt: AlarmClock startup code<br />

ClockInput butt2ctrl; // Interface to user actions via hardware/software.<br />

ClockOutput ctrl2disp; // Interface to display hardware/software.<br />

AlarmClock control; // The actual alarm -clock software.<br />

// ...<br />

control = new AlarmClock(butt2ctrl , ctrl2disp);<br />

control.start();<br />

In the same manner, when the applet is stopped (corresponding to hardware<br />

reset), there is a call control.terminate(); which you need to override, if you<br />

want to fulfil the optional specification item 5.<br />

The following classes are the ClockOutput and the ClockInput that describe<br />

the interface between the control software and the clock hardware/emulator.<br />

Excerpt from the ClockOutput class<br />

public class ClockOutput {<br />

}<br />

/**<br />

* Wake -up clock user.<br />

*/<br />

public void doAlarm() { ... }<br />

/**<br />

* If the display is currently used to display the time , update it.<br />

* If user is using display for setting clock or alarm time , do<br />

* nothing.<br />

*/<br />

public void showTime(int hhmmss) { ... }<br />

105

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!