Time synchronization method, electronic device, storage medium and program product

By combining gPTP messages and PPS signals to obtain time deviations and adaptively selecting synchronization protocols, the problem of insufficient accuracy of the traditional PTP protocol under network fluctuations is solved, and high-precision and stable time synchronization is achieved.

CN120602035APending Publication Date: 2025-09-05ZTE CORP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511002336.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-07-21
Publication Date
2025-09-05

AI Technical Summary

Technical Problem

The traditional PTP protocol has low time synchronization accuracy under network fluctuations and relies on insufficient network stability, resulting in reduced synchronization accuracy.

Method used

Combine the gPTP message and PPS signal to obtain the first and second time offsets, control the slave clock device to perform adaptive time synchronization based on the offsets, and select the appropriate protocol for synchronization.

Benefits of technology

It achieves high-precision and stable time synchronization in different network environments, improving the reliability and stability of time synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120602035A_ABST
    Figure CN120602035A_ABST
Patent Text Reader

Abstract

The invention provides a time synchronization method, electronic equipment, a storage medium and a program product. The method is applied to a master clock device, and comprises the following steps: sending a generalized precision time protocol gPTP message and a pulse per second PPS signal to a slave clock device; a first time deviation and a second time deviation are obtained, the first time deviation is determined according to a receiving and sending timestamp of the gPTP message, and the second time deviation is determined according to an arrival timestamp of the PPS signal; and controlling the slave clock equipment to perform time synchronization according to the first time deviation and the second time deviation. Thus, the slave clock device is controlled to perform time synchronization according to the first time deviation of the gPTP protocol and the second time deviation of the PPS signal, and the gPTP protocol or the PPS signal can be adaptively selected to perform time synchronization, so that high-precision time synchronization can be realized in different network environments, and the reliability and stability of time synchronization are effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of communication technology, and in particular to a time synchronization method, electronic equipment, storage medium, and program product. Background Art

[0002] In some communication scenarios, such as fifth-generation (5G) and sixth-generation (6G) mobile communication technologies, autonomous driving, and the Internet of Vehicles (IoV), high-precision time synchronization has become a core technical infrastructure supporting efficient operations in key areas. Related technologies use the Precision Time Protocol (PTP) for time synchronization, which enables nanosecond-level synchronization through interactive messages. However, in practical applications, PTP-based time synchronization relies on network stability and suffers from low synchronization accuracy in the event of network fluctuations. Summary of the Invention

[0003] The present application provides a time synchronization method, electronic device, storage medium and program product, which are used to at least solve the problem of low accuracy when using the traditional PTP protocol for time synchronization.

[0004] To solve the above technical problems, this application is implemented as follows: In a first aspect, a time synchronization method is provided, which is applied to a master clock device, comprising: Send generalized precision time protocol gPTP messages and pulse-per-second (PPS) signals to slave clock devices; Obtain a first time offset and a second time offset, where the first time offset is determined according to a sending and receiving timestamp of the gPTP message, and the second time offset is determined according to an arrival timestamp of the PPS signal; The slave clock device is controlled to perform time synchronization according to the first time offset and the second time offset.

[0005] In a second aspect, an electronic device is provided, including: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method as described in the first aspect.

[0006] According to a third aspect, a computer-readable storage medium is provided. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the method according to the first aspect.

[0007] In a fourth aspect, a computer program product is provided, comprising a non-transitory computer-readable storage medium storing a computer program, wherein the computer program is operable to cause a computer to execute some or all of the steps in the method described in the first aspect.

[0008] In an embodiment of the present application, when performing time synchronization, gPTP and PPS signals are combined for time synchronization. Specifically, the master clock device can send a gPTP message and a PPS signal to the slave clock device, and then obtain a first time deviation corresponding to the gPTP message and a second time deviation corresponding to the PSS signal. Based on these two time deviations, the slave clock device is controlled to perform time synchronization. Since the first time deviation can reflect the network status and the time synchronization accuracy based on the gPTP protocol, and the second time deviation can reflect the time synchronization accuracy based on the PPS signal, the slave clock device is controlled to perform time synchronization based on these two time deviations. According to the network status and time synchronization accuracy, the gPTP protocol or the PPS signal can be adaptively selected for time synchronization, thereby achieving high-precision time synchronization in different network environments, effectively improving the reliability and stability of time synchronization. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] In order to more clearly illustrate the technical solutions in this application or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are only some embodiments recorded in this application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0010] Figure 1 This is a flowchart of a time synchronization method according to an embodiment of the present application; Figure 2 This is a flowchart of a time synchronization method according to an embodiment of the present application; Figure 3 This is a flowchart of a method for determining link delay from a clock device according to an embodiment of the present application; Figure 4 This is a schematic diagram of time deviation convergence between master and slave clock devices according to an embodiment of the present application; Figure 5 This is a schematic structural diagram of an electronic device according to an embodiment of the present application; Figure 6 It is a structural diagram of a time synchronization device according to an embodiment of the present application. DETAILED DESCRIPTION

[0011] With the deepening evolution of digital, networked, and intelligent information technology, high-precision time synchronization has become core infrastructure supporting efficient operations in key sectors. For example, in 5G scenarios, 5G base stations require nanosecond-level time synchronization accuracy. In 6G scenarios, 6G networks place even higher demands on the reliability and anti-interference capabilities of cross-domain time synchronization. Another example is autonomous driving and connected vehicles. Vehicle perception and sensor data rely heavily on nanosecond-level synchronization accuracy to avoid decision delays caused by error accumulation. This is especially true in complex road environments, placing stringent demands on communication capabilities such as low latency and packet loss reduction for time synchronization.

[0012] In related technologies, time synchronization can be achieved at the nanosecond level based on the PTP protocol, such as the standard PTP protocol or gPTP protocol. However, the time synchronization accuracy of the PTP protocol depends on the stability of the network. In the event of network fluctuations, such as network delays or congestion, PTP messages may be lost or delayed, resulting in jitter, which in turn leads to low synchronization accuracy.

