Time synchronization method based on precise time protocol and related system

By introducing multi-message sampling and K-means residual clustering optimization, the problems of insufficient PTP synchronization accuracy and stability are solved, achieving high-precision time synchronization, which is suitable for complex network environments such as industrial internet and power dispatch communication.

CN122052956APending Publication Date: 2026-05-15STATE GRID SHANGHAI MUNICIPAL ELECTRIC POWER CO
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610160981.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-02-04
Publication Date
2026-05-15

AI Technical Summary

Technical Problem

Existing Precision Time Protocols (PTPs) are affected by factors such as network topology complexity, uncertainties in forwarding delays of switching equipment, and fluctuations in network load during time synchronization, resulting in insufficient synchronization accuracy and stability, making it difficult to meet the high-precision requirements of industrial automation, power communication, and other fields.

Method used

By employing a multi-message sampling and normalized clustering analysis mechanism, and through K-means residual clustering optimization, combined with joint modeling and dynamic optimization of clock skew and link transmission delay, high accuracy and stability of the time synchronization system can be achieved.

Benefits of technology

It significantly improves synchronization accuracy and resistance to changes in network environment, making it suitable for application scenarios with complex link structures such as industrial internet and power dispatch communication, and enhancing the robustness and stability of the synchronization system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122052956A_ABST
    Figure CN122052956A_ABST
Patent Text Reader

Abstract

The invention belongs to the field of precise time synchronization, and discloses a precise time protocol-based time synchronization method and a related system, which adopt a timestamp calculation mechanism between a master node and a slave node in the traditional PTP and introduce a multi-message sampling and normalized clustering analysis mechanism. Through extraction, calculation and normalization of sending and receiving timestamps in a plurality of message sampling periods, time deviation fluctuation caused by network jitter, asynchronous delay, random message congestion and other factors can be effectively eliminated, so that clock synchronization is more stable and accurate. According to the method, on the basis of calculating the clock skew and the link transmission delay, K-means residual error clustering optimization is further introduced. By grouping and clustering the time offset or the link delay data, abnormal deviation data and network burst delay data can be automatically identified, so that the robustness of synchronization parameter estimation is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of precise time synchronization, specifically relating to time synchronization methods and related systems based on precise time protocols. Background Technology

[0002] Under the current clock synchronization technology framework, common time synchronization methods mainly include Network Time Protocol (NTP) and Precision Time Protocol (PTP). NTP is widely used in wide area network environments, but because it relies on software timestamps and non-deterministic network paths, its synchronization accuracy is usually only at the millisecond level. PTP, on the other hand, implements hardware timestamp marking at the physical layer or data link layer, which can improve the synchronization accuracy to the microsecond or even sub-microsecond level. Therefore, it is widely used in applications with extremely high time accuracy requirements, such as industrial automation, power communication, financial settlement, and aerospace.

[0003] Existing PTP time synchronization technology still has several shortcomings in practical engineering applications. First, the PTP time synchronization process is affected by factors such as network topology complexity, uncertainties in switching equipment forwarding delays, and asymmetry in message transmission paths, leading to random fluctuations in the time deviation calculation results, thus reducing synchronization accuracy. Second, traditional PTP typically uses a fixed-period sampling method and adjusts synchronization parameters based on single measurement results or moving averages, failing to fully consider the dynamic changes in message delays and making it difficult to maintain high-precision synchronization when network load fluctuates or communication paths are unstable.

[0004] Existing PTP systems mostly employ linear estimation models when calculating link round-trip time, assuming symmetrical uplink and downlink delays and compensating based on individual delay samples. This fails to effectively distinguish between occasional abnormal packet delays or jitter caused by network congestion, making synchronization results susceptible to sudden errors. Furthermore, in large-scale distributed systems, with numerous clock nodes and a large volume of packet sampling data, the lack of intelligent classification and aggregation mechanisms for synchronization deviation data makes it difficult to filter out data noise, impacting the final synchronization convergence speed and stability.

