Automatic generation method, system and device for RTE code of Autosar CP

Through the method of constructing template files without logic and parsing ARXML files, the RTE code of Autosar CP is automatically generated, which solves the inconsistency, unreliability and maintenance difficulties of RTE code generation in the existing technology, and realizes the consistency and correctness of the code and flexibility reduce development costs.

CN119148996AActive Publication Date: 2024-12-17UNIV OF SCI & TECH OF CHINA

Patent Information

Application Number
CN202411367519.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-29
Publication Date
2024-12-17
Estimated Expiration
2044-09-29

AI Technical Summary

Technical Problem

The existing RTE code generation method of Autosar CP has problems such as cumbersome manual writing, insufficient flexibility in tool generation and difficulty in maintenance, resulting in system inconsistency, unreliability and high development costs.

Method used

Use logicless construction template files, parse ARXML files to construct data structures, build configuration files, and automatically generate RTE code based on template files, data structures and configuration files. Use a unified generation paradigm and template mechanism to ensure code consistency and correctness, and support Flexible to adapt to different project needs.

Benefits of technology

Improves the consistency and correctness of code generation, reduces human errors, reduces developer workload, simplifies the maintenance process, supports customization and extension of multiple application scenarios, and improves the automation and maintainability of code generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119148996A_ABST
    Figure CN119148996A_ABST
Patent Text Reader

Abstract

The invention provides a method, system and device for automatically generating RTE codes of Autosar CP, and belongs to the technical field of Autosar. The method comprises the steps that S1, a template file is constructed in a non-logic construction mode; s2, analyzing the ARXML file and constructing a data structure; s3, constructing a configuration file, wherein the configuration file comprises a file naming rule, a name of a required template file and a name of a data structure; and S4, automatically generating an RTE code according to the template file, the data structure and the configuration file. According to the method, a uniform generation normal form and a template mechanism are adopted, so that the consistency and correctness of codes are ensured, and high flexibility and expandability are provided to meet different project requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the technical field of Autosar, and in particular relates to a method, system and device for automatically generating RTE code of Autosar CP. Background Art

[0002] In modern automotive electronic systems, the complexity and scale of software are constantly increasing. In order 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 Classic Platform (CP) and Adaptive Platform (AP), of which Classic Platform (CP) is more suitable for vehicle control systems with high real-time requirements. In the Autosar CP architecture, Runtime Environment (RTE) is a key middle layer that is responsible for communication and data exchange between software components (SWC). RTE shields the differences in the underlying hardware by providing standardized interfaces and services, allowing software components to be independently developed and tested, thereby improving the modularity and reusability of the system.

[0003] Currently, the generation of RTE code mainly relies on manual writing or automatic generation based on specific tools. However, these methods have the following defects: Manual coding is tedious and error-prone: Manual coding of RTE is not only labor-intensive but also prone to human errors, leading to system inconsistency and unreliability.

[0004] (1) Insufficient flexibility in tool generation: Existing automated generation tools are usually customized for specific projects. They lack flexibility and scalability and are difficult to adapt to the needs of different projects.

[0005] (2) Difficulty in maintenance: Due to the lack of unified specifications and standards in the code generation process, subsequent maintenance and updating work is very difficult, which increases development costs and time. Summary of the invention

[0006] In order to solve the above technical problems, the present invention provides a method for automatically generating RTE code of Autosar CP, comprising the following steps: Step S1: constructing a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional drive statements; Step S2: Parse the ARXML file and construct a data structure; Step S3: construct a configuration file, including: a file naming rule, a name of the required template file and a name of the data structure; Step S4: Automatically generate RTE code according to the template file, the data structure and the configuration file.

[0007] Beneficial effects: 1. The present invention provides an automatic RTE code generation method for Autosar CP, which ensures the consistency and correctness of the generated code by adopting a unified generation paradigm and template mechanism, reduces human errors, and improves the consistency and correctness of code generation.

[0008] 2. The present invention reduces the workload of developers and improves the automation level of code generation by automatically parsing ARXML files and building data structures.