[0013] The embodiments of the present application provide a time synchronization method, electronic device, storage medium and program product, which can combine the advantages of gPTP and PPS to achieve adaptive high-precision time synchronization. Specifically, when performing time synchronization, the master clock device can send a gPTP message and a PPS signal to the slave clock device, and then obtain a first time deviation corresponding to the gPTP message and a second time deviation corresponding to the PSS signal, and control the slave clock device to perform time synchronization based on these two time deviations. Since the first time deviation can reflect the network status and the time synchronization accuracy based on the gPTP protocol, and the second time deviation can reflect the time synchronization accuracy based on the PPS signal, therefore, according to the two time deviations, the slave clock device is controlled to perform time synchronization. It is possible to adaptively select the gPTP protocol or the PPS signal for time synchronization according to the network status and time synchronization accuracy, thereby achieving high-precision time synchronization in different network environments, effectively improving the reliability and stability of time synchronization.

[0014] It should be noted that the time synchronization method provided in the embodiments of the present application is suitable for scenarios with high requirements for time synchronization and network stability, such as 5G / 6G edge computing, autonomous driving and Internet of Vehicles, industrial Internet of Things, industrial automation, intelligent driving, etc., without specific limitations here.

[0015] In order to help those skilled in the art better understand the technical solutions of this application, the following will clearly and completely describe the technical solutions of this application in conjunction with the drawings of one or more embodiments of this application. Obviously, the described embodiments are only part of the embodiments of this application, not all of the embodiments. Based on the embodiments of this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.

[0016] The terms "first," "second," and the like in this application and the claims are used to distinguish similar objects and are not used to describe a particular order or precedence. It should be understood that such terms are interchangeable where appropriate so that this application can be implemented in sequences other than those illustrated or described herein. In addition, the term "and / or" in this application and the claims refers to at least one of the connected objects, and the character " / " generally indicates that the connected objects are in an "or" relationship.

[0017] The following describes in detail the technical solutions provided by various embodiments of the present application in conjunction with the accompanying drawings.

[0018] Figure 1 It is a flowchart of a time synchronization method according to an embodiment of the present application. Figure 1 The time synchronization method shown is applied to a master clock device, in other words, Figure 1 The time synchronization method shown can be performed by software or hardware in the master clock device. Figure 1 The time synchronization method shown is described below.

[0019] Step S102: Sending a generalized precision time protocol gPTP message and a pulse second PPS signal to a slave clock device.

[0020] During time synchronization, a master clock device can send generalized Precision Time Protocol (gPTP) messages and pulse per second (PPS) signals to slave clock devices. gPTP messages can be sent over the network, while PPS signals can be sent over hardware lines.

[0021] In some implementations, to enable the master-clock device to send gPTP messages and PPS signals to slave-clock devices, the master-clock device's hardware can be pre-designed or modified accordingly. For example, the PPS signal of the master-clock device's Ethernet physical layer (PHY) chip can be connected to an interrupt pin to read the PPS seconds digit. The output PPS signal is then calibrated using a Time-Sensitive Network (TSN) master-clock chip. An integrated protocol stack obtains nanosecond timestamps from the Ethernet PHY chip for gPTP protocol processing. Similarly, to facilitate the slave-clock device receiving gPTP messages and PPS signals from the master-clock device, the same hardware design or modification can be performed on the slave-clock device, which will not be repeated here.

[0022] After the above-mentioned design or improvement is performed on the hardware of the master and slave clock devices, the master and slave clock devices can first be initialized during time synchronization. After initialization is complete, the master clock device can send gPTP messages and PPS signals to the slave clock device, and the slave clock device can receive gPTP messages and PPS signals from the master clock device. Taking the master clock device as an example, the initialization process includes but is not limited to: initializing the Ethernet PHY chip that supports IEEE 1588v2 (PTP) and configuring the hardware timestamp function; initializing the PPS signal input interface, including pin configuration, signal conditioning circuit startup, and interrupt setting; loading the network driver to achieve network communication with the slave clock device, loading the PPS driver to obtain the PPS signal; and loading the gPTP protocol stack to support the processing of gPTP protocol messages.

[0023] Step S104: Obtain a first time offset and a second time offset, where the first time offset is determined based on the sending and receiving timestamps of the gPTP message, and the second time offset is determined based on the arrival timestamp of the PPS signal.

[0024] The gPTP message carries the sending timestamp of the gPTP message, and the receiving timestamp of the gPTP message can be determined by the slave clock device based on the actual receiving time. Therefore, after the master clock device sends the gPTP message and PPS signal to the slave clock device, the slave clock device can record the sending and receiving timestamp of the gPTP message. In addition, the slave clock device can also record the arrival timestamp of the PPS signal or the receiving time of the PPS signal. Afterwards, the slave clock device can determine the first time deviation based on the sending and receiving timestamp of the gPTP message, and determine the second time deviation based on the arrival timestamp of the PPS signal. The first time deviation corresponds to the gPTP message, and can reflect the network status and the time synchronization accuracy based on the gPTP message. The second time deviation corresponds to the PPS signal, and can reflect the time synchronization accuracy based on the PPS signal.

[0025] There are multiple implementations for determining the first time offset based on the sending and receiving timestamps of the gPTP message by the slave clock device. Optionally, in some implementations, the first time offset can be determined by the following method: Based on the sending and receiving timestamps of the gPTP message, determine the time difference between the receiving timestamp and the sending timestamp; Determine the link delay between the master clock device and the slave clock device; A first time offset is determined according to the time difference and the link delay.

[0026] The link delay between the master clock device and the slave clock device can be determined by a variety of methods. Optionally, in some embodiments, the slave clock device receives the gPTP message and records the reception timestamp. t 2 and send timestamp t 1, a delay request message, such as a Delay_Req message, can be sent to the master clock device, and the sending timestamp of the delay request message is recorded. t 3. After receiving the delay request message, the master clock device records the receiving timestamp t 4. Send a delayed response message to the slave clock device, such as a Delay_Resp message, which carries a receiving timestamp. t 4. After receiving the delay response message from the clock device, you can parse it to obtain the receiving timestamp t 4. Then combine the previously recorded gPTP message sending and receiving timestamps t 1. t 2 and the sending timestamp of the delay request message t 3. Determine the link delay between the master clock device and the slave clock device. The link delay can be expressed as: .

