A method, system, terminal device and storage medium for assigning and analyzing DBC message signals

By creating signal and message structures and using regular expressions to extract DBC file information, the assignment and parsing of CAN communication message signals are simplified, solving the problems of high complexity and high error rate in existing technologies and improving development and testing efficiency.

CN116248771BActive Publication Date: 2026-04-24BEIJING NEW ENERGY VEHICLE TECH INNOVATION CENT CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING NEW ENERGY VEHICLE TECH INNOVATION CENT CO LTD
Filing Date
2023-03-06
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

During development and testing, manually organizing the code for CAN communication message signals is a complex, error-prone, and inefficient process, and there are many similar codes, resulting in a large workload.

Method used

By creating signal structures, signal dictionaries, message structures, and message dictionaries, information in DBC files is extracted using regular expressions, and signal assignment and parsing are implemented through reading, assignment, and parsing modules, simplifying code operations.

Benefits of technology

It improves development and testing efficiency, avoids errors caused by manual operation, simplifies code implementation, and reduces the generation of similar code.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116248771B_ABST
    Figure CN116248771B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of message processing, and discloses a DBC message signal assignment and analysis method and system, terminal equipment and a storage medium. By reading and analyzing a DBC file, a message structure body, a message dictionary, a signal structure body and a signal dictionary are created in a code. The DBC is stored in the form of the code, and is convenient to call in the code. In the process of developing and testing CAN communication related products, the functions of signal assignment and signal analysis need to be realized in the code. In the CAN network communication process, a large number of message interactions exist, so the data area of the message is manually constructed in advance before each interaction, and the values to be assigned to some signals are written in, which is prone to errors and a large number of similar codes, and when errors occur, it is not easy to troubleshoot problems. By calling the tool, time can be saved, the data area of the message is automatically constructed through the tool, errors can be avoided, and the work efficiency is greatly improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of message processing technology, and in particular to a method, system, terminal device, and storage medium for assigning and parsing DBC message signals. Background Technology

[0002] CAN, short for "Controller Area Network," is a multi-master serial communication bus and one of the most widely used fieldbuses internationally. This bus is also widely used for communication between vehicle ECUs.

[0003] In CAN networks, DBC refers to the CAN message database. Simply put, the data types communicated via the CAN bus can be read and understood using DBC files. DBC is an ASCII-based translation, a standard file developed in the 1990s and now used by the automotive industry worldwide. These files help identify the data within a CAN frame by describing it. As these CAN databases, the text files contain information that decodes the raw CAN bus data into physical values. Therefore, it also functions as a signal library. The primary carrier of CAN bus communication is the message, and signals are the main components of the message; without a DBC database, signals cannot be parsed. The DBC is essentially an encyclopedia of communication content.

[0004] In the process of developing and testing CAN network message sending and receiving, it is often necessary to assign values ​​to the message signals to be sent and to parse the received message signals. However, implementing this process in code is quite complex. When sending a signal, it is necessary to specifically define certain bytes of the data part of the message corresponding to that signal; when receiving a signal, it is necessary to specifically parse certain bytes of the data part of the corresponding message. Moreover, such situations occur frequently during the development and testing of CAN communication. Therefore, the workload of sending and parsing message signals is substantial. Manually organizing this code is often prone to errors and inefficient, and it also generates a large number of similar code snippets. Summary of the Invention

[0005] Based on this, it is necessary to address the above-mentioned technical problems by providing a method for directly assigning values ​​to signals to be sent and parsing received signals. This method can avoid errors in the code caused by human factors, improve development and testing efficiency, and make the code simple and clean to open.

[0006] This invention discloses a method for assigning and parsing DBC message signals, the method comprising at least the following:

[0007] S1. Create a signal structure and a signal dictionary;

[0008] S2. Create a message structure and a message dictionary, wherein the message dictionary is used to store messages;

[0009] S3. Create message flags and assign default values;

[0010] S4. Read the DBC message file line by line, and judge the message information, signal information, and message flag in turn. Then use regular expressions to extract all information about messages and signals in the DBC file, and store the extracted information in the message structure, message dictionary, signal structure, and signal dictionary. Traverse each line of the DBC message file.

[0011] S5. Close the DBC message file and return to the message dictionary;

