Method, apparatus, device and storage medium for generating code

By automatically reading message information from DBC files and generating code blocks, the inefficiency and errors caused by manual analysis in existing technologies are solved, achieving efficient and accurate automatic code generation.

CN117591151BActive Publication Date: 2026-08-04CHERY AUTOMOBILE CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHERY AUTOMOBILE CO LTD
Filing Date
2023-11-17
Publication Date
2026-08-04

AI Technical Summary

Technical Problem

In existing technologies, the code generation of DBC files relies on manual analysis, which leads to inefficiency and a high risk of errors.

Method used

By automatically reading the message information in the DBC file, code blocks are generated, including reading the signal start bit and signal bit width, and automatically generating code blocks.

Benefits of technology

It improves code generation efficiency, reduces human error, and ensures code accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117591151B_ABST
    Figure CN117591151B_ABST
Patent Text Reader

Abstract

The application discloses a method, device and equipment for generating code and a storage medium, and belongs to the field of communication technology. The method comprises the following steps: reading message information corresponding to a plurality of messages in a DBC file, any message in the plurality of messages being used for transmitting at least one signal, and the message information of any message comprising a signal start bit and a signal bit width of the at least one signal; and acquiring a first code block of any message based on the signal start bit and the signal bit width of the at least one signal corresponding to the any message, the first code block comprising code lines corresponding to the at least one signal, and the code line of any signal being used for generating or identifying any signal in any message. The method automatically reads the DBC file to realize automatic generation of the code block, replaces manual operation of a user, improves the generation efficiency of the code block, and can avoid manual errors, thereby improving the accuracy of the generated code block.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of communication technology, and in particular to a method, apparatus, device, and storage medium for generating code. Background Technology

[0002] In scenarios requiring data communication and distributed control, CAN (Controller Area Network) has seen rapid development as a serial communication protocol. For example, in the automotive field, CAN enables data communication between different subsystems such as controllers, sensors, and actuators within a vehicle. A DBC (Database CAN) file is used to describe information such as signals, messages, data length, and cycle time in CAN communication. Therefore, the code that generates or identifies messages during CAN communication needs to be based on the DBC file.

[0003] In related technologies, users need to manually analyze DBC files and generate code for the CAN communication process based on the analysis results. This manual operation leads to low code generation efficiency and is prone to errors due to user misunderstanding or distraction. Summary of the Invention

[0004] This application provides a method, apparatus, device, and storage medium for generating code, which can be used to solve problems existing in related technologies. The technical solution is as follows:

[0005] On the one hand, a method for generating code is provided, the method comprising:

[0006] Read message information corresponding to multiple messages in the database controller local area network (DBC) file, where any one of the multiple messages is used to transmit at least one signal, and the message information of any one message includes the signal start bit and signal bit width of the at least one signal;

[0007] Based on the signal start bit and signal bit width of at least one signal corresponding to any message, a first code block of the message is obtained. The first code block includes code lines corresponding to the at least one signal. The code line of any signal is used to generate or identify the signal in the message.

[0008] On the other hand, an apparatus for generating code is provided, the apparatus comprising:

[0009] The reading module is used to read message information corresponding to multiple messages in the database controller local area network (DBC) file. Each of the multiple messages is used to transmit at least one signal, and the message information of each message includes the signal start bit and signal width of the at least one signal.

[0010] The acquisition module is configured to acquire a first code block of any message based on the signal start bit and signal bit width of at least one signal corresponding to any message. The first code block includes code lines corresponding to the at least one signal, and the code line of any signal is used to generate or identify the any signal in the message.

[0011] On the other hand, a computer device is also provided, the computer device including a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to enable the computer device to implement any of the above-described methods for generating code.

[0012] On the other hand, a computer-readable storage medium is also provided, wherein at least one computer program is stored therein, the at least one computer program being loaded and executed by a processor to enable a computer to implement any of the above-described methods for generating code.

[0013] On the other hand, a computer program product or computer program is also provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform any of the above-described methods for generating code.

[0014] The technical solution provided in this application has at least the following beneficial effects:

[0015] The technical solution provided in this application embodiment realizes the automatic generation of code blocks by automatically reading DBC files, replacing manual operation by users, improving the generation efficiency of code blocks, avoiding human error, and improving the accuracy of generated code blocks. Attached Figure Description

[0016] To more clearly illustrate the technical solutions in the embodiments of this application, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0017] Figure 1This is a schematic diagram of an implementation environment provided in an embodiment of this application;

[0018] Figure 2 This is a flowchart of a code generation method provided in an embodiment of this application;

[0019] Figure 3 This is a flowchart of obtaining message information provided in an embodiment of this application;

[0020] Figure 4 This is another flowchart for obtaining message information provided in an embodiment of this application;

[0021] Figure 5 This is a byte splicing flowchart provided in an embodiment of this application;

[0022] Figure 6 This is a flowchart of a code line sorting method provided in an embodiment of this application;

[0023] Figure 7 This is a flowchart of a code line merging process provided in an embodiment of this application;

[0024] Figure 8 This is a schematic diagram of the structure of a code generation device provided in an embodiment of this application;

[0025] Figure 9 This is a schematic diagram of the structure of a server provided in an embodiment of this application;

[0026] Figure 10 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. Detailed Implementation

[0027] To make the objectives, technical solutions, and advantages of this application clearer, the embodiments of this application will be described in further detail below with reference to the accompanying drawings.

[0028] It should be noted that the terms "first," "second," etc. (if applicable) used in the specification of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. The implementations described in the following exemplary embodiments do not represent all implementations consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application.

[0029] With the development of communication technology, the update and iteration process of databases is accelerating. This rapid database updates necessitate corresponding updates to the code generated in the CAN communication process based on the database. Current technologies require users to manually analyze the database file and inject or replace the analysis results into relevant code blocks in the controller. This manual operation leads to inefficient code generation and is prone to errors due to user misunderstanding or distraction. Therefore, an automated and standardized method is urgently needed to generate corresponding controller code based on database files.

[0030] This application provides a method for generating code. Please refer to the following embodiments. Figure 1 The diagram illustrates an implementation environment for a code generation method provided in this application. This implementation environment may include: computer device 11.

