CAN communication detection method and device, detected equipment and storage medium
By adopting a loopback testing mechanism between the two CAN channels of the equipment under test, the problem that the existing technology cannot meet the simultaneous detection of multiple CAN channels is solved, and efficient CAN communication detection and communication quality evaluation are achieved, which improves the testing efficiency.
Patent Information
- Application Number
- CN202411885538.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-19
- Publication Date
- 2025-03-21
AI Technical Summary
The existing CAN communication detection mechanism cannot meet the simultaneous detection requirements of multiple CAN channels, especially in high-speed transmission scenarios, traditional methods have upper frame limits, and cannot effectively evaluate the communication quality of multiple CAN channels.
CAN communication detection is achieved by using a loopback test mechanism between the two CAN channels of the device under test. The specific steps include: receiving the reception enable command and heartbeat start command sent by the upper computer, enabling the reception function of the target CAN channel, periodically sending heartbeat messages and recording the transmission and reception status, and sending reported messages to the upper computer every preset period to conduct communication quality evaluation.
The simultaneous detection of multiple CAN channels is realized, the testing efficiency is improved, the communication quality of each pair of target CAN channels can be effectively evaluated, and the detection requirements of high-speed transmission are met.
Smart Images

Figure CN119676111A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of testing, and in particular to a CAN communication detection method, device, tested equipment and storage medium. Background Art
[0002] A CAN (Controller Area Network) channel refers to a physical or logical interface on a device that is used to implement CAN communication. The CAN channel allows a device to exchange data with other devices on the CAN network.
[0003] In order to ensure the availability of the CAN channel, it is necessary to perform communication tests on the CAN channel. A traditional CAN communication detection mechanism is to connect the CAN channel of the device under test to a CAN bus, and then connect the CAN bus to a third-party detection tool. However, since any manufacturer's third-party detection tools have a performance ceiling, it means that the maximum number of frames on a CAN bus is limited, so the number of frames allocated to each CAN channel is also limited. The more CAN channels on the CAN bus, the lower the upper limit of the number of frames corresponding to each CAN channel. In this case, some CAN high-speed transmission detection scenarios cannot be met, especially when the device under test has multiple CAN channels. Summary of the invention
[0004] The object of the present invention is to provide a CAN communication detection method, device, tested equipment and storage medium to improve the problems existing in the prior art.
[0005] The embodiments of the present invention can be implemented as follows:
[0006] In a first aspect, the present invention provides a CAN communication detection method, which is applied to a device under test, wherein the device under test is communicatively connected to a host computer; the device under test includes multiple pairs of CAN channels, and two CAN channels of each pair of CAN channels are communicatively connected; the method includes:
[0007] When receiving the receiving enable instruction sent by the host computer, after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, feeding back a start response signal to the host computer;
[0008] When a heartbeat start instruction sent by the host computer is received, a heartbeat message is periodically sent on each target CAN channel based on the heartbeat start instruction, and the sending and receiving status of each target CAN channel is recorded;
[0009] At every preset reporting cycle, a reporting message is sent to the host computer based on the receiving and sending status of each target CAN channel, so that the host computer performs communication quality evaluation on each pair of target CAN channels based on at least one received reporting message.
[0010] Optionally, the step of enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction includes:
[0011] Parsing the receiving enable instruction to obtain channel identification information and a receiving enable signal;
[0012] Based on the channel identification information, determining at least one pair of target CAN channels from all CAN channels;
[0013] Based on the enable signal, the receiving function of each of the target CAN channels is enabled.
[0014] Optionally, the step of periodically sending a heartbeat message on each target CAN channel based on the heartbeat start instruction and recording the sending and receiving status of each target CAN channel includes:
[0015] Parsing the heartbeat start instruction to obtain channel identification information, cycle data and count reset signal;
[0016] Based on the count reset signal, the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information are set to 0;
[0017] For each of the target CAN channels, the heartbeat message is periodically sent on the target CAN channel based on the periodic data; and, each time the heartbeat message is sent through the target CAN channel, the sending count value corresponding to the target CAN channel is increased by 1, and each time the target CAN channel receives a heartbeat message, the receiving count value corresponding to the target CAN channel is increased by 1.
[0018] Optionally, the step of sending a report message to the host computer based on the transceiver status of each target CAN channel includes:
[0019] Obtaining the sending and receiving status of each target CAN channel; the sending and receiving status includes a sending count value and a receiving count value;
[0020] Based on the receiving and sending status of each target CAN channel, generating the reporting message;
[0021] The report message is sent to the host computer.
[0022] In a second aspect, the present invention provides a CAN communication detection method, which is applied to a detection system, wherein the detection system includes a host computer and at least one device under test that is communicatively connected to the host computer; the device under test includes multiple pairs of CAN channels, and two CAN channels of each pair of CAN channels are communicatively connected; the method includes:
[0023] The host computer sends a receiving enable instruction to each of the devices under test;
[0024] After each of the devices under test starts the receiving function of at least one pair of target CAN channels based on the received receiving enable instruction, a start response signal is fed back to the host computer;
[0025] When the host computer receives the start response signal returned by each of the devices under test, it sends a heartbeat start instruction to each of the devices under test;
[0026] Each of the devices under test periodically sends a heartbeat message on each of the target CAN channels based on the received heartbeat start instruction, and records the sending and receiving status of each of the target CAN channels;
[0027] Each of the devices under test sends a reporting message to the host computer based on the transceiver status of each of the target CAN channels at every preset reporting period;
[0028] Each time the host computer receives a report message, it stores the report data in the report message; the report data includes the sending and receiving status of each target CAN channel of the device under test;
[0029] The host computer performs communication quality evaluation on each pair of target CAN channels of each of the devices under test based on multiple copies of reported data of each of the devices under test within the evaluation period at every preset evaluation period.
[0030] Optionally, the reported data includes a sending sequence and a receiving sequence, the i-th data and the i+1-th data in the sending sequence are the sending count values of the two target CAN channels of the communication connection, and the i-th data and the i+1-th data in the receiving sequence are the receiving count values of the two target CAN channels of the communication connection, where i is an odd number;
[0031] The step of the host computer evaluating the communication quality of each pair of target CAN channels of each of the devices under test based on multiple copies of reported data of each of the devices under test within the evaluation period includes:
[0032] For each reported data of each of the devices under test, the i-th sending count value and the i+1-th sending count value, the i-th receiving count value and the i+1-th receiving count value are obtained from the sending sequence and the receiving sequence respectively; wherein i=1, 3, 5, ..., 2N-1, and N is a positive integer;
[0033] Calculate the ratio between the i+1th receiving count value and the i-th sending count value to obtain the packet loss rate of the i+1th target CAN channel of the device under test;
[0034] Calculate the ratio between the i-th receiving count value and the i+1-th sending count value to obtain the packet loss rate of the i-th target CAN channel of the device under test;
[0035] For each of the target CAN channels of each of the devices under test, a packet loss line graph of the target CAN channel within the evaluation period is generated based on multiple packet loss rates of the target CAN channel.
[0036] In a third aspect, the present invention provides a CAN communication detection device, which is applied to a device under test, wherein the device under test is communicatively connected to a host computer; the device under test comprises a plurality of pairs of CAN channels, and the two CAN channels of each pair of CAN channels are communicatively connected; the device comprises:
[0037] A receiving start module, used for receiving a receiving enable instruction sent by the host computer, and after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, feeding back a start response signal to the host computer;
[0038] A loop detection module, used for receiving a heartbeat start instruction sent by the host computer, periodically sending a heartbeat message on each target CAN channel based on the heartbeat start instruction, and recording the sending and receiving status of each target CAN channel;
[0039] The reporting module is used to send a reporting message to the host computer based on the receiving and sending status of each target CAN channel at every preset reporting cycle, so that the host computer can evaluate the communication quality of each pair of target CAN channels based on at least one received reporting message.
[0040] Optionally, when the loop detection module is used to periodically send a heartbeat message on each target CAN channel based on the heartbeat start instruction and record the sending and receiving status of each target CAN channel, it is specifically used to:
[0041] Parsing the heartbeat start instruction to obtain channel identification information, cycle data and count reset signal;
[0042] Based on the count reset signal, the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information are set to 0;
[0043] For each of the target CAN channels, the heartbeat message is periodically sent on the target CAN channel based on the periodic data; and, each time the heartbeat message is sent through the target CAN channel, the sending count value corresponding to the target CAN channel is increased by 1, and each time the target CAN channel receives a heartbeat message, the receiving count value corresponding to the target CAN channel is increased by 1.
[0044] In a fourth aspect, the present invention provides a device under test, comprising: a memory and a processor, wherein the memory stores a software program, and when the device under test is running, the processor executes the software program to implement the CAN communication detection method as described in the first aspect above.
[0045] In a fifth aspect, the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the CAN communication detection method described in the first aspect is implemented.
[0046] Compared with the prior art, the embodiment of the present invention provides a CAN communication detection method, device, device under test and storage medium. The method is applied to a device under test connected to a host computer for communication. The device under test includes multiple pairs of CAN channels, and the two CAN channels of each pair of CAN channels are connected for communication. Therefore, when the device under test receives a receiving enable instruction sent by the host computer, after the receiving function of at least one pair of target CAN channels is turned on based on the receiving enable instruction, a start response signal is fed back to the host computer; when a heartbeat start instruction sent by the host computer is received, a heartbeat message is periodically sent in each target CAN channel based on the heartbeat start instruction, and the transceiver status of each target CAN channel is recorded; every preset reporting period, a reporting message is sent to the host computer based on the transceiver status of each target CAN channel, so that the host computer performs communication quality evaluation on each pair of target CAN channels based on at least one reporting message received. The present invention adopts a loopback test mechanism between two CAN channels of the device under test to realize CAN communication detection, meets the demand for simultaneous detection of multiple CAN channels, and improves test efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.
[0048] Figure 1 This is an example diagram of an application scenario of the present invention.
[0049] Figure 2 One of the flow charts of a CAN communication detection method provided in an embodiment of the present invention.
[0050] Figure 3 The second flowchart of a CAN communication detection method provided by an embodiment of the present invention.
[0051] Figure 4 A schematic diagram of the structure of a CAN communication detection device provided by an embodiment of the present invention.
[0052] Figure 5 A schematic diagram of the structure of a device under test provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.
[0054] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0055] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.
[0056] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.
[0057] There are usually two traditional CAN communication detection mechanisms: one is to connect the CAN channel of the device under test to a third-party detection tool (the detection tool is generally a CAN box or CAN card); the other is to connect the CAN channel of the device under test to a CAN bus, and then connect the CAN bus to the third-party detection tool.
[0058] The first detection mechanism mentioned above can usually meet the common CAN communication test and stress test, but its detection capability often depends on third-party detection tools. In addition, when the device under test has many CAN channels, or multiple devices under test need to be detected at the same time, it means that more third-party detection tool resources are required, which is very costly.
[0059] The second detection mechanism mentioned above uses the CAN bus, which saves some resources of third-party detection tools to a certain extent. However, third-party detection tools of any manufacturer have performance limits, which means that the maximum number of frames on a CAN bus is limited, so the number of frames allocated to each CAN channel is also limited. The more CAN channels on the CAN bus, the lower the upper limit of the number of frames corresponding to each CAN channel. In this case, some detection scenarios with high CAN transmission rates cannot be met, especially when the device under test has multiple CAN channels.
[0060] The above two CAN communication detection mechanisms have certain shortcomings both in application scenarios and in terms of time cost and resource cost.
[0061] Based on the discovery of the above technical problems, the inventors have proposed the following technical solutions to solve or improve the above problems through creative work. It should be noted that the defects in the solutions in the above prior art are the results obtained by the inventors after practice and careful research. Therefore, the discovery process of the above problems and the solutions proposed in the embodiments of the present application for the above problems below should all be the contributions made by the inventors to the present application in the process of invention and creation, and should not be understood as technical contents known to those skilled in the art.
[0062] In view of this, an embodiment of the present invention provides a CAN communication detection method, which can use a loopback test mechanism between two CAN channels of a device under test to implement CAN communication detection, meet the requirements of simultaneous detection of multiple CAN channels, and improve test efficiency. The following is a detailed description through embodiments and in conjunction with the attached drawings.
[0063] The application scenarios of the present invention are first introduced below.
[0064] The invention provides a detection system, which comprises a host computer and at least one device under test which is communicatively connected to the host computer; the device under test comprises a plurality of pairs of CAN channels, and two CAN channels of each pair of CAN channels are communicatively connected.
[0065] The host computer can be a personal notebook, a personal computer (PC), a desktop computer, a server, etc. The device under test can be but is not limited to the following devices:
[0066] (1) Industrial controllers: such as programmable logic controllers (PLCs) and industrial PCs. These controllers require multiple CAN channels to monitor and control devices on multiple CAN networks.
[0067] (2) Data logger: used to record and analyze data on the CAN network, especially during vehicle testing and development;
[0068] (3) Electronic Control Unit (ECU): Inside the vehicle, some advanced ECUs may have multiple CAN interfaces for controlling different vehicle systems.
[0069] (4) Test and simulation equipment: used to simulate node behavior on the CAN network during the development of automotive electronic systems;
[0070] (5) Robot controller: In automation and robotics, the controller may need to manage different actuators and sensors through multiple CAN interfaces.
[0071] For an optional example, see Figure 1 , Figure 1 This is an example diagram of an application scenario of the present invention. Figure 1 In the process, each device under test is connected to a network switch via a network cable, and the network switch is connected to a host computer (i.e., a PC), so that the host computer and each device under test can communicate using Ethernet.
[0072] Combination Figure 1 Each device under test includes 6 CAN channels (i.e. CAN1~CAN6), among which: CAN1 is connected to CAN2, CAN3 is connected to CAN4, and CAN5 is connected to CAN6, thus forming 3 pairs of CAN channels. Under the control of the host computer, each pair of CAN channels can communicate based on the loopback test mechanism (also called the custom heartbeat mechanism), thereby realizing simultaneous detection of multiple CAN channels.
[0073] It should be noted that Figure 1 The figure is only an example, and the embodiment of the present invention does not limit the number of CAN channels on the device under test.
[0074] See also Figure 2 , Figure 2 This is one of the flow charts of a CAN communication detection method provided by an embodiment of the present invention. The CAN communication detection method is applied to the device under test in the above detection system, and the CAN communication detection method may include the following steps S101 to S103.
[0075] S101. When a receiving enable instruction sent by a host computer is received, after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, a start response signal is fed back to the host computer.
[0076] In this embodiment, the receiving enable instruction is used to instruct the device under test to enable the receiving function of at least one pair of target CAN channels specified by the host computer. After being enabled, the device under test also needs to feed back a startup response signal to the host computer, which indicates that the receiving function of at least one pair of target CAN channels has been successfully enabled.
[0077] Optionally, the receiving function of the CAN channel can be turned on and off by controlling a hardware pin, such as RXEN (receive enable); or, the receiving function of the CAN channel can be turned on and off by controlling a software configuration register, for example, by setting a specific bit or mask to enable the receiving function.
[0078] S102: When a heartbeat start instruction is received from the host computer, a heartbeat message is periodically sent out on each target CAN channel based on the heartbeat start instruction, and the sending and receiving status of each target CAN channel is recorded.
[0079] In this embodiment, when the host computer receives the start response signal sent by the device under test, it can send a heartbeat start instruction to the device under test, and the heartbeat start instruction is used to instruct the device under test to periodically send heartbeat messages on each target CAN channel and record the sending and receiving status.
[0080] S103. Send a reporting message to the host computer based on the receiving and sending status of each target CAN channel at every preset reporting cycle, so that the host computer evaluates the communication quality of each pair of target CAN channels based on at least one received reporting message.
[0081] In this embodiment, the device under test sends a report message to the host computer based on the transceiver status of each target CAN channel at every preset report period, so that the host computer can evaluate the communication quality of each pair of target CAN channels based on at least one received report message.
[0082] The CAN communication detection method provided by the embodiment of the present invention is applied to a device under test that is connected to a host computer for communication. The device under test includes multiple pairs of CAN channels for communication connection, so when the device under test receives a receiving enable instruction sent by the host computer, the receiving function of at least one pair of target CAN channels is turned on; when a heartbeat start instruction sent by the host computer is received, a heartbeat message is periodically sent out in each target CAN channel based on the heartbeat start instruction, and the transceiving situation of each target CAN channel is recorded; every preset reporting period, a reporting message is sent to the host computer based on the transceiving situation of each target CAN channel, so that the host computer performs communication quality evaluation on each pair of target CAN channels based on at least one received reporting message. The present invention adopts a loopback test mechanism between two CAN channels of the device under test to realize CAN communication detection, meets the demand for simultaneous detection of multiple CAN channels, and improves test efficiency.
[0083] In an optional implementation, the process of "enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction" in the above step S101 may include the following sub-steps S1011 to S1013.
[0084] S1011. Analyze the receiving enable instruction to obtain channel identification information and a receiving enable signal.
[0085] In this embodiment, the receiving enable instruction may be a string in json format, which includes channel identification information and a receiving enable signal.
[0086] S1012: Determine at least one pair of target CAN channels from all CAN channels based on the channel identification information.
[0087] S1013: Based on the enable signal, enable the receiving function of each target CAN channel.
[0088] In an optional example, the receive enable instruction is as follows:
[0089] {'id':16777234,'method':'test_set_can_rx','params':[1048575,1]}
[0090] Among them, id represents the mapping value of the node identifier of the device under test, which is "16777234"; method represents the test interface called by the device under test, which is "test_set_can_rx"; params represents the parameters of the incoming value test interface, among which "1048575" is the channel identification information, indicating the mapping value of each specified target CAN channel, and "1" is the receive enable signal, indicating that the receive function is turned on (0 represents off).
[0091] For example, combining Figure 1For the device under test 1, "1048575" can represent the six target CAN channels CAN1 to CAN6 of the device under test 1. And after the receiving function of these six target CAN channels is turned on, the device under test 1 can send response data to the host computer as follows:
[0092] {'id':16777234,'result':0}
[0093] Among them, id represents the mapping value of the node identifier of the device under test, which is "16777234"; result represents the result returned by the table, where "0" is the startup response signal, indicating that the enablement is successful.
[0094] The above examples are merely illustrative and are not intended to be limiting.
[0095] In an optional implementation, the process of "periodically sending heartbeat messages on each target CAN channel based on the heartbeat start instruction and recording the sending and receiving status of each target CAN channel" in the above step S102 may include the following sub-steps S1021 to S1023.
[0096] S1021. Analyze the heartbeat start instruction to obtain channel identification information, cycle data, and count reset signal.
[0097] In this embodiment, the heartbeat start instruction may be a string in json format, which includes channel identification information, cycle data, and a count reset signal.
[0098] S1022. Based on the count reset signal, set the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information to 0.
[0099] In this embodiment, the device under test maintains a sending count value and a receiving count value of each CAN channel.
[0100] S1023. For each target CAN channel, a heartbeat message is periodically sent on the target CAN channel based on the periodic data; and, each time a heartbeat message is sent through the target CAN channel, a sending count value corresponding to the target CAN channel is increased by 1, and each time a heartbeat message is received by the target CAN channel, a receiving count value corresponding to the target CAN channel is increased by 1.
[0101] In this embodiment, the periodic data may be a specified period, and the device under test sends a heartbeat message at each target CAN channel at a specified period, for example, a specified period of 2ms, 5ms or 10ms.
[0102] Alternatively, according to the mapping rule that multiple specified periods correspond to one mapping value, the period data can be the mapping value of any specified period. For example, the mapping values corresponding to the three specified periods of 2ms, 5ms, and 10ms are 1, 2, and 3, respectively, and the period data can be the mapping value 3 of the specified period of 10ms, so the device under test sends a heartbeat message every 10ms at each target CAN channel.
[0103] In an optional example, the heartbeat start instruction can be as follows:
[0104] {'id':16842771,'method':'test_can_heartbeat','params':[3,0,1048575]}
[0105] Among them, id represents the mapping value of the node identifier of the device under test, which is "16842771"; method represents the test interface called by the device under test, which is "test_can_heartbeat"; params represents the parameters of the incoming value test interface, among which "3" is the mapping value of the periodic data, "0" is the count reset signal 0, and "1048575" is the channel identification information, indicating the mapping value of each specified target CAN channel.
[0106] Optionally, when the device under test starts to send a heartbeat message on each target CAN channel, it can also return heartbeat start response data to the host computer. The heartbeat start response data can be as follows:
[0107] {'id':16842771,'result':{'log':'test_can_heartbeat set OK'}}
[0108] Among them, id represents the mapping value of the node identifier of the device under test, which is "16842771"; result represents the result returned by the table, and {'log':'test_can_heartbeat set OK'} indicates that the heartbeat is started successfully.
[0109] The above examples are merely illustrative and are not intended to be limiting.
[0110] In an optional implementation, the process of "sending a report message to a host computer based on the transceiver status of each target CAN channel" in the above step S103 may include the following sub-steps S1031 to S1033.
[0111] S1031. Obtain the sending and receiving status of each target CAN channel.
[0112] S1032: Generate a report message based on the receiving and sending status of each target CAN channel.
[0113] S1033. Send the report message to the host computer.
[0114] In this embodiment, the transceiver status may include a transmission count value and a reception count value. Every reporting period, the device under test may determine a transmission sequence based on the transmission count value of each target CAN channel, and may determine a reception sequence based on the reception count value of each target CAN channel. The transmission sequence includes the transmission count value of each target CAN channel, and the reception sequence may include the reception count value of each target CAN channel. The device under test may generate a reporting message based on the transmission sequence and the reception sequence, and then send the reporting message to the host computer.
[0115] In the optional example, combine Figure 1 , assuming that the specified period of the heartbeat message interval sent by the device 1 under test on each target CAN channel is 10ms and the reporting period is 50ms. If each target CAN channel of the device 1 under test starts sending heartbeat messages at time t0, then after 300m from time t0, the device 1 under test needs to report for the sixth time. The sending sequence and receiving sequence obtained by the sixth report can be shown in the following table (1):
[0116] Table (1)
[0117] CAN Channel CAN1 CAN2 CAN3 CAN4 CAN5 CAN6 Send Sequence 30 30 30 30 30 30 Receiving sequence 28 29 30 26 0 0
[0118] This example is merely an example and is not intended to be limiting.
[0119] See also Figure 3 , Figure 3 The second flow chart of a CAN communication detection method provided by an embodiment of the present invention. The CAN communication detection method is applied to the above detection system, and its implementation principle is basically the same as the above CAN communication detection method applied to the device under test, and the repeated parts are not repeated here. The CAN communication detection method may include the following steps S201 to S207.
[0120] S201. The host computer sends a receiving enable instruction to each device under test.
[0121] In this embodiment, when batch detection of multiple CAN channels of multiple devices under test is required, the host computer will send a receive enable instruction to each device under test. If the host computer fails to send the receive enable instruction, an error will be reported.
[0122] S202: After each device under test starts the receiving function of at least one pair of target CAN channels based on the received receiving enable instruction, it feeds back a start response signal to the upper computer.
[0123] In this embodiment, if any device under test cannot enable the receiving function of the target CAN channel, a startup failure signal can be returned to the host computer, and the host computer reports an error.
[0124] S203: When receiving the start response signal returned by each device under test, the host computer sends a heartbeat start instruction to each device under test.
[0125] In this embodiment, the host computer sends a heartbeat start instruction to each device under test only when it receives a start response signal returned by each device under test, so that each pair of CAN channels of each device under test starts loopback detection synchronously.
[0126] If the host computer fails to receive the start response signal returned by each device under test within a preset time (e.g., 3 seconds) after issuing the receive enable command, an error will be reported. If the host computer fails to send the heartbeat start command, an error will also be reported.
[0127] S204: Each device under test periodically sends a heartbeat message on each target CAN channel based on the received heartbeat start instruction, and records the sending and receiving status of each target CAN channel.
[0128] In this embodiment, when each device under test successfully starts to send a heartbeat message on each target CAN channel, it can also return heartbeat start response data to the host computer, and the heartbeat start response data should inform the host computer to successfully start the loopback detection. If any device under test fails to send a heartbeat message on any target CAN channel, it can return heartbeat start failure data to the host computer, and the host computer reports an error.
[0129] S205 . Each device under test sends a reporting message to a host computer based on the receiving and sending status of each target CAN channel at every preset reporting period.
[0130] S206. Whenever the host computer receives a report message, it stores the report data in the report message.
[0131] In this embodiment, the reported data includes the sending and receiving status of each target CAN channel of the device under test.
[0132] S207 . The host computer performs communication quality evaluation on each pair of target CAN channels of each device under test based on multiple reports of each device under test within the evaluation period at every preset evaluation period.
[0133] In this embodiment, the evaluation period can be flexibly set based on the test objectives. For example, if a performance test is performed, the evaluation period can be 10 minutes or 30 minutes; if a stress test is performed, the evaluation period can be 1 hour or 3 hours.
[0134] The CAN communication detection method provided in an embodiment of the present invention is applied to a detection system, which includes a host computer and at least one device under test that is communicatively connected to the host computer; the device under test includes multiple pairs of CAN channels, and the two CAN channels of each pair of CAN channels are communicatively connected. The method comprises the following steps: a host computer sends a receiving enable instruction to each device under test; each device under test starts the receiving function of at least one pair of target CAN channels based on the received receiving enable instruction, and then feeds back a start response signal to the host computer; when the host computer receives the start response signal returned by each device under test, the host computer sends a heartbeat start instruction to each device under test; each device under test periodically sends a heartbeat message on each target CAN channel based on the received heartbeat start instruction, and records the transceiving status of each target CAN channel; each device under test sends a reporting message to the host computer based on the transceiving status of each target CAN channel at every preset reporting cycle; each time the host computer receives a reporting message, the host computer stores the reporting data in the reporting message; the reporting data includes the transceiving status of each target CAN channel of the device under test; and the host computer respectively performs communication quality evaluation on each pair of target CAN channels of each device under test based on multiple copies of reporting data of each device under test within the evaluation cycle at every preset evaluation cycle. The present invention adopts a loopback test mechanism between two CAN channels of the tested device under the control of the host computer to realize CAN communication detection, meets the demand of simultaneous detection of multiple CAN channels of multiple tested devices, and improves the test efficiency.
[0135] In an optional implementation, the reported data includes a sending sequence and a receiving sequence, the i-th data and the i+1-th data in the sending sequence are the sending count values of the two target CAN channels of the communication connection, and the i-th data and the i+1-th data in the receiving sequence are the receiving count values of the two target CAN channels of the communication connection, where i is an odd number.
[0136] Therefore, taking the calculation of packet loss as an example, the process of "the host computer performs communication quality evaluation on each pair of target CAN channels of each device under test based on multiple reported data of each device under test within the evaluation period" in the above step S207 may include the following sub-steps S2071 to S2074.
[0137] S2071. For each reported data of each device under test, obtain the i-th sending count value and the i+1-th sending count value, the i-th receiving count value and the i+1-th receiving count value from the sending sequence and the receiving sequence respectively; wherein i=1,3,5,…,2N-1, and N is a positive integer.
[0138] S2072. Calculate the ratio between the i+1th receiving count value and the i-th sending count value to obtain the packet loss rate of the i+1th target CAN channel of the device under test.
[0139] S2073. Calculate the ratio between the i-th receiving count value and the i+1-th sending count value to obtain the packet loss rate of the i-th target CAN channel of the device under test.
[0140] Therefore, within an evaluation cycle, the host computer stores multiple copies of reported data of each device under test within the evaluation cycle. The host computer can obtain multiple packet loss rates of each target CAN channel by using the multiple copies of reported data of each device under test within the evaluation cycle.
[0141] S2074. For each target CAN channel of each device under test, based on multiple packet loss rates of the target CAN channel, generate a packet loss line graph of the target CAN channel within an evaluation period.
[0142] In this embodiment, for each target CAN channel of each device under test, based on multiple packet loss rates of the target CAN channel, a packet loss line graph of the target CAN channel during the evaluation period is generated. The packet loss line graph can reflect the packet loss changes of the target CAN channel during the entire evaluation period.
[0143] For example, combined with Figure 1 In the device under test 1, combined with the above table (1), it can be seen that for the device under test 1:
[0144] The packet loss rate of CAN1 is: 28 / 30≈93.33%;
[0145] The packet loss rate of CAN2 is: 29 / 30≈96.67%;
[0146] The packet loss rate of CAN3 is: 30 / 30=100%;
[0147] The packet loss rate of CAN4 is: 26 / 30≈86.67%.
[0148] And it can be determined that there is at least one faulty CAN channel in CAN5 and CAN6.
[0149] This example is merely an example and is not intended to be limiting.
[0150] It should be noted that the execution order of each step in the above method embodiment is not limited to that shown in the drawings, and the execution order of each step shall be based on the actual application situation.
[0151] In order to execute the corresponding steps in the above method embodiment and each possible implementation mode, an implementation mode of a CAN communication detection device is provided below.
[0152] See also Figure 4 , Figure 4The structure diagram of the CAN communication detection device provided by the embodiment of the present invention is shown. The CAN communication detection device 200 is applied to the device under test, and the device under test is connected to the host computer for communication; the device under test includes multiple pairs of CAN channels, and the two CAN channels of each pair of CAN channels are connected for communication. The CAN communication detection device 200 includes: a receiving start module 210, a loop detection module 220 and a reporting module 230.
[0153] The receiving start module 210 is used to receive a receiving enable instruction sent by the host computer, and after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, feed back a start response signal to the host computer;
[0154] The loop detection module 220 is used to receive the heartbeat start instruction sent by the host computer, periodically send a heartbeat message on each target CAN channel based on the heartbeat start instruction, and record the sending and receiving status of each target CAN channel;
[0155] The reporting module 230 is used to send a reporting message to the host computer based on the transceiver status of each target CAN channel at every preset reporting period, so that the host computer can evaluate the communication quality of each pair of target CAN channels based on at least one received reporting message.
[0156] Optionally, when the receiving start module 210 is used to enable the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, it can be specifically used to: parse the receiving enable instruction to obtain channel identification information and a receiving enable signal; based on the channel identification information, determine at least one pair of target CAN channels from all CAN channels; based on the enable signal, enable the receiving function of each target CAN channel.
[0157] Optionally, when the loop detection module 220 is used to periodically send heartbeat messages on each target CAN channel based on the heartbeat start instruction and record the sending and receiving status of each target CAN channel, it can be specifically used to: parse the heartbeat start instruction to obtain channel identification information, periodic data and a count reset signal; based on the count reset signal, set the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information to 0; for each target CAN channel, periodically send a heartbeat message on the target CAN channel based on the periodic data; and, each time a heartbeat message is sent through the target CAN channel, the sending count value corresponding to the target CAN channel is increased by 1, and each time the target CAN channel receives a heartbeat message, the receiving count value corresponding to the target CAN channel is increased by 1.
[0158] Optionally, when the reporting module 230 is used to send a reporting message to the host computer based on the transceiver status of each target CAN channel, it can be specifically used to: obtain the transceiver status of each target CAN channel; the transceiver status includes a sending count value and a receiving count value; based on the transceiver status of each target CAN channel, generate a reporting message; and send the reporting message to the host computer.
[0159] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the CAN communication detection device 200 described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0160] See also Figure 5 , Figure 5 The structure diagram of a device under test provided by an embodiment of the present invention is as follows: The device under test 300 includes a processor 310 , a memory 320 and a bus 330 , and the processor 310 is connected to the memory 320 via the bus 330 .
[0161] The memory 320 can be used to store software programs, for example, software programs corresponding to the CAN communication detection device 200 provided in the embodiment of the present invention. The processor 310 executes various functional applications and data processing to implement the CAN communication detection method provided in the embodiment of the present invention by running the software programs stored in the memory 320.
[0162] Among them, the memory 320 can be but is not limited to: RAM (Random Access Memory), ROM (Read Only Memory), FLASH (Flash Memory), PROM (Programmable Read-Only Memory), EPROM (Erasable Programmable Read-Only Memory), EEPROM (Electric Erasable Programmable Read-Only Memory), etc.
[0163] The processor 310 may be an integrated circuit chip with signal processing capability. The processor 310 may be a general-purpose processor, including: CPU (Central Processing Unit), NP (Network Processor), SoC (System on Chip), etc.; it may also be: DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0164] Understandably, Figure 5 The structure shown is for illustration only. The device under test 300 may also include Figure 5 More or fewer components as shown, or with Figure 5 Different configurations are shown. Figure 5 Each component shown in the figure can be implemented by hardware, software or a combination thereof.
[0165] The embodiment of the present invention further provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the CAN communication detection method disclosed in the above embodiment is implemented. The computer-readable storage medium can be, but is not limited to, various media that can store program codes, such as a USB flash drive, a mobile hard disk, a ROM, a RAM, a PROM, an EPROM, an EEPROM, a FLASH disk, or an optical disk.
[0166] In summary, the embodiments of the present invention provide a CAN communication detection method, apparatus, device under test and storage medium. The detection system includes a host computer and at least one device under test communicatively connected to the host computer; the device under test includes multiple pairs of CAN channels, and the two CAN channels of each pair of CAN channels are communicatively connected. The method comprises the following steps: a host computer sends a receiving enable instruction to each device under test; each device under test starts the receiving function of at least one pair of target CAN channels based on the received receiving enable instruction, and then feeds back a start response signal to the host computer; when the host computer receives the start response signal returned by each device under test, the host computer sends a heartbeat start instruction to each device under test; each device under test periodically sends a heartbeat message on each target CAN channel based on the received heartbeat start instruction, and records the transceiving status of each target CAN channel; each device under test sends a reporting message to the host computer based on the transceiving status of each target CAN channel at every preset reporting cycle; each time the host computer receives a reporting message, the host computer stores the reporting data in the reporting message; the reporting data includes the transceiving status of each target CAN channel of the device under test; and the host computer respectively performs communication quality evaluation on each pair of target CAN channels of each device under test based on multiple copies of reporting data of each device under test within the evaluation cycle at every preset evaluation cycle. The present invention adopts a loopback test mechanism between two CAN channels of the tested device under the control of the host computer to realize CAN communication detection, meets the demand of simultaneous detection of multiple CAN channels of multiple tested devices, and improves the test efficiency.
[0167] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A CAN communication detection method, characterized in that: Applied to a device under test, the device under test is communicatively connected to a host computer; the device under test includes multiple pairs of CAN channels, and two CAN channels of each pair of CAN channels are communicatively connected; the method includes: When receiving the receiving enable instruction sent by the host computer, after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, feeding back a start response signal to the host computer; When a heartbeat start instruction sent by the host computer is received, a heartbeat message is periodically sent on each target CAN channel based on the heartbeat start instruction, and the sending and receiving status of each target CAN channel is recorded; At every preset reporting cycle, a reporting message is sent to the host computer based on the receiving and sending status of each target CAN channel, so that the host computer performs communication quality evaluation on each pair of target CAN channels based on at least one received reporting message.
2. The method according to claim 1, characterized in that The step of enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction includes: Parsing the receiving enable instruction to obtain channel identification information and a receiving enable signal; Based on the channel identification information, determining at least one pair of target CAN channels from all CAN channels; Based on the enable signal, the receiving function of each of the target CAN channels is enabled.
3. The method according to claim 1, characterized in that The step of periodically sending a heartbeat message on each target CAN channel based on the heartbeat start instruction and recording the sending and receiving status of each target CAN channel includes: Parsing the heartbeat start instruction to obtain channel identification information, cycle data and count reset signal; Based on the count reset signal, the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information are set to 0; For each of the target CAN channels, the heartbeat message is periodically sent on the target CAN channel based on the periodic data; and, each time the heartbeat message is sent through the target CAN channel, the sending count value corresponding to the target CAN channel is increased by 1, and each time the target CAN channel receives a heartbeat message, the receiving count value corresponding to the target CAN channel is increased by 1.
4. The method according to claim 1, characterized in that The step of sending a report message to the host computer based on the transceiver status of each target CAN channel includes: Obtaining the sending and receiving status of each target CAN channel; the sending and receiving status includes a sending count value and a receiving count value; Based on the receiving and sending status of each target CAN channel, generating the reporting message; The report message is sent to the host computer.
5. A CAN communication detection method, characterized in that: Applied to a detection system, the detection system includes a host computer and at least one device under test that is communicatively connected to the host computer; the device under test includes multiple pairs of CAN channels, and two CAN channels of each pair of CAN channels are communicatively connected; the method includes: The host computer sends a receiving enable instruction to each of the devices under test; After each of the devices under test starts the receiving function of at least one pair of target CAN channels based on the received receiving enable instruction, a start response signal is fed back to the host computer; When the host computer receives the start response signal returned by each of the devices under test, it sends a heartbeat start instruction to each of the devices under test; Each of the devices under test periodically sends a heartbeat message on each of the target CAN channels based on the received heartbeat start instruction, and records the sending and receiving status of each of the target CAN channels; Each of the devices under test sends a reporting message to the host computer based on the transceiver status of each of the target CAN channels at every preset reporting period; Each time the host computer receives a report message, it stores the report data in the report message; the report data includes the sending and receiving status of each target CAN channel of the device under test; The host computer performs communication quality evaluation on each pair of target CAN channels of each of the devices under test based on multiple copies of reported data of each of the devices under test within the evaluation period at every preset evaluation period.
6. The method according to claim 5, characterized in that The reported data includes a sending sequence and a receiving sequence, wherein the i-th data and the i+1-th data in the sending sequence are the sending count values of the two target CAN channels of the communication connection, and the i-th data and the i+1-th data in the receiving sequence are the receiving count values of the two target CAN channels of the communication connection, wherein i is an odd number; The step of the host computer evaluating the communication quality of each pair of target CAN channels of each of the devices under test based on multiple copies of reported data of each of the devices under test within the evaluation period includes: For each reported data of each of the devices under test, the i-th sending count value and the i+1-th sending count value, the i-th receiving count value and the i+1-th receiving count value are obtained from the sending sequence and the receiving sequence respectively; wherein i=1, 3, 5, ..., 2N-1, and N is a positive integer; Calculate the ratio between the i+1th receiving count value and the i-th sending count value to obtain the packet loss rate of the i+1th target CAN channel of the device under test; Calculate the ratio between the i-th receiving count value and the i+1-th sending count value to obtain the packet loss rate of the i-th target CAN channel of the device under test; For each of the target CAN channels of each of the devices under test, a packet loss line graph of the target CAN channel within the evaluation period is generated based on multiple packet loss rates of the target CAN channel.
7. A CAN communication detection device, characterized in that: Applied to a device under test, the device under test is connected to a host computer for communication; the device under test includes multiple pairs of CAN channels, and two CAN channels of each pair of CAN channels are connected for communication; the device includes: A receiving start module, used for receiving a receiving enable instruction sent by the host computer, and after enabling the receiving function of at least one pair of target CAN channels based on the receiving enable instruction, feeding back a start response signal to the host computer; A loop detection module, used for receiving a heartbeat start instruction sent by the host computer, periodically sending a heartbeat message on each target CAN channel based on the heartbeat start instruction, and recording the sending and receiving status of each target CAN channel; The reporting module is used to send a reporting message to the host computer based on the receiving and sending status of each target CAN channel at every preset reporting cycle, so that the host computer can evaluate the communication quality of each pair of target CAN channels based on at least one received reporting message.
8. The device according to claim 7, characterized in that When the loop detection module is used to periodically send a heartbeat message on each target CAN channel based on the heartbeat start instruction and record the sending and receiving status of each target CAN channel, it is specifically used to: Parsing the heartbeat start instruction to obtain channel identification information, cycle data and count reset signal; Based on the count reset signal, the sending count value and the receiving count value corresponding to at least two target CAN channels corresponding to the channel identification information are set to 0; For each of the target CAN channels, periodically sending the heartbeat message on the target CAN channel based on the periodic data; And, each time the heartbeat message is sent through the target CAN channel, the sending count value corresponding to the target CAN channel is increased by 1, and each time the target CAN channel receives a heartbeat message, the receiving count value corresponding to the target CAN channel is increased by 1.
9. A device under test, characterized in that: include: A memory and a processor, wherein the memory stores a software program, and when the device under test is running, the processor executes the software program to implement the CAN communication detection method according to any one of claims 1 to 4.
10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the CAN communication detection method according to any one of claims 1 to 4 is implemented.