[0027] When the time difference between the receiving timestamp and the sending timestamp of the gPTP message and the link delay are known, the difference between the time difference and the link delay can be determined as the first time offset. In other words, the first time offset is equal to the difference between the time difference and the link delay, where the time difference is the time difference between the receiving timestamp and the sending timestamp of the gPTP message, and the link delay is the link delay between the master clock device and the slave clock device. The first time offset can be expressed as: .

[0028] in,( t 2- t1) is the time difference between the receiving timestamp and sending timestamp of the gPTP message, and d is the link delay between the master clock device and the slave clock device.

[0029] There are multiple implementations of the slave clock device determining the second time offset based on the arrival timestamp of the PPS signal. Optionally, in some implementations, the second time offset may be determined by the following method: A second time offset is determined based on the local clock time of the master clock device and the arrival timestamp of the PPS signal.

[0030] The slave clock device can obtain the local clock time of the master clock device through hardware monitoring or other methods. When the local clock time of the master clock device is known, the difference between the arrival timestamp of the PPS signal and the local clock time of the master clock device can be determined as the second time offset, that is, the second time offset is equal to the difference between the arrival timestamp of the PPS signal and the local clock time of the master clock device. Assume that the local clock time of the master clock device is t local , the arrival timestamp of the PPS signal is t pps , then the second time deviation can be expressed as: .

[0031] After the slave clock device obtains the first and second time offsets, the master clock device can obtain the first and second time offsets. In some embodiments, while the master clock device and the slave clock device are in communication, the master clock device can obtain the first and second time offsets via a protocol stack or other means. Of course, in other possible embodiments, the master clock device can also obtain the first and second time offsets via other means, which are not specifically limited here.

[0032] Step S106: Control the slave clock device to perform time synchronization according to the first time offset and the second time offset.

[0033] After obtaining the first and second time offsets, the master clock device can control the slave clock devices for time synchronization based on these two time offsets. Because the first time offset reflects network conditions and the accuracy of gPTP-based time synchronization, and the second time offset reflects the accuracy of PPS-based time synchronization, controlling the slave clock devices for time synchronization based on these two time offsets allows adaptive selection of gPTP or PPS for time synchronization based on network conditions and time synchronization accuracy. This enables high-precision time synchronization in diverse network environments, effectively improving the reliability and stability of time synchronization.

[0034] In some implementations, the master clock device controlling the slave clock device to perform time synchronization based on the first time offset and the second time offset may include: Determining whether the first time deviation is greater than or equal to a time deviation threshold; When the first time deviation is less than the time deviation threshold, controlling the slave clock device to perform time synchronization according to the first time deviation; and / or, When the first time deviation is greater than or equal to the time deviation threshold, the slave clock device is controlled to perform time synchronization according to the first time deviation and the second time deviation.

[0035] The time deviation threshold can be set according to actual conditions and is not specifically limited here. Optionally, the time deviation threshold can be the maximum network delay that can be tolerated when performing time synchronization based on gPTP messages.

[0036] When the first time deviation is less than the time deviation threshold, it can be said that the current network delay is within the allowable range, the network condition is good, and the time synchronization accuracy of gPTP is high. At this time, the slave clock device can be controlled to perform time synchronization based on the first time deviation, that is, the slave clock device can be controlled to perform time synchronization based on the gPTP protocol. When controlling the slave clock device to perform time synchronization based on the first time deviation, the slave clock device can be controlled to use the sum of the current time of the slave clock device, that is, the time before synchronization, and the first time deviation as the time after synchronization. Optionally, in some embodiments, the master clock device can control the slave clock device to perform time synchronization by sending a control instruction to the slave clock device, and the control instruction is used to instruct the slave clock device to perform time synchronization based on the first time deviation. After receiving the control instruction, the slave clock device can use the sum of the time before synchronization and the first time deviation as the time after synchronization, thereby achieving time synchronization between the master and slave devices.

[0037] When the first time deviation is greater than or equal to the time deviation threshold, it can be said that the current network delay is serious and the network status is poor. At this time, the slave clock device can be controlled to perform time synchronization based on the first time deviation and the second time deviation. That is, gPTP and PPS are combined to control the slave clock device to perform time synchronization, so as to adaptively select a suitable time synchronization strategy for time synchronization and improve synchronization accuracy.

[0038] In some implementations, the master clock device controlling the slave clock device to perform time synchronization based on the first time offset and the second time offset may include: determining a third time offset based on the first time offset and the second time offset; Determining a corresponding time synchronization strategy according to the size of the third time deviation; Controls time synchronization of slave clock devices according to the time synchronization policy.

[0039] Considering that network quality, such as packet loss rate and link latency, can affect gPTP synchronization accuracy, and generally speaking, poorer network quality leads to lower synchronization accuracy and greater time deviation between master and slave clock devices. PPS, as a network-independent backup source, can quickly take over synchronization in the event of network anomalies. Therefore, when controlling time synchronization of slave clock devices based on a first and second time deviation, the first and second time deviations can be analyzed and a third time deviation calculated or determined based on them. This third time deviation comprehensively reflects network conditions and time synchronization requirements, and can be used to determine a time synchronization strategy. Different sizes of the third time deviation can correspond to different time synchronization strategies.

[0040] When determining the third time offset according to the first time offset and the second time offset, in some embodiments, the method may include: Predict the time deviation of the gPTP message at the current moment to obtain the time deviation prediction value at the current moment; Determine a time deviation measurement value at a current moment according to the first time deviation and the second time deviation; The time deviation prediction value is adjusted according to the time deviation measurement value to obtain a third time deviation.

[0041] The time deviation of the gPTP message is the time deviation between the master and slave clock devices when the gPTP protocol is used for time synchronization. When predicting the time deviation at the current moment, optionally, historical synchronization data can be collected when the gPTP protocol is used for time synchronization, such as synchronization accuracy, time deviation between the master and slave clock devices before and after synchronization, network conditions, etc., where the network conditions may include packet loss rate, link delay, etc., and then the change or fluctuation pattern of the time deviation is determined based on the collected historical synchronization data, and finally the time deviation of the gPTP message at the current moment is predicted based on the network status at the current moment to obtain the time deviation prediction value. At present, other methods can also be used to predict the time deviation of the gPTP message at the current moment, such as prediction based on an AI model, etc., which are not specifically limited here.

