Multi-source time synchronization method and apparatus, computer-readable storage medium

By predicting the time offset and reliability of the local clock source using a multi-source time synchronization device and a long short-term memory network, the reliability and accuracy problems of traditional time synchronization technology in complex environments are solved, and high-precision time synchronization is achieved in various environments.

CN122137493APending Publication Date: 2026-06-02BEIJING BOE DISPLAY TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202610274713.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-03-06
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

Traditional time synchronization technology relies on the reliability and accuracy of external time sources and cannot adapt to clock drift of local clock sources, resulting in decreased reliability and accuracy of time synchronization in complex network environments and under conditions of poor GPS signal.

Method used

A multi-source time synchronization device is adopted, which periodically samples the reference time through multiple external time sources, combines the prediction of the time offset and confidence of the local clock source with the Long Short-Term Memory Network, uses the confidence score for fusion processing, selects the optimal reference time and calibrates the local clock source.

Benefits of technology

It improves the accuracy and reliability of time synchronization, especially in scenarios where the network is disconnected or the GPS signal is poor, and can maintain high time accuracy and environmental adaptability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122137493A_ABST
    Figure CN122137493A_ABST
Patent Text Reader

Abstract

This disclosure provides a multi-source time synchronization method and apparatus, and a computer-readable storage medium. The multi-source time synchronization apparatus includes a multi-source time receiving module, a local offset sampling module, an offset prediction and fusion module, and a calibration control module. The multi-source time receiving module periodically samples reference times from multiple external time sources. The local offset sampling module determines the time offset of the local clock source relative to each external time source at each sampling point based on the local time and the reference time. For any external time source, the offset prediction and fusion module predicts a first time offset based on the state sequence of the external time source within the latest continuous time window, determines the credibility score of the external time source based on credibility data, and fuses the first time offsets corresponding to each external time source based on the credibility score to obtain the optimal reference time for this synchronization. The calibration control module calibrates the local clock source based on the optimal reference time.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of time synchronization technology. More specifically, it relates to a multi-source time synchronization method and apparatus, and a computer-readable storage medium. Background Technology

[0002] Precise time synchronization is crucial in fields such as distributed systems, industrial IoT, intelligent transportation systems, augmented reality / virtual reality (AR / VR), and multi-robot collaboration. Currently commonly used time synchronization technologies include Network Time Protocol (NTP), Precision Time Protocol (PTP), and Global Positioning System (GPS).

[0003] However, the reliability of traditional time synchronization technology depends entirely on the credibility and accuracy of the external time source. When the quality of the external time source deteriorates, the reliability of time synchronization will decrease. In addition, the local clock source of the system is not completely stable. Traditional time synchronization technology cannot adapt to the clock drift phenomenon of the local clock source, resulting in a decrease in time synchronization accuracy. Summary of the Invention

[0004] The purpose of this disclosure is to provide a multi-source time synchronization method and apparatus, and a computer-readable storage medium, to solve at least one of the above-mentioned technical problems.

[0005] To achieve the above objectives, the present disclosure adopts the following technical solution: The first aspect of this disclosure provides a multi-source time synchronization device, comprising: The multi-source time receiving module is configured to periodically sample reference time from multiple external time sources; The local offset sampling module is configured to acquire the local time of the local clock source at each sampling point, and determine the time offset of the local clock source at each sampling point relative to each external time source based on the local time and the reference time. The offset prediction and fusion module includes an offset prediction unit, a confidence generation unit, and a fusion unit. The offset prediction unit employs a long short-term memory network and is configured to predict a first time offset for any external time source based on the state sequence of that external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the device's operating status parameters and network environment parameters at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at a target time after the current time, and the offset change rate represents the rate of change of the time offset. The confidence generation unit is configured to determine a confidence score for any external time source based on the confidence data of that external time source within the latest continuous time window. The fusion unit is configured to use the confidence score to fuse the first time offsets corresponding to each external time source to obtain the optimal reference time for this synchronization. The calibration control module is configured to calibrate the local clock source based on the optimal reference time.

[0006] Optionally, the fusion unit is configured as follows: Based on the credibility scores of each external time source and the historical prediction error, the weight coefficient of each external time source is determined. The historical prediction error represents the average absolute error between the first time offset and the actual offset when the external time source is synchronized multiple times in the historical period. The actual offset represents the real time offset of the local clock source relative to the external time source when synchronized. For any external time source, the reference time of the current moment of the external time source is obtained as the first reference time, and the sum of the first time offset corresponding to the external time source and the first reference time is used as the first reference time after offset compensation. The optimal reference time for this synchronization is obtained by weighting and summing the first reference times after offset compensation for each external time source using the weighting coefficients.

[0007] Optionally, the calibration control module is further configured to: The difference between the current local time and the optimal reference time is used as the offset adjustment amount; The clock calibration mode is determined based on the offset adjustment amount. Using this determined clock calibration mode and the optimal reference time as a benchmark, the local clock source is calibrated. The clock calibration mode includes a soft calibration mode, a progressive calibration mode, and a hard calibration mode; wherein: The soft calibration mode is configured to use the sum of the local time and the offset adjustment as the calibrated local time; The progressive calibration mode is configured to determine the single calibration step size based on the offset adjustment amount, and set the frequency offset rate of the local clock source based on the single calibration step size to gradually reduce the difference between the local time and the optimal reference time. The hard calibration mode is configured to calibrate the time of the local clock source to the optimal reference time via hardware settings.

[0008] Optionally, the calibration control module determines the clock calibration mode based on the offset adjustment amount, including: In response to the absolute value of the offset adjustment amount being less than a first preset threshold, the clock calibration mode is determined to be soft calibration mode; In response to the absolute value of the offset adjustment being greater than or equal to a first preset threshold and less than or equal to a second preset threshold, the clock calibration mode is determined to be a progressive calibration mode, wherein the first preset threshold is less than the second preset threshold. In response to the absolute value of the offset adjustment being greater than a second preset threshold, the clock calibration mode is determined to be hard calibration mode.

[0009] Optionally, the soft calibration mode is also configured as follows: The offset adjustment amount for this synchronization is written into a preset offset cache window, which adopts a fixed-length, first-in-first-out storage structure. The average of the multiple offset adjustment values ​​stored in the offset cache window is taken as the effective offset adjustment value; The sum of the local time at the time of this synchronization and the effective offset adjustment amount is used as the calibrated local time.

[0010] Optionally, the multi-source time receiving module is further configured to: In response to the fact that the latest consecutive offset adjustment amounts stored in the offset cache window are all less than a third preset threshold, the sampling frequency of the reference time is reduced.

[0011] Optionally, the credibility generation unit is further configured to: Based on the credibility data, a first credibility score for each external time source is determined using a pre-set credibility rule engine, and a second credibility score for each external time source is determined using a pre-trained credibility prediction model. For any external time source, the credibility score of the external time source is obtained by fusing the first credibility score and the second credibility score of the external time source.

[0012] Optionally, the reliability data includes at least one of a first type of data, a second type of data, and a third type of data, wherein the first type of data reflects the accuracy of the external time source, the second type of data reflects the stability of the external time source, and the third type of data reflects the device network quality. The operating status parameters include at least one of CPU utilization, device temperature, battery level, and charge / discharge status. The network environment parameters include at least one of network latency and jitter, packet loss rate, and network signal strength.

