Method and apparatus for multi-time source adaptive handoff time alignment for a fusion terminal

By adopting a multi-time-source adaptive switching time synchronization method, the problem of insufficient time synchronization accuracy of power metering automation intelligent terminals on resource-constrained platforms is solved, achieving high-precision, low-overhead, and robust time assurance, and supporting accurate transmission of metering data and fault tracing.

CN123144891APending Publication Date: 2026-11-20NANJING NENGRUI AUTOMATION EQUIP
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611594066.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-10-15
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

Existing automated intelligent terminals for power metering suffer from problems such as task blocking and clock jitter, single-link failure, RTC temperature drift and aging, insufficient accuracy, and the need for recalibration after power failure and restart during the time calibration process, making it difficult to achieve high-precision time assurance on resource-constrained embedded platforms.

Method used

The method adopts a multi-time-source adaptive switching time synchronization method. By configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, historical drift parameters and time synchronization thresholds are loaded. The first-level real-time time synchronization task and the second-level link monitoring task are started, multi-time-source adaptive selection is performed, and the temperature-drift dual-factor prediction model is called for closed-loop correction. The parameters are maintained when power is lost.

Benefits of technology

It achieves high-precision, low-overhead, and robust time assurance on resource-constrained platforms, ensuring the time-series consistency of metering data and the accuracy of billing, and supporting fault tracing.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123144891A_ABST
    Figure CN123144891A_ABST
Patent Text Reader

Abstract

The application provides a multi-time source adaptive switching time correction method and device for a fusion terminal, comprising: system power-on initialization; starting a first real-time time correction task and a second link monitoring task; based on a real-time state set of each time source, performing multi-time source adaptive selection to obtain standard time; calculating a current deviation of the standard time and the current local time, and calling a temperature-drift double-factor prediction model to calculate a predicted drift compensation value of the current period; performing closed-loop correction according to the comparison result of the current deviation and a preset threshold; taking the corrected local time and the deviation data of this correction as new samples, updating the parameters of the temperature-drift double-factor prediction model, and writing the updated parameters into a storage unit for power-off retention. In this way, through double-stage scheduling decoupling blockage, double-source redundant non-disturbance switching, temperature-drift double-factor prediction compensation and power-off retention, high-precision, low-overhead and strong-robust concentrator full-scene time guarantee is realized.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of time synchronization technology, and in particular to a multi-time-source adaptive time synchronization method and apparatus for converged terminals. Background Technology

[0002] Intelligent terminals for power metering automation (such as intelligent fusion terminals for distribution areas and acquisition terminals) are responsible for collecting, storing, and uploading metering data. A unified time reference is a prerequisite for ensuring time consistency, accurate billing, and fault tracing. Currently, terminal time calibration mostly adopts single-link periodic polling: fixed polling is prone to task blocking and clock jitter, and retransmission in weak networks consumes bandwidth; it relies on a single Ethernet or GPRS link, and failure occurs upon interruption; it does not consider RTC temperature drift and aging, and the accumulated deviation continues to increase, making it difficult to meet the accuracy requirement of better than ±0.5s / 24h; the algorithm complexity is high, making it difficult to deploy in a lightweight manner on resource-constrained embedded platforms; it lacks power-off retention and timekeeping compensation, and recalibration is required upon restart. Although individual technologies such as multi-time source switching, dual-mode communication, and drift compensation have been researched, there is still no solution for organically integrating resource-constrained intelligent terminals to solve the above-mentioned collaborative problems. Summary of the Invention

[0003] In view of this, the purpose of the present invention is to provide a multi-time-source adaptive switching and synchronization method and device for converged terminals, which achieves high-precision, low-overhead, and robust time guarantee for concentrators in all scenarios through two-level scheduling decoupling blocking, dual-source redundant and disturbance-free switching, temperature-drift dual-factor prediction compensation and power failure retention.

[0004] In a first aspect, embodiments of the present invention provide a multi-time-source adaptive switching and time synchronization method for a converged terminal. The method includes: system power-on initialization, configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, loading historical drift parameters and time synchronization thresholds, and obtaining the initial local time and the initial state of each time source; starting a primary real-time time synchronization task and a secondary link monitoring task; the primary real-time time synchronization task periodically reads the local time and calculates the time synchronization deviation, and the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain a real-time state set of each time source; based on the real-time state set of each time source, performing multi-time-source adaptive selection to obtain a standard time; calculating the current deviation between the standard time and the current local time, and calling a temperature-drift dual-factor prediction model to calculate the predicted drift compensation value for the current period; performing closed-loop correction based on the comparison result of the current deviation and a preset threshold; using the corrected local time and the deviation data of this correction as new samples to update the parameters of the temperature-drift dual-factor prediction model, and writing the updated parameters into the storage unit for power-off retention.

[0005] In a preferred embodiment of the present invention, the adaptive selection of multiple time sources includes: when the Ethernet link is valid, setting Ethernet as the first priority time source and obtaining a first standard time; when the Ethernet link is invalid, automatically switching to the GPRS link to obtain a second standard time; when both Ethernet and GPRS links are valid, obtaining the first standard time and the second standard time respectively and performing cross-validation; if the deviation between the first standard time and the second standard time is less than a preset fusion threshold, obtaining a fused standard time by weighted averaging according to link confidence; if the deviation between the first standard time and the second standard time is greater than the preset fusion threshold, identifying and isolating abnormal sources, with the higher-priority normal source as the standard.

