Vehicle-mounted controller communication code generation method, device, equipment, medium and product
By automatically generating CAN communication code for the vehicle controller, the problems of poor flexibility, high complexity, and long cycle in existing technologies are solved, and efficient and flexible code development is achieved.
Patent Information
- Application Number
- CN202511881870.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-12-12
- Publication Date
- 2026-05-05
AI Technical Summary
In existing technologies, the development of the CAN communication intermediate layer code for vehicle controllers is characterized by poor flexibility, high complexity, susceptibility to errors, and long development cycles, resulting in project rework and low development efficiency.
By acquiring the target vehicle's communication definition file and controller identifier, filtering and creating output files, extracting communication signal information, and calling the corresponding communication code generation template according to the signal type, communication code is automatically generated without the need for hand-writing code or building simulation models.
It reduces the probability and complexity of development errors, shortens the development cycle, improves development flexibility, and adapts to different projects and network changes.
Smart Images

Figure CN121979501A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of vehicle controller technology, and in particular to a method, apparatus, device, medium and product for generating communication codes for an on-board controller. Background Technology
[0002] In the field of vehicle controller software development, the CAN (Controller Area Network) communication middleware layer is the core link connecting the controller and the vehicle's CAN network. Its development efficiency and stability directly affect the R&D cycle and reliability of the vehicle's electronic control system.
[0003] The relevant technologies mainly involve writing CAN communication middleware code by hand and building CAN communication models using Simulink. However, this approach is inflexible, requires redevelopment for different projects or different stages of the same project due to network changes, is highly complex and prone to errors, and is extremely susceptible to human error during the development phase, leading to project rework, long development cycles, large amounts of code, and significant time required for code or model testing after development. Summary of the Invention
[0004] This application provides a method, apparatus, device, medium, and product for generating communication codes for vehicle controllers, in order to solve problems such as poor flexibility, long development cycle, high complexity, and susceptibility to errors in related technologies.
[0005] The first aspect of this application provides a method for generating communication code for an on-board controller, comprising the following steps: obtaining a communication definition file of a target vehicle and an identifier of a target on-board controller; filtering the communication definition file based on the identifier of the target on-board controller and establishing an output file of the target on-board controller; extracting communication information of at least one communication signal in the target on-board controller from the filtered communication definition file, wherein the communication information includes signal nodes and signal parameters; generating corresponding interface signals and signal buffer interface definitions based on the communication information of at least one communication signal; determining the signal type of at least one communication signal based on the signal nodes; calling the corresponding communication code generation template based on the signal type; filling the communication code generation template with signal parameters, interface signals, and signal buffer interface definitions; and writing the filled communication code generation template, interface signals, and signal buffer interface definitions into the output file to generate the communication code of the target on-board controller.
[0006] Optionally, before writing the filled communication code generation template, interface signals, and signal buffer interface definitions into the output file, the method further includes: obtaining an interface signal definition table; if an interface signal definition table is obtained, extracting the signal names from the interface signal definition table, and determining the interface variable of the target vehicle controller corresponding to the interface signal based on the interface signal definition table when the interface signal contains the signal names from the interface signal definition table; if an interface signal definition table is not obtained, generating the signal names of the interface signals based on preset rules, determining the interface variable of the target vehicle controller corresponding to the interface signal based on the signal names; and writing the correspondence between the interface signals and the interface variables of the target vehicle controller into the output file.
[0007] Optionally, after generating the communication code of the target vehicle controller, the method further includes: writing the communication code into the target vehicle controller, and the target vehicle controller communicating with the communication network of the target vehicle based on the communication code.
[0008] Optionally, the signal parameters include at least one of name, address, length, start bit, offset, and coefficient; the signal type includes a first type and a second type, where the first type is a received signal and the second type is a transmitted signal; and the communication code generation template includes a first template and a second template.
[0009] Optionally, the corresponding communication code generation template is called based on the signal type, including: if the signal type is a first type, the first template is called; if the signal type is a second type, the second template is called.
[0010] Optionally, the first template includes: clearing the signal buffer to zero, looping through the communication signals in the signal receiving buffer, assigning the communication signals in the signal receiving buffer bit by bit to the signal buffer according to the start bit and length of the communication signals, calculating the interface signal value of the communication signals according to the offset and coefficient of the communication signals in the signal buffer, and assigning the interface signal value to the corresponding interface variable. The second template includes: Clear the signal buffer to zero, loop through the interface signal values in the signal buffer, calculate the original value of the communication signal based on the offset, coefficient, and interface signal value of the communication signal, store the original value in the signal buffer, determine the position of the original value in the signal transmission buffer based on the start bit and length of the communication signal, and assign the original value of the communication signal in the signal buffer bit by bit to the signal transmission buffer.
[0011] A second aspect of this application provides an apparatus for generating communication code for an on-board controller, comprising: an acquisition module for acquiring a communication definition file of a target vehicle and an identifier of a target on-board controller; an extraction module for filtering the communication definition file based on the identifier of the target on-board controller, establishing an output file of the target on-board controller, and extracting communication information of at least one communication signal in the target on-board controller from the filtered communication definition file, wherein the communication information includes signal nodes and signal parameters; a first generation module for generating corresponding interface signals and signal buffer interface definitions based on the communication information of at least one communication signal; a filling module for determining the signal type of at least one communication signal based on the signal nodes, calling a corresponding communication code generation template based on the signal type, and filling the communication code generation template with signal parameters, interface signals, and signal buffer interface definitions; and a second generation module for writing the filled communication code generation template, interface signals, and signal buffer interface definitions into an output file to generate communication code for the target on-board controller.
[0012] Optionally, it further includes: a determination module, used to obtain an interface signal definition table before writing the filled communication code generation template, interface signal, and signal buffer interface definition into the output file; if the interface signal definition table is obtained, the signal names in the interface signal definition table are extracted, and if the interface signal contains the signal names in the interface signal definition table, the interface variable of the target vehicle controller corresponding to the interface signal is determined according to the interface signal definition table; if the interface signal definition table is not obtained, the signal names of the interface signals are generated based on preset rules, and the interface variables of the target vehicle controller corresponding to the interface signal are determined based on the signal names; the correspondence between the interface signals and the interface variables of the target vehicle controller is written into the output file.
[0013] Optionally, it also includes: a writing module, used to write the communication code into the target vehicle controller after generating the communication code of the target vehicle controller, and the target vehicle controller communicates with the communication network of the target vehicle based on the communication code.
[0014] Optionally, the signal parameters include at least one of name, address, length, start bit, offset, and coefficient; the signal type includes a first type and a second type, where the first type is a received signal and the second type is a transmitted signal; and the communication code generation template includes a first template and a second template.
[0015] Optionally, the filling module is further configured to: call the first template if the signal type is a first type; and call the second template if the signal type is a second type.
[0016] Optionally, the first template includes: clearing the signal buffer to zero, looping through the communication signals in the signal receiving buffer, assigning the communication signals in the signal receiving buffer bit by bit to the signal buffer according to the start bit and length of the communication signals, calculating the interface signal value of the communication signals according to the offset and coefficient of the communication signals in the signal buffer, and assigning the interface signal value to the corresponding interface variable. The second template includes: Clear the signal buffer to zero, loop through the interface signal values in the signal buffer, calculate the original value of the communication signal based on the offset, coefficient, and interface signal value of the communication signal, store the original value in the signal buffer, determine the position of the original value in the signal transmission buffer based on the start bit and length of the communication signal, and assign the original value of the communication signal in the signal buffer bit by bit to the signal transmission buffer.
[0017] A third aspect of this application provides an electronic device, including: a memory, a processor, and a computer program stored in the memory and executable on the processor. The processor executes the program to perform the vehicle controller communication code generation method as described above.
[0018] A fourth aspect of this application provides a computer-readable storage medium having a computer program or instructions stored thereon, which are executed by a processor to perform the vehicle controller communication code generation method as described above.
[0019] The fifth aspect of this application provides a computer program product, including a computer program or instructions, which, when executed, implement the vehicle controller communication code generation method as described in the above embodiments.
[0020] Therefore, this application has at least the following beneficial effects: This application embodiment can filter the communication definition file of the target vehicle based on the identifier of the target vehicle controller, establish the output file of the target vehicle controller, and extract the communication information of at least one communication signal in the target vehicle controller from the filtered communication definition file. Based on the communication information, corresponding interface signals and signal buffer interface definitions are dynamically generated. The signal type of at least one communication signal is determined based on the signal node, specifically whether it is a receiving signal or a transmitting signal. Then, based on the signal type, the corresponding communication code generation template is called, and the signal parameters, interface signals, and buffers are filled into the communication code generation template. The filled communication code generation template, interface signals, and signal buffer interface definitions are written into the output file, thereby automatically generating the communication code of the target vehicle controller. This eliminates the need for developers to manually write code and build simulation modeling models, reducing the probability of errors and complexity, thus shortening the development cycle. Furthermore, different types of communication definition files can be switched to adapt to different projects or network changes, improving development flexibility. Therefore, it solves the technical problems of poor flexibility, long development cycles, high complexity, and susceptibility to errors in related technologies.
[0021] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0022] The above and / or additional aspects and advantages of this application will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, wherein: Figure 1 This is a flowchart of the vehicle controller communication code generation method provided according to an embodiment of this application; Figure 2 This is an execution flowchart of the first template provided according to an embodiment of this application; Figure 3 This is an execution flowchart of the second template provided according to an embodiment of this application; Figure 4 This is a flowchart of a method for generating communication code for an on-board controller according to an embodiment of this application; Figure 5 This is an example diagram of an on-board controller communication code generation device provided according to an embodiment of this application; Figure 6 This is a schematic diagram of the structure of an electronic device provided according to an embodiment of this application. Detailed Implementation
[0023] The embodiments of this application are described in detail below. Examples of these embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions throughout. The embodiments described below with reference to the accompanying drawings are exemplary and intended to explain this application, and should not be construed as limiting this application.
[0024] The following description, with reference to the accompanying drawings, describes a method, apparatus, device, medium, and product for generating communication codes for an on-board controller according to embodiments of this application. To address the problems of poor flexibility, high complexity, error-proneness, and long development cycles associated with hand-writing CAN communication intermediate layer code or Simulink-based development mentioned in the background, this application provides a method for generating communication code for an onboard controller. This method filters the communication definition file of the target vehicle based on the identifier of the target onboard controller, establishes the output file of the target onboard controller, extracts communication information of at least one communication signal from the filtered communication definition file, dynamically generates corresponding interface signals and signal buffer interface definitions based on the communication information, determines the signal type of at least one communication signal (whether it is a receiving signal or a transmitting signal) based on the signal node, and then calls the corresponding communication code generation template based on the signal type. The signal parameters, interface signals, and buffers are filled into the communication code generation template, and the filled communication code generation template, interface signals, and signal buffer interface definitions are written into the output file, thereby automatically generating the communication code for the target onboard controller. This eliminates the need for developers to hand-write code and build simulation models, reducing the probability of errors and complexity, thus shortening the development cycle. Furthermore, it allows switching between different types of communication definition files to adapt to different projects or network changes, improving development flexibility. This solves the problems of poor flexibility, long development cycle, high complexity and error susceptibility in related technologies.
[0025] Specifically, Figure 1 This is a flowchart illustrating a method for generating communication codes for an on-board controller, as provided in an embodiment of this application.
[0026] The communication in this application mainly refers to CAN communication and CANFD (CAN with Flexible Data-Rate) communication. The following embodiments mainly take CAN network as an example.
[0027] like Figure 1 As shown, the method for generating communication codes for the vehicle controller includes the following steps: In step S101, the communication definition file of the target vehicle and the identifier of the target vehicle controller are obtained.
[0028] The communication definition file is the DBC (Database CAN) file of the vehicle network, used to store CAN matrix-related information; the target on-board controller is the specific controller in the vehicle, which is the controller corresponding to the communication code that the user wants to generate.
[0029] In step S102, communication definition files are filtered based on the identifier of the target vehicle controller, and output files of the target vehicle controller are created. Communication information of at least one communication signal in the target vehicle controller is extracted from the filtered communication definition files, wherein the communication information includes signal nodes and signal parameters.
[0030] The output file includes a header file and an executable file, which are code files; the communication signal is the effective data unit transmitted in the vehicle CAN network, such as vehicle speed, transmitter speed signal, etc.; the signal parameters include at least one of name, address, length, start bit, offset, and coefficient.
[0031] It is understood that the embodiments of this application can filter communication definition files based on the identifier of the target vehicle controller, establish an output file containing header files and executable files, and extract communication information of at least one communication signal in the target vehicle controller from the filtered communication definition files.
[0032] In step S103, a corresponding interface signal and signal buffer interface definition are generated based on the communication information of at least one communication signal.
[0033] Among them, the interface signal is a signal that can interact with the BSW (Basic Software) and ASW (Application Software) of the vehicle controller, that is, the adapter carrier of communication signals and controller interface; the signal buffer interface definition is a set of exclusive access rules for the data type, memory address, read and write permissions of the signal buffer. Its function is to enable the generated communication code to accurately read and write the intermediate data in it, support the subsequent unpacking, parsing, encoding and packaging operations in the template, and connect the controller interface variables to ensure smooth data flow and direct integration.
[0034] It is understood that, according to the embodiments of this application, the corresponding interface signal and signal buffer interface definition can be dynamically generated based on the communication information of at least one communication signal, so that the data can be filled into the corresponding communication code generation template to generate communication code and integrated into the controller.
[0035] In step S104, the signal type of at least one communication signal is determined based on the signal node, and the corresponding communication code generation template is called based on the signal type to fill the communication code generation template with signal parameters, interface signals and buffers.
[0036] The signal types include a first type and a second type. The first type is a received signal, and the second type is a transmitted signal. The communication code generation template includes a first template and a second template. The first template is a packet unpacking and parsing template, and the second template is an encoding and packaging template. Both can be written in C language.
[0037] It is understood that, according to the embodiments of this application, the signal type of at least one communication signal can be determined based on the signal node, specifically whether it is a receiving signal or a transmitting signal, and then the corresponding communication code generation template is called based on the signal type to fill the communication code generation template with signal parameters, interface signals and buffers.
[0038] In some embodiments of this application, the corresponding communication code generation template is called based on the signal type, including: if the signal type is a first type, then the first template is called; if the signal type is a second type, then the second template is called.
[0039] It is understood that, according to the embodiments of this application, the corresponding communication code can be called to generate a template based on the signal type, so as to ensure that the signal can be correctly parsed or packaged. In some embodiments of this application, the first template includes: clearing the signal buffer to zero, iterating through the communication signals in the signal receiving buffer, assigning the communication signals in the signal receiving buffer bit by bit to the signal buffer according to the start bit and length of the communication signals, calculating the interface signal value of the communication signals according to the offset and coefficient of the communication signals in the signal buffer, and assigning the interface signal value to the corresponding interface variable. The second template includes: Clear the signal buffer to zero, loop through the interface signal values in the signal buffer, calculate the original value of the communication signal based on the offset, coefficient, and interface signal value of the communication signal, store the original value in the signal buffer, determine the position of the original value in the signal transmission buffer based on the start bit and length of the communication signal, and assign the original value of the communication signal in the signal buffer bit by bit to the signal transmission buffer.
[0040] The signal transmission buffer is a CAN transmission buffer, and the signal reception buffer is a CAN reception buffer. The buffer is a preset memory storage area in the vehicle controller. The CAN transmission buffer is used to temporarily store the spliced original binary data to be sent from the target vehicle controller to the vehicle CAN bus. The CAN reception buffer is used to temporarily store the original binary data transmitted from the vehicle CAN bus to the target vehicle controller.
[0041] It is understood that the embodiments of this application can achieve bidirectional format conversion between the original communication signal and the controller interface signal through templates, and the processing is carried out by looping during the encoding or parsing process, which can reduce the amount of code and improve code reusability and readability.
[0042] Specifically, the embodiments of this application describe the received first template, i.e., the signal unpacking and parsing process, as follows: Figure 2 As shown, the signal buffer is cleared, and each bit is iterated through in a loop. Based on the start bit position and signal length, each bit of the input CAN receive buffer is assigned to the signal buffer. Then, the CAN signal is multiplied by a coefficient and the offset is added to calculate the signal value, which is then assigned to the interface signal.
[0043] The process of encoding and packaging the transmitted signal is as follows: Figure 2 As shown, the signal buffer is cleared to zero, the signal interface is subtracted from the offset and then multiplied by the derivative of the coefficient and stored in the signal buffer. By looping through each bit, each bit of the signal buffer is assigned to the CAN transmit buffer according to the start bit position and the signal length.
[0044] In step S105, the filled communication code generation template, interface signals, and signal buffer interface definitions are written into the output file to generate the communication code of the target vehicle controller.
[0045] It is understood that the embodiments of this application can write the filled communication code generation template, interface signal and signal buffer interface definition into the output file, thereby automatically generating the communication code of the target vehicle controller. This eliminates the need for developers to write code by hand and build simulation modeling (such as Simulink) models, reducing the probability of errors and complexity, thereby shortening the development cycle. Furthermore, different types of communication definition files can be switched to adapt to different projects or network changes, improving development flexibility.
[0046] In some embodiments of this application, before writing the filled communication code generation template, interface signal, and signal buffer interface definition into the output file, the method further includes: obtaining an interface signal definition table; if an interface signal definition table is obtained, extracting the signal names from the interface signal definition table, and when the interface signal contains the signal names from the interface signal definition table, determining the interface variable of the target vehicle controller corresponding to the interface signal based on the interface signal definition table; if an interface signal definition table is not obtained, generating the signal names of the interface signals based on preset rules, determining the interface variable of the target vehicle controller corresponding to the interface signal based on the signal names; and writing the correspondence between the interface signals and the interface variables of the target vehicle controller into the output file.
[0047] The interface signal definition table is an external definition table and an association rule table, containing the correspondence between signal names and controller interface variables, used to accurately map interface signals to signal buffer interface definitions. The automatically generated interface signal names are interface signal names autonomously defined by Python scripts based on communication signal information in DBC files, without relying on the external definition table. The preset rules are the default adaptation rules of the controller software architecture. The correspondence between interface signals and controller BSW and ASW interface variables ensures that the generated code can directly interact with the controller.
[0048] It is understood that the embodiments of this application can support script files to automatically define variable names, or input interface signal definition tables to directly associate with the interface variables of the controller, in order to adapt to different hardware scenarios, and map the interface signals and signal buffer interface definitions to the corresponding interface variables of the target vehicle controller, and then write the correspondence between the interface signals and the interface variables of the controller into the output file so that the communication code can be directly integrated into the controller in the future.
[0049] In some embodiments of this application, after generating the communication code of the target vehicle controller, the method further includes: writing the communication code into the target vehicle controller, and the target vehicle controller communicating with the communication network of the target vehicle based on the communication code.
[0050] It is understood that, in the embodiments of this application, communication code can be written into the target vehicle controller, and the target vehicle controller can communicate and interact with the communication network of the target vehicle based on the communication code.
[0051] The following specific embodiment describes the vehicle controller communication code generation method of this application. It extracts CAN information from the CAN communication definition file, uses the corresponding C language processing function templates and signal information, and automatically generates the expected communication code, such as... Figure 4 As shown, it includes: 1. Load the DBC file and specify the names of the nodes to be filtered; 2. Create an output file, including header files and executable files; 3. Traverse all messages within the DBC and extract the signal node, name, address, length, start bit, offset, and coefficient; 4. Dynamically generate interface signals and signal buffer interface definitions; 5. Determine whether the signal node is sending or receiving; 6. Depending on whether it is sending or receiving, call the C language code templates for unpacking, parsing, encoding, and repackaging respectively, and fill the CAN signal information into the corresponding positions in the templates; 7. Write the template text to the output file.
[0052] In summary, this application can be used to automatically generate CAN communication-related code. The code functions include CAN signal definition, CAN unpacking, CAN parsing, CAN packetization, and CAN encoding. The specific implementation is described as follows: 1. Write a C language executable code template. This template contains CAN signal definition templates, CAN unpacking, CAN parsing, CAN packetization, and CAN encoding functions. 2. Write a Python script. The Python script calls the CAN communication DBC file to obtain CAN matrix information, including: name, nodes, address, start bit, length, offset, coefficients, etc. It then fills the CAN information into the corresponding C language template, automatically generating CAN communication code; it reads the interface signal definition table and assigns the generated variables to the corresponding interface signals.
[0053] This application allows for the creation of C language CAN communication middleware code by writing scripts in Python, calling C language middleware function templates and vehicle CAN network DBC files. This code can be directly integrated into the vehicle controller. Once the script file is developed, it automatically generates CAN communication middleware code based on the input vehicle CAN network DBC without requiring configuration. Different DBC files can be directly switched for different networks to generate corresponding code, significantly reducing project development time and minimizing software bugs caused by developing a large number of similar CAN communication codes. Furthermore, this application is compatible with both CAN and CANFD communication protocols without requiring software script updates, increasing software adaptability. The script file can automatically define variable names or directly associate variable definition tables with controller BSW and ASW interface variables, enabling one-click integration of the CAN communication function module into the current controller system.
[0054] The vehicle controller communication code generation method of this application can automatically generate CAN code files based on DBC files without manual writing. It uses a C language template plus a Python script to achieve automatic code generation. The Python script reads key information and fills it into the template to generate the code file. The script can automatically define interface signals and complete the entire process of unpacking, parsing, encoding and packaging CAN signals without manual operation. It uses loop traversal to input parameters into the software template, reducing the amount of code and improving code reusability and readability. The script extracts the signal names from the interface signal table, determines whether the signal name is contained, and automatically associates and processes the signal based on the determination.
[0055] The vehicle controller communication code generation method proposed in this application can filter the communication definition file of the target vehicle based on the identifier of the target vehicle controller, establish the output file of the target vehicle controller, extract the communication information of at least one communication signal in the target vehicle controller from the filtered communication definition file, dynamically generate the corresponding interface signal and signal buffer interface definition based on the communication information, determine the signal type of at least one communication signal based on the signal node, specifically whether it is a receiving signal or a transmitting signal, and then call the corresponding communication code generation template based on the signal type, fill the communication code generation template with signal parameters, interface signals and buffers, and write the filled communication code generation template, interface signals and signal buffer interface definitions into the output file, thereby automatically generating the communication code of the target vehicle controller. This eliminates the need for developers to write code manually and build simulation modeling models, reduces the probability of errors and complexity, shortens the development cycle, and allows switching between different types of communication definition files to adapt to different projects or network changes, improving development flexibility.
[0056] Next, the vehicle controller communication code generation apparatus according to an embodiment of this application is described with reference to the accompanying drawings.
[0057] Figure 5 This is a block diagram of an on-board controller communication code generation device according to an embodiment of this application.
[0058] like Figure 5 As shown, the vehicle controller communication code generation device 10 includes: an acquisition module 100, an extraction module 200, a first generation module 300, a filling module 400, and a second generation module 500.
[0059] The acquisition module 100 is used to acquire the communication definition file of the target vehicle and the identifier of the target vehicle controller; the extraction module 200 is used to filter the communication definition file based on the identifier of the target vehicle controller, and to create the output file of the target vehicle controller, and to extract the communication information of at least one communication signal in the target vehicle controller from the filtered communication definition file, wherein the communication information includes signal nodes and signal parameters; the first generation module 300 is used to generate corresponding interface signals and signal buffer interface definitions according to the communication information of at least one communication signal; the filling module 400 is used to determine the signal type of at least one communication signal based on the signal node, and to call the corresponding communication code generation template based on the signal type, and to fill the communication code generation template with signal parameters, interface signals and signal buffer interface definitions; the second generation module 500 is used to write the filled communication code generation template, interface signals and signal buffer interface definitions into the output file to generate the communication code of the target vehicle controller.
[0060] In some embodiments of this application, the vehicle controller communication code generation device 10 of this application embodiment further includes: a determination module.
[0061] The determination module is used to obtain an interface signal definition table before writing the filled communication code generation template, interface signals, and signal buffer interface definitions into the output file. If the interface signal definition table is obtained, the signal names in the interface signal definition table are extracted, and if the interface signal contains a signal name from the interface signal definition table, the interface variable of the target vehicle controller corresponding to the interface signal is determined according to the interface signal definition table. If the interface signal definition table is not obtained, the signal name of the interface signal is generated based on preset rules, and the interface variable of the target vehicle controller corresponding to the interface signal is determined based on the signal name. The correspondence between the interface signal and the interface variable of the target vehicle controller is written into the output file.
[0062] In some embodiments of this application, the vehicle controller communication code generation device 10 of this application embodiment further includes: a writing module.
[0063] The writing module is used to write the communication code of the target vehicle controller after generating the communication code. The target vehicle controller then communicates with the target vehicle's communication network based on the communication code.
[0064] In some embodiments of this application, the signal parameters include at least one of name, address, length, start bit, offset, and coefficient; the signal type includes a first type and a second type, the first type being a received signal and the second type being a transmitted signal; and the communication code generation template includes a first template and a second template.
[0065] In some embodiments of this application, the filling module 400 is further configured to: call the first template if the signal type is a first type; and call the second template if the signal type is a second type.
[0066] In some embodiments of this application, the first template includes: clearing the signal buffer to zero, iterating through the communication signals in the signal receiving buffer, assigning the communication signals in the signal receiving buffer bit by bit to the signal buffer according to the start bit and length of the communication signals, calculating the interface signal value of the communication signals according to the offset and coefficient of the communication signals in the signal buffer, and assigning the interface signal value to the corresponding interface variable. The second template includes: Clear the signal buffer to zero, loop through the interface signal values in the signal buffer, calculate the original value of the communication signal based on the offset, coefficient, and interface signal value of the communication signal, store the original value in the signal buffer, determine the position of the original value in the signal transmission buffer based on the start bit and length of the communication signal, and assign the original value of the communication signal in the signal buffer bit by bit to the signal transmission buffer.
[0067] It should be noted that the foregoing explanation of the embodiment of the vehicle controller communication code generation method also applies to the vehicle controller communication code generation device of this embodiment, and will not be repeated here.
[0068] The vehicle controller communication code generation device proposed in this application can filter the communication definition file of the target vehicle based on the identifier of the target vehicle controller, establish the output file of the target vehicle controller, extract the communication information of at least one communication signal in the target vehicle controller from the filtered communication definition file, dynamically generate the corresponding interface signal and signal buffer interface definition based on the communication information, determine the signal type of at least one communication signal based on the signal node (specifically, whether it is a receiving signal or a transmitting signal), and then call the corresponding communication code generation template based on the signal type. The signal parameters, interface signals, and buffers are filled into the communication code generation template, and the filled communication code generation template, interface signals, and signal buffer interface definitions are written into the output file, thereby automatically generating the communication code of the target vehicle controller. This eliminates the need for developers to manually write code and build simulation modeling models, reducing the probability of errors and complexity, thus shortening the development cycle. Furthermore, it allows switching between different types of communication definition files to adapt to different projects or network changes, improving development flexibility.
[0069] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of this application. The electronic device may include: The memory 601, the processor 602, and the computer program stored on the memory 601 and capable of running on the processor 602.
[0070] When the processor 602 executes the program, it implements the vehicle controller communication code generation method provided in the above embodiments.
[0071] Furthermore, electronic devices also include: Communication interface 603 is used for communication between memory 601 and processor 602.
[0072] The memory 601 is used to store computer programs that can run on the processor 602.
[0073] The memory 601 may include high-speed RAM memory, and may also include non-volatile memory, such as at least one disk storage device.
[0074] If the memory 601, processor 602, and communication interface 603 are implemented independently, then the communication interface 603, memory 601, and processor 602 can be interconnected via a bus to complete communication between them. The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 6 The bus is represented by a single thick line, but this does not mean that there is only one bus or one type of bus.
[0075] Optionally, in a specific implementation, if the memory 601, processor 602, and communication interface 603 are integrated on a single chip, then the memory 601, processor 602, and communication interface 603 can communicate with each other through an internal interface.
[0076] The processor 602 may be a central processing unit (CPU), an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application.
[0077] This application also provides a computer-readable storage medium storing a computer program or instructions thereon, which, when executed by a processor, implements the above-described vehicle controller communication code generation method.
[0078] This application also provides a computer program product, including a computer program or instructions, which, when executed, implement the above-described vehicle controller communication code generation method.
[0079] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples. Moreover, without contradiction, those skilled in the art can combine and integrate the different embodiments or examples described in this specification, as well as the features of different embodiments or examples.
[0080] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this application, "N" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0081] Any process or method described in the flowchart or otherwise herein can be understood as representing a module, segment, or portion of code comprising one or N executable instructions for implementing custom logic functions or processes, and the scope of the preferred embodiments of this application includes additional implementations in which functions may be performed not in the order shown or discussed, including substantially simultaneously or in reverse order depending on the functions involved, as should be understood by those skilled in the art to which embodiments of this application pertain.
[0082] It should be understood that the various parts of this application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, the N steps or methods can be implemented using software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or more of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (FPGAs), field-programmable gate arrays (FPGAs), etc.
[0083] Those skilled in the art will understand that all or part of the steps of the methods in the above embodiments can be implemented by a program instructing related hardware. The program can be stored in a computer-readable storage medium, and when executed, the program includes one or a combination of the steps of the method embodiments.
Claims
1. A method for generating communication codes for an on-board controller, characterized in that, Includes the following steps: Obtain the communication definition file of the target vehicle and the identifier of the target vehicle controller; The communication definition file is filtered based on the identifier of the target vehicle controller, and the output file of the target vehicle controller is established. The communication information of at least one communication signal in the target vehicle controller is extracted from the filtered communication definition file, wherein the communication information includes signal nodes and signal parameters. Generate corresponding interface signals and signal buffer interface definitions based on the communication information of at least one of the communication signals; Based on the signal node, determine the signal type of at least one of the communication signals, and based on the signal type, call the corresponding communication code generation template to fill the communication code generation template with the signal parameters, the interface signal, and the signal buffer interface definition. The populated communication code generation template, the interface signals, and the signal buffer interface definitions are written into the output file to generate the communication code for the target vehicle controller.
2. The method for generating communication codes for an on-board controller according to claim 1, characterized in that, Before writing the populated communication code generation template, the interface signals, and the signal buffer interface definitions into the output file, the following steps are also included: Obtain the interface signal definition table; If the interface signal definition table is obtained, the signal names in the interface signal definition table are extracted, and when the interface signal contains the signal names in the interface signal definition table, the interface variable of the target vehicle controller corresponding to the interface signal is determined according to the interface signal definition table. If the interface signal definition table is not obtained, the signal name of the interface signal is generated based on the preset rules, and the interface variable of the target vehicle controller corresponding to the interface signal is determined based on the signal name. Write the correspondence between the interface signals and the interface variables of the target vehicle controller into the output file.
3. The method for generating communication codes for an on-board controller according to claim 1, characterized in that, After generating the communication code for the target vehicle controller, the following is also included: The communication code is written into the target vehicle controller, and the target vehicle controller interacts with the communication network of the target vehicle based on the communication code.
4. The method for generating communication codes for an on-board controller according to claim 1, characterized in that, The signal parameters include at least one of name, address, length, start bit, offset, and coefficient. The signal type includes a first type and a second type, where the first type is a received signal and the second type is a transmitted signal. The communication code generation template includes a first template and a second template.
5. The method for generating communication codes for an on-board controller according to claim 4, characterized in that, The step of calling the corresponding communication code generation template based on the signal type includes: If the signal type is the first type, then the first template is invoked; If the signal type is the second type, then the second template is invoked.
6. The method for generating communication codes for an on-board controller according to claim 5, characterized in that, The first template includes: The signal buffer is cleared to zero. The communication signals in the signal receiving buffer are iterated in a loop. According to the start bit and length of the communication signal, the communication signal in the signal receiving buffer is assigned bit by bit to the signal buffer. The interface signal value of the communication signal is calculated according to the offset and coefficient of the communication signal in the signal buffer. The interface signal value is assigned to the corresponding interface variable. The second template includes: The signal buffer is cleared to zero. The interface signal values in the signal buffer are iterated in a loop. The original value of the communication signal is calculated based on the offset of the communication signal, the coefficient, and the interface signal value. The original value is stored in the signal buffer. The position of the original value in the signal transmission buffer is determined based on the start bit and length of the communication signal. The original value of the communication signal in the signal buffer is assigned bit by bit to the signal transmission buffer.
7. A vehicle-mounted controller communication code generation device, characterized in that, include: The acquisition module is used to acquire the communication definition file of the target vehicle and the identifier of the target vehicle controller; An extraction module is used to filter the communication definition file based on the identifier of the target vehicle controller, and to create the output file of the target vehicle controller. The module extracts communication information of at least one communication signal in the target vehicle controller from the filtered communication definition file, wherein the communication information includes signal nodes and signal parameters. The first generation module is used to generate corresponding interface signals and signal buffer interface definitions based on the communication information of at least one of the communication signals; The filling module is used to determine the signal type of at least one of the communication signals based on the signal node, call the corresponding communication code generation template based on the signal type, and fill the communication code generation template with the signal parameters, the interface signal and the signal buffer interface definition. The second generation module is used to write the filled communication code generation template, the interface signal, and the signal buffer interface definition into the output file to generate the communication code of the target vehicle controller.
8. An electronic device, characterized in that, include: A memory, a processor, and a computer program stored in the memory and executable on the processor, the processor executing the program to implement the vehicle controller communication code generation method as described in any one of claims 1-6.
9. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, The computer program or instructions are executed by a processor to implement the vehicle controller communication code generation method as described in any one of claims 1-6.
10. A computer program product, comprising a computer program or instructions, characterized in that, When the computer program or instructions are executed, they implement the vehicle controller communication code generation method as described in any one of claims 1-6.