Bluetooth equipment high-precision time synchronization method

By employing a high-precision time synchronization method for Bluetooth devices, utilizing target number verification and minimum time delay calibration mechanisms, and combining a dynamic time following process, the problem of accumulated Bluetooth BLE time synchronization errors was solved, achieving high-precision and stable time synchronization.

CN121397709APending Publication Date: 2026-01-23SHANGHAI XIAOGAN INTELLIGENT TECHNOLOGY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202511842316.X
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-12-09
Publication Date
2026-01-23

AI Technical Summary

Technical Problem

Existing Bluetooth BLE time synchronization solutions cannot achieve high-precision synchronization. The random value of the initial clock causes the synchronization error to accumulate and increase, affecting the reliability of data acquisition and device collaboration.

Method used

The master device sends the first synchronization clock signal to determine whether it is the first time sending and adjusts the local clock of the slave device. A target number verification and minimum time delay calibration mechanism is introduced, combined with the time dynamic following process, to correct clock drift and task scheduling delay in real time.

Benefits of technology

It achieves a closed loop for Bluetooth device time synchronization, from initial alignment to high-precision and stable operation, improving synchronization accuracy and avoiding the effects of initial deviation and transmission delay, making it suitable for scenarios requiring long-term continuous operation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121397709A_ABST
    Figure CN121397709A_ABST
Patent Text Reader

Abstract

The invention provides a high-precision time synchronization method for Bluetooth equipment, which comprises the following steps: S1, sending a first synchronous clock signal to slave equipment by master equipment, S2, judging whether the signal is sent for the first time or not, if so, executing S3, and otherwise, executing S4. S3, after the slave device receives the signal, a local clock is adjusted according to the receiving timestamp; s4, after the slave device adjusts the local clock by comparing the moment of receiving the signal with the moment of the appointed time point, S5, judging whether the number of times of receiving the signal by the slave device exceeds a target number of times and the condition that the moment of the appointed time point is later than the receiving time determined by the local clock does not occur within the target number of times, if so, executing S6, and if not, executing S1; and S6, adjusting the local clock of the slave device to a target time length, wherein the length is the minimum time delay from the time when the master device sends the signal to the time when the slave device receives the signal. In order to avoid influence of long-term accumulation of deviation on synchronization precision, a time dynamic following process is also provided. According to the invention, the time synchronization precision of the Bluetooth device can be effectively improved.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The application belongs to the technical field of clock synchronization, and particularly relates to a high-precision time synchronization method for Bluetooth devices. BACKGROUND

[0002] With the rapid development of the Internet of Things and smart wear, Bluetooth BLE technology is widely used in various device interconnection scenarios due to its advantages of low power consumption, low cost, stable short-distance communication, etc. In many practical applications, the time synchronization precision between master and slave BLE devices directly affects the accuracy of data collection and the reliability of device cooperation. For example, when collecting environmental data through multi-sensor networking, if the slave devices are not synchronized with the master device, the time stamp of the collected data will be deviated, which will affect the subsequent data fusion and analysis results. When recording the motion trajectory of a smart wearable device, the time deviation between the master device (such as a mobile phone) and the slave device (such as a smart watch) will cause the time sequence of the motion data to be chaotic, reducing the user experience.

[0003] Most of the existing Bluetooth BLE time synchronization schemes only rely on the initial time calibration when the Bluetooth connection is established, and the initial clock of the slave device is a random value when the initial synchronization is performed. Directly using the conventional alignment method will easily cause an initial deviation, and the clock error will be accumulated and increased during subsequent synchronization, so high-precision time synchronization cannot be achieved. Therefore, there is an urgent need for a high-precision Bluetooth BLE time synchronization scheme to solve the defects of the prior art. SUMMARY

[0004] In view of the above, the purpose of the present application is to provide a high-precision time synchronization method for Bluetooth devices to meet the demand for improving the time synchronization precision of Bluetooth devices.

[0005] To achieve the above purpose, the present application provides the following technical scheme: According to the first aspect, the application provides a high-precision time synchronization method for Bluetooth devices, comprising: S1, a master device sends a first synchronization clock signal to a slave device according to a scheduled time point with a target time interval; S2, it is judged whether the first synchronization clock signal is a first-time sending signal, and if so, step S3 is performed, and if not, step S4 is performed; S3, the slave device receives the first synchronization clock signal, and adjusts a local clock of the slave device according to a time stamp of receiving the first synchronization clock signal; S4, the slave device adjusts the local clock based on a time corresponding to the scheduled time point of receiving the first synchronization clock signal; S5, it is judged whether the number of times of receiving the first synchronization clock signal by the slave device exceeds a target number of times, and whether the time corresponding to the scheduled time point of the slave device is later than the receiving time of the first synchronization clock signal determined based on the local clock within the target number of times, and if so, S6 is performed, and if not, S1 is performed; S6, the local clock of the slave device is adjusted by a target time length, and the target time length is the minimum time delay from the sending of the first synchronization clock signal by the master device to the receiving of the first synchronization clock signal by the slave device.

[0006] Optionally, the method further comprises a time dynamic following process, which comprises: S7, the master device sends a second synchronization clock signal to the slave device according to a scheduled time point with a target time interval; S8, the slave device receives the second synchronization clock signal and determines a time difference according to the time of receiving the second synchronization clock signal and the scheduled time point; and S9, the local clock of the slave device is adjusted according to the time difference and the target time length.

[0007] Optionally, the high-precision time synchronization method for Bluetooth devices further comprises: S10, it is judged whether the number of times of receiving the second synchronization clock signal by the slave device exceeds a target number of times, and if not, S7 is performed, and if so, S11 is performed; S11, it is determined whether the time difference is greater than the target time length within the target number of times; if the time difference is less than the target time length at any time within the target number of times, S7 is performed, and if the time difference is greater than the target time length within the target number of times, S12 is performed; S12, the local clock of the slave device is slowed down, and the slowing-down time is the difference between a target time difference and the target time length, and the target time difference is the minimum time difference determined by the slave device according to the receiving time and the scheduled time point within the target number of times.

[0008] Optionally, the adjustment of the local clock of the slave device according to the time difference and the target time length comprises: when the time difference is less than the target time length, the local clock of the slave device is adjusted by a target adjustment value, and the target adjustment value is the difference between the time difference and the target time length; and when the time difference is greater than or equal to the target time length, the local clock of the slave device is maintained.

[0009] Optionally, the master device sends the first synchronization clock signal to the slave device at a predetermined time point with a target time interval, comprising: when a target communication task is received at the predetermined time point, determining the priority of the target communication task, the target communication task being any communication task other than the clock synchronization task; when the priority of the target communication task is higher than the priority of the clock synchronization task, waiting until the next predetermined time point for the slave device to send the first synchronization clock signal; when the priority of the target communication task is lower than the priority of the clock synchronization task, the slave device sending the first synchronization clock signal at the current predetermined time point.