[0012] S6. Based on the established message dictionary, synchronously determine whether to assign values ​​to signals and whether to parse message signals, and then end.

[0013] The signal structure contains various attributes of the signal, and the message structure contains various attributes of the message.

[0014] Specifically, "reading the DBC message file line by line" means:

[0015] The Split() method splits the entire line into a string array words using colons. If the length of the string array is 2, a regular expression is used to match the specific string matches.

[0016] If the number of matches is greater than or equal to 1, and words[0] contains "BO_", then it is a message header;

[0017] If the number of matches is greater than or equal to 7, and words[0] contains "SG_", then it is the message content.

[0018] Specifically, the phrase "sequentially judging message information, signal information, and message flag bits" refers to:

[0019] S41. Determine if it is a message. If it is, create a message with the data type being a message structure, add the message information to the message structure, and set the message flag to 1. If not, proceed to step S42.

[0020] S42. Determine whether it is signal information. If it is, create a signal with data type signal structure, add the signal information to the signal structure, and add the signal structure to the signal dictionary of the message. If not, execute step S43.

[0021] S43. Determine if the message flag is 1. If yes, add the message structure to the message dictionary and set the message flag to 0 again. If no, iterate through each line of the DBC message file and execute step S4 repeatedly.

[0022] Specifically, the phrase "synchronously determining whether to assign a value to the signal and whether to parse the message signal based on the established message dictionary" refers to:

[0023] S61. Determine whether to assign a value to a signal in the code. If yes, create a signal with a data type of signal structure, assign the corresponding signal from the message dictionary to the signal, and convert the value to be assigned into the original value and write it to the correct position in the data area of ​​the message to be sent. If no, execute step S62.

[0024] S62. Determine whether to parse the signals in the received message. If yes, create a signal with the data type signal structure, assign the corresponding signal from the message dictionary to the signal, and extract the original value to be parsed and convert it into a physical value. If no, execute step S61.

[0025] Specifically, step S61 is as follows:

[0026] S611. Calculate the currentByte byte in the corresponding message where the creation signal is located;

[0027] S612. Calculate the offset of the number of bits not occupied by the creation signal in the current byte currentByte;

[0028] S613. Calculate the expected raw value of the created signal;

[0029] S614. Determine whether the length bitLength of the creation signal is greater than the number of bits occupied by the creation signal in the current byte. If yes, the creation signal starts from the current byte and continues in the next byte. If no, the creation signal starts from the current byte and ends in the current byte.

[0030] Specifically, step S62 is as follows:

[0031] S621. Calculate the currentByte byte in the corresponding message where the creation signal is located;

[0032] S622. Calculate the offset of the number of bits not occupied by the creation signal in the current byte currentByte;

[0033] S623. Determine the length of the creation signal (bitLength). If it is less than or equal to 8-offset, the creation signal starts and ends in the current byte (currentByte). If it is greater than 8-offset, the creation signal starts in the current byte (currentByte) and continues in the next byte.

[0034] This invention also discloses a system for assigning and parsing DBC message signals, comprising:

[0035] The reading module is used to read message signals and establish a signal structure, a signal dictionary, a message structure, and a message dictionary.

[0036] The assignment module is used to call signals in the message dictionary, perform code calculations to convert physical values ​​into original values, and write the original values ​​of the signals into the correct positions in the message data area corresponding to the signals.

[0037] The parsing module is used to call signals in the message dictionary, perform code calculations, extract the original signal values ​​from the data area of ​​the received message, and convert them into bit physical values.

[0038] The present invention also discloses a terminal device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor performs the steps of the above method.

[0039] The present invention provides a computer-readable storage medium storing a computer program, the computer program being executed by a processor of the steps of the above method.

[0040] By adopting the above technical solution, the present invention has the following beneficial effects:

[0041] This invention enables the creation of message structures, message dictionaries, signal structures, and signal dictionaries within code by reading and parsing DBC files. Essentially, it stores the DBC in code form for easy access within the code. In the development and testing of CAN communication-related products, it is often necessary to implement signal assignment and parsing functions in the code. CAN network communication often involves a large number of message exchanges. Therefore, manually constructing the message data area before each exchange and writing the values ​​to be assigned to certain signals is prone to errors, generates a large amount of similar code, and makes troubleshooting difficult. This tool saves time by automatically constructing the message data area and avoids errors, greatly improving work efficiency. Attached Figure Description