[0042] When determining the time deviation measurement value at the current moment based on the first time deviation and the second time deviation, the average of the first time deviation and the second time deviation can be used as the time deviation measurement value at the current moment. For example, assuming that the first time deviation is Δt gptp , the second time deviation is Δt pps , then the time deviation prediction value at the current moment can be expressed as: .

[0043] After obtaining the time deviation prediction value and the time deviation measurement value at the current moment, the time deviation measurement value may be adjusted according to the time deviation prediction value to obtain a third time deviation.

[0044] In some implementations, when adjusting the time deviation measurement value according to the time deviation prediction value, it can be implemented based on a Kalman filter algorithm. Specifically, it can include: Determine the Kalman gain based on the state covariance prediction value and the measurement noise covariance at the current moment; The time deviation prediction value is adjusted according to the Kalman gain and the time deviation measurement value to obtain a third time deviation.

[0045] When determining the Kalman gain at the current moment based on the state covariance prediction value and the measurement noise covariance at the current moment, the Kalman gain can be determined in the following manner: .

[0046] in, is the state covariance prediction value at the current moment, which can be calculated according to the formula Definitely get it, is the state covariance at the previous moment, the initial value can be set to 1, Q is the process noise covariance, which can be set to 0.01, and R is the measurement noise covariance.

[0047] When the time offset prediction value is adjusted according to the Kalman gain and the time offset measurement value, the third time offset can be obtained by the following formula: .

[0048] in, is the time deviation prediction value at the current moment, is the time deviation measurement value at the current moment, is the Kalman gain at the current moment.

[0049] After obtaining the third time deviation, the state covariance prediction value at the current moment can optionally be updated to obtain the state covariance at the current moment, so as to determine the state covariance prediction value at the next moment based on the updated state covariance, and then determine the Kalman gain at the next moment based on the predicted value of the state covariance.

[0050] When updating the state covariance at the current moment, optionally, it can be implemented according to the following formula: .

[0051] in, is the updated state covariance at the current moment, is the Kalman gain at the current moment, is the state covariance prediction value at the current moment.

[0052] After the third time offset is obtained based on the above method, a corresponding time synchronization strategy may be determined according to the size of the third time offset.

[0053] In this embodiment, there may be multiple time synchronization strategies, and different sizes of the third time deviation may correspond to different time synchronization strategies. In some embodiments, the time synchronization strategy may include at least one of the PPS auxiliary mode and the PPS mode and the gPTP mode, that is, the time synchronization strategy may include the PPS auxiliary mode and the gPTP mode, or include the PPS mode and the gPTP mode, or include the PPS auxiliary mode, the PPS mode and the gPTP mode. Among them, the PPS auxiliary mode is to perform time synchronization according to the gPTP protocol and the PPS signal, that is, to perform time synchronization by assisting the gPTP protocol with the PSS signal. The PPS mode is to perform time synchronization according to the PSS signal, that is, it does not rely on the gPTP protocol, but performs time synchronization according to the PPS signal. The gPTP mode is to perform time synchronization according to the gPTP protocol, and does not require the PPS signal to assist in time synchronization. In this way, according to the size of the third time deviation, the time synchronization strategy is determined, which may include: When the third time deviation is less than the first threshold, determining that the time synchronization strategy is the gPTP mode; When the third time deviation is greater than or equal to the first threshold, the time synchronization strategy is determined to be the PPS-assisted mode or the PPS mode.

[0054] The first threshold can be set according to the actual situation and is not specifically limited here. Optionally, the first threshold can be set to 50ns. When determining the time synchronization strategy based on the third time deviation, if the third time deviation is less than the first threshold, it can be said that the third time deviation is within the allowable range. At this time, time synchronization can be performed according to the gPTP protocol, that is, the gPTP mode is determined as the time synchronization strategy. If the third time deviation is greater than or equal to the first threshold, it can be said that the third time deviation exceeds the set range. At this time, if time synchronization is performed according to the gPTP protocol, the third time deviation will become larger and larger. In order to avoid the third time deviation becoming larger and thus reducing the time synchronization accuracy, when the time synchronization strategy includes the PPS auxiliary mode, the PPS signal and the gPTP protocol can be combined for time synchronization, or, when the time synchronization strategy includes the PPS mode, time synchronization is performed according to the PPS signal, that is, the PPS auxiliary mode or the PPS mode is determined as the time synchronization strategy.

[0055] In some embodiments, when the time synchronization strategy includes PPS-assisted mode, PPS mode, and gPTP mode, when the third time deviation is greater than or equal to the first threshold, the PPS-assisted mode can be selected for time synchronization, or the PPS mode can be selected for time synchronization. In order to facilitate the determination of which mode to select for time synchronization to improve synchronization accuracy, a second threshold can be set. The second threshold is greater than the first threshold, and the specific size can be set according to actual conditions, for example, it can be 200ns, which is not specifically limited here. In this way, when determining the corresponding time synchronization strategy based on the size of the third time deviation, it can also include: When the third time deviation is greater than or equal to the first threshold and less than the second threshold, determining that the time synchronization strategy is a PPS auxiliary mode; When the third time deviation is greater than or equal to the second threshold, the time synchronization strategy is determined to be the PPS mode.

[0056] If the third time deviation is greater than or equal to the first threshold and less than the second threshold, it indicates that the third time deviation exceeds the allowable range but is relatively minor. Taking into account the network conditions and synchronization accuracy, the gPTP protocol and the PPS signal can be combined for time synchronization, i.e., the PPS auxiliary mode is determined as the time synchronization strategy. If the third time deviation is greater than or equal to the second threshold, it indicates that the third time deviation exceeds the allowable range and is relatively severe. To ensure synchronization accuracy, gPTP needs to be interrupted and time synchronization needs to be performed based on the PPS signal, i.e., the PPS mode is determined as the time synchronization strategy.