[0006] In a preferred embodiment of the present invention, the above-mentioned temperature-drift two-factor prediction model is: ΔT_pred=k1×t+k2×(T_cur) T_ref)+b; where t is the cumulative running time since the last full correction, T_cur is the current real-time temperature, T_ref is the preset reference temperature, k1 is the time cumulative drift rate, k2 is the temperature drift coefficient, and b is the initial deviation intercept.

[0007] In a preferred embodiment of the present invention, the above-mentioned initiation of the primary real-time time synchronization task and the secondary link monitoring task includes: the primary real-time time synchronization task runs in a preemptive scheduling manner with a fixed short cycle, performing local clock reading, standard time acquisition triggering, and instant deviation calculation; the secondary link monitoring task runs in a time-slice round-robin scheduling manner with a long cycle, statistically analyzing the round-trip delay and continuous packet loss rate of each time source, and updating the link status identifier; the secondary link monitoring task reads the deviation sequence of the most recent M time synchronization results of the primary real-time time synchronization task and calculates the deviation variance; when the deviation variance is greater than a first variance threshold, it is determined that the time synchronization jitter exceeds the limit, the running cycle of the primary real-time time synchronization task is shortened and its priority is increased; when the deviation variance is less than a second variance threshold and the current drift rate change rate is less than a preset change rate threshold, the running cycle of the primary real-time time synchronization task is extended to reduce system overhead.

[0008] In a preferred embodiment of the present invention, the above method further includes: a timekeeping mode processing step when communication is interrupted: when both the Ethernet link and the GPRS link are determined to be faulty, the system enters an autonomous timekeeping mode; the timestamp of the interruption time, the current time cumulative drift rate k1, and the current temperature are recorded; during the timekeeping period, the real-time temperature is continuously monitored, and the timekeeping compensation value is calculated using the latest temperature-drift dual-factor prediction model trained before the interruption, and the RTC timing is periodically and dynamically fine-tuned to maintain the accuracy of the local time; when any link is restored, the actual cumulative deviation during the timekeeping period is read, the actual cumulative deviation is added as a new extreme sample to the training set of the drift model, and a full correction is performed to achieve the alignment of the local time with the standard time.

[0009] In a preferred embodiment of the present invention, the above-mentioned updating parameters and writing them into the storage unit includes: after each closed-loop correction, assembling the currently updated time cumulative drift rate, temperature drift coefficient, intercept, deviation threshold, and the timestamp of the most recent full correction into a parameter set and writing it into the non-volatile storage area of ​​the storage unit; when the system is powered on and initialized again, directly loading the parameter set from the storage unit, and using the loaded time cumulative drift rate, temperature drift coefficient, and intercept as the initial fitting parameters of the temperature-drift two-factor prediction model.

[0010] In a preferred embodiment of the present invention, before performing multi-time-source adaptive selection based on the real-time state set of each time source and obtaining the standard time, the method further includes: a secondary link monitoring task maintaining the quality time series of each time source, and using a sliding window linear prediction model to predict the link quality trend value within the next P time synchronization periods; when the link quality trend value reaches a preset switching threshold, the link handshake and protocol stack warm-up of the backup time source are started in advance, and a time synchronization session cache for the backup link is established; when the current primary link actually deteriorates to the failure threshold, the time synchronization session is switched to the warmed-up backup link.

[0011] Secondly, embodiments of the present invention also provide a multi-time-source adaptive switching and synchronization device for a converged terminal. The device includes: a system power-on initialization module for initializing the system upon power-on, configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, loading historical drift parameters and synchronization thresholds, and acquiring the initial local time and the initial state of each time source; and a task startup module for starting a primary real-time synchronization task and a secondary link monitoring task. The primary real-time synchronization task periodically reads the local time and calculates the synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain a real-time state set for each time source. The system includes: a standard time acquisition module for acquiring standard time by performing adaptive selection of multiple time sources based on the real-time state sets of each time source; a data calculation module for calculating the current deviation between the standard time and the current local time, and calling the temperature-drift dual-factor prediction model to calculate the predicted drift compensation value for the current period; a closed-loop correction execution module for performing closed-loop correction based on the comparison result between the current deviation and the preset threshold; and a parameter update module for updating the parameters of the temperature-drift dual-factor prediction model by using the corrected local time and the deviation data of this correction as new samples, and writing the updated parameters to the storage unit for power-off retention.

[0012] Thirdly, embodiments of the present invention also provide an electronic device, including a processor and a memory, wherein the memory stores computer-executable instructions that can be executed by the processor, and the processor executes the computer-executable instructions to implement the multi-time source adaptive switching time synchronization method for a converged terminal described in the first aspect.

[0013] Fourthly, embodiments of the present invention also provide a computer-readable storage medium storing computer-executable instructions. When the computer-executable instructions are invoked and executed by a processor, the computer-executable instructions cause the processor to implement the multi-time source adaptive switching time synchronization method for a converged terminal described in the first aspect.

[0014] The embodiments of the present invention bring the following beneficial effects: This invention provides a method and apparatus for adaptive switching and synchronization of multiple time sources in a converged terminal. Upon system power-on initialization, a dual-mode communication unit, an RTC clock unit, and a storage unit are configured. Historical drift parameters and synchronization thresholds are loaded, and the initial local time and the initial state of each time source are obtained. A primary real-time synchronization task and a secondary link monitoring task are initiated. The primary real-time synchronization task periodically reads the local time and calculates the synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain a real-time state set for each time source. Based on the real-time state set of each time source, adaptive selection of multiple time sources is performed to obtain a standard time. The current deviation between the standard time and the current local time is calculated, and a temperature-drift dual-factor prediction model is called to calculate the predicted drift compensation value for the current period. Closed-loop correction is performed based on the comparison result between the current deviation and a preset threshold. The corrected local time and the deviation data from this correction are used as new samples to update the parameters of the temperature-drift dual-factor prediction model, and the updated parameters are written to the storage unit for power-off retention. This approach achieves high-precision, low-overhead, and robust time assurance for the concentrator across all scenarios through two-level scheduling to decouple blocking, dual-source redundant and disturbance-free switching, temperature-drift dual-factor prediction compensation, and power-loss retention.

