Time synchronization error determination method and device, equipment, medium and program product

By recording and calculating the time stamp difference between the devices and determining and adjusting the time synchronization error, the problems of large amount of calculation and low efficiency in the clock synchronization process in the prior art are solved, and more efficient and accurate equipment clock synchronization is achieved.

CN119109543APending Publication Date: 2024-12-10TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202310670759.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-06-07
Publication Date
2024-12-10

AI Technical Summary

Technical Problem

The prior art has a large amount of calculation during the equipment clock synchronization process, resulting in a reduced data interaction efficiency and it is difficult to accurately adjust the time synchronization error, affecting the reliability of data interaction between devices.

Method used

By recording the sending and receiving timestamps when sending and receiving data packets between devices, the average time difference is calculated to determine the time synchronization error between device clocks and make flexible adjustments to improve clock synchronization accuracy.

Benefits of technology

It improves the accuracy of time synchronization error, reduces the difficulty of adjustment, avoids interaction failures caused by equipment clock out of synchronization, and improves the reliability and efficiency of data interaction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119109543A_ABST
    Figure CN119109543A_ABST
Patent Text Reader

Abstract

The invention discloses a time synchronization error determination method and device, equipment, a medium and a program product, and relates to the technical field of communication. The method comprises the following steps: when a data message is sent to second equipment, recording a sending timestamp; receiving a response message sent by the second equipment; recording the moment of receiving the response message as a second receiving timestamp; based on a difference value between the sending timestamp and the second receiving timestamp, carrying out mean value operation on the transmission duration of the data message and the response message to obtain an average time difference; and determining a time synchronization error between the first device and the second device based on the average time difference and the first receiving timestamp and the response timestamp in the response message. By means of the mode, the problem of interaction faults caused by desynchrony between equipment clocks can be avoided, the precision of the time synchronization error is greatly improved, and meanwhile the difficulty of determining the time synchronization error is reduced. The method can be applied to various scenes such as cloud technology, artificial intelligence and intelligent transportation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of communication technology, and in particular to a method, apparatus, device, medium and program product for determining a time synchronization error. Background Art

[0002] With the development of computer network applications, the time synchronization of devices has become increasingly important. The accuracy of time affects almost all file operations. For example, if a file is created on a device that is ahead of time, when other devices view the file through the list command, they will get a negative value by subtracting the file creation time from the current time. Therefore, the time followed by the device is inaccurate, which will greatly affect the reliability of data interaction between devices.

[0003] In the related art, a time reference (or time synchronization beacon) is usually set in advance, and the time error of multiple devices interacting with each other is adjusted according to the time reference. For example, the time reference is set as a perpetual calendar, the timestamp of the interaction between devices is determined, the timestamp is compared with the perpetual calendar to determine the time error, and then the device clocks followed by multiple devices are adjusted according to the time error to improve the success rate of data interaction.

[0004] Although the method of setting a time reference can avoid the time error problem to a certain extent, the process of adjusting the time of multiple devices separately will result in a large amount of calculation, thereby reducing the efficiency of data interaction. Summary of the invention

[0005] The embodiments of the present application provide a method, apparatus, device, medium and program product for determining a time synchronization error, which can avoid interaction failures caused by asynchrony between device clocks, greatly improve the accuracy of the time synchronization error, and reduce the difficulty of determining the time synchronization error. The technical solution is as follows.

[0006] In one aspect, a method for determining a time synchronization error is provided, the method comprising:

[0007] When sending a data message to a second device, record a sending timestamp, where the sending timestamp is a time when the first device determines to send the data message based on a first device clock corresponding to the first device;

[0008] receiving a response message sent by the second device, the response message including a first receiving timestamp and a response timestamp, the first receiving timestamp being a time when the second device determines to receive the data message based on a second device clock corresponding to the second device, and the response timestamp being a time when the second device determines to respond to the data message based on the second device clock;

[0009] Recording the time when the response message is received as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on the clock of the first device;

[0010] Based on the difference between the sending timestamp and the second receiving timestamp, performing a mean operation on the transmission time of the data message and the response message to obtain an average time difference;

[0011] A time synchronization error between the first device and the second device is determined based on the average time difference, the first receiving timestamp, and the response timestamp. The time synchronization error is used to represent the time difference between the first device clock and the second device clock. The time synchronization error is used to adjust the device clock.

[0012] On the other hand, a device for determining a time synchronization error is provided, the device comprising:

[0013] a recording module, configured to record a sending timestamp when sending a data message to a second device, wherein the sending timestamp is a time when the first device determines to send the data message based on a first device clock corresponding to the first device;

[0014] a receiving module, configured to receive a response message sent by the second device, wherein the response message includes a first receiving timestamp and a response timestamp, wherein the first receiving timestamp is a time when the second device determines to receive the data message based on a second device clock corresponding to the second device, and the response timestamp is a time when the second device determines to respond to the data message based on the second device clock;

[0015] The recording module is further used to record the time when the response message is received as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on the clock of the first device;

[0016] A calculation module, configured to perform a mean calculation on the transmission time of the data message and the response message based on the difference between the sending timestamp and the second receiving timestamp to obtain an average time difference;

[0017] A determination module is used to determine a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp and the response timestamp, wherein the time synchronization error is used to represent the time difference between the first device clock and the second device clock, and the time synchronization error is used to adjust the device clock.

[0018] On the other hand, a computer device is provided, comprising a processor and a memory, wherein the memory stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement a method for determining a time synchronization error as described in any of the above-mentioned embodiments of the present application.

[0019] On the other hand, a computer-readable storage medium is provided, in which at least one instruction, at least one program, a code set or an instruction set is stored, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by a processor to implement a method for determining a time synchronization error as described in any of the above-mentioned embodiments of the present application.

[0020] On the other hand, a computer program product or a computer program is provided, the computer program product or the computer program comprising computer instructions, the computer instructions being stored in a computer-readable storage medium. A processor of a computer device reads the computer instructions from the computer-readable storage medium, and the processor executes the computer instructions, so that the computer device executes the method for determining the time synchronization error described in any of the above embodiments.

[0021] The beneficial effects brought by the technical solution provided by the embodiment of the present application include at least:

[0022] When the first device sends a data message to the second device, the sending timestamp under the clock of the first device is recorded, and when the response message sent by the second device is received, the second receiving timestamp of the received response message is recorded. The transmission time of the data message and the response message is averaged by the difference between the sending timestamp and the second receiving timestamp to obtain the average time difference, and then the time synchronization error between the first device and the second device is determined based on the average time difference and the first receiving timestamp and the response timestamp in the response message. The time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then the interactive operation status between the first device and the second device is analyzed in a targeted manner to avoid interactive failures such as interaction failure and low interaction accuracy due to the lack of synchronization between the device clocks. The device clock is adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0024] Figure 1 It is a schematic diagram of an implementation environment provided by an exemplary embodiment of the present application;

[0025] Figure 2 is a flow chart of a method for determining a time synchronization error provided by an exemplary embodiment of the present application;

[0026] Figure 3 is a flow chart of a device interactively determining multiple timestamps provided by an exemplary embodiment of the present application;

[0027] Figure 4 is a flow chart of a method for determining a time synchronization error provided by another exemplary embodiment of the present application;

[0028] Figure 5 is a flow chart of a method for determining a time synchronization error provided by yet another exemplary embodiment of the present application;

[0029] Figure 6 is a flow chart of a device interactively determining multiple timestamps and message identifiers provided by an exemplary embodiment of the present application;

[0030] Figure 7 is a schematic diagram of a byte area in a preset message provided by an exemplary embodiment of the present application;

[0031] Figure 8 is a flow chart of obtaining a reference time error provided by an exemplary embodiment of the present application;

[0032] Fig. 9 is a flow chart of a method for determining a time synchronization error provided by another exemplary embodiment of the present application;

[0033] Fig.10 It is a schematic diagram of a plurality of terminals performing device interaction with a server and determining a time synchronization error provided by an exemplary embodiment of the present application;

[0034] Fig.11 It is a schematic diagram of an implementation environment under a 5G network provided by an exemplary embodiment of the present application;

[0035] Fig.12 It is a schematic diagram of applying a method for determining a time synchronization error to an industrial Internet scenario provided by an exemplary embodiment of the present application;

[0036] Fig.13 is a schematic diagram of applying a method for determining a time synchronization error to a vehicle networking scenario provided by another exemplary embodiment of the present application;

[0037] Fig.14 is a structural block diagram of a device for determining a time synchronization error provided by an exemplary embodiment of the present application;

[0038] Fig.15 is a structural block diagram of a device for determining a time synchronization error provided by another exemplary embodiment of the present application;

[0039] Fig.16 It is a structural block diagram of a server provided by an exemplary embodiment of the present application. DETAILED DESCRIPTION

[0040] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below in conjunction with the accompanying drawings.

[0041] First, a brief introduction is given to the terms involved in the embodiments of the present application.

[0042] Network delay: Network delay refers to the time required for data to travel from the sender to the receiver, including transmission delay, propagation delay, processing delay, and queuing delay. Among them, transmission delay refers to the time required for data to travel from the sender to the first router on the network; propagation delay refers to the time required for data to propagate in the transmission medium; processing delay refers to the time required for the router to process data; and queuing delay refers to the time required for data to wait for processing in the router's cache queue. One-way delay refers to the time it takes for data to travel from the sender to the receiver, which can be calculated by the difference between the sending timestamp and the receiving timestamp. Round-trip delay refers to the time it takes for data to travel from the sender to the receiver and then back to the sender, which can be calculated by the difference between the sending timestamp and the receiving timestamp. Calculating accurate delay can help us better understand the performance and bottlenecks of the network, thereby optimizing the design and configuration of the network and improving the reliability and performance of the network.

[0043] Clock synchronization error: Clock synchronization error refers to the phenomenon that the clocks of different devices are different, resulting in deviations in their time synchronization. This error is caused by factors such as the accuracy and stability of the clock itself and communication delays. In order to fix this error, a clock synchronization protocol, such as Network Time Protocol (NTP) and Precise Time Protocol (PTP), can be used to transmit time information through the network so that the clocks of different devices are synchronized. For example, when two computers transfer files, if there are differences in their clocks, inconsistent timestamps will occur during the file transfer process, resulting in inaccurate information such as the creation time and modification time of the file. The occurrence of clock synchronization error is due to the differences in accuracy and stability of the clocks of different devices, and communication delays will also affect clock synchronization. In order to solve this problem, a clock synchronization protocol can be used to transmit time information through the network so that the clocks of different devices are synchronized. Common clock synchronization protocols include NTP and PTP. Clock synchronization error may cause inaccurate timestamps of the system, which in turn affects various functions of the system, such as logging and event triggering. The clock synchronization protocol can be used to fix this error and ensure that the system's timestamp is accurate. In addition, clock synchronization errors may also affect network communication and transmission, resulting in inaccurate timestamps for data packets, which in turn affects the reliability and correctness of the data.