[0005] Traditional PTP algorithms lack a joint modeling and dynamic optimization mechanism for time offset and link delay. They often only correct the time offset while ignoring the systematic deviation caused by changes in link transmission delay. This deficiency is particularly evident in complex power communication networks, industrial control buses, or virtualized data center environments, making it difficult to meet the real-time requirements of precision control systems in terms of clock synchronization stability and accuracy. Summary of the Invention

[0006] The purpose of this invention is to overcome the problems of large synchronization error, poor stability and insufficient anti-interference ability in existing PTP time synchronization technology, and to provide a time synchronization method and related system based on a precise time protocol.

[0007] To achieve the above objectives, the present invention adopts the following technical solution: In a first aspect, the present invention provides a time synchronization method based on a precise time protocol, comprising the following steps: According to the preset sampling period, the first and second messages sent by the master clock node are received and parsed. The sending and receiving timestamps of the first and second messages are extracted. The clock deviation is calculated based on the sending and receiving timestamps of the first and second messages to obtain the time offset of the local slave clock relative to the master clock. Within the same or independently set period, the slave clock sends a third message to the master clock. After receiving the message, the master clock returns a fourth message. The sending and receiving times of the third and fourth messages are analyzed, the path delay is calculated, and the estimated link transmission delay is obtained. Obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock. Divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and select K residual data as the initial cluster centers, where K is the number of clusters specified by the user. Calculate the distance from the local slave clock's time offset relative to the master clock or the estimated link transmission delay to each initial cluster center. Assign the local slave clock's time offset relative to the master clock or the estimated link transmission delay to the set containing each initial cluster center to form a residual cluster. Update the center of each cluster based on the points in the residual cluster. Repeat the assignment and update steps until the residual cluster no longer changes, or the objective function satisfies the condition.

[0008] A further improvement of this invention lies in the following method: Based on a preset sampling period, the first and second messages sent by the master clock node are received and parsed; the sending and receiving timestamps of the first and second messages are extracted; and the clock offset is calculated based on the sending and receiving timestamps of the first and second messages to obtain the time offset of the local slave clock relative to the master clock. Generate an initial clock frequency signal and generate a local initial PPS signal based on the initial clock frequency signal; The PPS signal of the master clock is acquired, and the PPS signal generated by the master clock is compared with the local initial PPS signal to obtain the fundamental frequency signal and generate a local calibration PPS signal. The basic clock frequency signal is divided to obtain the clock frequency signal; Using the clock frequency signal and the locally calibrated PPS signal, the clock synchronization message timestamp is generated. The clock synchronization message timestamp is then parsed to generate the local time. The local time is compared with the local initial PPS signal to obtain the time offset of the local slave clock relative to the master clock.

[0009] A further improvement of this invention lies in the following method for obtaining the clock frequency signal by performing frequency division processing on the basic clock frequency signal: The system counts the base clock frequency signal, calculates the local clock running time, compares the local clock running time with the master clock running time, and adjusts the base clock frequency signal based on the comparison result.

[0010] in, The base clock frequency signal before adjustment. The adjusted base clock frequency signal, Master clock running time This is the running time of the local clock.

[0011] A further improvement of this invention is that when the time offset or link transmission delay estimate of the local slave clock relative to the master clock is divided into K groups, the values ​​of the K groups are selected using the elbow rule.

[0012] A further improvement of this invention lies in the following method for selecting the K sets of values:

[0013] in, Given the number of clusters The total distortion level during time, where n is the total number of data points. It is a single data point. It is from the cluster center The set constituted The Euclidean distance from the data point to the cluster center.

[0014] A further improvement of this invention is that, given a number of clusters Total distortion during time The point at which the rate of decline begins to slow is the optimal number of clusters, k.

[0015] A further improvement of this invention lies in the following method for calculating the distance from the local slave clock to each initial cluster center, based on the time offset or link transmission delay estimate relative to the master clock:

[0016] in, This refers to the time offset of the local slave clock relative to the master clock or the estimated link transmission delay. with the initial cluster centers The Euclidean distance between them This refers to the time offset of the local slave clock relative to the master clock or the estimated link transmission delay. In the The values ​​taken on each feature dimension as initial cluster centers In the The values ​​can be taken in each feature dimension.

