Methods, systems, and apparatus for automatically generating RTE codes for Autosar CP
By constructing template files and parsing ARXML files without relying on logic, the RTE code for Autosar CP is automatically generated, solving the problems of inconsistency and maintenance difficulties in existing technologies, and achieving efficient and automated code generation and maintenance.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-29
- Publication Date
- 2026-04-07
AI Technical Summary
In existing technologies, the RTE code generation method of the Autosar CP architecture suffers from problems such as tedious and error-prone manual writing, insufficient tool generation flexibility, and maintenance difficulties, resulting in system inconsistency and high development costs.
It adopts a logic-free template file construction method, parses ARXML files and constructs data structures, and automatically generates RTE code through a unified generation paradigm and template mechanism, including static statements, variable resolution statements, loop statements and condition-driven statements, supporting a flexible template mechanism and a variety of application scenarios.
It improves the consistency and correctness of RTE code generation, reduces human error, simplifies the writing and maintenance of template files, increases the automation and adaptability of code generation, and reduces development costs.
Smart Images

Figure CN119148996B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of Autosar technology, and specifically relates to a method, system and apparatus for automatically generating RTE codes for Autosar CP. Background Technology
[0002] In modern automotive electronic systems, the complexity and scale of software are constantly increasing. To improve development efficiency and ensure system reliability, the automotive industry standardization organization AUTOSAR (AUTomotive Open System Architecture) has proposed a standardized automotive electronic software architecture. The AUTOSAR architecture is divided into the Classic Platform (CP) and the Adaptive Platform (AP), with the Classic Platform (CP) being more suitable for vehicle control systems with high real-time requirements. In the AUTOSAR CP architecture, the Runtime Environment (RTE) is a crucial middleware layer responsible for communication and data exchange between software components (SWCs). By providing standardized interfaces and services, the RTE shields the differences in underlying hardware, enabling software components to be developed and tested independently, thereby improving system modularity and reusability.
[0003] Currently, RTE code generation mainly relies on manual writing or automated generation based on specific tools. However, these methods have the following drawbacks:
[0004] Manual coding is tedious and error-prone: Manually coding RTE code is not only labor-intensive, but also prone to human error, leading to inconsistencies and unreliability in the system.
[0005] (1) Insufficient flexibility in tool generation: Existing automated generation tools are usually customized for specific projects, lacking flexibility and scalability, and are difficult to adapt to the needs of different projects.
[0006] (2) Difficult to maintain: Due to the lack of unified specifications and standards in the code generation process, the later maintenance and update work is very difficult, which increases development costs and time. Summary of the Invention
[0007] To address the aforementioned technical problems, this invention provides a method for automatically generating RTE code for Autosar CP, comprising the following steps:
[0008] Step S1: Construct a template file using a logic-free construction method. The template file's syntax includes: static statements, variable resolution statements, loop statements, and condition-driven statements.
[0009] Step S2: Parse the ARXML file and construct the data structure;
[0010] Step S3: Build the configuration file, including: file naming rules, the name of the required template file, and the name of the data structure;
[0011] Step S4: Automatically generate RTE code based on the template file, the data structure, and the configuration file.
[0012] Beneficial effects:
[0013] 1. This invention provides an automatic RTE code generation method for Autosar CP. By adopting a unified generation paradigm and template mechanism, it ensures the consistency and correctness of the generated code, reduces human error, and improves the consistency and correctness of code generation.
[0014] 2. This invention reduces the workload of developers and improves the automation of code generation by automatically parsing ARXML files and constructing data structures.
[0015] 3. This invention adopts a flexible template mechanism. The unified generation paradigm and template mechanism can flexibly adapt to different project needs and support the customization and expansion of various application scenarios.
[0016] 4. This invention adopts a logic-free template and a unified generation paradigm, which simplifies the writing and maintenance of template files and improves the maintainability of the code generation process. Attached Figure Description
[0017] Figure 1 This is a schematic diagram of the automatic generation method of RTE code for Autosar CP according to the present invention;
[0018] Figure 2 This is a schematic diagram of the overall structure of the method of the present invention;
[0019] Figure 3 This is a diagram illustrating template file types.
[0020] Figure 4 This is a diagram illustrating the parsing process of an ARXML file.
[0021] Figure 5 This is a structural block diagram of an Autosar CP automatic RTE code generation system according to the present invention. Detailed Implementation
[0022] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention. Furthermore, the technical features involved in the various embodiments of this invention described below can be combined with each other as long as they do not conflict with each other.
[0023] Example 1
[0024] like Figure 1 As shown in the figure, an embodiment of the present invention provides a method for automatically generating RTE code for Autosar CP, which includes the following steps:
[0025] Step S1: Construct a template file using a logic-free construction method. The template file's syntax includes: static statements, variable resolution statements, loop statements, and condition-driven statements.
[0026] Step S2: Parse the ARXML file and construct the data structure;
[0027] Step S3: Build the configuration file, including: file naming rules, the names of the required template files, and the names of the data structures;
[0028] Step S4: Automatically generate RTE code based on the template file, data structure, and configuration file.
[0029] Figure 2 A schematic diagram of the overall structure of the method of the present invention is shown.
[0030] In one embodiment, step S1 above: constructing a template file using a logic-free construction method, wherein the syntax of the template file includes: static statements, variable resolution statements, loop statements, and condition-driven statements, specifically including:
[0031] a) Static statements: When rendering the template file, static statements are output as is. They are used for text or code snippets that require fixed output and do not require any logical processing. Statements not enclosed in double brackets are static statements.
[0032] For example:
[0033] Template content:
[0034] #include "Rte.h"
[0035] Output:
[0036] #include "Rte.h"
[0037] b) Variable resolution statement: When rendering the template file, the variable resolution statement dynamically replaces the variables in the template file with real-time data, ensuring that the generated code or text can dynamically reflect the current data state. The variable resolution statement is enclosed in double curly braces.
[0038] For example:
[0039] Template content:
[0040] #ifndef RTE_{{ swc_name}}_H
[0041] #define RTE_{{ swc_name}}_H
[0042] Data structure (key to the left of the colon, value to the right):
[0043] {
[0044] "swc_name": "BswM
[0045] }
[0046] Output:
[0047] #ifndef RTE_BswM_H
[0048] #define RTE_BswM_H
[0049] c) Loop Statements: Loop statements repeatedly render the content defined within each element of a data list, used to generate structured, repetitive blocks of code or text. Loop statements consist of a pair of tags, including an opening tag. and close the tab , where section is a list of data.
[0050] For example:
[0051] Template content:
[0052] {{ #variable_rx_list}}
[0053] extern VAR({{ data_type}}, RTE_DATA)
[0054] {{ Communication_data}};
[0055] {{ variable_rx_list}}
[0056] Data Structures:
[0057] "variable_rx_list": [
[0058] {
[0059] "Communication_data": "Rte_Rx_000000",
[0060] "data_type": "UInt8"
[0061] },
[0062] {
[0063] "Communication_data": "Rte_Rx_000001",
[0064] "data_type": "UInt8"
[0065] } ]
[0067] Output:
[0068] extern VAR(UInt8, RTE_DATA) Rte_Rx_000000;
[0069] extern VAR(UInt8, RTE_DATA) Rte_Rx_000001;
[0070] d) Condition-driven statements: Condition-driven statements are divided into Boolean condition-driven statements and reverse condition-driven statements;
[0071] Boolean condition-driven statements: dynamically determine whether to render the content of a statement block based on real-time Boolean data; Boolean condition-driven statements consist of a pair of tags, including an open tag. and close the tab The value corresponding to section is of boolean type.
[0072] For example:
[0073] Template content:
[0074] {{ #is_assembly_connector}}
[0075] VAR(Std_ReturnType, AUTOMATIC) rtn;
[0076] ( (data)) = {{ Communication_data}};
[0077] rtn = ((VAR(Std_ReturnType, AUTOMATIC))RTE_E_OK);
[0078] return rtn;
[0079] {{ is_assembly_connector}}
[0080] Data Structures:
[0081] {
[0082] "is_assembly_connector": true,
[0083] "Communication_data": "Rte_Rx_000001"
[0084] }
[0085] Output:
[0086] VAR(Std_ReturnType, AUTOMATIC) rtn;
[0087] ( (data)) = Rte_Rx_000001;
[0088] rtn = ((VAR(Std_ReturnType, AUTOMATIC))RTE_E_OK);
[0089] return rtn;
[0090] Reverse conditional statements are used to handle exceptions and default conditions when data is false, null, or undefined. They render the statement block content. A reverse conditional statement consists of a pair of tags, including an open tag. and close the tab The value corresponding to section is of boolean type.
[0091] For example:
[0092] Template content:
[0093] {{ ^is_count}}
[0094] {{ runnable_entity}}();
[0095] {{ is_count}}
[0096] Data Structures:
[0097] a.{
[0098] "runnable_entity": "RE_ModeManagement_10ms"
[0099] }
[0100] b.{
[0101] "runnable_entity": "RE_ModeManagement_10ms"
[0102] "is_count": "True"
[0103] }
[0104] Output:
[0105] a. RE_ModeManagement_10ms();
[0106] b. Empty (no output)
[0107] like Figure 3 As shown, the template files are divided into the following 8 categories. The description of each category and the information to be extracted are as follows:
[0108] a) Software component header file template (Rte_{swc_name}.h):
[0109] 1) Template File Description: This template is used to generate the header file for software components, containing global variable declarations, API declarations, API mappings, and function declarations for runnable entities. The template file contains variable placeholders and loop structures for inserting specific data.
[0110] 2) Information to be extracted: basic information of the component, interface definition, data sending and receiving points, service call points, etc.
[0111] b) Software component type header file (Rte_{swc_name}_Type.h):
[0112] 1) Template File Description: This template is used to generate the data type header file for software components, containing the data type definitions and signal type definitions for the components. The template includes placeholders for type definitions, which can be dynamically replaced.
[0113] 2) Information to be extracted: component data type definition, signal type, etc.
[0114] c) Callback header file (Rte_Cbk.h):
[0115] 1) Template file description: This template is used to generate the header files for callback functions defined in the system, containing the declarations of all callback functions. The template file uses placeholders to replace the actual callback function names.
[0116] 2) Information to be extracted: Callback functions defined in the system and their corresponding signal information.
[0117] d) Rte C file (Rte.c):
[0118] 1) Template File Description: This template file is used to generate the C file for the RTE, containing the definition of global variables, the implementation of APIs, the implementation of callback functions, and the implementation of operating system tasks. The content in the template file is highly dynamic, using a large amount of variable interpolation, conditional rendering, and loop logic.
[0119] 2) Information to be extracted: Information from all components, including component references, runnable entities, signal mappings, data mappings, etc.
[0120] e) RTE type header file (Rte_Type.h):
[0121] 1) Template File Description: This template is used to generate the RTE configuration header file, containing basic system configuration information. The template file uses type mapping placeholders to generate the actual content.
[0122] 2) Information to be extracted: Data type definitions and mapping relationships of all signals.
[0123] f) RTE configuration header file (Rte_Cfg.h):
[0124] 1) Template File Description: This template file is used to generate the RTE configuration header file, containing basic system configuration information. Placeholders in the template file are used to insert specific configuration data.
[0125] 2) Information to be extracted: Basic system configuration information.
[0126] g) Operating system task C file (OsTask.c):
[0127] 1) Template File Description: This template file is used to generate the implementation file for the operating system task, including configurations such as task priority, stack size, and period, as well as the task's implementation function. The template file has a complex structure, supports conditional rendering and list looping. The Autosar specification does not require RTE to generate this file; it is used for adaptation to FreeRTOS.
[0128] 2) Information to be extracted: Runnable entities and their corresponding task scheduling information.
[0129] h) Operating system task header file (OsTask.h):
[0130] 1) Template File Description: This template file is used to generate the header file for operating system tasks, containing task definitions and declarations of task initialization functions. The template file contains placeholders for task names and initialization function declarations. The Autosar specification does not require RTE to generate this file; it is used for adaptation to FreeRTOS.
[0131] 2) Information to be extracted: the name of the task.
[0132] In one embodiment, step S2 above: parsing the ARXML file and constructing the data structure specifically includes:
[0133] Step S21: Parse the ARXML file: Parse the ARXML file containing system description and configuration, extracting the component, interface, and signal information required by the template file; if the necessary information cannot be extracted during the parsing process, an error will be immediately reported and the specific error location will be indicated, including:
[0134] a) Error detection: During the parsing process, check that each key field and node exists and conforms to the expected format and content;
[0135] b) Error Detection: Captures all errors that occur during the parsing process, including: missing fields, format errors, and data type mismatches;
[0136] c) Error location: Accurately locate the error position, including the specific line number and column number in the ARXML file, as well as the related node path;
[0137] d) Error Classification: Errors are classified into warnings, errors, and fatal errors in order to take different actions.
[0138] e) Error message: Generate detailed error message information, including: error type, error location and possible cause, and provide correction suggestions;
[0139] f) Error Log: Record all error messages in a log file for later analysis and debugging;
[0140] g) Error notification: Display error information in real time in the graphical user interface to ensure that users can understand and handle errors in a timely manner;
[0141] h) Error handling: Provides error handling options, including: retry parsing, ignore errors and continue parsing, or terminate the parsing process;
[0142] Step S22: Organize the information into a data structure consisting of key-value pairs that correspond one-to-one with the placeholders in the template file; use the placeholders as keys and the information as values to ensure the consistency and uniformity of the data during the subsequent rendering of the template file.
[0143] Figure 4 A diagram illustrating the process of parsing an ARXML file is shown.
[0144] In one embodiment, step S3 above: constructing the configuration file, including: file naming rules, the name of the required template file, and the name of the data structure, specifically including:
[0145] 1) File naming rules: Define file naming rules based on the Autosar specification and the type of RTE code, which will be used as the filenames for the generated RTE code;
[0146] 2) Template file name: The required template file must be specified in the configuration file;
[0147] 3) Data structure name: The configuration file specifies the name of the data structure required for template file rendering.
[0148] Here is an example of a generation paradigm for generating header files for software components:
[0149] app_header_cfg: &app_header_cfg
[0150] output_file: Rte_{swc_name}.h
[0151] per_instance_per_swc: True
[0152] template_file: rte_application_header.xtl
[0153] variable_key_mapping: {
[0154] wc_name: component_name_map,
[0155] variable_rx_list: global_variable_rx_map,
[0156] data_receive_point_api_list: data_receive_point_api_map,
[0157] data_send_point_api_list: data_send_point_api_map,
[0158] server_call_point_api_list: server_call_point_api_map,
[0159] runnable_entity_api_list: runnable_entity_api_map}
[0160] In this example, `output_file` defines the naming rules for the generated file. This invention uses `{swc_name}` as a placeholder, which will be replaced by the `swc_name` value in `component_name_map`. For example, the generated filename will be `Rte_BswM.h`.
[0161] `per_instance_per_swc` indicates whether to generate multiple files based on `swc_name`. If `True`, the system will generate a separate file for each `swc_name`; if `False`, it will generate a single file.
[0162] template_file is used to specify the template file for generating code;
[0163] `variable_key_mapping` is used to define the data structure required to generate the target code. Each key corresponds to a placeholder in the template, and each value corresponds to the data structure built after parsing the ARXML file.
[0164] In one embodiment, step S4 above, automatically generating RTE code based on the template file, data structure, and configuration file, specifically includes:
[0165] Step S41: Read and parse the configuration file to obtain the required data structure name, template file name, and file naming rules;
[0166] Step S42: Render template files one by one according to the corresponding data structure and generate corresponding code content; during the rendering process, fill the placeholder positions in the template file with the specific data in the data structure, and dynamically generate code files containing multiple formats and contents according to the variable resolution, loop and condition-driven syntax mechanism and file naming rules.
[0167] Step S43: Organize the code files and place them in the specified directory structure so that they are stored and managed according to predefined specifications.
[0168] The method of this invention can quickly generate RTE code after parsing input data and configuration files. The entire code generation process takes only 150ms and generates approximately 5000 lines of code. Moreover, when project requirements change, only the corresponding ARXML file and configuration file need to be updated for automatic re-parsing and generation of new code. If the naming rules are modified, only the configuration file needs to be modified.
[0169] Example 2
[0170] like Figure 5 As shown, this embodiment of the invention provides an automatic RTE code generation system for Autosar CP, comprising the following modules:
[0171] The template file construction module 51 is used to construct template files using a logic-free construction method. The syntax of the template files includes: static statements, variable resolution statements, loop statements, and condition-driven statements.
[0172] The data structure construction module 52 is used to parse ARXML files and construct data structures.
[0173] The configuration file module 53 is used to build configuration files, including: file naming rules, the names of required template files, and the names of data structures;
[0174] The code generation module 54 is used to automatically generate RTE code based on template files, data structures, and configuration files.
[0175] This invention also provides an automatic RTE code generation device for Autosar CP, including a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the computer program for the automatic RTE code generation method of Autosar CP described in the above embodiments.
[0176] The above embodiments are provided merely for the purpose of describing the present invention and are not intended to limit the scope of the invention. The scope of the invention is defined by the appended claims. Various equivalent substitutions and modifications made without departing from the spirit and principles of the invention should be covered within the scope of the invention.
Claims
1. A method for automatically generating RTE code for Autosar CP, characterized in that, include: Step S1: Construct a template file using a logic-free construction method. The template file's syntax includes: static statements, variable resolution statements, loop statements, and conditional statements, specifically including: a) Static statements: When rendering template files, static statements are output as is. They are used for text or code snippets that require fixed output and do not require any logical processing. Statements not enclosed in double curly braces are all static statements. b) Variable resolution statement: The variable resolution statement dynamically replaces the variables in the template file with real-time data when the template file is rendered; the variable resolution statement is enclosed in double curly braces; c) Loop Statements: Loop statements repeatedly render the content defined within each element of a data list, used to generate structured, repetitive blocks of code or text; a loop statement consists of a pair of tags, including an opening tag. and close the tab The section is a list of data; d) Conditional statements: Conditional statements are divided into Boolean conditional statements and reverse conditional statements. Boolean conditional statements dynamically determine whether to render the content of a statement block based on real-time Boolean data. A Boolean conditional statement consists of a pair of tags, including an open tag. and close the tab The value corresponding to `section` is a boolean type. Reverse conditional statements are used to handle cases where data is false, null, or undefined, rendering the statement block content; they are used to handle exceptions and default cases. A reverse conditional statement consists of a pair of tags, including an open tag. and close the tab The value corresponding to section is a boolean type. Among them, the template file of type operating system task C file is used to generate the implementation file of operating system task, which supports conditional rendering and list looping. The RTE in the Autosar specification does not need to generate this file. This file is used to adapt to FreeRTOS. For template files of type operating system task header files, which contain placeholders for task names and initialization function declarations, the Autosar specification does not require RTE to generate such a file; this file is used to adapt to FreeRTOS. Step S2: Parse the ARXML file and construct the data structure; Step S3: Build the configuration file, including: file naming rules, the name of the required template file, and the name of the data structure; Step S4: Automatically generate RTE code based on the template file, the data structure, and the configuration file.
2. The method for automatically generating RTE code for Autosar CP according to claim 1, characterized in that, Step S2: Parsing the ARXML file and constructing the data structure specifically includes: Step S21: Parse the ARXML file: Parse the ARXML file containing system description and configuration, extracting the component, interface, and signal information required by the template file; if the necessary information cannot be extracted during the parsing process, an error will be immediately reported and the specific error location will be indicated, including: a) Error detection: During the parsing process, check that each key field and node exists and conforms to the expected format and content; b) Error Detection: Captures all errors that occur during the parsing process, including: missing fields, format errors, and data type mismatches; c) Error location: Accurately locate the error position, including the specific line number and column number in the ARXML file, as well as the related node path; d) Error Classification: Errors are classified into warnings, errors, and fatal errors in order to take different actions. e) Error message: Generate detailed error message information, including: error type, error location and possible cause, and provide correction suggestions; f) Error Log: Record all error messages in a log file for later analysis and debugging; g) Error notification: Display error information in real time in the graphical user interface to ensure that users can understand and handle errors in a timely manner; h) Error handling: Provides error handling options, including: retry parsing, ignore errors and continue parsing, or terminate the parsing process; Step S22: Organize the information into a data structure consisting of key-value pairs that correspond one-to-one with the placeholders in the template file; use the placeholders as keys and the information as values to ensure the uniformity and consistency of data during the subsequent rendering of the template file.
3. The method for automatically generating RTE code for Autosar CP according to claim 2, characterized in that, Step S3: Constructing the configuration file, including: file naming rules, the name of the required template file, and the name of the data structure, specifically including: 1) File naming rules: Define file naming rules based on the Autosar specification and the type of RTE code, which will be used as the filenames for the generated RTE code; 2) Template file name: The required template file must be specified in the configuration file; 3) Data structure name: The configuration file specifies the name of the data structure required for template file rendering.
4. The method for automatically generating RTE code for Autosar CP according to claim 3, characterized in that, Step S4: Automatically generate RTE code based on the template file, the data structure, and the configuration file, specifically including: Step S41: Read and parse the configuration file to obtain the required data structure name, template file name, and file naming rules; Step S42: Render template files one by one according to the corresponding data structure to generate corresponding code content; during the rendering process, fill the placeholder positions in the template file with the specific data in the data structure, and dynamically generate code files containing multiple formats and contents according to the variable parsing, loop and condition-driven syntax mechanism and the file naming rules. Step S43: Organize the code files and place them in the specified directory structure so that they are stored and managed according to predefined specifications.
5. An automatic RTE code generation system for Autosar CP, characterized in that, Includes the following modules: A template file construction module is used to build template files using a logic-free construction method. The syntax of the template files includes: static statements, variable resolution statements, loop statements, and conditional statements, specifically including: a) Static statements: When rendering template files, static statements are output as is. They are used for text or code snippets that require fixed output and do not require any logical processing. Statements not enclosed in double curly braces are all static statements. b) Variable resolution statement: The variable resolution statement dynamically replaces the variables in the template file with real-time data when the template file is rendered; the variable resolution statement is enclosed in double curly braces; c) Loop Statements: Loop statements repeatedly render the content defined within each element of a data list, used to generate structured, repetitive blocks of code or text; a loop statement consists of a pair of tags, including an opening tag. and close the tab The section is a list of data; d) Conditional statements: Conditional statements are divided into Boolean conditional statements and reverse conditional statements. Boolean conditional statements dynamically determine whether to render the content of a statement block based on real-time Boolean data. A Boolean conditional statement consists of a pair of tags, including an open tag. and close the tab The value corresponding to `section` is a boolean type. Reverse conditional statements are used to handle cases where data is false, null, or undefined, rendering the statement block content; they are used to handle exceptions and default cases. A reverse conditional statement consists of a pair of tags, including an open tag. and close the tab The value corresponding to section is a boolean type. Among them, the template file of type operating system task C file is used to generate the implementation file of operating system task, which supports conditional rendering and list looping. The RTE in the Autosar specification does not need to generate this file. This file is used to adapt to FreeRTOS. For template files of type operating system task header files, which contain placeholders for task names and initialization function declarations, the Autosar specification does not require RTE to generate such a file; this file is used to adapt to FreeRTOS. The data structure module is used to parse ARXML files and construct data structures. A configuration file building module is used to build configuration files, including: file naming rules, the name of the required template file, and the name of the data structure; The code generation module is used to automatically generate RTE code based on the template file, the data structure, and the configuration file.
6. An automatic RTE code generation device for Autosar CP, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the automatic RTE code generation method of Autosar CP as described in any one of claims 1-4.
Citation Information
Patent Citations
Automobile electronic controller-oriented runtime environment generation system and method
CN102063298A
Vehicle-mounted service code generating and compiling method based on DDS and readable storage medium
CN114546341A
Vehicle control code automatic generation method and device, storage medium and electronic equipment
CN115437617A