CAN bus data verification method and system

By using the exclusive or inverse operation method in CAN bus data verification, the shortcomings of data verification in the prior art in complex scenarios and limited resources are solved, and more efficient and reliable data verification is achieved.

CN119847798APending Publication Date: 2025-04-18CHANGSHA ZHONGLIAN HENGTONG MACHINERY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411601976.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-11
Publication Date
2025-04-18

AI Technical Summary

Technical Problem

Existing data verification methods have insufficient accuracy and resource usage in complex application scenarios, especially parity, accumulation and checksum cyclic redundancy verification, in the face of multiple errors or limited resources, cannot effectively detect data errors or operate efficiently.

Method used

The CAN bus data verification method using the exclusive or inverse operation is used. The data sending unit and the receiving data unit perform the exclusive or inverse operation on the bytes in the data frame, generate a verification result, and the control unit compares the verification result to determine the integrity of the data.

Benefits of technology

It improves the accuracy and error rate of data verification, reduces the occupation of system resources, and can operate more efficiently especially in resource-limited environments, providing more reliable data verification guarantees.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119847798A_ABST
    Figure CN119847798A_ABST
Patent Text Reader

Abstract

The invention discloses a CAN bus data verification method and system, and the method comprises the steps: carrying out the calculation of to-be-verified first CAN bus data through a data transmission unit according to a defined first calculation method, and obtaining a first calculation result; after receiving the first CAN bus data sent by the data sending unit, the data receiving unit obtains second CAN bus data, and calculates the second CAN bus data according to a defined second calculation method to obtain a second calculation result; the control unit compares the second calculation result with the first calculation result, and if the second calculation result is consistent with the first calculation result, the to-be-verified first CAN bus data does not have an error in the transmission or storage process; and if the second calculation result is inconsistent with the first calculation result, indicating that the to-be-verified first CAN bus data has an error in the transmission or storage process. According to the invention, the accuracy and reliability of data verification are high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to the technical field of CAN bus data verification, and in particular discloses a CAN bus data verification method and system. Background Art

[0002] In the complex and critical process of data transmission and storage, the data sending unit plays an extremely important role. It will perform comprehensive and detailed processing on the data to be sent according to a specific and carefully designed calculation method. After the processing is completed, the calculated results will be sent out together. Data verification is a verification operation performed to ensure the integrity of the data. Usually, a verification value is calculated for the original data using a specified algorithm. The receiver calculates the verification value once using the same algorithm. If the verification values ​​calculated twice are the same, it means that the data is complete.

[0003] The existing data verification method is as follows:

[0004] 1. Data parity check;

[0005] Parity check is a simple data check method used to detect whether data errors occur during transmission or storage. It adds a check bit to the data so that the number of "1" in the entire data (including the check bit) is odd (odd check) or even (even check).

[0006] 2. Data and verification;

[0007] This method is to add up all bytes or bits in a set of data and use the sum as the check value. After the data is transmitted or stored, the receiver or reader performs the same sum operation on the data again and compares the sum with the pre-stored check value. If the two are consistent, it is considered that there is no error in the data transmission or storage process; if they are inconsistent, it indicates that the data may have an error.

[0008] 3. Such as cyclic redundancy check (CRC)

[0009] A checksum is generated by performing mathematical (polynomial) operations on the data. The sender sends the original data and the generated checksum together, and the receiver performs the same operation on the received data. If the calculated checksum matches the received checksum, the data is considered correct; otherwise, it means that an error occurred during the data transmission process.

[0010] The prior art has the following disadvantages:

[0011] 1. Data parity check

[0012] Data parity check is a relatively basic and simple verification method. When faced with complex application scenarios, its defects become more and more obvious. In the actual data transmission and storage process, due to external interference or other factors, various types of errors may occur in the data. In particular, when the number of "1"s in the data changes at multiple locations at the same time, the limitations of parity check are exposed. This verification method only judges whether the data is correct based on the parity of the total number of "1"s in the data, without considering the specific situation of each data bit. Therefore, once multiple errors occur and these errors interact with each other, resulting in the parity of the number of "1"s remaining unchanged, parity check cannot accurately detect errors in the data. This means that its verification results are seriously out of touch with the actual state of the data, and cannot provide reliable protection for the integrity and accuracy of the data. In a complex data processing environment, its reliability is greatly reduced.