[0017] Secondly, the present invention provides a time synchronization system based on a precise time protocol, comprising: The first error acquisition module receives and parses the first and second messages sent by the master clock node according to the preset sampling period, extracts the sending timestamp and receiving timestamp of the first and second messages, calculates the clock deviation based on the sending timestamp and receiving timestamp of the first and second messages, and obtains the time offset of the local slave clock relative to the master clock. The second error acquisition module is used to send a third message from the slave clock to the master clock within the same or independently set period. After the master clock receives the message, it returns a fourth message. The module parses the sending and receiving times of the third and fourth messages, calculates the path delay, and obtains the estimated link transmission delay. The time synchronization module is used to obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock; divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and select K residual data as initial cluster centers, where K is the number of clusters specified by the user; calculate the distance of the time offset or link transmission delay estimate of the local slave clock relative to the master clock to each initial cluster center, and assign the local slave clock time offset or link transmission delay estimate to the nearest set of each initial cluster center to form a residual cluster; update the center of each cluster based on each point in the residual cluster; repeat the assignment and update steps until the residual cluster no longer changes, or the objective function satisfies the condition. Delay request messages are sent to the master clock at regular intervals, and the message sending and receiving times of the delay request messages are obtained. The delay error is obtained based on the message sending and receiving times of the delay request messages. The clock is continuously corrected based on the relative time error and the delay error to perform time synchronization based on the precise time protocol.

[0018] Thirdly, the present invention provides an electronic device, including a memory and a processor, wherein the memory stores a computer program, and the processor executes the computer program to implement the steps of a time synchronization method based on a precise time protocol.

[0019] Fourthly, the present invention provides a storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of a time synchronization method based on a precise time protocol.

[0020] Compared with the prior art, the present invention has the following beneficial effects: This invention employs the timestamp calculation mechanism between master and slave nodes in traditional PTP and introduces a multi-message sampling and normalized clustering analysis mechanism. By extracting, calculating, and normalizing the sending and receiving timestamps within multiple message sampling periods, it effectively eliminates time deviation fluctuations caused by factors such as network jitter, asynchronous delay, and random message congestion, making clock synchronization more stable and accurate. Based on the calculation of clock deviation and link transmission delay, this invention further introduces K-means residual clustering optimization. By grouping and clustering time offset or link delay data, it can automatically identify abnormal deviation data and sudden network delay data, thereby improving the robustness of synchronization parameter estimation. Traditional PTP synchronization typically uses a single average or weighted average method, which is easily affected by occasional abnormal delays. This method, however, dynamically adjusts synchronization parameters through residual clustering, significantly improving synchronization accuracy. This invention employs a dual-channel feedback and dynamic correction mechanism. In addition to calculating the time offset between the slave clock and the master clock, the link round-trip delay is also calculated independently or within the same period. This enables the synchronization system to simultaneously correct clock deviation and path delay, thereby improving the system's ability to withstand changes in the network environment. It is particularly suitable for application scenarios with complex link structures, such as the Industrial Internet, power dispatch communication, and smart substations. Attached Figure Description

[0021] Figure 1 This is a flowchart of the present invention; Figure 2 This is a system diagram of the present invention; Figure 3 This is a system diagram for an embodiment. Detailed Implementation

[0022] To further understand the content of this invention, the invention will be described in detail below with reference to the accompanying drawings and specific embodiments. It should be understood that the embodiments are merely illustrative and not limiting of the invention.

[0023] Example 1: See Figure 1 The time synchronization method based on the precise time protocol includes the following steps: S1, according to the preset sampling period, receives and parses the first and second messages sent by the master clock node, extracts the sending timestamp and receiving timestamp of the first and second messages, calculates the clock deviation based on the sending timestamp and receiving timestamp of the first and second messages, and obtains the time offset of the local slave clock relative to the master clock.

[0024] S2, within the same or independently set period, sends a third message from the slave clock to the master clock. After receiving the message, the master clock returns a fourth message. The sending and receiving times of the third and fourth messages are analyzed, the path delay is calculated, and the link transmission delay estimate is obtained.

[0025] S3, obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock.

[0026] S4 divides the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and selects K residual data as the initial cluster centers, where K is the number of clusters specified by the user.

