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

By extracting metadata and extracting class information of DBC files and generating object code files, the problem of low configuration file generation efficiency after DBC file update is solved, the code maintainability and development efficiency are improved, and the system compatibility is ensured. reliability.

CN119316291AActive Publication Date: 2025-01-14DONGFENG MOTOR GRP

Patent Information

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

AI Technical Summary

Technical Problem

After the DBC file is updated, traditional methods generate configuration files inefficiently, prone to human errors, poor compatibility, and troublesome modification. Especially in the face of large amounts of data and different models, the processing complexity and maintenance difficulty have increased significantly.

Method used

By extracting metadata from the DBC file, the initial data serialization standard file is generated; extracting the demand header file class information to obtain the target class information; updating the initial data serialization standard file based on the target class information to obtain the target data serialization standard file to obtain the target data serialization Standard file; finally, the target code file is generated based on the target data serialization standard file, and DBC metadata extraction, class information extraction, matching and code generation are processed separately.

Benefits of technology

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

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119316291A_ABST
    Figure CN119316291A_ABST
Patent Text Reader

Abstract

The invention discloses a file generation method and device based on a DBC file, equipment and a storage medium, and relates to the technical field of intelligent driving, and the file generation method based on the DBC file comprises the steps of performing metadata extraction on the DBC file, and generating an initial data serialization standard file according to a metadata extraction result; performing class information extraction on the demand header file to obtain target class information; updating the initial data serialization standard file according to the target class information to obtain a target data serialization standard file; and generating a target code file according to the target data serialization standard file. DBC metadata extraction, class information extraction, matching and code generation are separately processed, so that the maintainability and expansibility of codes are improved, and the development efficiency and the code consistency are remarkably improved.
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, device, equipment 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), as a highly reliable and stable serial communication protocol, plays a core role in vehicle control systems. However, with the increase in the amount of CAN network data and the diversity of message IDs between controllers, traditional message parsing and data management methods have exposed many problems. The method of manually analyzing DBC (Database CAN) files and writing codes is inefficient and prone to human errors. Especially in the face of large amounts of data and different vehicle models, the processing complexity and maintenance difficulty are significantly increased. In addition, the script parsing method also faces problems such as poor compatibility and troublesome modifications. Therefore, how to solve the low efficiency of generating configuration files after the DBC file is updated has become an urgent problem to be solved. Summary of the invention

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

[0004] To achieve the above purpose, the present application proposes a file generation method based on a DBC file, and the file generation method based on a DBC file includes:

[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 according to 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 row in the DBC file to determine the 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 is 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] Generate target enumeration content according to the target enumeration information, and determine the 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 a 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 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 also used to extract class information from the demand header file to obtain target class information;

[0039] An updating module, used for updating 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 in 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 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 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, the steps of the file generation method based on the DBC file as described above are implemented.

[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 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. By processing DBC metadata extraction, class information extraction, matching, and code generation separately, the maintainability and extensibility of the code are improved, and the development efficiency and code consistency are significantly improved. 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 drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

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

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

[0049] Figure 3This is a schematic diagram of the module structure of a 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 described 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 only used to explain the technical solutions of the present application and are not used 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 according to 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), as a highly reliable and stable serial communication protocol, plays a core role in vehicle control systems. However, with the increase in the amount of CAN network data and the diversity of message IDs between controllers, traditional message parsing and data management methods have exposed many problems. The method of manually analyzing DBC (Database CAN) files and writing codes is inefficient and prone to human errors. Especially in the face of large amounts of data and different vehicle models, the processing complexity and maintenance difficulty are significantly increased. In addition, the script parsing method also faces problems such as poor compatibility and troublesome modifications. Therefore, how to solve the low efficiency of generating configuration files after the DBC file is updated has become an urgent problem to be solved.