[0013] 2. Data and verification

[0014] The data and verification method also has the characteristic of simplicity, which also greatly limits its application in complex scenarios. During the data processing process, when multiple errors occur, since this verification method is based on the sum of the data to judge the correctness of the data, positive and negative offsets may occur. For example, in a set of data, the increase of some data bits and the decrease of other data bits just make the overall data sum remain unchanged. Although the data has errors, the data and verification cannot identify this change, resulting in the error being hidden under the seemingly normal data appearance, and the error cannot be verified by this verification method. This limitation seriously affects the effectiveness of data verification and may cause erroneous data to propagate in the system, leading to a series of potential problems.

[0015] 3. Such as cyclic redundancy check (CRC)

[0016] Although cyclic redundancy check (CRC) is widely used in the field of data verification, it is not perfect. The performance of the polynomial selected for calculation has a crucial impact on the verification result. Different polynomials have different characteristics, and the generated check codes and error detection capabilities are different. If an inappropriate polynomial is selected, it may lead to a decrease in the sensitivity of error detection for certain types, thus affecting the accuracy of the entire verification process.

[0017] In addition, the calculation process of cyclic redundancy check is relatively complicated. It requires multiple cycles of data calculation, involving a large number of bit operations and polynomial division operations. This complex calculation method consumes more system resources, including CPU time and memory. When the system needs to process a large amount of data or when resources are limited, this resource occupation problem will become more prominent. Excessive resource consumption will cause delays in the system during data transmission, which will have a negative impact on data transmission efficiency and reduce the data processing capacity and response speed of the entire system. Summary of the invention

[0018] The present invention provides a CAN bus data verification method and system, aiming to solve at least one defect existing in the above-mentioned prior art.

[0019] One aspect of the present invention relates to a CAN bus data verification method, comprising the following steps:

[0020] The data sending unit calculates the first CAN bus data to be verified according to a defined first calculation method to obtain a first calculation result, and sends the first CAN bus data to the data receiving unit;

[0021] After receiving the first CAN bus data sent by the data sending unit, the data receiving unit obtains the second CAN bus data, and calculates the second CAN bus data according to the defined second calculation method to obtain a second calculation result;

[0022] The control unit compares the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that there is no error in the transmission or storage of the first CAN bus data to be verified; if the second calculation result is inconsistent with the first calculation result, it means that an error occurred in the transmission or storage of the first CAN bus data to be verified.

[0023] Further, the first calculation result is a first verification result of the first frame data, and the data sending unit calculates the first CAN bus data to be verified according to the defined first calculation method to obtain the first calculation result, and sends the first CAN bus data to the receiving data unit. In the step, the first frame data in the first CAN bus data is verified, and the first frame data is set as B n , then the first frame data is represented as follows:

[0024] B n =B0B1B2B3…B n-1

[0025] Among them, B nIndicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0026] The first verification result B of the first frame data n-1 The calculation formula is as follows:

[0027]

[0028] The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

[0029] Further, the second calculation result is a second verification result of the second frame data. After the data receiving unit receives the first CAN bus data sent by the data sending unit, it obtains the second CAN bus data and calculates the second CAN bus data according to the defined second calculation method. In the step of obtaining the second calculation result, the second frame data in the second CAN bus data is verified. The second frame data is set as C n , then the second frame data is expressed as follows:

[0030] C n =C0C1C2C3…C n-1

[0031] Among them, C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0032] The second verification result C of the second frame data n-1 The calculation formula is as follows:

[0033]

[0034] The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

[0035] Further, the control unit compares the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; if the second calculation result is inconsistent with the first calculation result, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified. In the step of the control unit comparing the second verification result C of the second frame data n-1 The first check result B with the first frame data n-1 Compare, if the second verification result C of the second frame data n-1 The first check result B with the first frame data n-1 If the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; if the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; n-1 The first check result B with the first frame data n-1 If they are inconsistent, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.

[0036] Another aspect of the present invention relates to a CAN bus data verification system, comprising a data sending unit, a data receiving unit and a control unit, wherein:

[0037] a data sending unit, configured to calculate the first CAN bus data to be verified according to a defined first calculation method, obtain a first calculation result, and send the first CAN bus data to the data receiving unit;

[0038] A data receiving unit, configured to obtain second CAN bus data after receiving the first CAN bus data sent by the data sending unit, and calculate the second CAN bus data according to a defined second calculation method to obtain a second calculation result;

[0039] The control unit is used to compare the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that there is no error in the transmission or storage of the first CAN bus data to be verified; if the second calculation result is inconsistent with the first calculation result, it means that an error occurred in the transmission or storage of the first CAN bus data to be verified.

[0040] Furthermore, the first calculation result is a first verification result of the first frame data. In the data sending unit, the first frame data in the first CAN bus data is verified. Assume that the first frame data is B n , then the first frame data is represented as follows:

[0041] B n =B0B1B2B3…B n-1

[0042] Among them, B n Indicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0043] The first verification result B of the first frame data n-1 The calculation formula is as follows:

[0044]

[0045] The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

[0046] Furthermore, the second calculation result is a second verification result of the second frame data. In the received data unit, the second frame data in the second CAN bus data is verified. The second frame data is set to C n , then the second frame data is expressed as follows:

[0047] C n =C0C1C2C3…C n-1

[0048] Among them, C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0049] The second verification result C of the second frame data n-1 The calculation formula is as follows:

[0050]

[0051] The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

[0052] Furthermore, in the control unit, the control unit compares the second verification result Cn-1 of the second frame data with the first verification result Bn-1 of the first frame data. If the second verification result Cn-1 of the second frame data is consistent with the first verification result Bn-1 of the first frame data, it means that there is no error in the transmission or storage of the first CAN bus data to be verified; if the second verification result Cn-1 of the second frame data is inconsistent with the first verification result Bn-1 of the first frame data, it means that an error occurred in the transmission or storage of the first CAN bus data to be verified.

[0053] The beneficial effects achieved by the present invention are:

[0054] The present invention provides a CAN bus data verification method and system, wherein a data sending unit calculates the first CAN bus data to be verified according to a defined first calculation method to obtain a first calculation result, and sends the first CAN bus data to a receiving data unit; after the receiving data unit receives the first CAN bus data sent by the data sending unit, it obtains the second CAN bus data, and calculates the second CAN bus data according to a defined second calculation method to obtain a second calculation result; the control unit compares the second calculation result with the first calculation result, and if the second calculation result is consistent with the first calculation result, it means that the first CAN bus data to be verified has no error during transmission or storage; if the second calculation result is inconsistent with the first calculation result, it means that the first CAN bus data to be verified has an error during transmission or storage. The CAN bus data verification method and system provided by the present invention have the following beneficial effects:

[0055] 1. In terms of accuracy and error rate, the present invention has more advantages than parity check and cumulative check.

[0056] Parity check and cumulative sum check are more traditional data verification methods, but they both have certain limitations. Taking parity check as an example, it simply checks the parity of the number of "1" in the data. This method is too simple and cannot accurately locate the specific error bit. For example, in the original data, if the number of "1" is odd, when two "1"s are converted to "0" and two "0"s are converted to "1", from the perspective of parity, the total parity of the number of "1" in the data has not changed. In this case, parity check is completely unable to detect that the data has errors.

[0057] Cumulative sum check also has similar problems, and its ability to detect data errors is limited. The verification method adopted by the present invention is a more advanced XOR operation verification. Although this verification method is not absolutely error-free, since the situation of XOR operation error has specific requirements for data bits, this makes the possibility of error in the present invention significantly reduced in practical applications compared with parity check and cumulative sum check, thereby providing more reliable guarantee for accurate data verification.

[0058] 2. In terms of system resource occupation, compared with CRC verification, the present invention has obvious advantages.

[0059] CRC verification is a widely used verification method, including CRC-8, CRC-16, CRC-32 and other polynomial forms. However, when the amount of data to be verified is large, CRC verification, which is based on cyclic redundancy calculation, has obvious shortcomings. It will occupy a large amount of system computing resources, because in the calculation process, complex cyclic calculations need to be performed on the data. As the amount of data increases, the amount of calculation will increase exponentially, thus placing high demands on the system's computing power.