[0010] Optionally, before the master device sends the first synchronization clock signal to the slave device at the target time interval, the master device learns and constructs a hidden Markov model of the slave device, the hidden state of the model being the working mode of the slave device and the observed state being the historical data traffic and synchronization request mode of the slave device; the master device predicts the probability of the slave device being in each working mode in the next time window at each synchronization time based on the hidden Markov model; and the master device calculates the target time interval that maximizes the long-term reward according to the probabilities of the working modes, the long-term reward function being constructed based on the synchronization power consumption and data waiting delay.

[0011] Optionally, the high-precision time synchronization method of the Bluetooth device further comprises: the slave device checking whether the drift compensation timer reaches the current compensation period and is in the safety window period, and when the current compensation period is reached and the pre-defined safety window period is reached, obtaining the master-slave device clock drift rate; calculating the relative drift rate based on the master-slave device clock drift rate; determining a new drift compensation period and compensation amount according to the relative drift rate; adjusting the local clock of the slave device at the start time of the compensation period; and resetting the drift compensation timer based on the new drift compensation period.

[0012] Optionally, the high-precision time synchronization method of the Bluetooth device further comprises: collecting real-time load state parameters of the current clock synchronization system before starting each clock synchronization period, the clock synchronization system being a system jointly constructed by the master and slave devices; determining the load state type based on the real-time load state parameters; determining the corresponding total execution time prediction value and fluctuation range based on the load state type and the pre-constructed time characteristic statistical model, the time characteristic statistical model being constructed based on historical running period data of the clock synchronization system; and dynamically correcting the start boundary and time length of the safety window period based on the corresponding total execution time prediction value and fluctuation range.

[0013] According to a second aspect, the present application provides an electronic device, comprising: a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the steps of the high-precision time synchronization method of the Bluetooth device according to the first aspect.

[0014] According to a third aspect, the application provides a computer storage medium, which stores computer instructions, and the instructions are executed by a processor to implement the steps of the high-precision time synchronization method for Bluetooth devices according to the first aspect.

[0015] The application provides a high-precision time synchronization method for Bluetooth devices, which directly calibrates a local clock with a timestamp of a first synchronization clock signal received from a slave device for a first synchronization scenario, quickly realizes preliminary alignment of the time of the master and slave devices, and avoids synchronization deviation caused by random initial time; secondly, for a non-first synchronization scenario, the difference between the receiving time and the scheduled time point is continuously adjusted to ensure the continuity of the synchronization process; finally, the target number verification and minimum time delay calibration mechanism are introduced, which not only eliminates the interference of accidental transmission delay on synchronization accuracy, but also offsets the fixed transmission delay between the master and slave devices to the maximum extent through minimum time delay correction, finally realizes the closed loop from preliminary alignment to high-precision stability of Bluetooth device time synchronization, and improves the Bluetooth time synchronization precision.

[0016] Other advantages, objects, and features of the application will be set forth in the following specification and will be apparent to those skilled in the art from the following description, or can be learned by practice of the application. The objects and other advantages of the application can be realized and attained by the below description. BRIEF DESCRIPTION OF DRAWINGS

[0017] In order to make the objects, technical solutions and beneficial effects of the application more clear, the application provides the following drawings for description: Figure 1 A specific example flowchart of the high-precision time synchronization method for Bluetooth devices in the application; Figure 2 A specific example flowchart of the high-precision time synchronization method for Bluetooth devices in the application; Figure 3 A detailed step timing chart of the first synchronization flow in the application; Figure 4 An oscilloscope verification result chart in the application; Figure 5 A principle block diagram of a specific example of an electronic device in the embodiment of the application. DETAILED DESCRIPTION

[0018] The technical solutions of the application will be described clearly and completely below with reference to the drawings, obviously, the described embodiments are part of the embodiments of the application, rather than all the embodiments. Based on the embodiments in the application, all other embodiments obtained by those skilled in the art without creative labor are within the protection scope of the application.

[0019] In the description of the present application, it should be noted that unless otherwise explicitly specified and limited, the terms mounting, connecting, and connecting should be understood in a broad sense, for example, can be fixedly connected, can be detachably connected, or integrally connected; can be mechanically connected, can be electrically connected; can be directly connected, can be indirectly connected through an intermediate medium, can be internal communication of two elements, can be wireless connection, or can be wired connection. For those skilled in the art, the specific meanings of the above terms in the present application can be understood according to the specific circumstances.

[0020] In addition, the technical features involved in the different embodiments of the application described below can be combined with each other as long as there is no conflict.

[0021] The embodiment provides a high-precision time synchronization method of a Bluetooth device, which comprises the following steps of: Figure 1 As shown in the figure, comprising: S1, the master device sends a first synchronization clock signal to the slave device according to the agreed time point with the target time interval; S2, it is judged whether the first synchronization clock signal is the initial sending, when it is the initial sending signal, step S3 is executed, when it is not the initial sending, step S4 is executed; S3, the slave device receives the first synchronization clock signal, and the slave device adjusts the local clock of the slave device according to the time stamp of receiving the first synchronization clock signal; S4, the slave device adjusts the local clock based on the time corresponding to the agreed time point of the time when the first synchronization clock signal is received; S5, it is judged whether the number of times of receiving the first synchronization clock signal of the slave device exceeds the target number of times, and whether the time corresponding to the agreed time point of the slave device is later than the receiving time of the first synchronization clock signal determined based on the local clock within the target number of times, when it is satisfied, S6 is executed, when it is not satisfied, S1 is executed; S6, the local clock of the slave device is adjusted by a target time length, and the target time length is the minimum time delay from the time when the master device sends the first synchronization clock signal to the time when the slave device receives the first synchronization clock signal.

[0022] Exemplarily, the method proposed in the embodiment can be applied to a communication environment, an indoor unobstructed environment, an environment with a distance between the master device and the slave device within 10 meters, and an environment without strong electromagnetic interference. The master device (Master) represents an initiator and a reference provider of clock synchronization, the slave device (Slave) represents a follower receiving a synchronization signal and adjusting its own clock according to the Master reference, the Master can be a mobile phone, and the Slave can be a smart bracelet, a smart watch, and the like. The specific device type of the master device and the slave device is not limited in the embodiment, and a person skilled in the art can determine it according to the need. For a multi-Slave device (one Master corresponding to multiple Slaves) scene, the Master can adopt a combination of “broadcasting + direction” to send the Token: broadcasting the Token to all Slaves (reducing power consumption), and if a Slave does not receive the Token as expected, the Master re-sends the Token to the Slave, which takes into account the efficiency and reliability of multi-device synchronization.

[0023] The master device can adopt a Bluetooth BLE master control chip with a model number of STM32WB55RG, a built-in 32MHz high-precision crystal oscillator, and a FreeRTOS operating system. The application layer needs to process sensor data reception (priority: medium) and first synchronization clock signal (Token) sending (priority: high) tasks. The slave device can adopt a Bluetooth BLE master control chip with a model number of nRF52832, a built-in 32MHz crystal oscillator, and a FreeRTOS operating system. The application layer needs to process sensor data collection (priority: medium) and first synchronization clock signal (Token) receiving and detecting (priority: high) tasks.

