<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://sinelabore.com/lib/exe/css.php?s=feed" type="text/css"?>
<rss version="2.0">
    <channel xmlns:g="http://base.google.com/ns/1.0">
        <title>SinelaboreRT - wiki:news</title>
        <description>Productivity for embedded software development</description>
        <link>https://sinelabore.com/</link>
        <lastBuildDate>Wed, 08 Apr 2026 00:04:47 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://sinelabore.com/lib/exe/fetch.php/favicon.ico</url>
            <title>SinelaboreRT</title>
            <link>https://sinelabore.com/</link>
        </image>
        <item>
            <title>Leader State Machine - Follower State Machines</title>
            <link>https://sinelabore.com/doku.php/wiki/news/1jan2016</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;leader_state_machine_-_follower_state_machines&quot;&gt;Leader State Machine - Follower State Machines&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Leader State Machine - Follower State Machines&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;leader_state_machine_-_follower_state_machines&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-62&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;background&quot;&gt;Background&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The Unified Modeling Language (&lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt;) allows to model quite elaborate state machines especially when using concurrent regions (aka AND states or parallel states). Concurrent regions are a powerful design measure but also have its price. 
&lt;/p&gt;

&lt;p&gt;
Unexperienced users tend to create one big state diagram containing all parts (subsystems) of the system. Due to their own behavior and parallel execution subsystems  must then be modeled as concurrent regions.
&lt;/p&gt;

&lt;p&gt;
Read on to learn about an alternative solution.
&lt;/p&gt;

&lt;p&gt;
Take a microwave oven as example. There is a lamp, motor and the microwave radiator itself all reacting on events. One approach is to create one big parent state and put the different parts of the oven in parallel regions.
&lt;/p&gt;

&lt;p&gt;
Figure 1: Simplified oven model, designed with regions.
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan012016/machine_with_regions.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The key benefits of &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; regions are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Unordered List Itemconcurrent regions allow to model parallelism.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; everything is shown on one page&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The drawbacks are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The diagrams can become quite large. Our diagram just shows some states. Reality might be much more complex.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; As a direct consequence one has to scroll back and forth all the time when working on different parts of the model&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Refining behavior in concurrent regions makes the parent state containing the regions bigger and bigger. Depending on the modeling tool features’ this often has the consequence that a lot of work is going into moving states around to make space for new ones instead on focussing on the design work itself.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Background&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;background&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;63-1632&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;alternative_solution&quot;&gt;Alternative solution&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
To reduce the complexity good practice in engineering is to break down the problem into smaller pieces. In software this good approach means to put the subsystem state machines into their own state diagrams.
&lt;/p&gt;

&lt;p&gt;
This has the benefit to create smaller diagrams dedicated to a specific subsystem e.g. the radiator. These diagrams can be developed, verified and validated   separately without considering the whole system. Eventually from a different developer (deepening on project size).
&lt;/p&gt;

&lt;p&gt;
As a consequence the state machines must be able to exchange events. Or at least one state machine (the leader) must be able to send events to the other state machines (the followers).
&lt;/p&gt;

&lt;p&gt;
Lets take the microwave example again. Now the leader machine contains only the overall behavior. The radiator, lamp and other subsystems were modeled as follower state machines. They are controlled from the leader machine. E.g. if the main machine reaches cooking it sends the radiator an event to switch on radiation. On this top level we are not interested how the radiator subsystem works in detail. In reality it might be a complex state machine with many states dealing with the radiator electronics in the oven. But this is not relevant on the top level diagram.
&lt;/p&gt;

&lt;p&gt;
The following figures show the leader machine and then two simplified examples of follower state machines.
&lt;/p&gt;

&lt;p&gt;
Figure 2a: Leader machine. It just sends events to the followers to trigger actions. Note that also the leader might receive events from other state machines (e.g. the button subsystem). In one extreme shape there is not even a leader but only cooperating subsystems.
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan012016/machine_leader.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Figure 2b: Simplified lamp subsystem reacting on events from the leader (or from additional sources e.g. hardware triggered events or timer events).
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan012016/lamp_subsys.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Figure 2c: Simplified radiator subsystem reacting on events from the leader (or from additional sources e.g. hardware triggered events or timer events).
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan012016/radiator_subsys.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Alternative solution&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;alternative_solution&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1633-3743&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;connecting_state_machines&quot;&gt;Connecting state machines&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
For communication between state machines different solutions are available.
What is actually used depends a lot on the overall system needs and system features e.g. with/without &lt;abbr title=&quot;Real-Time Operating System&quot;&gt;RTOS&lt;/abbr&gt; etc. On smaller systems binary flags might be sufficient. But usually a good solution is to use queues. Queues decouple the state machines and offer a clear interface to send and receive events. Event queues often have the feature to push events in front so high importance events can be processed first. A subsystem also might defer an event and put it into the queue again if it should be processed later. The subsystems might run in a separate thread (if an &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; is present) or can be called from a main loop.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Connecting state machines&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;connecting_state_machines&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;3744-4478&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Separating a system into different subsystems running their own state machines is a well know design practice and helps to better keep complex developments under control.
&lt;/p&gt;

&lt;p&gt;
Hope you enjoyed this article. Let me know your feedback!
&lt;/p&gt;

&lt;p&gt;
Peter
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Conclusion&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;conclusion&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;4479-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 06 Apr 2022 10:01:43 +0000</pubDate>
        </item>
        <item>
            <title>New version 3.6.6</title>
            <link>https://sinelabore.com/doku.php/wiki/news/1sep2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_version_366&quot;&gt;New version 3.6.6&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
This new version supports code generation from Astah* models with regions. A region is an orthogonal part of a state. Regions allow to express parallelism within a state. A state can have two or more regions. Region contains states and transitions. To add a region in astah* right click to a state and select &lt;em&gt;Add region&lt;/em&gt; from the context menu.
&lt;/p&gt;

&lt;p&gt;
An example state diagram with regions is shown below:
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/astah_regions.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
For more information how the code generator generates code from regions download the latest version and check-out the manual esp. sections 2.2 and A.5.
&lt;/p&gt;

&lt;p&gt;
{(rater&amp;gt;id=01092014|name=How do you like this article?|type=rate)}
~~DISCUSSION|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Mon, 01 Sep 2014 19:03:18 +0000</pubDate>
        </item>
        <item>
            <title>Using State-Machines in Low-Power Embedded Systems</title>
            <link>https://sinelabore.com/doku.php/wiki/news/02jan2015</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;using_state-machines_in_low-power_embedded_systems&quot;&gt;Using State-Machines in Low-Power Embedded Systems&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Using State-Machines in Low-Power Embedded Systems&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;using_state-machines_in_low-power_embedded_systems&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-65&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;introduction&quot;&gt;Introduction&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
I got requests from time to time asking how to integrate state-machines in a specific system design. Usually I can only give some general advice. But I like to present some design principles here which are hopefully useful for developers of deeply embedded systems in general and those of low power systems in particular. 
&lt;/p&gt;

&lt;p&gt;
The CPU in a low power system is usually only active from time to time to react on events triggered from outside (e.g. a pressed key) or triggered from inside the system (e.g. ADC ready, timer expired). After processing the event the CPU goes into low power mode again. 
&lt;/p&gt;

&lt;p&gt;
All this is done to keep the batteries running as long as possible. A good example for such a system is a wireless temperature sensor mounted outside the window sending temperature data from time to time to a central display, or a monitor attached to a bird to track the flight route or a bike computer etc. The longer the batteries last, the better. 
&lt;/p&gt;

&lt;p&gt;
But also systems connected to power all the time might benefit from a low-power design. Power consumption of a device is a real buying criteria nowadays.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Introduction&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;introduction&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;66-1196&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;system_design&quot;&gt;System Design&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The following example is based on a small MSP430F1232 header board with just 256 bytes of RAM and 8K of program memory. For the development the Code Composer Studio from TI was used. At the end the program needs &amp;lt;2k Flash and 182 bytes RAM incl. stack. The following block diagram shows the controller with its I/O connections.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/msp430.svg?id=wiki%3Anews%3A02jan2015&quot; class=&quot;media&quot; title=&quot;msp430.svg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/msp430.svg?w=400&amp;amp;tok=86d854&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;400&quot; /&gt;&lt;/a&gt;
Figure 1: MSP430F1232 block diagram
&lt;/p&gt;

&lt;p&gt;
To not hide the design principles behind too much details the uC runs just two state machines fully generated from &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state diagrams. One machine is measuring the battery voltage every 2 seconds. The other one measures the temperature also on a cyclic basis using a TMP100 from TI connected via I2C to the uC. Temperature measurement happens only if battery voltage is high enough. Otherwise a LED is pulsed to indicate low voltage state (P1.3). The radio part which sends the temperature to a central server was omitted here.
&lt;/p&gt;

&lt;p&gt;
The two state machines realizing the user application are shown in figure 2 below. The state machines were designed with the built-in Java &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; editor. To change or extend the functionality just modify the state machines, regenerate the state-machine code and then compile and link as usual. Changes on I/O port 1 were added to verify the timing via oscilloscope (see below).
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan2015_pwr.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan2015_toggle.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
Figure 2: Application logic implemented as state machines. Top: Triggering the voltage measurement with a cyclic timeout. Bottom: Switching between two operation modes depending on supply voltage level. Single-shot timers are used for timing. 
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;System Design&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;system_design&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1197-2847&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;reusable_library_layer&quot;&gt;Reusable Library Layer&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The design is based on the following library elements which can be reused from project to project:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; A timer abstraction layer provides timers for the user application. The timer abstraction is based on a system tick realized with hardware &lt;code&gt;timer A&lt;/code&gt; here. If a timer has expired the &lt;code&gt;tick()&lt;/code&gt; routine returns &lt;code&gt;true&lt;/code&gt; and the CPU is woken-up. Otherwise the low power mode is entered again.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code c&quot;&gt;__interrupt &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; Timer_A0&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  bool retVal&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  P1OUT &lt;span class=&quot;sy0&quot;&gt;^=&lt;/span&gt; BIT0&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;co1&quot;&gt;// toggling bit for debugging&lt;/span&gt;
  retVal &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; tick&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;co1&quot;&gt;// timer service. Check if any timer has expired&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;retVal&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// at least one timeout timer fired.&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// wake up main loop&lt;/span&gt;
    __bic_SR_register_on_exit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;LPM0_bits&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; 
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Listing 1: Timer interrupt service routine calling the timer handler &lt;em&gt;tick()&lt;/em&gt;.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The user code can create multiple timers and receive time-out events in case they expire. During timer creation the event queue and the timer event has to be provided. If a timer expires this event will be stored in the given event queue. The timer implementation can be found in the &lt;code&gt;library&lt;/code&gt; folder in files &lt;code&gt;timer.c&lt;/code&gt; and &lt;code&gt;timer.h&lt;/code&gt;. The &lt;code&gt;tick()&lt;/code&gt; function is the core of the timer library and shown below:&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code c&quot;&gt;bool tick&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  bool timeoutAvailable&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// Iterate over the timers and enque&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// timer events once a timeout has happend.&lt;/span&gt;
  &lt;span class=&quot;kw1&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt;MAX_TIMERS&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; i&lt;span class=&quot;sy0&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;timerStatus&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;ON&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
      timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;elapsedTicksSinceStart&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;++;&lt;/span&gt;
&amp;nbsp;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;elapsedTicksSinceStart&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;preset&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;// timeout time elapsed.&lt;/span&gt;
        timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;timerStatus&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;OFF&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// stop timer&lt;/span&gt;
        fifoPut&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;rbuf&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; timers&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;i&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;evTimeout&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// enqueue timeout event&lt;/span&gt;
        timeoutAvailable&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; timeoutAvailable&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// starts timer&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// Returns either ON if started or OFF if not started (e.g. preset=0)&lt;/span&gt;