[0060] Different from this, the XOR operation verification method used in the present invention will also occupy certain system computing resources during operation, but since the XOR operation itself is relatively simple and direct, compared with the complex cyclic redundancy calculation of CRC verification, its operation process is concise and clear. Therefore, when performing data verification, the present invention occupies fewer system computing resources, which enables the present invention to operate more efficiently in a system environment with limited resources, and also frees up more computing resources for the realization of other system functions. BRIEF DESCRIPTION OF THE DRAWINGS

[0061] Figure 1 A schematic diagram of a flow chart of an embodiment of a CAN bus data verification method of the present invention;

[0062] Figure 2 It is an intuitive expression of the calculated value of the verification result B7 in a CAN bus data verification method of the present invention. DETAILED DESCRIPTION

[0063] In order to better understand the above technical solution, the above technical solution will be described in detail below in conjunction with the accompanying drawings and specific implementation methods.

[0064] like Figure 1 As shown, the first embodiment of the present invention provides a CAN bus data verification method, comprising the following steps:

[0065] Step S100: The data sending unit calculates the first CAN bus data to be verified according to a defined first calculation method to obtain a first calculation result, and sends the first CAN bus data to the data receiving unit.

[0066] The first calculation method adopts an XOR inversion operation, which is used to perform an XOR operation on each byte in the data frame of the first CAN bus data to be verified, and invert the result of the XOR operation. By performing an XOR operation on each byte in the data frame of the first CAN bus data in sequence, errors in the data can be effectively detected. By inverting the result of the XOR operation on the first CAN bus data, the accuracy and reliability of the verification are further enhanced.

[0067] Step S200: After receiving the first CAN bus data sent by the data sending unit, the data receiving unit obtains the second CAN bus data, and calculates the second CAN bus data according to a defined second calculation method to obtain a second calculation result.

[0068] The second calculation method adopts an XOR inversion operation, which is used to perform XOR operations on each byte in the data frame of the second CAN bus data in sequence, and inverts the result of the XOR operation. By performing XOR operations on each byte in the data frame of the second CAN bus data in sequence, errors in the data can be effectively detected. By inverting the result of the XOR operation of the second CAN bus data, the accuracy and reliability of the verification are further enhanced. The second calculation method can be the same as the first calculation method, or it can be different.

[0069] Step S300, the control unit compares the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that there is no error in the transmission or storage of the first CAN bus data to be verified; if the second calculation result is inconsistent with the first calculation result, it means that an error occurred in the transmission or storage of the first CAN bus data to be verified.

[0070] The control unit verifies the accuracy of CAN bus data transmission and reception, improving the reliability of the data usage system.

[0071] This embodiment proposes a CAN bus data verification method, which can be used as one of the multiple methods for data transmission verification. In actual engineering applications, a suitable data verification method can be selected according to the specific situation. For example, when the data accuracy is extremely high and the system resources are sufficient, CRC verification can be given priority; and in some scenarios that are sensitive to system resource occupancy and have relatively high requirements for data accuracy, the verification method of the present invention is more applicable. In addition, different verification methods can be flexibly selected according to factors such as the data transmission rate and the amount of data to achieve the best verification effect.

[0072] Further, see Figure 1 and Figure 2 The present embodiment provides a CAN bus data verification method. In step S100, the first frame data in the first CAN bus data is verified. Assume that the first frame data is B n , then the first frame data is represented as follows:

[0073] B n =B0B1B2B3…B n-1 (1)

[0074] In formula (1), B nIndicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all previous bytes, that is, the last byte of each frame of message data is the check byte.

[0075] The first verification result B of the first frame data n-1 The calculation formula is as follows:

[0076]

[0077] In formula (2), the overline “-” indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

[0078] Preferably, see Figure 1 and Figure 2 The present embodiment provides a CAN bus data verification method. In step S200, the second frame data in the second CAN bus data is verified. Assume that the second frame data is C n , then the second frame data is expressed as follows:

[0079] C n =C0C1C2C3…C n-1 (3)

[0080] In formula (3), C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all previous bytes, that is, the last byte of each frame of message data is the check byte.

