<?xml version="1.0" encoding="UTF-8"?>
<!-- generator="FeedCreator 1.8" -->
<?xml-stylesheet href="https://sinelabore.de/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:landing_pages:sysml</title>
        <description>Productivity for embedded software development</description>
        <link>https://sinelabore.de/</link>
        <lastBuildDate>Sun, 05 Apr 2026 19:56:47 +0000</lastBuildDate>
        <generator>FeedCreator 1.8</generator>
        <image>
            <url>https://sinelabore.de/lib/exe/fetch.php/favicon.ico</url>
            <title>SinelaboreRT</title>
            <link>https://sinelabore.de/</link>
        </image>
        <item>
            <title>Generating CPP Code from SysML V2 textual models</title>
            <link>https://sinelabore.de/doku.php/wiki/landing_pages/sysml/sysml_v2</link>
            <description>


&lt;h2 class=&quot;sectionedit1&quot; id=&quot;generating_cpp_code_from_sysml_v2_textual_models&quot;&gt;Generating CPP Code from SysML V2 textual models&lt;/h2&gt;
&lt;div class=&quot;level2&quot;&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.de/lib/exe/fetch.php/wiki/landing_pages/sysml/sysml2-logo-tight.png&quot; class=&quot;medialeft&quot; align=&quot;left&quot; loading=&quot;lazy&quot; title=&quot;Sysml Logo&quot; alt=&quot;Sysml Logo&quot; /&gt;
SysML V2 is a newer version of SysML that is more flexible and powerful. 
An important aspect is that it now allows to write textual models.
This lowers the entry barrier to the model based system development a lot
becasue no special tools are needed to write the models. E.g. a
Visual Studio Code plugin is available to write SysML V2 models.
The Sinelabore Code Generator supports code generation from SysML V2 models.
In opposite to the current Sinelabore capabilites, the 
code generation also supports the generation of structural code and 
not just the generation of state machine code.
&lt;/p&gt;

&lt;p&gt;
This means that also code for parts, interactions between parts and so
forth is generated. This can be used to quickly generate mockups and
simulations of an intended system.
&lt;/p&gt;

&lt;p&gt;
To generate &lt;code&gt;CPP&lt;/code&gt; code from a sysml model call the code generator with the 
command line flag &lt;code&gt;-l Sysml2Text&lt;/code&gt;.
&lt;/p&gt;

&lt;p&gt;
&lt;img src=&quot;https://sinelabore.de/lib/exe/fetch.php/wiki/landing_pages/sysml/vscode_sysml.png&quot; class=&quot;mediacenter&quot; loading=&quot;lazy&quot; title=&quot; Visual Studio Code with SysML plugin&quot; alt=&quot; Visual Studio Code with SysML plugin&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;
A fully functional example is available on our &lt;a href=&quot;https://github.com/sinelabore/examples/tree/master/SysML_V2_TextualNotation&quot; class=&quot;urlextern&quot; title=&quot;https://github.com/sinelabore/examples/tree/master/SysML_V2_TextualNotation&quot; rel=&quot;ugc nofollow&quot;&gt;github&lt;/a&gt; site.
&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 CPP Code from SysML V2 textual models&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;generating_cpp_code_from_sysml_v2_textual_models&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:0,&amp;quot;secid&amp;quot;:1,&amp;quot;range&amp;quot;:&amp;quot;187-1441&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit2&quot; id=&quot;introduction&quot;&gt;Introduction&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
The present version only supports a small subset of the powerful SysML V2 feature set. 
Over time more features might be added. Main goal of this first version 
of the SysML V2 backend is to support a relevant set of
features to generate code for state machines and the interaction of statemachines between parts.
&lt;/p&gt;

&lt;p&gt;
To execute the generated code a small header only runtime environment is provided.
It contains some base classes and implements inter-part communication via
ports and timeout handling. So just the minimum to execute a model.
&lt;/p&gt;