[0044] Clock drift: Clock drift refers to the phenomenon that the clocks of different devices are different, resulting in deviations in their time synchronization, and this error will become larger and larger as time goes by. For example, when data is transmitted between two computers, if there is a difference in their clocks, the timestamp of the data transmission will be inaccurate, thus affecting the reliability and correctness of the data. The clock drift phenomenon occurs due to factors such as the accuracy and stability of the clock itself and communication delay. In order to deal with the clock drift phenomenon, clock synchronization protocols such as NTP and PTP can be used to transmit time information through the network so that the clocks of different devices are synchronized. The clock synchronization protocol can fix the clock drift phenomenon and ensure that the system's timestamp is accurate. The clock drift problem will bring many hazards to network communication and transmission. For example, when data is transmitted between two computers, if there is a difference in their clocks, the timestamp of the data transmission will be inaccurate, thus affecting the reliability and correctness of the data. In addition, the clock drift problem will also affect the performance and stability of the network, thereby causing network failures and interruptions. Therefore, we need to use a clock synchronization protocol to fix clock drift.

[0045] Link symmetry: Uplink and downlink symmetry in a network refers to the phenomenon that the bandwidth for uploading and downloading in the network is the same, that is, the upload speed and the download speed are equal. This phenomenon usually occurs in symmetrical networks, such as Symmetric Digital Subscriber Line (SDSL) and Symmetric Fiber To The Home (S-FTTH). For example, when a user uses DSL to access the Internet, the upload and download bandwidths are the same, both 1Mbps or 2Mbps. This symmetry can improve the stability and reliability of the network, and can also improve the user experience and satisfaction. Uplink and downlink symmetry in a network is more common in symmetrical networks, such as DSL and S-FTTH. In asymmetric networks, such as Wide Area Network (WAN) and the Internet, the upload and download bandwidths are usually asymmetric, and the download speed is faster than the upload speed. This is because in these networks, users usually need to download a large amount of data from the Internet, while the amount of uploaded data is relatively small, so the Internet Service Provider (ISP) will prioritize the download speed and reduce the upload speed to meet the needs of users. In addition, the symmetry of network uplinks and downlinks is also affected by factors such as network topology, network equipment and network load. The symmetry of network uplinks and downlinks is one of the important factors that need to be considered in network design and optimization. In a symmetric network, the upload and download bandwidths are the same, which can improve the stability and reliability of the network, and also improve the user experience and satisfaction. In an asymmetric network, the upload and download bandwidths are usually asymmetric and need to be reasonably adjusted according to factors such as user needs and network load. In addition, the symmetry of network uplinks and downlinks also needs to consider the influence of factors such as network topology, network equipment and network load to achieve efficient and reliable operation of the network.

[0046] In the related art, a time reference (or time synchronization beacon) is usually set in advance, and the time error of multiple devices interacting with each other is adjusted according to the time reference. For example: the time reference is set to a perpetual calendar, the timestamp for interaction between devices is determined, the timestamp is compared with the perpetual calendar to determine the time error, and then the device clocks followed by multiple devices are adjusted according to the time error to improve the success rate of data interaction. Although the method of setting a time reference can avoid the time error problem to a certain extent, the process of adjusting the time of multiple devices separately will result in a large amount of calculation, thereby reducing the efficiency of data interaction.

[0047] In an embodiment of the present application, when the first device sends a data message to the second device, the sending timestamp is recorded; the first receiving timestamp and the response timestamp are determined based on the response message sent by the second device, and the second receiving timestamp of the received response message is recorded; the difference between the sending timestamp and the second receiving timestamp is then averaged to obtain the average time difference; thus, the time synchronization error between the first device and the second device is determined by the average time difference, the first receiving timestamp and the response timestamp, so as to adjust the device clock, and avoid the interaction failure caused by the asynchronism between the device clocks, while greatly improving the accuracy of the time synchronization error, reducing the difficulty of determining the time synchronization error. The method for determining the time synchronization error provided in the embodiment of the present application can not only be applied to daily device interaction data processing scenarios, but also can be applied to many device clock synchronization scenarios such as industrial Internet scenarios, real-time data twin scenarios, and autonomous driving scenarios with high requirements for time accuracy, while reducing the time synchronization error to a subtle level, simplifying the deployment difficulty and deployment cost.

[0048] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of the relevant regions. For example, the sending timestamp, response message, device clock and other contents involved in this application are all obtained with full authorization.

[0049] Secondly, the implementation environment involved in the embodiment of the present application is explained. The method for determining the time synchronization error provided in the embodiment of the present application is based on the interaction between the first device and the second device. The first device can be implemented as one or more, and the second device can also be implemented as one or more; the first device can be implemented as a terminal or a server, and the second device can also be implemented as a terminal or a server. The embodiment of the present application does not limit this. Schematically, the first device is implemented as a terminal, and the second device is also implemented as a terminal; or, the first device is implemented as a terminal, and the second device is implemented as a server; or, the first device is implemented as a server, and the second device is implemented as a terminal; or, the first device is implemented as a server, and the second device is implemented as a terminal; or, the first device is implemented as a server, and the second device is also implemented as a server, etc.

[0050] Optionally, refer to Figure 1 Taking the first device 110 implemented as a terminal and the second device 120 implemented as a server as an example, the first device 110 and the second device 120 are connected via a communication network 130, and a method for determining a time synchronization error between the first device 110 and the second device 120 is described as follows.

[0051] In some embodiments, the first device 110 records a sending timestamp when sending a data message to the second device 120. The sending timestamp is determined based on a first device clock corresponding to the first device 110 to determine the time when the first device 110 sends the data message to the second device 120. Schematically, the first device 110 follows the first device clock to perform the device operation process, and the first device clock is used to characterize the timeline progress of the first device 110.

[0052] When the second device 120 receives the data message sent by the first device 110, the time when the second device 120 receives the data message is determined as the first receiving timestamp based on the second device clock corresponding to the second device 120; in addition, when the second device 120 responds to the data message, the time when the second device 120 responds to the data message is also determined based on the second device clock as the response timestamp. Schematically, the second device 120 follows the second device clock to perform the device operation process, and the second device clock is used to characterize the timeline progress of the second device 120. The first device clock and the second device clock may be synchronized or there may be differences, and the first device clock and the second device clock may also vary under the world reference time.

[0053] Optionally, after determining the first reception timestamp and the response timestamp, the second device 120 writes the first reception timestamp and the response timestamp into a response message and sends it to the first device 110, so that the first device 110 receives the response message sent by the second device 120, which includes the first reception timestamp and the response timestamp.

[0054] In some embodiments, the first device 110 determines a time at which a response message is received and records the time as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on a clock of the first device.

[0055] The first device 110 performs a mean operation on the transmission time of the data message and the response message based on the difference between the recorded sending timestamp and the second receiving timestamp to obtain an average time difference; and then determines the time synchronization error between the first device 110 and the second device 120 based on the average time difference, the first receiving timestamp and the response timestamp. The time synchronization error is used to represent the time difference between the first device clock corresponding to the first device 110 and the second device clock corresponding to the second device 120, and the time synchronization error can be used to adjust the device clock.

[0056] In some embodiments, the first device 110 adjusts the clock of the first device based on the time synchronization error and a preset error adjustment logic; or, the first device 110 presents the time synchronization error on a screen corresponding to the first device 110 so that the clock of the first device can be adjusted by manual adjustment; or, the first device 110 feeds back the time synchronization error to the second device 120 so that the second device 120 adjusts the clock of the second device based on a preset error adjustment logic; or, the first device 110 feeds back the time synchronization error to the second device 120, and the second device 120 presents the time synchronization error on a screen corresponding to the second device 120 so that the clock of the second device can be adjusted by manual adjustment, etc.

[0057] It is worth noting that the above-mentioned terminals include but are not limited to mobile terminals such as mobile phones, tablet computers, portable laptops, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, and can also be implemented as desktop computers, etc.; the above-mentioned servers can be independent physical servers, or they can be server clusters or distributed systems composed of multiple physical servers, or they can be cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (CDN), as well as big data and artificial intelligence platforms.

[0058] Among them, cloud technology refers to a hosting technology that unifies hardware, application programs, networks and other resources within a wide area network or local area network to achieve data computing, storage, processing and sharing. Cloud technology is a general term for network technology, information technology, integration technology, management platform technology, application technology, etc. based on the cloud computing business model. It can form a resource pool that can be used on demand and is flexible and convenient.

[0059] In some embodiments, the above server can also be implemented as a node in a blockchain system.

[0060] In combination with the above-mentioned noun introduction and application scenarios, the method for determining the time synchronization error provided by the present application is described, and the method is applied to the first device as an example. Figure 2 As shown, the method includes the following steps 210 to 250.

[0061] Step 210: When sending a data message to the second device, record the sending timestamp.

[0062] Illustratively, the process of sending a data message is a data interaction process between the first device and the second device, and the data message is used to represent the data format transmitted from the first device to the second device.

[0063] A data message is a data unit exchanged and transmitted in a network. In the embodiment of the present application, it is implemented as a data block sent by a first device to a second device at one time. Schematically, a data message contains complete data information to be sent, and the length of the data message may vary depending on the difference in the data being sent.

[0064] In some embodiments, the first device and the second device are devices that establish a communication connection; based on the communication connection, the first device sends a data message to the second device.

[0065] Optionally, the first device is implemented as a terminal; or, the first device is implemented as a server; similarly, the second device is implemented as a terminal, or, the second device is implemented as a server.

[0066] Illustratively, the first device is implemented as a terminal, the second device is implemented as a server, and a connection is established between the terminal and the server via a communication network, so that the terminal can send data packets to the server via the communication network; or, the first device is implemented as a first server, the second device is implemented as a second server, and a communication connection is established between the two terminals, so that the first server can send data packets to the second server via the communication connection.

[0067] When the first device sends a data message to the second device, the time of sending the data message is determined as the sending timestamp. Since the sending timestamp is a timestamp determined by the first device, the sending timestamp is a timestamp determined by the first device based on the first device clock followed by the first device.

[0068] That is, the sending timestamp is the time when the first device sends the data message to the second device based on the first device clock corresponding to the first device.

[0069] Among them, the first device clock is the device clock followed by the first device, which is used to indicate the timeline progress of the first device and is a measurement scale for measuring and recording time during the operation of the first device.

[0070] Illustratively, when the first device sends a data message to the second device, the first device determines that the sending timestamp of the sent data message is T1 based on the first device clock.

[0071] Step 220: Receive a response message sent by the second device.

[0072] Illustratively, after the first device successfully sends a data packet to the second device, if the second device successfully receives the data packet and responds based on the data packet, the second device will send a response packet to the first device based on the data packet. The response packet is a packet based on the data packet, and includes a data block that is fed back to the first device.

