Time synchronization method, electronic equipment and computer storage medium

The time deviation is filtered through the variable step Kalman filtering method, and the Kalman filter step size is dynamically adjusted, which solves the clock jump problem caused by the time synchronization deviation in the gPTP protocol stack, and improves the stability and accuracy of time synchronization.

CN119094072APending Publication Date: 2024-12-06HOZON NEW ENERGY AUTOMOBILE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411103605.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-08-12
Publication Date
2024-12-06

AI Technical Summary

Technical Problem

In the gPTP protocol stack, in the direct synchronization time scheme, time synchronization deviations caused by network delays and hardware failures may cause clock jumps and failures.

Method used

The variable step length Kalman filtering method is used to dynamically adjust the step length of the Kalman filter to filter the time deviation and improve the accuracy of time estimation and the stability of synchronization.

Benefits of technology

It effectively smooths the fluctuations of time deviation, avoids clock jumps, improves the continuity and stability of time synchronization, and ensures the reliability of the time control system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119094072A_ABST
    Figure CN119094072A_ABST
Patent Text Reader

Abstract

The invention relates to a time synchronization method, electronic equipment and a computer storage medium, and the method comprises the steps: obtaining a target message and local time, and the local time comprises a timestamp recorded when the target message is obtained; obtaining a calculated clock skew according to the timestamp in the target message and the local time; and performing variable step Kalman filtering according to the calculated clock skew and the local time to obtain estimated clock skew and estimated time. According to the technical scheme provided by the invention, the time deviation is filtered by using the variable step size Kalman filtering method, and the step size of the Kalman filter is dynamically adjusted, so that the accuracy of time estimation and the stability of time synchronization are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application belongs to the field of computer processing technology, and in particular, relates to a time synchronization method, an electronic device and a computer storage medium. Background Art

[0002] gPTP (Generalized Precision Time Protocol) is a protocol for precise time synchronization between network devices. It is usually used in application scenarios that require high-precision time synchronization, such as industrial automation, telecommunications infrastructure, and real-time control systems. After the gPTP protocol stack enters the "synchronized" state, the slave device uses the timestamp of the master clock to update its local time. However, in the direct time synchronization scheme, if there is an error in the underlying network or hardware, it may cause deviations in time synchronization. These deviations can be caused by changes in network delays, hardware failures, or other unforeseen factors. If the deviation is large enough, the time of the slave clock will suddenly jump, causing the time control system to fail.

[0003] The preceding description is intended to provide general background information and does not necessarily constitute prior art. Summary of the invention

[0004] In response to the above technical problems, the present application provides a time synchronization method, an electronic device and a computer storage medium, which use a variable step size Kalman filter method to filter the time deviation and dynamically adjust the step size of the Kalman filter to improve the accuracy of time estimation and the stability of time synchronization.

[0005] The present application provides a time synchronization method, including:

[0006] Obtaining a target message and local time, wherein the local time includes a timestamp recorded when the target message is obtained;

[0007] Obtaining a calculated clock deviation based on the timestamp in the target message and the local time;

[0008] A variable-step Kalman filter is performed according to the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time.

[0009] In one implementation, the target message includes at least one of a SYNC message, a SYNC_FOLLOWUP message, a PDELAY_RESP message, and a PDELAY_RESP_FOLLOWUP message.

[0010] In one implementation, the calculating the clock deviation according to the timestamp in the target message and the local time includes:

[0011] The calculated clock deviation is obtained according to a first timestamp, a second timestamp in the PDELAY_RESP message, a third timestamp in the PDELAY_RESP_FOLLOWUP message, and a fourth timestamp; wherein the first timestamp is the local time when the PDELAY_REQ message is sent, and the fourth timestamp is the local time when the PDELAY_RESP message is obtained.

[0012] In one implementation, the calculated clock deviation is obtained according to the following formula:

[0013]

[0014] Wherein, offset is the calculated clock deviation, t1 is the first timestamp of sending the PDELAY_REQ message; t2 is the second timestamp in the PDELAY_RESP message; t3 is the third timestamp in the PDELAY_RESP_FOLLOWUP message; t4 is the fourth timestamp when obtaining the PDELAY_RESP message.

