File generation method, device, equipment and storage medium based on DBC file

By extracting metadata and class information from DBC files and generating target code files, the problem of low configuration file generation efficiency after DBC file updates is solved, the maintainability and scalability of the code are improved, and the development efficiency and code consistency are enhanced.

CN119316291BActive Publication Date: 2025-09-23DONGFENG MOTOR GRP
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411402727.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-09
Publication Date
2025-09-23
Estimated Expiration
2044-10-09

AI Technical Summary

Technical Problem

Traditional DBC file parsing and data management methods are inefficient and prone to human errors, especially when faced with large amounts of data and different vehicle models. The processing complexity and maintenance difficulty increase significantly, and the script parsing method has poor compatibility and is difficult to modify.

Method used

By extracting metadata from the DBC file, an initial data serialization standard file is generated; class information is extracted from the requirement header file to obtain target class information; the initial data serialization standard file is updated according to the target class information to generate a target data serialization standard file; and finally a target code file is generated.

Benefits of technology

It improves the maintainability and scalability of the code, significantly enhances development efficiency and code consistency, and ensures the compatibility and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119316291B_ABST
    Figure CN119316291B_ABST
Patent Text Reader

Abstract

This application discloses a file generation method, apparatus, device, and storage medium based on a DBC file, relating to the field of intelligent driving technology. The DBC file-based file generation method comprises: extracting metadata from a DBC file and generating an initial data serialization standard file based on the metadata extraction result; extracting class information from a requirement header file to obtain target class information; updating the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; and generating a target code file based on the target data serialization standard file. By separating the DBC metadata extraction, class information extraction, matching, and code generation, the maintainability and scalability of the code are improved, and development efficiency and code consistency are significantly enhanced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of intelligent driving technology, and in particular to a file generation method, apparatus, device, and storage medium based on a DBC file. Background Art

[0002] With the development of new energy vehicle technology, the number of vehicle functions and controllers continues to increase. CAN (Controller Area Network), a highly reliable and stable serial communication protocol, plays a core role in vehicle control systems. However, with the increasing amount of CAN network data and the diversity of message IDs between controllers, traditional message parsing and data management methods have exposed many problems. Manually analyzing DBC (Database CAN) files and writing code is inefficient and prone to human error. Especially when faced with large amounts of data and different vehicle models, the processing complexity and maintenance difficulty increase significantly. In addition, script parsing methods also face problems such as poor compatibility and difficult modifications. Therefore, how to solve the low efficiency of configuration file generation after DBC file updates has become a pressing issue. Summary of the Invention

[0003] The main purpose of this application is to provide a file generation method, device, equipment and storage medium based on DBC files, aiming to solve the technical problem of low efficiency in generating configuration files after the DBC files are updated.

[0004] To achieve the above objectives, the present application proposes a file generation method based on a DBC file, the file generation method based on a DBC file comprising:

[0005] Extract metadata from DBC files and generate initial data serialization standard files based on the metadata extraction results;

[0006] Extract class information from the requirement header file to obtain target class information;

[0007] The initial data serialization standard file is updated according to the target class information to obtain a target data serialization standard file;

[0008] Generate a target code file according to the target data serialization standard file.

[0009] In one embodiment, the step of extracting metadata from the DBC file and generating an initial data serialization standard file based on the metadata extraction result includes:

[0010] Parse the signal data rows in the DBC file to determine the signal definition data;

[0011] Parsing the message data row in the DBC file to determine the message definition data;

[0012] Parsing the annotation data rows in the DBC file to determine target annotation data;

[0013] Parsing the signal value table row in the DBC file to generate an enumeration type;

[0014] Obtaining a metadata extraction result according to the signal definition data, the message definition data, the target annotation data, and the enumeration type;

[0015] An initial data serialization standard file is generated according to the metadata extraction result.

[0016] In one embodiment, the step of updating the initial data serialization standard file according to the target class information to obtain the target data serialization standard file includes:

[0017] Matching the target class information with the protocol data in the initial data serialization standard file;

[0018] The initial data serialization standard file is updated according to the matching result to obtain the target data serialization standard file.

[0019] In one embodiment, the step of updating the initial data serialization standard file according to the matching result to obtain the target data serialization standard file includes:

[0020] When the matching result indicates that there is class information matching the protocol data, the protocol data is updated according to the class name and header file path in the class information to obtain updated protocol data;

[0021] A plurality of signals in the updated protocol data are updated according to the member variable information in the class information to obtain an update result, and a target data serialization standard file is obtained according to the update result.

[0022] In one embodiment, the step of generating a target code file according to the target data serialization standard file includes:

[0023] Extracting information from the target data serialization standard file to obtain target class information, target enumeration information, target method declaration, and target protocol variables;

[0024] Generate an enumeration code according to the template file and the target enumeration information;

[0025] Generate a target header file according to the template file, the target class information and the target method declaration;

[0026] Generate a target source file according to the template file, the target class information and the target protocol variable;

[0027] A target code file is obtained according to the target source file, the target header file and the enumeration code.

[0028] In one embodiment, the step of generating an enumeration code according to the template file and the target enumeration information includes:

[0029] Determine the enumeration definition format according to the template file;

[0030] generating target enumeration content according to the target enumeration information, and determining a target enumeration declaration according to the target enumeration content;

[0031] Generate enumeration code according to the target enumeration declaration and the enumeration definition format.