[0024] Based on the above hardware, the embodiment performs the following process to realize clock synchronization, such as Figure 2As shown, first, before step S1, the Master and the Slave should also include the connection establishment through the Bluetooth BLE protocol, and enter the data communication ready state; in step S1, the Master sends the first synchronization clock signal to the Slave according to the target time interval. The target time interval can comprehensively consider the system low-power consumption requirement (the greater the target time interval, the lower the frequency of the Master sending the first synchronization clock signal, and the lower the power consumption) and the application data transmission requirement (the smaller the target time interval, the higher the synchronization frequency, which can reduce the accumulation of time drift, but needs to avoid frequent conflicts with application data transmission). In the embodiment, the target time interval N can be 1, and if the application scenario has very high power consumption requirement (such as a long-distance sensor powered by a battery), the target time interval can be appropriately increased (such as N = 2 seconds). The embodiment does not limit the value of the target time interval, and a person skilled in the art can determine it according to the need. In addition, the predetermined time point can be an integer second time point. It can be understood that the predetermined time point with the target time interval can be an integer second time point with an interval of N, such as N = 2, the predetermined time point with the target time interval is 1.1 seconds, 3.1 seconds, etc.

[0025] Since the initial time of the Slave after power-on can be a random time, in the embodiment, the real physical time point successfully demodulated by the Bluetooth module is taken as the initial time of the local clock, that is, the current local clock is synchronized to the time when the first synchronization clock signal is received, and the initial time alignment is completed.

[0026] At this time, due to the transmission delay, there is a time difference between the Slave and the Master. In order to realize synchronization and eliminate the time difference as much as possible, in the embodiment, the clock synchronization is in a stable state through repeated adjustment. Specifically, when the Slave receives the first synchronization clock signal every N seconds (not the first time) in the subsequent, it detects the difference between the predetermined time point of its own clock and the time when the first synchronization clock signal is received; if the predetermined time point of the Slave's own clock is later than the time when the first synchronization clock signal is received, the own time is immediately adjusted to the time when the first synchronization clock signal is received, and the detection is continued until the number of times that the Slave receives the first synchronization clock signal exceeds the target number M, and the time corresponding to the predetermined time point of the Slave does not appear later than the first synchronization clock signal receiving time determined based on the local clock within the target number of times. At this time, it is indicated that the clock synchronization is in a stable state, and the continuous detection is stopped. It should be noted that the target number M is a stability verification number, which is used to ensure that the minimum time delay of the Master and the Slave sending the first synchronization clock signal appears at least once in the continuous M times of sending the first synchronization clock signal, so as to ensure that the Slave can complete accurate correction based on the minimum time delay.

[0027] As an optional implementation, the target number M determination method is determined by repeated measurement, and the test scenarios include: Long-time test: the master and slave devices continuously send tokens, and the frequency of delay ≤D0 in continuous M times of sending is counted to ensure that the frequency is 100% (i.e., each continuous M times of sending contains at least one case of delay=D0); Repeated connection test: after each reconnection of the master and slave devices, the frequency of delay ≤D0 in continuous M times of token sending is counted to ensure that at least one occurrence is met in all connection scenarios, and the safe M value (such as M=3 times, M=5 times) is finally determined.

[0028] It should be further noted that the total time length of N×M should be ensured not to be too long to cause the time drift of the master and slave devices within the period to exceed the correctable range - if a larger N×M value (such as N=3 seconds, M=50 times, N×M=150 seconds) needs to be set, a "time drift compensation algorithm within N×M time length" (such as estimating the drift amount by historical drift rate and correcting in advance) needs to be additionally added in the synchronization logic.

[0029] In the stable state of the clock synchronization of the master and slave devices, the target time length of the slave local clock adjustment is the minimum time delay, and the minimum time delay D0 includes the minimum values of the Bluetooth air transmission delay and the protocol stack processing delay of the master and slave devices.

[0030] As an optional implementation, the minimum time delay D0 determination method is determined by repeated measurement, and the test scenarios include: Long-time test: the master and slave devices are continuously operated for more than 24 hours, the delay of each token transmission is recorded, and the minimum delay is taken as the initial D0; Repeated connection test: the master and slave devices are disconnected and then reconnected, and the process is repeated more than 100 times, the delay of the first token transmission after each connection is recorded, the stability of the initial D0 is verified, and if there is a deviation, the minimum delay average value of multiple tests is taken as the final D0.

[0031] The parameters D0 and M are determined by "long-time test + repeated connection test" to ensure the transmission characteristics of different hardware devices and different communication environments; the strategy of "batch adjustment of slave fast clock" in the dynamic following process can cope with the scenario of device clock drift rate change, and improve the stability of long-term operation of the system.

[0032] It should be noted that all the synchronization parameters (N, D0, M) in this embodiment are not fixed values, and can be adjusted by actual measurement according to different hardware platforms (such as different models of Bluetooth chips, different precision crystal oscillators), different communication environments (such as indoor / outdoor, with / without electromagnetic interference), and different application requirements (such as synchronization accuracy requirements ±1ms / ±5ms, power consumption requirements low / medium / high). If the application scenario has very high requirements for synchronization accuracy (such as ≤0.5ms), a "temperature compensation test" can be added in the parameter determination stage - because the device crystal oscillator drift is greatly affected by temperature, D0 and M values need to be measured under different temperature environments (such as -20℃~60℃) to ensure that the synchronization accuracy still meets the standard under extreme temperature.

[0033] The following specific embodiments are given to understand the above scheme: 1. Connection establishment: Master (STM32WB55) and Slave (nRF52832) complete connection through Bluetooth BLE 5.0 protocol, Slave enters slave role and waits for Token reception; 2. Master sends Token: Master sends Token at the whole second moment of its own clock (such as 10:00:00.000, 10:00:01.000) with high priority; if the Master is receiving sensor application data (medium priority task) at a certain whole second moment (such as 10:00:02.000), the Token sending of this time is cancelled, and is postponed to 10:00:03.000; 3. Slave first calibration: Slave receives Token for the first time at 10:00:00.002 (2ms delay), and immediately adjusts its own clock to 10:00:00.002. At this time, for the Slave, the whole second moment is: 10:00:01.002, 10:00:02.002, 10:00:03.002.

[0034] 4. Slave continuous detection: 10:00:01.002: Slave receives Token, detects that the whole second moment of its own clock (10:00:01.002) is consistent with the reception time, and does not adjust; 10:00:02.003: Slave receives Token (delay 3ms), detects that the whole second moment of its own clock (10:00:02.002) is earlier than the reception time (10:00:02.003), and does not adjust; 10:00:03.002: Slave receives Token (delay 2ms), detects that the whole second moment of its own clock (10:00:03.002) is consistent with the reception time, and does not adjust; The Token detection is performed for three times, and none of the self time is later than the receiving time.

[0035] It should be noted that the above clock is based on the clock of the Master.

[0036] 5. End calibration: the Slave adjusts the local clock by D0=2ms, and the final clock is 10:00:03.000. The first synchronization process is completed.

[0037] Based on the above process description, the embodiment gives the detailed step timing diagram of the first synchronization process, as shown in Figure 3 The time when the Master sends the Token, the time when the Slave receives the Token, and the node of the Slave clock adjustment are marked.