[0081] The second verification result C of the second frame data n-1 The calculation formula is as follows:

[0082]

[0083] In formula (4), the overline “-” indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

[0084] Further, see Figure 1 and Figure 2 In a CAN bus data verification method provided in this embodiment, in step S300, the control unit generates a second verification result C of the second frame data. n-1 The first check result B with the first frame data n-1 Compare, if the second verification result C of the second frame data n-1 The first check result B with the first frame data n-1 If the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; if the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; n-1 The first check result B with the first frame data n-1 If they are inconsistent, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.

[0085] The present embodiment relates to a CAN bus data verification system, comprising a data sending unit, a data receiving unit and a control unit, wherein the data sending unit is used to calculate the first CAN bus data to be verified according to a defined first calculation method to obtain a first calculation result, and send the first CAN bus data to the data receiving unit; the data receiving unit is used to obtain the second CAN bus data after receiving the first CAN bus data sent by the data sending unit, and calculate the second CAN bus data according to a defined second calculation method to obtain a second calculation result; the control unit is used to compare the second calculation result with the first calculation result, if the second calculation result is consistent with the first calculation result, it means that the first CAN bus data to be verified has no error during transmission or storage; if the second calculation result is inconsistent with the first calculation result, it means that the first CAN bus data to be verified has an error during transmission or storage.

[0086] In the data sending unit, the first calculation method adopts an XOR inversion operation, which is used to perform an XOR operation on each byte in the data frame of the first CAN bus data to be verified, and invert the result of the XOR operation. By performing an XOR operation on each byte in the data frame of the first CAN bus data in sequence, errors in the data can be effectively detected. By inverting the result of the XOR operation of the first CAN bus data, the accuracy and reliability of the verification are further enhanced.

[0087] In the receiving data unit, the second calculation method adopts an XOR inversion operation, which is used to perform XOR operations on each byte in the data frame of the second CAN bus data in sequence, and the result of the XOR operation is inverted. By performing XOR operations on each byte in the data frame of the second CAN bus data in sequence, errors in the data can be effectively detected. By inverting the result of the XOR operation of the second CAN bus data, the accuracy and reliability of the verification are further enhanced. The second calculation method can be the same as the first calculation method, or it can be different.

[0088] The control unit verifies the accuracy of CAN bus data transmission and reception, improving the reliability of the data usage system.

[0089] Furthermore, in the CAN bus data verification system provided by this embodiment, the first calculation result is the first verification result of the first frame data. In the data sending unit, the first frame data in the first CAN bus data is verified. Assume that the first frame data is B n , then the first frame data is represented as follows:

[0090] B n =B0B1B2B3…B n-1 (5)

[0091] In formula (5), B n Indicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0092] The first verification result B of the first frame data n-1 The calculation formula is as follows:

[0093]

[0094] In formula (6), the overline “-” indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

[0095] Preferably, in the CAN bus data verification system provided by this embodiment, the second calculation result is the second verification result of the second frame data. In the received data unit, the second frame data in the second CAN bus data is verified. The second frame data is C n , then the second frame data is expressed as follows:

[0096] C n =C0C1C2C3…C n-1 (7)

[0097] In formula (7), C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte;

[0098] The second verification result C of the second frame data n-1 The calculation formula is as follows:

[0099]

[0100] In formula (8), the overline “-” indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

[0101] Furthermore, in the CAN bus data verification system provided in this embodiment, the control unit converts the second verification result C of the second frame data into n-1 The first check result B with the first frame data n-1 Compare, if the second verification result C of the second frame data n-1 The first check result B with the first frame data n-1 If the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; if the second verification result C of the second frame data is consistent, it means that there is no error in the transmission or storage process of the first CAN bus data to be verified; n-1 The first check result B with the first frame data n-1 If they are inconsistent, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.

[0102] The following is explained with specific embodiments:

[0103] For example, if the frame data has 8 bytes, the check result is B7, and the 8 bytes of data B8 sent and the check result B7 can be expressed as follows:

[0104] B8=B0B1B2B3B4B5B6B7

[0105]