[0073] Optionally, the data message sent by the first device to the second device is used to request the specified data stored in the second device. If the second device successfully receives and responds to the data message, the response message fed back by the second device to the first device includes the specified data; or, the data message sent by the first device to the second device is used to request the storage address of the specified data. If the second device successfully receives and responds to the data message, the response message fed back by the second device to the first device includes the storage address of the specified data, etc.

[0074] In some embodiments, after the second device sends a response message to the first device, the first device receives the response message, and the response message includes a first receiving timestamp and a response timestamp.

[0075] The first receiving timestamp is the time when the second device determines to receive the data message based on the second device clock corresponding to the second device.

[0076] Illustratively, the second device corresponds to a second device clock. The second device clock is a device clock followed by the second device and is used to indicate the timeline progress of the second device. It is a measurement scale for measuring and recording moments during the operation of the second device.

[0077] Optionally, the second device determines the reception time of the data packet sent by the first device based on the second device clock, and uses the reception time as the first reception timestamp. For example, the second device determines that the first reception timestamp when the second device receives the data packet is T2 based on the second device clock. The first reception timestamp T2 and the sending timestamp T1 are timestamps determined using different measurement scales.

[0078] The response timestamp is the time when the second device determines to respond to the data message based on the second device clock.

[0079] Illustratively, after the second device successfully receives the data message, it processes the data message and sends feedback to the first device after the processing is completed, that is, sends a response message to the first device.

[0080] Optionally, the data message sent by the first device to the second device is used to request the specified data stored in the second device. If the second device successfully receives the data message, it will analyze the data message and search for the specified data stored in the second device. The analysis and search process can be regarded as the process of processing the data message; or, the data message sent by the first device to the second device is used to request the storage address of the specified data. If the second device successfully receives the data message, it will analyze the data message and search for the storage address of the specified data. The analysis and search process can be regarded as the process of processing the data message, etc.

[0081] Optionally, the second device determines the response time of the data message based on the second device clock, and the response time is also implemented as the time when the second device sends the response message to the first device, and the response time is used as the response timestamp. For example: the second device determines the response timestamp of the response message sent by the second device to the first device as T3 based on the second device clock, and the response timestamp T3 and the first receiving timestamp are timestamps determined by the same measurement scale (second device clock); the response timestamp T3 and the sending timestamp T1 are timestamps determined by different measurement scales.

[0082] Step 230: Record the time of receiving the response message as a second receiving timestamp.

[0083] Illustratively, after the second device sends a response message to the first device and the first device successfully receives the response message, the first device records the time of receiving the response message based on the first device clock and uses the time as the second receiving timestamp.

[0084] That is, the second receiving timestamp is a timestamp determined by the first device based on the first device clock.

[0085] For example: the first device determines that the second receiving timestamp of receiving the response message is T4 based on the first device clock. The second receiving timestamp T4 and the sending timestamp T1 are timestamps determined using the same measurement scale (first device clock); the second receiving timestamp T4 and the first receiving timestamp T2 are timestamps determined using different measurement scales; the second receiving timestamp T4 and the response timestamp T3 are also timestamps determined using different measurement scales.

[0086] Indicatively, Figure 3 As shown, it is a flow chart of data interaction between the first device and the second device. When the first device 310 sends a data message to the second device 320, the sending timestamp T1 determined based on the clock of the first device is recorded; the second device 320 records the first receiving timestamp T2 determined based on the clock of the second device for receiving the data message, and the second device 320 records the response timestamp T3 determined based on the clock of the second device for sending a response message to the first device 310; the first device 310 receives the response message sent by the second device and determines the second receiving timestamp T4 based on the clock of the first device.

[0087] Step 240: Based on the difference between the sending timestamp and the second receiving timestamp, perform an average operation on the transmission time of the data message and the response message to obtain an average time difference.

[0088] Illustratively, after the first device determines the sending timestamp and the second receiving timestamp, it determines the difference between the sending timestamp and the second receiving timestamp.

[0089] The difference is a round-trip delay, which is used to indicate the total time required for a data message to travel from the first device to the second device, and then for the second device to feed back a response message to the first device based on the data message.

[0090] In some embodiments, assuming that the links are symmetrical, that is, assuming that the upload and download bandwidths in the network are the same, the theoretical value of the one-way delay is realized as the average of the differences, that is, half of the differences.

[0091] Among them, the one-way delay is used to characterize the transmission time of a data message from the first device to the second device, or the response time of a response message from the second device to the first device; the one-way delay is realized as the mean of the difference to indicate that the transmission time and the response time are equal.

[0092] Indicatively, the difference is averaged to obtain an average time difference, which is used to characterize that the sending time of the data message and the sending time of the response message are equal when the link is symmetrical, wherein the sending time of the data message and the sending time of the response message are collectively referred to as transmission time.

[0093] For example, if the sending timestamp is T1 and the second receiving timestamp is T4, the difference between the sending timestamp and the second receiving timestamp is expressed as T1-T4. The difference T1-T4 is averaged and the average time difference is expressed as (T1-T4) / 2.

[0094] Step 250: determine a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp, and the response timestamp.

[0095] In an illustrative manner, after obtaining the average time difference between the first device and the second device for characterizing the theoretical state, the time synchronization error between the first device and the second device is analyzed in combination with the average time difference determined by the first device, and the first receiving timestamp and the response timestamp determined by the first device based on the response message.

[0096] Optionally, when the first device sends a data packet to the second device, the theoretical reception timestamp of the second device receiving the data packet in a theoretical state is determined to be T1+(T4-T1) / 2 based on the average time difference; based on the theoretical reception timestamp and the first reception timestamp, the time error when the first device sends the data packet to the second device can be determined.

[0097] Similarly, when the second device sends a response message to the first device, the theoretical response timestamp of the second device sending the response message in a theoretical state is determined to be T3+(T4-T1) / 2 based on the average time difference; based on the theoretical response timestamp and the response timestamp, the time error when the second device sends the response message to the first device can be determined.

[0098] In an optional embodiment, a time synchronization error between the first device and the second device can be determined based on the above two time errors.

[0099] The time synchronization error is used to represent the time difference between the first device clock and the second device clock.

[0100] Schematically, the sending timestamp and the second receiving timestamp are timestamps determined based on the clock of the first device, and the first receiving timestamp and the response timestamp are timestamps determined based on the clock of the second device. By comparing the sequence and time span between the timestamps in different device clock states, the difference between the first clock error followed by the first device and the second clock error followed by the second device can be determined, thereby determining the time synchronization error.

[0101] In an optional embodiment, the time synchronization error is used to adjust the device clock.

[0102] The device clock includes at least one of a first device clock and a second device clock.

[0103] Optionally, when the device clock for adjustment is implemented as a first device clock, the first device clock may be adjusted based on the second device clock; or, the first device clock may be adjusted according to a world clock.

[0104] Optionally, when the device clock for adjustment is implemented as a second device clock, the second device clock may be adjusted based on the first device clock; or, the second device clock may be adjusted according to a world clock.

[0105] Optionally, when the device clock for adjustment is implemented as a first device clock and a second device clock, the first device clock and the second device clock may be adjusted respectively according to the world clock.

[0106] In some embodiments, adjusting the device clock is used to synchronize the first device clock with the second device clock, which may also be referred to as synchronization adjustment.

[0107] Optionally, the synchronization adjustment includes at least one of phase synchronization adjustment and frequency synchronization adjustment.

[0108] Among them, phase synchronization adjustment is used to indicate the adjustment of the time of the device clock so that the time recorded by the first device clock is the same as the time recorded by the second device clock; frequency synchronization adjustment is used to indicate the adjustment of the time change speed of the device clock so that the change speed of the time recorded by the first device clock is the same as the change speed of the time recorded by the second device clock.

[0109] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0110] To summarize, when the first device sends a data message to the second device, the sending timestamp under the clock of the first device is recorded, and when the response message sent by the second device is received, the second receiving timestamp of the received response message is recorded. Based on the difference between the sending timestamp and the second receiving timestamp, the transmission time of the data message and the response message is averaged to obtain the average time difference, and then the time synchronization error between the first device and the second device is determined based on the average time difference and the first receiving timestamp and the response timestamp in the response message. The time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then the interactive operation status between the first device and the second device is analyzed in a targeted manner to avoid interaction failures, low interaction accuracy and other interaction failures caused by the lack of synchronization between the device clocks. The device clock is adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0111] In an optional embodiment, when determining the time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp, and the response timestamp, an uplink error of the first device sending a data message to the second device is determined, and a downlink error of the second device sending a response message to the first device is determined, and then the time synchronization error is determined by combining the uplink error and the downlink error. Schematically, as Figure 4 As shown above Figure 2 The illustrated step 250 may also be implemented as the following steps 410 to 430 .

[0112] Step 410: determine an uplink error sent from the first device to the second device based on the sending timestamp and the average time difference.

[0113] The uplink is used to indicate the process of the first device sending a data message to the second device; the uplink error is used to indicate the difference between the time period in which the first device sends the data message to the second device and the corresponding theoretical time period.

[0114] In an optional embodiment, the sum of the sending timestamp and the average time difference is obtained as the uplink time difference.

[0115] Schematically, the sending timestamp is represented by T1, the second receiving timestamp is represented by T4, and the average time difference (T4-T1) / 2 determined based on the sending timestamp and the second receiving timestamp is expressed as T1+(T4-T1) / 2, and this value is used as the uplink time difference.

[0116] Optionally, the average time difference (T4-T1) / 2 is a theoretical value for the first device to send a data packet to the second device assuming link symmetry, so the uplink time difference determined based on the sending timestamp and the average time difference is also a theoretical value in an uplink process.

[0117] In an optional embodiment, an uplink error sent by the first device to the second device is obtained based on the absolute value of the difference between the first receiving timestamp and the uplink time difference.

[0118] In an illustrative manner, the first receiving timestamp is a timestamp obtained based on the actual record of the clock of the second device. After obtaining the uplink time difference, the difference between the first receiving timestamp and the uplink time difference is determined, and the absolute value of the difference is taken to obtain the uplink error of the first device sending the data packet to the second device. The uplink error reflects the difference between the theoretical value and the actual value in the uplink process.

[0119] The calculation formula of the uplink error is shown in the following formula 1.

[0120] Formula 1:

[0121]

[0122] Among them, Error1 is used to indicate the uplink error; T2 is used to indicate the first receiving timestamp; T1 is used to indicate the sending timestamp; and T4 is used to indicate the second receiving timestamp.

[0123] Step 420: Determine a downlink error of the data sent from the second device to the first device based on the response timestamp and the average time difference.

[0124] The downlink is used to indicate the process of the second device sending a response message to the first device; the downlink error is used to indicate the difference between the time period in which the second device sends the response message to the first device and the corresponding theoretical time period.

