Generate C++ Type and Component Code
by Marco Wuelser
The DATAFLOW Code Generator can generate C++ classes for Data Types and Software Components defined in the DATAFLOW Designer Project.
See C++ Code Generation article for an overview.
Generated Artifacts
The Code Generator can generate classes for the following artifacts:
- Active Container
- Active Part
- Active Interrupt
- Startup Code
- Protocol Identifiers / Signals
- Protocol
- Custom Type (new in V2.0)
- Struct (new in V2.0)
Active Container
For Active Containers, a class is generated that instanciates all child components (other containers as well as Active Parts and Active Interrupts). The class will call all initialize and startup methods on all childeren. All DATAFLOW Channels inside the container will also be generated and connected during initialization of the container.
History: Added in V1.0
Active Part
For Active Parts, a class is generated that contains the main execute method. That method calls the correct user defined handler for any received protocol and expired timer. Handlers for initialization and startup are called as well.
To implement the user defined handlers, a handler class is generated. If such a class exists, it is not overwritten by default. See configuration of the overwrite behaviour.
History: Added in V1.0
Active Interrupt
For Active Interrupts a static class is generated that contains the interrupt handler(s). That method will notify the runtime on entry and exit of the interrupt service routine (ISR) and calls the user defined handler that implements the behaviour of the ISR. Handlers for initialization and startup are called as well.
To implement the user defined handlers, a handler class is generated. If such a class exists, it is not overwritten by default. See configuration of the overwrite behaviour.
History: Added in V1.0
Protocol Identifiers / Signals
For every protocol identifier, a constant is defined in the ProtocolIdentifiers.h header file. For protocols, a class is generated as well, see below. For signals, the identifier is the only generated artifact.
History: Added in V1.0
Protocols
For every protocol a class is generated. The class contains all defined protocol fields and implements methods for creation, compare, assignment, serialization and de-serialization.
History: Added in V1.0
Enumerations
For every enumeration an enum is generated. The class contains all enumerators as constants.
Note:
For C++98 the enum is nested inside a struct to avoid placement in the parent namespace. For C++11 and newer, enum class is used instead.
History: Added in V1.0
Structs
Added in V2.0, documentation will be added on release.
History: Added in V2.0
Custom Types
Added in V2.0, documentation will be added on release.
History: Added in V2.0
Parameters
Added in V2.0, documentation will be added on release.
History: Added in V2.0
Configuration
To add a Toolchain for code generation, use the DATAFLOW Designer. Add a new Toolchain to the root container of the software:
Select one of the Target templates for you Toolchain (e.g. IAR Systems Workbench for ARM):
General Page
The Toolchain configuration name can be adjusted after creation if required:
Configuration Page
Ensure that the Solution File Directory is the correct location for the solution file of your target workspace or solution.
Note that only one Toolchain in the same container can use Overwrite Runtime Configuration Header Files. Therefore, if there are multiple Toolchains, enable this option for the target Toolchain and disable it for any unit test Toolchain to avoid conflicts. The unit test build will then use the configuration files generated for the target Toolchain.
Dependency Page
Ensure that the Imt.Base Directory path is the same as for your other Toolchains. Otherwise, all Imt.Base files will be duplicated in your project.
Also make sure, that the selected Runtime Version does match your Toolchain for the target IDE (e.g. IAR).
It is not recommended to mix different Runtime Versions in the same project.
If the Imt.Base files are managed by hand, the Extract Libraries checkbox shall be disabled and the Imt.Base directory must point to the manual installation of the Imt.Base files.
Generator Page
The path of the generated components can be configured relative to the configured output directory and shall be adjusted according the the desired project structure. Note that the actual files containing the generated classes will be located in sub folders according to the defined namespace.
To ensure that the generator generates types and components, the Generate Source Code for Types and Component option must be enabled. This option can be disabled for other Toolchains (e.g. unit test Toolchain).
Coding Style Page
The coding style configuration options of the code generator are described in the article Coding Style Configuration
Add User Defined Code
The generated source code contains all features known to the DATAFLOW Designer. This does not include behavior of active parts and active interrupts. Therefore it is required for the user to add additional code to these software items. For that purpose, the generator will generate a ...Handler class (*.cpp and *.h file). This file is not overwritten when it already exists on code generation. Therefore the generator will never overwrite any user code.
Note:
Do not modify any other generated files. These files will be overwritten on code generation and all your changes will be lost.
This Article has been written based on V1.6.1 of the DATAFLOW Designer software.
Latest update 2021-10-18 by WUM.
Required Module: DATAFLOW Code, DATAFLOW Frames