[0106] The seven bytes of the data frame B8 above are application data bytes, and the last word B7 is a check byte. The calculation formula of the check byte B7 is as shown above.

[0107] like Figure 2 As shown, the calculated value of the verification result B7 can also be expressed in an intuitive way.

[0108] Compared with the prior art, the CAN bus data verification method and system provided in this embodiment have the following beneficial effects:

[0109] 1. In terms of accuracy and error rate, this embodiment has more advantages than parity check and cumulative sum check.

[0110] Parity check and cumulative sum check are more traditional data verification methods, but they both have certain limitations. Taking parity check as an example, it simply checks the parity of the number of "1" in the data. This method is too simple and cannot accurately locate the specific error bit. For example, in the original data, if the number of "1" is odd, when two "1"s are converted to "0" and two "0"s are converted to "1", from the perspective of parity, the total parity of the number of "1" in the data has not changed. In this case, parity check is completely unable to detect that the data has errors.

[0111] Cumulative sum check also has similar problems, and its ability to detect data errors is limited. The verification method adopted by the present invention is a more advanced XOR operation verification. Although this verification method is not absolutely error-free, since the situation of XOR operation error has specific requirements for data bits, this makes the possibility of error in this embodiment significantly reduced in practical applications compared with parity check and cumulative sum check, thereby providing more reliable guarantee for accurate data verification.

[0112] 2. In terms of system resource usage, compared with CRC verification, this embodiment has obvious advantages.

[0113] CRC verification is a widely used verification method, including CRC-8, CRC-16, CRC-32 and other polynomial forms. However, when the amount of data to be verified is large, CRC verification, which is based on cyclic redundancy calculation, has obvious shortcomings. It will occupy a large amount of system computing resources, because in the calculation process, complex cyclic calculations need to be performed on the data. As the amount of data increases, the amount of calculation will increase exponentially, thus placing high demands on the system's computing power.

[0114] Different from this, the XOR operation verification method used in this embodiment will also occupy certain system computing resources during operation, but since the XOR operation itself is relatively simple and direct, compared with the complex cyclic redundancy calculation of CRC verification, its operation process is concise and clear. Therefore, when performing data verification, this embodiment occupies fewer system computing resources, which enables this embodiment to run more efficiently in a system environment with limited resources, and also frees up more computing resources for the realization of other system functions.

[0115] Although preferred embodiments of the present invention have been described, additional changes and modifications may be made to these embodiments by those skilled in the art once the basic inventive concepts are known. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention. Obviously, those skilled in the art may make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.

Claims

1. A CAN bus data verification method, characterized in that: The following steps are involved: The data sending unit calculates the first CAN bus data to be verified according to a defined first calculation method to obtain a first calculation result, and sends the first CAN bus data to the data receiving unit; After receiving the first CAN bus data sent by the data sending unit, the data receiving unit obtains the second CAN bus data, and calculates the second CAN bus data according to a defined second calculation method to obtain a second calculation result; The control unit compares the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that no error occurs in the transmission or storage process of the first CAN bus data to be verified; If the second calculation result is inconsistent with the first calculation result, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.

2. The CAN bus data verification method according to claim 1, characterized in that: The first calculation result is the first verification result of the first frame data. The data sending unit calculates the first CAN bus data to be verified according to the defined first calculation method to obtain the first calculation result, and sends the first CAN bus data to the receiving data unit. In the step, the first frame data in the first CAN bus data is verified. Assume that the first frame data is B n , then the first frame data is represented as follows: B n =B0B1B2B3…B n-1 Among them, B n Indicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte; The first verification result B of the first frame data n-1 The calculation formula is as follows: The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

3. The CAN bus data verification method according to claim 2, characterized in that: The second calculation result is a second verification result of the second frame data. After the data receiving unit receives the first CAN bus data sent by the data sending unit, it obtains the second CAN bus data and calculates the second CAN bus data according to the defined second calculation method. In the step of obtaining the second calculation result, the second frame data in the second CAN bus data is verified, and the second frame data is set to C n , then the second frame data is expressed as follows: C n =C0C1C2C3…C n-1 Among them, C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte; The second verification result C of the second frame data n-1 The calculation formula is as follows: The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