[0032] In one embodiment, the step of generating a target header file according to the template file, the target class information, and the target method declaration includes:

[0033] Determine the header file definition structure according to the template file;

[0034] Prepare content according to the target class information and the target method declaration to generate multiple formatted values;

[0035] A target header file is generated according to each formatting value and the header file definition structure.

[0036] In addition, to achieve the above-mentioned purpose, the present application also proposes a file generation device based on a DBC file, and the file generation device based on a DBC file includes:

[0037] The extraction module is used to extract metadata from the DBC file and generate an initial data serialization standard file based on the metadata extraction result;

[0038] The extraction module is further used to extract class information from the requirement header file to obtain target class information;

[0039] An updating module, configured to update the initial data serialization standard file according to the target class information to obtain a target data serialization standard file;

[0040] A generation module is used to generate a target code file according to the target data serialization standard file.

[0041] In addition, to achieve the above-mentioned purpose, the present application also proposes a file generation device based on a DBC file, the device comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, the computer program being configured to implement the steps of the file generation method based on a DBC file as described above.

[0042] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium and stores a computer program. When the computer program is executed by a processor, the steps of the file generation method based on the DBC file as described above are implemented.

[0043] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program. When the computer program is executed by a processor, it implements the steps of the file generation method based on the DBC file as described above.

[0044] This application extracts metadata from DBC files and generates an initial data serialization standard file based on the metadata extraction results; extracts class information from the requirement header file to obtain target class information; updates the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; and generates a target code file based on the target data serialization standard file. By separating DBC metadata extraction, class information extraction, matching, and code generation, the maintainability and extensibility of the code are improved, and development efficiency and code consistency are significantly enhanced. BRIEF DESCRIPTION OF THE DRAWINGS

[0045] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without any creative work.

[0047] Figure 1 A flowchart of the first embodiment of the method for generating a file based on a DBC file is provided in this application;

[0048] Figure 2 A flowchart of the second embodiment of the method for generating a file based on a DBC file is provided in this application;

[0049] Figure 3This is a schematic diagram of the module structure of the file generation device based on DBC files in an embodiment of the present application;

[0050] Figure 4 Schematic diagram of the device structure of the hardware operating environment involved in the file generation method based on DBC files in the embodiment of the present application.

[0051] The purpose, features and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0052] It should be understood that the specific embodiments described herein are merely used to explain the technical solutions of the present application and are not intended to limit the present application.

[0053] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0054] The main solution of the embodiment of the present application is: extract metadata from the DBC file and generate an initial data serialization standard file based on the metadata extraction result; extract class information from the demand header file to obtain target class information; update the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; generate a target code file based on the target data serialization standard file.

[0055] With the development of new energy vehicle technology, the number of vehicle functions and controllers continues to increase. CAN (Controller Area Network), a highly reliable and stable serial communication protocol, plays a core role in vehicle control systems. However, with the increasing amount of CAN network data and the diversity of message IDs between controllers, traditional message parsing and data management methods have exposed many problems. Manually analyzing DBC (Database CAN) files and writing code is inefficient and prone to human error. Especially when faced with large amounts of data and different vehicle models, the processing complexity and maintenance difficulty increase significantly. In addition, script parsing methods also face problems such as poor compatibility and difficult modifications. Therefore, how to solve the low efficiency of configuration file generation after DBC file updates has become a pressing issue.

[0056] This application extracts metadata from DBC files and generates an initial data serialization standard file based on the metadata extraction results; extracts class information from the requirement header file to obtain target class information; updates the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; and generates a target code file based on the target data serialization standard file. By separating DBC metadata extraction, class information extraction, matching, and code generation, the maintainability and extensibility of the code are improved, and development efficiency and code consistency are significantly enhanced.

[0057] It should be noted that the execution entity of this embodiment can be a computing service device with data processing, network communication, and program execution capabilities, such as a tablet computer, personal computer, or mobile phone, or a DBC file-based file generation device capable of implementing the aforementioned functions. This embodiment and the following embodiments will be described below using a DBC file-based file generation device as an example execution entity.

[0058] Based on this, the embodiment of the present application provides a file generation method based on DBC file, referring to Figure 1 , Figure 1 This is a flowchart of the first embodiment of the file generation method based on DBC files of this application.

[0059] In this embodiment, the file generation method based on the DBC file includes steps S10 to S40:

[0060] Step S10, extracting metadata from the DBC file and generating an initial data serialization standard file based on the metadata extraction result;

[0061] It should be noted that this embodiment is mainly used to parse DBC files and automatically generate C++ code that can be directly used in the communication framework. This embodiment is a key tool in the development of communication frameworks in the field of intelligent driving. By reading parameters (such as DBC file path, protocol configuration, car type, etc.) from the configuration file, the program can flexibly adapt to different needs. It adopts a modular design, and separates DBC metadata extraction, class information extraction, matching and code generation, which improves the maintainability and scalability of the code. This method not only supports the processing of multiple files in a single file and directory, but also automatically matches the modules in the communication framework, generates C++ code consistent with the communication framework, significantly improves development efficiency and code consistency, and ensures the compatibility and reliability of the system. Among them, this embodiment is mainly divided into three modules: 1. DBC metadata extraction; 2. Class information extraction and yaml file update; 3. Automatic code generation.