[0013] Optionally, the multi-source time synchronization device further includes: The visualization query module is configured to respond to user query commands by providing feedback on at least one of the following: time synchronization status, performance indicators, and device operating status parameters. The time synchronization status includes the synchronization time of the latest synchronization, clock calibration mode, and offset adjustment amount. The performance indicators include the current quality parameters and offset change rate of each external time source. The operating status parameters include CPU utilization and memory usage.

[0014] Based on the same inventive concept, a second aspect of this disclosure provides a multi-source time synchronization method, comprising the following steps: The reference time is periodically sampled from multiple external time sources to obtain the local time of the local clock source at each sampling point, and the time offset of the local clock source relative to each external time source at each sampling point is determined based on the local time and the reference time. For any external time source, a first time offset is predicted based on the state sequence of the external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the device's operating status parameters and network environment parameters at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at the target time after the current time. The offset change rate represents the rate of change of the time offset. The credibility score of the external time source is determined based on the credibility data of the external time source within the latest continuous time window. The credibility score is used to fuse the first time offset corresponding to each external time source to obtain the optimal reference time for this synchronization. The local clock source is calibrated using the optimal reference time as a benchmark.

[0015] Based on the same inventive concept, a third aspect of this disclosure provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the multi-source time synchronization method as described above.

[0016] The beneficial effects of this disclosure are as follows: The multi-source time synchronization device of this disclosure includes a multi-source time receiving module that periodically samples reference times from multiple external time sources, a local offset sampling module that calculates the time offset of the local clock source relative to each external time source at each sampling point, and an offset prediction and fusion module that predicts the future target time and the first time offset of the local clock source relative to the external time source based on the time offset, offset change rate, device operating status parameters, and network environment parameters of each external time source within the latest continuous time window. The module also determines the reliability score of each external time source based on the reliability data within the latest continuous time window, and performs fusion processing on the first time offset based on the reliability score to obtain the optimal reference time for this synchronization. Finally, calibration is performed. The control module calibrates the local clock source based on the optimal reference time. With this setting, the predicted first time offset integrates the offset of the local clock source relative to the external time source, the device operating status parameters, and the network environment parameters. In other words, the prediction process takes into account the influence of clock drift, thus resulting in higher prediction accuracy. Furthermore, the reliability score of each external time source is calculated based on the latest reliability data, and then the predicted first time offset is fused using the reliability score. This enables the intelligent determination of the most reliable fusion result under different network conditions and environments, enhancing environmental adaptability. Even in scenarios where the network is disconnected or the GPS signal is poor, it can still maintain high time accuracy through prediction, improving the reliability of time synchronization in offline states. Attached Figure Description

[0017] The specific embodiments of this disclosure will be described in further detail below with reference to the accompanying drawings.

[0018] Figure 1 A schematic diagram of the structure of an embodiment of the multi-source time synchronization device provided in this disclosure; Figure 2 A flowchart illustrating the process of obtaining the optimal reference time for the fusion unit provided in this disclosure; Figure 3 A schematic diagram of the calibration process for the calibration control module provided in this disclosure; Figure 4 Another schematic diagram of the calibration process for the calibration control module provided in this disclosure; Figure 5 This is a flowchart of an embodiment of the multi-source time synchronization method provided in this disclosure. Detailed Implementation

[0019] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the described embodiments of this disclosure without creative effort are within the scope of protection of this disclosure.

[0020] Unless otherwise defined, the technical or scientific terms used in this disclosure shall have the ordinary meaning understood by one of ordinary skill in the art to which this disclosure pertains. The terms “first,” “second,” and similar terms used in this disclosure do not indicate any order, quantity, or importance, but are merely used to distinguish different components. Similarly, the terms “an,” “a,” or “the,” and similar terms do not indicate a quantity limitation, but rather indicate the presence of at least one. The terms “including,” “comprising,” or “containing,” and similar terms mean that the element or object preceding the word encompasses the elements or objects listed following the word and their equivalents, without excluding other elements or objects. The terms “connected,” “linked,” or similar terms are not limited to physical or mechanical connections, but can include electrical connections, whether direct or indirect. The terms “upper,” “lower,” “left,” and “right,” etc., are used only to indicate relative positional relationships, and these relative positional relationships may change accordingly when the absolute position of the described objects changes.

[0021] Traditional time synchronization technologies are mainly divided into three categories: Network Time Protocol (NTP), Precise Time Protocol (PTP), and Global Positioning System (GPS). Network Time Protocol (NTP) calibrates clocks by exchanging time messages between clients and servers over a network, making it relatively simple to implement and widely deployed in the Internet environment. However, its synchronization accuracy is typically limited to the millisecond level and is severely constrained by uncontrollable factors such as asymmetric latency in the network path, queuing jitter, and message loss. In complex or congested network environments, its accuracy and stability drop sharply. Precision Time Protocol (PTP) is designed for high-precision time synchronization, achieving microsecond-level accuracy. However, it has high requirements for network equipment and requires hardware support to achieve optimal performance. The Global Positioning System (GPS) directly receives Coordinated Universal Time (UTC) signals from satellites, providing an independent, highly accurate, and long-term stable absolute time reference with nanosecond-level precision. However, it is severely affected by environmental interference. In environments with obstructions such as indoors, tunnels, and urban canyons, or in environments subject to electromagnetic interference, the signal can be severely attenuated or even completely fail, rendering the time source unusable.

[0022] When performing time synchronization, a single time source, as shown above, is often used as the reference time. Even when some time synchronization techniques utilize multiple time sources, their time source selection strategies are usually quite simple and rigid, such as using static priority switching (e.g., always prioritizing GPS and only switching to PTP when it fails) or fixed weight averaging. These traditional methods have significant drawbacks: First, traditional time synchronization methods cannot intelligently select the optimal / most reliable external time source based on real-time dynamic changes in current environmental parameters (such as network quality, GPS signal strength, device temperature, load fluctuations, etc.) and historical performance data (such as the past deviation stability of a certain time source), resulting in poor environmental adaptability.

[0023] Secondly, the local clock source of the device itself is not ideally stable. The clock drift generated by its crystal oscillator has complex nonlinear characteristics. This drift is not only affected by the long-term aging of the device, but also changes dynamically with factors such as ambient temperature and load fluctuations. Traditional time synchronization methods are difficult to predict this dynamic nonlinear drift behavior of the local clock source, which affects the accuracy of time.

[0024] In addition, in offline scenarios (such as when the network is disconnected) or when the GPS signal is poor, the device may not be able to obtain the reference time from an external time source in a timely manner, affecting the reliability of time synchronization.

[0025] To address at least one of the aforementioned technical problems, embodiments of this disclosure provide a multi-source time synchronization method and apparatus, and a computer-readable storage medium.

[0026] Please refer to Figure 1 , Figure 1 This is a schematic diagram of the structure of an embodiment of the multi-source time synchronization device provided in this disclosure, as shown below. Figure 1 As shown, the multi-source time synchronization device 100 includes a multi-source time receiving module 11, a local offset sampling module 12, an offset prediction and fusion module 13, and a calibration control module 14.

[0027] The multi-source time receiving module 11 is configured to periodically sample reference time from multiple external time sources.

[0028] An external time source refers to a time source other than the local clock source (clk). It originates from outside the device or terminal and is typically obtained through networks, radio waves, or other means. The main function of an external time source is to provide a recognized, standard time point as a benchmark or reference for calibrating the local clock source (clk). External time sources include NTP, GPS, PTP, and other types. The local clock source (clk) can also be understood as the device's system clock.

[0029] In this embodiment, the multi-source time receiving module 11 is responsible for simultaneously accessing multiple external time sources and periodically acquiring the timestamps of each external time source as reference times. It should be noted that the multi-source time receiving module 11 acquires reference times from each external time source synchronously; that is, at any given sampling point, it acquires reference times from multiple external time sources simultaneously.