TIMER_STATE_T timerStart&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint16_t&lt;/span&gt; ticks&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// stops timer&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; timerStop&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// either returns ON or OFF or PAUSE&lt;/span&gt;
TIMER_STATE_T timerStatus&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// set timer timeout in ticks&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; timerSet&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint16_t&lt;/span&gt; ticks&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Timer function to be called from the timer irq handler.&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// If at least on timer fired the function returns 1. Otherwise 0.&lt;/span&gt;
bool tick&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// pause timer&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; timerPause&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// resume timer&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; timerCont&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Not yet implemented&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; timerErase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; t_id&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Listing 2: The timer interface and the tick handler. The tick handler is checking if any timer has elapsed. In this case the user provided event is stored in the corresponding queue.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; A queue service. Queues are used to store events from timers or other event sources in fifo order. Multiple queues can be created usually one per state-machine. The queue code is available in the &lt;code&gt;library&lt;/code&gt;  folder in files &lt;code&gt;ringbuf.c&lt;/code&gt; and &lt;code&gt;ringbuf.h&lt;/code&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; Buffer &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;data&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; mask&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// size - 1&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; read&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// index of oldest element&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; write&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// index of field to write to&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; FIFO_T&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; fifoInit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;FIFO_T &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; buffer&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt;  &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; pByte&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; size&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
bool fifoPut&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;FIFO_T &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; buffer&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; byte&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
bool fifoGet&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;FIFO_T  &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; buffer&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; pByte&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
bool fifoPutHead&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;FIFO_T &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; buffer&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;  &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; byte&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
bool fifoIsEmpty&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; FIFO_T &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;const&lt;/span&gt; buffer&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Listing 3: The queue interface. Multiple queues can exist. A state machine usually has one input queue to pick the next event from.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Reusable Library Layer&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;reusable_library_layer&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2848-6414&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;weaving_the_state_machines_and_the_library_part_together&quot;&gt;Weaving the state machines and the library part together&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
On top of the minimal abstraction layer (timers, queues) the application specific part is located. It is implemented as state-machines reacting on the events. The state machine code is fully generated. All is generated from the &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state machine diagrams. The main routine initializes the hardware and then enters a main-loop waiting in low-power mode. ADC and timer iqr handlers wake-up the CPU after they enqueued an event. When woken-up the main loop pulls out these events and calls the appropriate state-machine with the event as parameter. See the following code snippet for the implementation details:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;coMULTI&quot;&gt;/**
 * Main loop initializes the hardware and software
 * and then waits in low power mode until new events
 * are present. Events are then pulled out of the
 * queues and forwareded to the apropriate state-machine.
 */&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; main&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&quot;co1&quot;&gt;// Stop watchdog timer to prevent time out reset&lt;/span&gt;
  WDTCTL &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; WDTPW &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; WDTHOLD&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// initialize timer &lt;/span&gt;
  TACCTL0 &lt;span class=&quot;sy0&quot;&gt;|=&lt;/span&gt; CCIE&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;                           &lt;span class=&quot;co1&quot;&gt;// CCR0 interrupt enabled&lt;/span&gt;
  TACCR0 &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;  41U&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  TACTL &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; TASSEL_1 &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; MC_1 &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; ID_3&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;           &lt;span class=&quot;co1&quot;&gt;// SMCLK/8, upmode  &lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
  P1OUT &lt;span class=&quot;sy0&quot;&gt;&amp;amp;=&lt;/span&gt; 0x00U&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;               &lt;span class=&quot;co1&quot;&gt;// Shut down everything&lt;/span&gt;
  P1DIR &lt;span class=&quot;sy0&quot;&gt;&amp;amp;=&lt;/span&gt; 0x00U&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  P1DIR &lt;span class=&quot;sy0&quot;&gt;|=&lt;/span&gt; BIT0 &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; BIT1&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;BIT2&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;BIT3&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;       &lt;span class=&quot;co1&quot;&gt;// set pins to output the rest are input&lt;/span&gt;
  P1OUT &lt;span class=&quot;sy0&quot;&gt;|=&lt;/span&gt; BIT1 &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; BIT1&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;BIT2&lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt;BIT3&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;         &lt;span class=&quot;co1&quot;&gt;//Select pull-up mode&lt;/span&gt;
&amp;nbsp;
  fifoInit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;buf1&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; buf1data &lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;buf1data&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  fifoInit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;buf2&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; buf2data &lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;buf2data&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;sizeof&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  timerInit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  init_uart&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  radio_init&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  initWindSensor&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;co1&quot;&gt;// run once to init&lt;/span&gt;
  toggle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;smToggle&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; TOGGLE_NO_MSG&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  pwr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;smPwr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; PWR_NO_MSG&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;                      &lt;span class=&quot;co1&quot;&gt;//Loop forever&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; retVal&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; bufVal&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;                         &lt;span class=&quot;co1&quot;&gt;// first process all events for task A&lt;/span&gt;
      retVal &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; fifoGet&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;buf1&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;bufVal&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;retVal&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;QUEUE_EMPTY&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        toggle&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;smToggle&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; bufVal&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;retVal&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;QUEUE_EMPTY&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;                        &lt;span class=&quot;co1&quot;&gt;// then all evenets for task B&lt;/span&gt;
      retVal &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; fifoGet&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;buf2&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;bufVal&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;retVal&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;QUEUE_EMPTY&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        pwr&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;smPwr&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; bufVal&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;retVal&lt;span class=&quot;sy0&quot;&gt;!=&lt;/span&gt;QUEUE_EMPTY&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// more tasks could follow here&lt;/span&gt;
&amp;nbsp;
    __bis_SR_register&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;LPM3_bits &lt;span class=&quot;sy0&quot;&gt;+&lt;/span&gt; GIE&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;  &lt;span class=&quot;co1&quot;&gt;// Enter low power mode once&lt;/span&gt;
    __no_operation&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;                    &lt;span class=&quot;co1&quot;&gt;// no more events must be processed&lt;/span&gt;
&amp;nbsp;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Listing 4: The main routine waiting in low power mode until events are available. Then these events are forwarded to the state machine handlers.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Weaving the state machines and the library part together&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;weaving_the_state_machines_and_the_library_part_together&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:3,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;6415-8986&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;how_to_treat_with_longer_lasting_tasks&quot;&gt;How to treat with longer lasting tasks&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Execution time for handling events should be as short as possible. Longer lasting tasks should be split into chunks. Take the temperature measurement as an example. The temperature sensor TMP100 requires about 320ms conversion time according to the data sheet. The uC shouldn&amp;#039;t wait and burn CPU cycles but either wait in low-power mode or process other events. This can easily be done by starting the conversion in one state (&lt;code&gt;Step1&lt;/code&gt;) and then start a timer and enter low-power mode. If the timer fires we pick-up the conversion result (&lt;code&gt;Step2&lt;/code&gt;) and process it further.
&lt;/p&gt;

&lt;p&gt;
Another example is the wake-up procedure of the radio. After finishing low-power mode it takes a while before it is ready. Readiness is signalled via a transition of the RTS pin from high to low. After switching on the radio in state &lt;code&gt;Step2a&lt;/code&gt; we enter low-power mode again. The level change creates an irq and sends the event &lt;code&gt;evFallingEdgeRTS&lt;/code&gt;. Now the radio is ready to transmit data. 
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;How to treat with longer lasting tasks&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;how_to_treat_with_longer_lasting_tasks&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;8987-10005&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit7&quot; id=&quot;object_diagram&quot;&gt;Object Diagram&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
The software design  is shown in the next figure as &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; object diagram. You can clearly see how the &lt;code&gt;queues decouple the event sources from the event consumers&lt;/code&gt;. The main-loop serves as event dispatcher being only active if events are available in one of the queues. The main loop can also be used to prioritize one state machine over an other or ensure the order in which state machines are executed.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/jan2015_objdiag.png?id=wiki%3Anews%3A02jan2015&quot; class=&quot;media&quot; title=&quot;wiki:news:jan2015_objdiag.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan2015_objdiag.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
Figure 3: Object diagram of the whole application.
&lt;/p&gt;

&lt;p&gt;
To verify the overall system behavior some output port pins were used as follows:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Timer A interrupt routine shown als &lt;code&gt;clk&lt;/code&gt; in the first line. The port pin is inverted in each interrupt i.e. every 100 &lt;em&gt;ms&lt;/em&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The supply voltage goes down. As reaction the measurement stops (line 2) and the power fail LED starts flashing (line 4). The &lt;code&gt;evPowerFail&lt;/code&gt; starts from state &lt;code&gt;Running&lt;/code&gt;. As a result it can happen that the temperature measurement cycle just starts in case a &lt;code&gt;evPowerFail&lt;/code&gt; event happens but can&amp;#039;t finish. You can see this in the oscilloscope image. There is just one peak. To fix this let the &lt;code&gt;evPowerFail&lt;/code&gt; transition start from state &lt;code&gt;Step2&lt;/code&gt;. This would ensure that a measurement cycle always completes before state changes to &lt;code&gt;PowerFail&lt;/code&gt;.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Line 3 shows the timing of voltage measurement state machine (cycle of 2 seconds). &lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/jan2015_osci.png?id=wiki%3Anews%3A02jan2015&quot; class=&quot;media&quot; title=&quot;wiki:news:jan2015_osci.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan2015_osci.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
Figure 4: Oscilloscope image showing the timing of the whole application. Line 1: system tick. Line 2: timing of the temperature measurement phases. Measurement only happens if the supply voltage is above a defined threshold. Line 2: Supply voltage measurement. Line 3: LED output plus: Analog line: battery voltage.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Object Diagram&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;object_diagram&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:7,&amp;quot;range&amp;quot;:&amp;quot;10006-11737&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit8&quot; id=&quot;discussion&quot;&gt;Discussion&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; This article shows the principle concepts for designing low power embedded systems using state-machines, timers and queues.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Queues and timers as basic services which are application independent and can be reused from system to system. Timer resolution and number of timers and queues can be adjusted to optimize memory needs.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The user application is modeled as state machines receiving events from the outside or inside sources via queues. I.e. decoupling is done with queues.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; State-machine processing time must be short enough to ensure that no events get lost and overall response time is ensured.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The source code is just meant for demonstration purposes. I&amp;#039;m happy to receive suggestions for improvement which I will add and make available for others again. The code composer workspace is available for &lt;a href=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/jan2015_sample_design.zip&quot; class=&quot;media mediafile mf_zip&quot; title=&quot;wiki:news:jan2015_sample_design.zip (91.9 KB)&quot;&gt;download here&lt;/a&gt;.
&lt;/p&gt;

&lt;p&gt;
Hope you enjoyed this article. Let me know your feedback!
&lt;/p&gt;

&lt;p&gt;
Peter Mueller
&lt;/p&gt;
&lt;div class=&quot;tags&quot;&gt;&lt;span&gt;
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/msp430?do=showtag&amp;amp;tag=%5BMSP430&quot; class=&quot;wikilink1&quot; title=&quot;tag:msp430&quot; rel=&quot;tag&quot;&gt;[MSP430&lt;/a&gt;,
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/application_example?do=showtag&amp;amp;tag=Application_Example%5D&quot; class=&quot;wikilink1&quot; title=&quot;tag:application_example&quot; rel=&quot;tag&quot;&gt;Application Example]&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Discussion&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;discussion&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:4,&amp;quot;secid&amp;quot;:8,&amp;quot;range&amp;quot;:&amp;quot;11738-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 12 Mar 2023 16:50:16 +0000</pubDate>
        </item>
        <item>
            <title>New Version 2.7</title>
            <link>https://sinelabore.com/doku.php/wiki/news/3jan2012</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_version_27&quot;&gt;New Version 2.7&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;strong&gt;04.01.2012&lt;/strong&gt;
&lt;/p&gt;

&lt;p&gt;
Version 2.7 of sinelaboreRT extends the test case generation features and makes the specification of multiline state action code in EA easier. Furthermore it adds support for sub-machine states in Enterprise Architect models.
&lt;/p&gt;

&lt;p&gt;
Entering multi-line action code in EA
Entering multiline action code (entry / exit / do) for a state was so far limited to one line. The action name was used as code. Now the code can be entered into the behavior field of an action. See the figure above for an example of two lines of entry code.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/news_2_7_ea_multiline_behaviour.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot;Multiple line actions&quot; alt=&quot;Multiple line actions&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New Version 2.7&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_version_27&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-655&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;new_test_case_generation_algorithm&quot;&gt;New test case generation algorithm&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
So far the code generator used a “depth first” method to find test routes (call the codegen using option -c). The used algorithm generates test routes that are as long as possible. The benefit is that usually fewer but longer routes are generated. The figure on the right shows the &lt;a href=&quot;https://sinelabore.com/doku.php/wiki/examples/plcopen_function_block&quot; class=&quot;wikilink1&quot; title=&quot;wiki:examples:plcopen_function_block&quot; data-wiki-id=&quot;wiki:examples:plcopen_function_block&quot;&gt;Safety Function Block&lt;/a&gt; test routes as a tree. You can see how deep this tree is which corresponds to the longest test route.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/news_2_7_ea_equivalent_sc_c.jpg&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot;Depth first algorithm&quot; alt=&quot;Depth first algorithm&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
An additional new algorithms is available now (call the codegen using option -c1). It uses a &amp;#039;breadth first&amp;#039; algorithm to find test routes. It begins also at the init state and explores all the neighboring states first. Then for each of those nearest states, it explores their unexplored neighbor states, and so on, until 100% transition coverage was reached. The result are shorter but typically more test routes. The following tree shows again the &lt;a href=&quot;https://sinelabore.com/doku.php/wiki/examples/plcopen_function_block&quot; class=&quot;wikilink1&quot; title=&quot;wiki:examples:plcopen_function_block&quot; data-wiki-id=&quot;wiki:examples:plcopen_function_block&quot;&gt;PLC Open Safety Block&lt;/a&gt; test tree but now generated using the new algorithm. You can see that the tree is much broader - i.e. there are more test routes to go. But at the same time the routes are much shorter.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/news_2_7_ea_equivalent_sc_c1.jpg&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot;Breadth first algorithm&quot; alt=&quot;Breadth first algorithm&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
It is up to you which algorithm to use. A tester might probably find the shorter routes easier to understand.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New test case generation algorithm&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_test_case_generation_algorithm&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;656-2121&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;support_for_sub-machine_states_in_enterprise_architect_models&quot;&gt;Support for Sub-Machine States in Enterprise Architect Models&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Sub-machine states hide the complexity of a state from the viewer. A double click on the state opens the internals of this state. From the code generator point of view a sub-machine is a normal state with children. There is absolutely no difference compared to a normal hierarchal state. Take a look into the manual to find out more about the use of sub-machine states.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/news_2_7_ea_submachine.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Support for Sub-Machine States in Enterprise Architect Models&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;support_for_sub-machine_states_in_enterprise_architect_models&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2122-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Mon, 22 Oct 2012 19:46:29 +0000</pubDate>
        </item>
        <item>
            <title>Version 3.1</title>
            <link>https://sinelabore.com/doku.php/wiki/news/03jan2013</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;version_31&quot;&gt;Version 3.1&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Version 3.1&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;version_31&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-27&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;region_support_for_the_c_backend&quot;&gt;Region support for the C++ backend&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
A &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state might be divided into regions. Each region contains sub-states. Regions are executed in parallel. You can think of regions as independent state machines displayed in one diagram.
&lt;/p&gt;

&lt;p&gt;
For each region an own method is generated in the state machine class. Its name is automatically derived from the region name. If a state contains several regions they are called one after the other (in alphabetical order). If the event sent to the state machine was processed in one of the regions no further event handling happens in the parent state. Otherwise the event is processed in the parent state. This is similar to the event handling of normal hierarchical state machines.
&lt;/p&gt;