&lt;p&gt;
In case a part contains a state machine the code generatior also generates additional files
for the state machine. This code follows the structure that is already used by 
the &lt;code&gt;cppx&lt;/code&gt; backend.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;Parts&lt;/strong&gt;: Parts are the main building blocks of a system. They can contain other parts, attributes, a state machine, actions, enums, connections and ports. Parts are realized as CPP classes in the generated code. If a part contains other parts you are responsible to create them in the init method. Create a subclass of the part class and override the init method. Then call the base class init method. Example: &lt;pre class=&quot;code&quot;&gt; part def P1{part p2:P3;} &lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;Attributes&lt;/strong&gt; Parts can have attributes. Attributes can have a base type and a default value. Attributes can contain other attributes. Attributes are translated to CPP member variables. Depending on the type of the attribute it is realized as a basic data type or a class. Example: &lt;pre class=&quot;code&quot;&gt;attribute a:bool;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;Enums&lt;/strong&gt;: Basic enums with their enum values can be defined. Enums are directly translated to CPP enums in the generated code. Example: &lt;pre class=&quot;code&quot;&gt;enum def Color{RED; GREEN; BLUE;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;Ports&lt;/strong&gt;: Ports are the way to communication points between parts. The framework has some helper classes to realize ports. A port marked as “&lt;code&gt;in&lt;/code&gt;” has a &lt;em&gt;receive&lt;/em&gt; method, a port marked as “&lt;code&gt;out&lt;/code&gt;” has a &lt;em&gt;send&lt;/em&gt; method in the generated CPP code. Example: &lt;pre class=&quot;code&quot;&gt;port def p {attribute x : Integer;}&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;Connections&lt;/strong&gt;: Connections are the way to connect ports of  parts in order to share data. Connections are realized as queues in the generated code. Only ports of the same type can be connected. One part must be marked as “&lt;code&gt;in&lt;/code&gt;”, one as “&lt;code&gt;out&lt;/code&gt;”. If you need bidirectional communication you can add two other ports in opposite direction. All attributes in a port share the same direction. Example: &lt;pre class=&quot;code&quot;&gt;connect p1.sendPort to p2.recvPort;} &lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; &lt;strong&gt;State Machines&lt;/strong&gt;: A part can have a state machine. State machines are not as expressive as in &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; so far, but still powerful. With the help of a TimerManager class in the framework, timed transitions can be realized. Exampel:&lt;pre class=&quot;code&quot;&gt;{state def sm { ... }}&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
The following listing shows an example for a small traffic light control system model. It consists of three parts with some attributes and actions. The &lt;code&gt;TrafficManagementCenter&lt;/code&gt; part represents a central control system that can control  &lt;code&gt;TrafficLightController&lt;/code&gt; parts connected via ports.
&lt;/p&gt;

&lt;p&gt;
In this simple model the &lt;code&gt;TrafficManagementCenter&lt;/code&gt; just enables a traffic light controllers to operate by sending a start event. The &lt;code&gt;TrafficLightController&lt;/code&gt; then changes state from &lt;code&gt;OutOfService&lt;/code&gt; to &lt;code&gt;Operational&lt;/code&gt; and performs expected traffic light operations. In a real system this simulation is for sure much more complex. But the example is rich enough to show  the available possibilities. The &lt;code&gt;TrafficLightSystem&lt;/code&gt; part weaves together the &lt;code&gt;TrafficManagementCenter&lt;/code&gt; and the &lt;code&gt;TrafficLightController&lt;/code&gt; parts.
&lt;/p&gt;
&lt;pre class=&quot;code c&quot;&gt;private import ScalarValues&lt;span class=&quot;sy0&quot;&gt;::*;&lt;/span&gt;
&amp;nbsp;
package TrafficLight &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
&amp;nbsp;
    &lt;span class=&quot;co1&quot;&gt;// definition of events to control motor&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; def TRAFFICLIGHTCONTROLLERSM_EVENT_T &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        &lt;span class=&quot;co1&quot;&gt;//@TrafficLightController&lt;/span&gt;
        evOperational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        evError&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    &lt;span class=&quot;co1&quot;&gt;//@TrafficManagementCenter&lt;/span&gt;
    &lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; def TRAFFICMANAGEMENTCENTERSM_EVENT_T &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;
    port def ControlPortData &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        attribute msg &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; TRAFFICLIGHTCONTROLLERSM_EVENT_T&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        attribute test&lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt;Integer&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    part def Test&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;// traffic management center&lt;/span&gt;
    part def TrafficManagementCenter&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        out port sendPort &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; ControlPortData&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        part test1 &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; Test&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        state def tmcStateMachine &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; then PreOperational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
            state PreOperational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
            accept after &lt;span class=&quot;nu0&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; &lt;span class=&quot;kw1&quot;&gt;do&lt;/span&gt; send new ControlPortData&lt;span class=&quot;br0&quot;&gt;&amp;#40;&lt;/span&gt;TRAFFICLIGHTCONTROLLERSM_EVENT_T&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;evOperational&lt;/span&gt;&lt;span class=&quot;sy0&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nu0&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#41;&lt;/span&gt; via sendPort then Operational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
            state Operational &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
            &lt;span class=&quot;br0&quot;&gt;&amp;#125;&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;