[0015] In one embodiment, the calculating the clock deviation according to the timestamp in the target message and the local time further includes:

[0016] The calculated clock deviation is obtained according to the difference between the fifth timestamp and the sixth timestamp in the SYNC_FOLLOWUP message, where the fifth timestamp is the local time when the SYNC message is obtained.

[0017] In one implementation, performing a variable step size Kalman filter according to the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time includes:

[0018] constructing a state vector based on the local time and the calculated clock deviation;

[0019] Constructing a state transfer matrix according to the acquisition period of the target message;

[0020] Kalman filtering is performed according to the state vector and the state transfer matrix to obtain the estimated clock deviation and the estimated time.

[0021] In one embodiment, the method further comprises:

[0022] The Kalman filter frequency and the Kalman gain are dynamically adjusted according to the acquisition period of the target message.

[0023] In one embodiment, the method further comprises:

[0024] Real-time monitoring of network status;

[0025] The target message acquisition period is adjusted according to the network status.

[0026] The present application also provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above method when executing the computer program.

[0027] The present application also provides a computer storage medium, wherein the computer storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.

[0028] The time synchronization method, electronic device and computer storage medium provided by the present application include: obtaining a target message and a local time, the local time including a timestamp recorded when the target message is obtained; obtaining a calculated clock deviation according to the timestamp in the target message and the local time; performing a variable step-size Kalman filter according to the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time. The technical solution of the present application uses a variable step-size Kalman filter method to filter the time deviation and dynamically adjust the step size of the Kalman filter to improve the accuracy of time estimation and the stability of time synchronization. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a flowchart of the time synchronization method provided in an embodiment of the present application.

[0030] Figure 2 It is a specific flow chart of the time synchronization method provided in the embodiment of the present application.

[0031] Figure 3 It is a data timing diagram of the time synchronization method provided in an embodiment of the present application.

[0032] Figure 4 It is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0034] It should be noted that, in this article, the terms "include", "comprises" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also includes other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, an element defined by the sentence "includes a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element. In addition, components, features, and elements with the same name in different embodiments of the present application may have the same meaning or different meanings, and their specific meanings need to be determined by their explanation in the specific embodiment or further combined with the context of the specific embodiment.

[0035] It should be understood that, although the terms first, second, third, etc. may be used to describe various information in this article, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of this article, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein can be interpreted as "at the time of..." or "when..." or "in response to determination". Furthermore, as used in this article, the singular forms "one", "one" and "the" are intended to also include plural forms, unless there is an opposite indication in the context. It should be further understood that the terms "comprising", "including" indicate the presence of the described features, steps, operations, elements, parts, projects, kinds, and / or groups, but do not exclude the presence, occurrence or addition of one or more other features, steps, operations, elements, parts, projects, kinds, and / or groups. The terms "or" and "and / or" used herein are interpreted as inclusive, or mean any one or any combination. Thus, “A, B, or C” or “A, B and / or C” means “any of the following: A; B; C; A and B; A and C; B and C; A, B, and C.” An exception to this definition will occur only when a combination of elements, functions, steps, or operations are inherently mutually exclusive in some manner.

[0036] It should be understood that, although the various steps in the flowchart in the embodiment of the present application are displayed in sequence according to the indication of the arrows, these steps are not necessarily performed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and it can be performed in other orders. Moreover, at least a portion of the steps in the figure may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily performed at the same time, but can be performed at different times, and their execution order is not necessarily performed in sequence, but can be performed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0037] It should be noted that in this article, step codes such as S1 and S2 are used for the purpose of expressing the corresponding content more clearly and concisely, and do not constitute a substantial limitation on the order. When implementing the step, those skilled in the art may execute S2 first and then S1, etc., but these should all be within the scope of protection of this application.

[0038] It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0039] In the subsequent description, the suffixes such as "module", "component" or "unit" used to represent elements are only used to facilitate the description of the present application, and have no specific meanings. Therefore, "module", "component" or "unit" can be used in a mixed manner.

[0040] Figure 1 is a flow chart of the time synchronization method provided in the embodiment of the present application, such as Figure 1 As shown, the time synchronization method provided in the embodiment of the present application may include the following steps:

[0041] Step S1: Obtain a target message and local time, where the local time includes a timestamp recorded when the target message is obtained.

[0042] Step S2: Calculate the clock deviation based on the timestamp in the target message and the local time.

[0043] Step S3: Perform variable-step Kalman filtering based on the calculated clock deviation and local time to obtain an estimated clock deviation and an estimated time.

[0044] In the embodiment of the present application, by accurately recording the timestamp, calculating the clock deviation, and then using the variable step size Kalman filter technology to smooth the deviation estimation, the performance of the time synchronization system can be effectively improved. The filtering process smoothes the fluctuation of the time deviation, avoids the clock jump caused by sudden changes in network delay, and improves the continuity and stability of time synchronization.

[0045] Please refer to Figure 2 , the time synchronization method of the embodiment of the present application can be applied to electronic devices. The electronic device may include a network layer (Physical Layer, PHY), a network protocol stack (gPTP protocol stack), a slave clock (PTP clock) and a Kalman filter. Among them, the network layer refers to the first layer in the OSI (Open Systems Interconnection) model, that is, the physical layer. The network protocol stack refers to a collection of a series of software modules used to implement protocols at different levels in network communication. The gPTP protocol stack is a collection of software modules that specifically implement the gPTP protocol in a network protocol stack. They are responsible for processing network communications, timestamp generation and processing, time deviation calculation and other functions, so that nodes in the network can achieve time synchronization. In the gPTP time synchronization network, relative to the master clock (Master), other nodes that need to synchronize time with the master clock are called slave clocks. The slave clock will periodically request time information from the master clock and adjust its own time according to the information received.

[0046] It should be noted that the network layer periodically receives the target message sent by the master clock. The target message is used to synchronize the first time of the slave clock, and the first time is the local time recorded when the slave clock receives the target message. The target message can be an 802.1AS message. Among them, 802.1AS refers to the IEEE 802.1AS standard, which is a standard formulated by IEEE for the application of PTP (Precision Time Protocol) in local area networks and metropolitan area networks, aiming to provide high-precision time synchronization capabilities.

[0047] In some embodiments, the target message includes at least one of a SYNC message, a SYNC_FOLLOWUP message, a PDELAY_RESP message, and a PDELAY_RESP_FOLLOWUP message.

[0048] It should be noted that the SYNC message is sent by the master clock to initialize time synchronization and contains the precise timestamp of the message sent by the master clock. The SYNC_FOLLOWUP message follows the SYNC message and provides more precise send timestamp information to correct for possible network delay effects. The PDELAY_RESP message is a response to the PDELAY_REQ message and is used to measure network delay and contains the timestamp of the master clock receiving the PDELAY_REQ. The PDELAY_REQ message is sent by the slave clock to the master clock. The PDELAY_RESP_FOLLOWUP message follows the PDELAY_RESP message and provides more precise receive timestamp information for more accurate calculation of network delay.

[0049] In some embodiments, calculating the clock deviation according to the target message and the local time includes:

[0050] The clock deviation is calculated according to the first timestamp, the second timestamp in the PDELAY_RESP message, the third timestamp in the PDELAY_RESP_FOLLOWUP message, and the fourth timestamp; wherein the first timestamp is the local time when the PDELAY_REQ message is sent, and the fourth timestamp is the local time when the PDELAY_RESP message is obtained.

[0051] As an implementation of this embodiment, the clock deviation can be calculated according to the following formula (1):

[0052]

[0053] Wherein, offset is the calculated clock deviation, t1 is the first timestamp when sending the PDELAY_REQ message; t2 is the second timestamp in the PDELAY_RESP message; t3 is the third timestamp in the PDELAY_RESP_FOLLOWUP message; t4 is the fourth timestamp when obtaining the PDELAY_RESP message.

[0054] Please refer to Figure 3 , the slave clock acts as the Peer delay initiator, and the master clock acts as the Peer delay responder. The slave clock sends a PDELAY_REQ message to the master clock and records the local timestamp t1 at this time. The master clock responds to the received PDELAY_REQ message and sends a PDELAY_RESP message to the slave clock. The PDELAY_RESP message includes the timestamp t2 when the PDELAY_REQ message is received. Then, the master clock continues to send a PDELAY_RESP_FOLLOWUP message to the slave clock. The PDELAY_RESP_FOLLOWUP message includes the timestamp t3 recorded when the PDELAY_RESP message was sent. When the slave clock receives the PDELAY_RESP message, it records the local timestamp t4 at this time. Among them, pdelay=(t ir +t ri ) / 2,t ir =t2-t1, t ri = t4-t3. From this, we can get formula (1). pdelay (peer delay) refers to the total round-trip time from sending a time synchronization request from one device to another and then returning a response from the device.

