CAN communication matrix analysis and code generation method, system and device
Through automated analysis and generation technology, the cumbersome and error problems in the process of differential search and code modification of CAN communication matrix are solved, and efficient and accurate CAN communication matrix code generation is achieved, which improves work efficiency and accuracy, and meets the modern automotive electronic system. efficient demand.
Patent Information
- Application Number
- CN202411018911.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-26
- Publication Date
- 2024-12-13
AI Technical Summary
In the prior art, the process of differential search and code modification of CAN communication matrix is cumbersome and error-prone, resulting in low work efficiency, long construction period and time-consuming and labor-consuming.
It provides a method of analyzing CAN communication matrix and code generation. By automatically analyzing CAN communication matrix files, extracting information and automatically generating corresponding C codes, reducing manual operations, and improving accuracy and efficiency.
It realizes efficient, accurate and reliable analysis and code generation of the CAN communication matrix, eliminates manual errors, significantly improves work efficiency, shortens construction period, and saves labor and time costs.
Smart Images

Figure CN119127201A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of vehicle technology, and in particular to a method, system and device for parsing and generating codes for a CAN communication matrix. Background Art
[0002] In automotive electronics and embedded systems, CAN (Controller Area Network) communication is widely used in vehicle networks. In order to achieve effective communication between different electronic control units (ECUs), engineers usually use CAN communication matrices to define and describe various signals and messages. After network engineers have sorted out the contents of the CAN communication matrix, they usually publish it through Execl and dbc files, while other engineers view execl files through office and dbc files through other tools, and finally complete code modifications through the code compilation IDE they are familiar with.
[0003] The existing technical solution is mainly completed by engineers to add or change the modification. The process is summarized as follows: according to business needs, network communication engineers update and release a version of the CAN communication matrix file; the bottom software engineer compares the old and new versions of the CAN communication matrix file and finds the differences; the bottom software engineer completes the variable definition, sending table and receiving table modification based on the differences. There are the following disadvantages:
[0004] Differences are difficult to find. The CAN communication matrix has certain rules, but there is uncertainty in the content of the CAN communication matrix file, such as the order of CAN message placement, the adjustment of CAN message content, etc., which greatly increases the difficulty of finding differences and is prone to omissions. Manually adjusting the code is prone to errors. Even if engineers can find all the differences, there is still a large risk of errors when manually modifying the engineering code. The amount of content adjusted each time the CAN communication matrix is uncertain, which increases the complexity and error rate in the manual modification process. The construction period is long and time-consuming and labor-intensive. The existing technology mainly relies on manual inspection and modification, resulting in low work efficiency. Each CAN communication matrix adjustment requires engineers to perform a lot of manual operations, which consumes a lot of time and energy. Summary of the invention
[0005] Based on this, it is necessary to provide a CAN communication matrix parsing and code generation method, system and device to address the above-mentioned technical problems, which have the advantages of high efficiency, high accuracy and high reliability in CAN communication matrix parsing and code generation.
[0006] In a first aspect, a method for parsing and generating codes for a CAN communication matrix is provided, comprising:
[0007] Run the executable file, parse the CAN communication matrix file in the CAN communication matrix update directory, and obtain the content of the CAN communication matrix file;
[0008] Generate engineering code based on the content of the CAN communication matrix file;
[0009] If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
[0010] In some examples, before running the executable file and parsing the CAN communication matrix file in the CAN communication matrix update directory to obtain the content of the CAN communication matrix file, the following is also included:
[0011] The updated CAN communication matrix file is published, and the CAN communication matrix file is stored in the CAN communication matrix update directory.
[0012] In some examples, the running executable file performs a parsing operation on the CAN communication matrix file in the CAN communication matrix update directory to obtain the CAN communication matrix file content, including:
[0013] The executable file is run to parse the CAN communication matrix file from the CAN communication matrix update directory to extract the CAN communication matrix file content from the CAN communication matrix file.
[0014] In some examples, the communication matrix file content includes at least CAN message and signal definitions.
[0015] In some examples, the engineering code generation operation is performed according to the content of the CAN communication matrix file, including:
[0016] According to the content of the communication matrix file, a logic code is generated which includes at least variable definition, sending definition and receiving definition.
[0017] In some examples, if no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory, including:
[0018] Determine whether an exception or error occurs during the execution of the executable file;
[0019] If not, the generated engineering code is stored in the code generation directory in the form of an engineering code file.
[0020] In a second aspect, a CAN communication matrix parsing and code generation system is provided, comprising:
[0021] The parsing module is used to run the executable file, parse the CAN communication matrix file in the CAN communication matrix update directory, and obtain the content of the CAN communication matrix file;
[0022] The code generation module is used to generate engineering code according to the content of the CAN communication matrix file;
[0023] The storage module is used to generate an engineering code file in a code generation directory after the engineering code generation operation is completed when no exception occurs during the operation of the executable file. In a third aspect, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the program, the steps of the method for parsing and generating code of the CAN communication matrix of the first aspect and any possible implementation of the first aspect are implemented.
[0024] In a fourth aspect, a computer-readable storage medium is provided, on which a computer program is stored. When the program is executed by a processor, the steps of the method for parsing and generating codes for the CAN communication matrix of the above-mentioned first aspect and any possible implementation method of the first aspect are implemented.
[0025] In a fifth aspect, a computer program product is provided, on which a computer program is stored. When the program is executed by a processor, the steps of the method for parsing and generating codes for the CAN communication matrix of the above-mentioned first aspect and any possible implementation method of the first aspect are implemented.
[0026] The embodiments of the present application have the following advantages:
[0027] It has the advantages of automatic parsing and code generation. The CAN communication matrix update work in the prior art requires engineers to manually compare the matrix files of the new and old versions and manually modify the code. This process is cumbersome and error-prone. The present application solves this problem through automatic parsing and generation technology, which can automatically parse the CAN communication matrix file, extract information, and automatically generate the corresponding C code. Each time it is run, the latest code is generated from scratch, thereby ensuring that the generated content is always the latest and meets the requirements of the CAN communication matrix. It has the advantage of eliminating manual errors. Since all the generated content is automatically generated, there are no errors or omissions that may be caused by manual modification. The automatically generated code is implemented according to the content of the CAN communication matrix, ensuring the accuracy and consistency of the code; it has the advantage of improving production efficiency. The modification and update of the CAN communication matrix content in the prior art usually takes one to two weeks, and the present application, the whole process can be completed quickly, greatly improving production efficiency, saving a lot of manpower and time costs. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Other features, objects and advantages of the present application will become more apparent by reading the detailed description of non-limiting embodiments made with reference to the following drawings:
[0029] Figure 1 A flowchart of a method for parsing and generating codes for a CAN communication matrix provided in an embodiment of the present application;
[0030] Figure 2 A schematic diagram of the application of the CAN communication matrix analysis and code generation method provided in the embodiment of the present application;
[0031] Figure 3 A structural block diagram of a CAN communication matrix analysis and code generation system provided in an embodiment of the present application;
[0032] Figure 4 A structural block diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0033] The present application is further described in detail below in conjunction with the embodiments and drawings. It is to be understood that the specific embodiments described herein are only used to explain the relevant application, rather than to limit the application. It is also necessary to explain that, for ease of description, only the parts related to the application are shown in the drawings.
[0034] It should be noted that, in the absence of conflict, the embodiments of the present application, that is, the features of the embodiments, can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0035] The following describes in detail the CAN communication matrix parsing and code generation method, system, device and medium according to the embodiments of the present application in conjunction with the accompanying drawings.
[0036] This application can automatically parse the content of the CAN communication matrix, directly implement the automatic parsing of the new version of the CAN communication matrix in a code manner, and record all useful CAN communication matrix information; automatic code generation, automatically generate variable definition, CAN sending and CAN receiving codes according to business conditions and CAN matrix information, reduce manual operations, and improve accuracy; improve work efficiency, by realizing the above two main functions, reduce the time and labor intensity of manual inspection and modification, significantly improve work efficiency, and shorten the construction period. In this way, the efficiency and accuracy of CAN communication matrix updates and code generation are improved to meet the efficient and reliable requirements of modern automotive electronic systems.
[0037] Figure 1 FIG. 1 is a flow chart of a method for parsing and generating codes for a CAN communication matrix according to an embodiment of the present application. Figure 1 As shown, combined with Figure 2As shown, the method for parsing and generating code of the CAN communication matrix according to the embodiment of the present application includes the following steps:
[0038] S101: Run the executable file to parse the CAN communication matrix file in the CAN communication matrix update directory to obtain the content of the CAN communication matrix file.
[0039] The CAN communication matrix file is pre-stored in the CAN communication matrix update directory. Specifically, in a specific example, before running the executable file and parsing the CAN communication matrix file in the CAN communication matrix update directory to obtain the CAN communication matrix file content, it also includes: publishing the updated CAN communication matrix file and storing the CAN communication matrix file in the CAN communication matrix update directory.
[0040] After storing the CAN communication matrix file in the CAN communication matrix update directory, running the executable file, parsing the CAN communication matrix file in the CAN communication matrix update directory, and obtaining the CAN communication matrix file content, including: running the executable file, parsing the CAN communication matrix file from the CAN communication matrix update directory, and extracting the CAN communication matrix file content from the CAN communication matrix file. In this example, the communication matrix file content at least includes the definition of CAN messages and signals.
[0041] For example: after the network engineer finishes organizing the CAN communication matrix content, the CAN communication matrix file is usually published by email or other transmission methods. Then, the development engineer (such as the underlying software development engineer) copies the CAN communication matrix file in excel and dbc format published by the network engineer to the update directory, that is, to the pre-agreed CAN communication matrix update directory. That is, put the published CAN communication matrix file into the specified directory, that is, the engineer places the updated CAN communication matrix file in the specified directory. In a specific example, the directory is usually the matrix_files folder of the same level directory.
[0042] S102: Perform engineering code generation operation according to the content of the CAN communication matrix file.
[0043] In one embodiment of the present application, an engineering code generation operation is performed according to the content of a CAN communication matrix file, including: generating a logic code including at least variable definition, sending definition and receiving definition according to the content of the communication matrix file.
[0044] That is, run the executable file of the integrated processing logic. After running the executable file, the CAN communication matrix file placed in the matrix_files directory will be automatically parsed, and the content of the CAN communication matrix file will be parsed, such as extracting the definition of CAN messages and signals. Then, based on the extracted CAN message and signal definition, the code is automatically generated, such as the code written in C language. The engineering code includes but is not limited to variable definition, sending and receiving definition and logic code.
[0045] S103: If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
[0046] In one embodiment of the present application, if no exception occurs during the operation of the executable file, an engineering code file is generated in the code generation directory after the engineering code generation operation is completed, including: determining whether an exception or error occurs during the operation of the executable file; if not, storing the generated engineering code in the form of an engineering code file in the code generation directory.
[0047] That is to say, a code file written in C language is generated in the specified directory. If no exception or error occurs during the running process, the corresponding C code file will be generated in the generated folder of the same directory.
[0048] After the method is executed, the automatically generated C language code file and its storage structure are as follows:
[0049] generated /
[0050] ├──can_handle.c
[0051] ├──can_handle.h
[0052] ├──can_table.c
[0053] ├──can_table.h
[0054] └──rte
[0055] ├──inc
[0056] │├──Rte_ACAN.h
[0057] │├──Rte_BCAN.h
[0058] │├──Rte_Can_Common.h
[0059] │├──Rte_CCAN.h
[0060] │└──Rte_PCAN.h
[0061] └──src
[0062] ├──Rte_ACAN.c
[0063] ├──Rte_BCAN.c
[0064] ├──Rte_CCAN.c
[0065] └──Rte_PCAN.c
[0066] The CAN communication matrix analysis and code generation method of the embodiment of the present application has the following advantages:
[0067] It has the advantages of automatic parsing and code generation. The CAN communication matrix update work in the prior art requires engineers to manually compare the matrix files of the new and old versions and manually modify the code. This process is cumbersome and error-prone. The present application solves this problem through automatic parsing and generation technology, which can automatically parse the CAN communication matrix file, extract information, and automatically generate the corresponding C code. Each time it is run, the latest code is generated from scratch, thereby ensuring that the generated content is always the latest and meets the requirements of the CAN communication matrix. It has the advantage of eliminating manual errors. Since all the generated content is automatically generated, there are no errors or omissions that may be caused by manual modification. The automatically generated code is implemented according to the content of the CAN communication matrix, ensuring the accuracy and consistency of the code; it has the advantage of improving production efficiency. The modification and update of the CAN communication matrix content in the prior art usually takes one to two weeks, and the present application, the whole process can be completed quickly, greatly improving production efficiency, saving a lot of manpower and time costs.
[0068] According to the CAN communication matrix analysis and code generation method of the embodiment of the present application, the executable file is run, the CAN communication matrix file in the CAN communication matrix update directory is analyzed, the CAN communication matrix file content is obtained, and the engineering code generation operation is performed according to the CAN communication matrix file content. If the executable file does not have an abnormality during operation, the engineering code file is generated in the code generation directory after the engineering code generation operation is completed. The method has the advantages of high efficiency, high accuracy and high reliability in the analysis and code generation of the CAN communication matrix.
[0069] Figure 3 1 is a block diagram of a CAN communication matrix analysis and code generation system according to an embodiment of the present application. Figure 3As shown, according to an embodiment of the present application, the CAN communication matrix parsing and code generation system includes: a parsing module 310, a code generation module 320 and a storage module 330, wherein:
[0070] The parsing module 310 is used to run the executable file, parse the CAN communication matrix file in the CAN communication matrix update directory, and obtain the content of the CAN communication matrix file;
[0071] The code generation module 320 is used to perform an engineering code generation operation according to the content of the CAN communication matrix file;
[0072] The storage module 330 is used to generate an engineering code file in a code generation directory after the engineering code generation operation is completed when no exception occurs during the running of the executable file.
[0073] The CAN communication matrix file is pre-stored in the CAN communication matrix update directory. Specifically, in a specific example, before running the executable file and parsing the CAN communication matrix file in the CAN communication matrix update directory to obtain the CAN communication matrix file content, it also includes: publishing the updated CAN communication matrix file and storing the CAN communication matrix file in the CAN communication matrix update directory.
[0074] After storing the CAN communication matrix file in the CAN communication matrix update directory, running the executable file, parsing the CAN communication matrix file in the CAN communication matrix update directory, and obtaining the CAN communication matrix file content, including: running the executable file, parsing the CAN communication matrix file from the CAN communication matrix update directory, and extracting the CAN communication matrix file content from the CAN communication matrix file. In this example, the communication matrix file content at least includes the definition of CAN messages and signals.
[0075] For example: after the network engineer finishes organizing the CAN communication matrix content, the CAN communication matrix file is usually published by email or other transmission methods. Then, the development engineer (such as the underlying software development engineer) copies the CAN communication matrix file in excel and dbc format published by the network engineer to the update directory, that is, to the pre-agreed CAN communication matrix update directory. That is, put the published CAN communication matrix file into the specified directory, that is, the engineer places the updated CAN communication matrix file in the specified directory. In a specific example, the directory is usually the matrix_files folder of the same level directory.
[0076] In one embodiment of the present application, an engineering code generation operation is performed according to the content of a CAN communication matrix file, including: generating a logic code including at least variable definition, sending definition and receiving definition according to the content of the communication matrix file.
[0077] That is, run the executable file of the integrated processing logic. After running the executable file, the CAN communication matrix file placed in the matrix_files directory will be automatically parsed, and the content of the CAN communication matrix file will be parsed, such as extracting the definition of CAN messages and signals. Then, based on the extracted CAN message and signal definition, the code is automatically generated, such as the code written in C language. The engineering code includes but is not limited to variable definition, sending and receiving definition and logic code.
[0078] In one embodiment of the present application, if no exception occurs during the operation of the executable file, an engineering code file is generated in the code generation directory after the engineering code generation operation is completed, including: determining whether an exception or error occurs during the operation of the executable file; if not, storing the generated engineering code in the form of an engineering code file in the code generation directory.
[0079] That is to say, a code file written in C language is generated in the specified directory. If no exception or error occurs during the running process, the corresponding C code file will be generated in the generated folder of the same directory.
[0080] The CAN communication matrix analysis and code generation system of the embodiment of the present application has the following advantages:
[0081] It has the advantages of automatic parsing and code generation. The CAN communication matrix update work in the prior art requires engineers to manually compare the matrix files of the new and old versions and manually modify the code. This process is cumbersome and error-prone. The present application solves this problem through automatic parsing and generation technology, which can automatically parse the CAN communication matrix file, extract information, and automatically generate the corresponding C code. Each time it is run, the latest code is generated from scratch, thereby ensuring that the generated content is always the latest and meets the requirements of the CAN communication matrix. It has the advantage of eliminating manual errors. Since all the generated content is automatically generated, there are no errors or omissions that may be caused by manual modification. The automatically generated code is implemented according to the content of the CAN communication matrix, ensuring the accuracy and consistency of the code; it has the advantage of improving production efficiency. The modification and update of the CAN communication matrix content in the prior art usually takes one to two weeks, and the present application, the whole process can be completed quickly, greatly improving production efficiency, saving a lot of manpower and time costs.
[0082] According to the CAN communication matrix parsing and code generation system of the embodiment of the present application, the executable file is run, the CAN communication matrix file in the CAN communication matrix update directory is parsed, the CAN communication matrix file content is obtained, and the engineering code generation operation is performed according to the CAN communication matrix file content. If the executable file does not have an abnormality during operation, the engineering code file is generated in the code generation directory after the engineering code generation operation is completed. The CAN communication matrix parsing and code generation has the advantages of high efficiency, high accuracy and high reliability.
[0083] For the specific definition of the parsing and code generation system of the CAN communication matrix, please refer to the definition of the parsing and code generation method of the CAN communication matrix mentioned above, which will not be repeated here. The various modules of the above-mentioned parsing and code generation system of the CAN communication matrix can be implemented in whole or in part by software, hardware and their combination. The above-mentioned modules can be embedded in or independent of the processor in the computer device in the form of hardware, or can be stored in the memory of the computer device in the form of software, so that the processor can call and execute the operations corresponding to the above modules.
[0084] In one embodiment, a computer device is provided. Figure 4 This is a block diagram of the computer device provided in the embodiment of the present application, refer to Figure 4 The computer device includes a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the aforementioned CAN communication matrix parsing and code generation method embodiment is implemented. For example, execution: running an executable file, parsing the CAN communication matrix file in the CAN communication matrix update directory, and obtaining the CAN communication matrix file content;
[0085] Generate engineering code based on the content of the CAN communication matrix file;
[0086] If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
[0087] The embodiment of the present application also provides a computer-readable storage medium, which stores a computer program. When the processor executes the computer program, the above-mentioned CAN communication matrix parsing and code generation method embodiment is implemented. For example, the execution: running the executable file, parsing the CAN communication matrix file in the CAN communication matrix update directory, and obtaining the CAN communication matrix file content;
[0088] Generate engineering code based on the content of the CAN communication matrix file;
[0089] If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
[0090] The present application embodiment provides a computer program product, which includes instructions. When the instructions are executed, the method described in the embodiment of the present application is executed. For example, it can be executed Figure 1 The various steps of the method for parsing and generating codes for the CAN communication matrix shown, for example, are executed: running the executable file, parsing the CAN communication matrix file in the CAN communication matrix update directory, and obtaining the content of the CAN communication matrix file;
[0091] Generate engineering code based on the content of the CAN communication matrix file;
[0092] If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
[0093] Those of ordinary skill in the art can understand that all or part of the processes in the methods for implementing the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory or optical memory, etc. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM).
[0094] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0095] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the patent application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent application shall be subject to the attached claims.
Claims
1. A method for parsing and generating codes for a CAN communication matrix, characterized in that: include: Run the executable file, parse the CAN communication matrix file in the CAN communication matrix update directory, and obtain the content of the CAN communication matrix file; Generate engineering code based on the content of the CAN communication matrix file; If no exception occurs during the running of the executable file, then after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory.
2. The method for analyzing and generating codes for a CAN communication matrix according to claim 1, characterized in that: Before running the executable file and parsing the CAN communication matrix file in the CAN communication matrix update directory to obtain the content of the CAN communication matrix file, the following steps are also included: The updated CAN communication matrix file is published, and the CAN communication matrix file is stored in the CAN communication matrix update directory.
3. The method for analyzing and generating codes for a CAN communication matrix according to claim 1 or 2, characterized in that: The running executable file performs a parsing operation on the CAN communication matrix file in the CAN communication matrix update directory to obtain the CAN communication matrix file content, including: The executable file is run to parse the CAN communication matrix file from the CAN communication matrix update directory to extract the CAN communication matrix file content from the CAN communication matrix file.
4. The method for analyzing and generating codes for a CAN communication matrix according to claim 3, characterized in that: The communication matrix file content includes at least the definition of CAN messages and signals.
5. The method for analyzing and generating codes for a CAN communication matrix according to claim 4, characterized in that: The engineering code generation operation is performed according to the content of the CAN communication matrix file, including: According to the content of the communication matrix file, a logic code is generated which includes at least variable definition, sending definition and receiving definition.
6. The method for analyzing and generating codes for a CAN communication matrix according to claim 1, characterized in that: If no exception occurs during the running of the executable file, after the engineering code generation operation is completed, an engineering code file is generated in the code generation directory, including: Determine whether an exception or error occurs during the execution of the executable file; If not, the generated engineering code is stored in the code generation directory in the form of an engineering code file.
7. A CAN communication matrix analysis and code generation system, characterized in that: include: The parsing module is used to run the executable file, parse the CAN communication matrix file in the CAN communication matrix update directory, and obtain the content of the CAN communication matrix file; The code generation module is used to generate engineering code according to the content of the CAN communication matrix file; The storage module is used to generate an engineering code file in a code generation directory after the engineering code generation operation is completed when no exception occurs during the running of the executable file.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the program, the method for parsing and generating codes for the CAN communication matrix according to any one of claims 1 to 6 is implemented.
9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for parsing and generating codes for the CAN communication matrix according to any one of claims 1 to 6 is implemented.
10. A computer program product having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method for parsing and generating codes for the CAN communication matrix according to any one of claims 1 to 6 is implemented.