4. The CAN bus data verification method according to claim 3, characterized in that: The control unit compares the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that no error occurs in the transmission or storage process of the first CAN bus data to be verified; If the second calculation result is inconsistent with the first calculation result, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified. In the step, the control unit converts the second verification result C of the second frame data into n-1 and the first verification result B of the first frame data n-1 Compare, if the second verification result C of the second frame data n-1 and the first verification result B of the first frame data n-1 If they are consistent, it means that no error occurs in the transmission or storage process of the first CAN bus data to be verified; If the second verification result C of the second frame data n-1 and the first verification result B of the first frame data n-1 If they are inconsistent, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.

5. A CAN bus data verification system, characterized in that: It includes a data sending unit, a data receiving unit and a control unit, wherein: The data sending unit is used to calculate the first CAN bus data to be verified according to the defined first calculation method, obtain a first calculation result, and send the first CAN bus data to the data receiving unit; The data receiving unit is used to obtain second CAN bus data after receiving the first CAN bus data sent by the data sending unit, and calculate the second CAN bus data according to a defined second calculation method to obtain a second calculation result; The control unit is used to compare the second calculation result with the first calculation result. If the second calculation result is consistent with the first calculation result, it means that there is no error in the transmission or storage of the first CAN bus data to be verified; if the second calculation result is inconsistent with the first calculation result, it means that an error occurred in the transmission or storage of the first CAN bus data to be verified.

6. The CAN bus data verification system according to claim 5, characterized in that: The first calculation result is a first verification result of the first frame data. In the data sending unit, the first frame data in the first CAN bus data is verified. Assume that the first frame data is B n , then the first frame data is represented as follows: B n =B0B1B2B3…B n-1 Among them, B n Indicates the first frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, B0 indicates the first byte in the first frame of data, B1 indicates the second byte in the first frame of data, B2 indicates the third byte in the first frame of data, B3 indicates the fourth byte in the first frame of data, B n-1 Indicates the last byte in the first frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte; The first verification result B of the first frame data n-1 The calculation formula is as follows: The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the first check result of the first frame of data is B n-1 The calculated value is the XOR operation of the first byte B0 of the message and the second byte B1 of the message, and the result is XORed with the third byte B2 of the message. According to this operation rule, it is XORed with the last byte B n-2 After performing the XOR operation, the result is negated and the result is B. n-1 , and B n-1 Placed in B n The last byte of the data frame.

7. The CAN bus data verification system according to claim 6, characterized in that: The second calculation result is a second verification result of the second frame data. In the receiving data unit, the second frame data in the second CAN bus data is verified. Assume that the second frame data is C n , then the second frame data is expressed as follows: C n =C0C1C2C3…C n-1 Among them, C n Indicates the second frame of data sent in each frame of message, n indicates the number of bytes in the first frame of data, C0 indicates the first byte in the second frame of data, C1 indicates the second byte in the second frame of data, C2 indicates the third byte in the second frame of data, C3 indicates the fourth byte in the first frame of data, C n-1 Indicates the last byte in the second frame of data, which is placed at the last byte as the check result of all the previous bytes, that is, the last byte of each frame of message data is the check byte; The second verification result C of the second frame data n-1 The calculation formula is as follows: The overline "-" indicates a negation operation. Indicates that an XOR operation is performed, and the second check result C of the second frame data n-1 The calculated value is the XOR operation of the first byte C0 of the message and the second byte C1 of the message, and the result is XORed with the third byte C2 of the message. According to this operation rule, it is XORed with the last byte C n-2 After performing the XOR operation, the result is negated and the result is C. n-1 , and C n-1 Placed in C n The last byte of the data frame.

8. The CAN bus data verification system according to claim 7, characterized in that: In the control unit, the control unit converts the second verification result C of the second frame data into n-1 and the first verification result B of the first frame data n-1 Compare, if the second verification result C of the second frame data n-1 and the first verification result B of the first frame data n-1 If they are consistent, it means that no error occurs in the transmission or storage process of the first CAN bus data to be verified; If the second verification result C of the second frame data n-1 and the first verification result B of the first frame data n-1 If they are inconsistent, it means that an error occurs in the transmission or storage process of the first CAN bus data to be verified.