[0027] S5, calculate the distance from the local slave clock's time offset relative to the master clock or the estimated link transmission delay to each initial cluster center, and assign the local slave clock's time offset relative to the master clock or the estimated link transmission delay to the set where each initial cluster center is located to form a residual cluster; update the center of each cluster based on each point in the residual cluster.

[0028] S6, repeat the assignment and update steps until the residual clusters no longer change, or the objective function satisfies the condition.

[0029] Example 2: Time synchronization systems based on precise time protocols include: The first error acquisition module receives and parses the first and second messages sent by the master clock node according to the preset sampling period, extracts the sending timestamp and receiving timestamp of the first and second messages, calculates the clock deviation based on the sending timestamp and receiving timestamp of the first and second messages, and obtains the time offset of the local slave clock relative to the master clock. The second error acquisition module is used to send a third message from the slave clock to the master clock within the same or independently set period. After the master clock receives the message, it returns a fourth message. The module parses the sending and receiving times of the third and fourth messages, calculates the path delay, and obtains the estimated link transmission delay. The time synchronization module is used to obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock; divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and select K residual data as initial cluster centers, where K is the number of clusters specified by the user; calculate the distance of the time offset or link transmission delay estimate of the local slave clock relative to the master clock to each initial cluster center, and assign the local slave clock time offset or link transmission delay estimate to the nearest set of each initial cluster center to form a residual cluster; update the center of each cluster based on each point in the residual cluster; repeat the assignment and update steps until the residual cluster no longer changes, or the objective function satisfies the condition. Delay request messages are sent to the master clock at regular intervals, and the message sending and receiving times of the delay request messages are obtained. The delay error is obtained based on the message sending and receiving times of the delay request messages. The clock is continuously corrected based on the relative time error and the delay error to perform time synchronization based on the precise time protocol.

[0030] Example 3: This embodiment is divided into two stages: the offset measurement stage and the delay measurement stage. The offset measurement stage refers to measuring the time offset between the master clock and the slave clock and eliminating these offsets on the slave clock, while the delay measurement stage is used to determine the delay of message transmission between the master clock and the slave clock.

[0031] Offset Measurement Phase: At set intervals, the master clock sends a synchronization message to the slave clock and records the time t1 when the message is sent. When the slave clock receives the message, it immediately records the current time t2. Wherein:

[0032]

[0033]

[0034] ms_delay is the difference between t1 and t2, and ms_delay is the network delay of the clock synchronization message between the master clock and the slave clock. It is the relative error between the master clock time and the slave clock time, i.e., the time relative error.

[0035] Delay Measurement Phase: When the slave clock needs to measure network transmission delay, it sends a delay request message to the master clock, recording the current time t3 at the same time the message is sent. The master clock immediately sets a time stamp t4 upon receiving the delay request message. Wherein:

[0036]

[0037] This assumes that network latency is equal, meaning the delay in sending and receiving messages is the same.

[0038]

[0039] It can be confirmed that:

[0040] t4 is the difference between t4 and t3, and sm_delay is the network delay of the delay request message between the master and slave clocks. As the synchronization process proceeds, the system utilizes the calculated... The master clock is corrected, and the corrected slave clock time is used for the next round of time synchronization. Through multiple synchronizations, the time deviation between the master clock and the slave clock is gradually reduced, improving the time synchronization accuracy.

[0041] The process of using high-precision time synchronization technology based on the Precision Time Protocol (PTP) between edge aggregation control units includes the following steps: Step 1: The edge aggregation control unit generates an initial clock frequency signal and generates a local initial PPS signal based on the initial clock frequency signal.

[0042] Step 2: The edge aggregation control unit obtains the PPS signal of the master clock from the slave clock, compares the PPS signal generated by the master clock with the PPS signal generated by the local clock, obtains the standard frequency signal, and generates a local calibration PPS signal.

[0043] Step 3: Each edge aggregation control unit performs multiple frequency divisions on the standard clock frequency signal to obtain a high-precision clock frequency signal.

[0044] Step 4: Using the obtained high-precision clock frequency signal and the locally calibrated PPS signal, generate a PTP clock synchronization message timestamp, parse the PTP clock synchronization message timestamp, and generate the local time.