[0031] This application does not limit the product form of the computer device 11. Regardless of the product form, the computer device 11 only needs to be able to generate corresponding code based on the DBC file. For example, the computer device 11 can be a terminal or a server. The terminal can be any electronic product that can interact with the user through one or more methods such as a keyboard, touchpad, touch screen, remote control, voice interaction, or handwriting device, such as PC (Personal Computer), mobile phone, smartphone, PDA (Personal Digital Assistant), wearable device, PPC (Pocket PC), tablet computer, smart car system, smart TV, smart speaker, etc. The server can be a single server, a server cluster composed of multiple servers, or a cloud computing service center. Optionally, the computer device 11 can be a combination of a terminal and a server, with the terminal and server establishing a communication connection through a wired or wireless network.

[0032] Those skilled in the art should understand that the computer device 11 described above is merely an example, and other existing or future computer devices 11 that are applicable to this application should also be included within the scope of protection of this application, and are hereby incorporated by reference.

[0033] See Figure 2 , Figure 2 This application provides a flowchart of a method for generating code, which can be applied to... Figure 1 The implementation environment shown is, for example, by Figure 1 The computer device 11 shown executes this method. For example... Figure 2 As shown, the method includes, but is not limited to, the following steps 201 and 202.

[0034] Step 201: Read the message information corresponding to multiple messages in the DBC file. Each message is used to transmit at least one signal. The message information of each message includes the signal start bit and signal width of at least one signal.

[0035] The DBC file is the database file for CAN. CAN, as a serial communication protocol, defines a standardized way for multiple devices to communicate and share information within the same network. This application does not limit the application scenario of the generated code; this application uses the method applied to a vehicle as an example for illustration.

[0036] A vehicle's DBC file is a database file for the vehicle's electronic systems. It defines information such as data format, message ID, signal name, signal length, and signal type in the vehicle control network, enabling different controllers to communicate using a unified data format and achieve various functions. For example, when a vehicle malfunctions, the engine control module can send fault codes to an on-board diagnostic tool, which can then identify the cause of the fault based on the received codes. Furthermore, DBC files can be used to debug and test the vehicle control system. By examining the communication data between modules, existing problems can be identified and repaired accordingly.

[0037] The DBC file in this embodiment can be a DBC file output by the Electrical / Electronic Architecture. The Electrical / Electronic Architecture encompasses the hardware and software of the vehicle's computing and control systems, sensors, communication networks, electrical distribution systems, etc. It integrates various subsystems in an orderly manner through specific logic and specifications, forming an organic whole that achieves complex functions. In the Electrical / Electronic Architecture, the DBC file is used to define and control the communication between various Electronic Control Units (ECUs), i.e., communication in the CAN network, ensuring the correct transmission and parsing of data.

[0038] Before reading a DBC file, the DBC file address needs to be obtained, and the DBC file is read based on the DBC file address. This application does not limit the method of obtaining the DBC file address. For example, the DBC file address information can be obtained through input from external hardware on a computer device, such as a keyboard or mouse.

[0039] The DBC file contains multiple data lines, each containing message information for the various messages required for the generated code. Each message has a unique identifier. For each message, the corresponding message information includes the start bit and signal width for each signal. The start bit indicates which bit in the message begins reading the data for that signal, and the signal width indicates how many bits that signal occupies. For example, if a message indicates that it contains a signal with a start bit of 8 and a width of 7, then bits 8 to 14 of the message represent that signal.

[0040] For example, the message information also includes a message identifier. The process of reading the message information corresponding to multiple messages in the DBC file may include: reading multiple message identifiers in the DBC file, with one message identifier corresponding to one message; reading the DBC file again, and if the matching information corresponding to any message identifier among the multiple message identifiers is read, determining the first data line where the first key is located, where the first key indicates the signal start bit and signal width, wherein the matching information indicates the data line in the DBC file that includes any identifier, and obtaining the signal start bit and signal width of the message corresponding to any message identifier based on the content of the first data line.

[0041] This application does not limit the message identifier; it only needs to be able to distinguish different messages. For example, the message identifier may include at least one of message ID (identification) and message name. The message ID is a unique identifier used to identify the message on the CAN network, and the message name is a descriptive string that, in addition to identifying the message, also indicates the function or purpose of the message.

[0042] For example, the process of reading multiple message identifiers in a DBC file may include reading the second data line in the DBC file where the second key is located, where the second key indicates a message identifier, and obtaining the message identifiers corresponding to the multiple messages based on the content of the second data line.

[0043] In one possible implementation, taking a message identifier that includes a message ID and a message name as an example, the second key can indicate the message ID and the message name. The second data line containing the second key is determined in the content of the DBC file. The second key indicates the message ID and the message name. The message ID and message name corresponding to the message information are read based on the content of the second data line.

[0044] See Figure 3The flowchart shown illustrates a process for obtaining message information. The second key includes the keywords "BO_", "BA_", and "CM_". The DBC file is read line by line. It checks if the keyword "BO_" exists in any data line. If not, the process continues reading line by line. If a data line contains "BO_", it checks if it contains both "BA_" and "CM_". If either "BA_" or "CM_" exists, the line is not a message ID definition line. For example, if a data line contains both "BO_" and "BA_", it indicates the message attribute definition and does not include a message ID or message name. If a data line contains both "BO_" and "CM_", it is a message annotation and does not include a message ID or message name.

[0045] In a DBC file, if the keyword "BO_" exists in a data line but the keywords "BA_" and "CM_" do not, this data line defines the message ID. This data line includes the message ID and message name. Based on the data line containing the message ID and message name, the message ID and message name are retrieved. One message corresponds to one message ID, and one message corresponds to one message name. For example, the process of retrieving the message ID and message name based on a data line containing the message ID and message name includes determining whether the seventh character of the data line content is a space. If it is a space, the message ID and message name of messages with a DLC (Date Length Code) less than or equal to 9 are retrieved. If it is not a space, the message ID and message name of messages with a DLC greater than 9 are retrieved. Using a DLC of 9 as the basis for message segmentation is only an example; in specific applications, it can be set according to different needs. Similarly, the seventh character is only one way to indicate whether the DLC is 9; it is only an example and can be set according to different needs in specific applications.