&lt;p&gt;
To maintain consistency during execution of machine code a copy of the instance data is created at the beginning of the state machine code. All state machine internal tests are performed on the original instance data.
All changes are done on the copy. This ensures that all regions see the same situation when running. At the end of the machine code the modified instance data is copied back to the original data.
&lt;/p&gt;

&lt;p&gt;
Here is an example how the generated C++ code looks like:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// State machine event handler&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;processEvent&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;TESTCASE_EVENT_T msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; evConsumed &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m_initialized&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;co1&quot;&gt;//Create copy of statevar&lt;/span&gt;
	stateVarsCopy &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; stateVars&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;stateVars.&lt;span class=&quot;me1&quot;&gt;stateVar&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
		&lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; S1&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
			&lt;span class=&quot;coMULTI&quot;&gt;/* calling region code */&lt;/span&gt;
			evConsumed &lt;span class=&quot;sy0&quot;&gt;|=&lt;/span&gt; testcaseS1Region1&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
			evConsumed &lt;span class=&quot;sy0&quot;&gt;|=&lt;/span&gt; testcaseS1Region2&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
			&lt;span class=&quot;coMULTI&quot;&gt;/* Check if event was already processed  */&lt;/span&gt;
			&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;evConsumed&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                          ...
&amp;nbsp;
&amp;nbsp;
                &lt;span class=&quot;kw2&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/* end switch stateVar_root */&lt;/span&gt;
	&lt;span class=&quot;co1&quot;&gt;// Copy state variables back&lt;/span&gt;
	stateVars &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; stateVarsCopy&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; evConsumed&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// end processEvent&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Region handler code for state S1 Region1&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;testcaseS1Region1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;TESTCASE_EVENT_T msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
   ...
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Region handler code for state S1 Region2&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;testcaseS1Region2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;TESTCASE_EVENT_T msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
   ...
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Region support for the C++ backend&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;region_support_for_the_c_backend&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;28-2097&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;new_parameter_prefixstatenameswithmachinename&quot;&gt;New Parameter PrefixStateNamesWithMachineName&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
This parameter allows to prefix state names with the C machine name. Use this option if multiple state-machine header files are included into one other file (e.g. main.c) to avoid definition conflicts due to double used state names. See also parameter PrefixMsg- WithMachineName.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New Parameter PrefixStateNamesWithMachineName&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_parameter_prefixstatenameswithmachinename&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2098-2436&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;new_parameter_prefixstatenameswithparentname&quot;&gt;New Parameter PrefixStateNamesWithParentName&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
This parameter allows to prefix state names with the parent state name. Use this option if you have a hierarchical state machine and want to use the same state names in different child states. Example: There are two parent states called &lt;code&gt;EngineOn&lt;/code&gt; and &lt;code&gt;EngineOff&lt;/code&gt;. And in both states you have children &lt;code&gt;FuelPumpOn&lt;/code&gt; and &lt;code&gt;FuelPumpOff&lt;/code&gt;. To make the children names unique they can be prefixed with the parent name.
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New Parameter PrefixStateNamesWithParentName&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_parameter_prefixstatenameswithparentname&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2437-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Thu, 03 Jan 2013 19:48:21 +0000</pubDate>
        </item>
        <item>
            <title>Initial pseudo-states can end in a choice state now</title>
            <link>https://sinelabore.com/doku.php/wiki/news/3nov2013</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;initial_pseudo-states_can_end_in_a_choice_state_now&quot;&gt;Initial pseudo-states can end in a choice state now&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In the current released version of sinelabore it is only possible to connect an initial pseudo-state to a normal state (hierarchical or flat). In some situations is is desirable to decide at runtime which state should be active initially when entering the state machine or a hierarchical state.
&lt;/p&gt;

&lt;p&gt;
For that purpose it is now possible to connect the initial pseudo-state to a choice state which then points to the real initial state. This is possible
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; on the root level of a state machine diagram&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; in hierarchical states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; in regions&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; in sub-machines&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
This adds a lot of new possibilities to design state diagrams.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/init2choice.jpg&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
This new feature requires a lot of coding internal in the generator backends and other parts of the code. Therefore this feature is only available in the CX backend initially. Also some other features of the code generator can&amp;#039;t be used at the moment if “init to choice transitions” are used. Not available is:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; test case generation&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; simulation / editing using the built in editor&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; robustness checks (partly)&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
More backends and the missing features will be added step by step depending on your feedback.
&lt;/p&gt;

&lt;p&gt;
Please send me a note if you want to test the new beta. Feedback is highly welcome!
&lt;/p&gt;

&lt;p&gt;
{(rater&amp;gt;id=7|name=How do you like this article?|type=rate)}
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 17 Aug 2022 17:47:15 +0000</pubDate>
        </item>
        <item>
            <title>New versions 2.8.1 to 2.8.3</title>
            <link>https://sinelabore.com/doku.php/wiki/news/5aug2012</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_versions_281_to_283&quot;&gt;New versions 2.8.1 to 2.8.3&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
This update of the SinelaboreRT code helps Enterprise Architect and Magic Draw users to keep complex state diagrams with many transitions and/or states well-arranged.
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;entry_exit_points&quot;&gt;Entry &amp;amp; Exit Points&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
So far transitions entering a sub-machine always had to end in the initial state. If this is not what you want it is possible now to use entry points to overcome this limitation. Entry points serve as glue between the sub-machine state and the internal of the sub- machine.
&lt;/p&gt;

&lt;p&gt;
Exit states provide a similar function. If a transition should start from a specific state inside the sub-machine and should enter a state outside the sub-machine an exit state can be used. Again this exit state serves as glue between the inside and outside view.
&lt;/p&gt;

&lt;p&gt;
The following figures shows a state diagram with the sub-machine state S2 and the internals of this sub-machine state.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/8aug2012_img1.jpg?id=wiki%3Anews%3A5aug2012&quot; class=&quot;media&quot; title=&quot;wiki:8aug2012_img1.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/8aug2012_img1.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/8aug2012_img2.jpg?id=wiki%3Anews%3A5aug2012&quot; class=&quot;media&quot; title=&quot;wiki:8aug2012_img2.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/8aug2012_img2.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;multiple_triggers_per_transition&quot;&gt;Multiple Triggers per Transition&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
EA allows to define more than one trigger for a transition. This is useful if different triggers should trigger the same transition and have the same action code.
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;multiple_transitions_ending_in_a_choice&quot;&gt;Multiple Transitions ending in a Choice&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
To simplify complex state diagrams it can be helpful to specify multiple incoming transitions into a choice state instead of duplicating the choices. The left side of the diagram shows how much simpler the right diagram can be represented now. Internally - before code generation starts - the code generator transforms your drawing back to the left representation.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/8aug2012_img3.jpg?id=wiki%3Anews%3A5aug2012&quot; class=&quot;media&quot; title=&quot;wiki:8aug2012_img3.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/8aug2012_img3.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/images/smileys/exclaim.svg&quot; class=&quot;icon smiley&quot; alt=&quot;:!:&quot; /&gt; This version of the code-generator uses the new jdom2.jar 
package. Copy the jar file to the correct place on your PC. 
If you don&amp;#039;t know what this means please read section 
&amp;#039;Installation&amp;#039; in the manual.
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Mon, 22 Oct 2012 19:07:06 +0000</pubDate>
        </item>
        <item>
            <title>Swift backend added</title>
            <link>https://sinelabore.com/doku.php/wiki/news/5sep2014</link>
            <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;swift_backend_added&quot;&gt;Swift backend added&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/apple_swift_logo.png?w=100&amp;amp;tok=7c0ccd&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;100&quot; /&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Swift_(programming_language)&quot; class=&quot;urlextern&quot; title=&quot;https://en.wikipedia.org/wiki/Swift_(programming_language)&quot; rel=&quot;ugc nofollow&quot;&gt;Swift&lt;/a&gt; is a new object-oriented programming language for iOS and &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X development. To generate Swift code call the code generator with the command line flag &lt;code&gt;−l swift&lt;/code&gt; . To gener- ate a configuration file with all parameters related to the Swift code generation call the code generator as follows once: 
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;java −jar codegen.jar −l swift −gencfg &amp;gt; codegen.cfg&lt;/code&gt; .
&lt;/p&gt;

&lt;p&gt;
The events that can be sent to the machine are defined in a public enumeration.
&lt;/p&gt;

&lt;p&gt;
The generator generates just one
Swift class which implements the complete state machine. This has the benefit
that your Swift project does not become bloated with all kinds of helper
classes. This means that the generated code does not follow the usual state pattern as
you might expect (if you are familiar with common design patterns).  The reason
is that the machine code is  completely generated and no hand-coding is involved. 
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Swift backend added&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;swift_backend_added&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;14-1049&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;separate_generated_from_non-generated_code&quot;&gt;Separate generated from non-generated Code&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
Even if the state machine is fully generated this is usually only a smaller part
of your application whereas the lager part is coded manually. For several
reasons it is important to clearly separate generated code from non-generated
code. Use one of the following possibilities to achieve this.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The most basic method is to put hand written code into libraries and call the library from within the state machine.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Generated classes can also subclass non-generated classes (base class of StateMachine). Such base classes can contain useful methods that can be called from within the generated subclasses.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Hand written code is located in a child class of the state machine. I.e. the state machine classes are parts of other classes.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Separate generated from non-generated Code&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;separate_generated_from_non-generated_code&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1050-1845&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;supported_state_machine_features&quot;&gt;Supported state machine features&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; States and sub-states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Deep - and flat hierarchy&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Entry, Exit and Action code of states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Regions are supported and implemented as sub-functions called from the main state machine handler.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Option to define state machine signature&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Choice pseudo-states&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Supported state machine features&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;supported_state_machine_features&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1846-2160&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;example_design_and_generated_code&quot;&gt;Example Design and Generated Code&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/swift_state_machine.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/swift_testcase.swift&quot; class=&quot;media mediafile mf_swift&quot; title=&quot;wiki:news:swift_testcase.swift (19.4 KB)&quot;&gt;swift_testcase.swift&lt;/a&gt;
&lt;/p&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_start&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;&lt;div class=&quot;wrap_round wrap_info plugin_wrap&quot; style=&quot;width: 60%;&quot;&gt;
&lt;p&gt;
Please note that the Swift back-end is work-in-progress.
If you are interested to test and work with the code generator send me a mail
and you will receive the latest beta version.
Your feedback and feature requests are highly welcome!
&lt;/p&gt;
&lt;/div&gt;&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;plugin_wrap_end&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;&amp;quot;,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;0-&amp;quot;} --&gt;
&lt;p&gt;
~~DISCUSSION|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Example Design and Generated Code&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;example_design_and_generated_code&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;2161-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Fri, 03 May 2024 20:42:32 +0000</pubDate>
        </item>
        <item>
            <title>Generate code from Astah* activity diagrams</title>
            <link>https://sinelabore.com/doku.php/wiki/news/7june2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;generate_code_from_astah_activity_diagrams&quot;&gt;Generate code from Astah* activity diagrams&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In the latest version of the SinelaboreRT code generator support for activity diagrams was added for &lt;a href=&quot;http://astah.net&quot; class=&quot;urlextern&quot; title=&quot;http://astah.net&quot; rel=&quot;ugc nofollow&quot;&gt;astah*&lt;/a&gt; users. astah* is a &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; modeling tool written in Java and can therefore run on various platforms like Windows or Mac. In opposite to some other tools it provides a Java &lt;abbr title=&quot;Application Programming Interface&quot;&gt;API&lt;/abbr&gt; for direct access of the model file. Therefore it is not necessary to export the model (e.g. in XMI format) but the SinelaboreRT code generator can directly access the model file. This makes the development cycle very fast. Give it a try!
&lt;/p&gt;

&lt;p&gt;
The following figure shows an extended version of the microwave oven example. A simple hardware selftest function was added to the transition leaving the initial state. In case this test is ok the software enters the normal operation states. Otherwise an error state.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/astah_machine.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The hardware selftest function was modelled as activity. The activity itself is trivial but enough to show the new possibilities. The code of each action forming the activity is available in the properties dialog of the actions. Take a look into the manual what other diagram elements can be used.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/astah_selftest.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
To generate code from the activity diagram use the following commands (command line on a Mac):
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;java -Djava.ext.dirs=“../../bin/”:“/Applications/astah community/astah community.app/Contents/Java/” -Djava.awt.headless=true -jar ../../bin/codegen.jar -l cx -A -v -p ASTAH -o oven -t “final:oven:selftest”&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
The &lt;code&gt;-D&lt;/code&gt; options tells java where to look for the jar files. The new option &lt;code&gt;-A&lt;/code&gt; enables code generation for activity diagrams. 
&lt;/p&gt;

&lt;p&gt;
In case of questions, problems or suggestions please contact us.
&lt;/p&gt;

&lt;p&gt;
Have fun!
Peter
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 07 Jun 2014 09:44:09 +0000</pubDate>
        </item>
        <item>
            <title>New Version 3.0</title>
            <link>https://sinelabore.com/doku.php/wiki/news/07nov2012</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_version_30&quot;&gt;New Version 3.0&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New Version 3.0&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_version_30&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-31&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;generate_code_from_state_machines_with_regions&quot;&gt;Generate code from state machines with regions&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
In state diagrams usually only one state is active at a time. In &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state diagrams regions also allow to model concurrency - i.e. more than one state is active at a time (AND states).  
&lt;/p&gt;

&lt;p&gt;
A &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state may be divided into regions. Each region contains sub-states. Regions are executed in parallel. You can think of regions as independent state machines displayed in one diagram. The state machine below (Fig. 1) shows several regions each running in parallel in the state &lt;code&gt;Active&lt;/code&gt;. Dashed lines are used to divide a state into regions. 
&lt;/p&gt;