[0042] To make the content of this invention easier to understand, the invention will be further described in detail below with reference to specific embodiments and accompanying drawings, characterized in that...

[0043] Figure 1 This is a flowchart of the present invention. Detailed Implementation

[0044] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention.

[0045] Example 1

[0046] like Figure 1 As shown in the figure, this embodiment discloses a method for assigning and parsing DBC message signals. The method includes at least the following:

[0047] S1. Create a signal structure and a signal dictionary;

[0048] S2. Create a message structure and a message dictionary, wherein the message dictionary is used to store messages;

[0049] S3. Create message flags and assign default values;

[0050] S4. Read the DBC message file line by line, and judge the message information, signal information, and message flag in turn. Then use regular expressions to extract all information about messages and signals in the DBC file, and store the extracted information in the message structure, message dictionary, signal structure, and signal dictionary. Traverse each line of the DBC message file.

[0051] S5. Close the DBC message file and return to the message dictionary;

[0052] S6. Based on the established message dictionary, synchronously determine whether to assign values ​​to signals and whether to parse message signals, and then end.

[0053] The signal structure contains various attributes of the signal, and the message structure contains various attributes of the message.

[0054] Specifically, the phrase "sequentially judging message information, signal information, and message flag bits" refers to:

[0055] S41. Determine if it is a message. If it is, create a message with the data type being a message structure, add the message information to the message structure, and set the message flag to 1. If not, proceed to step S42.

[0056] S42. Determine whether it is signal information. If it is, create a signal with data type signal structure, add the signal information to the signal structure, and add the signal structure to the signal dictionary of the message. If not, execute step S43.

[0057] S43. Determine if the message flag is 1. If yes, add the message structure to the message dictionary and set the message flag to 0 again. If no, iterate through each line of the DBC message file and execute step S4 repeatedly.

[0058] Specifically, the phrase "synchronously determining whether to assign a value to the signal and whether to parse the message signal based on the established message dictionary" refers to:

[0059] S61. Determine whether to assign a value to a signal in the code. If yes, create a signal with a data type of signal structure, assign the corresponding signal from the message dictionary to the signal, and convert the value to be assigned into the original value and write it to the correct position in the data area of ​​the message to be sent. If no, execute step S62.

[0060] S62. Determine whether to parse the signals in the received message. If yes, create a signal with the data type signal structure, assign the corresponding signal from the message dictionary to the signal, and extract the original value to be parsed and convert it into a physical value. If no, execute step S61.

[0061] Example 2

[0062] This embodiment refines the specific implementation steps based on Embodiment 1, and specifically includes the following steps:

[0063] First, define a dictionary of CAN messages to store CAN messages. The dictionary keys are the names of the messages, and the values ​​are message structures.

[0064] Define a CAN message structure containing various attributes of the CAN message, including message name, DLC, ID, and a dictionary for storing signals. The key of the dictionary is the signal name, and the value is a signal structure.

[0065] Define a signal structure that contains various attributes of the signal, including start bit, length, resolution, offset, maximum value, minimum value, name, etc.

[0066] Use code to read DBC stored in a specific location;

[0067] Create a rule string: ([\d.-]+), which means to match some numeric strings. The length of the string can be any value.

[0068] Create an immutable regular expression rgx that reads a specific string according to the above rule string, without being case-sensitive;

[0069] First, read a line of content from the DBC file. Then, use the Split() method to split the entire line into a string array named words according to ":". If the length of the string array is 2, it means that the content of the message header may have been read. At this time, use the regular expression rgx to match the specific string matches according to the designed rule string. If the number of matches is greater than or equal to 1 and words[0] contains the three characters "BO_", it proves that the content of the message header has been found.

[0070] At this point, the message's DLC is the value of the matches data type converted to an integer. Then, the first string words[0] is split into a string array currentMsg by spaces using the Split() method. The second element currentMsg[1] is the message ID, and the third element currentMsg[2] is the message name; note that the data types of the message's DLC and ID are integers.

[0071] The message name, DLC, and ID read from the DBC file are added to the message structure.