[0038] The embodiment provides a high-precision time synchronization method of a Bluetooth device. For the initial synchronization scenario, the local clock is calibrated by the time stamp of the time when the first synchronization clock signal is received by the slave device, so that the time of the master-slave device is quickly aligned, and the synchronization deviation caused by the random initial time is avoided. Secondly, for the non-initial synchronization scenario, the difference between the receiving time and the agreed time point is continuously adjusted to ensure the continuity of the synchronization process. Finally, the target number verification and the minimum time delay calibration mechanism are introduced, which not only eliminates the interference of accidental transmission delay on the synchronization precision, but also offsets the fixed transmission delay between the master-slave device to the maximum extent through the minimum time delay correction, so that the Bluetooth device time synchronization is finally realized from the preliminary alignment to the high-precision stable closed loop, and the Bluetooth time synchronization precision is improved.

[0039] As an optional implementation, the high-precision time synchronization method of the Bluetooth device further includes: S7, the master device sends a second synchronization clock signal to the slave device according to the agreed time point with the target time interval; S8, the slave device receives the second synchronization clock signal, and determines the time difference according to the time of receiving the second synchronization clock signal and the agreed time point; S9, the local clock of the slave device is adjusted according to the time difference and the target time length.

[0040] Exemplarily, the second synchronization clock signal and the first synchronization clock signal can be represented by Token. The distinction between the second synchronization clock signal and the first synchronization clock signal is only to represent the synchronization clock signals in different stages, and the essence is the same. After the first synchronization is completed, the time dynamic following process is started to correct the time deviation of the master-slave device in real time, as shown in Figure 2 The steps are as follows: Master keeps sending Token: Master keeps sending Token at every N second, i.e. the agreed time point is the whole second, and the sending rule is consistent with the first synchronization process (if there is an application data communication task, the sending of this time is cancelled, and the next N second is postponed); Slave calculates the time difference and adjusts in real time: Slave calculates the time difference between the whole second time of its own clock (the clock after the first synchronization) and the time of receiving Token each time it receives Token, and records it as T milliseconds (T is the advance amount of Slave's own time relative to the time of receiving Token, i.e. T = Slave's whole second time - Token receiving time).

[0041] When the time difference is less than the target time length, the local clock of Slave is adjusted to be faster by the target adjustment value, which is the difference between the time difference and the target time length; when the time difference is greater than or equal to the target time length, the local clock of Slave is kept, i.e.: If T ≥ D0: it means that the advance amount of Slave's clock relative to Master's clock is greater than or equal to the minimum delay D0, and no adjustment is needed; if T < D0: it means that the advance amount of Slave's clock relative to Master's clock is insufficient, and the own time needs to be immediately adjusted to be faster by (T - D0) milliseconds (since T < D0, T - D0 is negative, adjusting (T - D0) milliseconds means actually correcting Slave's clock to the direction of aligning with Master's clock).

[0042] The following gives specific examples for understanding: Master keeps sending Token: keeps sending Token at every 1 second, and postpones if there is an application data task; Slave adjusts in real time: 10:00:04.002: Slave receives Token, calculates T = agreed time point (its own whole second time (10:00:04.000)) - receiving time (10:00:04.002) = -2ms, T < D0 (2ms), since the definition of T here should be the advance amount of Slave's own time relative to the time of receiving Token, then the time of receiving Token is 10:00:04.002, and Slave's own whole second time is 10:00:04.000, which means that Slave's clock is 2ms slower than the receiving time, i.e. T = 2ms (the time Slave needs to catch up), the definition of T is corrected here: T is the difference between Slave's own time and the time of receiving Token, if the time of receiving Token is T_recv, and Slave's own time is T_slave, then T = T_recv - T_slave (i.e. the time Slave is slower than Master); Modified Step 2: If T ≥ D0 (2ms): The Slave is slower than the Master's time ≥ target time length (minimum time delay), no adjustment is needed; If T < D0 (2ms): The Slave is not slow enough, immediately adjust faster (D0 - T) ms to align the Slave clock to T_recv; (Example: T_recv=10:00:04.002, T_slave=10:00:04.000, T=2ms=D0, no adjustment needed.) 10:00:05.001: T_recv=10:00:05.001, T_slave=10:00:05.000, T=1ms < D0, need to adjust faster (2-1)=1ms, Slave clock becomes 10:00:05.001.

[0043] The embodiment provides a high-precision time synchronization method for Bluetooth devices, constructs a time dynamic following correction mechanism, and combines the first embodiment to complete initial time alignment and real-time correction of deviations caused by clock drift and task scheduling delay through a two-level calibration mechanism of "first synchronization + dynamic following"; meanwhile, the D0 (minimum time delay) and M (stability times) parameters are introduced to ensure calibration based on actual transmission characteristics of the device and avoid precision loss caused by "blind calibration", and the actual measurement can control the time synchronization precision of the master-slave device within milliseconds. At the same time, the time deviation caused by factors such as device crystal oscillator drift and system task scheduling delay can be corrected in time, the influence of long-term accumulation of deviation on synchronization precision is avoided, the long-term stability of Bluetooth device time synchronization is improved, and the method is suitable for scenes that need to be continuously operated for a long time.

[0044] As an optional implementation, a high-precision time synchronization method for Bluetooth devices further comprises: S10, determining whether the number of times that the slave device receives the second synchronization clock signal exceeds a target number of times, when the target number of times is not exceeded, performing S7, and when the target number of times is exceeded, performing S11; S11, determining whether the time difference is greater than the target time length in the target number of times; when the time difference is less than the target time length in the target number of times, performing S7, and when the time difference is greater than the target time length in the target number of times, performing S12; S12, slowing down the local clock of the slave device, and the slowing down time is the difference between the target time difference and the target time length, and the target time difference is the minimum time difference determined by the slave device according to the received time and the agreed time point in the target number of times.

[0045] For example, if the Slave continuously detects the Token M times (consistent with the value of M in the first synchronization process), and the value of T detected each time satisfies T>D0 (no case of T ≤ D0), it is determined that the Slave clock is too fast relative to the Master clock; at this time, the minimum T value T1 in the M detections is taken, and the Slave clock is slowed down by (T1-D0) milliseconds to correct the deviation of the Slave clock being too fast.

[0046] Slave clock too fast adjustment: Three consecutive Token detections: 1. 10:00:06.002: T_recv=10:00:06.002, T_slave=10:00:06.001, T=1ms (does not satisfy T>D0); 2. If in the subsequent three detections, T is 3ms, 4ms, and 3ms (all >D0=2ms) respectively, the minimum T1=3ms is taken, and it is slowed down by (3-2)=1ms, the Slave clock is adjusted from 10:00:09.000 (assuming) to 10:00:08.999, and the deviation of being too fast is corrected.

[0047] The embodiment provides a high-precision time synchronization method for a Bluetooth device, which can effectively identify the trend of the clock of the Slave being too fast through target number of times judgment and continuous time difference detection, and calculate the slowing down time by taking the minimum time difference in the continuous target number of times, thereby ensuring the accuracy of the adjustment amount and avoiding the influence of excessive adjustment on the stability of the clock.