[0057] After the time synchronization policy is determined, the slave clock devices can be controlled to perform time synchronization according to the time synchronization policy.

[0058] In some embodiments, when the time synchronization strategy is the gPTP mode, controlling the slave clock device to perform time synchronization may include: controlling the slave clock device to perform time synchronization according to the gPTP protocol, wherein the local clock phase of the slave clock device after synchronization is equal to the sum of the clock phase before synchronization and the third time deviation, and the frequency remains unchanged. That is, when the slave clock device performs time synchronization according to the gPTP protocol, the sum of the clock phase before synchronization and the third time deviation may be used as the local clock phase after synchronization, i.e. , the frequency remains unchanged.

[0059] In some embodiments, when the time synchronization strategy is the PPS auxiliary mode, controlling the slave clock device to perform time synchronization may include: controlling the slave clock device to perform time synchronization according to the gPTP protocol and the PPS signal, wherein the local clock phase and frequency after synchronization of the slave clock device are determined according to the corrected time deviation, and the corrected time deviation is determined according to the first time deviation and the second time deviation. That is, when the slave clock device performs time synchronization according to the gPTP protocol and the PPS signal, it may first determine the corrected time deviation according to the first time deviation and the second time deviation, and then synchronize the local clock phase and frequency according to the corrected time deviation. When determining the corrected time deviation according to the first time deviation and the second time deviation, optionally, in some embodiments, the corrected time deviation may be determined by the following formula: .

[0060] The 0.7 and 0.3 in the above formula can also be adjusted according to actual conditions and are not specifically limited here.

[0061] In some embodiments, when the time synchronization strategy is the PPS mode, controlling the slave clock device to perform time synchronization may include: controlling the slave clock device to perform time synchronization according to the PPS signal, wherein the local clock phase of the slave clock device after synchronization is equal to the sum of the local clock phase before synchronization and the second time deviation. In other words, when the slave clock device performs time synchronization, the sum of the local clock phase before synchronization and the second time deviation may be determined as the local clock phase after synchronization, i.e. For frequency, optionally, if t pps If the changes over several consecutive cycles are not significant, no adjustment is required. If the changes are significant, fine-tuning may be required.

[0062] In this embodiment, after controlling the slave clock device to perform time synchronization according to the time synchronization policy, it is also possible to switch between different time synchronization policies according to the actual synchronization situation, so as to adaptively select the appropriate time synchronization policy for time synchronization, thereby improving the time synchronization accuracy, reliability and stability.

[0063] Optionally, in some implementations, when the time synchronization strategy is the PPS auxiliary mode or the PPS mode, after controlling the slave clock device to perform time synchronization according to the PPS auxiliary mode or the PPS mode, the method may further include: determining whether the third time deviation is less than or equal to a third threshold; When the third time deviation is less than or equal to the third threshold, the slave clock device is controlled to perform time synchronization according to the gPTP mode.

[0064] The third time deviation here is the time deviation re-determined based on the first time deviation corresponding to the gPTP message after time synchronization and the second time deviation corresponding to the PPS signal. After the slave clock device is controlled to synchronize time according to the PPS auxiliary mode or the PPS mode, it can be determined whether the re-determined third time deviation is less than or equal to the third threshold. The third threshold can be less than or equal to the above-mentioned first threshold, and can be set according to actual conditions, and is not specifically limited here. If the third time deviation is less than or equal to the third threshold, it can be explained that after the slave clock device is controlled to synchronize time according to the PPS auxiliary mode or the PPS mode, the time deviation between the master and slave clock devices is reduced. At this time, while ensuring the same time accuracy, it can be switched to the gPTP mode.

[0065] Based on the time synchronization method provided by the above-mentioned embodiment of the present application, during the time synchronization process, the master clock device can judge the network status and time synchronization accuracy according to the size of the dynamically changing third time deviation, and select gPTP or PPS for time synchronization according to the network status and time synchronization accuracy. For example, if the network condition is good, the measurement of the sending and receiving time of the gPTP message is accurate, and the synchronization accuracy of gPTP is higher than that of PPS, then gPTP is selected for time synchronization; if the network condition is poor, the measurement of the sending and receiving time of the gPTP message is inaccurate, or the synchronization accuracy of gPTP is lower than that of PPS, then PPS is selected for time synchronization; if the network condition is between good and poor, or the synchronization accuracy of gPTP is close to that of PPS, then gPTP and PPS are selected for time synchronization together. In this way, the appropriate time synchronization strategy can be adaptively selected for time synchronization, so that high-precision time synchronization can be achieved in different network environments, effectively improving the reliability and stability of time synchronization.

[0066] To facilitate understanding of the time synchronization method provided in the embodiments of the present application, a more specific implementation method is described below as an example.

[0067] In this embodiment, prior to time synchronization, the hardware of the master and slave clock devices was designed and improved accordingly. Taking the master clock device as an example, the hardware design or improvements include, but are not limited to: connecting the PPS signal of the Ethernet PHY chip in the master clock device to an interrupt pin to read the PPS seconds digit. The output 1PPS signal is calibrated by the TSN master clock chip. The protocol stack is integrated to obtain nanosecond timestamps from the Ethernet PHY chip for gPTP protocol processing. The slave clock device is similar and will not be repeated here.

[0068] When synchronizing time, see Figure 2 , which may include the following steps: Step 1: System initialization.

[0069] The system here can be the operating system of the master and slave clock devices.

[0070] Step 1.1: Device Preparation. Initialization, using the master clock device as an example, includes but is not limited to: initializing the Ethernet PHY chip supporting IEEE 1588v2 and configuring the hardware timestamp function; initializing the PPS signal input interface, including pin configuration, signal conditioning circuit startup, and interrupt setup; loading the network driver to enable network communication with the master clock device, loading the PPS driver to obtain PPS signal data; and loading the gPTP protocol stack to support the transmission and reception of gPTP protocol messages and timestamp processing.

[0071] Step 1.2: Parameter Setting. In adaptive synchronization based on gPTP and PPS, network quality, such as packet loss rate and link latency, can affect gPTP synchronization accuracy, leading to increasing time deviation. PPS, as a backup source independent of the network, can quickly take over synchronization when network anomalies occur.