[0015] Other features and advantages of this disclosure will be set forth in the following description, or some features and advantages may be inferred from the description or determined without doubt, or may be learned by practicing the techniques described above.

[0016] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description

[0017] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.

[0018] Figure 1A flowchart of a multi-time-source adaptive switching and time synchronization method for a converged terminal provided in an embodiment of the present invention; Figure 2 A schematic diagram of a multi-time-source adaptive switching and synchronization device for a converged terminal is provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

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

[0020] Intelligent terminals for power metering automation (such as intelligent fusion terminals for distribution areas and acquisition terminals) are responsible for collecting, storing, and uploading metering data. A unified time reference is a prerequisite for ensuring time consistency, accurate billing, and fault tracing. Currently, terminal time calibration mostly adopts single-link periodic polling: fixed polling is prone to task blocking and clock jitter, and retransmission in weak networks consumes bandwidth; it relies on a single Ethernet or GPRS link, and failure occurs upon interruption; it does not consider RTC temperature drift and aging, and the accumulated deviation continues to increase, making it difficult to meet the accuracy requirement of better than ±0.5s / 24h; the algorithm complexity is high, making it difficult to deploy in a lightweight manner on resource-constrained embedded platforms; it lacks power-off retention and timekeeping compensation, and recalibration is required upon restart. Although individual technologies such as multi-time source switching, dual-mode communication, and drift compensation have been researched, there is still no solution for organically integrating resource-constrained intelligent terminals to solve the above-mentioned collaborative problems.

[0021] Based on this, the present invention provides a multi-time-source adaptive switching and synchronization method and apparatus for a converged terminal. This method can be implemented through system power-on initialization, configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, loading historical drift parameters and synchronization thresholds, and obtaining the initial local time and the initial state of each time source. A primary real-time synchronization task and a secondary link monitoring task are initiated. The primary real-time synchronization task periodically reads the local time and calculates the synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain a real-time state set for each time source. Based on the real-time state set of each time source, multi-time-source adaptive selection is performed to obtain a standard time. The current deviation between the standard time and the current local time is calculated, and the temperature-drift dual-factor prediction model is called to calculate the predicted drift compensation value for the current period. Closed-loop correction is performed based on the comparison result between the current deviation and a preset threshold. The corrected local time and the deviation data from this correction are used as new samples to update the parameters of the temperature-drift dual-factor prediction model, and the updated parameters are written to the storage unit for power-off retention. This approach achieves high-precision, low-overhead, and robust time assurance for the concentrator across all scenarios through two-level scheduling to decouple blocking, dual-source redundant and disturbance-free switching, temperature-drift dual-factor prediction compensation, and power-loss retention.

[0022] To facilitate understanding of this embodiment, a multi-time source adaptive switching and time synchronization method for converged terminals disclosed in this embodiment of the invention will first be described in detail.

[0023] Example 1 This invention provides a multi-time-source adaptive switching time synchronization method for converged terminals. Figure 1 This is a flowchart illustrating a multi-time-source adaptive handover and time synchronization method for a converged terminal, provided as an embodiment of the present invention. Figure 1 As shown, the multi-time-source adaptive switching time synchronization method for fusion terminals may include the following steps: Step S101: The system is powered on and initialized. The dual-mode communication unit, RTC clock unit and storage unit are configured. Historical drift parameters and time synchronization thresholds are loaded. The initial local time and the initial state of each time source are obtained.

[0024] The initialization process includes: MCU clock and peripheral initialization, Ethernet PHY initialization and auto-negotiation, GPRS module power-on and AT command handshake, RTC chip I²C / SPI interface initialization, storage unit SPI interface initialization, parameter loading, and cache clearing.

[0025] Specifically, the MCU's main frequency is configured to 400MHz (taking STM32MP1 as an example), and the Ethernet MAC, I²C, SPI, and UART peripheral clocks are enabled. The RTC chip DS3231 is initialized via the I²C bus, and its time register is read to obtain the initial local time. The parameter set stored at address 0x0000 of the DataFlash (such as AT45DB161D) is read via the SPI bus, and the following parameters are parsed: time cumulative drift rate k1 (unit: seconds / second, representing the frequency offset rate of the RTC due to factors such as crystal aging over time), temperature drift coefficient k2 (unit: seconds / °C, representing the RTC frequency offset coefficient caused by the ambient temperature deviating from the reference temperature), initial deviation intercept b (unit: seconds, representing the fixed deviation of zero cumulative time at the reference temperature), deviation threshold ΔT_th (unit: seconds, used to determine full correction or incremental compensation), and the timestamp of the last full correction (used to calculate the cumulative running time t). If the verification fails, default values ​​are loaded: k1=0, k2=0, b=0, ΔT_th=1.0 seconds, indicating that the model initially has no prior knowledge of drift and uses the default time synchronization threshold. The Ethernet PHY chip (e.g., LAN8720) connects to the MCU via the RMII interface and reads the BMSR register to determine the link status after initialization. The GPRS module (e.g., EC20) connects to the MCU via UART and sends AT commands: AT, ATE0, AT+CPIN, AT+CGREG to detect the SIM card and network registration status. The NTP request / response cache and deviation sample queue are cleared, and the shared memory area between tasks is initialized.