[0072] Next, read the next line of the DBC file. Similarly, use the Split() method to split the entire line into a string array words according to ":". If the length of the string array is 2, it means that the content of the signal may be read. At this time, use the regular expression rgx to match the specific string matches according to the designed rule string. If the number of matches is greater than or equal to 7, and words[0] contains "SG_", it means that this line is about the signal in the above message.

[0073] The first string `words[0]` is split into a string array `currentSignal` using the `Split()` method. `currentSignal[1]` represents the signal name. The first number matched by the regular expression `rgx`, `matches[0]`, is the starting position; the second number, `matches[1]`, is the length; the fourth number, `matches[3]`, is the resolution; the fifth number, `matches[4]`, is the offset; the sixth number, `matches[5]`, is the minimum value; and the seventh number, `matches[6]`, is the maximum value. Note that the starting position, length, and offset data types must be converted to integers, and the resolution, minimum value, and maximum value data types must be converted to double-precision types.

[0074] The signal information read from the DBC file—start bit, length, resolution, offset, minimum value, and maximum value—is added to the signal structure.

[0075] Then, add the signal name as the key and the signal structure as the value to the signal dictionary in the message structure.

[0076] Continue reading the next line and repeat the above steps to add all the signals of the message to the message structure.

[0077] If the length of the newly read line is not 2 after being split into a string array `words` by the `Split()` method according to ":", it means that all signals of the message have been added. At this time, the message name is added to the message dictionary as the key and the message structure is added as the value.

[0078] Continue reading one more line and repeat the above steps to add all signals to the corresponding message until the entire DBC file is read, ultimately forming a message dictionary.

[0079] The specific steps for assigning DBC message signals using the generated message dictionary are as follows:

[0080] First, it's necessary to determine which signal in which message of the DBC needs to be assigned a value. A signal needs to be defined, with the data type of the aforementioned signal structure. Using the generated message dictionary, based on the message name and signal name, the signal defined in the DBC is assigned to the defined signal. Then, this signal, the message to be sent, and the value to be assigned to the signal are used as input.

[0081] First, calculate the currentByte byte in the corresponding message where the signal is located. The calculation method is: use the startBit of the signal, divide by 8 and take the integer.

[0082] Calculate the number of bits of the signal that are not occupied in the current byte (currentByte) using the offset method: use the start bit of the signal and divide by 8;

[0083] Calculate the expected raw value of the signal, i.e., the original value corresponding to the value we want to assign to the signal. The calculation method is: use the expected value of the signal, i.e., the value we want to assign to the signal, minus the offset of the signal, and then divide by the resolution of the signal.

[0084] Fourth, determine whether the length of the signal (bitLength) is greater than the number of bits (8-offset) occupied by the signal in the current byte. If this condition is met, it means that the signal starts from the current byte and continues in the next byte.

[0085] First, a mask, clearMask, is used to clear the bits associated with the signal in the current byte. The calculation method is as follows: shift 1 to the left by offset bits, then subtract 1 to get clearMask. Then, perform a bitwise AND operation with the currentByte of the message corresponding to the signal, and store the result in currentByte. The purpose is to set the signal to 0 in each position of the current byte.

[0086] Then, a mask `rewriteMask` is used to calculate the data to be written to the current byte for this signal. The calculation is as follows: shift 1 to the left by (8 - offset) bits, subtract 1 to get `rewriteMask`, then perform a bitwise AND operation with the original value `raw_value` of the signal, and then shift the result to the left by `offset` bits. Finally, perform a bitwise OR operation with `currentByte`, and store the result in `currentByte`. The purpose is to write the value of `raw_value` to the corresponding bit in that byte into `currentByte`.

[0087] The remaining bits of the signal are calculated by subtracting the number of bits occupied by the signal in the current byte (currentByte) from the signal length. If this remaining bit count is greater than 8, the (currentByte+1)th byte of the corresponding message is assigned the value 0x00. The original signal value is then shifted right by (8 - offset) bits and bitwise ORed with the current byte to write the signal content to that byte. The remaining bits are then calculated again to check if they are still greater than 8. If so, the above steps are repeated, noting that the original signal value is shifted right by (8 + (8 - offset)) bits each time, and so on. If the final remaining bits are 0, no further writing to the next byte is required. If the final remaining bits are greater than 0 but less than 8, the remaining bits are written to the next byte. This completes the signal assignment function. The method for writing the remaining bits to the next byte is as follows:

[0088] First, use a mask, clearMask, to clear the bits associated with the signal in the next byte. The calculation method is as follows: shift 1 to the left by remainBits bits, subtract 1, and note that the data type of the result must be converted to byte, then inverted to get clearMask. Then perform a bitwise AND operation with the byte and store the result in the byte.

[0089] Then, a rewriteMask is used to calculate the data to be written to the current byte for this signal. The calculation is as follows: shift 1 to the left by remainBits bits, subtract 1 to get the rewriteMask, shift the rewriteMask to the left by (bitLength - remainBits) bits, perform a bitwise AND operation with the raw_value, shift the result to the right by (bitLength - remainBits) bits, and then perform a bitwise OR operation with the byte.

[0090] Fifth, if the condition described in the fourth section is not met, and the length of the signal is less than or equal to (8-offset), then it means that the signal starts from the current byte and ends at the current byte.

[0091] First, a mask, clearMask, is used to clear the bits associated with the current byte and the signal. The calculation method is as follows: shift 1 to the left by the signal length bitLength, subtract 1, and then shift to the left by offset bits. Note that the data type of the result must be converted to byte, and then the result is inverted to get clearmask. Perform a bitwise AND operation with the current byte and set the bits associated with the signal to 0.

[0092] Then, a mask `rewriteMask` is used to calculate the data to be written to the current byte for this signal. The calculation is as follows: shift 1 to the left by the signal length `bitLength` bits, subtract 1 to get `rewriteMask`, perform a bitwise AND operation with the original signal value `raw_value`, shift the result to the left by `offset` bits, and then perform a bitwise OR operation with the current byte `currentByte`.

[0093] Finally, the values ​​of the relevant bytes of the message corresponding to the signal are obtained, and these values ​​are directly assigned to the corresponding bytes of the message.

[0094] The specific steps for using the generated message dictionary to parse DBC message signals are as follows:

[0095] First, it's necessary to determine which message and which signal's physical value we want to read from the DBC. We need to define a signal first, using the data type of the aforementioned signal structure. Using the generated message dictionary, based on the message name and signal name, assign the signal defined in the DBC to the defined signal. Then, use this signal and the acquired message containing it as input.

[0096] First, calculate the currentByte byte in the corresponding message where the signal is located. The calculation method is to use the startBit of the signal and divide it by 8.

[0097] Second, calculate the number of bits of the signal that are not occupied in the current byte (currentByte): The calculation method is to use the start bit of the signal and divide it by 8.

[0098] Third, if the signal length bitLength is less than or equal to (8-offset), then it means that the signal starts and ends in the current byte currentByte.

[0099] The byte currentByte corresponding to the signal in the collected message is shifted to the right by offset bits, and then bitwise ORed with byte 0x00 to obtain a new byte.

[0100] Next, shift the signal length bitLength by 1, subtract 1, and perform a bitwise AND operation between the result and the new byte obtained above to get the original value raw_value of the signal;

[0101] The physical value of the signal in the acquired message is then: raw_value multiplied by the signal resolution, plus the signal offset.

[0102] Fourth, if the condition described in the third point is not met, and the signal length bitLength is greater than (8-offset), then it means that the signal starts in the current byte currentByte and continues in the next byte.

[0103] First, shift currentByte to the right by offset bits, store the result in raw_value, and then move on to the next byte;

[0104] Calculate the remaining bits (remainBits) after dividing the bits in currentByte, using the formula: bitLength - (8 - offset).

[0105] If the remaining bits are greater than 8, shift the current byte (currentByte+1) to the left by (8-offset) bits, perform a bitwise OR operation between this result and raw_value, store the result in raw_value, and move on to the next byte.

[0106] Next, calculate the remaining bits (remainBits) using the bitwise expression: bitLength - (8 - offset) - 8. If the remaining bits are still greater than 8, shift the current byte (currentByte + 2) to the left by 8 + (8 - offset) bits, perform a bitwise OR operation between this result and raw_value, and proceed to the next byte.