[0072] In addition, the Kalman filter algorithm parameters can be initialized. Specifically, the time deviation can be set as the state variable and the state estimate can be initialized. The initial value of the state covariance P is set to 1, the process noise covariance Q is set to 0.01, and the measurement noise covariance R is set to 0.1.

[0073] Step 2: Data collection.

[0074] Step 2.1: gPTP data acquisition.

[0075] See Figure 3 The master clock device can send Sync messages to the slave clock device at a set period and record the sending timestamp. t 1. Receive Sync message from clock device and record the receiving timestamp t 2. Then send a Delay_Req message to the master clock device and record the sending timestamp t 3. After receiving the Delay_Req message, the master clock device records the receiving timestamp t 4. Then return the Delay_Resp message to the slave clock device, which carries t 4. After receiving the Delay_Resp message, the slave clock device can determine the link delay according to the following formula: .

[0076] Slave clock devices are based on t 1. t2 and the link delay, we can get the first time deviation corresponding to the gPTP message: .

[0077] Step 2.2: PPS data acquisition.

[0078] From the PPS signal processing hardware of the clock device to the rising edge of the PPS signal, the arrival timestamp of the PPS signal is recorded. t pps , then obtain the local clock time of the master clock device t local The second time deviation of the PPS signal is calculated by the following formula: .

[0079] Step 3: Kalman filter processing.

[0080] During the data collection phase, after obtaining the first time offset, the master clock device can determine whether the time offset is greater than or equal to the time offset threshold. If so, step 3 is executed, initiating Kalman filtering. If not, step 3 is omitted and the slave clock device is controlled for time synchronization according to the gPTP protocol. In this case, the time after synchronization of the slave clock device is equal to the sum of the time before synchronization and the first time offset. This embodiment uses step 3 as an example for illustration.

[0081] Kalman filter processing is divided into two steps: prediction and update. The details are as follows: Step 3.1: Prediction step.

[0082] The time deviation and state covariance of the gPTP message at the current moment can be predicted to obtain the time deviation prediction value and state covariance prediction value at the current moment. Among them, the time deviation prediction value at the current moment can be predicted based on the historical synchronization data of the gPTP protocol and can be expressed as The state covariance prediction value can be determined based on the state covariance and process noise covariance of the previous moment, which can be expressed as , is the state covariance at the previous moment, the initial value can be set to 1, Q is the process noise covariance, which can be set to 0.01.

[0083] Step 3.2: Update step.

[0084] When updating data, first, a time deviation measurement value is determined based on the first time deviation and the second time deviation. The time deviation measurement value can be expressed as: .

[0085] Secondly, the Kalman gain is determined based on the state covariance prediction value and the measurement noise covariance at the current moment. The Kalman gain can be expressed as: , is the state covariance prediction value at the current moment, and R is the measurement noise covariance.

[0086] Finally, the time deviation prediction value is updated according to the Kalman gain and the time deviation measurement value to obtain the third time deviation. The third time deviation can be expressed as: , is the time deviation prediction value at the current moment, is the time deviation measurement value at the current moment, is the Kalman gain at the current moment.

[0087] After obtaining the third time offset, the state covariance prediction value can also be updated to determine the state covariance prediction value at the next moment, and then the Kalman gain at the next moment is determined based on the state covariance prediction value at the next moment. The updated state covariance at the current moment can be expressed as: , is the updated state covariance at the current moment, is the Kalman gain at the current moment, is the state covariance prediction value at the current moment.

[0088] Step 4: Determine a time synchronization strategy according to the third time offset.

[0089] Taking the time synchronization strategy including PPS assisted mode, PPS mode and gPTP mode as an example, two thresholds can be set, namely a first threshold and a second threshold, where the second threshold is greater than the first threshold. Optionally, the first threshold can be 50ns and the second threshold can be 200ns.

[0090] When determining the time synchronization strategy based on the third time deviation, the relationship between the third time deviation and the first threshold and the second threshold can be determined. If the third time deviation is less than the first threshold, the time synchronization strategy is determined to be gPTP mode. If the third time deviation is greater than or equal to the first threshold and less than the second threshold, the time synchronization strategy is determined to be PPS-assisted mode. If the third time deviation is greater than or equal to the second threshold, the time synchronization strategy is determined to be PPS mode.

[0091] Step 5: Control the slave clock device to perform time synchronization.

[0092] When the time synchronization strategy is gPTP mode, the slave clock device can synchronize time according to the gPTP protocol. For example, according to the third time deviation Adjust the local clock phase , the frequency remains unchanged.

[0093] When the time synchronization strategy is PPS-assisted mode, the slave clock device maintains the gPTP protocol and combines the PPS signal for time synchronization. For example, The corrected time offset is calculated, and the local clock frequency and phase are adjusted according to the time offset.

[0094] When the time synchronization strategy is PSS mode, the slave clock device performs time synchronization based on the PPS signal. t pps Adjust the local clock phase For frequency, if t pps If the changes over several consecutive cycles are not significant, no adjustment is required. If the changes are significant, fine-tuning may be required.

[0095] Step 6: Recover judgment.

[0096] In PPS mode or PPS assisted mode, the gPTP protocol status and time deviation can be continuously monitored. When the time is less than the third threshold, the system can switch back to the gPTP mode. The third threshold may be less than or equal to the first threshold, for example, the third threshold may be 50 ns.

[0097] Figure 2 The illustrated embodiment dynamically integrates gPTP and PPS. gPTP primarily handles long-term clock frequency synchronization, maintaining microsecond-level stability, while PPS achieves nanosecond-level instantaneous phase synchronization through hardware pulse phase jumps. When network congestion or severe packet loss occurs, a Kalman filter algorithm monitors network status in real time to dynamically compensate for errors. Based on the algorithm's results, the system dynamically switches between gPTP mode, PPS-assisted mode, or PPS mode. Combining the advantages of PPS and gPTP, the system achieves adaptive, high-precision time synchronization, effectively addressing the issues of large network delay fluctuations, skip-second transmission, and precision degradation associated with traditional PTP. This ensures high-precision time synchronization in complex network environments, significantly improving the system's adaptability and reliability in these environments.