[0125] In an optional embodiment, the sum of the response timestamp and the average time difference is obtained as the downlink time difference.

[0126] Schematically, the average time difference (T4-T1) / 2 is determined by sending timestamp T1 and second receiving timestamp T4, and the response timestamp is represented by T3. Then the sum of the response timestamp and the average time difference is represented as T3(T4-T1) / 2, which is used as the downlink time difference.

[0127] Optionally, the average time difference (T4-T1) / 2 is a theoretical value for the first device to send a data packet to the second device assuming link symmetry, so the downlink time difference determined based on the response timestamp and the average time difference is also a theoretical value in a downlink process.

[0128] In an optional embodiment, a downlink error sent by the second device to the first device is obtained based on the absolute value of the difference between the second receiving timestamp and the downlink time difference.

[0129] In schematic form, the second received timestamp is a timestamp obtained based on the actual record of the first device clock. After obtaining the downlink time difference, the difference between the second received timestamp and the downlink time difference is determined, and the absolute value of the difference is taken to obtain the downlink error when the second device sends a response message to the first device. The downlink error reflects the difference between the theoretical value and the actual value in the downlink process.

[0130] The calculation formula of the downlink error is shown in the following formula 2.

[0131] Formula 2:

[0132]

[0133] Among them, Error2 is used to indicate the uplink error; T4 is used to indicate the second receiving timestamp; T3 is used to indicate the response timestamp; and T1 is used to indicate the sending timestamp.

[0134] Step 430: Determine the time synchronization error between the first device and the second device by combining the uplink error and the downlink error.

[0135] Illustratively, after obtaining an uplink error characterizing when the first device sends a data message to the second device, and obtaining a downlink error characterizing when the second device sends a response message to the first device, the sum of the uplink error and the downlink error is obtained as the sum of the errors between the first device and the second device.

[0136] In an optional embodiment, a mean operation is performed on the sum of the uplink error and the downlink error to obtain the time synchronization error between the first device and the second device.

[0137] Schematically, the uplink error is expressed as Error1, which is used to characterize the difference between the first receiving timestamp T2 actually recorded by the second device and the uplink time difference theoretically predicted by the first device; the downlink error is expressed as Error2, which is used to characterize the difference between the second receiving timestamp T4 actually recorded by the second device and the downlink time difference theoretically predicted by the first device. The time synchronization error between the first device and the second device is obtained by the following formula three.

[0138] Formula 3:

[0139]

[0140] Among them, avgError is used to characterize the time synchronization error between the first device and the second device, and is implemented as the average value of the uplink error Error1 and the downlink error Error2.

[0141] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0142] To summarize, the time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then conduct targeted analysis on the interactive operation status between the first device and the second device, thereby avoiding interaction failures, low interaction accuracy and other interaction failures due to the asynchrony between the device clocks. The device clocks can be adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0143] In the embodiment of the present application, a method for comprehensively determining the time synchronization error through the uplink error and the downlink error is introduced. The theoretical value of the message sending and receiving process between the first device and the second device under the assumption of link symmetry is introduced, and the uplink time difference and the downlink time difference representing the theoretical value are determined, and then the uplink error is determined by the difference between the uplink time difference and the first receiving timestamp time, and the downlink error is determined by the difference between the downlink time difference and the response timestamp. It avoids introducing additional modules or calculation logic to increase the calculation amount of the first device, and uses the known timestamp parameters to perform a more direct analysis between the first device and the second device, which improves the analysis efficiency and the calculation accuracy to a certain extent.

[0144] In an optional embodiment, when the first device sends a data message to the second device, the data message corresponds to a data identifier, and the data identifier is used to uniquely indicate the data message, thereby distinguishing it from other data messages. Figure 5 As shown above Figure 2 The illustrated embodiment may also be implemented as the following steps 510 to 550 .

[0145] Step 510: When sending a data message to the second device, record the message identifier and sending timestamp of the data message.

[0146] The data message corresponds to a data identifier, and the data identifier is used to uniquely indicate the data message.

[0147] The i-th data message is marked with the i-th message identifier, and i is a positive integer.

[0148] Schematically, different data messages are marked with different data identifiers. For example, data message 1 corresponds to data identifier a, and data message 2 corresponds to data identifier b.

[0149] Schematically, data messages are divided according to data types, and different data messages of the same type are marked with different data identifiers. For example: data message 1 and data message 2 belong to the same type, data message 1 is marked with data identifier a1, and data message 2 is marked with data identifier a2; data message 1 and data message 3 belong to different types, data message 1 is marked with data identifier a1, and data message 3 is marked with data identifier b1, etc.

[0150] like Figure 6 As shown, it is a schematic interaction flow chart, which includes a first device 610 running a communication tool and a second device 620 running a communication tool, wherein the communication tool is a tool for communication transmission based on User Datagram Protocol (UDP).

[0151] In schematic form, the communication tool that complies with UDP is a communication tool that is programmed using a computer programming language (Golang, Go), and is used to determine the timestamps between device interactions. With the connectionless feature of UDP, the message transmission between device interactions can be made more efficient, so that the time synchronization error between devices can be determined more efficiently and timely.

[0152] Optionally, the first device 610 is implemented as a terminal (or client), the second device 620 is implemented as a server, UDP communication is performed between the first device 610 and the second device, and the UDP communication between the first device 610 and the second device 620 is based on the communication protocol designed in the embodiment of the present application and the specified message mode.

[0153] Illustratively, the first step of the communication protocol process is implemented as follows: the first device 610 sends a data message to the second device 620, and locally records a message identifier and a sending timestamp T1 corresponding to the data message.

[0154] For example, the first device 610 sends a data message to the second device 620. Since the data message is usually implemented in a sequence form, the data message can be called a sequence, or seq for short. The first device 610 records the message identity (seq Identity, seq ID) corresponding to the data message seq and the sending timestamp T1.

[0155] Step 520: Receive a response message sent by the second device.

[0156] The response message includes a first receiving timestamp and a response timestamp.

[0157] The first receiving timestamp determines the time when the second device receives the data message based on the second device clock corresponding to the second device, and the response timestamp determines the time when the second device responds to the data message based on the second device clock.

[0158] In an optional embodiment, the response message includes a preset plurality of byte areas.

[0159] The byte area is used to represent an area that carries data through bytes. For example: byte area 1 is used to carry data a; or, byte area 1 to byte area 2 are used to carry data a; or, byte area 1 is used to carry data of type a; or, byte area 1 to byte area 2 are used to carry data of type a, etc.

[0160] Optionally, the first device and the second device pre-negotiate field types respectively carried by the multiple byte regions, and the field types include at least one timestamp type.

[0161] The multiple byte regions include a first byte region carrying a first receiving timestamp and a second byte region carrying a response timestamp. That is, the timestamp type is implemented as a first receiving timestamp type and a response timestamp type.

[0162] Indicatively, Figure 7 As shown, it is a schematic diagram of multiple byte regions determined by negotiation between the first device and the second device. For example, the first device and the second device jointly negotiate the data carried by each byte region (or field) in the payload of the data message.

[0163] For example: set 0 bytes to 9 bytes in the UDP Payload field to store seq ID; 10 bytes to 29 bytes to store the first receiving timestamp T2; 30 bytes to 59 bytes to store the response timestamp T3, etc., so as to achieve accurate reading of the response message sent by the first device to the second device.

[0164] Optionally, after the second device determines the first reception timestamp of the received data message based on the second device clock, the first reception timestamp is recorded in the response message in the first byte area for storing the first reception timestamp. If the above-mentioned 10 bytes to 29 bytes are used to store the first reception timestamp T2, then 10 bytes to 29 bytes are called the first byte area.

[0165] Similarly, after the second device determines the response timestamp of sending a response message based on the second device clock, the response timestamp is recorded in the response message in the second byte area for storing the response timestamp. For example, bytes 30 to 59 are used to store the response timestamp T2, then bytes 30 to 59 are called the second byte area.

[0166] It is worth noting that the above-mentioned division of byte areas and the functions of byte areas are merely illustrative examples and are not limited to the embodiments of the present application.

[0167] In an optional embodiment, a field in the first byte area of ​​the response message is read to obtain a first receiving timestamp.

[0168] The first byte area is the byte area where the second device writes the first receiving timestamp.

[0169] Illustratively, the data sent by the second device and received by the first device is implemented as a response message. When the first device needs to obtain the first receiving timestamp and the response timestamp recorded by the second device, the first device reads the response message.

[0170] Optionally, the response message is a message generated based on the data message, and the first device and the second device have negotiated on the message format. Therefore, when the first device reads the response message, it can obtain the first reception timestamp based on reading the field of the first byte area in the response message for storing the first reception timestamp.

[0171] Indicatively, the response message is implemented as follows Figure 7 In the message format shown, when the first device needs to determine the first receiving timestamp, the first receiving timestamp T2 is determined by reading the field of the first byte area 710 stored in bytes 10 to 29 in the response message.

[0172] In an optional embodiment, a field in the second byte area of ​​the response message is read to obtain a response timestamp.

[0173] The second byte area is a byte area where the second device writes the response timestamp.

[0174] Based on the method in which the first device obtains the first receiving timestamp by reading the field of the first byte area in the response message, when the first device reads the response message, it can obtain the response timestamp based on reading the field of the second byte area in the response message for storing the response timestamp.

[0175] Indicatively, the response message is implemented as follows Figure 7 In the message format shown, when the first device needs to determine the response timestamp, the response timestamp T3 is determined by reading the field of the second byte area 720 stored in bytes 30 to 59 in the response message.

[0176] In some embodiments, when the first device reads the response message, the message identifier is obtained based on reading a field in the third byte area of ​​the response message for storing the message identifier.

[0177] Indicatively, the response message is implemented as follows Figure 7 In the message format shown, when the first device needs to determine the message identifier, the message identifier is determined by reading the field stored in the third byte area 730 from byte 0 to byte 9 in the response message.

[0178] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0179] like Figure 6 As shown, after receiving the data packet, the second device 620 records the first receiving timestamp T2 of the received data packet based on the second device clock; in addition, the second device 620 records the response timestamp T3 for responding to the data packet, and when sending a response packet to the first device 610, stores the first receiving timestamp T2, the response timestamp T3 and the message identifier seq ID of the received data packet in the response packet, and sends the response packet to the first device 610 via UDP, so that the first device 610 receives the response packet sent by the second device 620.

[0180] Step 530, in response to receiving the i-th response message storing the i-th message identifier after sending the i-th data message, record the time of receiving the i-th response message as a second receiving timestamp corresponding to the i-th data message.