[0107] This process continues until the remaining bits (remainBits) are less than 8. If remainingBits equals 0, the physical value of the signal is: raw_value multiplied by the signal's resolution, plus the signal's offset. If remainingBits is greater than 0, shift 1 to the left by remainingBits bits, subtract 1, then shift to the left by (bitLength - remainingBits) bits. Perform a bitwise OR operation between the result and raw_value, and store the result in raw_value. The physical value of the signal is then: raw_value multiplied by the signal's resolution, plus the signal's offset.

[0108] The method proposed in this embodiment is developed using the C# language. By storing DBC file signals in code form, it facilitates in-code calls. When assigning values ​​to the message signals to be sent and parsing the received message signals, calling this tool in the code simplifies the process of sending and receiving message signals over the CAN network, avoids errors, and saves time for developers and testers. Similarly, this invention can also be implemented using other languages, which will not be elaborated here.

[0109] Example 3

[0110] Based on embodiments 1 and 2, this embodiment proposes a system for assigning and parsing DBC message signals, including:

[0111] The reading module is used to read message signals and establish a signal structure, a signal dictionary, a message structure, and a message dictionary.

[0112] The assignment module is used to call signals in the message dictionary, perform code calculations to convert physical values ​​into original values, and write the original values ​​of the signals into the correct positions in the message data area corresponding to the signals.

[0113] The parsing module is used to call signals in the message dictionary, perform code calculations, extract the original signal values ​​from the data area of ​​the received message, and convert them into bit physical values.

[0114] The reading module extracts information about messages and signals from the DBC file. Then, using this information, the assignment module assigns values ​​to the signals defined in the DBC file, and the parsing module parses the signals in the received messages.

[0115] Example 4

[0116] An embodiment of the present invention provides a terminal device. This terminal device includes a processor, a memory, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps in the various method embodiments described above. Alternatively, when the processor executes the computer program, it implements the functions of each module / unit in the various device embodiments described above.

[0117] The computer program can be divided into one or more modules / units, which are stored in the memory and executed by the processor to complete the present invention.

[0118] The terminal device may be a desktop computer, laptop, handheld computer, or cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.

[0119] The processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc.

[0120] The memory can be used to store the computer program and / or module. The processor implements various functions of the terminal device by running or executing the computer program and / or module stored in the memory and calling the data stored in the memory.

[0121] If the modules / units integrated into the terminal device are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0122] The specific embodiments described above further illustrate the purpose, technical solution, and beneficial effects of the present invention. It should be understood that the above descriptions are merely specific embodiments of the present invention and are not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for assigning and parsing DBC message signals, characterized in that, The method includes at least the following: the following: S1. Create a signal structure and a signal dictionary; S2. Create a message structure and a message dictionary, wherein the message dictionary is used to store messages; S3. Create message flags and assign default values; S4. Read the DBC message file line by line, and judge the message information, signal information, and message flag in turn. Then use regular expressions to extract all information about messages and signals in the DBC file, and store the extracted information in the message structure, message dictionary, signal structure, and signal dictionary. Traverse each line of the DBC message file. S5. Close the DBC message file and return to the message dictionary; S6. Based on the established message dictionary, synchronously determine whether to assign values ​​to signals and whether to parse message signals, and then end; Specifically, the phrase "synchronously determining whether to assign a value to the signal and whether to parse the message signal based on the established message dictionary" refers to: S61. Determine whether to assign a value to a signal in the code. If yes, create a signal with a data type of signal structure, assign the corresponding signal from the message dictionary to the signal, and convert the value to be assigned into the original value and write it to the correct position in the data area of ​​the message to be sent. If no, execute step S62. S62. Determine whether to parse the signal in the received message. If yes, create a signal with data type signal structure, assign the corresponding signal from the message dictionary to the signal, and extract the original value to be parsed and convert it into a physical value. If no, execute step S61. Specifically, the step of "creating a signal" in step S61 is as follows: S611. Calculate the currentByte byte in the corresponding message where the creation signal is located; S612. Calculate the offset of the number of bits not occupied by the creation signal in the current byte currentByte; S613. Calculate the expected raw value of the created signal; S614. Determine whether the length bitLength of the creation signal is greater than the number of bits occupied by the creation signal in the current byte. If yes, the creation signal starts from the current byte and continues in the next byte. If no, the creation signal starts from the current byte and ends in the current byte. The calculation method is as follows: first, use a mask clearMask to clear the bits related to the signal in the next byte. Then a rewriteMask is used to calculate the data to be written to the current byte for that signal; Finally, the values ​​of the relevant bytes of the message corresponding to the signal are obtained, and these values ​​are directly assigned to the corresponding bytes of the message; Specifically, the step of "creating a signal" in step S62 is as follows: S621. Calculate the currentByte byte in the corresponding message where the creation signal is located; S622. Calculate the offset of the number of bits not occupied by the creation signal in the current byte currentByte; S623. Determine the length of the creation signal (bitLength). If it is less than or equal to 8 - offset, then the creation signal begins and ends in the current byte (currentByte). The byte currentByte corresponding to the signal in the collected message is shifted to the right by offset bits, and then a bitwise OR operation is performed with the byte 0x00 to obtain a new byte. Shift 1 to the left by the signal length bitLength, decrement by 1, and perform a bitwise AND operation between the result and the new byte obtained above to get the original value of the signal, raw_value. If the value is greater than 8 - offset, the creation signal begins in the current byte (currentByte) and continues in the next byte. First, shift currentByte to the right by offset bits, store the result in raw_value, and then move on to the next byte; Calculate the number of bits remaining after dividing the bits in currentByte by bitLength - (8 - offset). If the number of bits remaining is greater than 8, shift the current byte (currentByte+1) to the left by (8 - offset) bits, perform a bitwise OR operation between this result and raw_value, store the result in raw_value, and move on to the next byte. Next, calculate the remaining bits (remainBits) using the bitwise expression: bitLength - (8 - offset) - 8. If the remaining bits are still greater than 8, shift the current byte (currentByte + 2) to the left by 8 + (8 - offset) bits, perform a bitwise OR operation between this result and raw_value, and proceed to the next byte. This process continues until the remaining bits (remainBits) are less than 8. If remainingBits equals 0, the physical value of the signal is: raw_value multiplied by the resolution of the signal, plus the offset of the signal. If remainingBits is greater than 0, shift 1 to the left by remainingBits bits, subtract 1, shift to the left by (bitLength-remainBits) bits, perform a bitwise OR operation between the result and raw_value, and store the result in raw_value.