[0098] Figure 2 The embodiment shown can achieve at least the following technical effects: (1) Dual calibration mechanism: gPTP calibrates the clock frequency, compensating for long-term clock drift and ensuring stable clock operation over a long period of time. PPS precisely calibrates the clock phase, ensuring a high-precision pulse signal once per second. This achieves long-term frequency synchronization and instantaneous phase synchronization, breaking through the limitations of a single protocol or hardware model.

[0099] (2) Dynamic switching and adaptation: By real-time monitoring of network status parameters and synchronization error indicators, gPTP or PPS mode can be selected to reduce manual intervention, improve production efficiency, and achieve full-scene coverage.

[0100] (3) Anti-interference capability: PPS does not rely on the protocol stack. In the event of network disconnection or abnormality, clock synchronization is performed by adopting the PPS mode.

[0101] Figure 4 This is a schematic diagram of time deviation convergence between master and slave clock devices in an embodiment of the present application.

[0102] Figure 4 A possible synchronization scenario corresponding to the illustrated embodiment is as follows: Phase 1: In the 0-10s period, only gPTP mode is used. When the network is normal, the time deviation is stable at ±50ns. When congestion occurs, the deviation increases sharply to ±200ns.

[0103] Phase 2: In 10-20 seconds, Kalman filtering is enabled to suppress noise through prediction and update, and the deviation converges to ±30ns.

[0104] Phase 3: Within 20-30 seconds, the network continues to deteriorate, for example, the packet loss rate is greater than 5%, and the system switches to PPS-assisted mode, maintaining the deviation at ±80 ns.

[0105] Phase 4: In 30-40 seconds, gPTP is interrupted and the deviation slowly accumulates to ±150ns in PPS mode.

[0106] from Figure 4 It can be seen that by switching between different modes, adaptive high-precision time synchronization can be achieved, and the stability and reliability of time synchronization can be improved.

[0107] The actual synchronization effect of the time synchronization method provided in the embodiments of this application was tested. The test results show that under conditions of large network fluctuations, time synchronization based on PPS-assisted mode or PPS mode has smaller time deviation fluctuations between master and slave clock devices and higher synchronization accuracy than gPTP mode.

[0108] In an embodiment of the present application, when performing time synchronization, gPTP and PPS signals are combined for time synchronization. Specifically, the master clock device can send a gPTP message and a PPS signal to the slave clock device, and then obtain a first time deviation corresponding to the gPTP message and a second time deviation corresponding to the PSS signal. Based on these two time deviations, the slave clock device is controlled to perform time synchronization. Since the first time deviation can reflect the network status and the time synchronization accuracy based on the gPTP protocol, and the second time deviation can reflect the time synchronization accuracy based on the PPS signal, the slave clock device is controlled to perform time synchronization based on these two time deviations. According to the network status and time synchronization accuracy, the gPTP protocol or the PPS signal can be adaptively selected for time synchronization, thereby achieving high-precision time synchronization in different network environments, effectively improving the reliability and stability of time synchronization.

[0109] The foregoing description describes specific embodiments of the present application. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims can be performed in an order different from that described in the embodiments and still achieve the desired results. Furthermore, the processes depicted in the accompanying drawings do not necessarily require the specific order shown or the sequential order to achieve the desired results. In certain embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0110] Figure 5 This is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. Figure 5 At the hardware level, the electronic device includes a processor and, optionally, an internal bus, a network interface, and memory. The memory may include internal memory, such as high-speed random-access memory (RAM), or non-volatile memory, such as at least one disk drive. Of course, the electronic device may also include other hardware required for its services.

[0111] The processor, network interface, and memory can be interconnected via an internal bus, which can be an ISA (Industry Standard Architecture) bus, a PCI (Peripheral Component Interconnect) bus, or an EISA (Extended Industry Standard Architecture) bus. The bus can be divided into an address bus, a data bus, a control bus, and the like. For ease of representation, Figure 5Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or one type of bus.

[0112] The memory is used to store programs. Specifically, the program may include program code, which includes computer operating instructions. The memory may include internal memory and non-volatile memory, and provides instructions and data to the processor.

[0113] The processor reads the corresponding computer program from the non-volatile memory into the internal memory and then runs it, forming a time synchronization device at the logical level. The processor executes the program stored in the memory and is specifically used to perform the following operations: Send generalized precision time protocol gPTP messages and pulse-per-second (PPS) signals to slave clock devices; Obtain a first time offset and a second time offset, where the first time offset is determined according to a sending and receiving timestamp of the gPTP message, and the second time offset is determined according to an arrival timestamp of the PPS signal; The slave clock device is controlled to perform time synchronization according to the first time offset and the second time offset.

[0114] The above application Figure 5The methods performed by the time synchronization device disclosed in the illustrated embodiments can be applied to or implemented by a processor. The processor may be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method can be performed by hardware integrated logic circuits within the processor or by software instructions. The above processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The methods, steps, and logic block diagrams disclosed in this application can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in this application can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules within the decoding processor. The software module can be located in a storage medium well-known in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.

[0115] The electronic device may also perform Figure 1 Method, and realize the driver access device in Figure 1 The functions of the illustrated embodiments will not be described in detail in this application.

[0116] Of course, in addition to software implementation, the electronic device of this application does not exclude other implementation methods, such as logic devices or a combination of software and hardware, etc. That is to say, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0117] The present application also proposes a computer-readable storage medium storing one or more programs, wherein the one or more programs include instructions that, when executed by a portable electronic device including a plurality of application programs, enable the portable electronic device to execute Figure 1 The method of the embodiment shown is specifically used to perform the following operations: Send generalized precision time protocol gPTP messages and pulse-per-second (PPS) signals to slave clock devices; Obtain a first time offset and a second time offset, where the first time offset is determined according to a sending and receiving timestamp of the gPTP message, and the second time offset is determined according to an arrival timestamp of the PPS signal; The slave clock device is controlled to perform time synchronization according to the first time offset and the second time offset.