[0026] In terms of effectiveness, it ensures that the system has a local time base and historical drift knowledge immediately after power-on, avoiding the accuracy gap during cold start; the loading of parameters after power failure allows the system to enter a high-precision timekeeping state without retraining.

[0027] Furthermore, during initialization, the temperature compensation register of the RTC chip can be configured. For example, the DS3231 has an internal temperature compensation function, and coarse adjustments can be made by writing to the aging offset register via I²C. Additionally, bad block detection can be performed on the storage units. If the parameter storage area is found to be damaged, the system automatically switches to the backup storage area and issues an alarm. The initial state of the time source can also include the NTP server domain name resolution status, GPRS signal strength RSSI value, etc.

[0028] Step S102: Start the first-level real-time time synchronization task and the second-level link monitoring task.

[0029] The first-level real-time time synchronization task periodically reads the local time and calculates the time synchronization deviation, while the second-level link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time status set of each time source.

[0030] Among them, the first-level real-time time synchronization task is a high-priority task, responsible for periodically performing core time synchronization operations, such as reading RTC, triggering standard time acquisition, and calculating deviation.

[0031] Among them, the secondary link monitoring task is a low-priority background task, responsible for monitoring link quality and updating the status set.

[0032] The link quality parameters include: physical connectivity status, NTP / SNTP round-trip time (RTT), continuous packet loss rate, and GPRS signal strength value. The triggering conditions for determining link failure are: physical link down, or three consecutive time request messages time out without response, or RTT exceeding 500ms, or continuous packet loss rate greater than 10%. If any condition is met, the time source is marked as unavailable.

[0033] The real-time status set is a structured data collection of each time source, including its current availability, quality level, and latency.

[0034] The process involves initiating a primary real-time time synchronization task and a secondary link monitoring task. The primary real-time time synchronization task operates with a fixed short cycle using preemptive scheduling, performing local clock reading, standard time acquisition triggering, and real-time deviation calculation. The secondary link monitoring task operates with a long cycle using time-slice round-robin scheduling, calculating the round-trip latency and continuous packet loss rate of each time source, and updating the link status identifier. The secondary link monitoring task reads the deviation sequence of the most recent M time synchronization results from the primary real-time time synchronization task and calculates the deviation variance. When the deviation variance exceeds a first variance threshold, the time synchronization jitter is deemed excessive, the running cycle of the primary real-time time synchronization task is shortened, and its priority is increased. When the deviation variance is less than a second variance threshold and the current drift rate change rate is less than a preset change rate threshold, the running cycle of the primary real-time time synchronization task is extended to reduce system overhead.

[0035] In practical applications, tasks are created in an RTOS (such as FreeRTOS) using: xTaskCreate(TimeSyncTask, "Sync", ..., priority 3); xTaskCreate(LinkMonitorTask, "Monitor", ..., priority 10); Each cycle of a first-level task involves: reading the RTC time - sending a request to the SNTP client - calculating the deviation ΔT - writing the deviation to a shared queue; Each cycle of a second-level task involves: reading the Ethernet PHY register, querying the GPRS AT+CSQ and AT+CGREG, sending NTP probe messages to calculate RTT and packet loss rate - updating the state set structure; The state set structure contains: {source type, availability flag, RTT_ms, packet loss rate, RSSI, last update time}.

[0036] In practical applications, task separation avoids time synchronization being blocked by link monitoring, ensuring real-time performance; the state set provides a basis for subsequent adaptive source selection.

[0037] Furthermore, Level 1 tasks can be triggered by timer interrupts, releasing semaphores in the interrupt service routine, with the task waiting on the semaphore. Level 2 tasks can use software timer callbacks, setting event flags in the callbacks for task processing. Shared memory areas must be protected with mutex locks to prevent race conditions. The real-time state set can include a time source confidence score, with the initial score set based on historical success rates.

[0038] Step S103: Based on the real-time state set of each time source, perform multi-time source adaptive selection to obtain the standard time.

[0039] In practical applications, the status set is queried. If Ethernet is available, a request is sent to ntp.aliyun.com via SNTP to obtain the first standard time. If Ethernet is unavailable but GPRS is available, a TCP connection is established via GPRS to send an NTP request to port 123 of time.nist.gov to obtain the second standard time. If both links are available, the two times are obtained simultaneously, and the difference is calculated. If it is less than the fusion threshold (e.g., 0.5 seconds), it is weighted inversely according to RTT. If the difference is greater than the fusion threshold, the abnormal source is isolated.

[0040] In terms of effectiveness, it improves the reliability of standard time and avoids time synchronization errors caused by single-source anomalies.

[0041] Furthermore, a third priority time source, such as a BeiDou / GPS module, can be set and activated when both links fail. Cross-validation can also include historical deviation statistics of the time sources; if a source has large deviations multiple times consecutively, its confidence weight will be automatically reduced.

[0042] The multi-time source adaptive selection includes: when the Ethernet link is valid, setting Ethernet as the first priority time source and obtaining the first standard time; when the Ethernet link is invalid, automatically switching to the GPRS link to obtain the second standard time; when both Ethernet and GPRS links are valid, obtaining the first and second standard times respectively and performing cross-validation; if the deviation between the first and second standard times is less than a preset fusion threshold, obtaining the fused standard time by weighted average according to link confidence; if the deviation between the first and second standard times is greater than the preset fusion threshold, identifying and isolating abnormal sources, and using the higher-priority normal source as the standard.