[0009] 3. The present invention adopts a flexible template mechanism. The unified generation paradigm and template mechanism can flexibly adapt to different project requirements and support customization and expansion of multiple application scenarios.

[0010] 4. The present invention adopts the use of logic-free templates and unified generation paradigm, which simplifies the writing and maintenance of template files and improves the maintainability of the code generation process. BRIEF DESCRIPTION OF THE DRAWINGS

[0011] Figure 1 A schematic flow chart of a method for automatically generating RTE code of Autosar CP of the present invention; Figure 2 It is a schematic diagram of the overall structure of the method of the present invention; Figure 3 This is a schematic diagram of the template file type; Figure 4 This is a schematic diagram of the ARXML file parsing process; Figure 5 The present invention is a structural block diagram of an RTE code automatic generation system of Autosar CP. DETAILED DESCRIPTION

[0012] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0013] Embodiment 1 like Figure 1As shown, an embodiment of the present invention provides an automatic RTE code generation method for Autosar CP, comprising the following steps: Step S1: constructing a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional drive statements; Step S2: Parse the ARXML file and construct a data structure; Step S3: construct a 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 according to the template file, data structure and configuration file.

[0014] Figure 2 The overall structural schematic diagram of the method of the present invention is shown.

[0015] In one embodiment, the above step S1: constructs a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional driving 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 need to be output in a fixed manner without any logical processing. Statements that are not enclosed in double brackets are all static statements.

[0016] For example: Template content: #include "Rte.h" Output: #include "Rte.h" b) Variable parsing statement: When rendering a template file, the variable parsing statement dynamically replaces the variables in the template file with real-time data to ensure that the generated code or text can dynamically reflect the current data status. The variable parsing statement is surrounded by double curly braces.

[0017] For example: Template content: #ifndef RTE_{{ swc_name}}_H #define RTE_{{ swc_name}}_H Data structure (key is on the left of the colon and value is on the right): { "swc_name": "BswM" } Output: #ifndef RTE_BswM_H #define RTE_BswM_H c) Loop statement: The loop statement repeatedly renders the content defined inside for each element in the data list, and is used to generate structured repeated code blocks or text. The loop statement consists of a pair of tags, including the opening tag and closing tags , where section is list data.

[0018] For example: Template content: {{ #variable_rx_list}} extern VAR({{ data_type}}, RTE_DATA) {{ Communication_data}}; {{ variable_rx_list}} Data structure: "variable_rx_list": [ { "Communication_data": "Rte_Rx_000000", "data_type": "UInt8" }, { "Communication_data": "Rte_Rx_000001", "data_type": "UInt8" } ] Output: extern VAR(UInt8, RTE_DATA) Rte_Rx_000000; extern VAR(UInt8, RTE_DATA) Rte_Rx_000001; d) Conditional driven statements: Conditional driven statements are divided into Boolean conditional driven statements and reverse conditional driven statements; Boolean conditional driven statement: dynamically decides whether the statement block content is rendered based on real-time Boolean type data; Boolean conditional driven statement consists of a pair of tags, including an open tag and closing tags , where the value corresponding to section is of Boolean type.

[0019] For example: Template content: {{ #is_assembly_connector}} VAR(Std_ReturnType, AUTOMATIC) rtn; ( (data)) = {{ Communication_data}}; rtn = ((VAR(Std_ReturnType, AUTOMATIC))RTE_E_OK); return rtn; {{ is_assembly_connector}} Data structure: { "is_assembly_connector": true, "Communication_data": "Rte_Rx_000001" } Output: VAR(Std_ReturnType, AUTOMATIC) rtn; ( (data)) = Rte_Rx_000001; rtn = ((VAR(Std_ReturnType, AUTOMATIC))RTE_E_OK); return rtn; Reverse conditional driven statement: used to render the statement block content when the data is false, empty or undefined, that is, used to handle exceptions and default situations; the reverse conditional driven statement consists of a pair of tags, including the opening tag and closing tags , where the value corresponding to section is of Boolean type.

[0020] For example: Template content: {{ ^is_count}} {{ runnable_entity}}(); {{ is_count}} Data structure: a.{ "runnable_entity": "RE_ModeManagement_10ms"} b.{ "runnable_entity": "RE_ModeManagement_10ms" "is_count": "True" } Output: a. RE_ModeManagement_10ms(); b. Empty (no output) like Figure 3 As shown, the template files are divided into the following 8 categories. The template file description corresponding to each category and the information that needs to be extracted are as follows: a) Software component header file template (Rte_{swc_name}.h): 1) Template file description: This template is used to generate the header file of the software component, which contains the component's global variable declaration, API declaration, API mapping, and function declaration of the runnable entity. The template file contains variable placeholders and loop structures for inserting specific data.

[0021] 2) Information that needs to be extracted: basic information of components, interface definitions, data sending and receiving points, service call points, etc.

[0022] b) Software component type header file (Rte_{swc_name}_Type.h): 1) Template file description: This template is used to generate the data type header file of the software component, which contains the data type definition and signal type definition of the component. The template contains placeholders for type definition and supports dynamic replacement.

