A method, system, device and storage medium for automatic code generation
By analyzing the file information in the DBC file and the Autosar architecture, the object code files at each level in the Autosar architecture are automatically generated, which solves the problems of manual configuration and long development cycles, and improves development efficiency and accuracy.
Patent Information
- Application Number
- CN202210737659.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-27
- Publication Date
- 2025-04-08
- Estimated Expiration
- 2042-06-27
AI Technical Summary
In the Autosar architecture, software engineers need to manually configure thousands of module options, call interfaces and encapsulated interface functions, resulting in a long development cycle, high technical threshold and a risk of development errors.
By analyzing DBC files and obtaining file information of the ECU abstraction layer, service layer and RTE layer, the object code files at each level are automatically generated, and the automatic configuration of CAN channel and the automatic generation of callback function entity files and interface function files are realized.
It improves the development and integration speed of basic software, reduces the development cycle or change cycle, and reduces the risk of errors in manual configuration.
Smart Images

Figure CN115048108B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of Autosar and relates to a method, system, device and storage medium for automatic code generation. Background Art
[0002] The Autosar architecture has the advantages of being hierarchical, modular, configurable, and interface standardized. Currently, more and more controllers are using the Autosar architecture to build the controller software framework. Upgrading from the original development model with a simple structure and process to the Autosar architecture, the requirements for the input and output file content remain unchanged, which enhances the portability of the software, but also increases the complexity of the software framework. Software engineers are required to invest more manpower and time in the software architecture and function development. When developing the ECU abstraction layer, service layer, and RTE layer of the basic software, software engineers often need to manually configure thousands of module options, build call interfaces, encapsulate interface functions, and build models based on information files such as DBC files. Not only does it require a long software development or change cycle, but it also requires extremely high technical barriers. In addition, due to the huge workload and mechanical and repetitive operations, there is a certain risk of development errors. Summary of the invention
[0003] The purpose of the present invention is to solve the problem in the prior art that it is necessary to manually configure thousands of module options, build calling interfaces and encapsulate interface functions, which prolongs the software development or change cycle, and to provide a method, system, device and storage medium for automatic code generation.
[0004] In order to achieve the above object, the present invention adopts the following technical solutions:
[0005] A method for automatically generating code comprises the following steps:
[0006] Parse the DBC file to obtain message signal information;
[0007] Get the CAN channel configuration file in the ECU abstract layer and the arxml files of each module in the service layer respectively;
[0008] Configure the functions of the Autosar module according to the message signal information and files at each level;
[0009] Generate target code files for ECU abstraction layer, service layer and RTE layer respectively.
[0010] A further improvement of the present invention is:
[0011] The target code file in the ECU abstraction layer is a target configuration file, and the generation of the target configuration file includes the following steps:
[0012] Get and parse the CAN channel configuration file of the CANIF module;
[0013] Get the CAN channel configuration file format requirements;
[0014] Match the message signal information with the CAN channel configuration file according to the CAN channel configuration file format requirements;
[0015] Generate target configuration files to realize automatic configuration of CAN channels.
[0016] The target code file in the service layer is a callback function entity file and a target arxml file, which specifically includes the following steps:
[0017] Get the arxml file format structure;
[0018] Get the function name information of the callback function entity in the arxml file;
[0019] Configure options such as function body return type and parameters;
[0020] Create a callback function entity file;
[0021] Configure or modify the functions of each module in the service layer;
[0022] Generate the target arxml file according to the arxml file format structure and the functional configuration or changes of each module.
[0023] The target arxml file and callback function entity file are implemented based on the basic software generated by the Autosar tool.
[0024] The target code file in the RTE layer is an interface function file, and the generation of the interface function file includes the following steps:
[0025] Get basic software layer variables;
[0026] Declare RTE layer signal variables according to the message signal information;
[0027] Process the message signal information to realize the data conversion between the basic software layer variables and the RTE layer signal variables;
[0028] Create an interface function file.
[0029] The message signal information includes a message ID, a message signal name, a signal length, a position, a coefficient, an offset and a period.
[0030] The generation of the target model is implemented using MATLAB.
[0031] A system for automatic code generation, comprising:
[0032] A data analysis module, which is used to analyze the DBC file and obtain message signal information;
[0033] A data acquisition module, which is used to respectively acquire the CAN channel configuration file in the ECU abstraction layer and the arxml files of each module in the service layer;
[0034] A data configuration module, wherein the data configuration module is used to perform function configuration of the Autosar module according to message signal information and files at each level;
[0035] The target code generation module is used to generate target code files for the ECU abstraction layer, the service layer and the RTE layer respectively.
[0036] A device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the method as described in any one of the preceding items when executing the computer program.
[0037] A computer-readable storage medium stores a computer program, wherein the computer program, when executed by a processor, implements the steps of the method described in any one of the preceding items.
[0038] Compared with the prior art, the present invention has the following beneficial effects:
[0039] By parsing the customer's DBC file and obtaining message signal information, the target code files at each level are automatically generated based on the actual needs of the ECU abstraction layer, service layer and RTE layer in the Autosar architecture. The basic code that originally required a lot of manual configuration and construction can now be automatically generated, which improves the development and integration speed of the basic software and effectively reduces the software development cycle or change cycle. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0041] Figure 1 A schematic diagram of the method flow for automatic code generation of the present invention;
[0042] Figure 2 A schematic diagram for generating an ECU abstraction layer target code file of the present invention;
[0043] Figure 3 A schematic diagram for generating a service layer object code file of the present invention;
[0044] Figure 4 A schematic diagram for generating an RTE layer target code file of the present invention;
[0045] Figure 5 A schematic diagram of a system for automatic code generation in the present invention. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0047] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0048] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0049] In the description of the embodiments of the present invention, it should be noted that if the terms "upper", "lower", "horizontal", "inner", etc. indicate an orientation or positional relationship based on the orientation or positional relationship shown in the drawings, or the orientation or positional relationship in which the product of the invention is usually placed when in use, it is only for the convenience of describing the present invention and simplifying the description, and does not indicate or imply that the device or element referred to must have a specific orientation, be constructed and operated in a specific orientation, and therefore cannot be understood as a limitation on the present invention. In addition, the terms "first", "second", etc. are only used to distinguish the description, and cannot be understood as indicating or implying relative importance.
[0050] In addition, if the term "horizontal" appears, it does not mean that the component must be absolutely horizontal, but can be slightly tilted. For example, "horizontal" only means that its direction is more horizontal than "vertical", which does not mean that the structure must be completely horizontal, but can be slightly tilted.
[0051] In the description of the embodiments of the present invention, it is also necessary to explain that, unless otherwise clearly specified and limited, the terms "set", "install", "connect", and "connect" should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection, or it can be indirectly connected through an intermediate medium, or it can be the internal connection of two components. For ordinary technicians in this field, the specific meanings of the above terms in the present invention can be understood according to specific circumstances.
[0052] The present invention is further described in detail below in conjunction with the accompanying drawings:
[0053] See also Figure 1 , is a flow chart of a method for automatic code generation in the present invention, which specifically includes the following steps:
[0054] S1, parse the DBC file to obtain message signal information;
[0055] S2, respectively obtain the CAN channel configuration file in the ECU abstraction layer and the arxml files of each module in the service layer;
[0056] S3, configure the function of the Autosar module according to the message signal information and files at each level;
[0057] S4, generates target code files for the ECU abstraction layer, service layer, and RTE layer respectively.
[0058] See also Figure 2 ,In the ECU abstraction layer, the CAN channel configuration is the module with the largest ,change requirements. The generation of the target configuration file in the ECU abstraction layer includes the following steps:
[0059] S1, obtain and parse the CAN channel configuration file of the CANIF module;
[0060] S2, obtain the CAN channel configuration file format requirements;
[0061] S3, matching the message signal information with the CAN channel configuration file according to the CAN channel configuration file format requirement;
[0062] S4, generates a target configuration file to realize automatic configuration of the CAN channel.
[0063] See also Figure 3, the service layer contains multiple functional modules. Since each functional module contains hundreds of configuration options, the content information of these configuration options is reflected in the arxml file corresponding to the module. Therefore, it is necessary to correspond the content in the arxml file to the configuration item information one by one. For configuration related to the message, the application layer variables are filled into the arxml file. For configuration content unrelated to the message, the configuration items are divided into default configuration options, common configuration options and key configuration options according to actual usage, and the final arxml file is generated after configuration. Regarding the calling relationship between modules, the target code files in the service layer are the callback function entity file and the target arxml file, which specifically includes the following steps:
[0064] S1, obtain the arxml file format structure;
[0065] S2, obtain the function name information of the callback function entity in the arxml file;
[0066] S3, configure options such as function body return type and parameters;
[0067] S4, create callback function entity file;
[0068] S5, configure or change the functions of each module in the service layer;
[0069] S6, generating a target arxml file according to the arxml file format structure and the functional configuration or changed content of each module.
[0070] See also Figure 4 , the target code file in the RTE layer is an interface function file, and the generation of the interface function file includes the following steps:
[0071] S1, obtain basic software layer variables;
[0072] S2, processes the message signal information and generates RTE layer signal variables;
[0073] S3, processing the message signal information to realize the data conversion between the basic software layer variables and the RTE layer signal variables;
[0074] S4, create interface function file.
[0075] By parsing the DBC file to obtain the message ID, message signal name, signal length, position, coefficient, offset and period, etc., create an interface function for each message in the function file to implement the analysis of the semaphore in the received or sent message or the combination of the message data field, that is, the data conversion between the basic software layer variable and the RTE layer signal variable value, and create the header file of the interface function file at the same time. The logic of data conversion is different in receiving and sending messages. In the received message, a group of ordered data combinations is converted into semaphores according to the byte order, and the combination of data segmentation, selection, shift, multiplication, division, addition and subtraction operations is performed. The calculated semaphore is the RTE layer signal variable, which realizes the data conversion between the basic software layer and the RTE of the received message. The sending message is a similar operation in the opposite direction. These operations are implemented in the interface function file in the form of code. Taking receiving messages as an example, when the RTE layer passes the semaphore obtained by parsing (i.e., the RTE layer signal variable) to the application layer, the application layer also needs to create the corresponding variable object for communication. The simulink model and variable declaration file play this role. Through automatic creation, engineers can create and declare variables in the application layer according to the variables passed up by the RTE layer. In this way, application engineers can directly use variables for logic development in the application layer. Similarly, when sending messages, the simulink model and variable declaration file define the signal variables that the application layer wants to pass to the RTE layer to achieve communication between the two layers. The simulink model is mainly built based on the semaphore transmitted between the application layer and the RTE layer, and the name and number of the signal can be obtained by parsing the DBC. The variable declaration file is a variable declaration for the variables transmitted between the application layer and the RTE layer, which contains information such as the name, limit value, transmission and reception type, and data type of the semaphore.
[0076] See also Figure 5 , is a system for automatic code generation in the present invention, comprising:
[0077] A data analysis module, which is used to analyze the DBC file and obtain message signal information;
[0078] A data acquisition module, which is used to respectively acquire the CAN channel configuration file in the ECU abstraction layer and the arxml files of each module in the service layer;
[0079] A data configuration module, wherein the data configuration module is used to perform function configuration of the Autosar module according to message signal information and files at each level;
[0080] The target code generation module is used to generate target code files for the ECU abstraction layer, the service layer and the RTE layer respectively.
[0081] An embodiment of the present invention provides a terminal device. The terminal device of this embodiment includes: a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the steps in the above-mentioned various code automatic generation method embodiments are implemented. Alternatively, when the processor executes the computer program, the functions of each module / unit in the above-mentioned various device embodiments are implemented.
[0082] The computer program may be divided into one or more modules / units, and the one or more modules / units are stored in the memory and executed by the processor to accomplish the present invention.
[0083] The automatic code generation device / terminal device may be a computing device such as a desktop computer, a notebook, a palm computer, a cloud server, etc. The automatic code generation device / terminal device may include, but is not limited to, a processor and a memory.
[0084] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.
[0085] The memory can be used to store the computer program and / or module, and the processor implements various functions of the automatic code generation device / terminal equipment by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory.
[0086] If the module / unit integrated in the automatic code generation device / terminal device is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present invention implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media does not include electrical carrier signals and telecommunication signals.
[0087] The above are only preferred embodiments of the present invention and are not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for automatic code generation, characterized in that: The following steps are involved: Parse the DBC file to obtain message signal information; Get the CAN channel configuration file in the ECU abstract layer and the arxml files of each module in the service layer respectively; Configure the functions of the Autosar module according to the message signal information and files at each level; Generate target code files for ECU abstraction layer, service layer and RTE layer respectively; The target code file in the ECU abstraction layer is a target configuration file, and the generation of the target configuration file includes the following steps: Get and parse the CAN channel configuration file of the CAN IF module; Get the CAN channel configuration file format requirements; Match the message signal information with the CAN channel configuration file according to the CAN channel configuration file format requirements; Generate target configuration files to realize automatic configuration of CAN channels; The target code file in the service layer is a callback function entity file and a target arxml file, which specifically includes the following steps: Get the arxml file format structure; Get the function name information of the callback function entity in the arxml file; Configure options such as function body return type and parameters; Create a callback function entity file; Configure or change the functions of each module in the service layer; for configuration related to the message, fill the application layer variables into the arxml file; for configuration content unrelated to the message, divide the configuration items into default configuration options, general configuration options and key configuration options according to actual usage, and generate the final arxml file after configuration; Generate the target arxml file according to the arxml file format structure and the functional configuration or changes of each module; The target arxml file and callback function entity file are implemented based on the basic software generated by the Autosar tool; The target code file in the RTE layer is an interface function file, and the generation of the interface function file includes the following steps: Get basic software layer variables; Declare RTE layer signal variables according to the message signal information; Process the message signal information to realize the data conversion between the basic software layer variables and the RTE layer signal variables; Create an interface function file; The message signal information includes a message ID, a message signal name, a signal length, a position, a coefficient, an offset and a period.
2. A system for automatic code generation, characterized in that: include: A data analysis module, which is used to analyze the DBC file and obtain message signal information; A data acquisition module, which is used to respectively acquire the CAN channel configuration file in the ECU abstraction layer and the arxml files of each module in the service layer; A data configuration module, wherein the data configuration module is used to perform function configuration of the Autosar module according to message signal information and files at each level; A target code generation module, wherein the target code generation module is used to generate target code files for the ECU abstraction layer, the service layer, and the RTE layer respectively; The target code file in the ECU abstraction layer is a target configuration file, and the generation of the target configuration file includes the following steps: Get and parse the CAN channel configuration file of the CAN IF module; Get the CAN channel configuration file format requirements; Match the message signal information with the CAN channel configuration file according to the CAN channel configuration file format requirements; Generate target configuration files to realize automatic configuration of CAN channels; The target code file in the service layer is a callback function entity file and a target arxml file, which specifically includes the following steps: Get the arxml file format structure; Get the function name information of the callback function entity in the arxml file; Configure options such as function body return type and parameters; Create a callback function entity file; Configure or change the functions of each module in the service layer; for configuration related to the message, fill the application layer variables into the arxml file; for configuration content unrelated to the message, divide the configuration items into default configuration options, general configuration options and key configuration options according to actual usage, and generate the final arxml file after configuration; Generate the target arxml file according to the arxml file format structure and the functional configuration or changes of each module; The target arxml file and callback function entity file are implemented based on the basic software generated by the Autosar tool; The target code file in the RTE layer is an interface function file, and the generation of the interface function file includes the following steps: Get basic software layer variables; Declare RTE layer signal variables according to the message signal information; Process the message signal information to realize the data conversion between the basic software layer variables and the RTE layer signal variables; Create an interface function file; The message signal information includes a message ID, a message signal name, a signal length, a position, a coefficient, an offset and a period.
3. A device 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 steps of the method according to claim 1 are implemented.
4. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the steps of the method according to claim 1 are implemented.
Citation Information
Patent Citations
Runtime environment generation method oriented to AUTOSAR software architecture
CN107885500A
Method for implementing AUTOSAR software architecture
CN109117121A