[0048] As an optional implementation, the Master device sends the first synchronization clock signal to the Slave device at a predetermined time point with a target time interval, including: When the target communication task is received at the predetermined time point, the priority of the target communication task is determined, and the target communication task is any communication task other than the clock synchronization task; when the priority of the target communication task is higher than the priority of the clock synchronization task, the Slave device waits until the next predetermined time point to send the first synchronization clock signal; when the priority of the target communication task is lower than the priority of the clock synchronization task, the Slave device sends the first synchronization clock signal at the current predetermined time point.

[0049] Exemplarily, in the actual operation scene of the Bluetooth device, the Master needs to process sensor data reception, user instruction response, multi-device networking communication and other target communication tasks in addition to the clock synchronization task. If the Master faces the conflict between the clock synchronization task and the target communication task at the agreed synchronization signal sending time point, it will directly lead to the delay of synchronization signal sending or the interruption of target communication task, and further affect the time synchronization accuracy or the core business function of the device. Therefore, the embodiment supplements the task priority scheduling mechanism to balance the synchronization accuracy and business continuity for the process of the Master sending the first synchronization clock signal according to the agreed time point with a target time interval.

[0050] The specific implementation process is as follows: In the operating system of the Master, the priority levels of the clock synchronization task and various target communication tasks are defined in advance. As an optional way, the priority of the clock synchronization task is set to be high, only lower than the core tasks such as device hardware failure processing and emergency safety instruction response; the priority of the target communication task is divided into two levels of medium and low according to the business importance, for example, the real-time uploading task of the central rate data of the medical wearable device is set to be medium priority, the device firmware version query task is set to be low priority, the device failure alarm signal transmission in industrial sensor networking is set to be medium priority, and the historical data backup request is set to be low priority.

[0051] The Master triggers the task conflict detection module 10 ms before reaching the preset synchronization signal sending agreed time point (such as the whole second moment), scans the current task queue to be executed, and judges whether there is an unfinished target communication task. If there is no target communication task, the Master directly sends the first synchronization clock signal at the current agreed time point; if there is a target communication task, the priority information of the task is extracted and compared with the high priority of the clock synchronization task.

[0052] When the priority of the target communication task is higher than the priority of the clock synchronization task, the Master suspends the current synchronization signal sending, waits for the target communication task to be executed, sends the first synchronization clock signal at the next agreed time point, and carries the delay identifier in the synchronization signal to inform the Slave of the reason for the delay of this synchronization, so as to avoid the Slave misjudging the synchronization exception.

[0053] When the priority of the target communication task is lower than the priority of the clock synchronization task, the Master triggers the task preemption mechanism, suspends the execution of the current target communication task, and preferentially sends the first synchronization clock signal at the current agreed time point; after the synchronization signal sending is completed, the suspended target communication task is immediately restored to continue execution from the suspension point, so as to ensure that the target communication task only has a very short interruption time and does not affect the business data integrity.

[0054] The embodiment provides a high-precision time synchronization method of a Bluetooth device. The scenes of "Master sending Token being interrupted by application data" and "Slave receiving Token being occupied by high-priority tasks" are explicitly adapted, the Master avoids interruption of the synchronization process through "postponing sending", and the Slave avoids interruption of the synchronization process through "giving up single detection", so that the synchronization reliability in a complex task scene is improved.

[0055] The following gives the precision verification result of the above embodiment: 1. Long-time examination: the master-slave device is continuously operated for 72 hours, the time difference of the whole-second time of the master-slave device is recorded once per hour, the maximum deviation is ±1 ms, and the high-precision synchronization demand is met; 2. Frequent reconnection examination: the master-slave device is disconnected and reconnected 50 times, the first synchronization completion time after each connection is ≤3 seconds (M=3 times, N=1 second), and the synchronization precision is ≤1 ms; 3. Application data interference test: the master-slave device randomly sends application data to each other (1 time per 10 seconds, data length 50 bytes), for 24 hours, the time synchronization precision is not affected, and the maximum deviation is still ±1 ms; 4. Oscilloscope verification: as shown in Figure 4 The master-slave device outputs 5V pulses (pulse width 100 μs) at the whole-second time, the time difference of the two pulses is measured through a double-channel oscilloscope, the actual measured maximum time difference is 0.8 ms, and it is verified that the synchronization precision meets the standard.

[0056] As an optional implementation, before the Master sends the first synchronization clock signal to the Slave according to the target time interval, the method comprises the following steps: The master device learns and constructs a hidden Markov model of the slave device, the hidden state of the model is the working mode of the slave device, and the observation state is the historical data flow and synchronization request mode of the slave device; the master device predicts the probability of the slave device being in each working mode in the next time window based on the hidden Markov model at each synchronization time; and the master device calculates the target time interval that maximizes the long-term reward according to the probability of each working mode, and the long-term reward function is constructed based on synchronization power consumption and data waiting delay.

[0057] For example, the setting of the target time interval directly affects the synchronization accuracy and power consumption balance of Bluetooth devices: if the time interval is too short and the synchronization frequency is too high, although time drift can be reduced, it will increase the wireless transmission power consumption and task scheduling pressure of the master and slave devices; if the time interval is too long, although power consumption can be reduced, it will cause drift to accumulate too quickly and the synchronization accuracy will decrease. Especially in scenarios where the slave's working mode changes dynamically (such as when a smartwatch switches between activity monitoring, standby, and call modes, where data traffic and synchronization requirements differ significantly), a fixed target time interval cannot adapt to the needs of dynamic scenarios. Therefore, this embodiment introduces a Hidden Markov Model (HMM) to learn the working mode patterns of the slave and dynamically calculate the optimal target time interval to achieve an adaptive balance between accuracy and power consumption.

[0058] The specific implementation process for constructing a Hidden Markov Model is as follows: Hidden State Definition: Set the Slave's working mode to the hidden state of the HMM, denoted as S={ , , },in For high-load modes (such as when a smartwatch is monitoring sports, the data acquisition frequency is 50Hz and the synchronization requirement is high). For medium load mode (such as during daily standby, the data acquisition frequency is 1Hz, and the synchronization requirement is moderate). In low-load mode (such as when sleeping at night, the data acquisition frequency is 0.1Hz, and the synchronization requirement is low).

[0059] Observation state definition: Set the historical running data of the Slave as the observation state of the HMM, denoted as O={ , },in For historical data traffic, such as Approximately 100KB / minute in this mode. Approximately 10KB / minute in this mode. Approximately 1KB / minute in this mode. For historical synchronization request mode, such as In this mode, the Slave initiates synchronization requests 5 times per minute. 1 time / minute in this mode 0 times / minute in mode.