[0045] In step 3, the high-precision clock frequency signal is counted, and the local clock running time is calculated. The local clock running time is compared with the master clock running time, and the high-precision clock frequency signal is adjusted according to the comparison result.

[0046] in, The high-precision clock frequency signal before adjustment. This is the adjusted high-precision clock frequency signal. Master clock running time This is the running time of the local clock.

[0047] High-precision time synchronization technology based on the Precise Time Protocol (PTP) is used between edge aggregation control units to basically keep the clocks of the slave aggregation control units synchronized with the clocks of the master aggregation control units. However, errors will inevitably occur between the slave aggregation control units due to factors such as time delay. To eliminate these errors and further improve the time synchronization accuracy, the K-means clustering algorithm can be used to process the residuals of each slave aggregation control unit to reduce the time synchronization error.

[0048] After synchronization using high-precision time synchronization technology based on the Precision Time Protocol (PTP), the remaining error between each slave clock and the master clock is called the residual. The virtual power plant's aggregation control units use the K-means clustering algorithm to determine a unified time base. The basic idea is to cluster an n-dimensional vector of residual data, ultimately dividing the residual data set D into K clusters for further processing. The specific steps are as follows: Step 1: First, collect the residual data of the local clock of each aggregation control unit.

[0049] Step 2: Preprocess the residual data of each aggregation control unit, that is, normalize the residual data of each aggregation control unit to ensure that different error scales will not affect the clustering results based on the K-means algorithm.

[0050] Step 3: Set the initial K value, which means dividing the residual dataset of the aggregation control unit into K groups and selecting K residual data as the initial cluster centers, where K is the number of clusters specified by the user. The determination of its value should fully consider the clock correction and the synchronization accuracy of the system.

[0051] Step 4: Calculate the distance from the residual data points of the aggregation control unit to each initial cluster center, and assign the data points to the nearest set of each initial cluster center to form a residual cluster.

[0052] Step 5: Update the center of each cluster based on the points in the residual clusters.

[0053] Step 6: Repeat the assignment and update steps until the residual clusters no longer change, or the objective function satisfies the conditions.

[0054] Step 7: By dividing the clock into different residual clusters, a customized correction strategy can be developed for each residual cluster, thereby making clock adjustments more accurate and improving the overall time synchronization accuracy.

[0055] The K-means clustering algorithm typically uses Euclidean distance as a similarity measure and the sum of squared error (SSE) as an objective function to measure clustering quality. By minimizing the objective function, data points are divided into K residual clusters according to their distance from the cluster center.

[0056] Euclidean distance between residual data points:

[0057] In step b-3, determining the optimal K value (i.e., the number of residual clusters) is a crucial step because it directly affects the clustering results. Here, the Elbow Method is used to determine the optimal K value, and a graph is plotted showing the relationship between the cost (usually the sum of squares of the total intracluster distances) and the K value for different K values.

[0058] Its mathematical model is as follows:

[0059] in Given the number of clusters The total distortion level during time, where n is the total number of data points. It is a single data point. It is from the cluster center The set constituted The Euclidean distance from the data point to the cluster center.