[0062] It can be understood that the metadata extraction result refers to the result of whether the metadata extraction is successful, the initial data serialization standard file refers to the initial yaml file, and the DBC file (CAN Database File) is used to describe and define the standard file format of controller area network (CAN) messages and signals in the vehicle communication system.

[0063] In the specific implementation, the DBC file is parsed to extract the information defined by the standard signal, the information defined by the message, as well as the annotations and the numerical table, and then determine whether the metadata extraction is successful, that is, obtain the metadata extraction result. Finally, when the metadata extraction result is a successful result, the initial data serialization standard file (yaml file) is generated according to the extracted metadata.

[0064] In a feasible implementation, step S10 may include steps A11 to A16:

[0065] Step A11, parsing the signal data row in the DBC file to determine the signal definition data;

[0066] It can be understood that the signal data row refers to the SG_ row in the DBC file, which is used to extract the standard signal definition information. The signal definition data includes the signal name, position, length, offset, data order, whether it is signed, precision, physical range and unit, etc.

[0067] In practice, the SG_ line in the DBC file is parsed to extract standard signal definition information. This information includes the signal name, location, length, offset, data order, signedness, precision, physical range, and units. Based on the signal's length and range, its data type (e.g., bool, float, double, int, uint, etc.) is determined. Extended signal definitions (specific to certain signals, such as corner radar) in the SG_ line are also parsed.

[0068] Step A12, parsing the message data row in the DBC file to determine the message definition data;

[0069] It is understandable that the message data row refers to the BO_ row in the DBC file, which is used to extract message definition information. The message definition data includes message ID, name, sender and other information.

[0070] In practice, the BO_ line in the DBC file is parsed to extract message definition information. Information such as the message ID, name, and sender is extracted. If the ID is in the blacklist, an empty dictionary is returned. The SG_ line is parsed to add signal data to the current protocol. Depending on the signal length and whether it is an extended signal, the corresponding parsing method is called. If non-signal data is encountered and the current protocol contains signals, the protocol is added to the predefined dictionary and the protocol is reset.

[0071] Step A13: parsing the annotation data rows in the DBC file to determine target annotation data;

[0072] It can be understood that the annotation data row refers to the CM_ row in the DBC file, which is used to add descriptive text. These texts can be descriptions or comments on objects defined in the database (such as messages, signals, etc.). The target annotation data refers to the description or comment data of the signal.

[0073] In a specific implementation, the annotation data in the CM_ line in the DBC file is parsed to obtain the description or comment data of the signal, so as to add the annotation to the description field of the corresponding signal.

[0074] Step A14, parsing the signal value table row in the DBC file to generate an enumeration type;

[0075] As you can understand, an enumeration type is a user-defined data type consisting of a set of named constants that typically represent a series of related integer values. In the context of DBC files, enumeration types are often used to explain the meaning of signal values, making the values ​​easier to understand.

[0076] In practice, the VAL_ line in a DBC file defines a signal's value mapping table, mapping the signal's numeric value to a meaningful enumeration value. This helps improve readability and maintainability, especially when dealing with discrete-valued signals, such as status codes and error codes. The signal value table in the VAL_ line is then parsed to define an enumeration type for the signal, generating the enumeration type and adding it to the protocol.

[0077] Step A15, obtaining a metadata extraction result according to the signal definition data, the message definition data, the target annotation data, and the enumeration type;

[0078] In a specific implementation, the standard signal definition information, message definition information, annotation data, and enumeration types extracted from the DBC file are summarized to obtain metadata extraction results based on the extraction results of each data.

[0079] Step A16: Generate an initial data serialization standard file based on the metadata extraction result.

[0080] In practice, the DBC file is parsed and generated into a YAML file. The DBC file is read, parsed line by line, and the data is extracted. The parsed protocol is processed to ensure that signal names do not conflict with C++ reserved keywords (such as minor and major). A configuration dictionary containing the vehicle type and protocol data is generated and saved to the YAML file. Statistics of the parsing results are printed.

[0081] Step S20, extracting class information from the requirement header file to obtain target class information;

[0082] It can be understood that the required header file refers to the C++ header file in the communication framework, and the target class information includes information about the class and member variables.

[0083] In the specific implementation, the class information extraction module matches the communication framework generated by the AUTOSAR AP configuration and extracts class information from the C++ header file in the communication framework, that is, obtains the information of the class and member variables.

[0084] Step S30, updating the initial data serialization standard file according to the target class information to obtain a target data serialization standard file;

[0085] It can be understood that the target data serialization standard file refers to the updated initial data serialization standard file.

[0086] In the implementation, class information is extracted from the C++ header files in the communication framework and then combined with the protocol data in the existing YAML file. First, the C++ header files in the specified directory are scanned to extract class and member variable information. This information is then applied to the YAML configuration file, updating the corresponding class name, header file path, and member variables for each protocol message. Finally, the target data serialization standard file is generated.

[0087] In a feasible implementation, step S30 may include steps A31 to A32:

[0088] Step A31, matching the target class information with the protocol data in the initial data serialization standard file;

[0089] It is understood that protocol data refers to various information describing a communication protocol, including but not limited to message format, signal definition, signal range, signal type, signal value mapping, etc.

[0090] In the specific implementation, the existing YAML configuration file is read and parsed into an object. The protocol data (protocols) in the YAML file are traversed, and each protocol is matched with the class information extracted from the C++ header file.

[0091] Step A32: updating the initial data serialization standard file according to the matching result to obtain a target data serialization standard file.

