Tasks

Modeling a statemachine

  1. Make sure the YAKINDU Modeling perspective is active.
  2. Create a new project.
  3. Click File > New > Other... > YAKINDU > YAKINDU Statechart Model.
  4. Click Next name the sct file and click Finish
  5. The YAKINDU statechart editor opens on the statechart model. It already has an initial state and an unnamed simple state connected by a transition.
  6. Now you can add states and transitions from the palette.

To edit the states and transitions you can use the properties view. It has an integrated Xtext support. This makes correct editing easier. You can also change the appearance of the model elements.

On the palette you will also find a composite submachine state. This is a state that contains a complete statemachine. You can choose an existing statemachine or create a new one.

Related topics

Statemachine Elements reference
Textual modeling lanuage Reference

Validating a statemachine

The statemachine is validated automatically during build. The elements that cause problems get error markers. You can find the details about the problems on the problems view.

Simulating a statemachine

The YAKINDU simulation engine supports simulation modes:

The default setting is cycle based with a cycle period of 200 ms. In this mode the simulation engine processes the state machine transitions in steps of the given cycle duration. The following statechart illustrates this. It is simulated cycle based with a cycle period of 3 seconds.

What happend during simulation is the following:

  1. After 3s init switches to pre1
  2. After 3 further seconds recursive transition to pre1 is processed (not after 2s the transition says)
  3. After 3 further seconds recursive transition to pre1 is processed again and the condition becomes true so result gets activated

In contrast to cycle based the event driven simulation mode concentrates on the events of a state machine. The same state machine above could be simulated as follows:

  1. Immediately init switches to pre1
  2. Immediately the event touch is raised twice
  3. The condition becomes true so that the result state is reached after 2 or 3 seconds instead of 9

Start a simulation with the different modes as follows

  1. Make sure the YAKINDU Simulation Perspectiv is opened.
  2. Start the simulation by clicking Run > Run Configurations....
  3. Select the statechart you want to simulate and the simulation mode.
  4. Apply the setting and Run the simulation.

Simulation Concept
Simulation perspective
Simulation View

Generating Code

For configuring the code generation process, YAKINDU Statechart Tools uses a textual generator model called SGen. It can be created either by using the provided wizard Yakindu Statechart Generator Model or by creating a new text file with the file extension ‚.sgen’.
To create a generator model with the wizard,

  1. Click File > New > Other... > Yakindu Statechart Generator Model
  2. Type a name and click Next
  3. Choose the desired generator, i.e. YAKINDU Java Code Generator
  4. Check the model(s) to generate code from and click Finish

The result is an .sgen file of the following format:

GeneratorModel for [GeneratorId] {
	statechart [StatechartReference] {
		feature [Feature] {
			[ParameterName] = [ParameterValue]
		}
	}
}

The [GeneratorId] is the unique id of the Generator. Currently, the following Generators are supported out of the box:

  1. yakindu::java – Generator ID for the Java Code Generator
  2. yakindu::c – Generator ID for the C Code Generator
  3. yakindu::cpp – Generator ID for the C++ Code Generator
  4. yakindu::xpand – Generator ID for custom Xpand based Code Generators
  5. yakindu::generic – Generator ID for custom Java based Code Generators

One GeneratorModel can contain several [StatechartReference]s. These are cross references to statechart models for which the code should be generated. For each reference, the generator process can be configured with [Feature]s. Each Feature consists of several parameters. These parameters can be configured with [ParameterName] = [ParameterValue].

The Generator Model is executed by a builder. Thus, the artifacts are generated automatically if Project > Build Automatically is checked. If you want to execute your Generator Model by hand, select Generate Statechart Artifacts from the Package Explorer’s context menu.

Core Features

The following section describes the Core Features which are available for all code generators:

Outlet

The Outlet feature specifies the target project and folder for the generated artifacts. It is a required feature and consists of the following parameters:

  1. targetProject (String, required): The project to store the generated artifacts
  2. targetFolder (String, required): The folder to store the generated artifacts

Example configuration:

feature Outlet {
	targetProject = "ExampleProject"
	targetFolder = "src-gen"
}


LicenseHeader

The LicenseHeader feature specifies the license text that should be added as a header to the generated artifacts. It is an optional feature and consists of the following parameters:

  1. licenseText (String, required): The license text to add as a header

Example configuration:

feature LicenseHeader {
	licenseText = "Copyright (c) 2012 committers of YAKINDU and others."
}


FunctionInlining

The FunctionInlining feature allows the inlining of expressions instead of generating separate functions or methods. This might reduce the readability of the generated code, but increases performance because less operation calls are necessary.
It is an optinal feature and consists of the following parameters:

  1. inlineReactions (Boolean, optional): Inlines the expression for reactions
  2. inlineEntryActions (Boolean, optional): Inlines the expression for entry actions
  3. inlineExitActions (Boolean, optional): Inlines the expression for exit actions
  4. inlineEnterSequences (Boolean, optional): Inlines the expression for enter sequences
  5. inlineExitSequences (Boolean, optional): Inlines the expression for exit sequences
  6. inlineChoices (Boolean, optional): Inlines the expression for choices
  7. inlineEnterRegion (Boolean, optional): Inlines the expression for enter regions
  8. inlineExitRegion (Boolean, optional): Inlines the expression for exit regions
  9. inlineEntries (Boolean, optional): Inlines the expression for entries

