This assignment will make you familiar with Statechart modelling, simulation and code synthesis.
In this assignment, you will design a Statechart model specifying the reactive behaviour of a Digital Watch (inspired by the 1981 Texas Instruments LCD Alarm Chronograph).
You will first model the reactive behaviour of the watch in the DCharts formalism (a variant of Statecharts) in the tool AToM3. The Statechart compiler SCXML JS will allow you to check, by means of simulation, whether your model behaves according to the requirements. Note that it is good practice to start modelling and simulating small parts of the desired behaviour in isolation. These can be saved and later loaded to build the full solution Statechart.
The model (saved as DigitalWatchStatechart_DCharts_MDL.py) and its visual representation must both be included in your index.html solution page. The visual representation is obtained by printing the model to file in Postscript format from AToM3 as DigitalWatchStatechart_DCharts_MDL.eps and subsequently converting it to a bitmap (e.g., DigitalWatchStatechart_DCharts_MDL.gif). Alternately, you can print the model to file in SVG (Scalable Vector Graphics) format as DigitalWatchStatechart_DCharts_MDL.svg and include it as such in your solution (as browsers such as Firefox now support SVG).
When you are satisfied with the simulated behaviour, you are ready to build a Digital Watch software application. The application's reactive behaviour will be generated from the Statechart.
The software application is composed of a static component, a controller and a dynamic component.
The static component (digitalWatch-simulator.svg and digitalWatch-standalone.svg, for simulation-enabled and standalone versions, respectively) implements the visual aspects of the watch such as buttons, the display and the Indiglo light and organizes them into a graphical user interface (built using SVG and the Web browser runtime).
The dynamic component (out.js for digitalWatch-simulator.svg, and standalone-behaviour/DigitalWatchStatechart.js for digitalWatch-standalone.svg) will be generated from your Statecharts model.
The communication between the static and the dynamic components is handled by the controller (found in DigitalWatchController.js). User events such as button press/release are passed from the GUI to the Statechart (as strings) by the controller. Conversely, the Statechart modifies the (visual) state of the GUI by invoking the controller's methods.
Note that the Statechart receives a reference to the controller object as a parameter of the start event when, at application startup time, it goes from its initial state Setup to the state Running.
To help clarify the requirements, the following execOnly.tgz contains a working solution (without the alarm activation). The Statechart model is only present in compiled version however.
getTime() Returns the current clock time. getAlarm() Returns the alarm time set. checkTime() Checks if the alarm time set is equal to the current clock time. If so, it will broadcast the "alarmStart" event to the statechart and return true. Otherwise, it returns false. Note that checkTime() does not care/check whether the alarm has been set "on". refreshTimeDisplay() Redraw the time with the current internal time value. The display does not need to be cleaned before calling this function. For instance, if the alarm is currently displayed, it will be deleted before drawing the time. refreshChronoDisplay See refreshTimeDisplay() refreshDateDisplay() See refreshTimeDisplay() refreshAlarmDisplay() See refreshTimeDisplay() resetChrono() Resets the internal chrono to 00:00:00. startSelection() Selects the leftmost digit group currently displayed on the screen. increaseSelection() Increases the currently selected digit group's value by one. selectNext() Select the next digit group, looping back to the leftmost digit group when the rightmost digit group is currently selected. If the time is currently displayed on the screen, select also the date digits. If the alarm is displayed on the screen, don't select the date digits (to simplify the statechart). stopSelection() increaseTimeByOne() Increase the time by one second. Note how minutes, hours, days, month and year will be modified appropriately, if needed (for example, when increaseTimeByOne() is called at time 11:59:59, the new time will be 12:00:00). increaseChronoByOne() Increase the chrono by 1/100 second. setIndiglo() Turn on the display background light unsetIndiglo() Turn off the display background light setAlarm() Flag the alarm to be on or off. Events sent to the Statechart (as strings): (due to button press) - topRightPressed - topRightReleased - topLeftPressed - topLeftReleased - bottomRightPressed - bottomRightReleased - bottomLeftPressed - bottomLeftReleased (generated by checkTime() if current time == alarm time) - alarmStart
The archive wristwatch.tgz contains a very simple example to get you started. This starting point Statechart is reproduced here
The Models/DCharts/ folder in the central AToM3 installation contains some small examples demonstrating various features of Statecharts. The Models/DCharts/TrafficLight/ folder contains the small traffic light example.
It is good practice to model/simulate different parts of the overall solution in isolation (bottom-up design). You can save them in different files and later load them into a combined model.
Hint: for the assignment, a "natural" solution will require 6 orthogonal components.
You will find some example models in the central Models DCharts directory (Models/DCharts/). This is a good place to find examples of the [AFTER()], [EVENT()], etc. macros.
The SCXML JS compiler and simulation tools are available here and here. There is a tutorial on SCXML JS here.
It is possible to install AToM3 and SCXML JS on your own computer, however AToM3 is only known to work on Windows and Linux, and SCXML JS has only been tested on Ubuntu 10.04.
You need to download the latest version of AToM3 from http://atom3.cs.mcgill.ca/, then follow the instructions in the tutorial regarding how to set up SCXML JS.
To make things a little easier, the following archive atom3-scxml-js.tgz contains everything you need rolled in one.
Maintained by Hans Vangheluwe. | Last Modified: 2010/10/4. |