[0092] It's understood that the match result refers to whether the class information successfully matches the protocol data. First, a matching class name is searched for based on the protocol name. If no suitable match is found, a default or other specific class name is selected based on some rules for the protocol ID and name. The class_name and header fields in the protocol are updated to include the corresponding class information. The vars field in the protocol is further updated to attempt to match member variable names and add the memvar and memvar_type attributes to them (if a matching member variable is found). The updated content is written back to the YAML file.

[0093] In a feasible implementation, step A32 may include steps B321 to B322:

[0094] Step B321: When the matching result indicates that class information matching the protocol data exists, the protocol data is updated according to the class name and header file path in the class information to obtain updated protocol data;

[0095] It can be understood that when the matching result is that there is class information that matches the protocol data, it indicates that there is a class name that matches the protocol name, and then the class_name and header fields in the protocol are updated according to the matching class name and header file path to include the corresponding class information, and finally the updated protocol data is obtained.

[0096] Step B322: Update multiple signals in the updated protocol data according to the member variable information in the class information to obtain an update result, and obtain a target data serialization standard file according to the update result.

[0097] It can be understood that the vars field in the protocol is updated according to the member variable information in the class information, an attempt is made to match the member variable name, and memvar and memvar_type attributes are added to it (if a matching member variable is found). Finally, the updated content is written back to the YAML file to obtain the target data serialization standard file.

[0098] It should be noted that the module that extracts class information and updates the YAML file is used to match the communication framework generated by the AUTOSAR AP configuration. It extracts class information from the C++ header files in the communication framework and combines this information with the protocol data in the existing YAML file. First, the C++ header files in the specified directory are scanned to extract class and member variable information. Next, this information is applied to the YAML configuration file, updating the corresponding class name, header file path, and member variables for each protocol message. This process ensures that the data in the C++ class and configuration file can be correctly paired and used during code generation or other processing. This module mainly includes two steps: extracting class information (extract_class_info) and extract_class_info_in_dir) and updating the YAML file (update_output_yml).

[0099] As you can understand, extract_class_info: Iterates through all files in the msg_dir directory, extracting class information. It extracts two specific classes (FrontCornerRadarObjectsArray and RearCornerRadarObjectsArray) and adds their information to a defined dictionary. The information for these two classes is hard-coded, and their paths and class member variables are defined directly in this method. extract_class_info_in_dir: Iterates through all files and subdirectories in the specified directory. For each class, it extracts its public member variables and their types from its attributes and stores this information in a predefined dictionary. If the directory is a directory, this method is recursively called to process files in subdirectories.

[0100] It should be understood that updating the YAML file: update_output_yml method: Reads the existing YAML configuration file and parses it into an object. It traverses the protocol data (protocols) in the YAML file and tries to match each protocol with the class information extracted from the C++ header file: First, it searches for a matching class name based on the protocol name. If no suitable match is found, a default class name or other specific class name is selected based on some rules for the protocol ID and name. The class_name and header fields in the protocol are updated to include the corresponding class information. The vars field in the protocol is further updated, trying to match the member variable name and adding the memvar and memvar_type attributes to it (if a matching member variable is found). The updated content is written back to the YAML file.

[0101] It's important to note that the module for extracting class information and updating YAML files extracts class and member variable information from C++ header files, helping to generate or configure code related to these classes and ensuring accurate code generation or configuration. Updating the class names and member variable information from the protocol data into the YAML file enhances the integrity and accuracy of the protocol data. This helps ensure that the protocol data is consistent with the actual C++ classes and code, facilitating subsequent integration and development. Providing the required class information for code generation or further configuration enables seamless integration of protocol data with existing C++ codebases.

[0102] Step S40: Generate a target code file according to the target data serialization standard file.

[0103] It's understood that the target code file refers to the C++ code directly usable within the communication framework. This code is then generated based on the updated data serialization standard file. Specifically, this involves extracting information from the protocol configuration, generating parsing functions, handling multiplexers, selecting different code templates based on class names, and writing the generated code to a file. This automated source code generation significantly reduces manual coding workload and ensures the consistency and correctness of protocol parsing logic.

[0104] This embodiment extracts metadata from a DBC file and generates an initial data serialization standard file based on the metadata extraction results; extracts class information from a requirement header file to obtain target class information; updates the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; and generates a target code file based on the target data serialization standard file. By separating DBC metadata extraction, class information extraction, matching, and code generation, this improves code maintainability and extensibility, and significantly enhances development efficiency and code consistency.

[0105] Based on the first embodiment of the present application, in the second embodiment of the present application, the same or similar contents as those in the above embodiment 1 can be referred to the above introduction and will not be described in detail later. Figure 2 In the DBC file-based file generation method, step S40 further includes steps S41 to S45:

[0106] Step S41, extracting information from the target data serialization standard file to obtain target class information, target enumeration information, target method declaration, and target protocol variables;

[0107] It can be understood that the target class information refers to the class definition information, the target enumeration information includes the enumeration name, enumeration variables and their values, the target method declaration refers to the class and method declaration related to the protocol, and the target protocol variable refers to all variables in the protocol.

[0108] In a specific implementation, information is extracted from the updated data serialization standard file to obtain class definition information, enumeration names, enumeration variables and their values, class and method declarations related to the protocol, and all variables in the protocol.

[0109] Step S42, generating an enumeration code according to the template file and the target enumeration information;

