Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 33 Next »

Prom - Project Management in KIELER

Topics


Overview

The KIELER Compiler (KiCo) can generate different code targets from models. For example it is possible to generate C and Java code from an SCT file. As a result KIELER has to integrate with existing development tools and practices for the C and Java world. In the context of embedded systems, the target device also varies heavily.

Therefore the KIELER Project Management (Prom) has been developed. It eases the creation, compilation and deployment of projects, when using models that can be compiled via KiCo (e.g. SCCharts, Esterel). Furthermore it eases the creation of wrapper code, which is used to initialize and run the model. To do so, there are mainly three components: An Eclipse Launch Configuration, so called Environments, and Project Wizards, which will be introduced in the following.


The KiCo Launch Configuration

Prom provides a launch configuration (launch config) to

  1. compile code from models via KiCo
  2. at the same time, generate wrapper code for these model files
  3. afterwards, execute arbitrary shell commands sequentially if the KiCo compilation and wrapper code generation finished successfully

KiCo launch configurations work per project basis so that every project has to create its own launch config. This is done automatically when performing Right Click > Run As > KiCo Compilation on a model file.

The Run As command will search for a KiCo launch config for the project. If there is such a config, the selected file is only added to the list of model files that should be compiled. If there is none, a launch config is created by using the main file and environment the project has been created with. If the main file and environment information could not be found, dialogs will query it from the user.

Launch Configuration Tabs

The main file of the launch config is used to set several file path variables, which can be used in several fields of the configuration, notably the shell commands to be executed, and wrapper code input. To use a variable, the syntax is ${variable_name}. The variables that are set are

  • main_name : The file name, including its file extension (e.g. MyModel.sct)
  • main_path : The project relative path (e.g. src/MyModel.sct)
  • main_loc : The absolute file system path (e.g. /home/me/workspace/MyProject/src/MyModel.sct)
  • main_name_no_ext : The file name without its file extension (e.g. MyModel)

Further, similar variables for the compiled main file are set, which is the main file in the directory of kieler generated files (see below)

  • compiled_main_name : The file name, including its file extension (e.g. MyModel.sct)
  • compiled_main_path : The project relative path (e.g. kieler-gen/MyModel.sct)
  • compiled_main_loc : The absolute file system path (e.g. /home/me/workspace/MyProject/kieler-gen/MyModel.sct)
  • compiled_main_name_no_ext : The file name without its file extension (e.g. MyModel)

Note: The variables are created in the first KiCo launch. So if you want to select them in a variable selection dialog of Eclipse, you must have started at least one KiCo launch configuration.

Variable Selection Dialog of Eclipse

The values of the launch config can also be (re)set to an environment. This will revert the fields for the compilation target, wrapper code generation and command execution.

The compilation via KiCo is configured on the Compilation tab. Here you can add/remove files that should be compiled via KiCo and the target language as well as the file extension for the language (such as .java for Java). The files will be compiled sequentially in order of appearance in the list. Further, it is possible to add a file path to a template for the output. This is useful to add surrounding content to the KiCo output. The placeholder ${kico_code} can be used in the template.

On the Execute tab, a list of shell commands can be added. They are typically used to further compile the KiCo and wrapper code output and afterwards deploy the result to the target platform. The commands are executed sequentially in order as they appear in the list, after the KiCo compilation and wrapper code generation finished successfully. If a command fails (returns a non-zero exit code), following commands will not be excuted. The name of commands have to be unique and must not contain a comma.

 

The standard streams of executed shell commands (stdin, stderr, stdout), as well as errors from the KiCo compilation and wrapper code generation, are printed to the Console View.

Console View

Launch Groups

The list of shell commands are a simple mechanism to further compile and deploy code via command line tools. However, there are cases in which command line tools are not available or reasonable to use, for example because a different Eclipse launch configuration does a better job.

In this case it is desirable that the KiCo launch config only compiles the model and another Eclipse launch config does the rest. This can be achieved via launch groups. They let you define a launch configuration, which starts other launch configurations sequentially. To illustrate this, another use-case for launch groups is that you have a Client-Server application and want to start the client right after the server for debugging. Then you can create a launch config for the server and a launch config for the client. Afterwards you create a launch group with aforesaid configurations.

Launch Groups

Launch groups are a part of the C/C++ Development Tools (CDT), although they provide a general mechanism that could be a part of any Eclipse IDE. The CDT is available in the Eclipse Marketplace (Help > Eclipse Marketplace)


Prom Environments

Environments are used to provide default settings for project creation and launch. They are configured in the preferences (Window > Preferences > KIELER > Environments).

An environment consists of

  1. a unique name, that does not contain a comma
  2. a related project wizard
  3. information about a main file for the project
  4. information about the target code KiCo should produce
  5. information for wrapper code generation
  6. a list of shell commands which should be run as part of a project launch

Besides the name, all of these are optional, but can improve the workflow.

The related project wizard is run as part of the Prom project wizard and takes care of the actual project creation.