[0030] In some embodiments, the external time sources accessed by the multi-source time receiving module 11 include three types: NTP, GPS, and PTP. In this case, the multi-source time receiving module 11 includes three sub-modules: an NTP client, a GPS receiver, and a PTP client. Each of the three sub-modules is responsible for communicating with different types of external time sources.

[0031] The NTP client implements the Network Time Protocol (NTP), supports communication with multiple NTP servers, and maintains a list of NTP servers, including a master server and one or more backup servers. When communicating with NTP servers, the client can also obtain quality parameters reflecting the reliability of the NTP time source, such as the NTP level. The GPS receiver obtains time information from the GPS system. On GPS-enabled devices or terminals, the GPS receiver accesses the GPS hardware through the system API to obtain UTC time and location information. Simultaneously, the GPS receiver records quality parameters such as the number of satellites and signal strength for subsequent PTP time source reliability assessment. The PTP client implements the Precision Time Protocol (PTP), supports communication with the PTP master clock, and can record parameters such as the offset and path delay between the master and slave clocks for subsequent PTP time source reliability assessment.

[0032] It is understood that the embodiments disclosed herein only use three types of external time sources, namely NTP, GPS and PTP, as examples for description. In actual applications, there may be two or more types of external time sources, and the types of external time sources may also be more than the three types in the specific example.

[0033] The local offset sampling module 12 is configured to acquire the local time of the local clock source at each sampling point, and determine the time offset of the local clock source relative to each external time source at each sampling point based on the local time and the reference time.

[0034] The local clock source clk can be understood as recording a local time at each sampling point, meaning that each sampling point corresponds to a local time and multiple reference times.

[0035] For example, suppose the local time obtained from the sampling at the i-th sampling point is denoted as T. sys_i, where the reference time obtained by the i-th sampling point from the n-th (1≤n≤N, where N represents the number of external time sources) external time source is denoted as T. source If _ni, then when the external time source includes the three types shown above, and the first external time source is an NTP time source, the second external time source is a GPS time source, and the third external time source is a PTP time source, the reference time obtained from the NTP time source can be denoted as T. source _1i, The reference time obtained from the GPS time source is denoted as T. source _2i, The reference time obtained from the PTP time source is denoted as T. source If _3i, then after the i-th sampling, a set of timestamps can be obtained, which includes the local time T. sys _i, Reference time T source _1i、T source _2i and T source _3i.

[0036] The local offset sampling module 12 is used to calculate and record the time offset of the local clock source clk relative to each external time source. Assuming that the time offset of the local clock source clk at the i-th sampling point relative to the n-th external time source is denoted as ΔT_ni, then for the three external time sources shown above, three sets of time offsets can be obtained, which are expressed as follows: ΔT_1i=T sys _i-T source _1i ΔT_2i=T sys _i-T source _2i ΔT_3i=T sys _i-T source _3i.

[0037] By performing multiple consecutive samplings and offset calculations, a time series dataset f1 can be obtained. This time series dataset f1 includes the time offsets of each sampling point within a continuous time period, and the time offsets at each sampling point within the time series dataset f1 are sorted according to the chronological order of the sampling times. The length of the time series dataset f1 is configurable; assuming its length is L0, this dataset f1 is used to store the latest time offset of the local clock source clk of length L0 relative to each external time source.