Example configuration:

feature FunctionInlining {
	inlineChoices = false
	inlineEnterRegion = true
	inlineEntries = true
}


Debug

The Debug feature dumps the Execution Model to the target folder as xmi model. It is an optional feature and consists of the following parameters:

  1. dumpSexec (Boolean, required): The license text to add as a header

Example configuration:

feature Debug {
	dumpSexec = true
}

Java Generator Features

Naming

The Naming feature allows the configuration of package names as well as class name prefix / suffix.
It is an optional feature and consists of the following parameters:

  1. basePackage (Boolean, required): The package to create for the generated java classes
  2. implementationSuffix (Boolean, optional): The suffix for the implementing classes

Example configuration:

feature Naming {
	basePackage = "org.yakindu.sct"
	implementationSuffix = "Impl"
}


GeneralFeatures

The GeneralFeatures feature allows to configure additional services to generate with the statemachine. Per default, all parameters are configured to false It is an optional feature and consists of the following parameters:

  1. EventBasedStatemachine (Boolean, optional): Enables/disables the generation of a cycle based statemachine implementation
  2. InterfaceObserverSupport (Boolean, optional): Enables/disables the generation of listener interfaces for the statemachine
  3. RuntimeService (Boolean, optional): Enables/disables the generation of a runtime service that triggers the runcycle of a cycle based statemachine
  4. TimerService (Boolean, optional): Enables/disables the generation of a timer service implementation using java.util.Timer
  5. GenericInterfaceSupport (Boolean, optional): Enables/disables the generation of generic interfaces
  6. StatemachineFactorySupport (Boolean, optional): Enables/disables the generation of a factory class

Example configuration:

feature GeneralFeatures {
	EventBasedStatemachine = true
	InterfaceObserverSupport = true
	RuntimeService = true
	TimerService = true
	GenericInterfaceSupport = true
	StatemachineFactorySupport = true
}

C Generator Features

CCodeFeature

The CCodeFeature feature allows to configure c code specific generator properties. It is an optional feature and consists of the following parameters:

  1. InterfaceEventListener (Boolean, mandatory): generates listener interface for notification of outgoing events.
  2. Singleton (Boolean, mandatory): generates a statically allocated singleton variant of the state machine that does not allow multiple instances.
  3. DebugType (String, optional): don’t use this property – it will be removed

Example configuration:

feature CCodeFeature {
	InterfaceEventListerner = true
	Singleton = true
}

Create Custom Code Generators

YAKINDU Statechart Tools provides a rich feature set to supports custom code generators out of the box. These code generators can be either written in Java, Xtend or in Xpand

Writing a custom code generator with Xtend2/Java

First, you have to create a new Xtend2 generator project. Click File > New > Other... > YAKINDU > YAKINDU Xtend2/Java Generator Project to create a new Xtend2 Generator Project.

The wizards asks for a Project name and the name of the Generator class, where you have to specify a full qualified class name. If you check the Use Xtend checkbox, the Generator class will be initially created as an Xtend class. Otherwise, Java will be used for the generator.

The check box Configure for Plugin Export adds all required extension point registrations to the new project for exporting as a plugin The Generator Model can refer to the new Generator Plugin via its unique Generator ID. If you want to contribute custom generator features for your code generator, check the Create Feature Library check box.

After click on Finish a new project is created in your workspace. All required plugin dependencies and extension points are registered and you can start to write your code generator based on the ExecutionFlow meta model [Link].

Executing a custom Xtend2/Java code generator

YAKINDU Statechart Tools provide a convenient way to execute your generator while you are developing it.
Therefore, you have to create a new Generator Model with the generator id yakindu::generic, either by using the New Statechart Generator Model wizard or by simple creating a new text file with the file extension .sgen. the following feature allows to configure your code generator.

Generator

The Generator feature allows the configuration of a custom code generator located in the workspace and written in Java or another JVM language. It is a required feature and consists of the following parameters:

  1. generatorProject (String, required): The name of the generator project
  2. generatorClass (String, required): The full qualified class name of the code generator class.
  3. configurationModule (String, optional): The full qualified class name for a guice module to configure the code generator

Example configuration:

feature Generator {
	generatorProject = "org.yakindu.sct.mygenerator"
	generatorClass = "org.yakindu.sct.MyGenerator"
}
		

Executing a custom Xpand code generator

to execute an xpand based custom code generator, you have to create a new Generator Model with the generator id yakindu::xpand, either by using the New Statechart Generator Model wizard or by simple creating a new text file with the file extension .sgen. the following feature allows to configure your code generator.

Template

The Generator feature allows the configuration of a custom code generator located in the workspace and written in Java or another JVM language. It is a required feature and consists of the following parameters:

  1. templateProject (String, required): The name of the generator project
  2. templatePath (String, required): The full qualified template path to the main template.

Example configuration:

feature Template {
	templateProject = "ExampleProject"
	templatePath = "org::yakindu::sct::generator::xpand::Main::main"
}