&lt;p&gt;
Consider a microwave oven. The power setting, light and microwave radiator are be considered as independent (concurrent) parts of the oven, each with its own states. The door and timer as the main external trigger are used in the regions to trigger state transitions. For example the radiator is switched on if the door gets closed and the timer is &amp;gt; zero. 
&lt;/p&gt;

&lt;p&gt;
As you can see multiple concurrent regions can be used to explicitly visualize different parts of a device. And all the states in the one diagram.
&lt;/p&gt;

&lt;p&gt;
The model and the generated code thereof is provided in the examples folder of the current release. 
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_with_regions_umodel.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Oven model with regions&quot; alt=&quot; Oven model with regions&quot; /&gt;
Figure 1a: State machine model of a microwave oven using regions (created with UModel).
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Generate code from state machines with regions&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;generate_code_from_state_machines_with_regions&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;32-1408&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;uml_tool_modelio_supported&quot;&gt;UML tool Modelio supported&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Modelio is an open source modeling environment based on Eclipse and providing high quality &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; modeling capabilities. Commercial support is available too. The following figures show state diagrams created with Modelio. The tool runs on Linux and Windows.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/and_states_modelio.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
Model with parallel regions.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/sub_machine_top_modelio.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
Model with a sub-machine in state S2.
&lt;/p&gt;

&lt;p&gt;
Supported state diagram features:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Hierarchical states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Regions (CX language backend only)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Sub-machines in a top level state&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; (Signal-)Events with event name, guard and action&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Initial and final pseudo-states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; History states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Choices&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
For a quick start download the latest release version and import the microwave oven
into your Modelio workspace.
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;UML tool Modelio supported&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;uml_tool_modelio_supported&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1409-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 29 Jan 2013 17:09:59 +0000</pubDate>
        </item>
        <item>
            <title>Multiple instances of the same machine</title>
            <link>https://sinelabore.com/doku.php/wiki/news/10oct2013</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;multiple_instances_of_the_same_machine&quot;&gt;Multiple instances of the same machine&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Sometimes you want to run the same state machine multiple times. E.g. processing three serial interfaces with the same state machine. In object orient languages this is easy as the concept of objects is the basis of these languages. You would simply instantiate the class three times.
&lt;/p&gt;

&lt;p&gt;
Luckily in C there is also a well known concept to do this. Instead of defining objects you define a (instance) structure that contains all local data a function needs. When calling that function a pointer to the instance data structure is handed over. In our case the function is the state machine handler. The code generator automatically creates the instance data structure automatically for you.
&lt;/p&gt;

&lt;p&gt;
In this example we will show you how to “create multiple instances” of the state machine.
And then we show you how to create an own structure where additional private data for the state handler can be defined.
&lt;/p&gt;

&lt;p&gt;
Let&amp;#039;s start …
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Multiple instances of the same machine&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;multiple_instances_of_the_same_machine&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-969&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;create_multiple_instances&quot;&gt;Create Multiple Instances&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Follow these simple steps to prepare the generated code for multiple instances. First set some parameters in the configuration file:
&lt;/p&gt;
&lt;ol&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Set parameter &lt;code&gt;HsmFunctionWithInstanceParameters&lt;/code&gt; to &lt;code&gt;YES&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Set parameter &lt;code&gt;HsmFunctionWithEventParameter&lt;/code&gt; to &lt;code&gt;YES&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;
As a result the generated state machine handler signature looks like this:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;  testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;TESTCASE_INSTANCEDATA_T&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; userInstanceVar&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; TESTCASE_EVENT_T msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
You can now simply declare multiple variables of type TESTCASE_INSTANCEDATA_T which contains the data per instance. When calling the state machine just point to one of these variables. 
&lt;/p&gt;

&lt;p&gt;
Sometimes it is necessary that a state machine knows on which object it currently works on. Therefore a predefined member called &lt;code&gt;inst_id&lt;/code&gt; is generated by default. You can set it to any value that makes sense in your context (e.g. provide the COM port number the machine currently processes).
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;TESTCASE_INSTANCEDATA_T instDataA &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
TESTCASE_INSTANCEDATA_T instDataB &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
TESTCASE_INSTANCEDATA_T instDataC &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Set object ID if the machine needs to know which object it is&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// E.g. which serial port to open ...&lt;/span&gt;
instDataA.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
instDataB.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
instDataC.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// call &amp;quot;object A&amp;quot;&lt;/span&gt;
testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;instDataA&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// call &amp;quot;object B&amp;quot;&lt;/span&gt;
testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;instDataB&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// call &amp;quot;object C&amp;quot;&lt;/span&gt;
testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;instDataC&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
I think you agree that there is no magic in running multiple instances of the state handler.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Create Multiple Instances&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;create_multiple_instances&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;970-2556&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;provide_an_own_instance_structure&quot;&gt;Provide an own Instance Structure&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Sometimes it makes sense to provide an own instance structure. In our example we want to store the baud rate, parity and other values relevant for each serial port.
&lt;/p&gt;

&lt;p&gt;
So first define an own struct in a file called &lt;code&gt;own_inst_type.h&lt;/code&gt; (as an example). The example below shows how to define local variables like the &lt;code&gt;noRxBytes&lt;/code&gt; (number of already defined bytes) as well as parameters like the parity etc.
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#ifndef __OWN_INST_TYPE__&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#define __OWN_INST_TYPE__&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; InstanceData MY_TESTCASE_INSTANCEDATA_T&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;stdint.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;lt;testcase_ext.h&amp;gt;&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#include &amp;quot;testcase.h&amp;quot;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;struct&lt;/span&gt; InstanceData&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint16_t&lt;/span&gt; baudrate&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; noBits&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; parity&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; stopBit&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; 
        TESTCASE_INSTANCEDATA_T instanceVar&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co2&quot;&gt;#endif // __OWN_INST_TYPE__&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Then tell the code generator to use this struct. Add the third line to the configuration file which then looks like this:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;HsmFunctionWithInstanceParameters=YES
HsmFunctionWithEventParameter=YES
HsmFunctionUserDefinedParameter=MY_TESTCASE_INSTANCEDATA_T&lt;/pre&gt;

&lt;p&gt;
The generated state machine signature now looks as follows. The difference is that the own instance structure is now used instead of the generic one.
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;  testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;MY_TESTCASE_INSTANCEDATA_T&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; userInstanceVar&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; TESTCASE_EVENT_T msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
To use the newly defined instance type declare the instance variables now as follows:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// init three different serial ports&lt;/span&gt;
MY_TESTCASE_INSTANCEDATA_T instDataA &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&#039;N&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
MY_TESTCASE_INSTANCEDATA_T instDataB &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;19200&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&#039;E&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
MY_TESTCASE_INSTANCEDATA_T instDataC &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;9600&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&#039;N&#039;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;TESTCASE_INSTANCEDATA_INIT&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// Set object ID if the machine needs to know which object it is&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// E.g. which serial port to open ...&lt;/span&gt;
instDataA.&lt;span class=&quot;me1&quot;&gt;instanceVar&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
instDataB.&lt;span class=&quot;me1&quot;&gt;instanceVar&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
instDataC.&lt;span class=&quot;me1&quot;&gt;instanceVar&lt;/span&gt;.&lt;span class=&quot;me1&quot;&gt;inst_id&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// call &amp;quot;object A&amp;quot;&lt;/span&gt;
testcase&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;instDataA&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Now the state machine is ready to use the new private instance data inside the machine code.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Provide an own Instance Structure&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;provide_an_own_instance_structure&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:2,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;2557-4662&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;putting_all_things_together&quot;&gt;Putting all Things Together&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Coming back now to the example of three serial interfaces. The following figure shows a simplified state machine for handling a serial interface. The state machine is generic. Whether COM0 or COM1 or COM2 is processed is determined only from the content of the instance variable. And also other parameters are stored there and of course the local machine variables.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/multiple_instances.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
I hope that the concepts how to run multiple state machines of the same type are clearer now. And also how to define an own instance structure that is necessary for more complex machines.
&lt;/p&gt;

&lt;p&gt;
In case of any questions don&amp;#039;t hesitate to contact me!
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Putting all Things Together&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;putting_all_things_together&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:6,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;4663-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 17 Aug 2022 17:44:23 +0000</pubDate>
        </item>
        <item>
            <title>Creating complex state machines</title>
            <link>https://sinelabore.com/doku.php/wiki/news/10sep2013</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;creating_complex_state_machines&quot;&gt;Creating complex state machines&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The sinelabore code generator allows the generation of state machine
code from quite complex state machines.
&lt;/p&gt;

&lt;p&gt;
Nevertheless there are users who want to generate code from even more
complex models. Especially if you used specialized state machine modeling tools
before and now want to switch to general purpose &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; tools this is for you.
&lt;/p&gt;