[0055] When measuring clock bias using the method described above, each exchange of PDELAY_REQ and PDELAY_RESP produces a time bias estimate. These estimates may also be affected by noise due to the uncertainty of network delays. A Kalman filter can combine these measurements with previous clock bias estimates to reduce noise and provide a more stable time bias estimate.

[0056] In some embodiments, calculating the clock deviation according to the target message and the local time further includes:

[0057] The clock deviation is calculated according to the difference between the fifth timestamp and the sixth timestamp in the SYNC_FOLLOWUP message, where the fifth timestamp is the local time when the SYNC message is obtained.

[0058] As an implementation method of this embodiment, the SYNC method assumes that the network delay is symmetrical in both directions between the master clock and the slave clock, that is, the outbound and return delays are the same. The SYNC message is sent periodically by the master clock, which contains the timestamp when the master clock sends the message. The slave clock records the local time when it receives the SYNC message. By comparing the timestamp of the master clock and the local time when the slave clock receives the message, the clock deviation can be calculated.

[0059] When using SYNC messages for time synchronization, each SYNC message received from the clock will bring a new time deviation estimate. Due to the randomness of network delays, these estimates may contain noise. The Kalman filter can combine the previous time deviation estimate with the currently received SYNC message information to give a more accurate, smoothed time deviation estimate.

[0060] In some embodiments, performing a variable step size Kalman filter based on the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time includes:

[0061] Construct a state vector based on the local time and the calculated clock deviation;

[0062] Construct a state transfer matrix according to the acquisition cycle of the target message;

[0063] Kalman filtering is performed based on the state vector and the state transfer matrix to obtain the estimated clock deviation and the estimated time.

[0064] As an implementation of this embodiment, the state vector may be constructed using the following expression:

[0065]

[0066] Where, X k is the state vector, t k is the local time, θk To calculate the clock deviation.

[0067] The expression of the state transfer matrix is:

[0068]

[0069] In the formula, A k is the state transfer matrix, Δt k is the time step. When the time step changes, the state transfer matrix changes accordingly.

[0070] The state equation in the Kalman filter is:

[0071] X k+1 =A k X k +W k (4)

[0072] Where W k is the process noise, which is a Gaussian white noise with an error of Q.

[0073] The observation equation in the Kalman filter is:

[0074] y k =CX k +v k (5)

[0075] In the formula, C = (1 1), V k is the observation noise, which conforms to the normal distribution.

[0076] The expression of the predicted state vector is:

[0077]

[0078] In the formula, is the predicted state vector.

[0079] The expression of the predicted error covariance matrix is:

[0080]

[0081] Where P k+1|k is the covariance matrix of the predicted errors.

[0082] Kalman gain K k The expression is:

[0083] K k =P k+1|k C T (CP k+1|k C T +R) -1 (8)

[0084] Where R is the observation noise covariance matrix.

[0085] The expression of the state update equation is:

[0086]

[0087] The error covariance update equation is expressed as:

[0088] P k+1|k+1 =(IK k C)P k+1|k (10)

[0089] In some embodiments, the time synchronization method of the embodiment of the present application further includes:

[0090] The Kalman filter frequency and Kalman gain are dynamically adjusted according to the acquisition period of the target message.

[0091] As an implementation method of this embodiment, under normal circumstances, it is assumed that the clock synchronization period is set to 125 milliseconds, that is, Δt k = 125 milliseconds, the Kalman filter performs a calculation every 125 milliseconds to update the estimate of the time deviation. In the case of packet loss, the timestamp is not received at 125 milliseconds of the first timestamp, and is received at 300 milliseconds of the next timestamp. At this time, Δt k =175 milliseconds, the state transfer matrix, the predicted error covariance matrix, and the Kalman gain change accordingly. At the same time, the period of the Kalman filter also changes. If the next timestamp arrives normally, the Kalman filter returns to the normal 125 millisecond update period. If data packet loss occurs again, repeat the above variable step size calculation process. In this way, the variable step size Kalman filter can still provide continuous time deviation estimation in the event of data packet loss, thereby improving the accuracy and stability of time synchronization.