[0046] In this embodiment, the message information also includes the message's transmit / receive mode and the message's DLC. Given the message ID and message name, the transmit / receive mode and DLC are obtained by checking key characters. The DLC represents the length of the data fields in the message, and the retrieval method is determined based on whether the message's DLC exceeds a length threshold. For example, ... Figure 3As shown, taking the key character ":" and the length threshold of 9 as an example, the position of the key character ":" in the data line containing the message ID and message name is determined, and it is determined whether the third position after the key character ":" is a space. If the third position after ":" is not a space, it means that the message's DLC is greater than 9, and the message information is obtained according to the first acquisition method; if the third position after ":" is a space, it means that the message's DLC is less than or equal to 9, and the message information is obtained according to the second acquisition method.

[0047] The first acquisition method can be to obtain message information such as the message transmission / reception mode, signal start bit, and signal width based on the data line containing "BO_". The second acquisition method can be to obtain message information such as the message transmission / reception mode, signal start bit, and signal width based on data lines other than the data line containing "BO_". This application embodiment does not limit the specific process of the first and second acquisition methods, and can be adjusted according to the needs of the specific data processing process.

[0048] For example, the content of a data line in the DBC file that contains the keyword "BO_" but does not contain the keywords "BA_" and "CM_" is BO_201959408 MSG1: 8 VCU_Vehicle_Control_Unit. Here, the message ID is "201959408", the message name is "MSG1", the key character is ":", the message DLC is 8 bytes, and the message sender is VCU_Vehicle_Control_Unit.

[0049] Optionally, multiple message lists can be generated based on the message identifiers of multiple messages. Each message list corresponds to one message, and each message list can include the message name and message information of the corresponding message. For example, a message ID list and a message name list are determined based on the obtained message ID and message name. The first data line containing the first key indicating the start of the signal and the signal width is then determined sequentially in the content of the DBC file according to the message ID list and message name list. The signal start of the message and the signal width are obtained based on the content of the first data line, and the obtained signal start of the message and signal width are added to the corresponding message ID list or message name list. Optionally, the message information may also include a signal name, which is used to identify different signals or describe the function of the signals in the message.

[0050] See Figure 4The flowchart shown illustrates a process for obtaining message information. After generating a message ID list and a message name list based on the corresponding message ID and message name, the contents of a DBC file are read line by line. When reading each data line, it is determined whether there are any unprocessed messages in the message ID list and message name list. If unprocessed messages exist, the message ID or message name corresponding to the unprocessed message is used as matching information for a query. This embodiment does not limit the format of the matching information; for example, the matching information can be BO_Message ID + space + message name.

[0051] If a matching information is found, the vehicle program determines that the data row contains information about the signal corresponding to the message name or message ID. When a matching information for a message is found, the index count for that message is incremented by 1 and recorded, indicating that a new message has been processed, to prevent duplicate processing of the same message or omission of messages. Regardless of whether a matching information is found or not, the signal name, signal start bit, and signal width of at least one signal corresponding to the message ID or message name are retrieved based on the first key. For example, the first key may include "SG_" and ":", meaning "SG_" and ":" are used as search conditions. When "SG_" and ":" are retrieved, the content of the data row corresponding to "SG_" and ":" is the corresponding signal name, signal start bit, and signal width.

[0052] Optionally, for each acquired signal, the signal index is incremented by 1 and recorded, while the intermediate variables for the acquired signal name, signal start bit, and signal width are cleared to prepare for processing the next signal. After acquiring the signal name, signal start bit, and signal width, or if "SG_" and ":" are not found, the acquired signal name, signal start bit, and signal width are stored in the message ID list and / or message name list. The process of acquiring message information based on the DBC file is repeated until the last message is processed.

[0053] Step 202: Based on the signal start bit and signal bit width of at least one signal corresponding to any message, obtain the first code block of any message. The first code block includes code lines corresponding to at least one signal. The code line of any signal is used to generate or identify any signal in any message.

[0054] When message information from multiple messages is obtained, the first code block of any message can be retrieved based on the message information of any given message, and thus the first code blocks corresponding to each of the multiple messages can be retrieved. A module in a CAN network possesses at least one first code block, which can be used to generate messages to be sent to other modules, thereby enabling communication between two or more modules.

[0055] For example, in the process of obtaining the first code block corresponding to multiple messages, the index count of the message ID is incremented by 1 for each first code block generated for a message, until the index count is greater than the total number of messages. If the multiple messages are stored as a list of message IDs, this process continues until the index count exceeds the length of the message ID list, indicating that all messages have been traversed. The message's send / receive mode is used to determine whether it is a receiving or sending message, and different processing methods are selected based on the different send / receive modes.

[0056] Optionally, when the message's transmit / receive mode indicates receive mode, the message is a receive message. In this case, the identifier ^^RX^^ is output to the corresponding code block. This identifier is used to determine the processing method for subsequent sorting or merging steps, and then the processing of the byte containing the signal is determined based on the signal's bit width. The terminal device can calculate and concatenate the first code block using the obtained bit width, byte number, and displacement. The calculation and concatenation process can be found in [reference needed]. Figure 5 .

[0057] Furthermore, before determining the transmit / receive mode, the message type needs to be determined. If the message type is a diagnostic message, since diagnostic messages are data formats used for network troubleshooting and performance analysis, not for CAN communication, the first code block is not generated for diagnostic messages. The processing logic for sending messages is similar to that for receiving messages, but there is a difference in the output format. When the transmit / receive mode indicator is set to send mode, the process enters send mode and outputs a different identifier ^^TX^^.

[0058] See Figure 5 The flowchart shown illustrates a byte concatenation process, using a list of message IDs as an example. Since the index of the first code block of each generated message is incremented by 1, the loop iterates through all messages, using the condition that the index count is less than the length of the message ID list. For each message, if the message ID is not a diagnostic ID (i.e., the message is not a diagnostic message), the send / receive mode is further determined. If it is a diagnostic message, the index count is incremented by 1. If the send / receive mode is receive (i.e., the message is a receive message), all signals under that message ID, along with their corresponding start bits, bit widths, etc., are read sequentially. The index count j of each signal is then checked to ensure it is greater than the number of signals contained in the message, thus preventing omissions.