[0060] Model parameter training: The Master first continuously collects the Slave's observation status time series data over the past 72 hours via Bluetooth link (including historical data traffic at each moment). Synchronization request mode with history Then, based on these known observation sequences, the Baum-Welch algorithm is used to initiate HMM model parameter training—this process is performed in high / medium / low load mode on the slave ( / / The hidden state is not directly observable. The model parameters are gradually optimized through multiple rounds of E-step and M-step iterations: In the E-step, the model parameters are optimized based on the current initial state probability. Given the state transition probability A and the observation probability B, calculate the posterior probability of the Slave being in each hidden state at each time step. And the posterior probability of transitioning from one hidden state to another at adjacent time steps. The M-step utilizes the results obtained from the E-step. and Update the initial state probabilities respectively (corresponding to the probability of each hidden state appearing at the initial moment), state transition probability A (corresponding to the probability of switching between each hidden state), and observation probability B (corresponding to the probability of each hidden state generating corresponding observation data); iterate the above E-step and M-step repeatedly until... When the changes in the three sets of parameters A, B, and C are less than the preset threshold, convergence is achieved, and finally an HMM model that can accurately map the pattern of "hidden state - observed data - state switching" is obtained.

[0061] Working mode probability prediction: At each synchronization moment (i.e., after the current synchronization signal is sent), the Master, based on the trained HMM model, inputs the Slave's real-time observation state data from the past 5 minutes (the latest data). and The Viterbi algorithm is used to decode the current working mode of the Slave and predict the hidden state of the Slave within a future time window (e.g., 30 seconds). , , The probability of ), denoted as P( ), P( ), P( ).

[0062] Optimal target time interval calculation: Long-term reward function construction: Define a long-term reward function R(T) to quantify the combined accuracy-power gain at different target time intervals T. The formula can be: ; in: The gain in synchronization accuracy is inversely proportional to T (the shorter T is, the higher the accuracy and the greater the gain). The specific relationship can be obtained by fitting historical data. This embodiment provides a specific formula as follows: ,in, is the precision coefficient, such as in the =100, in the =50, in the =10; is the power consumption cost, which is inversely proportional to T (the shorter T is, the more transmission times there are, the higher the power consumption is, and the greater the cost is), and its specific relationship can be obtained based on historical data fitting, and a specific formula given in this embodiment is: = , where is the power consumption coefficient, such as in the =20, in the =50, in the =100; , is the weight coefficient, =1, which is adjusted according to the application scenario, such as medical equipment =0.7, =0.3; ordinary wearable device =0.5, =0.5.

[0063] Reward calculation in multiple modes: according to the predicted probability of each mode, the weighted long-term reward corresponding to different T is calculated: ; wherein , , are the reward functions in , , modes respectively.

[0064] Optimal T determination: traverse the preset T candidate set (such as 100 ms, 200 ms, 500 ms, 1 s, 2 s), and select the T that makes the maximum as the target time interval in the next stage.

[0065] The embodiment provides a high-precision time synchronization method for a Bluetooth device, a mapping relationship between a working mode (high / medium / low load) of a slave device and an observation state (historical data flow, synchronization request mode) is learned through HMM, and a subsequent working mode probability of the slave device can be accurately predicted; secondly, an optimal time interval is calculated based on a long-term reward function (comprehensive synchronization precision benefit and power consumption cost), so that the interval can be shortened in a high load mode to ensure precision, and the interval can be prolonged in a low load mode to reduce power consumption.

[0066] As an optional implementation, a high-precision time synchronization method for a Bluetooth device further comprises: The slave device checks whether a drift compensation timer reaches a current compensation period and is in a safety window period, and when the current compensation period is reached and the slave device is in the predefined safety window period, a master-slave clock drift rate is obtained; a relative drift rate is calculated based on the master-slave clock drift rate; a new drift compensation period and a compensation amount are determined according to the relative drift rate; at the start time of the compensation period, the local clock of the slave device is adjusted; and the drift compensation timer is reset based on the new drift compensation period.

[0067] Exemplarily, a slave built-in drift compensation timer, and an initial period of the timer can be preset according to device hardware characteristics. The slave device checks two conditions in real time: whether the drift compensation timer reaches a current compensation period, for example, if the current period is 5 minutes, the detection is triggered once every 5 minutes; and whether the current time is in a safety window period, the safety window period refers to a time period in which the slave device has no high-priority task, and the safety window period can be predicted by a task scheduling queue. Only when the two conditions are met at the same time, the subsequent drift rate calculation and compensation process are started; if the two conditions are not met, the next detection node is continued to wait.

[0068] The master carries a current clock reference value of the master itself in a signal frame when sending a synchronization clock signal (a first or second synchronization signal) each time, for example, a tick number of cumulative timing based on a built-in 32 MHz crystal oscillator, 1 tick corresponds to 1 / 32 MHz second; after the slave device receives the synchronization signal, a current local clock value of the slave device is recorded, and the clock reference value of the master is stored. When triggering drift compensation, the slave device extracts a master clock reference value sequence in the last 10 synchronization signals, denoted as , and a local clock value sequence of the slave device itself, denoted as .

[0069] Then, the clock drift rates of the master and the slave are calculated respectively, the master drift rate : the master clock reference value is calculated according to a deviation between a theoretical value and an actual value. For example, theoretically, the master crystal oscillator should generate 300*32*10 6=9.6×10 9 9 =1200tick / 300s=4tick / s, i.e. Master clock is faster than the theoretical value by 4 ticks per second; 9 9 =-800tick / 300s =-2.67tick / s, i.e. Slave clock is slower than the theoretical value by 2.67 ticks per second.

[0070] Then, the relative drift rate characterizes the relative deviation rate of the master and slave device clocks, and the calculation formula is: ; Following the above example, =(-2.67)-4=-6.67tick / s, i.e. Slave clock is slower than Master clock by 6.67 ticks per second, which will cause Slave clock to continuously lag in the long run.

[0071] When |≥5tick / s (faster drift), the new compensation period is set to 80% of the current period to increase the compensation frequency; when 3tick / s≤ |<5tick / s (moderate drift), the current period is maintained; when |<3tick / s (slower drift), the new compensation period is set to 120% of the current period, such as from 5 minutes to 6 minutes, to reduce unnecessary compensation overhead.

[0072] The compensation amount ΔT needs to offset the current accumulated relative deviation, and the calculation formula is: ΔT= × ; Wherein is the current compensation period. Following the above example, ΔT=(-6.67tick / s)×300s=-2001tick, the negative sign indicates that Slave needs to adjust the clock to align with Master, 1tick corresponds to 1 / 32MHz second, i.e. ΔT converted to time is about -2001 / (32×10 6 )≈-62.5μs, i.e. Slave needs to adjust the clock by 62.5μs. ​​​​​

[0073] The clock adjustment and timer reset are at the start of the new compensation period. If the adjusted period is 4 minutes, then 4 minutes after the current compensation completion time is the next compensation start time. The slave adjusts the local clock according to the calculated compensation amount AT: If AT is negative, indicating that the slave lags, the cumulative tick number of the local clock is increased by |AT| (for example, by 2001 ticks); If AT is positive, indicating that the slave leads, the cumulative tick number of the local clock is reduced by AT (for example, if AT = 1500 ticks, then 1500 ticks are reduced). After the adjustment is completed, the slave resets the drift compensation timer based on the new compensation period and waits for the next compensation trigger.

[0074] The embodiment provides a high-precision time synchronization method for a Bluetooth device. The triggering condition of a compensation period + a safety window period is used to ensure that drift compensation is performed during a device idle period, so as to avoid interfering with core business. In addition, a relative drift rate is calculated based on clock drift rates of master and slave devices, so as to accurately quantify the time deviation rate of the two devices. Furthermore, the compensation period and the compensation amount are dynamically adjusted according to the relative drift rate, so as to not only timely offset accumulated deviation, but also reduce unnecessary compensation overhead.