[0181] Illustratively, the first device sends at least one data message to the second device, and different data messages are marked with different message identifiers. When the second device receives at least one data message sent by the first device and generates a response message based on the data message, the message identifier corresponding to the data message is written into a pre-agreed byte area in the response message (such as the third byte area mentioned above). That is, the i-th message identifier is stored in the third byte area for storing message identifiers in the i-th response message.

[0182] Among them, the i-th data message is any one of the at least one data message sent by the first device to the second device; the i-th message identifier is the message identifier corresponding to the i-th data message, which is used to distinguish the i-th data message from other data messages; the i-th response message is a response message generated based on the i-th data message, and has a corresponding relationship with the i-th data message.

[0183] After the first device sends multiple data messages including the i-th data message to the second device, the first device may receive multiple response messages. For the i-th data message, when the multiple response messages received by the first device include a response message marked with the i-th message identifier, then the response message is the i-th response message that corresponds to the i-th data message.

[0184] Illustratively, the first device reads the multiple received response messages respectively, and based on the reading process of the third byte area storing the message identifier, determines the message identifiers corresponding to the multiple response messages respectively, thereby determining the i-th response message corresponding to the i-th data message.

[0185] Optionally, when the first device reads the multiple response messages received separately, it adopts a serial reading method to read the multiple response messages in sequence according to the order in which the response messages are received; or, it reads the multiple response messages in sequence according to the message size (storage size, etc.) of the response messages.

[0186] Optionally, when the first device reads the multiple received response messages separately, it adopts a parallel reading method to read the multiple response messages together; or, it reads at least one response message within the number limit of parallel reading in parallel, etc.

[0187] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0188] In some embodiments, when the first device receives the i-th response message storing the i-th message identifier, the time of receiving the i-th response message is recorded as the second receiving timestamp corresponding to the i-th data message.

[0189] The second receiving timestamp is a timestamp determined based on the first device clock.

[0190] Illustratively, after the first device determines that a corresponding i-th response message is obtained based on the i-th data message sent, the time of receiving the i-th response message is recorded based on the first device clock, thereby obtaining a second receiving timestamp that follows the first device clock.

[0191] like Figure 6 As shown, after the first device 610 receives the response message sent by the second device 620, it determines whether the seq ID in the response message is consistent with the message identifier corresponding to the sent data message. If they are consistent, the second receiving timestamp T4 is recorded, and then the time synchronization error is calculated based on T1, T2, T3, and T4.

[0192] Step 540: Based on the difference between the sending timestamp and the second receiving timestamp, perform a mean operation on the transmission time of the data message and the response message to obtain an average time difference.

[0193] Illustratively, after the first device determines the sending timestamp and the second receiving timestamp, it determines the difference between the sending timestamp and the second receiving timestamp.

[0194] For example, if the sending timestamp is T1 and the second receiving timestamp is T4, the difference between the sending timestamp and the second receiving timestamp is expressed as T1-T4. The difference T1-T4 is averaged and the average time difference is expressed as (T1-T4) / 2.

[0195] Step 550: determine a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp, and the response timestamp.

[0196] The time synchronization error is used to represent the time difference between the first device clock and the second device clock.

[0197] Among them, the time synchronization error is used to adjust the device clock.

[0198] In an optional embodiment, a time synchronization error between the first device and the second device at the sending timestamp is determined based on the average time difference, the first receiving timestamp, and the response timestamp.

[0199] In an illustrative manner, after obtaining the average time difference, the first receiving timestamp and the response timestamp, the uplink error when the first device sends a data message to the second device is determined by the above formula 1, and the downlink error when the second device sends a response message to the first device is determined by formula 2, thereby determining the time synchronization error between the first device and the second device based on the uplink error and the downlink error.

[0200] Optionally, the starting calculation moment based on the uplink error and the downlink error is the sending timestamp under the clock of the first device, so the time synchronization error determined based on the uplink error and the downlink error can be used as the error corresponding to the sending timestamp.

[0201] In an optional embodiment, the first device sends multiple data packets to the second device, and determines the time synchronization errors of the multiple data packets at corresponding sending timestamps to obtain multiple time synchronization errors; the time synchronization error between the first device and the second device is determined by combining the multiple time synchronization errors.

[0202] In schematic form, with the help of the time synchronization errors corresponding to multiple data packets at corresponding sending timestamps, the time dimension (there may be multiple sending timestamps) and the sending magnitude dimension of the data packet (avoiding the limitations of a single transmission) can be combined to improve the accuracy of determining the time synchronization error between the first device and the second device.

[0203] In some embodiments, based on the average time difference, the first receiving timestamp, and the response timestamp, the time synchronization error may also be determined as an error at the second receiving timestamp.

[0204] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0205] In an optional embodiment, in response to the time synchronization error reaching a preset adjustment threshold, the first device clock of the first device is adjusted based on the time synchronization error.

[0206] The preset adjustment threshold is a pre-set adjustment threshold used to characterize a condition for adjusting the device clock based on the time synchronization error, and the device clock includes at least one of a first device clock and a second device clock.

[0207] Illustratively, after obtaining the time synchronization error between the first device and the second device, the time synchronization error is compared with a preset adjustment threshold, and when the time synchronization error reaches the preset adjustment threshold, the first device clock of the first device is adjusted.

[0208] For example: the preset adjustment threshold is 3. When the calculated time synchronization error is 4, the first device clock of the first device is adjusted based on the time synchronization error being greater than (reaching) the preset adjustment threshold; or, the preset adjustment threshold is 3. When the calculated time synchronization error is 3, the first device clock of the first device is adjusted based on the time synchronization error being equal to (reaching) the preset adjustment threshold; or, the preset adjustment threshold is 3. When the calculated time synchronization error is 2.1, based on the time synchronization error not reaching the preset adjustment threshold, there is no need to adjust the first device clock of the first device, etc.

[0209] In an optional embodiment, in response to the time synchronization error reaching a preset adjustment threshold, the second device clock of the second device is adjusted based on the time synchronization error.

[0210] Illustratively, after obtaining the time synchronization error between the first device and the second device, the time synchronization error is compared with a preset adjustment threshold, and when the time synchronization error reaches the preset adjustment threshold, the second device clock of the second device is adjusted.

[0211] In an optional embodiment, the first device and the second device have a preset master-slave relationship.

[0212] Optionally, when the device clock is adjusted based on the first device and the second device, the master-slave relationship between the first device and the second device is determined, that is, whether the first device belongs to the master device and the second device belongs to the slave device; or whether the second device belongs to the master device and the first device belongs to the slave device.

[0213] Among them, the master-slave relationship between devices is pre-set.

[0214] Optionally, in response to the time synchronization error reaching a preset adjustment threshold, and the first device is a slave device and the second device is a master device, the first device clock of the first device is adjusted based on the time synchronization error.

[0215] Illustratively, when the second device is a master device and the first device is a slave device, when the device clock is adjusted based on the comparison result that the time synchronization error reaches a preset adjustment threshold, the first device clock corresponding to the first device is adjusted based on the second device clock corresponding to the second device.

[0216] Optionally, in response to the time synchronization error reaching a preset adjustment threshold, and the first device is a master device and the second device is a slave device, the second device clock of the second device is adjusted based on the time synchronization error.

[0217] When the first device is a master device and the second device is a slave device, when the device clocks are adjusted based on the comparison result that the time synchronization error reaches a preset adjustment threshold, the second device clock corresponding to the second device is adjusted based on the first device clock corresponding to the first device.

[0218] Taking the adjustment of the second device clock based on the first device clock as an example, the phase of the second device clock can be adjusted based on the moment of the first device clock; and / or the frequency of the second device clock can be adjusted based on the moment of the first device clock.

[0219] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0220] In some embodiments, two preset adjustment thresholds are set, namely a first preset adjustment threshold and a second preset adjustment threshold. The first preset adjustment threshold is used to characterize the conditions for adjusting the clock of the first device based on the time synchronization error; the second preset adjustment threshold is used to characterize the conditions for adjusting the clock of the second device based on the time synchronization error.

[0221] Schematically, the time synchronization error is compared with a first preset adjustment threshold and a second preset adjustment threshold. When the time synchronization error reaches the first preset adjustment threshold, the first device clock is adjusted; when the time synchronization error reaches the second preset adjustment threshold, the second device clock is adjusted; when the time synchronization error reaches the first preset adjustment threshold and reaches the second preset adjustment threshold, the first device clock and the second device clock are adjusted respectively, etc.

[0222] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0223] To summarize, the time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then conduct targeted analysis on the interactive operation status between the first device and the second device, thereby avoiding interaction failures, low interaction accuracy and other interaction failures due to the asynchrony between the device clocks. The device clocks can be adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0224] In the embodiment of the present application, it is introduced that the first device determines whether to record the second receiving timestamp of receiving the response message through the message identifier stored in the response message, thereby deciding whether to perform the calculation process of the time synchronization error. With the help of the message identifier, the message management efficiency can be improved when a large number of messages are exchanged between the first device and the second device, and the recording of useless messages can be avoided, which improves the storage efficiency of the memory space for the second receiving timestamp to a certain extent.

[0225] In an optional embodiment, after the time synchronization error is obtained, the accuracy of the time synchronization error can be determined by using an artificially determined reference time error. Figure 8 As shown in the figure, when the accuracy of the time synchronization error needs to be judged, the above Figure 2 The illustrated embodiment may then further include the following steps 810 to 830 .

[0226] Step 810: Acquire a first data packet transmitted between a first device and a second device.

[0227] The data packet includes at least one of a data message and a response message, and the first data packet is at least one data packet captured by the first device from multiple data packets transmitted between the first device and the second device.

[0228] Packet capture is the process of intercepting, retransmitting, editing, transferring, and other operations on data packets sent and received over a network. It is often used to intercept data and check network security.

[0229] Illustratively, a plurality of data packets are transmitted between a first device and a second device, wherein the plurality of data packets include a data message sent by the first device to the second device.

[0230] Optionally, when obtaining a data packet by means of packet capture, conditions such as the type and size of the obtained data packet are determined by setting parameters.

[0231] Illustratively, if the first device and / or the second device runs a Windows system, packet capture is enabled through a network protocol analyzer (wireshark); or, if the first device and / or the second device runs a Linux system, packet capture is performed through a network data packet capture command (dump the Traffic on a network, Tcpdump), etc.

[0232] For example, by setting parameters in Wireshark, you can select the type, size, and other conditions for obtaining data packets; or by setting parameters in Tcpdump, you can select the type, size, and other conditions for obtaining data packets.

[0233] Step 820: Receive a second data packet sent by the second device to the first device.

[0234] The second data packet is at least one data packet captured by the second device from multiple data packets transmitted between the first device and the second device.

[0235] Step 830: Obtain a reference time error between the first device and the second device based on the same data packet in the first data packet and the second data packet.