[0059] Different processing methods are used for signals with different signal widths. This application does not limit the signal width in its embodiments. For example, taking a byte containing 8 bits as an example, signals can be categorized based on their signal width into signals with a width of 8 bits or less, signals with a width greater than 8 bits and less than or equal to 16 bits, and signals with a width greater than 16 bits and less than or equal to 24 bits. For signals with a width of 8 bits or less, the processing method for signals with a width of 8 bits or less is used; for signals with a width greater than 8 bits and less than or equal to 16 bits, the processing method for signals with a width greater than 8 bits and less than or equal to 16 bits is used, and so on.

[0060] For signals with a bit width greater than 16 and less than or equal to 24, the bit width is greater than the number of bits in two complete bytes. Therefore, the signal may span four bytes. Correspondingly, a processing method can be adopted where the signal bit width is greater than 16 and less than or equal to 24 and the signal spans 4 bytes, or a processing method where the signal bit width is greater than 16 and less than or equal to 24 and the signal does not span 4 bytes. This application does not specifically limit the processing method for different signals in its embodiments. Examples of embodiments with a bit width less than or equal to 8 and a bit width greater than 8 and less than or equal to 16 can be referred to below. For the processing method of signals with a bit width greater than 16, please refer to the following examples, which will not be repeated here.

[0061] If the transmit / receive mode is "transmit", meaning the message is a sent message, read all signals under the message ID one by one, as well as the start bit, bit width, and other information of the corresponding signals, to determine whether the index number j of the signal is greater than the number of signals contained in the message, thereby avoiding omissions.

[0062] Different processing methods are used for signals with different signal widths. Taking a byte containing 8 bits as an example, signals can be divided into signals with a width of less than or equal to 8 bits and signals with a width greater than 8 bits and less than or equal to 16 bits, etc. This application does not limit the signal width. For signals with a width of less than or equal to 8 bits, the processing method for signals with a width of less than or equal to 8 bits is used; for signals with a width greater than 8 bits and less than or equal to 16 bits, the processing method for signals with a width greater than 8 bits and less than or equal to 16 bits is used, and so on. The processing method for signals transmitting messages can be found in the processing method for signals receiving messages, and will not be repeated here.

[0063] For example, if ^^RX^^ is output to the output file, it indicates that the message is a received message. Different signal processing methods are used to generate code lines according to different signal widths, including but not limited to the following cases.

[0064] Case 1: A byte consists of 8 bits, and the signal bit width is less than or equal to 8.

[0065] In this case, the signal processing method can be to calculate the byte number and offset of the signal based on the signal start bit. The byte number is equal to the integer part of the signal start bit divided by 8, and the offset is equal to the start bit plus 1 minus the bit 0 of the byte minus the signal width. Then, the corresponding code line is output to extract the value of the signal from the corresponding byte. The output can be the following code line corresponding to the signal: TCU_U.{signal}raw=(uint8)(byte[{bytenum1}]>>{offset})&{bitwidth1}.

[0066] Here, "TCU_U.{signal}raw" represents a member variable "{signal}raw" within the structure "TCU_U," where "{signal}" is a placeholder that can be replaced with a specific signal name. "byte[{bytenum1}]" retrieves the element at index "{bytenum1}" from the array named "byte" (bytes), where "{bytenum1}" is a placeholder and needs to be replaced with the specific byte index. ">>{offset}" is a right shift operator that shifts the bits in "byte[{bytenum1}]" to the right by "{offset}" bits, where "{offset}" is a placeholder and needs to be replaced with the specific offset.

[0067] The code `&{bitwidth1}` uses the AND operator `&` to perform a bitwise AND operation between the right-shifted result and `{bitwidth1}`, where `{bitwidth1}` is a placeholder that needs to be replaced with the actual bit width. This clears the high-order bits, retaining only the low-order bits. `(uint8)(...)` is a type conversion, converting the result of the above operation to the `uint8` (eight-bit) type. This line of code retrieves the element at index `{bytenum1}` from the array named `byte`, right-shifts it by `{offset}` bits, clears the high-order bits of the code line, retains only the low-order bits, and finally converts the code line to `uint8` and assigns it to the variable `TCU_U.{signal}raw`, thus outputting the code line.

[0068] Case 2: A byte consists of 8 bits, and the signal bit width is greater than 8 and less than or equal to 16.

[0069] In this second scenario, "bytenum1" indicates byte number 1, meaning which byte from 0 to 64 is being concatenated. "bytenum2" indicates byte number 2, which is equal to byte number 1 plus 1. "bytewidth1" indicates that the signal spans two bytes, representing the width of the first byte, which is equal to the start bit plus 1 minus "bytebit0". "bytewidth1" is equal to "width" (signal bit width) minus "bytewidth1" (byte width 1). "offset" (the offset of the second byte; the offset of the first byte is "bytewidth2") is equal to 8 minus "bytewidth2". The following code line corresponding to this signal can be output:

[0070] "TCU_U.{signal}raw=(uint16)(byte[{bytenum1}]&{bytewidth1})<<{byteoffset1}|(uint16)(byte[{bytenum2}]<<{byteoffset2})&{bytewidth2}".

[0071] For a sent message, ^^TX^^ is output to the output file to indicate that the message is a sent message. Using a similar calculation method as for received messages, the signal value is split into the corresponding bytes, and the corresponding code line is output. For example, the code line could be:

[0072] byte[{bytenum1}]=(uint8)(TCU_Y.{signal}raw>>{byteoffset1})&{bytewidth1};\nbyte[{bytenum2}]=(uint8)(TCU_Y.{signal}raw>>{byteoffset2})&{bytewidth2}.

[0073] For example, there is a received message with message ID 0x123. This message contains a signal named MySignal, with a signal start bit of 8, a signal width of 12, bit 0 as 0, and the receiving object as 0xFFF. Therefore, the byte number is 8 / 8 = 1, and the offset is 8 + 1 - 0 - 12 = -3. Thus, the corresponding line of code can be: TCU_U.MySignalraw = (uint8)(byte[1]>>3)&0xFFF. In this embodiment, the line of code is also simply referred to as code.