[0075] As an optional implementation, a high-precision time synchronization method for a Bluetooth device further includes the following steps. Before starting each clock synchronization period, a real-time load state parameter of a current clock synchronization system is collected. The clock synchronization system is a system jointly constructed by master and slave devices. Based on the real-time load state parameter, a load state type is determined. Based on the load state type and a pre-constructed time characteristic statistical model, a corresponding total execution time prediction value and a fluctuation range are determined. The time characteristic statistical model is constructed based on historical running period data of the clock synchronization system. Based on the corresponding total execution time prediction value and the fluctuation range, a start boundary and a time length of the safety window period are dynamically corrected.

[0076] Exemplarily, the safety window period mentioned in the above embodiment is a key to ensure that drift compensation does not interfere with core business. However, a fixed safety window period (for example, the 10th-15th minute of each hour) cannot adapt to dynamic changes of device load. For example, when a smart watch suddenly starts motion monitoring (a high-priority task) at 10:10, the original safety window period conflicts with the task, causing the compensation process to be frequently delayed. Therefore, the embodiment supplements a safety window period dynamic correction mechanism based on real-time load. By collecting system real-time load parameters, a task idle period in the synchronization period is predicted, and the start boundary and the time length of the safety window period are adaptively adjusted.

[0077] Specifically, real-time load state parameter collection is started before each clock synchronization period, i.e. in the interval of the Master sending a synchronization signal, such as a target time interval of 1 second, the collection is started once every second, and the clock synchronization system (hereinafter referred to as the synchronization system) jointly constructed by the master and slave devices collects the following three types of real-time load state parameters: CPU occupancy rate: the master and slave devices respectively count the idle time proportion of the CPU in the last 100 ms; Task queue length: the number of tasks to be executed by the synchronization system is counted, which is divided into three levels of high, medium and low according to priority, and the number of tasks at each level is recorded; Data transmission bandwidth occupancy rate: the Master counts the current bandwidth occupancy of the Bluetooth link. The collection frequency is consistent with the synchronization period to ensure that the parameters can reflect the real-time state of the current load.

[0078] Load state type determination is based on the three types of parameters collected, and the current load state of the synchronization system is divided into three types of load through a preset determination rule, specifically, when the CPU occupancy rate is less than or equal to 30%, the number of high-priority tasks is 0, and the data transmission bandwidth occupancy rate is less than or equal to 20%, it is divided into low load state; when the CPU occupancy rate is greater than 30% and less than or equal to 60%, the number of high-priority tasks is 0 or 1, and the data transmission bandwidth occupancy rate is greater than 20% and less than or equal to 50%, it is divided into medium load state; when the CPU occupancy rate is greater than 60%, the number of high-priority tasks is greater than or equal to 1, and the data transmission bandwidth occupancy rate is greater than 50%, it is divided into high load state.

[0079] The synchronization system pre-constructs a time characteristic statistical model based on historical running period data, which takes the load state type as input and outputs the predicted value and fluctuation range of the total execution time in the synchronization period. The specific construction and prediction process is as follows: First, before the device is shipped or first started, simulate the synchronization process under different load states (low, medium and high), and record the total execution time in the synchronization period under each state, i.e. the total time spent on completing the synchronization signal sending, receiving and deviation calculation, denoted as . For example, 1000 synchronization periods are collected under low load , and the data set is obtained: , ,..., }; Next, statistical analysis is performed on the historical data set of each load state, and the mean μ and standard deviation σ are calculated, and the mean μ is taken as the predicted value of the total execution time, and [μ-σ, μ+σ] is taken as the fluctuation range. For example: Low load: = 50 ms, = 5ms, prediction 50ms, fluctuation range [45ms, 55ms]; Medium load: = 80ms, = 8ms, prediction 80ms, fluctuation range [72ms, 88ms]; High load: = 120ms, = 10ms, prediction 120ms, fluctuation range [110ms, 130ms]; According to the current determined load state type, the corresponding total execution time prediction value and fluctuation range are called from the model output. For example, the current is medium load, and the total execution time in the synchronization period is predicted to be 80ms, and the fluctuation range is [72ms, 88ms].

[0080] The dynamic correction of the safety window period is based on the total execution time prediction value and the fluctuation range. The safety window period is divided from the idle period in the synchronization period, and the specific correction rules are as follows: The idle period refers to the period without high / medium priority tasks in the synchronization period, which can be predicted by the task scheduling queue. For example, if the synchronization period is 1 second, 0-200ms and 500-800ms are predicted to be idle periods. The starting boundary of the safety window period needs to avoid the task execution period and be separated from the synchronization signal sending time by The maximum value of the fluctuation range, for example, the maximum value of the fluctuation range is 88ms, then the starting boundary needs to be separated from the synchronization signal sending time by ≥88ms to avoid the conflict between the compensation process and the synchronization task. For example, the synchronization signal sending time is 10:00:00.000, and the idle period is predicted to be 0-200ms, then the starting boundary is set to 10:00:00.088 (interval 88ms); The time length of the safety window period needs to be The total execution time prediction value + 2xσ, that is, covering the fluctuation range, to ensure that the compensation process has enough time to complete. For example, the prediction value is 80ms under medium load, and σ=8ms, then the time length needs to be ≥80+2x8=96ms. If the idle period is predicted to be 0-200ms, then from the starting boundary 10:00:00.088, a safety window period of 96ms is divided, that is, 10:00:00.088-10:00:00.184; If it is a high load state, and the idle period is short (such as only 150ms), then the time length of the safety window period is appropriately compressed, such as set to 130ms, covering the maximum value of the fluctuation range, and the starting boundary is moved to the middle of the idle period, such as the idle period 500-650ms, then the starting boundary is set to 565ms, and the window period is 565-700ms. If it is a low load state, the time length can be extended, such as set to 100ms, which exceeds the prediction value 50ms, to improve the fault tolerance rate of the compensation process.

[0081] The embodiment provides a high-precision time synchronization method for a Bluetooth device, collects real-time load parameters such as CPU occupancy, task queue length, and bandwidth occupancy, and can accurately determine the current system load state; secondly, a time characteristic statistical model constructed based on historical data can output the total execution time prediction value and fluctuation range of a synchronization task under different loads; finally, the starting boundary (avoiding task peak) and time length (covering fluctuation range) of the safety window period are adjusted according to the prediction result, which not only avoids the conflict between the compensation process and the high-priority task, but also ensures that the compensation has enough time to complete.

[0082] The embodiment of the application further provides an electronic device, as shown in the accompanying drawings, a processor 501 and a memory 502, wherein the processor 501 and the memory 502 can be connected through a bus or other means. Figure 5

[0083] The processor 501 can be a central processing unit (CPU). The processor 501 can also be other general-purpose processors, digital signal processors (DSP), application specific integrated circuits (ASIC), field programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or combinations thereof.