A main file typically contains the entry point of the program on the target environment. Its wrapper code initializes and runs the model and sets inputs and outputs to the physical components of the target device. To ease the project setup and because wrapper code for a specific target platform is often similar, it is possible to define default content for the main file. Therefore the field main file origin can contain an absolute file path to a file with the default contents of a newly created main file for this environment. Furthermore, predefined wrapper code snippets can be injected as part of a project launch, which is described below.

The snippets origin is used to initialize the wrapper code snippet directory of a newly created project.

The other fields are default settings for KiCo launch configurations.

Environments Preference Page

Paths for initial content

The path of the main file origin accept an absolute file path as well as an URL with the platform protocol of Eclipse. An URL for the field has the form plaftorm:/plugin/a.plugin.name/folder/in/the/plugin/file.txt

The snippets origin works analog. It accepts an absolute directory path as well as an URL with the platform protocol which points to a directory. An URL for the field has the form plaftorm:/plugin/a.plugin.name/folder/in/the/plugin


Project Wizards with Prom

Prom provides project wizards, which can create and initialize a project with a model file, a main file and wrapper code snippets. The wizards for different model file types (e.g. SCChart project vs Esterel project) differ only in the initial content for the model file. Other initial content is choosen from the environment, which is selected on the first page of a Prom wizard. The project creation itself is done by another wizard, that is started from within the Prom wizard.

If the snippets directory of an environment is a project relative path, the contents from the snippets origin will be copied to this location in the newly created project. If it is an absolute path, it is not copied to the project. Keeping snippets in a single, project indepentent folder, makes it easier to maintain them. For example it is possible to set an absolute path to a directory outside any project as directory for wrapper code snippets. This directory can then be easily maintained using a version control system. Furthermore, if an issue occurs, it has to be addressed only once, because the snippets are not copied to every new project.

For example to create a project to develop Minstorms running leJOS, one can choose the SCCharts project wizard. In this wizard, one can choose the Mindstorms NXJ environment and define what will be initialized in the project (model file, main file, snippets). Now when pressing the finish button, the related project wizard from the leJOS plugin will be started. When it finishes, the newly created project is initialized with an initial model file, main file and wrapper code snippets.

Prom Project Wizard


Wrapper Code Generation

When modeling a program for an embedded system, it is necessary to set inputs and outputs of physical components (sensors/actuators) to inputs and outputs of the model. This is typically done using wrapper code. However, wrapper code is often similar for a specific device and programming language.

Therefore one can write wrapper code snippets for a target device. These can then be injected to a template file as part of a KiCo launch. What snippets are injected is defined using annotations on inputs and outputs directly in the model file.

In SCT files, annotations are added as in java, with an at-sign e.g. @Wrapper Clock, "500". You can write implicit and explicit wrapper code annotations.

Explicit annotations have the form @Wrapper SnippetName, arg1, arg2, ..., argN. An explicit wrapper annotation raises an error if the snippet does not exist, thus it is recommened to use the explicit @Wrapper annotation. Every other annotation is tried as wrapper code annotation as well, but will be ignored, if no such snippet could be found. Thus you can write the above explicit annotation as @SnippetName arg1, arg2, ..., argN, but there will be no error if the snippet with this name does not exist or could not be found, for example because of a typo.

Wrapper Code Injection Scheme

In the template file one can use special placeholders.

${model_name} will be replaced with the name of the model.

${declarations} and ${decls} will be replaced with additional declarations of variables and functions (<@decl>...</@decl> of a snippet definition). Declarations should occur before the tick loop of the model file. In general they are not required for Java code but may be useful in C applications (e.g. for extern calls).

${initializations} and ${inits} will be replaced with initialization code for components (<@init>...</@init> of a snippet definition). Initialization should occur before the tick loop of the model file.

${inputs} will be replaced with code to set inputs for the model (<@input>...</@input> of a snippet definition). Setting model inputs should occur in the tick loop, before the tick function call.

${outputs} will be replaced with code to read outputs of the model. (<@output>...</@output> of a snippet definition). Reading outputs of the model should occur in the tick loop, after the tick function call.

Wrapper Code Template File Structure

To ease the modification of the template file, one can open it with the text editor the final code will be for. This will enable syntax highlighting and code completion for the langauge, but it will not show any errors. You can open the file for example with the Java Editor of Eclipse using Right Click > Open With > Other > Java Editor

FreeMarker

The wrapper code injection is done using the open source template engine FreeMarker. A wrapper code snippet is basically a Macro definition of FreeMarker. The Macro is called when the corresponding annotation is found in the model file. The file extension of FreeMarker templates is .ftl.

There is an Eclipse plugin for FreeMarker as part of the JBoss Tools Project. It can be installed using the Eclipse Marketplace.

Wrapper Code Generation Example


Automatically generated files

Files created by Prom are saved in the directory kieler-gen. Thereby the directory structure of files is retained, but without a starting Java source folder. This is because kieler-gen itself is a Java source folder.

For example (if code is not a Java source folder) the file code/subfolder/MyModel.sct, will be save to kieler-gen/code/subfolder/MyModel.sct.

In contrast (if src is a Java source folder) the file src/subfolder/MyModel.sct, will be saved to kieler-gen/subfolder/MyModel.sct.

  • No labels