[0110] In practice, the template file defines classes related to intelligent driving sensors. The template file reads FMT variables and defines the overall format of enumerations. This file then combines the target enumeration information to generate enumeration code, converting the enumeration information in the protocol configuration into enumeration definitions in the C++ header file. By parsing the enumeration definitions in the protocol configuration file, the code generates a header file containing all enumeration definitions, enabling other C++ code to use these enumeration types.

[0111] It should be noted that setting up a template file defines the classes related to intelligent driving sensors, including header files, namespaces, class definitions, constructors, member functions, etc. Placeholders are used in the template file to define each part, which will be replaced by specific content when the actual code is generated.

[0112] In a feasible implementation, step S42 may include steps A421 to A423:

[0113] Step A421, determining the enumeration definition format according to the template file;

[0114] It is understood that the enumeration definition format refers to the overall format of the enumeration, wherein the FMT variable is read from the template file and defines the overall format of the enumeration.

[0115] Step A422: generating target enumeration content according to the target enumeration information, and determining a target enumeration declaration according to the target enumeration content;

[0116] It can be understood that the target enumeration content refers to the name and value pairs of the enumeration variables, and the target enumeration declaration refers to the declaration of each enumeration value.

[0117] In practice, a predefined dictionary of record namespaces is traversed to obtain each namespace and its corresponding enumeration list. For each enumeration name, the corresponding enumeration string (enum_str) is obtained, from which the enumeration variables and their values ​​are parsed. enumVariableList stores the name and value pairs of the enumeration variables, generating the enumeration definition in C++ by splitting and processing the string. enum_declare_list is used to store the declaration of each enumeration value, in the format of "<enumeration value name> = <value>". Ultimately, all enumeration definitions are concatenated to form a complete enumeration type definition.

[0118] Step A423: Generate enumeration code according to the target enumeration declaration and the enumeration definition format.

[0119] It can be understood that the enumeration code is generated according to the overall format of the enumeration and the enumeration name, enumeration variables and their values. Specifically, the report_enum_file file is opened in write mode using the open function, and the generated enumeration content is written therein, that is, the enumeration code is generated.

[0120] It should be noted that the enumeration code is generated using the generate_enum_code method. This step is mainly divided into the following functions: Directory and file name settings: can_type: extract the file name (excluding the extension) from the path of the protocol configuration file to generate the final enumeration file name. report_enum_file: save path of the enumeration type header file, the file name is<can_type> _signal_type.h. vehicle_signal_type_tbl_file: Template file path, used to generate code for the enumeration type. Template format: The FMT variable is read from the template file and defines the overall format of the enumeration. Generate enumeration content: Traverse the predefined dictionary of record namespaces, obtain each namespace and its corresponding enumeration list. For each enumeration name, obtain the corresponding enumeration string (enum_str), and parse the enumeration variables and their values ​​from it. enumVariableList stores the name and value pairs of the enumeration variables, and generates the enumeration definition in C++ by splitting and processing the string. Generate enumeration declaration: enum_declare_list is used to store the declaration of each enumeration value, in the format "<enumeration value name> = <value>". Ultimately, all enumeration definitions are concatenated to form a complete enumeration type definition. Write to file: Use the open function to open the report_enum_file file in write mode and write the generated enumeration content to it. This method converts the enumeration information in the protocol configuration into the enumeration definition in the C++ header file. By parsing the enumeration definitions in the protocol configuration file, the code generates a header file containing all the enumeration definitions, allowing other C++ code to use these enumeration types. This is very beneficial for projects that need to automatically generate C++ code from configuration files, especially when dealing with a large number of enumerations and protocols, which can greatly improve work efficiency.

[0121] Step S43, generating a target header file according to the template file, the target class information and the target method declaration;

[0122] It is understood that the target header file refers to the C++ header file, which contains the class and method declarations related to the protocol. The file is generated based on the given protocol configuration, formatted according to the preset template and written to the file.

[0123] In a feasible implementation, step S43 may include steps A431 to A433:

[0124] Step A431, determining a header file definition structure according to the template file;

[0125] It can be understood that the header file definition structure refers to the template file path for generating the header file.

[0126] In a specific implementation, the template file specifies a template file path (template / report_protocol.h.tpl) for generating a header file, and generates a file path: generating a final header file path according to the protocol name.

[0127] Step A432: Prepare content based on the target class information and the target method declaration to generate multiple formatted values;

[0128] It is understood that the formatted value includes lowercase and uppercase forms of the vehicle type, uppercase form of the protocol name, and uppercase form of the first letter of the protocol name.

[0129] In the implementation, multiple formatted values ​​are generated based on the class definition information, class and method declarations associated with the protocol. Specifically, the formatted values ​​(fmt_val) are prepared: car_type_lower and car_type_upper: the lowercase and uppercase forms of the vehicle type, respectively; protocol_name_upper: the uppercase form of the protocol name; classname: the uppercase first letter of the protocol name; fullclassname: the full class name determined by the class_name key in the protocol. If class_name does not exist, it is set to "Unknown"; varname: the file name (excluding the extension) extracted from the path of the protocol configuration file; header: the included header file is set according to the header key in the protocol, or empty if it does not exist.

[0130] Step A433: Generate a target header file according to each formatting value and the header file definition structure.

[0131] It can be understood that all formatting values ​​are applied to the template to generate the final header file content, and the generated header file content is written to the specified file path, and finally the C++ header file is obtained.