[0060] For k=1, 2, 3... ( (This is the preset maximum number of clusters), calculation And draw. The graph shows the change with k. Observe the "elbow" in the graph, i.e. The point at which the rate of decline begins to slow. This point is generally considered to be the optimal number of clusters, k.

[0061] This embodiment uses the K-means algorithm to perform cluster analysis on the residual data from multiple aggregation control units. By dividing the clocks into different residual clusters, a customized correction strategy can be formulated for each residual cluster. This is more effective than adjusting all clocks in the same way and can meet the requirements for higher precision time synchronization.

[0062] The PTP protocol can improve the synchronization accuracy of the NTP protocol from milliseconds to nanoseconds. Its improved communication model and BMC algorithm also reduce manual intervention and improve the automation level of the time synchronization network. Compared with satellite time synchronization, PTP is low-cost and high-precision, making it suitable for the time synchronization requirements of third-party flexible resources participating in the small time scale control of the power grid. Therefore, the PTP protocol can be used as an effective means of time synchronization between distributed resources and the control master station, or as a backup method for satellite time synchronization.

[0063] Example 4: See Figure 3 The present invention also provides an electronic device 100 based on a time synchronization method of a precise time protocol; the electronic device 100 includes a memory 101, at least one processor 102, a computer program 103 stored in the memory 101 and executable on the at least one processor 102, and at least one communication bus 104.

[0064] The memory 101 can be used to store the computer program 103. The processor 102 implements the steps of the time synchronization method based on the precise time protocol described in Embodiment 1 by running or executing the computer program stored in the memory 101 and calling the data stored in the memory 101. The memory 101 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device 100 (such as audio data), etc. In addition, the memory 101 may include non-volatile memory, such as hard disk, memory, plug-in hard disk, smart media card (SMC), secure digital (SD) card, flash card, at least one disk storage device, flash memory device, or other non-volatile solid-state storage device.

[0065] The at least one processor 102 may be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The processor 102 may be a microprocessor or any conventional processor. The processor 102 is the control center of the electronic device 100, connecting various parts of the electronic device 100 via various interfaces and lines.

[0066] The memory 101 in the electronic device 100 stores multiple instructions to implement a time synchronization method based on a precise time protocol, and the processor 102 can execute the multiple instructions to achieve: According to the preset sampling period, the first and second messages sent by the master clock node are received and parsed. The sending and receiving timestamps of the first and second messages are extracted. The clock deviation is calculated based on the sending and receiving timestamps of the first and second messages to obtain the time offset of the local slave clock relative to the master clock. Within the same or independently set period, the slave clock sends a third message to the master clock. After receiving the message, the master clock returns a fourth message. The sending and receiving times of the third and fourth messages are analyzed, the path delay is calculated, and the estimated link transmission delay is obtained. Obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock. Divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and select K residual data as the initial cluster centers, where K is the number of clusters specified by the user. Calculate the distance from the local slave clock's time offset relative to the master clock or the estimated link transmission delay to each initial cluster center. Assign the local slave clock's time offset relative to the master clock or the estimated link transmission delay to the set containing each initial cluster center to form a residual cluster. Update the center of each cluster based on the points in the residual cluster. Repeat the assignment and update steps until the residual cluster no longer changes, or the objective function satisfies the condition.

[0067] Example 5 If the modules / units integrated in the electronic device 100 are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, a recording medium, a USB flash drive, a portable hard drive, a magnetic disk, an optical disk, a computer memory, and a read-only memory (ROM).

[0068] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0069] This invention is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart illustrations and / or block diagrams. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0070] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0071] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0072] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and not to limit it. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that modifications or equivalent substitutions can still be made to the specific implementation of the present invention. Any modifications or equivalent substitutions that do not depart from the spirit and scope of the present invention should be covered within the scope of protection of the claims of the present invention.

Claims

1. A time synchronization method based on a precise time protocol, characterized in that, Includes the following steps: According to the preset sampling period, the first and second messages sent by the master clock node are received and parsed. The sending and receiving timestamps of the first and second messages are extracted. The clock deviation is calculated based on the sending and receiving timestamps of the first and second messages to obtain the time offset of the local slave clock relative to the master clock. Within the same or independently set period, the slave clock sends a third message to the master clock. After receiving the message, the master clock returns a fourth message. The sending and receiving times of the third and fourth messages are analyzed, the path delay is calculated, and the estimated link transmission delay is obtained. Obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock. Divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, and select K residual data as the initial cluster centers, where K is the number of clusters specified by the user. Calculate the distance from the local slave clock's time offset relative to the master clock or the estimated link transmission delay to each initial cluster center. Assign the local slave clock's time offset relative to the master clock or the estimated link transmission delay to the set containing each initial cluster center to form a residual cluster. Update the center of each cluster based on the points in the residual cluster. Repeat the assignment and update steps until the residual cluster no longer changes, or the objective function satisfies the condition.