[0023] 2) Information that needs to be extracted: component data type definition, signal type, etc.

[0024] c) Callback header file (Rte_Cbk.h): 1) Template file description: This template is used to generate the callback function header file defined in the system, which contains the declaration of all callback functions. The template file uses placeholders to replace the actual callback function name.

[0025] 2) Information that needs to be extracted: callback functions defined in the system and their corresponding signal information.

[0026] d) Rte C file (Rte.c): 1) Template file description: This template file is used to generate the C file of RTE, including the definition of global variables, API implementation, callback function implementation, and operating system task implementation. The content in the template file is highly dynamic, using a lot of variable interpolation, conditional rendering, and loop logic.

[0027] 2) Information to be extracted: Comprehensive information of all components, including component references, runnable entities, signal mapping, data mapping, etc.

[0028] e) RTE type header file (Rte_Type.h): 1) Template file description: This template is used to generate the configuration header file of RTE, which contains the basic information of system configuration. The template file uses the placeholders of type mapping to generate the actual content.

[0029] 2) Information that needs to be extracted: data type definitions of all signals and their mapping relationships.

[0030] f) RTE configuration header file (Rte_Cfg.h): 1) Template file description: This template file is used to generate the configuration header file of RTE, which contains the basic information of system configuration. The placeholders in the template file are used to insert specific configuration data.

[0031] 2) Information to be extracted: basic information of system configuration.

[0032] g) Operating system task C file (OsTask.c): 1) Template file description: This template file is used to generate the implementation file of the operating system task, including the configuration of the task priority, stack size, cycle, and the implementation function of the task. The template file has a complex structure and supports conditional rendering and list loops. The RTE in the Autosar specification does not need to generate this file. This file is used to adapt to FreeRTOS.

[0033] 2) Information that needs to be extracted: runnable entities and their corresponding task scheduling information.

[0034] h) Operating system task header file (OsTask.h): 1) Template file description: This template file is used to generate the header file of the operating system task, including the definition of the task and the declaration of the task initialization function. The template file contains placeholders for the task name and initialization function declaration. The RTE in the Autosar specification does not need to generate this file. This file is used to adapt FreeRTOS.

[0035] 2) Information to be extracted: the name of the task.

[0036] In one embodiment, the above step S2: parsing the ARXML file and constructing a data structure specifically includes: Step S21: Parsing the ARXML file: Parsing the ARXML file containing the system description and configuration, extracting the components, interfaces, and signal information required by the template file; if the necessary information cannot be extracted during the parsing process, an error is immediately reported and the specific error location is prompted, including: a) Error detection: During the parsing process, check whether each key field and node exists and conforms to the expected format and content; b) Error capture: Capture all errors that occur during the parsing process, including: missing fields, format errors, and data type mismatch; c) Error location: Accurately locate the error location, including the specific line and column number in the ARXML file, and the related node path; d) Error classification: Classify errors into warnings, errors, and fatal errors so that different processing measures can be taken; e) Error prompt: Generate detailed error prompt information, including: error type, error location and possible cause, and provide correction suggestions; f) Error log: record all error information in a log file for subsequent 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 corresponding to the placeholders in the template file; use the placeholder as the key and the information as the value to ensure the unity and consistency of the data in the subsequent rendering process of the template file.