[0132] It should be noted that: (1) Template and file settings, template file: specifies the template file path (template / report_protocol.h.tpl) used to generate the header file. Generate file path: Generate the final header file path based on the protocol name; (2) Initialize template formatting content, read template format: read the formatting content from the template file, which determines the overall structure of the header file; (3) Prepare formatted content, prepare formatted values ​​(fmt_val): car_type_lower and car_type_upper: lowercase and uppercase forms of the vehicle type, respectively. protocol_name_upper: uppercase form of the protocol name. classname: uppercase form of the first letter of the protocol name. fullclassname: Determine the full name of the class based on the class_name key value in the protocol. If class_name does not exist, set it to "Unknown". varname: Extract the file name (excluding the extension) from the path of the protocol configuration file. header: Sets the included header file based on the header key value in the protocol, or leaves it empty if it doesn't exist. ⑷ Generates method declarations, iterates through the variables in the protocol: Generates a method declaration for each variable and adds it to the method declaration list (func_declare_list). If the variable type is enum, it is processed as a combination of the protocol name and the variable name. Generates function declarations: Generates function declarations for each variable, with a format that includes configuration details and the method's return type. ⑸ Processes enumeration types, collects enumeration types: Iterates through the variable list, searching for variables of type enum. Generates the corresponding enumeration name and adds it to the enumeration name list (enum_name_list). Stores the enumeration definition in self.enum2enumstr. Updates the enumeration namespace: If an enumeration type exists, associates it with the protocol name and generates the corresponding enumeration header file path (enumheader). ⑹ Writes to file, formats the content: Apply all formatting values ​​to the template to generate the final header file content. Writes to file: Writes the generated header file content to the specified file path. This step combines the information in the protocol configuration (such as vehicle type, protocol name, method, and parameters) with predefined templates to generate a C++ header file containing class and method declarations. This header file defines the protocol-related interface and includes any required enumeration types. This automated code generation helps ensure consistency between the protocol and the code, improving development efficiency.

[0133] Step S44, generating a target source file according to the template file, the target class information and the target protocol variables;

[0134] It can be understood that the target source file refers to a C++ source file (.cc file), which is used to implement the parsing logic of a specific protocol. The code uses a template to generate C++ code with specific implementation details based on the provided protocol configuration information.

[0135] It should be noted that: ⑴ Initialize the template and file path, template file: specifies the template path for generating the C++ source file (template / report_protocol.cc.tpl). Generate file path: Generate the path of the C++ source file based on the protocol name; ⑵ Prepare formatted data, basic formatting value (fmt_val): car_type_lower: lowercase form of the vehicle type. protocol_name_lower: lowercase form of the protocol name. varname: The file name extracted from the protocol configuration file path (excluding the extension). classname: The first letter of the protocol name is capitalized. fullclassname: The full class name set according to the class_name key value in the protocol (if not, it is set to "Unknown"). Protocol ID: Convert the protocol ID to uppercase and decide whether to generate an extended ID based on its value; ⑶ Process protocol variables, function declaration generation: traverse the variables in the protocol, generate the corresponding function implementation for each variable, and store it in the function implementation list (func_impl_list). ⑷ Handle variables of enum type and format the return type of the function; ⑷ Handle multiplexers (Multiplexor) and detect multiplexers: If a multiplexer is found (via variable name inspection), generate the relevant switch statement. Generate multiplexer-related code: If there is a multiplexer in the protocol, generate the corresponding code block based on the configuration and add it to the protocol processing list; ⑸ Generate variable assignment code and process each variable: Based on the type and configuration of the protocol variable, generate code to set the parsed value to the corresponding object member variable. Handle special cases, such as special logic related to the Fradar_obj, Flr_, and Rlr_ class names. Generate and add code lines to the set_var_to_protocol_list list. These code lines assign the variable value to the member variable of the protocol object; ⑹ Select templates based on class names: Select templates based on class names (such as Fradar_obj, Flr_, Rlr_) and generate the corresponding code. Generate a corresponding code snippet for each specific type of protocol object and add it to set_var_to_protocol_list; ⑺Write the generated file and format the final content: use the template and the previously prepared formatted value to generate the final C++ source file content, write to the file: write the generated content to the specified C++ source file.

[0136] Step S45: Obtain a target code file according to the target source file, the target header file, and the enumeration code.

[0137] In a specific implementation, the C++ source files, C++ header files, and generated enumeration codes are aggregated to obtain C++ codes that can be directly used in the communication framework.

[0138] This embodiment extracts information from the target data serialization standard file to obtain target class information, target enumeration information, target method declarations, and target protocol variables; generates enumeration code based on a template file and the target enumeration information; generates a target header file based on the template file, the target class information, and the target method declarations; generates a target source file based on the template file, the target class information, and the target protocol variables; and obtains a target code file based on the target source file, the target header file, and the enumeration code. This approach reduces the workload of manual coding and ensures the consistency and correctness of protocol parsing logic.

[0139] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the file generation method based on DBC files of the present application. More simple transformations based on this technical concept are all within the scope of protection of the present application.

[0140] This application also provides a file generation device based on DBC file, please refer to Figure 3 , the file generation device based on DBC file includes:

[0141] The extraction module 10 is used to extract metadata from the DBC file and generate an initial data serialization standard file based on the metadata extraction result;

