Real-time detection method, system and equipment for communication abnormity of automobile CAN (Controller Area Network) bus
By receiving and analyzing communication messages in the automotive CAN bus system, calculating the average cycle and bus load rate, the problem of difficulty in real-time detection in the prior art is solved, efficient and accurate communication abnormality detection is achieved, and cost is reduced.
Patent Information
- Application Number
- CN202411669215.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-21
- Publication Date
- 2025-02-28
AI Technical Summary
The prior art is difficult to realize real-time detection of automotive CAN bus communication, and the cost of using external equipment or upper computer detection methods is high.
By receiving communication messages on the CAN bus, judge their importance, calculate the average period and bus load rate, and confirm whether the communication is abnormal based on these two indicators.
It realizes real-time and accurate detection of vehicle CAN bus communication abnormalities without external equipment and host computers, reducing detection costs.
Smart Images

Figure CN119544550A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the field of bus communication detection, and in particular relates to a real-time detection method, system and equipment for abnormal communication of a CAN bus of an automobile. Background Art
[0002] The automotive CAN bus is a multi-host local area network communication protocol widely used in automobiles and other industrial control systems. It allows various electronic control units (ECUs) in the vehicle to communicate with each other to achieve information sharing and coordinated control. As the basis of vehicle control, the stability and reliability of CAN bus communication is particularly critical. The causes of CAN bus communication anomalies include: defects in bus design, such as poor quality of bus cables, terminal resistance configuration that does not meet requirements, and weak anti-interference ability; or the bus is attacked maliciously, such as replay attacks and fault injection.
[0003] In the related art, the communication detection of the automobile CAN bus mainly adopts the error correction mechanism of the serial communication protocol, such as CRC check and error frame declaration, etc. Or it adopts the detection method of external equipment or host computer.
[0004] Regarding the above-mentioned related technologies, real-time monitoring cannot be achieved by using external devices, while detection by a host computer is costly. Summary of the invention
[0005] The technical problem to be solved by the present invention is to provide a real-time detection method, system and equipment for automobile CAN bus communication anomalies, which can detect in real time without increasing costs. At the same time, two detection methods, namely average cycle and bus load rate, are used to improve the accuracy of bus communication anomaly detection.
[0006] A real-time detection method for abnormal communication of a vehicle CAN bus, comprising:
[0007] Receive communication messages on the CAN bus;
[0008] Determining whether the communication message is an important message;
[0009] If it is an important message, the average period of important messages received within a verification period is calculated;
[0010] Get the number of important messages received within a verification period;
[0011] The CAN bus load rate is calculated according to the number of messages and the load rate formula;
[0012] Whether the automobile CAN bus communication is abnormal is confirmed according to the CAN bus load rate and the average period.
[0013] Optionally, the determining whether the communication message is an important message includes:
[0014] Obtaining an identifier of an important message from an important message database;
[0015] If the identifier of the communication message is the same as the identifier of the important message in the important message database, the communication message is confirmed to be an important message.
[0016] Optionally, get the main function running time;
[0017] When an important message is received, the current reception flag is set to 1, the previous reception flag is set to 0, and the reception count is increased by 1;
[0018] Assign the value of the receiving flag bit at the previous moment to the current receiving flag bit;
[0019] Obtaining cumulative time according to the main function running time and the number of main function running times;
[0020] Determine whether the accumulated time is greater than the verification period;
[0021] If the accumulated time is less than or equal to the verification period, repeat the above steps until the accumulated time is greater than the verification period;
[0022] If the accumulated time is greater than the verification period, the average period of the important messages is calculated based on the number of receptions and the verification period.
[0023] Optionally, the calculating the CAN bus load rate according to the number of messages and the load rate formula includes:
[0024] When the accumulated time is greater than the verification period, the number of receptions is taken as the number of messages, and the CAN bus load rate is calculated according to the number of messages, the load rate formula and the bus baud rate;
[0025] The load rate formula is:
[0026] num*128*0.001*100 / Baudrate / T s ;
[0027] Among them, num is the number of messages, Baudrate is the bus baud rate, T s The calibration cycle.
[0028] Optionally, confirming whether the automobile CAN bus communication is abnormal according to the CAN bus load rate and the average period includes:
[0029] Calculate the difference between the average period and the protocol period as a comparison period;
[0030] If the comparison period is higher than the set period, it is confirmed that the average period is abnormal;
[0031] Confirm whether the CAN bus load rate is within a preset normal load rate range;
[0032] If the CAN bus load rate is within a preset normal load rate range, then confirming that the CAN bus load rate is abnormal;
[0033] If at least one of the CAN bus load rate and the average period is abnormal, it is confirmed that the vehicle CAN bus communication is abnormal.
[0034] Optionally, the set period = protocol period * 0.2.
[0035] Optionally, the verification period is 1 second.
[0036] A real-time detection system for abnormal communication of a vehicle CAN bus, comprising:
[0037] A receiving module, used for receiving communication messages on the CAN bus;
[0038] A first judgment module, used to judge whether the communication message is an important message;
[0039] A first calculation module, for calculating an average period of important messages received within a verification period if the message is an important message;
[0040] An acquisition module, used to acquire the number of important messages received within a verification period;
[0041] A second calculation module is used to calculate the CAN bus load rate according to the number of messages and the load rate formula;
[0042] The second judgment module is used to determine whether the automobile CAN bus communication is abnormal according to the CAN bus load rate and the average period.
[0043] A terminal device comprises a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor loads and executes the computer program, a real-time detection method for abnormal communication of a vehicle CAN bus is adopted.
[0044] A computer-readable storage medium stores a computer program. When the computer program is loaded and executed by a processor, a real-time detection method for abnormal communication of a vehicle CAN bus is adopted.
[0045] The beneficial effects of the present invention are:
[0046] The present application integrates a real-time detection method for abnormal communication of the automobile CAN bus into the original passenger control. By detecting the average cycle and the CAN bus load rate of the automobile CAN bus, when any one of the average cycle and the CAN bus load rate is abnormal, it is considered that the automobile CAN bus communication is abnormal. Without the aid of external equipment or an additional host computer, it is possible to accurately detect in real time whether the automobile CAN bus communication is abnormal. Moreover, the accuracy of the detection is improved by detecting the two conditions of the average cycle and the CAN bus load rate. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A flow chart of a method for real-time detection of abnormal communication of a vehicle CAN bus according to the present invention;
[0048] Figure 2 A schematic diagram of a process for calculating an average period of the present invention;
[0049] Figure 3 It is a schematic diagram of the flow chart of calculating the bus load rate according to the present invention. DETAILED DESCRIPTION
[0050] A real-time detection method for abnormal communication of automobile CAN bus, such as Figure 1 As shown, the present invention includes:
[0051] S1. Receive communication messages on the CAN bus.
[0052] Specifically, a message is the basic unit used in communication protocols and data transmission. It is a data structure that encapsulates information and is used to exchange data between different devices or systems. A message can contain various types of information, such as text, numbers, commands, status, and error information, depending on the type of communication protocol and application scenario.
[0053] S2. Determine whether the communication message is an important message.
[0054] Specifically, the importance of a message is usually evaluated based on multiple factors, such as the type of data, the sensitivity of the content, and the urgency of the purpose. Messages with higher importance are often closely related to the security, stability, and real-time performance of the system.
[0055] S3. If it is an important message, calculate the average period of the important messages received within a verification period.
[0056] Specifically, the average period of important messages received within a verification cycle is limited by a verification cycle. Within this time range, the average period of receiving each important message is obtained based on the number of important messages received and the time used. The average period is the average frequency or time interval of the appearance or processing of important messages within the verification cycle.
[0057] In practical applications, generally only relatively important messages need to be checked, and the cycle of important messages is generally shorter.
[0058] S4. Obtain the number of important messages received within a verification period.
[0059] S5. Calculate the CAN bus load rate according to the number of messages and the load rate formula.
[0060] Specifically, the CAN bus load rate refers to the ratio between the actual use of data transmission and the total bandwidth in the CAN bus system. This indicator can reflect the busyness of the network and the efficiency of the use of available bandwidth.
[0061] S6. According to the CAN bus load rate and average cycle, confirm whether the vehicle CAN bus communication is abnormal.
[0062] Specifically, the abnormality of the automobile CAN bus communication is judged in combination with the bus load rate and the average cycle, and the detection is more accurate. As long as one of the bus load rate and the average cycle is abnormal, it is considered that the automobile CAN bus communication is abnormal.
[0063] In one implementation of this embodiment, step S2, i.e., determining whether the communication message is an important message, includes:
[0064] S21. Obtain an identifier of the important message from an important message database.
[0065] Specifically, in the CAN bus, each message has a unique identifier (ID). First, it is necessary to confirm whether the message ID matches the ID of the important message. Important messages are usually pre-defined by system designers and assigned specific identifiers to form an important message database.
[0066] S22. If the identifier of the communication message is the same as the identifier of the important message in the important message database, the communication message is confirmed to be an important message.
[0067] Specifically, if the identifier of the received message can find the same identifier in the important message database, the communication message is confirmed to be an important message.
[0068] In one implementation of this embodiment, Figure 2 As shown, step S3, if it is an important message, calculate the average period of the important message received within a verification period, including:
[0069] S31. Get the main function running time.
[0070] Specifically, when performing CAN message cycle verification, the main function running time refers to the time required for each main control loop (or main program loop) to execute. In this embodiment, the main function running time Trun is set to 1 millisecond.
[0071] S32. When an important message is received, the current reception flag is set to 1, the previous reception flag is set to 0, and the reception times are increased by 1.
[0072] Specifically, in this embodiment, the number of receptions is represented by n, so each time an important message is received, the following relationship exists:
[0073] n=n+1.
[0074] S33, assigning the value of the reception flag at the previous moment to the current reception flag.
[0075] Specifically, each time an important message is received, the number of receptions is increased by 1. At the same time, the current reception flag RcvFlg is set to 1 and the reception flag RcvFlgpre at the previous moment is set to 0. When an important message cycle is completed and before the next important message enters, the current reception flag needs to be reset to 0 until a new important message enters, then it becomes 1 again.
[0076] S34. Obtain cumulative time according to the main function running time and the number of main function running times.
[0077] Specifically, the main function running time is marked as Trun, which is the time it takes for the main function to run once. Therefore, each time the main function is run once, the cumulative time is as follows:
[0078] t=t+Trun*N。
[0079] The number of main function runs is the total number of times the main function is run from the beginning of verification. Regardless of whether a message is received, the main function will continue to run. N is the number of main function runs, and the initial value of t is 0.
[0080] S35. Determine whether the accumulated time is greater than the verification period.
[0081] Specifically, the verification period is a set time, which is set to 1 second in this embodiment. When the accumulated time is greater than the verification period, the number of receptions is no longer calculated. If the accumulated time is less than or equal to the verification period, the above steps are always performed.
[0082] S36. If the accumulated time is less than or equal to the verification period, repeat the above steps until the accumulated time is greater than the verification period.
[0083] S37. If the accumulated time is greater than the verification period, the average period of the important message is calculated according to the number of receptions and the verification period.
[0084] Specifically, average period Tcur = number of receptions n / check period T s .
[0085] In one implementation of this embodiment, Figure 3 As shown, step S5 is to calculate the CAN bus load rate according to the number of messages and the load rate formula, including:
[0086] S41. When the accumulated time is greater than the verification period, the number of receptions is taken as the number of messages, and the CAN bus load rate is calculated based on the number of messages, the load rate formula and the bus baud rate.
[0087] S42, load rate formula is:
[0088] num*128*0.001*100 / Baudrate / T s ;
[0089] Among them, num is the number of messages, Baudrate is the bus baud rate, T s is the check period, 128 is the bit of a broadcast frame, and the bus baud rate BaudRate is commonly 250K and 500K (unit: bit / s).
[0090] Specifically, the number of messages is the number of important messages received within a verification period, so the number is equal to the number of reception times.
[0091] In one implementation of this embodiment, step S6, that is, confirming whether the vehicle CAN bus communication is abnormal according to the CAN bus load rate and the average cycle, includes:
[0092] S51. Calculate the difference between the average period and the protocol period as a comparison period.
[0093] Specifically, the protocol cycle refers to a period of time used for data exchange, message delivery, or event processing in a communication protocol.
[0094] Comparison period = |average period Tcur - protocol period Ttar|.
[0095] S52: If the comparison period is higher than the set period, it is determined that the average period is abnormal.
[0096] Specifically, in this embodiment, the setting period=protocol period*0.2.
[0097] S53: confirm whether the CAN bus load rate is within a preset normal load rate range.
[0098] Specifically, the normal load rate range is [Ratemin, Ratemax], where Ratemin and Ratemax are respectively the normal minimum load rate of the bus and the normal maximum load rate of the bus, and are set according to the actual situation of the bus. In this embodiment, Ratemin is temporarily set to 1 and Ratemax is temporarily set to 70. If the bus load rate Loadrate is not in the normal load rate range, it means that the bus load rate is abnormal.
[0099] S54, if the CAN bus load rate is within the preset normal load rate range, confirming that the CAN bus load rate is abnormal;
[0100] If at least one of the CAN bus load rate and the average cycle is abnormal, it is confirmed that the vehicle CAN bus communication is abnormal.
[0101] When the CAN bus load rate is abnormal, the bus load rate abnormal flag can be changed to 1 and an alarm will be issued.
[0102] When the average cycle is abnormal, the average cycle abnormal flag bCanCycleErr is changed to 1 and an alarm is issued.
[0103] After each verification cycle, by initializing num and t, the load rate of the CAN bus can be continuously verified; by applying the array, multiple CAN buses can be verified at the same time. Similarly, after each verification cycle, by initializing n and t, the target message can be continuously verified; by applying the array, multiple target messages can be verified at the same time.
[0104] A real-time detection system for abnormal communication of a vehicle CAN bus, comprising:
[0105] A receiving module, used for receiving communication messages on the CAN bus;
[0106] A first judgment module, used to judge whether the communication message is an important message;
[0107] A first calculation module, for calculating an average period of important messages received within a verification period if the message is an important message;
[0108] An acquisition module, used to acquire the number of important messages received within a verification period;
[0109] The second calculation module is used to calculate the CAN bus load rate according to the number of messages and the load rate formula;
[0110] The second judgment module is used to determine whether the vehicle CAN bus communication is abnormal according to the CAN bus load rate and the average cycle.
[0111] The embodiment of the present application also discloses a terminal device, including a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor loads and executes the computer program, a real-time detection method for automobile CAN bus communication anomalies is adopted.
[0112] The terminal device may be a computer device such as a desktop computer, a laptop computer or a cloud server, and the terminal device includes but is not limited to a processor and a memory. For example, the terminal device may also include input and output devices, a network access device and a bus.
[0113] Among them, the processor can adopt a central processing unit (CPU). Of course, according to actual usage, other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. can also be adopted. The general-purpose processor can adopt a microprocessor or any conventional processor, etc., and this application does not impose any restrictions on this.
[0114] Among them, the memory can be an internal storage unit of the terminal device, such as a hard disk or memory of the terminal device, or it can be an external storage device of the terminal device, such as a plug-in hard disk, a smart memory card (SMC), a secure digital card (SD) or a flash memory card (FC) equipped on the terminal device, etc., and the memory can also be a combination of an internal storage unit and an external storage device of the terminal device. The memory is used to store computer programs and other programs and data required by the terminal device. The memory can also be used to temporarily store data that has been output or is to be output, and this application does not impose any restrictions on this.
[0115] Among them, through this terminal device, a real-time detection method of automobile CAN bus communication anomaly in the above embodiment is stored in the memory of the terminal device, and is loaded and executed on the processor of the terminal device for easy use.
[0116] An embodiment of the present application further discloses a computer-readable storage medium, and the computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, a real-time detection method for automobile CAN bus communication anomalies in the above embodiment is adopted.
[0117] Among them, the computer program can be stored in a computer-readable medium, the computer program includes computer program code, the computer program code can be in the form of source code, object code, executable file or certain middleware, etc. The computer-readable medium includes any entity or device that can carry the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc. It should be noted that the computer-readable medium includes but is not limited to the above-mentioned components.
[0118] Among them, through this computer-readable storage medium, a real-time detection method for automobile CAN bus communication anomalies in the above embodiment is stored in a computer-readable storage medium, and is loaded and executed on a processor to facilitate the storage and application of the above method.
[0119] A person skilled in the art should understand that the discussion of any of the above embodiments is merely illustrative and is not intended to imply that the scope of protection of the present application is limited to these examples. In line with the concept of the present application, the technical features in the above embodiments or different embodiments may be combined, the steps may be implemented in any order, and there are many other variations of different aspects of one or more embodiments of the present application as above, which are not provided in detail for the sake of simplicity.
[0120] One or more embodiments of the present application are intended to cover all such substitutions, modifications and variations that fall within the broad scope of the present application. Therefore, any omissions, modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present application should be included in the protection scope of the present application.
Claims
1. A real-time detection method for abnormal communication of automobile CAN bus, characterized in that: include: Receive communication messages on the CAN bus; Determining whether the communication message is an important message; If it is an important message, the average period of important messages received within a verification period is calculated; Get the number of important messages received within a verification period; The CAN bus load rate is calculated according to the number of messages and the load rate formula; Whether the automobile CAN bus communication is abnormal is confirmed according to the CAN bus load rate and the average period.
2. The real-time detection method for automobile CAN bus communication anomaly according to claim 1 is characterized in that: The determining whether the communication message is an important message comprises: Obtaining an identifier of an important message from an important message database; If the identifier of the communication message is the same as the identifier of the important message in the important message database, the communication message is confirmed to be an important message.
3. The real-time detection method of automobile CAN bus communication anomaly according to claim 1 is characterized in that: If it is an important message, the average period of important messages received within a verification period is calculated including: Get the main function running time; When an important message is received, the current reception flag is set to 1, the previous reception flag is set to 0, and the number of receptions is increased by 1; Assign the value of the receiving flag bit at the previous moment to the current receiving flag bit; Obtaining cumulative time according to the main function running time and the number of main function running times; Determine whether the accumulated time is greater than the verification period; If the accumulated time is less than or equal to the verification period, repeat the above steps until the accumulated time is greater than the verification period; If the accumulated time is greater than the verification period, the average period of the important messages is calculated based on the number of receptions and the verification period.
4. The real-time detection method of automobile CAN bus communication anomaly as claimed in claim 3 is characterized in that: The CAN bus load rate is calculated according to the number of messages and the load rate formula, including: When the accumulated time is greater than the verification period, the number of receptions is taken as the number of messages, and the CAN bus load rate is calculated according to the number of messages, the load rate formula and the bus baud rate; The load rate formula is: num*128*0.001*100 / Baudrate / T s ; Among them, num is the number of messages, Baudrate is the bus baud rate, T s The calibration cycle.
5. The real-time detection method of automobile CAN bus communication anomaly according to claim 1 is characterized in that: According to the CAN bus load rate and the average period, confirming whether the vehicle CAN bus communication is abnormal includes: Calculate the difference between the average period and the protocol period as a comparison period; If the comparison period is higher than the set period, it is confirmed that the average period is abnormal; Confirm whether the CAN bus load rate is within a preset normal load rate range; If the CAN bus load rate is within a preset normal load rate range, then confirming that the CAN bus load rate is abnormal; If at least one of the CAN bus load rate and the average period is abnormal, it is confirmed that the vehicle CAN bus communication is abnormal.
6. The real-time detection method of automobile CAN bus communication anomaly as claimed in claim 5 is characterized in that: include: The setting period=protocol period*0.
2.
7. The real-time detection method of automobile CAN bus communication anomaly according to claim 1, characterized in that: include: The verification period is 1 second.
8. A real-time detection system for abnormal communication of automobile CAN bus, characterized in that: include: A receiving module, used for receiving communication messages on the CAN bus; A first judgment module, used to judge whether the communication message is an important message; A first calculation module, for calculating an average period of important messages received within a verification period if the message is an important message; An acquisition module, used to acquire the number of important messages received within a verification period; A second calculation module is used to calculate the CAN bus load rate according to the number of messages and the load rate formula; The second judgment module is used to determine whether the automobile CAN bus communication is abnormal according to the CAN bus load rate and the average period.
9. A terminal device, comprising a memory and a processor, characterized in that: The memory stores a computer program that can be run on the processor, and when the processor loads and executes the computer program, the method according to any one of claims 1 to 7 is adopted.
10. A computer-readable storage medium having a computer program stored therein, characterized in that: When the computer program is loaded and executed by a processor, the method according to any one of claims 1 to 7 is adopted.