[0037] Figure 4 Shows a schematic diagram of the ARXML file parsing process.

[0038] In one embodiment, the above step S3: constructing a configuration file includes: a file naming rule, a name of a required template file and a name of a data structure, specifically including: 1) File naming rules: According to the Autosar specification and the type of RTE code, define the file naming rules as the file name of the generated RTE code; 2) Name of the template file: The required template file is specified in the configuration file; 3) Name of the data structure: The configuration file specifies the name of the data structure required for rendering the template file.

[0039] The following is an example of a build pattern for generating a software component header file: app_header_cfg: &app_header_cfg output_file: Rte_{swc_name}.h per_instance_per_swc: True template_file: rte_application_header.xtl variable_key_mapping: { wc_name: component_name_map, variable_rx_list: global_variable_rx_map, data_receive_point_api_list: data_receive_point_api_map, data_send_point_api_list: data_send_point_api_map, server_call_point_api_list: server_call_point_api_map, runnable_entity_api_list: runnable_entity_api_map} In this example, output_file is used to define the naming rules of the generated file. The present invention uses {swc_name} as a placeholder, which will be replaced by the swc_name value in component_name_map. For example, the generated file name will be Rte_BswM.h; per_instance_per_swc is used to indicate whether to generate multiple files based on swc_name. If it is True, the system will generate a separate file for each swc_name; if it is False, it will generate one file; template_file is used to specify the template file for generating code; 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; In one embodiment, the above step S4: automatically generating RTE code according to the template file, the data structure and the configuration file, specifically includes: 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 the template files one by one according to the corresponding data structure to generate corresponding code content; during the rendering process, fill the specific data in the data structure into the placeholder position in the template file, and according to the variable parsing, loop and condition-driven syntax mechanism, as well as the file naming rules, the template file dynamically generates code files containing multiple formats and contents; Step S43: Organize the code files and put them into a specified directory structure so that they can be stored and managed according to predefined specifications.

[0040] The method of the present invention can be used to quickly generate RTE code after parsing input data and configuration files. The entire code generation process only takes 150ms to generate a total of about 5,000 lines of code. Moreover, when project requirements change, only the corresponding ARXML files and configuration files need to be updated to automatically re-parse and generate new code. If the naming rules are modified, only the configuration file needs to be modified.

[0041] Embodiment 2 like Figure 5 As shown, an embodiment of the present invention provides an RTE code automatic generation system for Autosar CP, including the following modules: The template file construction module 51 is used to construct the template file in a logic-free construction mode, wherein the syntax of the template file includes: static statements, variable parsing statements, loop statements and conditional driving statements; A data structure building module 52 is used to parse the ARXML file and construct a data structure; The configuration file building module 53 is used to build the configuration file, including: a file naming rule, a name of a required template file and a name of a data structure; The code generation module 54 is used to automatically generate RTE code according to the template file, data structure and configuration file.

[0042] An embodiment of the present invention further provides an apparatus for automatically generating RTE code for Autosar CP, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the method for automatically generating RTE code for Autosar CP in the above embodiment of the computer program.

[0043] The above embodiments are provided only for the purpose of describing the present invention, and are not intended to limit the scope of the present invention. The scope of the present invention is defined by the appended claims. Various equivalent substitutions and modifications made without departing from the spirit and principles of the present invention should all be included within the scope of the present invention.

Claims

1. A method for automatically generating RTE code for Autosar CP, characterized in that: include: Step S1: constructing a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional drive statements; Step S2: Parse the ARXML file and construct a data structure; Step S3: construct a configuration file, including: a file naming rule, a name of the required template file and a name of the data structure; Step S4: Automatically generate RTE code according to the template file, the data structure and the configuration file.