[0236] Schematically, the first data packet is implemented as a plurality of data packets obtained by the first device through packet capture, and therefore the first data packet is a data packet determined based on the clock of the first device, and the generation time, sending time, etc. of the first data packet follow the clock of the first device; similarly, the second data packet is implemented as a plurality of data packets obtained by the second device through packet capture, and therefore the second data packet is a data packet determined based on the clock of the second device, and the generation time, sending time, etc. of the second data packet follow the clock of the second device.

[0237] In an optional embodiment, multiple data in the same data packet of the first data packet and the second data packet are determined.

[0238] Optionally, the first data packet and the second data packet are compared to determine the same data packet shared by the first data packet and the second data packet. For example, if the first data packet includes data packet a1, data packet a2, and data packet a3, and the second data packet includes data packet b1 and data packet a2, then the same data packet shared by the first data packet and the second data packet is data packet a2.

[0239] In an optional embodiment, first data timestamps respectively corresponding to the plurality of data in the first data packet are determined, and second data timestamps respectively corresponding to the plurality of data in the second data packet are determined.

[0240] Illustratively, the same multiple data are stored in the same data packet, but the first data packet is a data packet generated based on the first device clock, and the second data packet is a data packet generated based on the second device clock, and considering that the first device clock and the second device clock may not be synchronized, the first data timestamps corresponding to the multiple data in the first data packet and the second data timestamps corresponding to the multiple data in the second data packet may not be the same.

[0241] Schematically, the first data timestamp is used to represent one of the multiple timestamps such as the generation timestamp, sending timestamp, receiving timestamp, etc. corresponding to any data in the first data packet; similarly, the second data timestamp is used to represent one of the multiple timestamps such as the generation timestamp, sending timestamp, receiving timestamp, etc. corresponding to any data in the second data packet.

[0242] In an optional embodiment, a reference time error between the first device and the second device is obtained based on the first data timestamp and the second data timestamp.

[0243] In schematic form, the time difference between the first data timestamp and the second data timestamp is used as the reference time error between the first device and the second device; or, the absolute value of the time difference between the first data timestamp and the second data timestamp is used as the reference time error between the first device and the second device; or, the time differences corresponding to multiple data are summed and averaged to obtain the reference time error between the first device and the second device; or, the first data timestamp representing the sending timestamp corresponding to data a and the second data timestamp representing the receiving timestamp corresponding to data a are manually compared to determine the time error corresponding to data a, and the reference time error is obtained by combining the time errors corresponding to multiple data, etc.

[0244] The reference time error is used to determine the accuracy of the time synchronization error.

[0245] Illustratively, the reference time error is an error determined based on an actual data transmission process and has high accuracy. The reference time error is compared with the predicted time synchronization error to determine the accuracy of the time synchronization error.

[0246] Optionally, when the difference between the reference time error and the time synchronization error is less than a preset accuracy threshold, the time synchronization error is deemed to have a higher accuracy; or, when the difference between the reference time error and the time synchronization error is greater than a preset accuracy threshold, the time synchronization error is deemed to have a lower accuracy, etc.

[0247] In an optional embodiment, if Fig. 9As shown, it is a schematic flowchart of testing the time synchronization error accuracy by analyzing the data packets obtained by packet capture, and is explained by taking the first device implemented as a client (terminal) and the second device implemented as a server as an example. The process includes the following steps 911 to 930.

[0248] Step 911: The client starts packet capture.

[0249] Indicatively, packet capture is started based on Wireshark on the client.

[0250] Step 912: The client starts the UDP-Client.

[0251] Schematically, UDP-Client is used to represent a communication tool configured on a client for UDP.

[0252] Optionally, the client starts a UDP-Client, such as starting a UDP-Client written in a Go program, to transmit data with a server (Server) at a known Internet Protocol Address (IP) through a port (port), that is, starting a Go-UDP-Client server IP:port.

[0253] Step 913: The client calculates the clock error.

[0254] Schematically, the clock error is the above-mentioned time synchronization error. Optionally, the client calculates the time synchronization error in real time and prints the result on a corresponding window interface of the client.

[0255] The process of calculating the time synchronization error can refer to the above Figure 2 , Figure 4 as well as Figure 5 The illustrated embodiments will not be described in detail here.

[0256] Step 914: The client stops capturing packets.

[0257] Indicatively, when the packet capture duration reaches a preset duration, the client stops capturing packets; or, when no data packet is captured within a certain period of time, the client stops capturing packets, and so on.

[0258] Step 921: The server starts packet capture.

[0259] Indicatively, packet capture based on Tcpdump is started on the server.

[0260] Step 922, the server starts UDP-Server.

[0261] Schematically, UDP-Server is used to represent a communication tool for UDP configured on a server, and the server starts UDP-Server.

[0262] Optionally, after the server starts UDP-Server, the terminal starts UDP-Client. For example, the UDP communication tool (UDP-Server and UDP-Client) is developed based on Golang and uses the UDP protocol for communication. First, the server's receiving program is started through the UDP-Server specified port, and then the client's sending program is started through UDP-Client, thereby avoiding invalid sending from the client to the server.

[0263] Optionally, the server starts UDP-Server while the client starts UDP-Client; or, the client starts UDP-Client and then the server starts UDP-Server, etc.

[0264] In some embodiments, after the client and the server establish communication, data is transmitted between the client and the server based on the UDP protocol, such as the data message sending process and the response message receiving process performed by the above-mentioned first device (such as: the client), and the data message receiving process and the response message sending process performed by the above-mentioned second device (such as: the server).

[0265] Step 923: The server stops capturing packets.

[0266] Indicatively, when the packet capture duration reaches a preset duration, the server stops packet capture; or, when no data packet is captured within a certain period of time, the server stops packet capture; or, when the client stops packet capture, the server stops packet capture, etc.

[0267] Step 930, compare and verify the results of packet capture and program calculation.

[0268] Indicatively, after both the client and the server stop capturing packets, the captured packet pcap file is exported, the pcap file is used for manual verification, the clock error between the two devices is calculated, and the result is compared and verified with the result of the automatic calculation.

[0269] Fig. 9 The network process data set (Packet capture, Pcap) files exported by the client and the server respectively are further displayed. Based on the Pcap files exported by the client and the pcap files exported by the server, the benchmark time error can be obtained by manual calculation, and the accuracy is compared with the time synchronization error predicted by the above-mentioned automated calculation tool to verify the accuracy of the time synchronization error.

[0270] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0271] To summarize, the time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then conduct targeted analysis on the interactive operation status between the first device and the second device, thereby avoiding interaction failures, low interaction accuracy and other interaction failures due to the asynchrony between the device clocks. The device clocks can be adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0272] In the embodiment of the present application, a method for determining a reference time error by packet capture is introduced. The timestamps when two devices process the same data are obtained by packet capture, and the reference time error is determined by comparing the difference in timestamps, and then the accuracy of the time synchronization error can be analyzed by using the reference time error, so as to more intuitively verify the effectiveness of the time synchronization error.

[0273] In an optional embodiment, the first device can be implemented as one device or multiple devices; similarly, the second device can be implemented as one device or multiple devices. The time synchronization error determination method can also be called an automatic calculation method of clock synchronization error based on UDP communication and four-segment timestamp.

[0274] Indicatively, Fig.10 As shown, a brief description is given by taking the first device implemented as multiple terminals 1010 (Client) and the second device implemented as a server 1020 as an example. The network communication process between the multiple terminals 1010 and the server 1020 follows the UDP protocol, and the framework is implemented as a Client-Server architecture.

[0275] The multiple terminals 1010 respectively determine the time synchronization error corresponding to each terminal 1010 based on the communication process with the server 1020 (the sending and receiving of data messages and the sending and receiving process of response messages, etc.), such as: the time synchronization error Error1 corresponding to the terminal 1011 among the multiple terminals 1010, the time synchronization error Error2 corresponding to the terminal 1012 among the multiple terminals 1010, and the time synchronization error Error3 corresponding to the terminal 1013 among the multiple terminals 1010.

[0276] Schematically, the process of determining the time synchronization error is briefly introduced as follows.

[0277] (1) It is determined that the devices serving as multiple terminals 1010 and the devices serving as server 1020 respectively run UDP communication tools developed based on Golang, and then the multiple terminals 1010 will send data packets to the server, and the server 1020 will respond and send a response packet after receiving the data packets.

[0278] (2) The UDP communication between multiple terminals 1010 and the server must be based on the communication protocol and the specified message format. The process of the communication protocol is as follows: multiple terminals 1010 send data messages to the server 1020, and record the sending timestamp T1 locally at each terminal. After receiving the data message, the server 1020 records the first receiving timestamp T2, which corresponds to the terminal and the data message; in addition, the server 1020 responds to the corresponding terminal and records the response timestamp T3; in addition, the server 1020 inserts the first receiving timestamp T2 and the response timestamp T3 into the response message and sends it to the corresponding terminal, so that multiple terminals 1010 respectively receive the response messages sent by the server 1020 based on the data message, and record the second receiving timestamp T4 of the received response message.

[0279] (3) Each of the multiple terminals 1010 calculates the time synchronization error with the server 1020 based on the four timestamps T1, T2, T3 and T4 recorded and received by it, thereby obtaining the time synchronization errors corresponding to the multiple terminals 1010, such as: the multiple time synchronization errors include time synchronization error 1 corresponding to terminal 1011, time synchronization error 2 corresponding to terminal 1012, and time synchronization error 3 corresponding to terminal 1013, and then compares the multiple time synchronization errors with the preset adjustment threshold respectively, and determines whether they exceed the preset adjustment threshold.

[0280] The preset adjustment threshold is used to characterize the condition for adjusting the device clock based on the time synchronization error.

[0281] Illustratively, if the time synchronization error 1 corresponding to terminal 1011 reaches a preset adjustment threshold, the device clock corresponding to terminal 1011 is adjusted based on the time synchronization error 1 corresponding to terminal 1011; and / or, if the time synchronization error 2 corresponding to terminal 1012 reaches a preset adjustment threshold, the device clock corresponding to terminal 1012 is adjusted based on the time synchronization error 2 corresponding to terminal 1012; and / or, if the time synchronization error 3 corresponding to terminal 1013 reaches a preset adjustment threshold, the device clock corresponding to terminal 1013 is adjusted based on the time synchronization error 3 corresponding to terminal 1013, etc.

[0282] (4) After obtaining the comparison results between multiple time synchronization errors and preset adjustment thresholds, when the comparison results indicate that the device clock needs to be adjusted according to the time synchronization error, a device clock synchronization process is performed between the terminal and the server 1020 based on NTP or PTP under the open source tool Linux operating system, referred to as Linux PTP, to correct the device clock and ensure the consistency between the device clocks.