[0043] The cross-validation and anomaly source isolation include: when both links are valid, obtaining T1 and T2 respectively and calculating the difference ΔT_diff=|T1 T2|; If ΔT_diff is less than the first fusion threshold, then the confidence weight is configured according to the inverse ratio of the link round-trip time (RTT), i.e., W1=RTT2 / (RTT1+RTT2), W2=RTT1 / (RTT1+RTT2), and the fusion standard time T_std=W1×T1+W2×T2; If ΔT_diff is greater than or equal to the first fusion threshold but less than the second fusion threshold, the side with the larger delay or higher packet loss rate is determined to be a suspected abnormal source, its confidence weight is set to zero, and the time of the normal source on the other side is used as the standard. At the same time, an abnormal alarm flag is generated and reported to the master station; If ΔT_diff is greater than or equal to the second fusion threshold, it is determined that the dual time sources are seriously out of sync, the use of the external time source is suspended, the RTC local time arbitration mechanism is started, and the dual-link hardware reconnection and protocol renegotiation are forcibly triggered.

[0044] In this context, a valid Ethernet link means that PHYLinkUp is active and NTP packets can be successfully sent and received. The first standard time is T1. An invalid Ethernet link includes Link Down or three consecutive NTP timeouts. The second standard time is T2.

[0045] In practical applications, the PHY BMSR register Bit2=1 is read, an SNTP request is sent to ntp.aliyun.com, with a timeout of 5 seconds, and the response packet is parsed; GPRS is attached via AT+CGATT=1, TCP is established via AT+CIPSTART, a request is sent to NTP server port 123, and T2 is obtained; simultaneously, T1 and T2 are acquired, and ΔT_diff=|T1 T2|;W1=RTT2 / (RTT1+RTT2), W2=RTT1 / (RTT1+RTT2), T_std=W1T1+W2T2;If ΔT_diff>0.5 seconds, mark the side with larger RTT or higher packet loss rate as abnormal, set its weight to zero, and use the other side's time.

[0046] The method, based on the real-time state sets of each time source, performs multi-time source adaptive selection before obtaining the standard time. It also includes: a secondary link monitoring task maintaining the quality time series of each time source and using a sliding window linear prediction model to predict the link quality trend value within the next P time synchronization periods; when the link quality trend value reaches the preset switching threshold, the link handshake and protocol stack warm-up of the backup time source are started in advance, and the time synchronization session cache of the backup link is established; when the current primary link actually deteriorates to the failure threshold, the time synchronization session is switched to the warmed-up backup link.

[0047] Step S104: Calculate the current deviation between the standard time and the current local time, and call the temperature-drift two-factor prediction model to calculate the predicted drift compensation value for the current period.

[0048] The temperature-drift two-factor prediction model is: ΔT_pred=k1×t+k2×(T_cur) T_ref)+b.

[0049] Where t is the cumulative running time since the last full calibration, T_cur is the current real-time temperature, T_ref is the preset reference temperature, k1 is the time cumulative drift rate, k2 is the temperature drift coefficient, and b is the initial deviation intercept.

[0050] Specifically, read the current time from the RTC and the current temperature from the temperature sensor; ΔT = T_std T_local; calculates t = current time The last full calibration time; substitute into the formula to calculate ΔT_comp.