[0142] The extraction module 10 is further used to extract class information from the demand header file to obtain target class information;

[0143] An updating module 20 is configured to update the initial data serialization standard file according to the target class information to obtain a target data serialization standard file;

[0144] The generating module 30 is configured to generate a target code file according to the target data serialization standard file.

[0145] Optionally, the extraction module 10 is further configured to:

[0146] Parse the signal data rows in the DBC file to determine the signal definition data;

[0147] Parsing the message data row in the DBC file to determine the message definition data;

[0148] Parsing the annotation data rows in the DBC file to determine target annotation data;

[0149] Parsing the signal value table row in the DBC file to generate an enumeration type;

[0150] Obtaining a metadata extraction result according to the signal definition data, the message definition data, the target annotation data, and the enumeration type;

[0151] An initial data serialization standard file is generated according to the metadata extraction result.

[0152] Optionally, the updating module 20 is further configured to:

[0153] Matching the target class information with the protocol data in the initial data serialization standard file;

[0154] The initial data serialization standard file is updated according to the matching result to obtain the target data serialization standard file.

[0155] Optionally, the updating module 20 is further configured to:

[0156] When the matching result indicates that there is class information matching the protocol data, the protocol data is updated according to the class name and header file path in the class information to obtain updated protocol data;

[0157] A plurality of signals in the updated protocol data are updated according to the member variable information in the class information to obtain an update result, and a target data serialization standard file is obtained according to the update result.

[0158] Optionally, the generating module 30 is further configured to:

[0159] Extracting information from the target data serialization standard file to obtain target class information, target enumeration information, target method declaration, and target protocol variables;

[0160] Generate an enumeration code according to the template file and the target enumeration information;

[0161] Generate a target header file according to the template file, the target class information and the target method declaration;

[0162] Generate a target source file according to the template file, the target class information and the target protocol variable;

[0163] A target code file is obtained according to the target source file, the target header file and the enumeration code.

[0164] Optionally, the generating module 30 is further configured to:

[0165] Determine the enumeration definition format according to the template file;

[0166] generating target enumeration content according to the target enumeration information, and determining a target enumeration declaration according to the target enumeration content;

[0167] Generate enumeration code according to the target enumeration declaration and the enumeration definition format.

[0168] Optionally, the generating module 30 is further configured to:

[0169] Determine the header file definition structure according to the template file;

[0170] Prepare content according to the target class information and the target method declaration to generate multiple formatted values;

[0171] A target header file is generated according to each formatting value and the header file definition structure.

[0172] The DBC file-based file generation device provided in this application utilizes the DBC file-based file generation method described in the aforementioned embodiments, thereby resolving the technical issue of inefficient configuration file generation after a DBC file is updated. Compared to the prior art, the DBC file-based file generation device provided in this application offers the same beneficial effects as the DBC file-based file generation method described in the aforementioned embodiments. Other technical features of the DBC file-based file generation device are the same as those disclosed in the aforementioned embodiments and are not further elaborated upon here.

[0173] The present application provides a file generation device based on a DBC file, and the file generation device based on a DBC file includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the file generation method based on the DBC file in the above-mentioned embodiment 1.

[0174] Reference below Figure 4, which shows a schematic structural diagram of a DBC file-based file generation device suitable for implementing embodiments of the present application. The DBC file-based file generation device in the embodiments of the present application may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Descriptions), PMPs (Portable Media Players), and in-vehicle terminals (e.g., in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Figure 4 The DBC file-based file generation device shown is merely an example and should not limit the functions and scope of use of the embodiments of the present application.

[0175] like Figure 4 As shown, the DBC file-based file generation device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes based on a program stored in a read-only memory (ROM) 1002 or a program loaded from a storage device 1003 into a random access memory (RAM) 1004. Various programs and data required for the operation of the DBC file-based file generation device are also stored in RAM 1004. Processing device 1001, ROM 1002, and RAM 1004 are connected to each other via a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, touchpad, keyboard, mouse, image sensor, microphone, accelerometer, gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), speaker, vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, hard disk, etc.; and a communication device 1009. The communication device 1009 can allow the DBC file-based file generation device to communicate with other devices wirelessly or by wire to exchange data. Although the figure shows a DBC file-based file generation device with various systems, it should be understood that it is not required to implement or have all of the systems shown. More or fewer systems may be implemented or have instead.

[0176] In particular, according to the embodiments disclosed in the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments disclosed in the present application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program comprising program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0177] The DBC file-based file generation device provided in this application utilizes the DBC file-based file generation method of the aforementioned embodiment, thereby resolving the technical issue of inefficient configuration file generation after a DBC file is updated. Compared to the prior art, the DBC file-based file generation device provided in this application achieves the same beneficial effects as the DBC file-based file generation method of the aforementioned embodiment. Other technical features of the DBC file-based file generation device are the same as those disclosed in the aforementioned embodiment and are not further elaborated upon here.

[0178] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0179] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.

[0180] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer program) stored thereon, wherein the computer-readable program instructions are used to execute the file generation method based on the DBC file in the above embodiment.

[0181] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.

[0182] The computer-readable storage medium may be included in the file generation device based on the DBC file; or may exist independently without being assembled into the file generation device based on the DBC file.