&amp;nbsp;
    part def TrafficLightController&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
&amp;nbsp;
        in port recvPort &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; ~ControlPortData&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        part test1 &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; Test&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        action def setRedLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def resetRedLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def setYellowLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def resetYellowLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def setGreenLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def resetGreenLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def setRedAndYellowLED&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        action def resetRedAndYellowLED&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;
        state def tlcStateMachine &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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;// Main system composition&lt;/span&gt;
    part def TrafficLightSystem &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        doc &lt;span class=&quot;coMULTI&quot;&gt;/*
        * Main system that contains the parts
        */&lt;/span&gt;
        part tmc &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; TrafficManagementCenter&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        part tlc &lt;span class=&quot;sy0&quot;&gt;:&lt;/span&gt; TrafficLightController&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        &lt;span class=&quot;co1&quot;&gt;// Connect the parts&lt;/span&gt;
        connect tmc.&lt;span class=&quot;me1&quot;&gt;sendPort&lt;/span&gt; to tlc.&lt;span class=&quot;me1&quot;&gt;recvPort&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;/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;1442-6784&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit3&quot; id=&quot;adding_a_state_machine_to_a_part&quot;&gt;Adding a State Machine to a Part&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
A state machine can be added to a part. The following listing shows an example
of a state machine definition. Presently the following features are supported which 
are demonstrated in the following listing.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; State machine definition: &lt;code&gt;state def sm { … }&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Default state: &lt;code&gt;entry; then statename;&lt;/code&gt;&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Default state setting extended form: This allows to select the default state based on conditions.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; States long form: They can have $entry$, $exit$ and $do$ actions. See state  &lt;code&gt;OperationalRed { entry; … }&lt;/code&gt; as example.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; States short form without details. Just a name must be given.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Transitions short form. This transition can only directly follow a state and allows a short form.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Transitions long form: This transition must have the extended form. An example for this is &lt;code&gt;transition t1&lt;/code&gt; shown in the listing.&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class=&quot;code c&quot;&gt;&lt;span class=&quot;sy0&quot;&gt;/&lt;/span&gt; definition of events
&lt;span class=&quot;kw2&quot;&gt;enum&lt;/span&gt; def TRAFFICLIGHTCONTROLLERSM_EVENT_T &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&quot;co1&quot;&gt;//@TrafficLightController&lt;/span&gt;
    evOperational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    evError&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
state def tlcStateMachine &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
    entry&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; then OutOfService&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
    state  OutOfService &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        entry&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; then OutOfServiceYellowOn&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        state OutOfServiceYellowOn&lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action setYellowLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        accept after &lt;span class=&quot;nu16&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; then OutOfServiceYellowOff&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        state OutOfServiceYellowOff &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action resetYellowLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
        accept after &lt;span class=&quot;nu16&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; then OutOfServiceYellowOn&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        transition t1 first OutOfService 
            accept TRAFFICLIGHTCONTROLLERSM_EVENT_T&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;evOperational&lt;/span&gt; then Operational&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
    state Operational &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
        entry&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt; then OperationalRed&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