[0283] Illustratively, if the comparison result indicates that the time synchronization error 1 reaches a preset adjustment threshold, the device clock of terminal 1011 is corrected based on the NTP or PTP tool; and / or, if the comparison result indicates that the time synchronization error 2 reaches a preset adjustment threshold, the device clock of terminal 1012 is corrected based on the NTP or PTP tool; and / or, if the comparison result indicates that the time synchronization error 3 reaches a preset adjustment threshold, the device clock of terminal 1013 is corrected based on the NTP or PTP tool.

[0284] (5) Multiple terminals 1010 continue to repeatedly send data messages to the server 1020 and continuously calculate the real-time time synchronization error.

[0285] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0286] In an optional embodiment, taking the first device as a client (terminal) and the second device as a server as an example, the data interaction between the first device and the second device is implemented under the fifth generation mobile communication technology (5th Generation Mobile Communication Technology, 5G) as an example.

[0287] like Fig.11 As shown, a test environment is shown in which a client 1110 and a server 1120 transmit UDP packets through a 5G core network (5G Core network, 5GC) 1130, wherein a customer premise equipment (Customer Premise Equipment, CPE) 1140 and a base station 1150 are also shown.

[0288] Among them, the function of CPE is to convert mobile network signals (such as 5G, 4G, etc.) or wired broadband signals into local signals for use by client 1110.

[0289] Illustratively, the client 1110 determines the time synchronization error based on the message interaction process with the server 1120. Fig.11The test environment shown belongs to a client and a server, and the method for determining the time synchronization error involved in the embodiment of the present application can also be expanded to multiple clients and servers for multi-point communication, thereby calculating the time synchronization error between each client and server separately.

[0290] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0291] In an optional embodiment, the method for determining the time synchronization error is used to solve the problem of low automation level and low versatility in calculating the time synchronization error. As a basic and key issue in the communication field, solving the time synchronization issue is of great significance.

[0292] In schematic form, the above method for determining the time synchronization error can be well applied to scenarios with high requirements for time accuracy, such as: Industrial 4.0 Internet scenarios, real-time digital twin scenarios, autonomous driving scenarios, etc.

[0293] Among them, the real-time digital twin scenario is used to represent the real-time detection of relevant dynamic information about physical devices to assist in streaming analysis. Due to the characteristics of real-time use, real-time digital twins can better identify emerging problems and enhance situational awareness. Since the process of real-time detection of equipment is usually implemented by another device, the determination of time synchronization error in the digital twin scenario is crucial. The more accurately the time synchronization error can be determined, the more accurate the real-time detection can be improved. The determination method of time synchronization error and the real-time digital twin scenario can take corresponding actions based on the results of real-time detection under the premise of ensuring time synchronization, avoiding ineffective production of physical equipment (such as: production of inferior products), etc.

[0294] Indicatively, Fig.12 As shown, it is a schematic diagram of applying the method for determining time synchronization error to the industrial Internet scenario.

[0295] Among them, multiple devices in the industrial Internet scenario are shown, such as device 1210, device 1220, etc. Different devices have corresponding device clocks (represented by clock identifiers). The device clock is used to represent the time axis progress of the device and is a measurement scale for measuring and recording the moment during the operation of the device. The numerical representation between different devices (such as "1.2μs" between device 1210 and device 1220) is the time synchronization error obtained in real time using the above-mentioned method for determining the time synchronization error. Similarly, the time synchronization error between other devices is determined.

[0296] based on Fig.12It characterizes the time synchronization error between multiple devices at any moment, so the time synchronization error between multiple devices at different moments may change, that is, the time synchronization error determined in real time may become larger, smaller, or remain unchanged. The above is only an illustrative example, and the embodiments of the present application are not limited to this.

[0297] Indicatively, Fig.13 As shown, it is a schematic diagram of applying the method for determining time synchronization error to the Internet of Vehicles scenario.

[0298] Among them, multiple devices in the Internet of Vehicles scenario are shown, such as an on-board controller 1310, a test vehicle 1320 and other devices, as well as auxiliary factors such as a test site 1330. Each device has a corresponding device clock (indicated by a clock mark). The device clock is used to indicate the timeline progress of the device and is a measurement scale for measuring and recording time during the operation of the device.

[0299] Optionally, by configuring a client program for determining the time synchronization error on roadside sensing devices such as millimeter-wave radars, cameras, lidars and other devices, and configuring a server program on the vehicle-mounted controller 1310, the time synchronization error between the roadside device and the vehicle-mounted device can be calculated through an automated time synchronization error determination method, thereby ensuring the efficiency of signal communication and command issuance and the safety of vehicle driving with the help of the time synchronization error.

[0300] Indicatively, through the above-mentioned method for determining the time synchronization error and the automated calculation tool used in conjunction with the method, the consistency of the time synchronization accuracy between different devices can be understood in real time. This avoids the limitation that the time synchronization error between devices can only be calculated by introducing additional modules such as the Global Positioning System (GPS) module, the Phase Locked Loop (PLL) module, the error calculation module, and the synchronization processing module in the terminal. While reducing the clock error to a subtle level, the simplicity of deployment and the controllability of costs are improved. By correcting the device clock through an optimization mechanism when the time synchronization error is large, it ensures that the devices can communicate, collaborate, and schedule stably to support the normal operation of the Industrial Internet project.

[0301] It is worth noting that the above are merely illustrative examples and are not limited to the embodiments of the present application.

[0302] To summarize, the time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then conduct targeted analysis on the interactive operation status between the first device and the second device, thereby avoiding interaction failures, low interaction accuracy and other interaction failures due to the asynchrony between the device clocks. The device clocks can be adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0303] Fig.14 is a structural block diagram of a device for determining a time synchronization error provided by an exemplary embodiment of the present application, such as Fig.14 As shown, the device includes the following parts:

[0304] A recording module 1410, configured to record a sending timestamp when sending a data message to a second device, where the sending timestamp is a time when the first device determines to send the data message based on a first device clock corresponding to the first device;

[0305] a receiving module 1420, configured to receive a response message sent by the second device, the response message including a first receiving timestamp and a response timestamp, the first receiving timestamp being a time when the second device determines to receive the data message based on a second device clock corresponding to the second device, and the response timestamp being a time when the second device determines to respond to the data message based on the second device clock;

[0306] The recording module 1410 is further configured to record the time when the response message is received as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on the clock of the first device;

[0307] A calculation module 1430 is used to perform a mean calculation on the transmission time of the data message and the response message based on the difference between the sending timestamp and the second receiving timestamp to obtain an average time difference;

[0308] Determination module 1440 is used to determine the time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp and the response timestamp, the time synchronization error is used to represent the time difference between the first device clock and the second device clock, and the time synchronization error is used to adjust the device clock.

[0309] In an optional embodiment, the determination module 1440 is also used to determine the uplink error sent by the first device to the second device based on the sending timestamp and the average time difference; determine the downlink error sent by the second device to the first device based on the response timestamp and the average time difference; and determine the time synchronization error between the first device and the second device by combining the uplink error and the downlink error.

[0310] In an optional embodiment, the determination module 1440 is also used to obtain the sum of the sending timestamp and the average time difference as the uplink time difference; based on the absolute value of the difference between the first receiving timestamp and the uplink time difference, the uplink error sent by the first device to the second device is obtained.

[0311] In an optional embodiment, the determination module 1440 is also used to obtain the sum of the response timestamp and the average time difference as the downlink time difference; based on the absolute value of the difference between the second receiving timestamp and the downlink time difference, the downlink error sent by the second device to the first device is obtained.

[0312] In an optional embodiment, the determination module 1440 is further configured to perform a mean operation on the sum of the uplink error and the downlink error to obtain the time synchronization error between the first device and the second device.

[0313] In an optional embodiment, the receiving module 1420 is also used to read the field in the first byte area of ​​the response message to obtain the first receiving timestamp, and the first byte area is the byte area where the second device writes the first receiving timestamp; read the field in the second byte area of ​​the response message to obtain the response timestamp, and the second byte area is the byte area where the second device writes the response timestamp.

[0314] In an optional embodiment, the response message includes a plurality of pre-set byte areas;

[0315] The receiving module 1420 is also used for the first device and the second device to pre-negotiate the field types respectively carried by the multiple byte areas; wherein the multiple byte areas include the first byte area carrying the first receiving timestamp, and the second byte area carrying the response timestamp.

[0316] In an optional embodiment, the recording module 1410 is further used to record the message identifier and the sending timestamp of the data message when sending the data message to the second device; wherein the i-th data message is correspondingly marked with the i-th message identifier, and i is a positive integer.

[0317] In an optional embodiment, the i-th response message is a response message corresponding to the i-th data message, and the i-th response message is correspondingly marked with the i-th message identifier;

[0318] The recording module 1410 is also used to record the moment of receiving the i-th response message storing the i-th message identifier after sending the i-th data message, as the second receiving timestamp corresponding to the i-th data message; wherein the i-th message identifier is stored in the third byte area for storing the message identifier in the i-th response message.

[0319] In an optional embodiment, the determination module 1440 is also used to determine the time synchronization error between the first device and the second device at the sending timestamp based on the average time difference, the first receiving timestamp and the response timestamp; send multiple data packets to the second device, and determine the time synchronization errors of the multiple data packets at the corresponding sending timestamps to obtain multiple time synchronization errors; and determine the time synchronization error between the first device and the second device by combining the multiple time synchronization errors.

[0320] like Fig.15 As shown, in an optional embodiment, the device further includes:

[0321] The judgment module 1450 is used to obtain a first data packet transmitted between the first device and the second device, the data packet including at least one of the data message and the response message, the first data packet being at least one data packet captured by the first device from multiple data packets transmitted between the first device and the second device; receiving a second data packet sent by the second device to the first device, the second data packet being at least one data packet captured by the second device from multiple data packets transmitted between the first device and the second device; and obtaining a reference time error between the first device and the second device based on the same data packets in the first data packet and the second data packet, the reference time error being used to perform accuracy judgment on the time synchronization error.

[0322] In an optional embodiment, the judgment module 1450 is also used to determine multiple data in the same data packet in the first data packet and the second data packet; determine first data timestamps corresponding to the multiple data in the first data packet, and determine second data timestamps corresponding to the multiple data in the second data packet; and obtain a reference time error between the first device and the second device based on the time difference between the first data timestamp and the second data timestamp.

[0323] In an optional embodiment, the determination module 1440 is also used to adjust the first device clock of the first device based on the time synchronization error in response to the time synchronization error reaching a preset adjustment threshold; or, in response to the time synchronization error reaching a preset adjustment threshold, adjust the second device clock of the second device based on the time synchronization error.

[0324] In an optional embodiment, the determination module 1440 is also used to, in response to the time synchronization error reaching a preset adjustment threshold, and the first device is a slave device, and the second device is a master device, adjust the first device clock of the first device based on the time synchronization error; or, in response to the time synchronization error reaching a preset adjustment threshold, and the first device is a master device, and the second device is a slave device, adjust the second device clock of the second device based on the time synchronization error.