2. The method for assigning and parsing DBC message signals as described in claim 1, characterized in that, The signal structure contains various attributes of the signal, and the message structure contains various attributes of the message.

3. The method for assigning and parsing DBC message signals as described in claim 1, characterized in that, The aforementioned "reading DBC message files line by line" specifically refers to: The Split() method splits the entire line into a string array words by ":". If the length of the string array is 2, a regular expression is used to match the specific string matches. If the number of matches is greater than or equal to 1, and words[0] contains "BO_", then it is a message header; If the number of matches is greater than or equal to 7, and words[0] contains "SG_", then it is the message content.

4. The method for assigning and parsing DBC message signals as described in claim 1, characterized in that, The aforementioned "sequentially judging message information, signal information, and message flag bits" specifically refers to: S41. Determine if it is a message. If it is, create a message with the data type being a message structure, add the message information to the message structure, and set the message flag to 1. If not, proceed to step S42. S42. Determine if it is signal information. If it is, create a signal with data type signal structure, add the signal information to the signal structure, and add the signal structure to the signal dictionary of the message. If not, execute step S43. S43. Determine if the message flag is 1. If yes, add the message structure to the message dictionary and set the message flag to 0 again. If no, iterate through each line of the DBC message file and execute step S4 repeatedly.

5. A system for assigning and parsing DBC message signals, characterized in that, The system is used to implement the steps of the method according to any one of claims 1-4, including: The reading module is used to read message signals and establish a signal structure, a signal dictionary, a message structure, and a message dictionary. The assignment module is used to call signals in the message dictionary, perform code calculations to convert physical values ​​into original values, and write the original values ​​of the signals into the correct positions in the message data area corresponding to the signals. The parsing module is used to call signals in the message dictionary, perform code calculations, extract the original signal values ​​from the data area of ​​the received message, and convert them into bit physical values.

6. A terminal device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1-4.

7. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by a processor, it implements the steps of the method as described in any one of claims 1-4.

Citation Information

Patent Citations

  • DBC file parsing and message analyzing method based on regular expression

    CN108600192A

  • File format conversion method and device and computer readable storage medium

    CN111191422A