[0051] Furthermore, the temperature sensor can be integrated into the RTC chip (such as the DS3231's built-in temperature sensor, with an accuracy of ±3℃), or it can be an external thermistor acquired via an ADC. Model parameters can be updated online using recursive least squares, without needing to store all historical samples.

[0052] Step S105: Perform closed-loop correction based on the comparison result between the current deviation and the preset threshold.

[0053] Specifically, compare |ΔT| with ΔT_th; full correction: write standard time to the RTC time register via I²C; incremental fine-tuning: decompose ΔT_comp into multiple small steps (e.g., 10ms), and adjust once in each time synchronization cycle; after correction, read the local time, calculate the residual deviation, and if it exceeds the limit, trigger a secondary task re-evaluation.

[0054] Furthermore, during incremental fine-tuning, the RTC calibration register (such as the AgingOffset register of the DS3231) can be modified or the compensation value can be accumulated via software, incrementing or decrementing the timer in each second interrupt. Before full calibration, RTC write protection can be disabled and re-enabled after the write operation.

[0055] The closed-loop correction further includes: setting a deviation threshold ΔT_th; performing full jump correction when |ΔT|>ΔT_th, directly setting the RTC clock to the standard time T_std; performing incremental fine-tuning when |ΔT|≤ΔT_th, making small incremental corrections to the RTC's timing register according to the predicted drift compensation value ΔT_comp; and calculating the actual residual deviation ΔT_res=|T_local_after after the correction is completed. If ΔT_res exceeds the allowable residual error range, the deviation information of this correction is marked as an abnormal feedback sample and sent to the secondary task, triggering the secondary task to immediately perform a comprehensive reassessment of the link quality.

[0056] Step S106: Use the corrected local time and the deviation data of this correction as new samples to update the parameters of the temperature-drift two-factor prediction model, and write the updated parameters into the storage unit for power-off retention.

[0057] In practical applications, (t, T_cur, ΔT) is added to the queue; if the queue is full, the oldest sample is removed; when the number of samples is ≥10, the parameters are updated by solving the normal equation using the least squares method; the DataFlash sector is erased via SPI and a 24-byte parameter set is written; the verification is read back.

[0058] Furthermore, the parameter set can be enhanced with a CRC checksum. During writing, the system first erases and then reprograms; the number of erase cycles is limited, and alternating dual-zone storage (A / B zones) can be used to extend its lifespan. If zone A fails verification during loading, zone B is read instead.

[0059] The process of updating parameters and writing them to the storage unit includes: after each closed-loop correction, assembling the currently updated time cumulative drift rate, temperature drift coefficient, intercept, deviation threshold, and the timestamp of the most recent full correction into a parameter set and writing it to the non-volatile storage area of ​​the storage unit; when the system is initialized for the next power-on, the parameter set is directly loaded from the storage unit, and the loaded time cumulative drift rate, temperature drift coefficient, and intercept are used as the initial fitting parameters for the temperature-drift two-factor prediction model.

[0060] Furthermore, the method also includes: timekeeping mode processing steps during communication interruption: when both the Ethernet link and the GPRS link are determined to be faulty, the system enters autonomous timekeeping mode; records the timestamp of the interruption, the current time cumulative drift rate k1, and the current temperature; during the timekeeping period, continuously monitors the real-time temperature, calculates the timekeeping compensation value using the latest temperature-drift dual-factor prediction model trained before the interruption, and periodically dynamically fine-tunes the RTC timing to maintain local time accuracy; when any link is restored, reads the actual cumulative deviation during the timekeeping period, adds the actual cumulative deviation as a new extreme sample to the training set of the drift model, and performs a full correction to achieve alignment between local time and standard time.

[0061] The multi-time-source adaptive switching and synchronization method for converged terminals provided in this invention can be implemented through system power-on initialization, configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, loading historical drift parameters and synchronization thresholds, and obtaining the initial local time and the initial state of each time source; starting a primary real-time synchronization task and a secondary link monitoring task; the primary real-time synchronization task periodically reads the local time and calculates the synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time state set of each time source; based on the real-time state set of each time source, performing multi-time-source adaptive selection to obtain a standard time; calculating the current deviation between the standard time and the current local time, and calling the temperature-drift dual-factor prediction model to calculate the predicted drift compensation value for the current period; performing closed-loop correction based on the comparison result of the current deviation and the preset threshold; using the corrected local time and the deviation data of this correction as new samples to update the parameters of the temperature-drift dual-factor prediction model, and writing the updated parameters into the storage unit for power-off retention. This approach achieves high-precision, low-overhead, and robust time assurance for the concentrator across all scenarios through two-level scheduling to decouple blocking, dual-source redundant and disturbance-free switching, temperature-drift dual-factor prediction compensation, and power-loss retention.

[0062] Example 2 Corresponding to the above method embodiments, this invention provides a multi-time-source adaptive switching and synchronization device for a fusion terminal. Figure 2 This is a schematic diagram of a multi-time-source adaptive switching and synchronization device for a fusion terminal provided in an embodiment of the present invention, as shown below. Figure 2 As shown, the multi-time-source adaptive switching and synchronization device for fusion terminals may include: The system power-on initialization module 201 is used for system power-on initialization, configuring the dual-mode communication unit, RTC clock unit and storage unit, loading historical drift parameters and time synchronization thresholds, and obtaining the initial local time and the initial state of each time source.

[0063] The task initiation module 202 is used to initiate the primary real-time time synchronization task and the secondary link monitoring task. The primary real-time time synchronization task periodically reads the local time and calculates the time synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time status set of each time source.

[0064] The standard time acquisition module 203 is used to perform multi-time source adaptive selection based on the real-time status set of each time source to acquire the standard time.

[0065] The data calculation module 204 is used to calculate the current deviation between the standard time and the current local time, and to call the temperature-drift two-factor prediction model to calculate the predicted drift compensation value for the current period.

[0066] The closed-loop correction execution module 205 is used to perform closed-loop correction based on the comparison result between the current deviation and the preset threshold.

[0067] The parameter update module 206 is used to update the parameters of the temperature-drift two-factor prediction model by taking the corrected local time and the deviation data of this correction as new samples, and write the updated parameters into the storage unit for power-off retention.

[0068] The multi-time-source adaptive switching and synchronization device for converged terminals provided in this invention can be initialized upon system power-on, configuring a dual-mode communication unit, an RTC clock unit, and a storage unit, loading historical drift parameters and synchronization thresholds, and obtaining the initial local time and the initial state of each time source; starting a primary real-time synchronization task and a secondary link monitoring task; the primary real-time synchronization task periodically reads the local time and calculates the synchronization deviation, while the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time state set of each time source; based on the real-time state set of each time source, performing multi-time-source adaptive selection to obtain the standard time; calculating the current deviation between the standard time and the current local time, and calling the temperature-drift dual-factor prediction model to calculate the predicted drift compensation value for the current period; performing closed-loop correction based on the comparison result of the current deviation and the preset threshold; using the corrected local time and the deviation data of this correction as new samples to update the parameters of the temperature-drift dual-factor prediction model, and writing the updated parameters into the storage unit for power-off retention. This approach achieves high-precision, low-overhead, and robust time assurance for the concentrator across all scenarios through two-level scheduling to decouple blocking, dual-source redundant and disturbance-free switching, temperature-drift dual-factor prediction compensation, and power-loss retention.

[0069] In this embodiment, the method is further configured to: when the Ethernet link is valid, set Ethernet as the first priority time source and obtain the first standard time; when the Ethernet link is invalid, automatically switch to the GPRS link to obtain the second standard time; when both Ethernet and GPRS links are valid, obtain the first standard time and the second standard time respectively and perform cross-validation; if the deviation between the first standard time and the second standard time is less than a preset fusion threshold, obtain the fused standard time by weighted average according to the link confidence; if the deviation between the first standard time and the second standard time is greater than the preset fusion threshold, determine the abnormal source and isolate it, and take the normal source with higher priority as the standard.

[0070] In this embodiment, the temperature-drift two-factor prediction model is: ΔT_pred=k1×t+k2×(T_cur) T_ref)+b; where t is the cumulative running time since the last full correction, T_cur is the current real-time temperature, T_ref is the preset reference temperature, k1 is the time cumulative drift rate, k2 is the temperature drift coefficient, and b is the initial deviation intercept.