[0038] In specific implementation, the local offset sampling module 12 uses the system monotonic clock (e.g., Android's elapsedRealtimeNanos) as a reference to record the time offset of the local clock source clk relative to each external time source, and stores it as the aforementioned time series dataset f1. Using the system monotonic clock as a reference means using the reading of the system monotonic clock to represent the time of the sampling point. For example, if the system monotonic clock reading is ti for the i-th sampling, then this sampling will form a record in the time series dataset f1, represented as (ti, ΔTi), where ΔTi includes ΔT_1i, ΔT_2i, and ΔT_3i.

[0039] The system monotonic clock is a clock that only increases and never decreases, typically starting from system startup and unaffected by local time adjustments. Therefore, by using the system monotonic clock to record the clock deviation (i.e., the aforementioned time offset) at each sampling point, even if the system time (local time) is calibrated or adjusted, the recorded deviation sequence remains continuous, accurately reflecting the changes of the local clock source relative to the external time source.

[0040] In some embodiments, before storing the time offset data of a certain sampling point (including the time offset of the local clock source relative to each external time source) into the time series dataset f1, it is necessary to perform preliminary filtering on the time offset data to remove obviously abnormal data points, and then store the remaining valid data into the time series dataset f1.

[0041] The offset prediction and fusion module 13 includes an offset prediction unit 131, a confidence generation unit 132, and a fusion unit 133. The offset prediction unit 131 employs a long short-term memory network and is configured to predict a first time offset for any external time source based on the state sequence of that external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the device's operating status parameters and network environment parameters at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at the target time after the current time, and the offset change rate represents the rate of change of the time offset. The confidence generation unit 132 is configured to determine a confidence score for any external time source based on the confidence data of that external time source within the latest continuous time window. The fusion unit 133 is configured to use the confidence score to fuse the first time offsets corresponding to each external time source to obtain the optimal reference time for this synchronization.

[0042] The offset prediction unit 131 employs a deep learning model based on a Long Short-Term Memory (LSTM) network. LSTM, a variant of recurrent neural networks, can address the vanishing gradient problem of traditional RNNs by introducing gating mechanisms (such as input gates, forget gates, and output gates). When applied to historical offset data with long-term dependencies in this application, this network structure can effectively capture the temporal characteristics of clock drift, such as slow trends and abrupt changes. For ease of description, the offset prediction unit 131 can be referred to as a prediction model.

[0043] The latest continuous time window W represents the latest continuous time period. It includes multiple sampling points, each corresponding to a set of state data. This set of state data includes multi-dimensional data such as the time offset, offset change rate, operating status parameters, and network environment parameters for that sampling point. The state data corresponding to multiple sampling points constitute a time series data set, which serves as the input data for the offset prediction unit 131. The length of the latest continuous time window W is a fixed length preset by the user. Assuming the length of the latest continuous time window W is represented as L1, L1 is typically less than L0. By extracting the latest time offset data of length L1 from the time series dataset f1, the time offset of each external time source within the latest continuous time window W can be obtained.

[0044] In this embodiment of the disclosure, the offset prediction unit 131 is used to predict the time offset of the local clock source clk relative to each external time source within a future period (i.e., the target time) based on historical offset data (e.g., offset data within the latest continuous time window W). This is the first time offset as shown above. The future period here is usually a small value preset by the user, such as the target time being 1 minute or 5 minutes before the current time. Here, the current time can be understood as the time predicted by the offset prediction and fusion module 13 based on the state data. Assume that the first time offset of the local clock source clk relative to the nth external time source predicted by the offset prediction unit 131 is represented as P. n The output of the offset prediction unit 131 includes the first time offsets P1, P2 and P3.

[0045] The input data for the offset prediction unit 131 is multidimensional data involving multiple dimensions, specifically including: Dimension 1: Historical offset data, including the time offset of the local clock source clk at each sampling point within the latest continuous time window W relative to each external time source.

[0046] Dimension 2: Rate of change of offset. The rate of change of offset can be represented by the difference in time offset at adjacent sampling points. This difference can reflect the rate of change of time offset, that is, the clock drift rate.

[0047] Dimension 3: Device operating status parameters, which include at least one of CPU utilization, device temperature, battery level, and charging / discharging status.

[0048] CPU utilization represents the percentage of time the CPU spends executing non-idle tasks at any given sampling point; it is a dynamically changing instantaneous load metric.

[0049] Device temperature, such as the real-time temperature of the area where the motherboard, CPU, or crystal oscillator is located, is a crucial physical factor affecting clock drift. The output frequency of the crystal oscillator of the local clock source (clk) changes non-linearly with temperature. Temperature fluctuations directly cause the clock to run fast or slow, resulting in systematic drift. The CPU / motherboard temperature can largely reflect the ambient temperature of the crystal oscillator.

[0050] Among them, battery power affects the stability of power supply voltage. For example, when the battery power decreases, its output voltage will slowly drop. The local clock source crystal oscillator is sensitive to the supply voltage, so voltage changes may also cause slight changes in the local clock source frequency.

[0051] Among them, the charging and discharging status refers to whether the device is currently connected to an external power source and is charging. During charging, certain power noise and thermal effects may be generated, causing the local clock source clk to drift.

[0052] CPU utilization, device temperature, battery level, and charging / discharging status can all cause varying degrees of clock drift in the local clock source clk. Therefore, this information is comprehensively utilized when predicting clock drift. It is understood that the embodiments disclosed herein only illustratively list operating state parameters that may affect the local clock source clk. In other embodiments, operating state parameters may include other parameters that may affect the local clock source clk, and are not limited to the examples listed above.

[0053] Dimension 4: Network environment parameters of the device, including at least one of network latency and jitter, packet loss rate, and network signal strength.

[0054] The time offset of the local clock source relative to the external time source, calculated during sampling, is essentially a calculated value. If network latency or jitter is severe, the calculated time offset will fluctuate drastically. If the input data of the offset prediction unit 131 does not include network features (network environment parameters), the offset prediction unit 131 may misjudge the time offset fluctuations caused by the network environment as drift of the local clock source, thus giving an incorrect predicted offset. By using network environment parameters as part of the input data, this embodiment of the disclosure enables the offset prediction unit 131 to extract the current network features, thereby filtering out noise and more accurately extracting the true and smooth clock drift trend.

[0055] Packet loss rate represents the proportion of data packets lost during communication between a device and an external time source. It can be statistically analyzed using a sliding time window. For example, maintaining a fixed-length window, such as the last 10 seconds, continuously records the number of packets sent and received in communication between the device and the external time source, calculating the packet loss rate for that window at each sampling point. High packet loss rates are often accompanied by severe network congestion or failures, which can lead to extremely low or no reliability of the reference time provided by the external time source. By adding packet loss rate as a network feature to the input data of the prediction model, the model can not only better handle missing data but also unreliable data, improving the accuracy of prediction offsets. For instance, a consistently high packet loss rate will trigger the prediction model to rely more on the device's operating state parameters to predict clock drift behavior, rather than attempting to learn patterns from unreliable external time sources.

[0056] The network signal strength includes GPS signal strength, primarily targeting the GPS time source. GPS signal strength affects the accuracy of the reference time provided by GPS satellites. For example, in scenarios with weak GPS signals, such as indoors or in urban canyons, the reference time provided by the GPS time source may be accurate or inaccurate. In such cases, if the prediction model does not incorporate network signal strength as a network feature, it may misinterpret a sudden change in the time offset corresponding to the GPS time source as a severe drift in the local clock source (clk), leading to decreased prediction accuracy. However, by incorporating network signal strength into the prediction model, it learns that when the network signal strength is below a certain threshold, the reference time provided by the GPS time source is inaccurate, thus reducing the contribution of the GPS time source's reference time to the prediction result when predicting the offset.

[0057] It is understood that the embodiments disclosed herein only illustratively list network environment parameters that may affect the prediction results. In other embodiments, network environment parameters may also include other parameters that may affect the prediction results, and are not limited to the few examples above.

[0058] The data from the different dimensions mentioned above are aligned according to a unified timestamp to form synchronized multidimensional data. The state data can also be understood as a multidimensional data time series formed by the multidimensional data at each sampling point position within the latest continuous time window W.

[0059] Furthermore, before inputting the multidimensional data time series into the offset prediction unit 131 for prediction, the multidimensional data time series can be preprocessed. This preprocessing includes, but is not limited to, missing value handling, outlier detection and cleaning, and normalization. For example, missing value handling uses linear interpolation or forward imputation to complete missing data; outlier detection and cleaning uses the 3σ principle or IQR method to identify and remove outlier values; and normalization uses Min-Max normalization or Z-score standardization.

[0060] In a specific example, the basic network structure of the prediction model includes an input layer, an LSTM layer, a fully connected layer, and an output layer. The input layer receives data within a fixed-length time window. In this embodiment, the fixed-length time window data is the multidimensional data time series within the latest continuous time window W. For example, the length of the latest continuous time window W is T, where T = 60 minutes (corresponding to data from the past 60 minutes). If sampling is performed every minute, and assuming the dimension of the multidimensional data at each sampling point is represented as D, then the tensor shape of the input data is (T, D). The LSTM layer is the core processing layer of the prediction model, comprising one or more stacked LSTM units. Each LSTM unit contains an input gate, a forget gate, an output gate, and a unit state to preserve historical context information. The fully connected layer maps the high-dimensional features output by the LSTM layer to the prediction space. The output layer outputs the predicted time offset of the local clock source clk relative to an external time source for a specific future time range (e.g., 1 minute, 5 minutes, etc.), i.e., P1, P2, and P3 as shown above.

[0061] It is understood that the embodiments disclosed herein utilize existing LSTM network structures to predict clock drift behavior without modifying the basic structure of the LSTM network. Furthermore, the prediction model needs to be pre-trained, and the embodiments disclosed herein can employ existing model training methods for pre-training.

[0062] The credibility generation unit 132 is used to determine the credibility score of each external time source based on the credibility data of each external time source within the latest continuous time window W. In other words, the credibility generation unit 132 is used to evaluate the credibility of each external time source in the current environment and generate a normalized credibility score for each external time source.

[0063] Optionally, the reliability data includes at least one of a first type of data, a second type of data, and a third type of data, wherein the first type of data reflects the accuracy of the external time source, the second type of data reflects the stability of the external time source, and the third type of data reflects the device network quality.

[0064] For different types of external time sources, their accuracy is typically reflected by different parameters. Therefore, the first type of data includes parameters reflecting the accuracy characteristics of each external time source. For example, the first type of data includes parameters such as NTP level, number of GPS satellites, PTP clock class, and accuracy class. The NTP level reflects the accuracy of the NTP time source; generally, the lower the NTP level, the higher the accuracy of the NTP time source, meaning a higher accuracy of the reference time obtained from that external time source. The number of GPS satellites reflects the accuracy of the GPS time source; more satellites generally result in higher positioning and timing accuracy. The PTP clock class and accuracy class reflect the accuracy of the PTP time source.

[0065] The stability of an external time source can be reflected by characteristics such as historical offset variance, offset jitter, and synchronization interval fluctuation. Therefore, the second type of data can include data such as the historical offset variance, offset jitter, and synchronization interval fluctuation of the external time source. Among them, historical offset variance refers to the variance of the offset of the local clock source relative to the external time source within a certain historical length, and synchronization interval fluctuation refers to the fluctuation of the interval between two adjacent samples within a certain historical length. Ideally, the external time source should be synchronized at a fixed period, but the synchronization interval may fluctuate due to network congestion, signal loss, etc.

[0066] The quality of a device's network can be reflected by the device's network environment parameters. Therefore, the third type of data can include data such as network latency and jitter, packet loss rate, and network signal strength.

[0067] Based on the credibility data within the latest continuous time window W, the credibility, or reliability, of each external time source can be evaluated. In practice, a method combining a rule engine and a machine learning model is used to calculate the credibility score.

[0068] In some embodiments, the credibility generation unit 132 is configured to: determine a first credibility score for each external time source based on the credibility data using a pre-set credibility rule engine, and determine a second credibility score for each external time source using a pre-trained credibility prediction model; for any external time source, fuse the first credibility score and the second credibility score of the external time source to obtain the credibility score of the external time source. It should be noted that the credibility score output by the credibility generation unit 132 is a normalized numerical value, with a value range of [0,1]. A higher credibility score indicates a more credible external time source.

[0069] The credibility rule engine has multiple predefined rules. Based on these predefined rules, the credibility rule engine performs preliminary screening of credibility data and handles extreme abnormal scenarios (such as complete signal loss or equipment failure) to avoid invalid data interfering with the accuracy of credibility assessment.

[0070] The rules are as follows: a1. If the number of GPS satellites is less than 4, then the first confidence score of the GPS time source is C. rule =0 indicates that the GPS time source is unreliable; a2. If the network packet loss rate exceeds 50%, the first confidence score for both NTP and PTP time sources is C. rule =0 indicates that the NTP and PTP time sources are unreliable due to network unavailability; a3. If the NTP level is greater than 15, then the first credibility score of the NTP time source is C. rule =0 indicates that the NTP time source is not synchronized and its reference time is unreliable; a4. If the offset jitter of the external time source is greater than 100µs, the corresponding first confidence score is C. rule =C rule *0.3 indicates that the external time source is currently unstable and its reliability is reduced; The credibility rule engine can determine an initial score, or first credibility score C, for each external time source. rule It should be noted that the processing order and combination of different rules can be predefined according to the actual situation, and the embodiments disclosed herein do not limit them.

[0071] The pre-trained credibility prediction model employs a supervised learning model, which predicts the credibility of each external time source based on credibility data and outputs a second credibility score C. ml .

[0072] For the nth external time source, its final credibility score C n Based on the first credibility score C rule Second credibility score C ml The result of fusion is represented as:

[0073] in, This indicates an adjustable fusion coefficient. The value range is, for example, 0.5 to 0.8, which is used to balance the influence of rules and machine learning methods on the final credibility score.

[0074] The credibility generation unit 132 of this embodiment uses rules (prior knowledge) to handle extreme cases and machine learning models to capture the relationships between complex features. This design can improve the robustness of the credibility generation unit 132 and avoid the machine learning model from giving unreliable credibility scores under abnormal conditions.

[0075] In this embodiment, the fusion unit 133 is used to proactively compensate for short-term clock drift based on the credibility scores and historical prediction errors of multiple external time sources, and calculates the optimal reference time T for this time synchronization through intelligent weighted fusion. fusion .

[0076] Optionally, the fusion unit 133 uses the confidence score to fuse the first time offsets corresponding to each external time source to obtain the optimal reference time for this synchronization. The specific process is as follows: Figure 2 As shown, it includes: Step A1: Determine the weighting coefficient of each external time source based on the credibility score of each external time source and the historical prediction error. The historical prediction error represents the average absolute error between the first time offset and the actual offset of the external time source during multiple synchronizations in the historical period. The actual offset represents the real time offset of the local clock source relative to the external time source during synchronization.

[0077] The goal of this step is to assign appropriate weighting coefficients to each external time source based on its real-time reliability (reliability score) and long-term stability (historical prediction error).

[0078] Among them, historical prediction error E n Maintained by the fusion unit 133 itself, or calculated in a separate performance evaluation unit. Historical prediction error E n This represents the average absolute error between the first time offset and the actual offset corresponding to the external time source within a past time window (i.e., a historical period, such as the last 24 hours or the last 20 synchronization cycles). The first time offset is the predicted offset obtained by the offset prediction unit 131 during synchronization in the historical period. The actual offset refers to the real time difference (i.e., the real time offset) between the local clock source clk and the external time source during synchronization in the historical period. Specifically, it refers to the real time offset at the moment corresponding to the predicted offset during each synchronization.

[0079] For example, for the nth external time source, its corresponding weighting coefficient W n It can be represented as:

[0080] in, This is a pre-set small constant to prevent the denominator from being zero.

[0081] Assuming the historical period includes M (e.g., M=20) synchronizations, for the nth external time source, the first time offset predicted at the mth (1≤m≤M)th synchronization is denoted as P. nm The actual offset obtained from the actual measurement is expressed as Q. nm Then the historical prediction error E n It can be represented as:

[0082] Step A2: For any external time source, obtain the reference time of the current moment of the external time source as the first reference time, and use the sum of the first time offset corresponding to the external time source and the first reference time as the first reference time after offset compensation.

[0083] The goal of this step is to use short-term forecasts of the future to advance the reference time of the current moment provided by each external time source, so as to obtain a time estimate that is closer to the actual value of the future synchronization / calibration moment.

[0084] For the nth external time source, let's assume the reference time of the current moment obtained from this external time source (denoted as the first reference time for distinction) is denoted as T. n T n It can also be represented as T source_ncurrent After short-term prediction offset compensation for the external time source, the first reference time after compensation is denoted as... The compensation formula can then be expressed as:

[0085] First reference time after compensation This can be understood as an estimation of the time of the external time source at the target time. This extends the basis of multi-source fusion from the current time to the target time in the near future, improving the foresight and accuracy of time synchronization.

[0086] Step A3: Use the weighting coefficients to perform a weighted summation of the first reference times after offset compensation for each external time source to obtain the optimal reference time for this synchronization.

[0087] Assume the optimal reference time is expressed as The fusion process can then be represented as:

[0088] Among them, the optimal reference time It is a robust and accurate calibration target value that integrates the real-time status, historical performance, and prediction of short-term changes from all available external time sources and serves as the reference for calibration control module 14.

[0089] The calibration control module 14 is configured to calibrate the local clock source based on the optimal reference time.

[0090] In some embodiments, the calibration control module 14 is further configured to: use the difference between the current local time and the optimal reference time as an offset adjustment amount; determine a clock calibration mode based on the offset adjustment amount; and calibrate the local clock source using the determined clock calibration mode and the optimal reference time as a reference. The clock calibration mode includes a soft calibration mode Mod1, a progressive calibration mode Mod2, and a hard calibration mode Mod3. The specific process is as follows: Figure 3 As shown.

[0091] The core function of the calibration control module 14 provided in this embodiment is to receive the optimal reference time calculated by the fusion unit 133. This optimal reference time The local time T provided by the local clock source clk at the current moment sys _ current By comparison, the offset adjustment amount ΔT is obtained, which can be expressed as ΔT = -T sys _ current A positive ΔT indicates that the local clock source clk is lagging and needs to be sped up, while a negative ΔT indicates that the local clock source clk is leading and needs to be slowed down. (Specific details are as follows...) Figure 3 As shown in step B1, the offset adjustment ΔT reflects the calibration magnitude of this time synchronization.

[0092] Meanwhile, the calibration control module 14 also needs to intelligently select one of three modes—soft calibration mode Mod1, progressive calibration mode Mod2, or hard calibration mode Mod3—based on the magnitude of the offset adjustment ΔT, to complete clock synchronization / calibration in the most suitable way, ensuring time accuracy while guaranteeing the stability of the equipment.

[0093] Specifically, the clock calibration mode is intelligently determined based on the magnitude of the offset adjustment ΔT through two preset thresholds.

[0094] Optionally, the calibration control module determines the clock calibration mode based on the offset adjustment amount, such as... Figure 3 As shown, it includes: Step B2: Determine the relationship between the offset adjustment amount and the first preset threshold and the second preset threshold.

[0095] Step B3, determine that the clock calibration mode is the soft calibration mode in response to the absolute value of the offset adjustment amount being less than the first preset threshold.

[0096] Step B4, determine that the clock calibration mode is the progressive calibration mode in response to the absolute value of the offset adjustment amount being greater than or equal to the first preset threshold and less than or equal to the second preset threshold, where the first preset threshold is less than the second preset threshold.

[0097] Step B5, determine that the clock calibration mode is the hard calibration mode in response to the absolute value of the offset adjustment amount being greater than the second preset threshold.

[0098] Assume that the first preset threshold is denoted as Th1 and the second preset threshold is denoted as Th2, which are fixed values preset by the user. For example, the first preset threshold Th1 = 50ms and the second preset threshold Th2 = 500ms. Then the process of determining the clock calibration mode can be expressed as: If |ΔT| < Th1, that is, the current is a small offset scenario, then the soft calibration mode Mod1 is adopted, and this calibration mode has the least impact on the system.

[0099] If Th1 ≤ |ΔT| ≤ Th2, that is, the current is a medium offset scenario, then the progressive calibration mode Mod2 is adopted. This calibration mode can maintain the continuity of time by decomposing the adjustment, that is, by controlling the change amplitude, system jitter can be avoided.

[0100] If |ΔT| > Th2, that is, the current is a large offset scenario, then the hard calibration mode Mod3 is adopted. This calibration mode is usually used for initial synchronization or post - anomaly synchronization and can quickly restore time accuracy.

[0101] In the embodiments of the present disclosure, different clock calibration modes are automatically selected according to the offset adjustment amount, which can ensure the time accuracy after calibration, reduce the impact of time calibration on the device, avoid device jitter, and ensure the stability of the device.

[0102] Compared with related technologies, the multi-source time synchronization device provided in this disclosure involves a multi-source time receiving module that periodically samples reference times from multiple external time sources, a local offset sampling module that calculates the time offset of the local clock source relative to each external time source at each sampling point, and then an offset prediction and fusion module that predicts the first time offset of the local clock source relative to the external time source at the target time based on the time offset of each external time source within the latest continuous time window, the offset change rate, the device's operating status parameters, and network environment parameters. Based on the reliability data of each external time source within the latest continuous time window, a reliability score for each external time source is determined, and the first time offset is fused according to the reliability score to obtain the optimal reference time for this synchronization. The post-calibration control module calibrates the local clock source based on the optimal reference time. With this setting, the predicted first time offset integrates the offset of the local clock source relative to the external time source, device operating status parameters, and network environment parameters. This prediction process takes into account the influence of clock drift, so the prediction results are more accurate. Furthermore, the reliability score of each external time source is calculated based on the latest reliability data, and then the predicted first time offset is fused using the reliability score. This enables the intelligent determination of the most reliable fusion result under different network conditions and environments, enhancing environmental adaptability. Even in scenarios where the network is disconnected or the GPS signal is poor, it can still maintain high time accuracy through prediction, improving the reliability of time synchronization in offline states.

[0103] Optionally, the soft calibration mode Mod1 is configured to use the sum of the local time and the offset adjustment as the calibrated local time.

[0104] The essence of the soft calibration mode Mod1 is logical calibration at the software or application level. It doesn't directly modify the local clock source clk, but instead maintains a software-level offset cache f1. This offset cache f1 stores at least the most recently calculated offset adjustment ΔT. When a user requests time from the multi-source time synchronization device 100 via the application layer interface API, the multi-source time synchronization device 100 dynamically compensates the local time with the offset adjustment ΔT stored in the offset cache f1 and returns it. Assuming the time when the multi-source time synchronization device 100 receives the user's request is t, the local time at time t is represented as T. sys (t), where the calibrated local time is represented as T. calib (t), then T calib (t)=T sys (t)+ΔT, which is the timestamp of the feedback given to the user based on the user request, is T. calib (t), for the application layer, the timestamp it obtains is a calibrated time close to the optimal reference time. The time value was changed, but the local clock source clk at the system's underlying layer did not change.

[0105] In some embodiments, in order to improve the calibration accuracy in the soft calibration mode Mod1, the offset buffer f1 can be set to have a certain length to store the offset adjustment amount ΔT obtained during the most recent synchronizations, and then the effective offset adjustment amount for this time can be determined based on the multiple offset adjustment amounts ΔT of the most recent synchronizations.

[0106] Optionally, the soft calibration mode Mod1 is further configured as follows: Step C1: Write the offset adjustment amount of this synchronization into the preset offset cache window f2. The offset cache window f2 adopts a fixed length, first-in-first-out storage structure.

[0107] In this embodiment of the disclosure, the offset cache window f2 has a certain length. The offset adjustment amount ΔT calculated each time is written into the offset cache window f2. The window f1 adopts a fixed-length, first-in-first-out (FIFO) circular queue structure, for example, with a size of 10. The latest offset cache window ΔT is stored at the tail of the queue, and the oldest one is removed from the head of the queue.

[0108] Step C2: The average of the multiple offset adjustment values ​​stored in the offset cache window is taken as the effective offset adjustment value.

[0109] Continuing with the example of an offset buffer window f2 with a length of 10, assuming the offset adjustment ΔT calculated in this synchronization is denoted as ΔT(t), and the offset adjustment ΔT calculated in the previous 9 iterations is denoted as ΔT(t-1), ΔT(t-1), ..., ΔT(t-9), then the offset buffer window f2 can be represented as {ΔT(t-9), ΔT(t-8), ..., ΔT(t)}. The effective offset adjustment calculated at this point can be expressed as: (t)=(ΔT(t-9)+ΔT(t-9)+...+ΔT(t-1)+ΔT(t)) / 10.

[0110] Step C3: The sum of the local time at the time of this synchronization and the effective offset adjustment amount is taken as the calibrated local time. The calibrated local time T calib (t) can be represented as: T calib (t)=T sys (t)+ (t).

[0111] In this embodiment of the disclosure, the method of using the average value of the offset buffer window f2 can effectively smooth out the noise or short-term fluctuations that may be introduced during a single synchronization, thereby improving the accuracy of the offset adjustment amount.

[0112] In some embodiments, the multi-source time receiving module 11 is further configured to: reduce the sampling frequency of the reference time in response to the fact that the latest consecutive offset adjustment amounts stored in the offset buffer window are all less than a third preset threshold.

[0113] The multi-source time receiving module 11 periodically requests reference time from an external time source. The frequency of this request can also be represented as the sampling frequency, which is typically a pre-configured fixed value. The multi-source time receiving module 11 triggers sampling according to the configured sampling frequency interval. For example, sampling is performed every minute, at which point the sampling frequency is 60Hz / h. Correspondingly, the local offset sampling module 12 also periodically calculates the time offset, with the calculation frequency being the same as the sampling frequency. This sampling frequency also affects the time synchronization frequency; generally, a higher sampling frequency results in a higher time synchronization frequency, and vice versa.

[0114] In this embodiment of the disclosure, when the offset adjustment amount stored in the offset cache window f2 is continuously less than the third preset threshold, for example, when the latest several offset adjustment amounts ΔT are all less than the third preset threshold (for example, the latest 10 or 8 consecutive offset adjustment amounts ΔT are all less than 30ms), it indicates that the clock drift of the local clock source is small at this time. Therefore, the sampling frequency of the reference time can be reduced. The reduction of the sampling frequency will lead to an extension of the time synchronization period, for example, changing from sampling once every 10 seconds to sampling once every 30 seconds. This can reduce CPU and memory operations and unnecessary network requests, thereby reducing computing overhead, saving power, and improving resource utilization.

[0115] Optionally, the progressive calibration mode Mod2 is configured to determine a single calibration step size based on the offset adjustment amount, and set the frequency offset rate of the local clock source based on the single calibration step size to gradually reduce the difference between the local time and the optimal reference time.

[0116] The core of the progressive calibration mode Mod2 is to break down large offset adjustments into multiple small steps, reducing the impact on the system. It is suitable for medium offset scenarios (50ms-500ms) and can maintain time continuity. Its calibration process typically includes steps D1 and D2.

[0117] Step D1: Determine the single calibration step size s based on the currently calculated offset adjustment amount ΔT.

[0118] First, take a portion of the offset adjustment ΔT (e.g., 20%) as the reference step size: s1 = |ΔT| × 20%; if the reference step size s1 is greater than the preset calibration step size s2 (e.g., s2 = 50ms), then set the single calibration step size s to s = s2 = 50ms. If the reference step size s1 is less than or equal to 50ms, then set the single calibration step size s to s = s1. For example, if s1 = 40ms, then s = s1. This process can be expressed as s = min(s1, s2). By setting the single calibration step size s1 to less than or equal to 50ms, the smoothness of the calibration process can be ensured. Step D2: Determine the direction of time adjustment.

[0119] If the offset adjustment ΔT > 0, it means that the local clock source clk provides local time lag, and the local clock source clk needs to run faster to catch up with the optimal reference time. At this point, the local clock source clk will be configured to operate with a positive frequency offset, meaning it will increase by s per second, and vice versa. In practice, the frequency offset rate of the local clock source clk can be set through the operating system's clock adjustment interface, thus controlling the local clock source clk to move towards the optimal reference time at a rate of s per step. convergence.

[0120] During the calibration process using the progressive calibration mode Mod1, the calibration control module 14 also monitors the local time and the optimal reference time in real time. If the absolute value of the difference is less than the first preset threshold at a certain moment, the calibration control module 14 will switch from the progressive calibration mode Mod1 back to the soft calibration mode Mod1. The switching process includes: immediately restoring the frequency offset rate of the local clock source clk to 0 or the previously saved initial frequency offset rate, and executing the soft calibration mode Mod1.

[0121] Optionally, the hard calibration mode is configured to calibrate the time of the local clock source to the optimal reference time via hardware settings.

[0122] The hard calibration mode (Mod3) directly adjusts the system's local clock source (clk), suitable for initial synchronization or large-scale adjustments (e.g., offset adjustments greater than 500ms), with immediate results. In practice, the local clock source (clk) time is directly set to the optimal reference time by calling kernel interfaces (e.g., the clock_settime(CLOCK_REALTIME,&ts) interface). The entire setup process is usually completed in microseconds, and the time jump takes effect immediately.

[0123] After the hard calibration is completed, the calibration control module 14 will also clear the data in the offset cache window f2 and reinitialize the parameters of the soft calibration mode Mod1 and the progressive calibration mode Mod2.

[0124] In some embodiments, such as Figure 4 As shown, the calibration control module 14 is also configured to perform the following steps: Step S1: Determine whether this synchronization is the first synchronization after the device starts up. If the result is yes, proceed to step S2. If the result is no, proceed to step S3.

[0125] Step S2: Set the clock calibration mode to hard calibration mode and perform calibration.

[0126] Step S3: Obtain the load status of the device and determine whether the load status is high load or low load. If it is low load, proceed to step S4; if it is high load, proceed to step S9. It should be noted that the low load status in this embodiment also includes an idle state.

[0127] Step S4: Obtain the offset adjustment amount for this calibration, and then proceed to step S5.

[0128] Step S5: Determine the relationship between the offset adjustment amount and the first preset threshold and the second preset threshold. If the absolute value of the offset adjustment amount is less than the first preset threshold, proceed to step S6. If the absolute value of the offset adjustment amount is greater than or equal to the first preset threshold and less than or equal to the second preset threshold, proceed to step S7. If the absolute value of the offset adjustment amount is greater than the second preset threshold, proceed to step S8.

[0129] Step S6: Set the clock calibration mode to soft calibration mode and perform calibration.

[0130] Step S7: Set the clock calibration mode to progressive calibration mode and perform calibration.

[0131] Step S8: Set the clock calibration mode to hard calibration mode and perform calibration.

[0132] Step S9: Implement the delayed calibration strategy.

[0133] In this approach, when the system is under high load, to avoid interference with system performance, calibration is temporarily postponed until the system load decreases to a low load state; this is known as delayed calibration. Furthermore, in some embodiments, step S3 can further determine whether the device is performing a critical task. If the device is performing a critical task, the delayed calibration strategy shown in step S9 is also executed to prevent calibration from interfering with task execution.

[0134] The calibration control module of this embodiment performs an initial synchronization when the device starts up. This initial synchronization uses a hard calibration mode to quickly calibrate the local clock source. For subsequent non-initial synchronizations, the load status of the device is used to determine whether to execute a delayed calibration strategy. If the device is under high load or performing a critical task, the delayed calibration strategy is executed. The calibration process is only executed when the device is under low load (including idle state). In this way, the impact on system performance and application real-time performance can be minimized while ensuring time synchronization accuracy.

[0135] In some embodiments, the multi-source time synchronization device 100 further includes a log module 15. The log module 15 is used to record data such as time synchronization status, performance indicators, and device operating status parameters for subsequent fault diagnosis and performance optimization.

[0136] The time synchronization status includes, but is not limited to, the synchronization time of the latest synchronization, the clock calibration mode, and the offset adjustment amount; performance indicators include the current quality parameters and offset change rate of each external time source; and operating status parameters include CPU utilization and memory usage. In addition, the log module 15 can also record data such as key events of the device.

[0137] In some embodiments, the multi-source time synchronization device 100 further includes a visualization query module 16. The visualization query module 16 is configured to respond to a user query command by providing feedback on at least one of the following: time synchronization status, performance indicators, and device operating status parameters. The time synchronization status includes the synchronization time of the latest synchronization, the clock calibration mode, and the offset adjustment amount. Specifically, the device provides a query interface through which users can query data such as time synchronization status and performance indicators.

[0138] Based on the same inventive concept, a second aspect of this disclosure provides a multi-source time synchronization method, applicable to the multi-source time synchronization device shown above, such as... Figure 5 As shown, it includes the following steps: Step S101: Periodically sample reference time from multiple external time sources to obtain the local time of the local clock source at each sampling point, and determine the time offset of the local clock source relative to each external time source at each sampling point based on the local time and reference time.

[0139] Step S102: For any external time source, predict a first time offset based on the state sequence of the external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the operating status parameters and network environment parameters of the device at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at the target time after the current time. The offset change rate represents the rate of change of the time offset. Determine the credibility score of the external time source based on the credibility data of the external time source within the latest continuous time window.

[0140] Step S103: Use the credibility score to fuse the first time offset corresponding to each external time source to obtain the optimal reference time for this synchronization.

[0141] Step S104: Calibrate the local clock source using the optimal reference time as a benchmark.

[0142] Compared with related technologies, the multi-source time synchronization method provided in this disclosure integrates the offset of the local clock source relative to the external time source, device operating status parameters, and network environment parameters in predicting the first time offset. This prediction process takes into account the influence of clock drift, thus the prediction result is more accurate. Furthermore, the reliability score of each external time source is calculated based on the latest reliability data, and then the predicted first time offset is fused using the reliability score. This enables intelligent determination of the most reliable fusion result under different network conditions and environments, enhancing environmental adaptability. Even in scenarios where the network is disconnected or the GPS signal is poor, it can still maintain high time accuracy through prediction, improving the reliability of time synchronization in offline states.

[0143] Based on the same inventive concept, this disclosure also provides a computer-readable storage medium storing a computer program thereon, which, when executed by a processor, implements the steps of the multi-source time synchronization method described above. In specific implementations, the computer-readable storage medium may include various storage media capable of storing program code, such as a Universal Serial Bus Flash Drive (USB), a portable hard drive, a Read Only Memory (ROM), a Random Access Memory, a magnetic disk, or an optical disk.

[0144] Obviously, the above embodiments of this disclosure are merely examples for clearly illustrating this disclosure, and are not intended to limit the implementation of this disclosure. For those skilled in the art, other variations or modifications can be made based on the above description. It is impossible to exhaustively list all implementation methods here. Any obvious variations or modifications derived from the technical solutions of this disclosure are still within the protection scope of this disclosure.

Claims

1. A multi-source time synchronization device, characterized in that, include: The multi-source time receiving module is configured to periodically sample reference time from multiple external time sources; The local offset sampling module is configured to acquire the local time of the local clock source at each sampling point, and determine the time offset of the local clock source at each sampling point relative to each external time source based on the local time and the reference time. The offset prediction and fusion module includes an offset prediction unit, a confidence generation unit, and a fusion unit. The offset prediction unit uses a long short-term memory network and is configured to predict a first time offset for any external time source based on the state sequence of the external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the device's operating status parameters and network environment parameters at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at the target time after the current time, and the offset change rate represents the rate of change of the time offset. The confidence generation unit is configured to determine a confidence score for any external time source based on the confidence data of the external time source within the latest continuous time window. The fusion unit is configured to use the confidence score to fuse the first time offsets corresponding to each external time source to obtain the optimal reference time for this synchronization. as well as The calibration control module is configured to calibrate the local clock source based on the optimal reference time.

2. The multi-source time synchronization device according to claim 1, characterized in that, The fusion unit is configured as follows: Based on the credibility scores of each external time source and the historical prediction error, the weight coefficient of each external time source is determined. The historical prediction error represents the average absolute error between the first time offset and the actual offset when the external time source is synchronized multiple times in the historical period. The actual offset represents the real time offset of the local clock source relative to the external time source when synchronized. For any external time source, the reference time of the current moment of the external time source is obtained as the first reference time, and the sum of the first time offset corresponding to the external time source and the first reference time is used as the first reference time after offset compensation. The optimal reference time for this synchronization is obtained by weighting and summing the first reference times after offset compensation for each external time source using the weighting coefficients.

3. The multi-source time synchronization device according to claim 1, characterized in that, The calibration control module is also configured to: The difference between the current local time and the optimal reference time is used as the offset adjustment amount; The clock calibration mode is determined based on the offset adjustment amount. Using this determined clock calibration mode and the optimal reference time as a benchmark, the local clock source is calibrated. The clock calibration mode includes a soft calibration mode, a progressive calibration mode, and a hard calibration mode; wherein: The soft calibration mode is configured to use the sum of the local time and the offset adjustment as the calibrated local time; The progressive calibration mode is configured to determine the single calibration step size based on the offset adjustment amount, and set the frequency offset rate of the local clock source based on the single calibration step size to gradually reduce the difference between the local time and the optimal reference time. The hard calibration mode is configured to calibrate the time of the local clock source to the optimal reference time via hardware settings.

4. The multi-source time synchronization device according to claim 3, characterized in that, The calibration control module determines the clock calibration mode based on the offset adjustment amount, including: In response to the absolute value of the offset adjustment amount being less than a first preset threshold, the clock calibration mode is determined to be soft calibration mode; In response to the absolute value of the offset adjustment being greater than or equal to a first preset threshold and less than or equal to a second preset threshold, the clock calibration mode is determined to be a progressive calibration mode, wherein the first preset threshold is less than the second preset threshold. In response to the absolute value of the offset adjustment being greater than a second preset threshold, the clock calibration mode is determined to be hard calibration mode.

5. The multi-source time synchronization device according to claim 3, characterized in that, The soft calibration mode is also configured as follows: The offset adjustment amount for this synchronization is written into a preset offset cache window, which adopts a fixed-length, first-in-first-out storage structure. The average of the multiple offset adjustment values ​​stored in the offset cache window is taken as the effective offset adjustment value; The sum of the local time at the time of this synchronization and the effective offset adjustment amount is used as the calibrated local time.

6. The multi-source time synchronization device according to claim 5, characterized in that, The multi-source time receiving module is further configured to: In response to the fact that the latest consecutive offset adjustment amounts stored in the offset cache window are all less than a third preset threshold, the sampling frequency of the reference time is reduced.

7. The multi-source time synchronization device according to any one of claims 1 to 6, characterized in that, The credibility generation unit is further configured to: Based on the credibility data, a first credibility score for each external time source is determined using a pre-set credibility rule engine, and a second credibility score for each external time source is determined using a pre-trained credibility prediction model. For any external time source, the credibility score of the external time source is obtained by fusing the first credibility score and the second credibility score of the external time source.

8. The multi-source time synchronization device according to any one of claims 1 to 6, characterized in that, The reliability data includes at least one of a first type of data, a second type of data, and a third type of data. The first type of data reflects the accuracy of the external time source, the second type of data reflects the stability of the external time source, and the third type of data reflects the network quality of the device. The operating status parameters include at least one of CPU utilization, device temperature, battery level, and charge / discharge status. The network environment parameters include at least one of network latency and jitter, packet loss rate, and network signal strength.

9. The multi-source time synchronization device according to any one of claims 1 to 6, characterized in that, Also includes: The visualization query module is configured to respond to user query commands by providing feedback on at least one of the following: time synchronization status, performance indicators, and device operating status parameters. The time synchronization status includes the synchronization time of the latest synchronization, clock calibration mode, and offset adjustment amount. The performance indicators include the current quality parameters and offset change rate of each external time source. The operating status parameters include CPU utilization and memory usage.

10. A multi-source time synchronization method, characterized in that, Includes the following steps: The reference time is periodically sampled from multiple external time sources to obtain the local time of the local clock source at each sampling point, and the time offset of the local clock source relative to each external time source at each sampling point is determined based on the local time and the reference time. For any external time source, a first time offset is predicted based on the state sequence of the external time source within the latest continuous time window. The state sequence includes each sampling point within the latest continuous time window, the time offset of the local clock source relative to the external time source, the offset change rate, and the device's operating status parameters and network environment parameters at each sampling point. The first time offset represents the predicted offset of the local clock source relative to the external time source at the target time after the current time. The offset change rate represents the rate of change of the time offset. The credibility score of the external time source is determined based on the credibility data of the external time source within the latest continuous time window. The credibility score is used to fuse the first time offset corresponding to each external time source to obtain the optimal reference time for this synchronization. The local clock source is calibrated using the optimal reference time as a benchmark.

11. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by the processor, it implements the steps of the multi-source time synchronization method as described in claim 10.