[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 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. By processing DBC metadata extraction, class information extraction, matching, and code generation separately, the maintainability and extensibility of the code are improved, and the development efficiency and code consistency are significantly improved.

[0057] It should be noted that the execution subject of this embodiment may be a computing service device with data processing, network communication and program running functions, such as a tablet computer, a personal computer, a mobile phone, etc., or a file generation device based on a DBC file that can realize the above functions, etc. The following takes the file generation device based on a DBC file as an example of the execution subject to illustrate this embodiment and the following embodiments.

[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 the present 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 according to 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 is directly available 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 configuration files, 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 extensibility of the code. This method not only supports the processing of multiple files under 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 value 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, an 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 the specific implementation, the SG_ line in the DBC file is parsed to extract the information of the standard signal definition. The signal name, position, length, offset, data order, whether it is signed, precision, physical range and unit are extracted. The data type (such as bool, float, double, int, uint, etc.) is determined according to the length and range of the signal, and the extended signal definition (specific to certain signals such as corner radar) in the SG_ line is parsed.

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

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

[0070] In the specific implementation, parse the BO_ line in the DBC file to extract the information of the message definition. Extract the message ID, name, sender and other information. If the ID is in the blacklist, return an empty dictionary. Parse the SG_ line and add the signal data to the current protocol. Call the corresponding parsing method based on the signal length and whether it is an extended signal. If non-signal data is encountered and the current protocol contains a signal, add the protocol to the pre-defined dictionary and reset the protocol.

[0071] Step A13, parsing the annotation data row in the DBC file to determine the 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 usually 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 the specific implementation, in the DBC file, the VAL_ line is used to define the value mapping table of the signal, that is, to map the numerical value of the signal to a meaningful enumeration value. This helps to improve readability and maintainability, especially when dealing with some discrete value signals, such as status codes, error codes, etc. Then, the signal value table in the VAL_ line is parsed to define the enumeration type for the signal, that is, to generate the enumeration type and add 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, generating an initial data serialization standard file according to the metadata extraction result.

[0080] In the specific implementation, parse the DBC file and generate a YAML file, read the DBC file, parse it line by line and extract the data. Process the parsed protocol to ensure that the signal name does not conflict with C++ reserved keywords (such as minor, major, etc.). Generate a configuration dictionary containing vehicle type and protocol data and save it to a YAML file. Print the statistics of the parsing results.

[0081] Step S20, extracting class information from the demand 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 of the class and member variables.

[0083] In a specific implementation, the class information extraction module matches the communication framework generated by the AUTOSAR AP configuration, and extracts the 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 specific implementation, after extracting the class information from the C++ header file in the communication framework, this information is combined with the protocol data in the existing YAML file. That is, first scan the C++ header file in the specified directory to extract the class and member variable information. Then, apply this information to the YAML configuration file, update the corresponding class name, header file path and member variable for each protocol message, and finally obtain the target data serialization standard file.

[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 understandable that protocol data (protocols) refers to various information describing the communication protocol, including but not limited to message format, signal definition, signal range, signal type, signal value mapping, etc.

[0090] In the specific implementation, an existing YAML configuration file is read and parsed into an object. The protocol data (protocols) in the YAML file is traversed, and each protocol is tried to match 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 is understandable that the match result refers to whether the class information matches the protocol data successfully. First, find the matching class name according to the protocol name. If no suitable match is found, select the default class name or other specific class name according to some rules of the protocol ID and name. Update the class_name and header fields in the protocol to include the corresponding class information. Further update the vars field in the protocol, try to match the member variable name, and add memvar and memvar_type attributes to it (if a matching member variable is found). Write the updated content 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 is 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;

[0095] It can be understood that when the matching result is that there is class information matching the protocol data, it indicates that there is a class name matching 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, updating multiple signals in the updated protocol data according to the member variable information in the class information to obtain an update result, and obtaining 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), and 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 for class information extraction and updating of yaml files is used to match the communication framework generated by the AUTOSAR AP configuration, extract class information from the C++ header file in the communication framework, and combine this information with the protocol data in the existing YAML file. First, scan the C++ header files in the specified directory to extract the class and member variable information. Then, apply this information to the YAML configuration file to update 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 2 steps: extracting class information extract_class_info, extract_class_info_in_dir and updating the yaml file update_output_yml.

[0099] It can be understood that extracting class information extract_class_info: traverses all files in the msg_dir directory and extracts class information. Extracts two specific classes (FrontCornerRadarObjectsArray and RearCornerRadarObjectsArray) and adds their information to the defined dictionary. The information of these two classes is hard-coded, and their paths and class member variables are directly defined in this method; extract_class_info_in_dir: traverses all files and subdirectories in the specified directory. For each class, extracts public member variables and their types from its attributes, and stores this information in a pre-defined dictionary. If it is a directory, recursively call this method to process files in subdirectories.

[0100] It should be understood that updating a YAML file: update_output_yml method: Reads an 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, find a matching class name based on the protocol name. If no suitable match is found, select a default class name or other specific class name based on some rules for the protocol ID and name. Update the class_name and header fields in the protocol to include the corresponding class information. Further update the vars field in the protocol, try to match the member variable name, and add memvar and memvar_type attributes to it (if a matching member variable is found). Write the updated content back to the YAML file.

[0101] It should be noted that the module for class information extraction and updating yaml files extracts information about classes and their member variables from C++ header files, which can help generate or configure code related to these classes and ensure the accuracy of code generation or configuration. Updating the class name and member variable information in the protocol data to 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 the protocol data to be seamlessly integrated with the existing C++ code base.

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

[0103] It is understandable that the target code file refers to the C++ code that can be directly used in the communication framework, and then the C++ code that can be directly used in the communication framework is generated according to the updated data serialization standard file, including extracting information from the protocol configuration, generating parsing functions, processing multiplexers, selecting different code templates according to class names, and writing the generated code to the file. Automatically generating source code helps to significantly reduce the workload of manual coding and ensure the consistency and correctness of the protocol parsing logic.

[0104] This embodiment 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. By processing DBC metadata extraction, class information extraction, matching, and code generation separately, the maintainability and extensibility of the code are improved, and the development efficiency and code consistency are significantly improved.

[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-mentioned embodiment 1 can be referred to the above introduction, and will not be repeated in the following. 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 variables refer 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 the specific implementation, the template file refers to the template that defines the class related to the intelligent driving sensor. The FMT variable is read according to the template file, and the overall format of the enumeration is defined. Then, the enumeration code is generated in combination with the target enumeration information, that is, the enumeration information in the protocol configuration is converted into the enumeration definition in the C++ header file. By parsing the enumeration definition in the protocol configuration file, the code generates a header file containing all enumeration definitions, so that other C++ codes can use these enumeration types.

[0111] It should be noted that the template file is set up to define the classes related to the intelligent driving sensor, 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 code is actually 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 can be 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 the specific implementation, the dictionary of predefined record namespaces is traversed to obtain each namespace and its corresponding enumeration list. For each enumeration name, its corresponding enumeration string (enum_str) is obtained, and the enumeration variable and its value are parsed from it. enumVariableList saves the name and value pairs of the enumeration variable, and generates 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>". Finally, all enumeration definitions are spliced ​​together to form a complete enumeration type definition.

[0118] Step A423, generating 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, the enumeration variable and its value. 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: The 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 the 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 dictionary of the pre-defined record namespaces, obtain each namespace and its corresponding enumeration list. For each enumeration name, obtain its corresponding enumeration string (enum_str), and parse the enumeration variable and its value from it. enumVariableList saves the name and value pairs of the enumeration variable, and generates the enumeration definition in C++ by splitting and processing the string. Enumeration declaration generation: enum_declare_list is used to store the declaration of each enumeration value, in the format of "<enumeration value name> = <value>". Finally, all enumeration definitions are spliced ​​together to form a complete enumeration type definition. Write to the file: Use the open function to open the report_enum_file file in write mode and write the generated enumeration content into 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 enumeration definitions, so that other C++ codes can 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 a C++ header file, which contains class and method declarations related to the protocol. The file is generated based on a given protocol configuration, formatted according to a 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: a final header file path is generated according to a protocol name.

[0127] Step A432, preparing content according to the target class information and the target method declaration, generating a plurality of formatted values;

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

[0129] In the specific implementation, multiple formatted values ​​are generated according to the class definition information, the class and method declarations related to 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 form of the first letter of the protocol name; fullclassname: the full name of the class is determined according to the class_name key value in the protocol. If class_name does not exist, it is set to "Unknown"; varname: extract the file name (excluding the extension) from the path of the protocol configuration file; header: set the included header file according to the header key value in the protocol, or empty if it does not exist.

[0130] Step A433, generating 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 a C++ header file is obtained.

[0132] It should be noted that, ⑴ 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 according to the protocol name; ⑵ Initialize template formatting content, read template format: read formatting content from the template file, which determines the overall structure of the header file; ⑶ Formatting content preparation, prepare formatting value (fmt_val): car_type_lower and car_type_upper: lowercase and uppercase forms of vehicle type respectively. protocol_name_upper: uppercase form of protocol name. classname: uppercase form of the first letter of the protocol name. fullclassname: Determine the full name of the class according to 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: Set the included header file according to the header key value in the protocol, or empty if it does not exist;⑷Method declaration generation, traverse the variables in the protocol: Generate method declarations for each variable and add them to the method declaration list (func_declare_list). If the variable type is enum, it is processed as a combination type of the protocol name and the variable name. Generate function declarations: Generate function declarations for each variable, the format includes configuration details and the return type of the method;⑸Process enumeration types, enumeration type collection: traverse the variable list and find variables of type enum. Generate the corresponding enumeration name and add it to the enumeration name list (enum_name_list). Store the enumeration definition in self.enum2enumstr. Update the enumeration namespace: If there is an enumeration type, associate it with the protocol name and generate the corresponding enumeration header file path (enumheader);⑹Write to file, format content: Apply all formatting values ​​to the template to generate the final header file content. Write to file: Write the generated header file content to the specified file path. This step generates a C++ header file containing class declarations and method declarations by combining the information in the protocol configuration (such as vehicle type, protocol name, method and its parameters, etc.) with predefined templates. This header file defines the interface related to the protocol and includes the enumeration types that may be required. This automated code generation method can help ensure the consistency of the protocol and code and improve development efficiency.

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

[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 generates C++ code with specific implementation details using a template 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 C++ source files (template / report_protocol.cc.tpl). Generate file path: Generate the path of C++ source files based on the protocol name; ⑵ Prepare formatted data, basic formatting value (fmt_val): car_type_lower: lowercase form of vehicle type. protocol_name_lower: lowercase form of protocol name. varname: file name extracted from the protocol configuration file path (excluding extension). classname: the first letter of the protocol name in uppercase. fullclassname: the full class name set according to the class_name key value in the protocol (if not, 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 corresponding function implementations for each variable, and store them in the function implementation list (func_impl_list). Process variables of enum type and format the return type of the function;⑷ Process multiplexers (Multiplexor) and detect multiplexers: If a multiplexer is found (checked by the variable name), generate the relevant switch statement. Generate multiplexer-related code: If there is a multiplexer in the protocol, generate the corresponding code block according to the configuration and add it to the protocol processing list;⑸ Generate variable assignment code and process each variable: Generate code according to the type and configuration of the protocol variable 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, which assign the value of the variable to the member variable of the protocol object;⑹ Select templates based on class names, select templates: Select different template files based on class names (such as Fradar_obj, Flr_, Rlr_) to generate 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, obtaining 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 are directly usable 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 declaration and target protocol variable; generates enumeration code according to the template file and the target enumeration information; generates target header file according to the template file, the target class information and the target method declaration; generates target source file according to the template file, the target class information and the target protocol variable; and obtains target code file according to the target source file, the target header file and the enumeration code. The above method reduces the workload of manual coding and ensures the consistency and correctness of the 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 protection scope 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 according to the metadata extraction result;

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

[0143] An updating module 20, 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 used to generate a target code file according to the target data serialization standard file.

[0145] Optionally, the extraction module 10 is further used for:

[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 row in the DBC file to determine the 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 is 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 used for:

[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 used for:

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

[0166] Generate target enumeration content according to the target enumeration information, and determine the 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 used for:

[0169] Determine a 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 by the present application adopts the DBC file-based file generation method in the above embodiment, which can solve the technical problem of low generation efficiency of the configuration file after the DBC file is updated. Compared with the prior art, the beneficial effects of the DBC file-based file generation device provided by the present application are the same as the beneficial effects of the DBC file-based file generation method provided by the above embodiment, and other technical features in the DBC file-based file generation device are the same as the features disclosed in the above embodiment method, which will not be repeated 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 diagram of the structure of a file generation device based on a DBC file suitable for implementing an embodiment of the present application. The file generation device based on a DBC file in the embodiment 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), vehicle-mounted terminals (such as vehicle-mounted navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 4 The DBC file-based file generation device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0175] like Figure 4 As shown, the file generation device based on the DBC file may include a processing device 1001 (such as a central processing unit, a graphics processor, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the file generation device based on the DBC file are also stored. The processing device 1001, the ROM 1002, and the 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 may be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touchpad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the DBC file-based file generation device to communicate wirelessly or wired with other devices to exchange data. Although the DBC file-based file generation device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.

[0176] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a 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 through 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 by the present application adopts the DBC file-based file generation method in the above embodiment, which can solve the technical problem of low generation efficiency of the configuration file after the DBC file is updated. Compared with the prior art, the beneficial effects of the DBC file-based file generation device provided by the present application are the same as the beneficial effects of the DBC file-based file generation method provided by the above embodiment, and other technical features in the DBC file-based file generation device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0178] It should be understood that the various parts disclosed in this application can be implemented by 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 is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0180] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and 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 the present 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 of the above. 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 of the above. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination 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 of the above.

[0182] The computer-readable storage medium may be included in a file generation device based on a DBC file; or may exist independently without being assembled into a file generation device based on a 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 according to the metadata extraction result; extracts class information from the demand header file to obtain target class information; updates the initial data serialization standard file according to the target class information to obtain a target data serialization standard file; and generates a target code file according to 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 separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of 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., via the Internet using an Internet service provider).

[0185] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the 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 square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square 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 square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0186] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0187] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned file generation method based on DBC files, and can solve the technical problem of low efficiency in generating configuration files after the DBC files are updated. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the file generation method based on DBC files provided by the above-mentioned embodiments, and will not be described in detail 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 the present application can solve the technical problem of low efficiency in generating configuration files after the DBC file is updated. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as the beneficial effects of the file generation method based on the DBC file provided by the above embodiment, which will not be described in detail here.

[0190] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications 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 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, characterized in that The step of extracting metadata from the DBC file and generating an initial data serialization standard file according to the metadata extraction result includes: 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 row in the DBC file to determine the 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, characterized in that The step of updating the initial data serialization standard file according to the target class information to obtain the target data serialization standard file comprises: 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, characterized in that The step of updating the initial data serialization standard file according to the matching result to obtain the target data serialization standard file comprises: When the matching result is 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, characterized in that 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, characterized in that The step of generating an enumeration code according to the template file and the target enumeration information comprises: Determine the enumeration definition format according to the template file; Generate target enumeration content according to the target enumeration information, and determine the 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, characterized in that The step of generating a target header file according to the template file, the target class information and the target method declaration comprises: Determine a 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 also used to extract class information from the demand header file to obtain target class information; An updating module, used for updating 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 comprises: 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 file generation method based on the 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, and 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

  • DBC file analysis method and device, equipment and storage medium

    CN116112583A

  • Test code generation method and device, computer equipment and storage medium

    CN118409953A

  • Method and system for deconstructing and searching binary based vehicular data

    US20190258727A1

Cited By

  • DBC file analysis method and device, vehicle and storage medium

    CN120996026A