[0071] In this embodiment, the primary real-time time synchronization task is run in a preemptive scheduling manner with a fixed short cycle, performing local clock reading, standard time acquisition triggering, and instant deviation calculation; the secondary link monitoring task is run in a time-slice round-robin scheduling manner with a long cycle, statistically analyzing the round-trip delay and continuous packet loss rate of each time source, and updating the link status identifier; the secondary link monitoring task reads the deviation sequence of the most recent M time synchronization results of the primary real-time time synchronization task and calculates the deviation variance; when the deviation variance is greater than the first variance threshold, it is determined that the time synchronization jitter exceeds the limit, the running cycle of the primary real-time time synchronization task is shortened and its priority is increased; when the deviation variance is less than the second variance threshold and the current drift rate change rate is less than the preset change rate threshold, the running cycle of the primary real-time time synchronization task is extended to reduce system overhead.

[0072] In this embodiment, the system is further configured to enter an autonomous timekeeping mode when both the Ethernet link and the GPRS link are determined to be faulty; record the timestamp of the interruption, the current cumulative time drift rate k1, and the current temperature; during the timekeeping period, continuously monitor the real-time temperature, calculate the timekeeping compensation value using the latest temperature-drift dual-factor prediction model trained before the interruption, periodically and dynamically fine-tune the RTC timing to maintain local time accuracy; when any link is restored, read the actual cumulative deviation during the timekeeping period, add the actual cumulative deviation as a new extreme sample to the training set of the drift model, and perform a full correction to achieve alignment between local time and standard time.

[0073] In this embodiment, after each closed-loop correction, the updated time cumulative drift rate, temperature drift coefficient, intercept, deviation threshold, and the timestamp of the most recent full correction are assembled into a parameter set and written into the non-volatile storage area of ​​the storage unit; when the system is powered on and initialized again, the parameter set is directly loaded from the storage unit, and the loaded time cumulative drift rate, temperature drift coefficient, and intercept are used as the initial fitting parameters of the temperature-drift two-factor prediction model.

[0074] In this embodiment, the secondary link monitoring task maintains the quality time series of each time source and uses a sliding window linear prediction model to predict the link quality trend value within the next P time synchronization periods. When the link quality trend value reaches the preset switching threshold, the link handshake and protocol stack warm-up of the backup time source are started in advance, and the time synchronization session cache of the backup link is established. When the current primary link actually deteriorates to the failure threshold, the time synchronization session is switched to the warmed-up backup link.

[0075] The device provided in this embodiment of the invention has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.

[0076] Example 3 This invention also provides an electronic device for running the above-described multi-time-source adaptive switching time synchronization method for converged terminals; see also Figure 3 The diagram shows the structure of an electronic device, which includes a memory 500 and a processor 501. The memory 500 stores one or more computer instructions, which are executed by the processor 501 to implement the above-mentioned multi-time source adaptive switching synchronization method for fusion terminals.

[0077] Furthermore, Figure 3 The electronic device shown also includes a bus 502 and a communication interface 503. The processor 501, the communication interface 503, and the memory 500 are connected via the bus 502.

[0078] The memory 500 may include high-speed random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 503 (which can be wired or wireless), such as the Internet, wide area network, local area network, metropolitan area network, etc. The bus 502 can be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 3 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.

[0079] Processor 501 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of processor 501 or by instructions in software form. Processor 501 can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 500, and processor 501 reads information from memory 500 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.

[0080] This invention also provides a computer-readable storage medium storing computer-executable instructions. When these computer-executable instructions are called and executed by a processor, they cause the processor to implement the above-described multi-time-source adaptive switching synchronization method for fused terminals. For specific implementation details, please refer to the method embodiments, which will not be repeated here.

[0081] The computer program product for performing a multi-time-source adaptive switching and synchronization method for a converged terminal provided in this embodiment of the invention includes a computer-readable storage medium storing non-volatile program code executable by a processor. The instructions included in the program code can be used to execute the methods described in the preceding method embodiments. For specific implementation details, please refer to the method embodiments, which will not be repeated here.

[0082] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0083] In the several embodiments provided by this invention, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. The apparatus embodiments described above are merely illustrative. For example, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Additionally, the coupling or direct coupling or communication connection shown or discussed may be through some communication interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.

[0084] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0085] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0086] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0087] Finally, it should be noted that the above-described embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A multi-time-source adaptive handover time synchronization method for converged terminals, characterized in that, The method includes: The system is powered on and initialized, configuring the dual-mode communication unit, RTC clock unit and storage unit, loading historical drift parameters and time synchronization thresholds, and obtaining the initial local time and the initial state of each time source; Initiate a primary real-time time synchronization task and a secondary link monitoring task; the primary real-time time synchronization task periodically reads the local time and calculates the time synchronization deviation, and the secondary link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time status set of each time source; Based on the real-time state sets of each time source, multi-time source adaptive selection is performed to obtain the standard time; Calculate the current deviation between the standard time and the current local time, and call the temperature-drift two-factor prediction model to calculate the predicted drift compensation value for the current period; Based on the comparison result between the current deviation and the preset threshold, closed-loop correction is performed; The corrected local time and the deviation data of this correction are used as new samples to update the parameters of the temperature-drift two-factor prediction model, and the updated parameters are written to the storage unit for power-off retention.