&lt;p&gt;
Examples for features not possible before are states in regions that contain regions again (region in region&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt;.
Or models with sub-machines in regions. Both is shown in the figure below.
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/sm_ea_region_region.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
{(rater&amp;gt;id=5|name=How do you like this article?|type=rate)}
~~DISCUSSION|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;Regions are well supported from the code-generator. But simulation and test-case generation is not yet possible. For more details have a look in the manual.&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sat, 21 Sep 2013 17:12:45 +0000</pubDate>
        </item>
        <item>
            <title>Building a ModbusRTU server with state machines, activity diagrams and minimal runtime environment</title>
            <link>https://sinelabore.com/doku.php/wiki/news/11aug2015</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;building_a_modbusrtu_server_with_state_machines_activity_diagrams_and_minimal_runtime_environment&quot;&gt;Building a ModbusRTU server with state machines, activity diagrams and minimal runtime environment&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In one of the last design articles I described how to use state-machines in low power embedded software design together with timers and queues to create a wireless sensor node.
&lt;/p&gt;

&lt;p&gt;
This time I use the same architecture to design and implement a basic ModbusRTU server.  A &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state machine diagram shows the core behavior of the server. An activity diagram shows how the received frame is checked and a reply telegram generated. The server supports not all function codes and has a simple address map. But it will be easy to expand the design with more features.
&lt;/p&gt;

&lt;p&gt;
The design is based again on a small TI MSP430 board already used in the previous article. The whole server runs in  less than 256 bytes of ram and needs only few kilobytes of code. A RS485 interface was added as physical interface as defined by the ModbusRTU specification.
&lt;/p&gt;

&lt;p&gt;
Modbus defines function codes to read/write either bit or word data. Function code four is defined to read analog input words (in our case only simulated values). Function codes one and five are defined to read/write digital outputs (coils). For demo purposes a LED is connected to a port pin of the µC.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/modbus_schematic.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
For those not familiar with Modbus and ModbusRTU. Have a look &lt;a href=&quot;http://www.modbus.org&quot; class=&quot;urlextern&quot; title=&quot;http://www.modbus.org&quot; rel=&quot;ugc nofollow&quot;&gt;www.modbus.org&lt;/a&gt; and search for the technical specification of the RS485 layer and the ModbusRTU server protocol.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Building a ModbusRTU server with state machines, activity diagrams and minimal runtime environment&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;building_a_modbusrtu_server_with_state_machines_activity_diagrams_and_minimal_runtime_environment&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-1493&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit2&quot; id=&quot;overall_system_design&quot;&gt;Overall System Design&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The model was realized with the Astah &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; Editor. The model file is available here
&lt;a href=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/modbus.asta&quot; class=&quot;media mediafile mf_asta&quot; title=&quot;wiki:news:modbus_client:modbus.asta (24.1 KB)&quot;&gt;modbus.asta&lt;/a&gt; for download.
The fastest overview provides an interaction diagram (see below). The relevant players are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;modbus&lt;/code&gt;: The central function realizing the modbus server functionality. The code was fully     generated from a state machine diagram discussed later on. &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;modbus_helper&lt;/code&gt;: Helper functions used from the state machine and the rx frame checking code.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;ringbuf&lt;/code&gt;, &lt;code&gt;timer&lt;/code&gt;, &lt;code&gt;crc16&lt;/code&gt; …: Library classes that can be reused from project to project. These classes were already used in the previous examples (e.g. wireless temperature sensor).&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;timerA&lt;/code&gt;: Hardware timer to generate system tick&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;code&gt;rs485&lt;/code&gt;: serial interface handler&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The &lt;code&gt;main()&lt;/code&gt; function initializing the hardware and software is not shown. It cyclically calls the modbus state machine and timer. In case of any pending events the modbus state machine is called. 
&lt;/p&gt;

&lt;p&gt;
For practical reasons classes were implemened as C/H files and member functions as C-functions. In the case a class is used multiple times instance data is packed into a structure and provided as reference to the functions. An example for this “object aware programming” is the fifo class. 
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/modbus_client/objectdiagram.png?id=wiki%3Anews%3A11aug2015&quot; class=&quot;media&quot; title=&quot;wiki:news:modbus_client:objectdiagram.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/objectdiagram.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Beside the object interaction diagram the following workspace view shows the project structure and used/generated files.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/modbus_workspace.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Overall System Design&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;overall_system_design&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;1494-3051&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit3&quot; id=&quot;modbusrtu_state_machine&quot;&gt;ModbusRTU State Machine&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The state machine starts in state &lt;code&gt;Idle&lt;/code&gt;. It initially enables the receiver and waits for the first byte. Then it changes to state &lt;code&gt;Receiving&lt;/code&gt; until the complete frame was received. Every new byte retriggers the timer. The condition to detect that a complete frame was received is not receiving any new byte for a given amount of time (depends on baud rate, about 4ms @ 9600 Baud). The timer event evTimeout indicates this. The frame is checked before exiting the &lt;code&gt;Receiving&lt;/code&gt; state (explained later on). Depending of the check result the machine either
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; enters &lt;code&gt;Idle&lt;/code&gt; again without answering the request (see Modbus &lt;abbr title=&quot;specification&quot;&gt;spec&lt;/abbr&gt;)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; enables the transmitter and sends an error message back to the master&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; enables the transmitter and sends requested information back to the master.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
When the complete reply frame was sent  - indicated by event &lt;code&gt;evTxDone&lt;/code&gt; from the rs485 transceiver - the state machine waits for about 4ms to indicate frame end and then goes to state &lt;code&gt;Idle&lt;/code&gt; again waiting for the next frame.
&lt;/p&gt;

&lt;p&gt;
Despite the ModbusRTU state machine looks simple it implements everything required for a slave!
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/rxtx_machine.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;ModbusRTU State Machine&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;modbusrtu_state_machine&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;3052-4261&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit4&quot; id=&quot;checking_the_received_frame&quot;&gt;Checking the Received Frame&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Quite some complexity is hidden in checking the received frame (exit code of state &lt;code&gt;Receiving&lt;/code&gt;). Therefore this function is designed with the help of an activity diagram and is fully generated from the code generator. The ModbusRTU specification uses flow charts. I tooke over the flow charts to a certain extend and reused that way what the ModbusRTU designers put into the &lt;abbr title=&quot;specification&quot;&gt;spec&lt;/abbr&gt;. 
&lt;/p&gt;

&lt;p&gt;
The ModbusRTU &lt;abbr title=&quot;specification&quot;&gt;spec&lt;/abbr&gt; contains an own flow chart for each function code. The presented design combined these single diagrams into just one activity diagram. As a consequence the single activities (e.g. check number of inputs, check valid address range) uses the function code to distinguish different requests. It is a matter of taste if this should also be made explicit in the activity diagram.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/check_rx_frame.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Checking the Received Frame&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;checking_the_received_frame&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;4262-5141&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit5&quot; id=&quot;testing&quot;&gt;Testing&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
To test the complete design and implementation a ModbusRTU master is required. The next figures shows &lt;em&gt;QModbus&lt;/em&gt; [2] running on a Linux box. There are also other command line tools which makes batch testing simpler.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/modbus_master.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The timing of the final device is shown below. D0 shows the system clock generated by hardware timer A. It calls the timer tick function. If no timer events were detected the CPU enters low power mode again. D2 shows the receiving telegram. D1 the transmission telegram. The CPU replys within 14ms. This could be further optimized if needed. The RS485 line is shown in the bottom part as differential signal (CH1-CH2).
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/modbus_client/modbus_timing.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
One hint regarding stack-check: During development I had the need to check how much stack my code needs. I found the following code snipped on the web which turned out to be very useful. After running my test cases I could directly see how much space was left just looking at the memory browser window.
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;    &lt;span class=&quot;co1&quot;&gt;// for checking the stack later on&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;extern&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; _stack&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;extern&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; __STACK_END&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw4&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt; p&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
    p &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;_stack&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;p &lt;span class=&quot;sy0&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;__STACK_END &lt;span class=&quot;sy0&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;p &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu12&quot;&gt;0xA5A5&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        p&lt;span class=&quot;sy0&quot;&gt;++;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// end for checking the stack later on&lt;/span&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Testing&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;testing&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;5142-6507&amp;quot;} --&gt;
&lt;h1 class=&quot;sectionedit6&quot; id=&quot;wrapping_up&quot;&gt;Wrapping Up&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
This article has presented the design of a MobusRTU server. It is is based on some library classes which can be reused from project to project. In addition state machine and activity diagrams were used to model the behavior of the device. From these models code was generated. So the design and the code will be always in sync and the modes are not just drawings!
&lt;/p&gt;

&lt;p&gt;
The source code and model file is available upon request. I&amp;#039;m happy to receive suggestions for improvement which I will add and make available for others again. 
&lt;/p&gt;

&lt;p&gt;
Hope you enjoyed this article. Let me know your feedback!
Peter
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;
References:
[1] &lt;a href=&quot;http://www.modbus.org&quot; class=&quot;urlextern&quot; title=&quot;http://www.modbus.org&quot; rel=&quot;ugc nofollow&quot;&gt;www.modbus.org&lt;/a&gt;
[2] &lt;a href=&quot;http://qmodbus.sourceforge.net&quot; class=&quot;urlextern&quot; title=&quot;http://qmodbus.sourceforge.net&quot; rel=&quot;ugc nofollow&quot;&gt;http://qmodbus.sourceforge.net&lt;/a&gt;
&lt;/p&gt;
&lt;div class=&quot;tags&quot;&gt;&lt;span&gt;
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/modbus?do=showtag&amp;amp;tag=%5BModbus&quot; class=&quot;wikilink1&quot; title=&quot;tag:modbus&quot; rel=&quot;tag&quot;&gt;[Modbus&lt;/a&gt;,
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/modbusrtu?do=showtag&amp;amp;tag=ModbusRTU&quot; class=&quot;wikilink1&quot; title=&quot;tag:modbusrtu&quot; rel=&quot;tag&quot;&gt;ModbusRTU&lt;/a&gt;,
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/application_example?do=showtag&amp;amp;tag=Application_Example&quot; class=&quot;wikilink1&quot; title=&quot;tag:application_example&quot; rel=&quot;tag&quot;&gt;Application Example&lt;/a&gt;,
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/activity?do=showtag&amp;amp;tag=Activity&quot; class=&quot;wikilink1&quot; title=&quot;tag:activity&quot; rel=&quot;tag&quot;&gt;Activity&lt;/a&gt;,
	&lt;a href=&quot;https://sinelabore.com/doku.php/tag/msp430?do=showtag&amp;amp;tag=MSP430%5D&quot; class=&quot;wikilink1&quot; title=&quot;tag:msp430&quot; rel=&quot;tag&quot;&gt;MSP430]&lt;/a&gt;
&lt;/span&gt;&lt;/div&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Wrapping Up&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;wrapping_up&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;6508-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 17 Aug 2022 17:41:59 +0000</pubDate>
        </item>
        <item>
            <title>Using State-Machines in Low-Power Embedded Systems - Part II</title>
            <link>https://sinelabore.com/doku.php/wiki/news/12feb2015</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;using_state-machines_in_low-power_embedded_systems_-_part_ii&quot;&gt;Using State-Machines in Low-Power Embedded Systems - Part II&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In the last part I&amp;#039;ve described a basic system design based on &lt;strong&gt;state machines&lt;/strong&gt;, &lt;strong&gt;timers&lt;/strong&gt; and &lt;strong&gt;queues&lt;/strong&gt;. In this short update I extend the existing design with a radio transmitting the measured temperature to a central server. The updated hardware diagram looks as follows:
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/feb2015schematics.png?id=wiki%3Anews%3A12feb2015&quot; class=&quot;media&quot; title=&quot;wiki:news:feb2015schematics.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/feb2015schematics.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
One new hardware signal is the &lt;code&gt;/RTS&lt;/code&gt; line indicating readiness of the radio. The other one is an output signal to drive the radio into &lt;code&gt;sleep mode&lt;/code&gt; and back into &lt;code&gt;active&lt;/code&gt; mode.
&lt;/p&gt;

&lt;p&gt;
The updated state machine works as follows. To keep the battery driven system running as long as possible the radio is in low-power mode most of the time. Only just before sending the µC wakes-up the radio in &lt;code&gt;Step2a&lt;/code&gt;. The falling edge of the &lt;code&gt;/RTS&lt;/code&gt; signal indicates the radio readiness which leads into &lt;code&gt;Step2&lt;/code&gt;. In &lt;code&gt;Step2&lt;/code&gt; transmission takes place on interrupt basis (started by putchar()). During transmission &lt;code&gt;/RTS&lt;/code&gt; is high. If transmission is over &lt;code&gt;/RTS&lt;/code&gt; goes to low again. If this happens the radio is switched off again. In case transmission couldn’t completed the radio is switched off latest after 200ms. In &lt;code&gt;Step3&lt;/code&gt; we wait for 5s then the board signals the successful transmission with a short blink code (state &lt;code&gt;BlinkGood&lt;/code&gt;). An then the cycle begins again. Output PORT1/Bit1 is used for debugging purposes. In low power mode just the LED blinks two times slowly to indicate low battery.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/feb2015_toggle.png?id=wiki%3Anews%3A12feb2015&quot; class=&quot;media&quot; title=&quot;wiki:news:feb2015_toggle.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/feb2015_toggle.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
To feed in the /RTS signal into the state machine a new interrupt handler was added as shown below:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co2&quot;&gt;#pragma vector=PORT2_VECTOR&lt;/span&gt;
__interrupt &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; Port_2&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;fifoPut&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;buf1&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; evFallingEdgeRTS&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		globalErrHandler&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// buffer full&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		P2IFG &lt;span class=&quot;sy0&quot;&gt;&amp;amp;=&lt;/span&gt; ~RADIO_RTS&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		disableRtsIRQ&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;co1&quot;&gt;// wake up main routine to process state machines&lt;/span&gt;
		__bic_SR_register_on_exit&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;LPM3_bits&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Listing 1: The falling edge event is put into the fifo queue. The state machine takes out event by event from that queue processing the events.
&lt;/p&gt;

&lt;p&gt;
The main part of the UART code is the &lt;code&gt;putchar()&lt;/code&gt; function and the transmit interrupt.
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;co1&quot;&gt;// Send a character via serial interface. If no transmission is running&lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// the character is directly put into the tx register, otherwise enqueued.&lt;/span&gt;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; &lt;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/putchar.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;putchar&lt;/span&gt;&lt;/a&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; cByte&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
	TX_INT_DISABLE&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// disable transmit interrupt (in IE2)&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;fifoIsEmpty&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;txbuf&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;sy0&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!&lt;/span&gt;txrunning&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// queue empty and no transmission running&lt;/span&gt;
	    txrunning&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	    TXBUF0 &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; cByte&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// load tx register, inc index&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		fifoPut&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;txbuf&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; cByte&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
	TX_INT_ENABLE&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// enable interrupt (in IE2)&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
&lt;span class=&quot;co1&quot;&gt;// UART0 TX ISR. &lt;/span&gt;
&lt;span class=&quot;co1&quot;&gt;// The isr takes out the next char from the fifo.&lt;/span&gt;
&lt;span class=&quot;co2&quot;&gt;#pragma vector=USART0TX_VECTOR&lt;/span&gt;
__interrupt &lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt; usart0_tx &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
	&lt;span class=&quot;kw4&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; txchar&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
	bool empty &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; fifoGet&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;amp;&lt;/span&gt;txbuf&lt;span class=&quot;sy0&quot;&gt;,&amp;amp;&lt;/span&gt;txchar&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	_EINT&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;!&lt;/span&gt;empty&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		TXBUF0 &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; txchar&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;co1&quot;&gt;// buffer empty, nothing to do&lt;/span&gt;
		txrunning&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
The updated state machine design was created with the built-in state machine editor of Sinelabore&lt;em&gt;RT&lt;/em&gt;. The reason is simple: I wanted to use the development environment CCS from Texas Instruments on Linux. And Cadifra is only available on Windows. But this was no problem because every state machine can be automatically migrated to the internal editor.
Those of you not knowing CCS should really take a look on it. It has some really cool features - e.g. the power measurement option to just name one.
&lt;/p&gt;

&lt;p&gt;
Let me know if you are interested in the complete source code or need more explanation.
&lt;/p&gt;

&lt;p&gt;
Have fun!
Peter
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 17 Aug 2022 17:42:03 +0000</pubDate>
        </item>
        <item>
            <title>New version 3.6 has support for activity diagrams</title>
            <link>https://sinelabore.com/doku.php/wiki/news/12may2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_version_36_has_support_for_activity_diagrams&quot;&gt;New version 3.6 has support for activity diagrams&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
There are two diagrams that can be used to express dynamic behaviour in the &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt;. State machine diagrams express the states of an object and the events and transitions to change the state. In contrast activity diagrams (aka flow diagrams) describe the control flow of an algorithm. The great thing of both types of diagrams is that they allow to generate 100% code out of the model description.
&lt;/p&gt;

&lt;p&gt;
The latest version of the sinelabore code generator can now also generate code from activity diagrams. Activity diagrams consist of the following elements:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Black circle to indicate the begin of the activity&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Circled black circle to indicate the end of the activity (return)&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Rounded rectangles representing actions&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Diamonds representing decisions and merge&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Arrows connect the other elements and represent the flow throughout the diagram. Arrows might have a guard expression. If the guard expression is true the control flow follows this arrow to the next action.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Activity diagrams might contain sub-activities&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
In addition to this basic elements &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; activity diagrams also allow to model loops and decisions.
&lt;/p&gt;

&lt;p&gt;
To generate code from an activity diagram just call the code generator with the new command line parameter &lt;code&gt;-A&lt;/code&gt;. The other command line parameters are still the same. Use the &lt;code&gt;-t&lt;/code&gt; parameter to define the path in the model file to the class containing the activity. And &lt;code&gt;-l&lt;/code&gt; for the target language.
&lt;/p&gt;

&lt;p&gt;
Presently the code generator only supports XMI files exported from Enterprise Architect models and can only generate C code.
&lt;/p&gt;

&lt;p&gt;
The following figure shows a fictitious activity diagram with all the elements presently supported from the code generator.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/activity.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The code generator supports several configuration parameters that can be specified in the codegen.cfg file. The parameters are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ActivityFileNamePostfix: By default the c/h file with the activity are based on the name specified by -o and the activity name in the model file. But for specific reasons it might be necessary to provide an additional postfix to the file names.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ActivityFunctionParameterDefinition: Allows to define the parameters for the activity function in the c file&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ActivityFunctionPrefixHeader: Same as above but for the header file&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ActivityFunctionPrefixCFile: Allows to define the type of the return value if the activity returns something&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; ActivityFunctionReturnCode: Defines the code snipped that is used at the end of the activity to actually return something.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
To generate code from the above example diagram call the code generator the following way:
&lt;/p&gt;

&lt;p&gt;
&lt;code&gt;java -jar codegen.jar -A -p EA -o testcase -t “Model:test:class_with_activities”  testcase.xml&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
The generated c-file can be found &lt;a href=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/testcase_test_operation.c&quot; class=&quot;media mediafile mf_c&quot; title=&quot;wiki:news:testcase_test_operation.c (3.4 KB)&quot;&gt;here&lt;/a&gt;. Due the way the algorithm is generated (based on a while loop with switch / case statements) all kinds of loops including back links can be generated without problem. For the shown diagram the generated code contains just 180 lines of code including empty lines and some documentation.
&lt;/p&gt;

&lt;p&gt;
⇒The activity generator backend is still under development. Error handling and parser robustness must be increased. Additionally sections about the activity generator must be added to the manual.
&lt;/p&gt;

&lt;p&gt;
Nevertheless the generator can already be used for real word applications. Please give it a try! Your feedback is very welcome.
&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;
Beside the activity generator backend the new version also contains several improvements in the state machine generator. In addition support for transitions from initial states to choice states in Java was added.
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 13 May 2014 16:45:11 +0000</pubDate>
        </item>
        <item>
            <title>How to generate Lua Code from State Diagrams</title>
            <link>https://sinelabore.com/doku.php/wiki/news/14feb2020</link>
            <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;how_to_generate_lua_code_from_state_diagrams&quot;&gt;How to generate Lua Code from State Diagrams&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Lua is a powerful, efficient, lightweight, embeddable scripting language (&lt;a href=&quot;http://www.lua.org/&quot; class=&quot;urlextern&quot; title=&quot;http://www.lua.org/&quot; rel=&quot;ugc nofollow&quot;&gt;http://www.lua.org/&lt;/a&gt;).
To generate Lua code call the code generator with the command
line flag &lt;code&gt;-l lua&lt;/code&gt; .
&lt;/p&gt;

&lt;p&gt;
The generator generates one Lua module which implements the complete state machine. Take this simple state machine as example.
&lt;/p&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/testcase_lua.jpg?id=wiki%3Anews%3A14feb2020&quot; class=&quot;media&quot; title=&quot;wiki:news:testcase_lua.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/testcase_lua.jpg?w=400&amp;amp;tok=9e9c14&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot; Image of an example statemachine to generate LUA code &quot; alt=&quot; Image of an example statemachine to generate LUA code &quot; width=&quot;400&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
For a simple state machine with 4 states and 2 events the generated module looks like this:
&lt;/p&gt;
&lt;pre class=&quot;code Lua&quot;&gt;&lt;span class=&quot;kw1&quot;&gt;function&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;new&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; new_inst &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        &lt;span class=&quot;kw3&quot;&gt;setmetatable&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt; new_inst&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; testcase&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
        &lt;span class=&quot;co1&quot;&gt;-- machine states&lt;/span&gt;
        new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;states &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                S1&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;S1&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                S11&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;S11&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                S12&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;S12&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                S3&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;S3&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                __UNKNOWN_STATE__&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;__UNKNOWN_STATE__&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span class=&quot;co1&quot;&gt;-- machine events&lt;/span&gt;
        new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;events &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                evB&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;evB&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                evA&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;evA&amp;quot;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
                TESTCASE_NO_MSG&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;st0&quot;&gt;&amp;quot;TESTCASE_NO_MSG&amp;quot;&lt;/span&gt;
        &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        &lt;span class=&quot;co1&quot;&gt;-- Set state vars to default states&lt;/span&gt;
        new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;stateVar &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;states&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;S1
        new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;stateVarS1 &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;states&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;S11 &lt;span class=&quot;co1&quot;&gt;-- set init state of S1 &lt;/span&gt;
&amp;nbsp;
        new_inst&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;init&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;
        &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; new_inst
&lt;span class=&quot;kw1&quot;&gt;end&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;function&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;processEvent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Event&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&lt;span class=&quot;sy0&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; evConsumed&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;kw1&quot;&gt;end&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; testcase&lt;/pre&gt;

&lt;p&gt;
The statemachine can be used as follows:
&lt;/p&gt;
&lt;pre class=&quot;code lua&quot;&gt;testcase &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kw3&quot;&gt;require&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;testcase&amp;quot;&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw1&quot;&gt;local&lt;/span&gt; testcase1 &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; testcase&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;new&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
Event &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;event &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; testcase1&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;events&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;TESTCASE_NO_MSG&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt; condition&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;kw4&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
testcase1&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;processEvent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Event&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;
&amp;nbsp;
Event&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;event&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;testcase1&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;events&lt;span class=&quot;sy0&quot;&gt;.&lt;/span&gt;evA&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
testcase1&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;processEvent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Event&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
The following state machine features are supported:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; States and sub-states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Deep – and flat hierarchy&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Entry, Exit and Action code of states&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Regions are supported and implemented as sub-functions called from the main state machine handler&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Choice pseudo-states&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The complete example is available in the &lt;code&gt;examples/microwave_handbook_lua&lt;/code&gt; folder.
&lt;/p&gt;

&lt;p&gt;
Any feedback is highly welcome!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;How to generate Lua Code from State Diagrams&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;how_to_generate_lua_code_from_state_diagrams&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;14-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Fri, 03 May 2024 20:42:23 +0000</pubDate>
        </item>
        <item>
            <title>Need to design on a Unix like OS?</title>
            <link>https://sinelabore.com/doku.php/wiki/news/14sep2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;need_to_design_on_a_unix_like_os&quot;&gt;Need to design on a Unix like OS?&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
Due to the fact that the code generator is written in Java it runs on basically all operating systems. The only requirement is to have a fairly recent Java version installed. But what if you want to design on a Unix system?
&lt;/p&gt;

&lt;p&gt;
Most &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; modelling tools don&amp;#039;t run on Unix systems. What can you do?
&lt;/p&gt;

&lt;p&gt;
Simply use the built in state machine editor. The only additional prerequisite is to install graphviz (for auto-layout) which is available also for many Unix like systems.
&lt;/p&gt;

&lt;p&gt;
Below the state diagram editor runs on my FreeBSD server showing the &lt;abbr title=&quot;Graphical User Interface&quot;&gt;GUI&lt;/abbr&gt; on my Mac box.
&lt;/p&gt;

&lt;p&gt;
Enjoy your flexibility &lt;img src=&quot;https://sinelabore.com/lib/images/smileys/smile.svg&quot; class=&quot;icon smiley&quot; alt=&quot;:-)&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Peter
&lt;/p&gt;
&lt;pre class=&quot;code zsh&quot;&gt;freebsd-version -u
10.0-RELEASE-p8
export DISPLAY=192.168.6.25:0.0
java -jar codegen.jar -p ssc -E -o test.xml test.xml&lt;/pre&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/onbsd.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 14 Sep 2014 09:56:44 +0000</pubDate>
        </item>
        <item>
            <title>Astah SysML</title>
            <link>https://sinelabore.com/doku.php/wiki/news/16april2016</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;astah_sysml&quot;&gt;Astah SysML&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In the latest version of the Sinelabore&lt;em&gt;RT&lt;/em&gt; code generator the SysML Modeling tool Astah SysML is supported. The following screenshots show how the modeling tool looks like.
&lt;/p&gt;

&lt;p&gt;
Instead using classes in class diagrams SysML uses blocks and block definition diagrams.
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/block_definition_diagram.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;Defining includes of the generated code&quot; alt=&quot;Defining includes of the generated code&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
This example is the the model of a microwave oven as used in the manual and examples folder.
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/astah_sysml_machine.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;Astah SysML microwave oven model&quot; alt=&quot;Astah SysML microwave oven model&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Also activity diagrams are possible and the generator can generate 100% code from these diagrams.
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/astah_sysml_selftest.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot;activity diagram of the statemachine&quot; alt=&quot;activity diagram of the statemachine&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
For a quick start download the latest release version and load the Astah SysML microwave oven from the examples folder.
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 23 Feb 2020 18:22:56 +0000</pubDate>
        </item>
        <item>
            <title>Generating C# code</title>
            <link>https://sinelabore.com/doku.php/wiki/news/16aug2013</link>
            <description>


&lt;h1 class=&quot;sectionedit1&quot; id=&quot;generating_c_code&quot;&gt;Generating C# code&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
To generate C# code call the code generator with the new command line flag &lt;code&gt;-l csharp&lt;/code&gt;. All states are created into one source file. The file name is determined by the &lt;code&gt;-o&lt;/code&gt; command line switch.
&lt;/p&gt;

&lt;p&gt;
The generated code does not follow the state pattern as you might expect (if you are fa- miliar with common design patterns). The reason is that the machine code is completely generated and no hand-coding is involved. So the number of classes and files in your project is reduced to a minimum. The following figure shows the structure of the generated code. The classes marked with &lt;code&gt;&amp;lt;generated&amp;gt;&lt;/code&gt; are generated from the code generator. Classes marked with &lt;code&gt;&amp;lt;optional&amp;gt;&lt;/code&gt; are optional and must be provided by yourself if needed.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/csharpgen.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
Figure: Structure of the generated C# code.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Generating C# code&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;generating_c_code&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;14-862&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;microwave_oven_example_in_c&quot;&gt;Microwave Oven Example in C#&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
A microwave oven is taken from the examples folder of the code generator to demonstrate the generator features. The example realizes a simple microwave oven and can be compiled with Microsoft Visual Studio&lt;sup&gt;&lt;a href=&quot;#fn__1&quot; id=&quot;fnt__1&quot; class=&quot;fn_top&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; on Windows&lt;sup&gt;&lt;a href=&quot;#fn__2&quot; id=&quot;fnt__2&quot; class=&quot;fn_top&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt;. The next figure shows the state diagram of the oven. It was created with the Cadifra &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; editor. 
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_csharp_cadifra.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
A simple hardware abstraction layer provides helper functions like a timer etc. You can see how it is called from the state machine (e.g. in an entry action) as &lt;code&gt;hal.ovenOff()&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
You have the option to either generate an own state class per state or inline all the entry/do/exit action code directly into the generated state machine code. As there is no need for separate state classes (e.g. complex and long actions) they were inlined in this example. The generation process can be controlled with a simple configuration file as shown below. You can also see that we provide an own base class for the Oven class to implement some special functions directly usable from the state machine.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;Namespace=OvenMachineNS
BaseClassMachine=OvenBase
BaseClassStates=StateBase
SeparateStateClasses=NO&lt;/pre&gt;

&lt;p&gt;
To generate code from the diagram call the generator as follows:
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;java&lt;/span&gt; -Djava.ext.dirs=..&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;bin&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-jar&lt;/span&gt;  &lt;span class=&quot;st0&quot;&gt;&amp;quot;../bin/codegen.jar&amp;quot;&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-p&lt;/span&gt; CADIFRA &lt;span class=&quot;re5&quot;&gt;-l&lt;/span&gt; csharp &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; Oven oven.cdd&lt;/pre&gt;

&lt;p&gt;
The generated code looks as follows:
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;namespace OvenMachineNS
&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
  public class Oven &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; OvenBase
  &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
    public &lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; States &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      Super&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      Completed&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      CookingPause&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      Idle&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      Cooking&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      __UNKNOWN_STATE__
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    public &lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; Events &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
      evDoorOpen&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evDec&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evTimeout&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evDoorClosed&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evInc&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evPwrLow&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      evPwrHigh&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;
      OVEN_NO_MSG
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
  ...
&amp;nbsp;
&amp;nbsp;
    &lt;span class=&quot;me1&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; ProcessEvent&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;Events msg&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
      &lt;span class=&quot;kw4&quot;&gt;int&lt;/span&gt; evConsumed &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
      &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;m_initialized&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;kw2&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
      &lt;span class=&quot;coMULTI&quot;&gt;/* action code */&lt;/span&gt;
      &lt;span class=&quot;coMULTI&quot;&gt;/* just a comment */&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
        &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;stateVar&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
          &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; States.&lt;span class=&quot;me1&quot;&gt;Super&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
&amp;nbsp;
            &lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;stateVarSuper&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
              &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; States.&lt;span class=&quot;me1&quot;&gt;Idle&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
                &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;msg&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;Events.&lt;span class=&quot;me1&quot;&gt;evDoorClosed&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                  &lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;hal.&lt;span class=&quot;me1&quot;&gt;timer_preset&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span class=&quot;coMULTI&quot;&gt;/* Transition from Idle to Cooking */&lt;/span&gt;
                    evConsumed&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
                    &lt;span class=&quot;coMULTI&quot;&gt;/* Action code for transition  */&lt;/span&gt;
                    hal.&lt;span class=&quot;me1&quot;&gt;timer_start&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
                    &lt;span class=&quot;coMULTI&quot;&gt;/* OnEntry code of state Cooking */&lt;/span&gt;
                    hal.&lt;span class=&quot;me1&quot;&gt;ovenOn&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
                    &lt;span class=&quot;coMULTI&quot;&gt;/* adjust state variables  */&lt;/span&gt;
                    stateVarSuper &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; States.&lt;span class=&quot;me1&quot;&gt;Cooking&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
                  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                    &lt;span class=&quot;coMULTI&quot;&gt;/* Intentionally left blank */&lt;/span&gt;
                  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/*end of event selection */&lt;/span&gt;
                &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
                  &lt;span class=&quot;coMULTI&quot;&gt;/* Intentionally left blank */&lt;/span&gt;
                &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/*end of event selection */&lt;/span&gt;
              &lt;span class=&quot;kw2&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/* end of case Idle  */&lt;/span&gt;
&amp;nbsp;
              &lt;span class=&quot;kw1&quot;&gt;case&lt;/span&gt; States.&lt;span class=&quot;me1&quot;&gt;Cooking&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
&amp;nbsp;
  ...
&amp;nbsp;
&amp;nbsp;
&amp;nbsp;
          &lt;span class=&quot;kw2&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/* end of case Super  */&lt;/span&gt;
&amp;nbsp;
          &lt;span class=&quot;kw1&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;
            &lt;span class=&quot;coMULTI&quot;&gt;/* Intentionally left blank */&lt;/span&gt;
          &lt;span class=&quot;kw2&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;coMULTI&quot;&gt;/* end switch stateVar_root */&lt;/span&gt;
    &lt;span class=&quot;kw1&quot;&gt;return&lt;/span&gt; evConsumed&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
  &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// end of namespace&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Finally start the generated exe file and play with the microwave oven. First increment the cooking time. Then start cooking by closing the door. 
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_windows_capture.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The sinelabore code generator provides much more features than just code generations. Before generation an extensive check is performed to ensure your diagram is correct (e.g. each transition has an associated event, all state names are unique …). You can add trace code if needed, simulate the state machine, generate test cases and more.
&lt;/p&gt;

&lt;p&gt;
If you want to try out the example yourself download the code generator demo. The oven can be found in the examples folder.
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Microwave Oven Example in C#&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;microwave_oven_example_in_c&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;863-&amp;quot;} --&gt;&lt;div class=&quot;footnotes&quot;&gt;
&lt;div class=&quot;fn&quot;&gt;&lt;sup&gt;&lt;a href=&quot;#fnt__1&quot; id=&quot;fn__1&quot; class=&quot;fn_bot&quot;&gt;1)&lt;/a&gt;&lt;/sup&gt; 
, &lt;sup&gt;&lt;a href=&quot;#fnt__2&quot; id=&quot;fn__2&quot; class=&quot;fn_bot&quot;&gt;2)&lt;/a&gt;&lt;/sup&gt; 
&lt;div class=&quot;content&quot;&gt;Copyright Microsoft Cooperation&lt;/div&gt;&lt;/div&gt;
&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Fri, 03 May 2024 20:42:13 +0000</pubDate>
        </item>
        <item>
            <title>New versions 2.9</title>
            <link>https://sinelabore.com/doku.php/wiki/news/17sep2012</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_versions_29&quot;&gt;New versions 2.9&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;New versions 2.9&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;new_versions_29&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-33&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;editorsimulator_improvements&quot;&gt;Editor / Simulator Improvements&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; A new editor component is used in the built–in state machine editor / simulator. The new editor supports folding, line numbers, syntax highlighting, correct copy/cut/paste short-cuts for the different operating systems and other nice features. Thanks to Robert Futrell for his very nice component (see section copyright in the manual for more info). The figure below gives an impression how the editor now looks like.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/17sep2012_img1.jpg?id=wiki%3Anews%3A17sep2012&quot; class=&quot;media&quot; title=&quot;wiki:17sep2012_img1.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/17sep2012_img1.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot; &quot; alt=&quot; &quot; /&gt;&lt;/a&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Issue fixed when simulating state machines with a history state &lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Visual representation of innerEvents in the built–in editor improved. Inner events are now clearly represented in the graphics as well as in the tree view&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/17sep2012_img2.jpg?id=wiki%3Anews%3A17sep2012&quot; class=&quot;media&quot; title=&quot;wiki:17sep2012_img2.jpg&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/17sep2012_img2.jpg&quot; class=&quot;media&quot; loading=&quot;lazy&quot; title=&quot; &quot; alt=&quot; &quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Editor \/ Simulator Improvements&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;editorsimulator_improvements&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;34-800&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;other_improvements&quot;&gt;Other improvements&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The &lt;em&gt;isIn()&lt;/em&gt; methods returns a bool now instead an int in C++&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;em&gt;getInnermostActiveState()&lt;/em&gt; is now a public method in Java&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/images/smileys/exclaim.svg&quot; class=&quot;icon smiley&quot; alt=&quot;:!:&quot; /&gt; This version of the code-generator uses 
the new rsyntaxtextarea.jar package. Copy this 
jar file like the other jar files in the bin 
folder to the correct place on your PC. If you 
don&amp;#039;t know what this means please read section 
&amp;#039;Installation&amp;#039; in the manual.
&lt;/p&gt;

&lt;p&gt;
This new version is free for users who bought their license within the last two years.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Other improvements&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;other_improvements&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;801-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Mon, 22 Oct 2012 19:06:08 +0000</pubDate>
        </item>
        <item>
            <title>Using Activities -- Updated Microwave Oven</title>
            <link>https://sinelabore.com/doku.php/wiki/news/18may2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;using_activities_--_updated_microwave_oven&quot;&gt;Using Activities -- Updated Microwave Oven&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In the manual a simplified microwave oven is used to explain the generation of source code from state machine diagrams. This example was updated here to show how to generate code also from activity diagrams.
&lt;/p&gt;

&lt;p&gt;
The extended state machine of the oven is shown below. For demonstration on how to use activities the oven performs a hardware selftest at startup. The hardware test happens on the incoming transition of the choice. Depending on the result of the selftest the machine enters an error state (marked in red) or the normal operation state (super).
The hardware selftest routine was modelled as activity diagram.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_sm.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
The following code snipped shows the call of the hardware selftest. The selftest function itself was fully generated from the code generator
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;...
&lt;span class=&quot;kw4&quot;&gt;uint8_t&lt;/span&gt; hwStatus&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;co1&quot;&gt;// selftest status&lt;/span&gt;
&amp;nbsp;
&lt;span class=&quot;kw4&quot;&gt;void&lt;/span&gt;  oven&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;OVEN_INSTANCEDATA_T &lt;span class=&quot;sy0&quot;&gt;*&lt;/span&gt;instanceVar&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
	OVEN_EV_CONSUMED_FLAG_T evConsumed &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; 0U&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
	&lt;span class=&quot;coMULTI&quot;&gt;/*execute entry code of default state once to init machine */&lt;/span&gt;
	&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;instanceVar&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;superEntry&lt;span class=&quot;sy0&quot;&gt;==&lt;/span&gt;1U&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
		hwStatus &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; hardwareTest&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;kw1&quot;&gt;if&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;hwStatus&lt;span class=&quot;sy0&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
			instanceVar&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;stateVar &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Error&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;&lt;span class=&quot;kw1&quot;&gt;else&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
			instanceVar&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;stateVar &lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt; Super&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
		&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
		instanceVar&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;superEntry&lt;span class=&quot;sy0&quot;&gt;=&lt;/span&gt;0U&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
	&lt;span class=&quot;kw1&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;instanceVar&lt;span class=&quot;sy0&quot;&gt;-&amp;gt;&lt;/span&gt;stateVar&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
...&lt;/pre&gt;

&lt;p&gt;
The hardware selftest function was modelled in an own activity diagram. A class can have one or more activity diagrams. The code generator generates an own c-file/header per activity. The activity of the hardware test function is shown below. The single steps do not really do anything useful and only the most basic features of an activity diagram are used. But it shows the principles and how well both generators complement each other.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_activity.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
To generate code from the diagram call the code generator as follows. The &lt;code&gt;-A&lt;/code&gt; enables the generation of code from activity diagrams. Without this flag state machine code is generated. To generate both call the generator twice.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;java -jar codegen.jar -p EA -A -t &amp;quot;Model:Class Model:first_example_step3&amp;quot; -o oven  first_example_step3.xml&lt;/pre&gt;

&lt;p&gt;
The latest download contains the full model and code in the examples folder. The example is called &lt;code&gt;microwave_handbook_enterpr_arch&lt;/code&gt;
&lt;/p&gt;

&lt;p&gt;
In case of questions just send a mail.
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Using Activities -- Updated Microwave Oven&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;using_activities_--_updated_microwave_oven&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;2-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 18 May 2014 16:41:11 +0000</pubDate>
        </item>
        <item>
            <title>New version 3.6.5</title>
            <link>https://sinelabore.com/doku.php/wiki/news/20july2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;new_version_365&quot;&gt;New version 3.6.5&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
This new version provides two important optimisations which results in better readability of the generated code and the activity diagram itself.
&lt;/p&gt;

&lt;p&gt;
a) Actions in an activity diagram can contain spaces e.g. “check hardware” is translated into “CHECK_HARDWARE”. This increases the readability of the activity diagram.
&lt;/p&gt;

&lt;p&gt;
b) Combining multiple actions into one action. If successive actions only have one incoming edge they can be combined into one actions. This increases performance and readability of the generated code.
&lt;/p&gt;

&lt;p&gt;
The following activity diagram shows some examples where actions can be combined. This is the &lt;code&gt;unnamed action&lt;/code&gt; and &lt;code&gt;Action10&lt;/code&gt; in the sub-activity Activity1. As well as &lt;code&gt;Action2&lt;/code&gt; with &lt;code&gt;Action 3 with spaces&lt;/code&gt; and &lt;code&gt;Action5&lt;/code&gt; to &lt;code&gt;Action9&lt;/code&gt;. The generated code for the latter looks as follows. The new action has a generated name but the comment clearly indicates which actions were the basis for the new action.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;/* Merged from nodes:   Action5 Action8 Action9 */
case TEST_OPERATION_326F4FB4_71A5_42F3_94F5_BF4E5D5BA1EE:
   printf(&amp;quot;action 5\n&amp;quot;);
   printf(&amp;quot;Effekt Action 8\n&amp;quot;);
   printf(&amp;quot;Action 9\n&amp;quot;);
   id=TEST_OPERATION_ACTIVITYFINAL;
   break;&lt;/pre&gt;

&lt;p&gt;
&lt;a href=&quot;https://sinelabore.com/lib/exe/detail.php/wiki/news/combined_activities.png?id=wiki%3Anews%3A20july2014&quot; class=&quot;media&quot; title=&quot;wiki:news:combined_activities.png&quot;&gt;&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/combined_activities.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
Feedback is as always welcome!
Have fun!
&lt;/p&gt;

&lt;p&gt;
Peter Mueller
&lt;/p&gt;

&lt;p&gt;
~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 18 Apr 2021 11:42:16 +0000</pubDate>
        </item>
        <item>
            <title>Vending Machine example on GitHub</title>
            <link>https://sinelabore.com/doku.php/wiki/news/22may2016</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;vending_machine_example_on_github&quot;&gt;Vending Machine example on GitHub&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Vending Machine example on GitHub&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;vending_machine_example_on_github&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-49&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
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: &lt;a href=&quot;https://github.com/sinelabore/examples&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/sinelabore/examples&quot; rel=&quot;ugc nofollow&quot;&gt;https://github.com/sinelabore/examples&lt;/a&gt;
&lt;/p&gt;

&lt;p&gt;
The envisioned machine is shown below.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/vending.png?w=300&amp;amp;tok=190958&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; width=&quot;300&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
To compile the example just call make. It is assumed that you have installed the code generator from sinelabore and the Astah* Community &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; tool (locations see Makefile).
&lt;/p&gt;

&lt;p&gt;
After startup you can select a product “A”, “B” or “C” by pressing one of theses buttons on your keyboard.
&lt;/p&gt;

&lt;p&gt;
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.
&lt;/p&gt;

&lt;p&gt;
After you paid the product will be released and you receive back your change.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Overview&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;overview&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;50-890&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
Most of the code is automatically generated from the &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; 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.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Implementation&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;implementation&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;891-1335&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;product_store_state_machine&quot;&gt;Product Store State Machine&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
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.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Product Store State Machine&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;product_store_state_machine&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1336-1527&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit5&quot; id=&quot;vending_machine&quot;&gt;Vending Machine&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
This is the controller machine keeping things together.
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Vending Machine&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;vending_machine&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:5,&amp;quot;range&amp;quot;:&amp;quot;1528-1612&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit6&quot; id=&quot;change_algorithm&quot;&gt;Change Algorithm&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
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.
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Change Algorithm&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;change_algorithm&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:6,&amp;quot;range&amp;quot;:&amp;quot;1613-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 25 Sep 2022 08:57:54 +0000</pubDate>
        </item>
        <item>
            <title>Activity diagram generation from UModel</title>
            <link>https://sinelabore.com/doku.php/wiki/news/24may2014</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;activity_diagram_generation_from_umodel&quot;&gt;Activity diagram generation from UModel&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
With this new version 3.6.2 it is now possible to generate code from activity diagrams created with UModel. UModel has support for the basic activity elements such as actions, init - and final nodes.
&lt;/p&gt;

&lt;p&gt;
The microwave oven model &lt;code&gt;microwave_handbook_umodel&lt;/code&gt; was extended to show how to use activity diagrams together with state machines in UModel. The example uses a selftest function called at initialisation of the state machine. If the selftest fails the machine enters an error state. The following figures show the extended oven model and a very simple selftest activity diagram.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_umodel_state_diagrm.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/selftest_activity_umodel.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
Download the latest version and give it a try. Activity modelling is a very useful extension to state machine modelling!
&lt;/p&gt;

&lt;p&gt;
Have fun!
&lt;/p&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Tue, 03 Jun 2014 20:17:30 +0000</pubDate>
        </item>
        <item>
            <title>Screenshots of the Simulator using Regions</title>
            <link>https://sinelabore.com/doku.php/wiki/news/26feb2013</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;screenshots_of_the_simulator_using_regions&quot;&gt;Screenshots of the Simulator using Regions&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
The following screenshots show the simulator simulating the microwave oven example as available in the examples folder. States marked in red are active at the moment. Transitions marked in blue can be triggered from the active states. The output window shows the executed code (i.e. the entry/do/exit code you added to the state diagram). The simulator has to be called as shown below. I assume your shell prompt is located in the &lt;code&gt;microwave_ea9_using_regions_c&lt;/code&gt; folder. Make sure you have &lt;code&gt;Graphviz&lt;/code&gt; installed and in &lt;code&gt;codegen.cfg&lt;/code&gt; configuration file the correct path to the &lt;code&gt;dot.exe&lt;/code&gt; is set (e.g. &lt;code&gt;DotPath=“C:\\Program Files\\Graphviz2.22\\bin\\dot.exe”&lt;/code&gt; for Windows or &lt;code&gt;DotPath=/usr/local/bin/dot&lt;/code&gt; if you are on &lt;abbr title=&quot;Operating System&quot;&gt;OS&lt;/abbr&gt; X)
&lt;/p&gt;
&lt;pre class=&quot;code bash&quot;&gt;&lt;span class=&quot;kw2&quot;&gt;java&lt;/span&gt; -Djava.ext.dirs=..&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;..&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;bin&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-jar&lt;/span&gt; ..&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;..&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;bin&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt;codegen.jar &lt;span class=&quot;re5&quot;&gt;-E&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-p&lt;/span&gt; EA &lt;span class=&quot;re5&quot;&gt;-t&lt;/span&gt; &lt;span class=&quot;st0&quot;&gt;&amp;quot;Model:implementation:oven&amp;quot;&lt;/span&gt; &lt;span class=&quot;re5&quot;&gt;-o&lt;/span&gt; oven  oven.xml&lt;/pre&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;Screenshots of the Simulator using Regions&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;screenshots_of_the_simulator_using_regions&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;1-929&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit2&quot; id=&quot;after_startup_and_reset_of_the_simulation&quot;&gt;After startup and reset of the simulation&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/region_cooking_startup.png&quot; class=&quot;media&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;After startup and reset of the simulation&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;after_startup_and_reset_of_the_simulation&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:2,&amp;quot;range&amp;quot;:&amp;quot;930-1035&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit3&quot; id=&quot;after_some_time_of_cooking_and_then_opening_the_door_pause&quot;&gt;After some time of cooking and then opening the door (pause)&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/region_cooking_pause.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;After some time of cooking and then opening the door (pause)&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;after_some_time_of_cooking_and_then_opening_the_door_pause&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;1036-1159&amp;quot;} --&gt;
&lt;h2 class=&quot;sectionedit4&quot; id=&quot;after_oven_has_counted_down_to_zero_and_waiting_the_cook_to_open_the_door&quot;&gt;After oven has counted down to zero and waiting the cook to open the door.&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/region_cooking_ready.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; alt=&quot;&quot; /&gt;
&lt;/p&gt;
&lt;hr /&gt;