[0092] In the actual process, for the packet loss caused by network problems or hardware failures, if a fixed step-size Kalman filter is used, during the packet loss period, the filter either does not perform calculations or uses the previous estimate for prediction. This may lead to inaccuracy in the time deviation estimate. Therefore, the embodiment of the present application uses a variable step-size Kalman filter to maintain the effectiveness of the filter in the case of packet loss. This method allows the filter to perform calculations based on the time interval of the actual received data, rather than strictly following a fixed cycle.

[0093] In some embodiments, the time synchronization method of the embodiment of the present application further includes:

[0094] Real-time monitoring of network status;

[0095] Adjust the target message acquisition cycle according to the network status.

[0096] As an implementation method of this embodiment, changes in network conditions may cause different delays in time synchronization, and a fixed synchronization interval may not be able to adapt to all situations. The embodiment of the present application dynamically adjusts the synchronization frequency between the slave clock and the master clock according to the network conditions. By regularly monitoring key indicators such as network delay and packet loss rate, the stability of the network is evaluated based on the monitoring results. If the network is stable, the synchronization interval can be appropriately increased to reduce the network load. If the network is unstable, shorten the synchronization interval to ensure the accuracy of time synchronization.

[0097] The time synchronization method provided in the embodiment of the present application obtains the target message and the local time, and the local time includes the timestamp recorded when the target message is obtained; the clock deviation is calculated according to the timestamp in the target message and the local time; and the variable step size Kalman filter is performed according to the calculated clock deviation and the local time to obtain the estimated clock deviation and the estimated time. The technical solution of the present application uses the variable step size Kalman filter method to filter the time deviation and dynamically adjust the step size of the Kalman filter to improve the accuracy of time estimation and the stability of time synchronization.

[0098] Based on the same inventive concept as the above embodiments, the embodiments of the present invention further provide an electronic device, such as Figure 4 As shown, the electronic device includes: a processor 310 and a memory 311 storing a computer program; wherein, Figure 4 The processor 310 shown in the figure is not used to indicate that the number of the processor 310 is one, but is only used to indicate the positional relationship of the processor 310 relative to other devices. In actual applications, the number of the processor 310 may be one or more; similarly, Figure 4 The memory 311 shown in the figure has the same meaning, that is, it is only used to refer to the position relationship of the memory 311 relative to other devices. In practical applications, the number of memories 311 can be one or more. When the processor 310 runs the computer program, the above method is implemented.

[0099] The electronic device may also include: at least one network interface 312. The various components in the electronic device are coupled together via a bus system 313. It is understood that the bus system 313 is used to achieve connection and communication between these components. In addition to the data bus, the bus system 313 also includes a power bus, a control bus, and a status signal bus. However, for the sake of clarity, the bus system 313 is not described in detail. Figure 4 Various buses are labeled as bus system 313.