[0074] The above describes the implementation process of obtaining the first code block of any message directly based on the signal start bit and signal width of at least one signal corresponding to any message. Optionally, the first code block of any message obtained directly based on the signal start bit and signal width of at least one signal corresponding to any message can be referred to as the second code block. If the second code block is a transmission code block, it can be optimized, for example, by at least one of sorting or merging, and the optimized second code block can be used as the final first code block of any message. If the second code block is a reception code block, it can be directly used as the final first code block of any message.

[0075] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The process of obtaining the first code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message includes: obtaining a second code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message; if the second code block is a transmission code block, sorting the code lines in the second code block according to the size order of the byte numbers of at least one signal to obtain a third code block of any message; and merging code lines with the same byte number in the third code block into a single code line to obtain the first code block of any message.

[0076] The process of obtaining the second code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message can be found in the relevant descriptions of Case 1 and Case 2 in step 202, and will not be repeated here. Optionally, the process of sorting and merging the code lines corresponding to the signals in the message according to the byte number of the signal can be sorting first and then merging, or merging first and then sorting, or the sorting process and the merging process can be performed simultaneously. This embodiment of the application does not limit this, and the corresponding processing method can be selected according to the needs of the data processing process. The second code block can be determined as a sending code block or a receiving code block by the send / receive mode in the message information. That is, the second code block generated by a message with a send / receive mode of receive is a receiving code block, and the second code block generated by a message with a send / receive mode of send is a sending code block.

[0077] For example, the sorting process can be as follows: First, read the second code block line by line, storing each line in a list or other variable. This list may contain data for multiple message IDs. Then, check if the read data contains "^^TX^^". If it does, initialize intermediate variables by setting the index i of the first code block to 0 and setting flag=1, indicating that the first code block needs to be sorted; flag=1 indicates that the message is a sent message. If the read data contains "^^RX^^", set flag to 0, meaning no sorting is needed. Then, sort the content that needs sorting. This ensures that messages are transmitted or processed in the correct order, which guarantees data integrity and accuracy.

[0078] See Figure 6 The flowchart illustrates a code line sorting process. It reads a second code block line by line, storing each line in a list. First, it checks if all lines in the second code block have been read. If so, the sorting process ends. If not, it reads the lines line by line. For any line read, if it contains "^^TX^^", intermediate variables are initialized (the byte list is cleared, the index i of the second code block is set to 0, and flag is set to 1), indicating that sorting is required. If it contains "^^RX^^", flag is set to 0, indicating that sorting is not required.

[0079] Next, the presence of the keyword "byte" and flag=1 are used as the trigger condition for sorting. If the keyword "byte" does not exist, or flag=0, no sorting is performed. Here, "byte" indicates that a byte number exists in the corresponding line of code; if no byte number exists, sorting cannot be performed. The sorting algorithm can be bubble sort, but this embodiment does not limit the sorting algorithm.

[0080] For example, at least one signal in the second code block is marked with an index of 1, 2, 3... The maximum index value in the second code block is used as the loop condition, and the number of iterations does not exceed the maximum index value, thereby traversing all the code lines corresponding to all signals in the second code block. Each byte number read from the second code block is temporarily stored in a byte list; it is then checked whether there is a byte number smaller than the currently read byte number, and the byte numbers are rearranged in size order in the byte list. The sorted third code block is obtained according to the rearranged byte list, where the byte numbers of each code line are arranged in size order. This size order can be from largest to smallest or smallest to largest. Furthermore, after obtaining the third code block, the index i of the code block is incremented by one to indicate that the code block has been sorted, and the third code block is output as code.

[0081] If the second code block is a receiving code block, keep the order of the code lines in the second code block unchanged, and output the second code block as code.

[0082] For example, taking the code to be merged as including code blocks corresponding to two messages, the code blocks corresponding to the two messages are the third code block and the second code block, respectively. The third code block is the sending code block, i.e., the sorted second code block, and the second code block is the receiving code block, i.e., the unsorted second code block. The code line merging process may include reading the second and third code blocks line by line, checking if "^^TX^^" exists in the read code line. If "^^TX^^" exists, the code block is determined to be the sending code block, intermediate variables are initialized, the index number i of the third code block is set to 0, and flag is set to 1, indicating that merging processing is required. If "^^RX^^" exists in the read code line, the code block is determined to be the receiving code block, and flag is set to 0, indicating that merging processing is not required.

[0083] By merging and organizing the bytes corresponding to the sent messages, it is ensured that in the final output code block, code lines with the same byte number are merged into one and arranged in the correct order, thus facilitating subsequent operations such as data transmission, storage, or analysis. Simultaneously, merging code lines with the same byte number helps reduce code redundancy and improve data processing efficiency. After code line merging is completed, the index j of the code line is incremented by one, and the index number determines whether to traverse all code lines.

[0084] See Figure 7The flowchart illustrates a code line merging process. It reads the second and third code blocks line by line, storing each line in a list. First, it checks if all lines in the list have been read. If so, the sorting process ends. If not, it reads the lines line by line. For any read line, if it contains "^^TX^^" (corresponding to the third code block), intermediate variables are initialized: the byte list is cleared, the index i of the third code block is set to 0, and flag is set to 1, indicating that merging is required. If it contains "^^RX^^" (corresponding to the second code block), flag is set to 0, indicating that merging is not required.

[0085] Next, the condition for merging is the presence of the keyword "byte" and flag=1. If the keyword "byte" does not exist, or flag=0, then merging will not be performed. "byte" indicates that the corresponding line of code has a byte number. If the byte number does not exist, merging cannot be performed.

[0086] For example, at least one signal in the third code block is marked with an index of 1, 2, 3... The maximum index of the code line in the third code block is used as the loop condition, meaning the number of indexes for a code line does not exceed the total number of code lines, and the number of loops does not exceed the maximum index value, thus traversing all the code lines corresponding to all signals in the third code block. In the merging process, each byte number read from the third code block is temporarily stored in a byte list. The byte number of each signal is used as the replacement condition. When the replacement condition is met (i.e., the previous byte number stored in the byte list is the same as the current one), the contents of the two lines are merged, and the original contents of the two lines are deleted. The merged content is used as the replacement, that is, the code lines corresponding to signals with the same byte number are merged to obtain the replacement data. The original code lines with the same byte number are deleted from the list storing the read data, and the replacement data is stored in the position of the original code line with the same byte number.