&lt;p&gt;
A demo of the code generator is available for &lt;a href=&quot;https://sinelabore.com/doku.php/wiki/download&quot; class=&quot;wikilink1&quot; title=&quot;wiki:download&quot; data-wiki-id=&quot;wiki:download&quot;&gt;download&lt;/a&gt;.
Give it a try!
&lt;/p&gt;

&lt;/div&gt;
&lt;!-- EDIT{&amp;quot;target&amp;quot;:&amp;quot;section&amp;quot;,&amp;quot;name&amp;quot;:&amp;quot;After oven has counted down to zero and waiting the cook to open the door.&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;after_oven_has_counted_down_to_zero_and_waiting_the_cook_to_open_the_door&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:1,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;1160-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Fri, 01 Mar 2013 19:13:24 +0000</pubDate>
        </item>
        <item>
            <title>Generate code from state machines with regions</title>
            <link>https://sinelabore.com/doku.php/wiki/news/27okt2012</link>
            <description>
&lt;h1 class=&quot;sectionedit1&quot; id=&quot;generate_code_from_state_machines_with_regions&quot;&gt;Generate code from state machines with regions&lt;/h1&gt;
&lt;div class=&quot;level1&quot;&gt;

&lt;p&gt;
In state diagrams usually only one state is active at a time. In &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; state diagrams regions also allow to model concurrency - i.e. more than one state is active at a time (AND states).  
&lt;/p&gt;

&lt;p&gt;
The latest beta now supports the modeling of parallel regions with the following constraints:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Transitions must not cross region boarders. Why this is important is discussed further down&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; No regions in regions&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; No support for fork &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Join can be realized with transitions using guards like &lt;code&gt;isInS221 &amp;amp;&amp;amp; isInS222&lt;/code&gt; as an example&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; UModel and EnterpriseArchitect as modeling tools &lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Only C/C&lt;a class=&quot;folder&quot; href=&quot;#folded_cdff5c7d1ac21efb31471c1b979046d0_1&quot;&gt;code generation. No simulation etc.

The remainder of this article explains how to use regions based on the microwave oven example also used in the manual. It also discusses why it can be tricky to use regions.

==== Notation ====

A UML state may be divided into regions. Each region contains sub-states. Regions are executed in parallel. You can think of regions as independent state machines displayed in one diagram. The state machine below (Fig. 1) shows several regions each running in parallel in the state &amp;#039;&amp;#039;Active&amp;#039;&amp;#039;. Dashed lines are used to divide a state into regions. 

==== Using multiple regions ====

Consider a microwave oven. The power setting, light and microwave radiator are be considered as independent (concurrent) parts of the oven, each with its own states. The door and timer as the main external trigger are used in the regions to trigger state transitions. For example the radiator is switched on if the door gets closed and the timer is &amp;gt; zero. 

As you can see multiple concurrent regions can be used to explicitly visualize different parts of a device. And all the states in the one diagram.

The model and the generated code thereof is provided in the examples folder of the latest beta. 


{{ :wiki:news:oven_with_regions_umodel.png?nolink &lt;/a&gt;&lt;span class=&quot;folded hidden&quot; id=&quot;folded_cdff5c7d1ac21efb31471c1b979046d0_1&quot;&gt; Oven model with regions}}
Figure 1a: State machine model of a microwave oven using regions (created with UModel).

&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_with_regions_ea.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Oven model with regions&quot; alt=&quot; Oven model with regions&quot; /&gt;
Figure 1b: State machine model of a microwave oven using regions (created with EA).

==== Alternative design without using regions ====

The microwave oven can also be modelled in a different way as shown below (the example is taken from the manual and code is available in the examples folder of the Sinelabore&lt;em&gt;RT&lt;/em&gt; download). This model was created from an outside perspective not showing the state of different parts explicitly. It might be easier to follow the state flow during debugging and simulation because there is no parallelism. On the other hand the status of some 
 parts of the oven are not a visible as in the model with regions.

&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/oven_without_regions.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Oven model without regions&quot; alt=&quot; Oven model without regions&quot; /&gt;
Figure 2: Oven model not using regions.


==== How regions are implemented ====

The following brief descriptions explains how regions are implemented.

  * For each region an own function is generated. Its name is automatically derived from the region name.
  * If a state contains several regions they are called one after the other (in alphabetical order). If the event sent to the state machine was processed in one of the regions no further event handling happens. Otherwise the event is processed in the parent state. This is similar to the event handling of normal hierarchical state machines.
  * To maintain consistency during execution of machine code a copy of the instance data is created at the beginning of the state machine code. All tests are performed on the original instance data. All changes are done on the copy. This ensures that all regions “see” the same situation when running. At the end of the machine code the modified instance data is copied back to the original data.  &lt;del&gt;Note: this is not yet available in the C&lt;a class=&quot;folder&quot; href=&quot;#folded_cdff5c7d1ac21efb31471c1b979046d0_2&quot;&gt;backend.&amp;lt;/del&amp;gt;



Here is the simplified C-code example of the oven state machine. 

&amp;lt;code c&amp;gt;
void  oven(OVEN_INSTANCEDATA_T *instanceVar){

  OVEN_EV_CONSUMED_FLAG_T evConsumed = 0U;
  OVEN_INSTANCEDATA_T instanceVarCopy = *instanceVar;
  
  switch (instanceVar-&amp;gt;stateVar) {

    case Active:
      /* calling region code */
      evConsumed &lt;/a&gt;&lt;span class=&quot;folded hidden&quot; id=&quot;folded_cdff5c7d1ac21efb31471c1b979046d0_2&quot;&gt;= ovenActiveLight(instanceVar, &amp;amp;instanceVarCopy, msg);&lt;pre class=&quot;code&quot;&gt;    evConsumed |= ovenActivePower(instanceVar, &amp;amp;instanceVarCopy, msg);
    evConsumed |= ovenActiveRadioator(instanceVar, &amp;amp;instanceVarCopy, msg);&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt;    /* Check if event was already processed  */
    if(evConsumed==0U){
      .... /* handle event on parent level */
	&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt;  break;
 } /* end switch stateVar_root */&lt;/pre&gt;
&lt;pre class=&quot;code&quot;&gt; /* Save the modified instance data */
 *instanceVar = instanceVarCopy;&lt;/pre&gt;

&lt;p&gt;
}

OVEN_EV_CONSUMED_FLAG_T ovenActiveLight(OVEN_INSTANCEDATA_T *instanceVar, OVEN_INSTANCEDATA_T *instanceVarCopy, OVEN_EVENT_T msg){
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;...&lt;/pre&gt;

&lt;p&gt;
}

OVEN_EV_CONSUMED_FLAG_T ovenActivePower(OVEN_INSTANCEDATA_T *instanceVar, OVEN_INSTANCEDATA_T *instanceVarCopy, OVEN_EVENT_T msg){
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;...&lt;/pre&gt;

&lt;p&gt;
}

OVEN_EV_CONSUMED_FLAG_T ovenActiveRadioator(OVEN_INSTANCEDATA_T *instanceVar, OVEN_INSTANCEDATA_T *instanceVarCopy, OVEN_EVENT_T msg){
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;...&lt;/pre&gt;

&lt;p&gt;
}

&amp;lt;/code&amp;gt;


And the same example for C&lt;/span&gt;:

&amp;lt;code c++&amp;gt;
&lt;em&gt; State machine event handler
int oven::processEvent(OVEN_EVENT_T msg){

  int evConsumed = 0;
  
  OVEN_INSTANCEDATA_T instanceVarCopy = *instanceVar;

  if(m_initialized==false) return 0;

  switch (stateVar) {

    case Active:
	/* calling region code */
	evConsumed |= ovenActiveLight(msg);
	evConsumed |= ovenActivePower(msg);
	evConsumed |= ovenActiveRadioator(msg);

	/* Check if event was already processed  */
	if(evConsumed==0){
           …. /* handle event on parent level */

  …
  return evConsumed;
}

/* Region code for state Active */

int oven::ovenActiveLight(OVEN_EVENT_T msg){
  …
}

int oven::ovenActivePower(OVEN_EVENT_T msg){
  …
}

int oven::ovenActiveRadioator(OVEN_EVENT_T msg){
  …
}

&amp;lt;/code&amp;gt;


==== Points to consider with regions ====

&lt;strong&gt;Transitions must not cross region boundaries &lt;/strong&gt;

In the first diagram state transitions do not cross region boundaries and therefore the modeller’s intension is quite clear. But look at the next diagram which is a valid diagram too. Now it is not clear anymore what the modeller had in mind. And it is also not very obvious what a code generator would/should generate. For that reason it is necessary that a code generator defines some limits here. 

&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/problems_with_regions.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Problems with regions&quot; alt=&quot; Problems with regions&quot; /&gt;


&lt;strong&gt; Regions must work on the same instance data &lt;/strong&gt;

State diagrams follow the &lt;/em&gt;run-to-completion&lt;em&gt; concept: Transitions that fire are fully executed and the state machine reaches a stable state configuration until it returns and can respond to the next event. To ensure this a copy of the instance data is kept and state changes are only performed on that copy. In practice this means that changes in one region does not influence other regions. Look into the following figure below. 

  * If the event  &lt;code&gt;evClosed&lt;/code&gt; is sent region &lt;code&gt;ValveA&lt;/code&gt; and &lt;code&gt;ValveB&lt;/code&gt; change state. 
  * But there is no state change in region &lt;code&gt;Motor&lt;/code&gt; at the same time. The reason is that the transition from &lt;code&gt;Stop&lt;/code&gt; → &lt;code&gt;Run&lt;/code&gt; was not triggered at the beginning of the machine execution. 
  * This behavior ensures that the result of a machine execution step is 100% predictable and e.g. not dependent of the execution order of the regions.
  * But on the other side it means that a second run of the machine is required to reach state &lt;code&gt;MachineRun&lt;/code&gt;. I.e. the region &lt;code&gt;Motor&lt;/code&gt; is always one cycle behind the &lt;code&gt;Valve&lt;/code&gt; regions.

&lt;img src=&quot;https://sinelabore.com/lib/exe/fetch.php/wiki/news/problems_with_regions_2.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Problems with regions II&quot; alt=&quot; Problems with regions II&quot; /&gt;
==== And the conclusions? ====

Usually there is a way to model a problem with regions and without regions. The solution with regions allows to model a kind of parallelism and allows to explicitly display independent parts of a system.

On the other side exactly this parallelism is responsible that models with regions looks a bit more complex at first view.


&lt;strong&gt;If you have comments and suggestions please let me know!
If you are interested to test this version download the latest beta following this &lt;a href=&quot;https://sinelabore.com/doku.php/wiki/download&quot; class=&quot;wikilink1&quot; title=&quot;wiki:download&quot; data-wiki-id=&quot;wiki:download&quot;&gt;download&lt;/a&gt; link. &lt;/strong&gt;


—-

~~DISCUSSION:closed|Leave your comments~~
&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Wed, 17 Aug 2022 17:47:48 +0000</pubDate>
        </item>
    </channel>
</rss>