[0100] The memory 311 may be a volatile memory or a nonvolatile memory, or may include both volatile and nonvolatile memories. The nonvolatile memory may be a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a magnetic random access memory (FRAM), a flash memory, a magnetic surface memory, an optical disk, or a compact disc read-only memory (CD-ROM); the magnetic surface memory may be a disk memory or a tape memory. The volatile memory may be a random access memory (RAM), which is used as an external cache. By way of example and not limitation, many forms of RAM are available, such as static random access memory (SRAM), synchronous static random access memory (SSRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous link dynamic random access memory (SLDRAM, SyncLink Dynamic Random Access Memory), and direct RAM bus random access memory (DRRAM, Direct Rambus Random Access Memory).The memory 311 described in the embodiments of the present invention is intended to include but is not limited to these and any other suitable types of memories.

[0101] The memory 311 in the embodiment of the present invention is used to store various types of data to support the operation of the electronic device. Examples of these data include: any computer program used to operate on the electronic device, such as an operating system and an application; contact data; phone book data; messages; pictures; videos, etc. Among them, the operating system includes various system programs, such as a framework layer, a core library layer, a driver layer, etc., which are used to implement various basic services and process hardware-based tasks. The application program may include various applications, such as a media player (Media Player), a browser (Browser), etc., which are used to implement various application services. Here, the program that implements the method of the embodiment of the present invention may be included in the application program.

[0102] Based on the same inventive concept as the above-mentioned embodiment, this embodiment further provides a computer-readable storage medium, in which a computer program is stored. The computer-readable storage medium may be a magnetic random access memory (FRAM), a read-only memory (ROM), a programmable read-only memory (PROM), an erasable programmable read-only memory (EPROM), an electrically erasable programmable read-only memory (EEPROM), a flash memory, a magnetic surface memory, an optical disc, or a compact disc read-only memory (CD-ROM); or various devices including one or any combination of the above memories, such as a mobile phone, a computer, a tablet device, a personal digital assistant, etc. When the computer program stored in the computer-readable storage medium is run by the processor, the above method or system is implemented. For the specific steps implemented when the computer program is executed by the processor, please refer to the description of the above embodiment, which will not be repeated here.

[0103] The technical features of the above-described embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above-described embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0104] In this document, the terms "comprises," "comprising," or any other variations thereof, are intended to cover a non-exclusive inclusion of elements other than those listed and may also include additional elements not expressly listed.

[0105] The above is only a specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any person skilled in the art can easily think of changes or substitutions within the technical scope disclosed by the present invention, which should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.

Claims

1. A time synchronization method, It is characterized in that include: Obtaining a target message and local time, wherein the local time includes a timestamp recorded when the target message is obtained; Obtaining a calculated clock deviation based on the timestamp in the target message and the local time; A variable-step Kalman filter is performed according to the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time.

2. The method according to claim 1, It is characterized in that The target message includes at least one of a SYNC message, a SYNC_FOLLOWUP message, a PDELAY_RESP message, and a PDELAY_RESP_FOLLOWUP message.

3. The method according to claim 2, It is characterized in that The calculating the clock deviation according to the timestamp in the target message and the local time includes: The calculated clock deviation is obtained according to a first timestamp, a second timestamp in the PDELAY_RESP message, a third timestamp in the PDELAY_RESP_FOLLOWUP message, and a fourth timestamp; wherein the first timestamp is the local time when the PDELAY_REQ message is sent, and the fourth timestamp is the local time when the PDELAY_RESP message is obtained.

4. The method according to claim 3, It is characterized in that The calculation clock deviation is obtained according to the following formula: Where offset is the calculation clock deviation, t 1 The first timestamp of sending the PDELAY_REQ message; t 2 is the second timestamp in the PDELAY_RESP message; 3 is the third timestamp in the PDELAY_RESP_FOLLOWUP message; 4 The fourth timestamp when obtaining the PDELAY_RESP message.

5. The method according to claim 2, It is characterized in that The calculating clock deviation according to the timestamp in the target message and the local time also includes: The calculated clock deviation is obtained according to the difference between the fifth timestamp and the sixth timestamp in the SYNC_FOLLOWUP message, where the fifth timestamp is the local time when the SYNC message is obtained.

6. The method according to claim 1, It is characterized in that The performing a variable step size Kalman filter according to the calculated clock deviation and the local time to obtain an estimated clock deviation and an estimated time includes: constructing a state vector based on the local time and the calculated clock deviation; Constructing a state transfer matrix according to the acquisition period of the target message; Kalman filtering is performed according to the state vector and the state transfer matrix to obtain the estimated clock deviation and the estimated time.

7. The method according to claim 6, It is characterized in that The method further comprises: The Kalman filter frequency and the Kalman gain are dynamically adjusted according to the acquisition period of the target message.

8. The method according to claim 1, It is characterized in that The method further comprises: Real-time monitoring of network status; The target message acquisition period is adjusted according to the network status.

9. An electronic device, It is characterized in that The electronic device comprises a memory, a processor and a computer program stored in the memory and executable on the processor, and the processor implements the steps of the method according to any one of claims 1 to 8 when executing the computer program.

10. A computer storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 8 are implemented.