[0084] The memory 502, as a non-transitory computer readable storage medium, can be used to store non-transitory software programs, non-transitory computer executable programs and modules, such as program instructions / modules corresponding to the high-precision time synchronization method based on a Bluetooth device. The processor executes various functions of the processor and data processing by running the non-transitory software programs, instructions and modules stored in the memory.

[0085] The memory 502 can include a program storage area and a data storage area, wherein the program storage area can store an operating system and at least one application required by a function; the data storage area can store data created by the processor and the like. In addition, the memory can include a high-speed random access memory, and can also include a non-transitory memory, such as at least one magnetic disk storage device, a flash memory device, or other non-transitory solid-state memory device. In some embodiments, the memory 502 can optionally include a memory remotely arranged relative to the processor, which can be connected to the processor through a network. Examples of the above network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and combinations thereof.​

[0086] The one or more modules are stored in the memory 502 and, when executed by the processor 501, perform the method of high-precision time synchronization based on a Bluetooth device as described above. Figure 1 The method of high-precision time synchronization based on a Bluetooth device in the embodiments shown.

[0087] The specific details of the electronic device described above can be referred to in the corresponding description and effects of the embodiments shown, which will not be repeated here. Figure 1 The specific details of the electronic device described above can be referred to in the corresponding description and effects of the embodiments shown, which will not be repeated here.

[0088] The embodiment also provides a computer storage medium storing computer executable instructions, which can execute the method of high-precision time synchronization based on a Bluetooth device in any of the above method embodiments. The storage medium can be a disc, an optical disc, a read-only memory (ROM), a random access memory (RAM), a flash memory, a hard disk drive (HDD) or a solid-state drive (SSD), etc. The storage medium can also include a combination of the above types of memories.

[0089] Finally, it should be pointed out that the above preferred embodiments are only used to illustrate the technical solutions of the present application and not to limit it. Although the present application has been described in detail through the above preferred embodiments, those skilled in the art should understand that various changes can be made in form and details without departing from the scope defined by the claims of the present application.

Claims

1. A method for high precision time synchronization of Bluetooth devices, characterized in that, Comprising: S1, the master device sends a first synchronization clock signal to the slave device according to the agreed time point with the target time interval; S2, it is judged whether the first synchronization clock signal is the initial sending, when it is the initial sending signal, step S3 is executed, when it is not the initial sending, step S4 is executed; S3, the slave device receives the first synchronization clock signal, and the slave device adjusts the local clock of the slave device according to the time stamp of receiving the first synchronization clock signal; S4, the slave device adjusts the local clock based on the time corresponding to the agreed time point of receiving the first synchronization clock signal; S5, it is judged whether the receiving frequency of the first synchronization clock signal of the slave device exceeds the target frequency, and whether the time corresponding to the agreed time point of the slave device is later than the receiving time of the first synchronization clock signal determined based on the local clock within the target frequency, when it is satisfied, S6 is executed, when it is not satisfied, S1 is executed; S6, the local clock of the slave device is adjusted by a target time length, and the target time length is the minimum time delay from the master device sending the first synchronization clock signal to the slave device receiving the first synchronization clock signal.

2. The method of claim 1, wherein, Further comprising a time dynamic following process, the time dynamic following process is: S7, the master device sends a second synchronization clock signal to the slave device according to the agreed time point with the target time interval; S8, the slave device receives the second synchronization clock signal, and determines the time difference according to the receiving time of the second synchronization clock signal and the agreed time point; S9, the local clock of the slave device is adjusted according to the time difference and the target time length.

3. The method of claim 2, wherein, Further comprising: S10, it is judged whether the receiving frequency of the second synchronization clock signal of the slave device exceeds the target frequency, when it does not exceed the target frequency, S7 is executed, when it exceeds the target frequency, S11 is executed; S11, it is determined whether the time difference is greater than the target time length within the continuous target frequency; when the time difference is less than the target time length within the continuous target frequency, S7 is executed, when the time difference is greater than the target time length within the continuous target frequency, S12 is executed; S12, the local clock of the slave device is slowed down, and the slowing down time is the difference between the target time difference and the target time length, and the target time difference is the minimum time difference determined by the slave device according to the receiving time and the agreed time point within the continuous target frequency.

4. The method of claim 1, wherein, Adjusting the local clock of the slave device according to the time difference and the target time length, comprising: when the time difference is less than the target time length, the local clock of the slave device is adjusted by a target adjustment value, and the target adjustment value is the difference between the time difference and the target time length; when the time difference is greater than or equal to the target time length, the local clock of the slave device is kept.

5. The method of claim 1, wherein, The master device sends a first synchronization clock signal to the slave device according to the agreed time point with the target time interval, comprising: when a target communication task is received at the agreed time point, the priority of the target communication task is determined, and the target communication task is any communication task other than the clock synchronization task; when the priority of the target communication task is higher than the priority of the clock synchronization task, the slave device sends the first synchronization clock signal at the next agreed time point; when the priority of the target communication task is lower than the priority of the clock synchronization task, the slave device sends the first synchronization clock signal at the current agreed time point.

6. The method of claim 1, wherein, The master device sends a first synchronization clock signal to the slave device according to a target time interval, and before the master device sends the first synchronization clock signal to the slave device, the method comprises: The master device learns and constructs a hidden Markov model of the slave device, the hidden state of the model being the working mode of the slave device and the observation state being the historical data traffic and synchronization request mode of the slave device; The master device predicts the probability of the slave device being in each working mode in the next time window at each synchronization moment based on the hidden Markov model; The master device calculates the target time interval that maximizes the long-term reward according to the probability of each working mode, and the long-term reward function is constructed based on the synchronization power consumption and data waiting delay.

7. The method of claim 1, wherein, Further comprising: The slave device checks whether the drift compensation timer reaches the current compensation period and is in the safety window period, and when the current compensation period is reached and the pre-defined safety window period is reached, the master-slave device clock drift rate is obtained; Based on the master-slave device clock drift rate, the relative drift rate is calculated; The new drift compensation period and compensation amount are determined according to the relative drift rate; At the start of the compensation period, the local clock of the slave device is adjusted; Based on the new drift compensation period, the drift compensation timer is reset.

8. The method of claim 7, wherein, Further comprising: Before starting each clock synchronization period, the real-time load state parameters of the current clock synchronization system are collected, and the clock synchronization system is a system jointly constructed by the master and slave devices; Based on the real-time load state parameters, the load state type is determined; Based on the load state type and the pre-constructed time characteristic statistical model, the corresponding total execution time prediction value and fluctuation range are determined, and the time characteristic statistical model is constructed based on the historical running period data of the clock synchronization system; Based on the corresponding total execution time prediction value and fluctuation range, the starting boundary and time length of the safety window period are dynamically corrected.

9. An electronic device, the device comprising: A memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor executes the steps of the high-precision time synchronization method based on Bluetooth devices according to any one of claims 1-8.

10. A computer storage medium having stored thereon computer instructions, wherein the computer instructions, when executed by a computer, cause the computer to perform the method of claim 1. The instructions are executed by the processor to implement the steps of the high-precision time synchronization method based on Bluetooth devices according to any one of claims 1-8.