2. The method according to claim 1, characterized in that, Adaptive selection of multiple time sources, including: When the Ethernet link is active, set Ethernet as the first priority time source and obtain the first standard time. When the Ethernet link becomes invalid, it automatically switches to the GPRS link to obtain the second standard time. When both Ethernet and GPRS links are valid, the first standard time and the second standard time are obtained and cross-validated respectively. If the deviation between the first standard time and the second standard time is less than the preset fusion threshold, the fusion standard time is obtained by weighted average based on the link confidence. If the deviation between the first standard time and the second standard time is greater than the preset fusion threshold, the abnormal source is identified and isolated, and the normal source with higher priority is used.

3. The method according to claim 1, characterized in that, The temperature-drift two-factor prediction model is: ΔT_pred=k1×t+k2×(T_cur) T_ref)+b; Where t is the cumulative running time since the last full calibration, T_cur is the current real-time temperature, T_ref is the preset reference temperature, k1 is the time cumulative drift rate, k2 is the temperature drift coefficient, and b is the initial deviation intercept.

4. The method according to claim 1, characterized in that, The initiation of the first-level real-time time synchronization task and the second-level link monitoring task includes: The first-level real-time time synchronization task runs in a preemptive scheduling manner with a fixed short cycle, performing local clock reading, standard time acquisition triggering, and instant deviation calculation. The secondary link monitoring task is run in a long-term time-slice round-robin schedule, which counts the round-trip delay and continuous packet loss rate of each time source and updates the link status identifier. The secondary link monitoring task reads the deviation sequence of the most recent M time synchronization results of the primary real-time time synchronization task and calculates the deviation variance. When the variance of the deviation is greater than the first variance threshold, the time synchronization jitter is determined to be excessive, the running cycle of the first-level real-time time synchronization task is shortened and its priority is increased. When the deviation variance is less than the second variance threshold and the current drift rate change rate is less than the preset change rate threshold, the running cycle of the first-level real-time time synchronization task is extended to reduce system overhead.

5. The method according to claim 1, characterized in that, The method also includes: timekeeping mode handling steps when communication is interrupted: When both the Ethernet link and the GPRS link are determined to be faulty, the system enters autonomous timekeeping mode; it records the timestamp of the interruption, the current cumulative time drift rate k1, and the current temperature. During the timekeeping period, the real-time temperature is continuously monitored, and the timekeeping compensation value is calculated using the temperature-drift dual-factor prediction model that was most recently trained before the interruption. The RTC timing is then periodically and dynamically fine-tuned to maintain local time accuracy. Once any link is restored, the actual cumulative deviation during the timekeeping period is read, and the actual cumulative deviation is added as a new extreme sample to the training set of the drift model. A full correction is then performed to align the local time with the standard time.

6. The method according to claim 1, characterized in that, Updating parameters and writing them to the storage unit includes: After each closed-loop correction, the updated time cumulative drift rate, temperature drift coefficient, intercept, deviation threshold, and the timestamp of the most recent full correction are assembled into a parameter set and written into the non-volatile storage area of ​​the storage unit. When the system is powered on and initialized again, the parameter set is loaded directly from the storage unit, and the loaded time cumulative drift rate, temperature drift coefficient, and intercept are used as the initial fitting parameters of the temperature-drift two-factor prediction model.

7. The method according to claim 1, characterized in that, Based on the real-time state sets of each time source, before performing multi-time source adaptive selection and obtaining the standard time, the method further includes: The secondary link monitoring task maintains the quality time series of each time source and uses a sliding window linear prediction model to predict the link quality trend value within the next P time synchronization periods. When the link quality trend value reaches the preset switching threshold, the link handshake and protocol stack warm-up of the backup time source are started in advance, and the time synchronization session cache of the backup link is established. When the current primary link actually degrades to the failure threshold, the time synchronization session will be switched to the pre-warmed backup link.

8. A multi-time-source adaptive switching and time synchronization device for a converged terminal, characterized in that, The device includes: The system power-on initialization module is used for system power-on initialization, configuring the dual-mode communication unit, RTC clock unit and storage unit, loading historical drift parameters and time synchronization thresholds, and obtaining the initial local time and the initial state of each time source; The task initiation module is used to initiate a first-level real-time time synchronization task and a second-level link monitoring task. The first-level real-time time synchronization task periodically reads the local time and calculates the time synchronization deviation, while the second-level link monitoring task periodically monitors the link quality parameters of each time source to obtain the real-time status set of each time source. The standard time acquisition module is used to perform multi-time source adaptive selection based on the real-time status set of each time source to acquire the standard time. The data calculation module is used to calculate the current deviation between the standard time and the current local time, and to call the temperature-drift two-factor prediction model to calculate the predicted drift compensation value for the current period. The closed-loop correction execution module is used to perform closed-loop correction based on the comparison result between the current deviation and the preset threshold. The parameter update module is used to update the parameters of the temperature-drift two-factor prediction model by taking the corrected local time and the deviation data of this correction as new samples, and write the updated parameters into the storage unit for power-off retention.

9. An electronic device, characterized in that, The device includes a processor and a memory, the memory storing computer-executable instructions that can be executed by the processor, the processor executing the computer-executable instructions to implement the multi-time-source adaptive switching time synchronization method for a converged terminal as described in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the multi-time-source adaptive switching time synchronization method for a converged terminal as described in any one of claims 1 to 7.