2. The method for automatically generating RTE code of Autosar CP according to claim 1, characterized in that: The step S1: constructing a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional driving statements, specifically including: a) Static statements: When rendering template files, static statements will be output as is. They are used for text or code snippets that need to be output in a fixed manner without any logical processing. Statements that are not wrapped in double curly braces are all static statements. b) Variable parsing statement: When rendering a template file, the variable parsing statement dynamically replaces the variables in the template file with real-time data; the variable parsing statement is surrounded by double curly braces; c) Loop statement: The loop statement repeatedly renders the content defined inside for each element in the data list, and is used to generate structured repeated code blocks or text; the loop statement consists of a pair of tags, including an open tag and closing tags , where section is list data; d) Conditional driven statements: Conditional driven statements are divided into Boolean conditional driven statements and reverse conditional driven statements. Boolean conditional driven statements dynamically determine whether the statement block content is rendered based on real-time Boolean type data. Boolean conditional driven statements consist of a pair of tags, including an open tag and closing tags , where the value corresponding to section is of Boolean type; the reverse conditional driven statement is used to render the statement block content when the data is false, empty or undefined, that is, it is used to handle exceptions and default situations. The reverse conditional driven statement consists of a pair of tags, including an open tag and closing tags , where the value corresponding to section is of Boolean type.

3. The method for automatically generating RTE code of Autosar CP according to claim 2, characterized in that: The step S2: parsing the ARXML file and constructing a data structure specifically includes: Step S21: Parsing the ARXML file: Parsing the ARXML file containing the system description and configuration, extracting the components, interfaces, and signal information required by the template file; if the necessary information cannot be extracted during the parsing process, an error is immediately reported and the specific error location is prompted, including: a) Error detection: During the parsing process, check whether each key field and node exists and conforms to the expected format and content; b) Error capture: Capture all errors that occur during the parsing process, including: missing fields, format errors, and data type mismatch; c) Error location: Accurately locate the error location, including the specific line and column number in the ARXML file, and the related node path; d) Error classification: Classify errors into warnings, errors, and fatal errors so that different processing measures can be taken; e) Error prompt: Generate detailed error prompt information, including: error type, error location and possible cause, and provide correction suggestions; f) Error log: All error information is recorded in a log file for subsequent 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 corresponding to the placeholders in the template file; use the placeholder as the key and the information as the value to ensure the unity and consistency of data in the subsequent rendering process of the template file.

4. The method for automatically generating RTE code of Autosar CP according to claim 3, characterized in that: The step S3: constructing a configuration file includes: a file naming rule, the name of the required template file and the name of the data structure, specifically including: 1) File naming rules: According to the Autosar specification and the type of RTE code, define the file naming rules as the file name of the generated RTE code; 2) Name of the template file: the required template file is specified in the configuration file; 3) Name of the data structure: The configuration file specifies the name of the data structure required for rendering the template file.

5. The method for automatically generating RTE code of Autosar CP according to claim 4, characterized in that: The step S4: automatically generating RTE code according to the template file, the data structure and the configuration file, specifically includes: Step S41: reading and parsing the configuration file to obtain the required data structure name, template file name and file naming rules; Step S42: Rendering the template files one by one according to the corresponding data structure to generate corresponding code content; during the rendering process, filling the specific data in the data structure into the placeholder position in the template file, and according to the variable parsing, loop and condition-driven grammar mechanism, and the file naming rule, the template file dynamically generates a code file containing multiple formats and contents; Step S43: Organize the code files and put them into a specified directory structure so that they can be stored and managed according to predefined specifications.

6. An RTE code automatic generation system for Autosar CP, characterized in that: Includes the following modules: A template file construction module is used to construct a template file in a logic-free construction method, wherein the grammatical content of the template file includes: static statements, variable parsing statements, loop statements and conditional drive statements; Build a data structure module to parse ARXML files and construct data structures; A configuration file building module is used to build a configuration file, including: a file naming rule, a name of the required template file and a name of the data structure; A code generation module is used to automatically generate RTE code according to the template file, the data structure and the configuration file.

7. 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, the method for automatically generating RTE code for Autosar CP according to any one of claims 1 to 5 is implemented.

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

  • Real-time operating system generation method and device, real-time operating system use method and device, electronic equipment and medium

    CN115826938A

  • Real-time operation environment generation system and method, computer equipment and storage medium

    CN117873650A

Cited By

  • Client code framework construction method, equipment and medium

    CN119861967A