[0183] The above-mentioned computer-readable storage medium carries one or more programs. When the above-mentioned one or more programs are executed by a file generation device based on a DBC file, the file generation device based on the DBC file: extracts metadata from the DBC file and generates an initial data serialization standard file based on the metadata extraction result; extracts class information from the demand header file to obtain target class information; updates the initial data serialization standard file based on the target class information to obtain a target data serialization standard file; and generates a target code file based on the target data serialization standard file.

[0184] Computer program code for performing the operations of the present application may be written in one or more programming languages, or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a stand-alone software package, partially on the user's computer and partially on a remote computer, or entirely on the remote computer or server. In cases involving a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0185] The flow charts and block diagrams in the accompanying drawings illustrate the possible architecture, functions and operations of the systems, methods and computer program products according to various embodiments of the present application. In this regard, each box in the flow chart or block diagram can represent a module, program segment or a part of code, and the module, program segment or a part of code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than that marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flow chart, and the combination of the boxes in the block diagram and / or flow chart can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.

[0186] The modules described in the embodiments of the present application may be implemented in software or hardware, wherein the name of a module does not necessarily limit the unit itself.

[0187] The computer-readable storage medium provided in this application stores computer-readable program instructions (i.e., a computer program) for executing the aforementioned method for generating a file based on a DBC file. This computer-readable storage medium can address the technical issue of inefficient configuration file generation after a DBC file is updated. Compared to the prior art, the beneficial effects of the computer-readable storage medium provided in this application are similar to those of the method for generating a file based on a DBC file provided in the aforementioned embodiment, and are not further elaborated here.

[0188] The present application also provides a computer program product, including a computer program, which implements the steps of the above-mentioned file generation method based on the DBC file when executed by a processor.

[0189] The computer program product provided by this application can solve the technical problem of low efficiency in generating configuration files after updating a DBC file. Compared with the prior art, the beneficial effects of the computer program product provided by this application are the same as those of the DBC file-based file generation method provided in the above embodiment, and will not be elaborated here.

[0190] The above description is only part of the embodiments of the present application and does not limit the patent scope of the present application. All equivalent structural transformations made by using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect application in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A file generation method based on DBC file, characterized in that: The file generation method based on the DBC file includes: Extract metadata from DBC files and generate initial data serialization standard files based on the metadata extraction results; Extract class information from the requirement header file to obtain target class information; The initial data serialization standard file is updated according to the target class information to obtain a target data serialization standard file; Generate a target code file according to the target data serialization standard file.

2. The method according to claim 1, wherein The steps of extracting metadata from the DBC file and generating an initial data serialization standard file according to the metadata extraction result include: Parse the signal data rows in the DBC file to determine the signal definition data; Parsing the message data row in the DBC file to determine the message definition data; Parsing the annotation data rows in the DBC file to determine target annotation data; Parsing the signal value table row in the DBC file to generate an enumeration type; Obtaining a metadata extraction result according to the signal definition data, the message definition data, the target annotation data, and the enumeration type; An initial data serialization standard file is generated according to the metadata extraction result.

3. The method according to claim 1, wherein The step of updating the initial data serialization standard file according to the target class information to obtain the target data serialization standard file includes: Matching the target class information with the protocol data in the initial data serialization standard file; The initial data serialization standard file is updated according to the matching result to obtain the target data serialization standard file.

4. The method according to claim 3, wherein The step of updating the initial data serialization standard file according to the matching result to obtain the target data serialization standard file includes: When the matching result indicates that there is class information matching the protocol data, the protocol data is updated according to the class name and header file path in the class information to obtain updated protocol data; A plurality of signals in the updated protocol data are updated according to the member variable information in the class information to obtain an update result, and a target data serialization standard file is obtained according to the update result.

5. The method according to claim 1, wherein The step of generating a target code file according to the target data serialization standard file comprises: Extracting information from the target data serialization standard file to obtain target class information, target enumeration information, target method declaration, and target protocol variables; Generate an enumeration code according to the template file and the target enumeration information; Generate a target header file according to the template file, the target class information and the target method declaration; Generate a target source file according to the template file, the target class information and the target protocol variable; A target code file is obtained according to the target source file, the target header file and the enumeration code.

6. The method according to claim 5, wherein The step of generating an enumeration code according to the template file and the target enumeration information includes: Determine the enumeration definition format according to the template file; generating target enumeration content according to the target enumeration information, and determining a target enumeration declaration according to the target enumeration content; Generate enumeration code according to the target enumeration declaration and the enumeration definition format.

7. The method according to claim 5, wherein The step of generating a target header file according to the template file, the target class information and the target method declaration comprises: Determine the header file definition structure according to the template file; Prepare content according to the target class information and the target method declaration to generate multiple formatted values; A target header file is generated according to each formatting value and the header file definition structure.

8. A file generation device based on DBC file, characterized in that: The device comprises: The extraction module is used to extract metadata from the DBC file and generate an initial data serialization standard file based on the metadata extraction result; The extraction module is further used to extract class information from the requirement header file to obtain target class information; An updating module, configured to update the initial data serialization standard file according to the target class information to obtain a target data serialization standard file; A generation module is used to generate a target code file according to the target data serialization standard file.

9. A file generation device based on DBC file, characterized in that: The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the method for generating a file based on a DBC file according to any one of claims 1 to 7.

10. A storage medium, characterized in that: The storage medium is a computer-readable storage medium. A computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the file generation method based on the DBC file according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • Code generation system and method

    CN110196715A

  • Code updating method and device for vehicle-mounted controller software, equipment and medium

    CN114780126A