[0087] Repeat the above steps until the last signal corresponding to the last message ID has been processed. Obtain the merged first code block according to the merged byte list. The first code block does not contain signals with the same byte number. For each code line processed, the code line index is incremented by 1 until the code line index exceeds the number of code lines, indicating that all code lines have been read. Optionally, if two code lines are merged, the code line index and the total number of code lines are decremented by 1. Furthermore, after obtaining the first code block, the index i of that code block is incremented by one to indicate that the code block has been merged.

[0088] For example, if two lines of code are read from the signal, both of which are "byte[0]=0x12", then the two lines of code are merged into one line "byte[0]=0x12, 0x12". Then, the data in the list that originally stored the read data is deleted, and the replacement data is stored in the location of the original line of code.

[0089] For example, the second code block with the same order is the receiving code block. The code line content in the second code block remains unchanged, and the first code block and the second code block with unchanged content are used as the code output.

[0090] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The process of obtaining the first code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message includes: obtaining the second code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message; if the second code block is a transmission code block, sorting the code lines in the second code block according to the size order of the byte numbers of at least one signal to obtain the first code block of any message. The process of obtaining the second code block can refer to the relevant description of case one or case two in step 202, and the process of obtaining the first code block of any message can refer to the relevant description of obtaining the third code block based on the above sorting process, and will not be repeated here.

[0091] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The process of obtaining the first code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message includes obtaining the second code block of any message based on the signal start bit and signal width of at least one signal corresponding to any message; if the second code block is a transmit code block, merging code lines with the same byte number in the second code block into a single code line to obtain the first code block of any message. The process of obtaining the second code block can be referred to the relevant description of case one or case two in step 202, and the process of obtaining the first code block of any message can be referred to the relevant description of obtaining the first code block based on the above merging process, and will not be repeated here.

[0092] In summary, the code generation method provided in this application automatically generates code blocks by reading DBC files, replacing manual operation by the user, improving the efficiency of code block generation, avoiding human error, and improving the accuracy of the generated code blocks.

[0093] See Figure 8 This application provides an apparatus for generating code, the apparatus comprising:

[0094] The reading module 801 is used to read the message information corresponding to multiple messages in the DBC file. Each message in the multiple messages is used to transmit at least one signal. The message information of each message includes the signal start bit and signal bit width of at least one signal.

[0095] The acquisition module 802 is used to acquire the first code block of any message based on the signal start bit and signal bit width of at least one signal corresponding to any message. The first code block includes code lines corresponding to at least one signal. The code line of any signal is used to generate or identify any signal in any message.

[0096] In one possible implementation, the message information also includes a message identifier. The reading module 801 is used to read multiple message identifiers in the DBC file, with one message identifier corresponding to one message. The DBC file is read again. If the matching information corresponding to any message identifier among the multiple message identifiers is read, the first data line containing the first key is determined. The first key indicates the signal start bit and signal width, and the matching information indicates the data line in the DBC file that includes any message identifier. The signal start bit and signal width of the message corresponding to any message identifier are obtained based on the content of the first data line.

[0097] In one possible implementation, the reading module 801 is used to read the second data line containing the second key in the DBC file, where the second key indicates the message identifier; and to obtain multiple message identifiers based on the content of the second data line.

[0098] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The acquisition module 802 is used to acquire the second code block of any message based on the signal start bit and signal bit width of at least one signal corresponding to any message. If the second code block is a transmission code block, the code lines in the second code block are sorted according to the size order of the byte numbers of at least one signal to obtain the first code block of any message.

[0099] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The acquisition module 802 is used to acquire the second code block of any message based on the signal start bit and signal bit width of at least one signal corresponding to any message. If the second code block is a transmission code block, the code lines with the same byte number in the second code block are merged into the same code line to obtain the first code block of any message.

[0100] In one possible implementation, the code line of any signal indicates the byte number corresponding to any signal. The acquisition module 802 is used to acquire the second code block of any message based on the signal start bit and signal bit width of at least one signal corresponding to any message. If the second code block is a transmission code block, the code lines in the second code block are sorted according to the size order of the byte numbers of at least one signal to obtain the third code block of any message. The code lines with the same byte number in the third code block are merged into the same code line to obtain the first code block of any message.

[0101] In summary, the code generation apparatus provided in this application automatically parses DBC files and generates code blocks. These code blocks are used for message generation or recognition during CAN communication. Automatic parsing replaces manual operation by the user, improving the efficiency and accuracy of code block generation.

[0102] It should be noted that the code generation device provided in the above embodiments is only illustrated by the division of the above functional modules. In actual operation, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the device and method embodiments provided in the above embodiments belong to the same concept, and their specific implementation process can be found in the method embodiments, which will not be repeated here.

[0103] Figure 9 This is a schematic diagram of a server structure provided in an embodiment of this application. The server can vary significantly due to differences in configuration or performance. It may include one or more processors 1101 and one or more memories 1102. The one or more memories 1102 store at least one computer program, which is loaded and executed by the one or more processors 1101 to enable the server to implement the code generation methods provided in the above-described method embodiments. Of course, the server may also have wired or wireless network interfaces, a keyboard, and input / output interfaces for input and output. The server may also include other components for implementing device functions, which will not be elaborated upon here.

[0104] Figure 10 This is a schematic diagram of the structure of a terminal provided in an embodiment of this application. The terminal may be, for example, an in-vehicle terminal, a smartphone, a tablet computer, a media player, a laptop computer, or a desktop computer. The terminal may also be referred to as user equipment, a portable terminal, a laptop terminal, a desktop terminal, or other names.

[0105] Typically, a terminal includes a processor 1501 and a memory 1502.

[0106] Processor 1501 may include one or more processing cores, such as a quad-core processor, an octa-core processor, etc. Processor 1501 may be implemented using at least one hardware form selected from DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). Processor 1501 may also include a main processor and a coprocessor. The main processor, also known as a CPU (Central Processing Unit), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, processor 1501 may integrate a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content required to be displayed on the screen. In some embodiments, processor 1501 may also include an AI (Artificial Intelligence) processor, which is used to handle computational operations related to machine learning.