[0118] Figure 6 This is a schematic diagram of the structure of a time synchronization device 60 according to an embodiment of the present application. Figure 6 In a software implementation, the time synchronization device 60 may include: a sending module 61, an acquisition module 62 and a control module 63, wherein: The sending module 61 sends a generalized precision time protocol gPTP message and a pulse per second (PPS) signal to a slave clock device; An acquisition module 62 is configured to acquire a first time offset and a second time offset, wherein the first time offset is determined based on a sending and receiving timestamp of the gPTP message, and the second time offset is determined based on an arrival timestamp of the PPS signal; The control module 63 controls the slave clock device to perform time synchronization according to the first time offset and the second time offset.

[0119] The time synchronization device 60 provided by this application can also perform Figure 1 The method and the time synchronization device 60 are implemented in Figure 1 The functions of the illustrated embodiments will not be described in detail in this application.

[0120] The present application also proposes a computer program product, which includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to enable a computer to execute part or all of the steps in the above-mentioned time synchronization method embodiment.

[0121] In short, the above description is only a preferred embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

[0122] The systems, devices, modules, or units described in the above embodiments may be implemented by computer chips or entities, or by products having certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.

[0123] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic tape, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0124] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.

[0125] The various embodiments in this application are described in a progressive manner. Similar parts between the various embodiments can be referred to in conjunction with each other. Each embodiment focuses on the differences between the other embodiments. In particular, the system embodiment is generally similar to the method embodiment, so the description is relatively simple. For relevant parts, refer to the partial description of the method embodiment.

Claims

1. A time synchronization method, applied to a master clock device, comprising: Send generalized precision time protocol gPTP messages and pulse-per-second (PPS) signals to slave clock devices; Obtain a first time offset and a second time offset, where the first time offset is determined according to a sending and receiving timestamp of the gPTP message, and the second time offset is determined according to an arrival timestamp of the PPS signal; The slave clock device is controlled to perform time synchronization according to the first time offset and the second time offset.

2. The method as claimed in claim 1, wherein the first time deviation is equal to the difference between the time difference and the link delay, the time difference is the time difference between the receiving timestamp and the sending timestamp of the gPTP message, and the link delay is the link delay between the master clock device and the slave clock device.

3. The method of claim 1, wherein the second time offset is equal to a difference between an arrival timestamp of the PPS signal and a local clock time of the master clock device.

4. The method according to claim 1, wherein controlling the slave clock device to perform time synchronization according to the first time offset and the second time offset comprises: Determining whether the first time deviation is greater than or equal to a time deviation threshold; When the first time deviation is less than the time deviation threshold, controlling the slave clock device to perform time synchronization according to the first time deviation; and / or, When the first time deviation is greater than or equal to the time deviation threshold, the slave clock device is controlled to perform time synchronization according to the first time deviation and the second time deviation.

5. The method according to claim 4, wherein controlling the slave clock device to perform time synchronization according to the first time deviation comprises: The slave clock device is controlled to use the sum of the current time of the slave clock device and the first time deviation as the synchronized time.

6. The method according to claim 4, wherein controlling the slave clock device to perform time synchronization according to the first time offset and the second time offset comprises: determining a third time offset according to the first time offset and the second time offset; Determining a corresponding time synchronization strategy according to the size of the third time deviation; According to the time synchronization strategy, the slave clock device is controlled to perform time synchronization.

7. The method according to claim 6, wherein determining a third time offset according to the first time offset and the second time offset comprises: Predicting the time deviation of the gPTP message at the current moment to obtain a predicted time deviation value at the current moment; Determining a time deviation measurement value at a current moment according to the first time deviation and the second time deviation; The time deviation prediction value is adjusted according to the time deviation measurement value to obtain the third time deviation.

8. The method according to claim 7, wherein adjusting the time deviation prediction value according to the time deviation measurement value to obtain the third time deviation comprises: Determine the Kalman gain based on the state covariance prediction value and the measurement noise covariance at the current moment; The time deviation prediction value is adjusted according to the Kalman gain and the time deviation measurement value to obtain the third time deviation.

9. The method of claim 6, wherein the time synchronization strategy includes at least one of a PPS-assisted mode and a PPS mode, and a gPTP mode; and determining the corresponding time synchronization strategy according to the size of the third time offset comprises: When the third time deviation is less than the first threshold, determining that the time synchronization strategy is the gPTP mode; When the third time deviation is greater than or equal to the first threshold, the time synchronization strategy is determined to be the PPS-assisted mode or the PPS mode.

10. The method according to claim 9, wherein determining a corresponding time synchronization strategy according to the size of the third time offset further comprises: When the third time deviation is greater than or equal to the first threshold and less than a second threshold, determining that the time synchronization strategy is the PPS auxiliary mode; When the third time deviation is greater than or equal to the second threshold, the time synchronization strategy is determined to be the PPS mode.

11. The method according to claim 9 or 10, wherein controlling the slave clock device to perform time synchronization according to the time synchronization policy comprises at least one of the following: When the time synchronization strategy is the gPTP mode, the slave clock device is controlled to perform time synchronization according to the gPTP protocol, wherein: The local clock phase after synchronization of the slave clock device is equal to the sum of the clock phase before synchronization and the third time deviation, and the frequency remains unchanged; When the time synchronization strategy is the PPS assisted mode, controlling the slave clock device to perform time synchronization according to the gPTP protocol and the PPS signal, wherein the phase and frequency of the local clock of the synchronized slave clock device are determined according to the corrected time deviation, and the corrected time deviation is determined according to the first time deviation and the second time deviation; When the time synchronization strategy is the PPS mode, the slave clock device is controlled to perform time synchronization according to the PPS signal, wherein the local clock phase of the slave clock device after synchronization is equal to the sum of the local clock phase before synchronization and the second time deviation.

12. An electronic device comprising: processor; a memory for storing instructions executable by the processor; The processor is configured to execute the instructions to implement the method according to any one of claims 1 to 11.

13. A computer-readable storage medium, when instructions in the storage medium are executed by a processor of an electronic device, enables the electronic device to perform the method according to any one of claims 1 to 11.

14. A computer program product, comprising a non-transitory computer-readable storage medium storing a computer program, wherein the computer program is operable to cause a computer to execute part or all of the steps of the method according to any one of claims 1 to 11.