Table of Contents
Vending Machine example on GitHub
A new fully functional vending machine example is available now. It is now hosted on GitHub so you can quickly check out the model and code yourself. Link to the repository: https://github.com/sinelabore/examples
The envisioned machine is shown below.
To compile the example just call make. It is assumed that you have installed the code generator from sinelabore and the Astah* Community UML tool (locations see Makefile).
After startup you can select a product “A”, “B” or “C” by pressing one of theses buttons on your keyboard.
Then you have to insert the coins to pay for the product. Only 10Ct, 20Ct and 50Ct coins are supported. To “insert” them click “1”,“2” or “5” on your keyboard.
After you paid the product will be released and you receive back your change.
Most of the code is automatically generated from the UML model. It contains two state machines and an activity diagram. The state machines receive events from a message queue and can also send messages to other state machines. This is a well known design pattern to decouple objects. A timer service provides basic timer services that can be used from the state machines to realize delays or repetitive activities.
Product Store State Machine
The “product_store_sm” implements a simple product store containing the goods. It is responsible to release the products by turning on the motor etc.
This is the controller machine keeping things together.
This is a simple algorithm modeled with the help of an activity diagram to release the right amount of money if the user overpaid. It takes care if one coin type is empty.