[0107] The memory 1502 may include one or more computer-readable storage media, which may be non-transitory. The memory 1502 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In some embodiments, the non-transitory computer-readable storage media in the memory 1502 are used to store at least one instruction, which is executed by the processor 1501 to cause the terminal to implement the code generation method provided in the method embodiments of this application.

[0108] In some embodiments, the terminal may also optionally include: a peripheral device interface 1503 and at least one peripheral device. The processor 1501, memory 1502, and peripheral device interface 1503 can be connected via a bus or signal line. Each peripheral device can be connected to the peripheral device interface 1503 via a bus, signal line, or circuit board. Specifically, the peripheral device includes at least one of: a radio frequency circuit 1504, a display screen 1505, a camera assembly 1506, an audio circuit 1507, and a power supply 1508.

[0109] Peripheral device interface 1503 can be used to connect at least one I / O (Input / Output) related peripheral device to processor 1501 and memory 1502. In some embodiments, processor 1501, memory 1502 and peripheral device interface 1503 are integrated on the same chip or circuit board; in some other embodiments, any one or two of processor 1501, memory 1502 and peripheral device interface 1503 can be implemented on separate chips or circuit boards, which is not limited in this embodiment.

[0110] The radio frequency (RF) circuit 1504 is used to receive and transmit RF (Radio Frequency) signals, also known as electromagnetic signals. The RF circuit 1504 communicates with communication networks and other communication devices via electromagnetic signals. The RF circuit 1504 converts electrical signals into electromagnetic signals for transmission, or converts received electromagnetic signals back into electrical signals. Optionally, the RF circuit 1504 includes: an antenna system, an RF transceiver, one or more amplifiers, a tuner, an oscillator, a digital signal processor, a codec chipset, a user identity module card, etc. The RF circuit 1504 can communicate with other terminals via at least one wireless communication protocol. This wireless communication protocol includes, but is not limited to: metropolitan area networks (MANs), various generations of mobile communication networks (2G, 3G, 4G, and 5G), wireless local area networks (WLANs), and / or WiFi (Wireless Fidelity) networks. In some embodiments, the RF circuit 1504 may also include circuitry related to NFC (Near Field Communication), which is not limited in this application.

[0111] Display screen 1505 is used to display a UI (User Interface). This UI may include graphics, text, icons, videos, and any combination thereof. When display screen 1505 is a touch display screen, it also has the ability to collect touch signals on or above its surface. These touch signals can be input as control signals to processor 1501 for processing. In this case, display screen 1505 can also be used to provide virtual buttons and / or a virtual keyboard, also known as soft buttons and / or a soft keyboard. In some embodiments, display screen 1505 can be a single screen, disposed on the front panel of the terminal; in other embodiments, display screen 1505 can be at least two screens, disposed on different surfaces of the terminal or in a folded design; in other embodiments, display screen 1505 can be a flexible display screen, disposed on a curved or folded surface of the terminal. Furthermore, display screen 1505 can be configured as a non-rectangular, irregular shape, i.e., a non-rectangular screen. Display screen 1505 can be made of materials such as LCD (Liquid Crystal Display) or OLED (Organic Light-Emitting Diode).

[0112] The camera assembly 1506 is used to acquire images or videos. Optionally, the camera assembly 1506 includes a front-facing camera and a rear-facing camera. Typically, the front-facing camera is located on the front panel of the terminal, and the rear-facing camera is located on the back of the terminal. In some embodiments, there are at least two rear-facing cameras, which are any one of a main camera, a depth-sensing camera, a wide-angle camera, and a telephoto camera, to achieve background blurring by fusion of the main camera and the depth-sensing camera, panoramic shooting by fusion of the main camera and the wide-angle camera, VR (Virtual Reality) shooting, or other fusion shooting functions. In some embodiments, the camera assembly 1506 may also include a flash. The flash can be a single-color temperature flash or a dual-color temperature flash. A dual-color temperature flash refers to a combination of a warm-light flash and a cool-light flash, which can be used for light compensation at different color temperatures.

[0113] The audio circuit 1507 may include a microphone and a speaker. The microphone is used to collect sound waves from the user and the environment, converting the sound waves into electrical signals that are input to the processor 1501 for processing, or input to the radio frequency circuit 1504 for voice communication. For stereo sound acquisition or noise reduction purposes, multiple microphones may be used, each positioned at a different location on the terminal. The microphone may also be an array microphone or an omnidirectional microphone. The speaker is used to convert electrical signals from the processor 1501 or the radio frequency circuit 1504 into sound waves. The speaker may be a conventional diaphragm speaker or a piezoelectric ceramic speaker. When the speaker is a piezoelectric ceramic speaker, it can convert electrical signals not only into audible sound waves but also into inaudible sound waves for purposes such as distance measurement. In some embodiments, the audio circuit 1507 may also include a headphone jack.

[0114] Power supply 1508 is used to power the various components in the terminal. Power supply 1508 can be AC ​​power, DC power, a disposable battery, or a rechargeable battery. When power supply 1508 includes a rechargeable battery, the rechargeable battery can support wired or wireless charging. The rechargeable battery can also be used to support fast charging technology.

[0115] In some embodiments, the terminal further includes one or more sensors 1509. The one or more sensors 1509 include, but are not limited to: an acceleration sensor 1510, a gyroscope sensor 1511, a pressure sensor 1512, an optical sensor 1513, and a proximity sensor 1514.

[0116] Accelerometer 1510 can detect the magnitude of acceleration along the three coordinate axes of a coordinate system established by the terminal. For example, accelerometer 1510 can be used to detect the components of gravitational acceleration along the three coordinate axes. Processor 1501 can control display screen 1505 to display the user interface in either a landscape or portrait view based on the gravitational acceleration signal acquired by accelerometer 1510. Accelerometer 1510 can also be used for games or for acquiring user motion data.