2. The time synchronization method based on a precise time protocol according to claim 1, characterized in that, According to the preset sampling period, the first and second messages sent by the master clock node are received and parsed. The sending and receiving timestamps of the first and second messages are extracted. The clock offset is calculated based on the sending and receiving timestamps of the first and second messages. The specific method for obtaining the time offset of the local slave clock relative to the master clock is as follows: Generate an initial clock frequency signal and generate a local initial PPS signal based on the initial clock frequency signal; The PPS signal of the master clock is acquired, and the PPS signal generated by the master clock is compared with the local initial PPS signal to obtain the fundamental frequency signal and generate a local calibration PPS signal. The basic clock frequency signal is divided to obtain the clock frequency signal; Using the clock frequency signal and the locally calibrated PPS signal, the clock synchronization message timestamp is generated. The clock synchronization message timestamp is then parsed to generate the local time. The local time is compared with the local initial PPS signal to obtain the time offset of the local slave clock relative to the master clock.

3. The time synchronization method based on a precise time protocol according to claim 2, characterized in that, The specific method for obtaining the clock frequency signal by dividing the fundamental clock frequency signal is as follows: The system counts the base clock frequency signal, calculates the local clock running time, compares the local clock running time with the master clock running time, and adjusts the base clock frequency signal based on the comparison result. in, The base clock frequency signal before adjustment. The adjusted base clock frequency signal, Master clock running time This is the running time of the local clock.

4. The time synchronization method based on a precise time protocol according to claim 1, characterized in that, When the time offset or link transmission delay estimate of the local slave clock relative to the master clock is divided into K groups, the values ​​of the K groups are selected using the elbow rule.

5. The time synchronization method based on a precise time protocol according to claim 4, characterized in that, The method for selecting K sets of values ​​is as follows: in, Given the number of clusters The total distortion level during time, where n is the total number of data points. It is a single data point. It is from the cluster center The set constituted The Euclidean distance from the data point to the cluster center.

6. The time synchronization method based on a precise time protocol according to claim 5, characterized in that, Given number of clusters Total distortion during time The point at which the rate of decline begins to slow is the optimal number of clusters, k.

7. The time synchronization method based on a precise time protocol according to claim 1, characterized in that, The specific method for calculating the distance from the local slave clock's time offset relative to the master clock, or the estimated link transmission delay, to each initial cluster center is as follows: in, This refers to the time offset of the local slave clock relative to the master clock or the estimated link transmission delay. with the initial cluster centers The Euclidean distance between them This refers to the time offset of the local slave clock relative to the master clock or the estimated link transmission delay. In the The values ​​taken on each feature dimension Initial cluster centers In the The values ​​can be taken in each feature dimension.

8. A time synchronization system based on a precise time protocol, characterized in that, include: The first error acquisition module receives and parses the first and second messages sent by the master clock node according to the preset sampling period, extracts the sending timestamp and receiving timestamp of the first and second messages, calculates the clock deviation based on the sending timestamp and receiving timestamp of the first and second messages, and obtains the time offset of the local slave clock relative to the master clock. The second error acquisition module is used to send a third message from the slave clock to the master clock within the same or independently set period. After the master clock receives the message, it returns a fourth message. The module parses the sending and receiving times of the third and fourth messages, calculates the path delay, and obtains the estimated link transmission delay. The time synchronization module is used to obtain the time offset or link transmission delay estimate of the local slave clock relative to the master clock, and normalize the time offset or link transmission delay estimate of the local slave clock relative to the master clock; divide the time offset or link transmission delay estimate of the local slave clock relative to the master clock into K groups, select K residual data as initial cluster centers, where K is the number of clusters specified by the user; calculate the distance of the time offset or link transmission delay estimate of the local slave clock relative to the master clock to each initial cluster center, and assign the time offset or link transmission delay estimate of the local slave clock relative to the master clock to the nearest set of each initial cluster center to form a residual cluster; update the center of each cluster according to each point in the residual cluster; repeat the assignment and update steps until the residual cluster no longer changes or the objective function satisfies the condition; send delay request messages to the master clock at intervals, and obtain the message sending time and message receiving time of the delay request message, and obtain the delay error according to the message sending time and message receiving time of the delay request message; The clock is continuously corrected based on relative time error and delay error to perform time synchronization based on a precise time protocol.

9. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the time synchronization method based on the precise time protocol as described in any one of claims 1 to 7.

10. A storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the time synchronization method based on the precise time protocol as described in any one of claims 1 to 7.