&amp;nbsp;
        state OperationalRed &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action setRedLED&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;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt; action resetRedLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        state OperationalRedYellow &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action setRedAndYellowLED&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;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt; action resetRedAndYellowLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        state OperationalGreen &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action setGreenLED&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;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt; action resetGreenLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;
&amp;nbsp;
        state OperationalYellow &lt;span class=&quot;br0&quot;&gt;&amp;#123;&lt;/span&gt;
            entry action setYellowLED&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;a href=&quot;http://www.opengroup.org/onlinepubs/009695399/functions/exit.html&quot;&gt;&lt;span class=&quot;kw3&quot;&gt;exit&lt;/span&gt;&lt;/a&gt; action resetYellowLED&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;br0&quot;&gt;&amp;#125;&lt;/span&gt;				
&amp;nbsp;
        transition t1 first OperationalRed  accept after &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; 
            then OperationalRedYellow&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        transition t2 first OperationalRedYellow  accept after &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; 
            then OperationalGreen&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        transition t3 first OperationalGreen  accept after &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; 
            then OperationalYellow&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        transition t4 first OperationalYellow  accept after &lt;span class=&quot;nu0&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#91;&lt;/span&gt;SI&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;br0&quot;&gt;&amp;#93;&lt;/span&gt; 
            then OperationalRed&lt;span class=&quot;sy0&quot;&gt;;&lt;/span&gt;
        transition t5 first Operational 
            accept TRAFFICLIGHTCONTROLLERSM_EVENT_T&lt;span class=&quot;sy0&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;me2&quot;&gt;evError&lt;/span&gt; then OutOfService&lt;span class=&quot;sy0&quot;&gt;;&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;
The system including the state machines are then fully generated following the well known Sinelabore&lt;em&gt;RT&lt;/em&gt; state machine  structure.
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;defining_events&quot;&gt;Defining Events&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
It is required to use enums to define events to be processed by the state machine.
&lt;/p&gt;

&lt;p&gt;
It is necessary to add a comment in the enum that starts with 
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;//@. --&amp;gt; example see above&lt;/pre&gt;

&lt;p&gt;
 plus the name of the part containing the state machine processing the events. 
&lt;/p&gt;

&lt;/div&gt;

&lt;h4 id=&quot;transition_triggered_by_timeouts&quot;&gt;Transition triggered by Timeouts&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
A great new feature with SysML V2 is the ability to trigger transitions by timeouts.
In &lt;abbr title=&quot;Unified Modeling Language&quot;&gt;UML&lt;/abbr&gt; this was also possible but in much more limited way.
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;transition t1 first start state  accept after 0.1[SI::second] then next state;&lt;/pre&gt;

&lt;p&gt;
At present the time can only be specified in seconds. If other units are needed you can write e.g. &lt;code&gt;0.001[SI::second]&lt;/code&gt; for 1 millisecond. Each part has by default a TimerManager class that is used to manage the timeouts. The code generator generates the needed entry code to start the timer if the state is entered. Also the exit code is generated to stop the timer when the state is left.  A timeout event is added to the event list.
&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;Adding a State Machine to a Part&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;adding_a_state_machine_to_a_part&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:7,&amp;quot;secid&amp;quot;:3,&amp;quot;range&amp;quot;:&amp;quot;6785-10697&amp;quot;} --&gt;
&lt;h3 class=&quot;sectionedit4&quot; id=&quot;basic_executing_a_model&quot;&gt;Basic executing a model&lt;/h3&gt;
&lt;div class=&quot;level3&quot;&gt;