[0117] The gyroscope sensor 1511 can detect the terminal's orientation and rotation angle. The gyroscope sensor 1511 can work in conjunction with the accelerometer sensor 1510 to collect the user's 3D movements on the terminal. Based on the data collected by the gyroscope sensor 1511, the processor 1501 can perform the following functions: motion sensing (e.g., changing the UI based on the user's tilt), image stabilization during shooting, game control, and inertial navigation.

[0118] The pressure sensor 1512 can be disposed on the side bezel of the terminal and / or the lower layer of the display screen 1505. When the pressure sensor 1512 is disposed on the side bezel of the terminal, it can detect the user's grip signal on the terminal, and the processor 1501 can perform left / right hand recognition or quick operation based on the grip signal collected by the pressure sensor 1512. When the pressure sensor 1512 is disposed on the lower layer of the display screen 1505, the processor 1501 can control the operable controls on the UI interface based on the user's pressure operation on the display screen 1505. The operable controls include at least one of button controls, scroll bar controls, icon controls, and menu controls.

[0119] Optical sensor 1513 is used to collect ambient light intensity. In one embodiment, processor 1501 can control the display brightness of display screen 1505 based on the ambient light intensity collected by optical sensor 1513. Specifically, when the ambient light intensity is high, the display brightness of display screen 1505 is increased; when the ambient light intensity is low, the display brightness of display screen 1505 is decreased. In another embodiment, processor 1501 can also dynamically adjust the shooting parameters of camera assembly 1506 based on the ambient light intensity collected by optical sensor 1513.

[0120] The proximity sensor 1514, also known as a distance sensor, is typically installed on the front panel of the terminal. The proximity sensor 1514 is used to detect the distance between the user and the front of the terminal. In one embodiment, when the proximity sensor 1514 detects that the distance between the user and the front of the terminal is gradually decreasing, the processor 1501 controls the display screen 1505 to switch from a screen-on state to a screen-off state; when the proximity sensor 1514 detects that the distance between the user and the front of the terminal is gradually increasing, the processor 1501 controls the display screen 1505 to switch from a screen-off state to a screen-on state.

[0121] Those skilled in the art will understand that Figure 10 The structure shown does not constitute a limitation on the terminal and may include more or fewer components than shown, or combine certain components, or use different component arrangements.

[0122] In an exemplary embodiment, a computer device is also provided, comprising a processor and a memory storing at least one computer program. The at least one computer program is loaded and executed by one or more processors to enable the computer device to implement any of the above-described methods for generating code.

[0123] In an exemplary embodiment, a computer-readable storage medium is also provided, which stores at least one computer program that is loaded and executed by a processor of a computer device to enable the computer to implement any of the above-described methods for generating code.

[0124] In one possible implementation, the aforementioned computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), magnetic tape, floppy disk, and optical data storage device, etc.

[0125] In an exemplary embodiment, a computer program product or computer program is also provided, the computer program product or computer program including computer instructions stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, causing the computer device to perform any of the above-described methods for generating code.

[0126] It should be noted that all information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.), and signals involved in this application have been authorized by the user or fully authorized by all parties, and the collection, use, and processing of related data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the information related to the DBC files involved in this application was obtained with full authorization.

[0127] It should be understood that "multiple" as used in this article refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.

[0128] The above description is merely an exemplary embodiment of this application and is not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the principles of this application should be included within the protection scope of this application.

Claims

1. A method of generating code, characterized by, The method includes: Read message information corresponding to multiple messages in the database controller local area network (DBC) file, wherein the message is used to transmit at least one signal, and the message information of the message includes the signal start bit and signal bit width of the at least one signal; Based on the signal start bit and signal bit width of at least one signal corresponding to the message, a second code block of the message is obtained. The second code block includes code lines corresponding to the at least one signal. The code line of any signal is used to generate or identify any signal in the message. When the second code block is a transmission code block, the code lines in the second code block are sorted according to the size of the byte number, and / or, the code lines with the same byte number in the second code block are merged into the same code line to obtain the first code block of the message.

2. The method according to claim 1, characterized in that, The message information also includes a message identifier; the step of reading the message information corresponding to multiple messages in the database controller local area network (DBC) file includes: Read multiple message identifiers from the DBC file, where each message identifier corresponds to a message; The DBC file is read again. If the matching information corresponding to any message identifier among the plurality of message identifiers is read, the first data line where the first key is located is determined. The first key indicates the signal start bit and the signal bit width. The matching information indicates the data line in the DBC file that includes any message identifier. Based on the content of the first data row, obtain the signal start bit and signal width of the message corresponding to any message identifier.

3. The method according to claim 2, characterized in that, The reading of multiple message identifiers in the DBC file includes: Read the second data line containing the second key in the DBC file, where the second key indicates the message identifier; The multiple message identifiers are obtained based on the content of the second data row.

4. An apparatus for generating code, characterized in that, The device includes: The reading module is used to read message information corresponding to multiple messages in the database controller local area network (DBC) file. The messages are used to transmit at least one signal, and the message information of the messages includes the signal start bit and signal width of the at least one signal. The acquisition module is configured to acquire a second code block of the message based on the signal start bit and signal bit width of at least one signal corresponding to the message. The second code block includes code lines corresponding to the at least one signal, and the code line of any signal is used to generate or identify the signal in the message. When the second code block is a transmission code block, the code lines in the second code block are sorted according to the size of the byte number, and / or the code lines with the same byte number in the second code block are merged into the same code line to obtain a first code block of the message.

5. The apparatus according to claim 4, characterized in that, The message information also includes a message identifier; the reading module is used to read multiple message identifiers in the DBC file, with one message identifier corresponding to one message; read the DBC file again, and if the matching information corresponding to any message identifier among the multiple message identifiers is read, determine the first data line where the first key is located, the first key indicates the signal start bit and the signal bit width, and the matching information indicates the data line in the DBC file that includes any message identifier; obtain the signal start bit and signal bit width of the message corresponding to any message identifier based on the content of the first data line.

6. A computer device, characterized in that, The computer device includes a processor and a memory, the memory storing at least one computer program, the at least one computer program being loaded and executed by the processor to enable the computer device to implement the method of generating code as described in any one of claims 1 to 3.

7. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores at least one computer program, which is loaded and executed by a processor to enable the computer to implement the method of generating code as described in any one of claims 1 to 3.