[0325] To summarize, the time synchronization error can express the time difference between the clock of the first device and the clock of the second device in a more real-time manner, and then conduct targeted analysis on the interactive operation status between the first device and the second device, thereby avoiding interaction failures, low interaction accuracy and other interaction failures due to the asynchrony between the device clocks. The device clocks can be adjusted more flexibly and timely through the time synchronization error, which greatly improves the accuracy of the time synchronization error and reduces the deployment difficulty of determining the time synchronization error.

[0326] It should be noted that the device for determining the time synchronization error provided in the above embodiment is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the device for determining the time synchronization error provided in the above embodiment and the method for determining the time synchronization error belong to the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0327] Fig.16The schematic diagram of the structure of a server provided by an exemplary embodiment of the present application is shown. The server 1600 includes a central processing unit (CPU) 1601, a system memory 1604 including a random access memory (RAM) 1602 and a read-only memory (ROM) 1603, and a system bus 1605 connecting the system memory 1604 and the central processing unit 1601. The server 1600 also includes a mass storage device 1606 for storing an operating system 1613, an application program 1614, and other program modules 1615.

[0328] The mass storage device 1606 is connected to the central processing unit 1601 through a mass storage controller (not shown) connected to the system bus 1605. The mass storage device 1606 and its associated computer readable media provide non-volatile storage for the server 1600. That is, the mass storage device 1606 may include a computer readable medium (not shown) such as a hard disk or a compact disc read only memory (CD-ROM) drive.

[0329] Without loss of generality, computer readable media may include computer storage media and communication media. Computer storage media include volatile and non-volatile, removable and non-removable media implemented in any method or technology for storing information such as computer readable instructions, data structures, program modules or other data. The above-mentioned system memory 1604 and mass storage device 1606 can be collectively referred to as memory.

[0330] According to various embodiments of the present application, the server 1600 can also be connected to a remote computer on the network through a network such as the Internet. That is, the server 1600 can be connected to the network 1612 through the network interface unit 1611 connected to the system bus 1605, or the network interface unit 1611 can be used to connect to other types of networks or remote computer systems (not shown).

[0331] The above-mentioned memory also includes one or more programs, and the one or more programs are stored in the memory and configured to be executed by the CPU.

[0332] An embodiment of the present application also provides a computer device, which includes a processor and a memory, in which at least one instruction, at least one program, a code set or an instruction set is stored, and the at least one instruction, at least one program, a code set or an instruction set is loaded and executed by the processor to implement the method for determining the time synchronization error provided in the above-mentioned method embodiments.

[0333] An embodiment of the present application also provides a computer-readable storage medium, on which is stored at least one instruction, at least one program, code set or instruction set, and the at least one instruction, at least one program, code set or instruction set is loaded and executed by a processor to implement the method for determining the time synchronization error provided in the above-mentioned method embodiments.

[0334] The embodiments of the present application also provide a computer program product or a computer program, which includes a computer instruction stored in a computer-readable storage medium. The processor of the computer device reads the computer instruction from the computer-readable storage medium, and the processor executes the computer instruction, so that the computer device executes the method for determining the time synchronization error described in any of the above embodiments.

[0335] The above description is only an optional embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection scope of the present application.

Claims

1. A method for determining a time synchronization error, characterized in that: Executed by a first device, the method includes: When sending a data message to a second device, record a sending timestamp, where the sending timestamp is a time when the first device sends the data message determined by the first device based on a first device clock corresponding to the first device; receiving a response message sent by the second device, the response message including a first receiving timestamp and a response timestamp, the first receiving timestamp being a time when the second device receives the data message determined based on a second device clock corresponding to the second device, and the response timestamp being a time when the second device responds to the data message determined based on the second device clock; Recording the time when the response message is received as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on the clock of the first device; Based on the difference between the sending timestamp and the second receiving timestamp, performing a mean operation on the transmission time of the data message and the response message to obtain an average time difference; A time synchronization error between the first device and the second device is determined based on the average time difference, the first receiving timestamp, and the response timestamp. The time synchronization error is used to represent the time difference between the first device clock and the second device clock. The time synchronization error is used to adjust the device clock.

2. The method according to claim 1, characterized in that The determining a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp, and the response timestamp includes: Determine an uplink error sent by the first device to the second device based on the sending timestamp and the average time difference; Determine a downlink error sent by the second device to the first device based on the response timestamp and the average time difference; The time synchronization error between the first device and the second device is determined by combining the uplink error and the downlink error.

3. The method according to claim 2, characterized in that The determining, based on the sending timestamp and the average time difference, an uplink error sent by the first device to the second device includes: Obtaining the sum of the sending timestamp and the average time difference as the uplink time difference; The uplink error sent by the first device to the second device is obtained based on the absolute value of the difference between the first receiving timestamp and the uplink time difference.

4. The method according to claim 2, characterized in that: The determining, based on the response timestamp and the average time difference, a downlink error sent by the second device to the first device includes: Obtaining the sum of the response timestamp and the average time difference as the downlink time difference; The downlink error sent by the second device to the first device is obtained based on the absolute value of the difference between the second receiving timestamp and the downlink time difference.

5. The method according to claim 2, characterized in that: The step of determining the time synchronization error between the first device and the second device by combining the uplink error and the downlink error includes: Perform a mean operation on the sum of the uplink error and the downlink error to obtain the time synchronization error between the first device and the second device.

6. The method according to any one of claims 1 to 5, characterized in that: The receiving a response message sent by the second device includes: Reading a field in a first byte area of ​​the response message to obtain the first receiving timestamp, where the first byte area is a byte area where the second device writes the first receiving timestamp; The field in the second byte area of ​​the response message is read to obtain the response timestamp, where the second byte area is the byte area where the second device writes the response timestamp.

7. The method according to claim 6, characterized in that The response message includes a plurality of pre-set byte areas; The method further comprises: The first device and the second device pre-negotiate field types respectively carried by the multiple byte areas, and the field types include at least one timestamp type; The multiple byte areas include the first byte area carrying the first receiving timestamp, and the second byte area carrying the response timestamp.

8. The method according to any one of claims 1 to 5, characterized in that: When sending a data message to the second device, recording a sending timestamp includes: When sending a data message to the second device, recording a message identifier and a sending timestamp of the data message; The i-th data message is marked with the i-th message identifier, and i is a positive integer.

9. The method according to claim 8, characterized in that The i-th response message is a response message corresponding to the i-th data message, and the i-th response message is marked with the i-th message identifier; The recording of the time when the response message is received as a second receiving timestamp includes: In response to receiving an i-th response message storing the i-th message identifier after sending the i-th data message, recording a time when the i-th response message is received as the second receiving timestamp corresponding to the i-th data message; The i-th message identifier is stored in the third byte area for storing message identifiers in the i-th response message.

10. The method according to any one of claims 1 to 5, characterized in that: The determining a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp, and the response timestamp includes: Determine the time synchronization error between the first device and the second device at the sending timestamp based on the average time difference, the first receiving timestamp, and the response timestamp; The method further comprises: Sending a plurality of data packets to the second device, and determining time synchronization errors of the plurality of data packets at corresponding sending timestamps, to obtain a plurality of time synchronization errors; The time synchronization error between the first device and the second device is determined by combining the multiple time synchronization errors.

11. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: Acquire a first data packet transmitted between the first device and the second device, the data packet including at least one of the data message and the response message, the first data packet being at least one data packet captured by the first device from multiple data packets transmitted between the first device and the second device; receiving a second data packet sent by the second device to the first device, where the second data packet is at least one data packet captured by the second device from multiple data packets transmitted between the first device and the second device; Based on the same data packets in the first data packet and the second data packet, a reference time error between the first device and the second device is obtained, and the reference time error is used to determine the accuracy of the time synchronization error.

12. The method according to claim 11, characterized in that The obtaining, based on the same data packet in the first data packet and the second data packet, a reference time error between the first device and the second device, comprises: Determine a plurality of data in the same data packet in the first data packet and the second data packet; Determine first data timestamps corresponding to the plurality of data in the first data packet, and determine second data timestamps corresponding to the plurality of data in the second data packet; Based on the time difference between the first data timestamp and the second data timestamp, a reference time error between the first device and the second device is obtained.

13. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: In response to the time synchronization error reaching a preset adjustment threshold, adjusting the first device clock of the first device based on the time synchronization error; or, In response to the time synchronization error reaching a preset adjustment threshold, the second device clock of the second device is adjusted based on the time synchronization error.

14. The method according to claim 13, characterized in that The first device and the second device have a preset master-slave relationship; In response to the time synchronization error reaching a preset adjustment threshold, adjusting the first device clock of the first device based on the time synchronization error includes: In response to the time synchronization error reaching a preset adjustment threshold, and the first device is a slave device and the second device is a master device, adjusting the first device clock of the first device based on the time synchronization error; In response to the time synchronization error reaching a preset adjustment threshold, adjusting the second device clock of the second device based on the time synchronization error includes: In response to the time synchronization error reaching a preset adjustment threshold, and the first device is a master device and the second device is a slave device, the second device clock of the second device is adjusted based on the time synchronization error.

15. A device for determining a time synchronization error, characterized in that: The device comprises: a recording module, configured to record a sending timestamp when sending a data message to a second device, wherein the sending timestamp is a time when the first device determines to send the data message based on a first device clock corresponding to the first device; a receiving module, configured to receive a response message sent by the second device, wherein the response message includes a first receiving timestamp and a response timestamp, wherein the first receiving timestamp is a time when the second device determines to receive the data message based on a second device clock corresponding to the second device, and the response timestamp is a time when the second device determines to respond to the data message based on the second device clock; The recording module is further used to record the time when the response message is received as a second receiving timestamp, where the second receiving timestamp is a timestamp determined based on the clock of the first device; A calculation module, configured to perform a mean calculation on the transmission time of the data message and the response message based on the difference between the sending timestamp and the second receiving timestamp to obtain an average time difference; A determination module is used to determine a time synchronization error between the first device and the second device based on the average time difference, the first receiving timestamp and the response timestamp, wherein the time synchronization error is used to represent the time difference between the first device clock and the second device clock, and the time synchronization error is used to adjust the device clock.

16. A computer device, characterized in that: The computer device includes a processor and a memory, wherein the memory stores at least one program, and the at least one program is loaded and executed by the processor to implement the method for determining the time synchronization error as described in any one of claims 1 to 14.

17. A computer-readable storage medium, characterized in that: The storage medium stores at least one instruction, at least one program, a code set or an instruction set, and the at least one instruction, the at least one program, the code set or the instruction set is loaded and executed by the processor to implement the method for determining the time synchronization error as described in any one of claims 1 to 14.

18. A computer program product, characterized in that It comprises a computer program or an instruction, which, when executed by a processor, implements the method for determining the time synchronization error as claimed in any one of claims 1 to 14.