&lt;p&gt;
It is possible to directly execute the model in a CPP main function. But in most cases you you might want to add own CPP behaviour. Then it is necessary to subclass the generated &lt;code&gt;Part&lt;/code&gt; classes and implement the
intended business logic and handlers (i.e. methods of the generated part classes).  By default a &lt;code&gt;process()&lt;/code&gt; and &lt;code&gt;init()&lt;/code&gt; method is generated per part.
&lt;/p&gt;

&lt;p&gt;
If needed overwrite these two methods and add your own code. Then call the baseclass method to ensure
that the part is initialized correctly. Parts used in a part (i.e. sub-parts) must be created
in the init method.
&lt;/p&gt;

&lt;p&gt;
Here is an example for a simple main program:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;MyTrafficLightSystem tls;

tls.init();

// Start process thread
for(int i = 0; i &amp;lt; 80; i++) {
   tls.process();
   std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
&lt;/pre&gt;

&lt;/div&gt;

&lt;h4 id=&quot;executing_model_with_state_machines&quot;&gt;Executing Model with State Machines&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
For each state machine, state handling classes are generated (details see section &amp;#039;3.4. Generating C++ Code&amp;#039; in the manual). Set the following parameters in the config file – &lt;code&gt;codegen.cfg&lt;/code&gt; otherwise the compiler will fail:
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; UseEnumBaseTypes=yes&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; UseStdLibrary = yes&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; CallInitializeInCtor = no&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; EnumBaseTypeForEvents = std::int16_t&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;
A state handling method named like the topmost state def of the part is generated.
&lt;/p&gt;

&lt;p&gt;
For ports and timeouts a handler method is added into the generated part class. Overwrite this handler in your derived class and forward the timeout event or the event received in the port to the state machine. Examples for such handlers are as follows:
&lt;/p&gt;
&lt;pre class=&quot;code&quot;&gt;    void onTimeout(const TLCEvent&amp;amp; e) override{
        std::cout &amp;lt;&amp;lt; &amp;quot;[MyTrafficLightController] Timeout fired with id=&amp;quot;
            &amp;lt;&amp;lt; getNameByEvent(e)&amp;lt;&amp;lt; std::endl;
        // put event to input queue to be able to handle it via sysml code
        recvPort.receive(ControlPortDataDef{e});
        tlcStateMachine();
}&lt;/pre&gt;

&lt;/div&gt;

&lt;h4 id=&quot;missing_features&quot;&gt;Missing Features&lt;/h4&gt;
&lt;div class=&quot;level4&quot;&gt;

&lt;p&gt;
Sysml V2 is a very rich model language. There are many features that are not yet supported by the code generator.  The following list is not exhaustive but list some of the not supported features. Take a look at the code on github to see what is used in the  code generator and therefore supported.
&lt;/p&gt;
&lt;ul&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Regions in state machines&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Inner transitions&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Attributes can&amp;#039;t be qualified by additional keywords like $ordered$ or $unique$&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Attributes can&amp;#039;t have multiplicity&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Referencing, Subsetting, …&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Additions features in enums beside basic definition&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Other inter part communication features than ports and connections as shown above&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; The complete model must reside in a single file. It is not supported to split the model into multiple files.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Sysml imports are ignored and no code is generated for them. But it still useful just to satisfy sysmlv2 editors and get rid of error messages.&lt;/div&gt;
&lt;/li&gt;
&lt;li class=&quot;level1&quot;&gt;&lt;div class=&quot;li&quot;&gt; Many other features not shown in the example code.&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;Basic executing a model&amp;quot;,&amp;quot;hid&amp;quot;:&amp;quot;basic_executing_a_model&amp;quot;,&amp;quot;codeblockOffset&amp;quot;:10,&amp;quot;secid&amp;quot;:4,&amp;quot;range&amp;quot;:&amp;quot;10698-&amp;quot;} --&gt;</description>
            <author>anonymous@undisclosed.example.com (Anonymous)</author>
            <pubDate>Sun, 15 Mar 2026 19:16:03 +0000</pubDate>
        </item>
    </channel>
</rss>
