Generate C++ Type and Component Code
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
- Identifiers (for Protocols and Signals)
- Protocol
- Custom Type
- Struct
Active Container
For Active Containers, a class is generated that instantiates all child components (other containers as well as Active Parts and Active Interrupts). The class will call all initialize and startup methods on all children. 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 behavior.
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 behavior.
History: Added in V1.0
Identifiers
For every protocol and signal in the model, 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 in the model, a class is generated. The protocol will contain all fields defined in the model. It provides compare and assignment operators and can be serialized and de-serialized using the Imt.Base.Core.Serialization package.
History: Added in V1.0
Enumerations
For every enumeration in the model, 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
For every struct in the model, a struct is generated in the target code. The struct will contain all fields defined in the model. It provides compare and assignment operators and can be serialized and de-serialized using the Imt.Base.Core.Serialization package.
History: Added in V2.0
Custom Types
For every cusom type in the model, a class is generated. The class can be used to create strongly typed values of the given custom type. The class provides compare and assignment operators and can be serialized and deserialized using the Imt.Base.Core.Serialization package.
History: Added in V2.0
Configuration
The source code generation can be configured in the Build Configuration on the Generator Page.
There are 2 groups of values that will be used to configure the generated source code:
- Source Paths
- Source Code
Source Paths Group
In this group, the root path for all generated source code can be configured.
NOTE: The configured folder must not overlap with any other output folder for this or any other build configuration.
When 'Clear Output Directory' is checked, all contents of the folder and all its sub-folders will be erased before code is generated. Warning: This will delete all user defined code in these folder and all sub-folders.
To place code for a group of generated artifacts in a sub folder, it can be set in the given field. The path is added to the root path. If the field is empty, the root path will be used.
For Components and Data Types, there will be sub folders generated inside the folder (root+ specific path) if the component/type is located in a sub namespace.
Source Code Group
In this group, the source code that will be generated can be defined.
The generation of source code for components, startup code and data types can be enabled independent of each other. If none is enabled, no unit test code will be generated.
When referenced data types generation is enabled, data type code will be generated as well for all data types defined in referenced projects. If it is disabled, only data types defined inside the model of the current project will be generated.
To protect the generated code files, 'Protect Generated Files' can be checked. This will set the read only flag in the generated files that are not meant to be changed by the developer. These files will still be overwritten when code is generated again. (The file is protected from changes by the developer).
If 'Overwrite AP Handler' is enabled, all handler files already existing will be overwritten. If not checked, existing handler files will not be overwritten to preserve user code. Warning: This will override all user defined code in these files.
The given file headers will be used for all generated header (.h) and source code files (.cpp).
Source Code Coding Style
The coding style configuration of the Build Configuration as described in the article Coding Style Configation will be applied to all generated source code.
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 V2.0.1 of the DATAFLOW Designer software.
Latest update 2022-04-09 by WUM.
Required Module: DATAFLOW Code, DATAFLOW Frames
Comments
0 comments
Please sign in to leave a comment.