Network time synchronization method and device, equipment and storage medium
After the audio equipment is restarted, the time synchronization is used to use the default initialization strategy and network time synchronization protocol to solve the problem of abnormal network services caused by inaccurate internal clocks in the equipment, and realize the synchronization of equipment and network time servers and the stability of network functions. sex.
Patent Information
- Application Number
- CN202411056989.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-02
- Publication Date
- 2025-01-28
AI Technical Summary
After the audio device restarts, the network service abnormality caused by inaccurate internal clocks.
When the time synchronization function of the audio equipment is detected, the preliminary initialization strategy is used to initialize the module associated with the network service in the audio equipment, establish a connection between audio equipment and the network, obtain target time information from the time server, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information, and also obtain target time information. And and get target time information, and get target time information, and also obtain target time information, and also obtain target time information. And and get the target time information, and also obtain the target time information, and also obtain the target time information. And and obtain the target time information, and also obtain the target time information. Use the preset network time synchronization protocol to perform multi -level time synchronization, and start the network service function after completing synchronization.
Ensure that the device is synchronized with the network time server, accurately calibrate the internal clock, further ensure the high quality and stability of the network function, and solves the problem of abnormal network services caused by the inaccurate clock after the audio equipment is restarted.
Smart Images

Figure CN119382821A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of audio device control, and in particular to a network time synchronization method, apparatus, device and storage medium. Background Art
[0002] At present, every audio device has a power on and off operation, and after each power on and off, the time of the device will be updated and adjusted. Specifically, the audio device is first connected to the Internet, and then the device time is synchronized based on the time on the Internet.
[0003] However, with this time synchronization method, the devices will still communicate before the audio devices complete synchronization. Before synchronization is completed, network services that rely on accurate time may be abnormal, thereby affecting the normal operation of the devices. Summary of the invention
[0004] The main purpose of this application is to solve the problem of abnormal network services caused by inaccurate internal clocks after the audio device is restarted.
[0005] A first aspect of the present application provides a network time synchronization method, which is applied to an audio device, and the method includes: when it is detected that the time synchronization function of the audio device is triggered, using a preset initialization strategy to initialize the module associated with the network service in the audio device, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module; establishing a connection between the audio device and the network, and after the connection is successful, obtaining target time information from a time server; using a preset network time synchronization protocol, performing multi-level time synchronization on the local time of the audio device according to the target time information, and after the local time is synchronized, starting the network service function of each module.
[0006] Optionally, the modules associated with the network services in the audio device are initialized using a preset initialization strategy, including: loading an operating system and using the operating system to initialize each circuit module of the audio device once; extracting the network modules with network functions in the audio device after the initialization is completed once, and re-initializing the network services of each of the network modules, and stopping the network service functions therein.
[0007] Optionally, the process of establishing a connection between the audio device and the network and, after the connection is successful, obtaining target time information from a time server includes: utilizing a signal traversal method to search for network signals in the environment where the audio device is located to obtain a signal set; based on signal priority, sequentially calling corresponding network interfaces to connect to corresponding network signals; and after the connection is successful, obtaining and reading target time information from a time server corresponding to the connected network signal.
[0008] Optionally, the step of obtaining and reading the target time information from a time server corresponding to a connected network signal includes: if the audio device is successfully connected to multiple network signals, reading the time information from a time server corresponding to each network signal respectively; and averaging all the time information to obtain the target time information.
[0009] Optionally, the method of reading the target time information from the time server corresponding to each network signal respectively includes: reading the time synchronization record of the audio device, and selecting two consecutive records closest to the current time to calculate a historical synchronization interval; comparing the historical synchronization interval with a preset time threshold range; determining a corresponding time collection interval based on the comparison result, and reading the target time information from the time server corresponding to each network signal based on the time collection interval.
[0010] Optionally, the method utilizes a preset network time synchronization protocol to perform multi-level time synchronization on the local time of the audio device according to the target time information, and starts the network service function of each module after the local time is synchronized, including: extracting the networking priority of the network module with network function in the audio device and the level of accuracy of the time when starting the service; determining the synchronization logic based on the accuracy level corresponding to a network module with the highest networking priority, using a preset network time synchronization protocol; synchronizing the local time of the audio device based on the synchronization logic and the target time information; and starting the network service function of each module after the local time is synchronized.
[0011] Optionally, the synchronization logic is determined based on the accuracy level corresponding to a network module with the highest networking priority and using a preset network time synchronization protocol, including: if the accuracy level corresponding to a network module with the highest networking priority is the first level, determining to use the one-way time difference method in the preset network time synchronization protocol as the synchronization logic; if the accuracy level corresponding to a network module with the highest networking priority is the second level, determining to use the two-way time difference method in the preset network time synchronization protocol as the synchronization logic; if the accuracy level corresponding to a network module with the highest networking priority is the third level, determining to use the cyclic two-way time difference method in the preset network time synchronization protocol as the synchronization logic.
[0012] Optionally, synchronizing the local time of the audio device based on the synchronization logic and the target time information includes: calculating the time difference between the target time information and the current time information of the audio device; determining whether the time difference is greater than a time difference threshold; if so, determining that the local time synchronization of the audio device is completed; if not, continuing to read the target time information from the time server, and re-synchronizing the local time after the synchronization is completed.
[0013] Optionally, after the local time is synchronized, the network service function of each module is started, including: after the local time is synchronized, building a network service dependency graph based on the networking priority of each network module; using a topological sorting algorithm to determine the network service startup order of each network module: initializing and starting the network service function of each module in turn based on the network service startup order.
[0014] Optionally, before using the topological sorting algorithm to determine the network service startup order of each network module, it also includes: obtaining the association relationship between each network module and other network modules, and adjusting the network service dependency graph based on the association relationship, wherein the association relationship is the network service dependency parent-child relationship of the network module.
[0015] Optionally, after the local time is synchronized, it also includes: starting a local clock verification program, and after the timer reaches a preset duration, calling a preset local clock drift detection algorithm to predict the predicted local time when the preset duration is reached; calculating the difference between the predicted local time and the real-time local time when the preset duration is reached, and judging whether the local clock synchronization is qualified based on the difference.
[0016] Optionally, after determining whether the local clock synchronization is qualified based on the difference, it also includes: if the local clock synchronization is determined to be unqualified based on the difference, using the temperature compensated crystal oscillator and Kalman filter algorithm on the audio device, predicting the local time based on the target time information, and updating it.
[0017] The second aspect of the present application provides a network time synchronization device, which is applied to an audio device, and the device includes: an initialization module, which is used to initialize the module associated with the network service in the audio device using a preset initialization strategy when it is detected that the time synchronization function of the audio device is triggered, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module; an acquisition module, which is used to establish a connection between the audio device and the network, and after the connection is successful, obtain the target time information from the time server; a synchronization module, which is used to use a preset network time synchronization protocol to perform multi-level time synchronization on the local time of the audio device according to the target time information, and after the local time is synchronized, start the network service function of each module.
[0018] A third aspect of the present application provides an audio device, comprising a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory to enable the audio device to execute the network time synchronization method as described above.
[0019] A fourth aspect of the present application provides a computer-readable storage medium, on which instructions are stored, and when the instructions are executed by a processor, the network time synchronization method described above is implemented.
[0020] Beneficial effects of this application:
[0021] In the technical solution provided by the present application, when the time synchronization function of the audio device is detected to be triggered, the module associated with the network service in the audio device is initialized using a preset initialization strategy, and the initialization strategy is to initialize the parameters of the module and stop the network service function of the module; establish a connection between the audio device and the network, and after the connection is successful, obtain the target time information from the time server; use the preset network time synchronization protocol to perform multi-level time synchronization on the local time of the audio device according to the target time information, and after the local time is synchronized, start the network service function of each module. Such an implementation scheme separates the local time synchronization of the device and the network service startup by connecting to the network, and executes the network service startup function after completing the time synchronization, thereby ensuring that the device is synchronized with the network time server, accurately calibrating the internal clock, and further ensuring the high quality and stability of the network function. It effectively solves the problem of abnormal network service caused by inaccurate internal clock after the audio device is restarted. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] Figure 1 A schematic diagram of a first embodiment of a network time synchronization method provided in an embodiment of the present application;
[0023] Figure 2A schematic diagram of a second embodiment of the network time synchronization method provided in an embodiment of the present application;
[0024] Figure 3 A schematic diagram of the structure of a network time synchronization device provided in an embodiment of the present application;
[0025] Figure 4 Another structural diagram of the network time synchronization device provided in the embodiment of the present application;
[0026] Figure 5 A schematic diagram of the structure of an audio device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0027] In order to solve the defects of the prior art, this application proposes a network time synchronization method, which ensures that the time synchronization is successful after the device is restarted before initializing the network service. This method uses an improved network time synchronization protocol to allow the network service to start only after the device is connected to the network and time synchronization is completed. This can ensure the accuracy of the device's internal clock and improve system reliability. At the same time, this method takes into account a variety of network environments to ensure efficient synchronization in various situations.
[0028] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" or "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, device, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0029] For ease of understanding, the specific process of the embodiment of the present application is described below. Figure 1 A first embodiment schematic diagram of a network time synchronization method provided in an embodiment of the present application, the method specifically comprises the following steps:
[0030] 101. When it is detected that a time synchronization function of an audio device is triggered, a module associated with a network service in the audio device is initialized using a preset initialization strategy, where the initialization strategy is to initialize parameters of the module and stop the network service function of the module.
[0031] In this embodiment, the audio device should be understood as a mobile terminal, such as a mobile phone, a tablet, a smart speaker, etc., by monitoring the trigger operation on the audio device in real time, and determining whether the time synchronization function needs to be started based on the trigger operation.
[0032] For example, by detecting whether the time synchronization function on the user interface of the audio device is triggered, or detecting whether the audio device is restarted and powered on, if so, the audio device is initialized using a preset initialization strategy, which is to initialize the module parameters and stop the module's network service function.
[0033] The initialization includes initializing all basic hardware systems of the audio device, including but not limited to the CPU, memory, storage unit, etc., and after completing the basic hardware system initialization, continuing to initialize the network module in the audio device.
[0034] Specifically, the operating system is loaded and used to initialize each circuit module of the audio device; the network module with network function in the audio device is extracted after the initialization is completed, and the network service of each network module is re-initialized to stop the network service function.
[0035] Further, after completing the initialization process, the audio device is controlled to jump to the process of communicating with the network time server.
[0036] Suppose a smart speaker reboots. At this stage, the speaker completes basic hardware initialization, loads the operating system (such as lightweight Linux), but does not start network services. Network hardware (such as Wi-Fi or Ethernet controllers) will be initialized, but may not yet be connected to the network.
[0037] 102. Establish a connection between the audio device and the network, and after the connection is successful, obtain target time information from the time server.
[0038] In this embodiment, the network function of the audio device is started to connect to the surrounding network signals, and then the target time information is obtained from the server of the network signal. The target time information can be a local clock on the server or a clock synchronization signal of the server.
[0039] In actual applications, multiple network interfaces of the audio device are controlled to try to establish a network connection with a searchable network signal, such as Wi-Fi, Ethernet, or cellular network, and the connection is tried according to priority.
[0040] After the audio device detects that the connection is successful, an improved network time synchronization protocol (such as NTPv4) is immediately started to communicate with the time server to obtain target time information.
[0041] 103. Using a preset network time synchronization protocol, perform multi-level time synchronization on the local time of the audio device according to the target time information, and after the local time is synchronized, start the network service function of each module.
[0042] The preset network time synchronization protocol is an algorithm with multi-level synchronization logic that is set based on the networking priority of the network module in the audio device.
[0043] In actual applications, abnormal modules or functions may appear in the network service of the audio device, mainly the modules or functions that start up when the audio device restarts. The network modules with network service functions in the audio device are divided into two categories of priority by the modules or functions that start up when the audio device restarts.
[0044] Then, multi-level time synchronization is performed on the network module that is restarted and followed, and the corresponding time synchronization logic is determined according to the accuracy of the time required by the module or function that is restarted and followed.
[0045] The multi-level time synchronization here is actually a synchronization logic sequence with multiple different synchronization logics. The synchronization logic sequence is determined according to the networking priority of the network function. That is, the time synchronization logic corresponding to each network module is first determined, and then the time synchronization logics are sorted according to the networking priority of the network module to obtain the synchronization logic sequence.
[0046] After time synchronization is completed based on the synchronization logic sequence, the network service functions of each network module are started. Specifically, a network function dependency graph is constructed for each network module, and the modules are started in sequence based on the graph.
[0047] This embodiment separates the local time synchronization of the device and the network service startup by connecting to the network, and executes the network service startup function after completing the time synchronization, thereby ensuring that the device is synchronized with the network time server, accurately calibrating the internal clock, and further ensuring the high quality and stability of the network function. This effectively solves the problem of abnormal network services caused by inaccurate internal clocks after the audio device is restarted.
[0048] See also Figure 2 , a schematic diagram of a second embodiment of a network time synchronization method provided in an embodiment of the present application, the method specifically comprises the following steps:
[0049] 201. Restart and initialize the audio device.
[0050] In this step, after detecting that the audio device is restarted, the operating system is loaded and each circuit module of the audio device is initialized once using the operating system; the network module with network function in the audio device after the initialization is completed is extracted, and the network service of each network module is re-initialized to stop the network service function.
[0051] 202. Control the audio device to stop the network service function, and synchronize the network connection and time.
[0052] It should be noted that the network service function means that certain functions or modules of the audio device need to communicate or interact through the network and have data transmission; the network connection is to enable the audio device to enter the network and does not have data transmission.
[0053] In this embodiment, during the network connection and time synchronization process, there are two synchronization modes, one is to select a single network signal to complete the synchronization, and the other is to select multiple network signals to complete the synchronization.
[0054] When a single network signal is selected, the network signals around the audio device are searched and one with the best signal quality is selected for synchronization.
[0055] When multiple network signals are selected, a signal traversal method is used to search for network signals in the environment where the audio device is located to obtain a signal set; based on the signal priority, the corresponding network interfaces are called in sequence to connect to the corresponding network signals; after the connection is successful, the time information is read from the time server corresponding to the connected network signal.
[0056] The step of obtaining target time information from a time server corresponding to the connected network signal includes:
[0057] If the audio device is successfully connected to multiple network signals, the time information is read from the time server corresponding to each network signal respectively; and the average of all the time information is calculated to obtain the target time information.
[0058] When calculating the average value, you can also configure corresponding weights according to the quality of each signal, and then calculate the average value based on the weights.
[0059] In another embodiment, the step of reading the target time information from the time server corresponding to each network signal includes:
[0060] Read the audio device time synchronization record, and select two consecutive records closest to the current time to calculate the historical synchronization interval; compare the historical synchronization interval with a preset time threshold range; determine the corresponding time collection interval based on the comparison result, and read the target time information from the time server corresponding to each network signal based on the time collection interval.
[0061] Specifically, if the historical synchronization interval is less than the lower limit of the time threshold range, the time information is read from the time server corresponding to each network signal at an interval of N times the historical synchronization interval, where N is greater than or equal to 2; if the historical synchronization interval is within the time threshold range, the time information is read from the time server corresponding to each network signal at an interval of the historical synchronization interval; if the historical synchronization interval is greater than the upper limit of the time threshold range, the time information is read from the time server corresponding to each network signal at an interval of half the historical synchronization interval.
[0062] For the above synchronization interval to obtain the target time information, in addition to setting it as the current interval, it can also be set as the next synchronization interval. The specific implementation logic is as follows:
[0063] If the last synchronization deviation < threshold 1:
[0064] Next synchronization interval = current interval * 2
[0065] elif last synchronization deviation < threshold 2:
[0066] Next sync interval = current interval
[0067] else:
[0068] Next synchronization interval = current interval / 2
[0069] Increase the synchronization level.
[0070] In this embodiment, after obtaining the target time information, the networking priority of the network module with network function in the audio device and the level of accuracy of the time when starting the service are extracted; based on the accuracy level corresponding to the network module with the highest networking priority, the synchronization logic is determined using the preset network time synchronization protocol; based on the synchronization logic and the target time information, the local time of the audio device is synchronized.
[0071] It should be noted that this embodiment selects to set three synchronization logics, each of which corresponds to a time accuracy level.
[0072] If the accuracy level corresponding to a network module with the highest networking priority is the first level, determine to use the one-way time difference method in the preset network time synchronization protocol as the synchronization logic; if the accuracy level corresponding to a network module with the highest networking priority is the second level, determine to use the two-way time difference method in the preset network time synchronization protocol as the synchronization logic; if the accuracy level corresponding to a network module with the highest networking priority is the third level, determine to use the cyclic two-way time difference method in the preset network time synchronization protocol as the synchronization logic.
[0073] A multi-level time synchronization algorithm is constructed through the first level, the second level, and the third level. The appropriate synchronization level is selected according to the network conditions and the required accuracy level to synchronize the network module. The calculation logic of each level is as follows:
[0074] Level 1 (first level): coarse synchronization
[0075] Time deviation = server time - local time;
[0076] Adjusted local time = local time + time offset.
[0077] Level 2 (Second Level): Considering Network Latency
[0078] Round trip delay = (T4-T1)-(T3-T2);
[0079] Time deviation = ((T2-T1)+(T3-T4)) / 2;
[0080] Adjusted local time = local time + time offset.
[0081] Level 3: Multiple sampling
[0082] Perform N level 2 synchronizations and take the median as the final time deviation.
[0083] Among them, T1 is the local time when the request is sent, T2 is the time when the server receives the request, T3 is the time when the server sends the response, and T4 is the local time when the response is received.
[0084] In another embodiment, synchronizing the local time of the audio device based on the synchronization logic and the target time information includes:
[0085] Calculate the time difference between the target time information and the current time information of the audio device; determine whether the time difference is greater than a time difference threshold; if so, determine that the local time synchronization of the audio device is completed; if not, continue to read the target time information from the time server, and re-synchronize the local time after the synchronization is completed.
[0086] That is, a synchronization accuracy threshold ε is set. When |time deviation|<ε, the time synchronization is considered successful. For example, the smart speaker is connected to the home Wi-Fi network and then synchronizes time with the preset NTP server (such as pool.ntp.org). First, use the level 1 method for fast synchronization. If the deviation is greater than 1 second, upgrade to the level 2 method. Assuming that the deviation calculated for the first synchronization is 2 seconds, the device will adjust the local clock and perform a second synchronization. If ε=50ms is set, 3-5 synchronizations may be required to achieve this accuracy. At the same time, the system records the results of each synchronization for subsequent optimization of the synchronization strategy.
[0087] 203. Use a local clock verification program to verify the synchronized local time.
[0088] In this embodiment, a local clock verification program is started, and after the timer reaches a preset duration, a preset local clock drift detection algorithm is called to predict the predicted local time when the preset duration is reached; the difference between the predicted local time and the real-time local time when the preset duration is reached is calculated, and based on the difference, it is determined whether the local clock synchronization is qualified.
[0089] In actual applications, after time synchronization is successful, the clock stability verification phase begins. This phase is to set a local clock drift detection algorithm to periodically compare the local clock with the expected time after the last synchronization. The algorithm is as follows:
[0090] Expected time = last synchronization time + elapsed time interval;
[0091] Actual time = current local time;
[0092] Clock drift = |actual time - expected time|;
[0093] If clock drift > maximum allowed drift:
[0094] Triggering a resync
[0095] Furthermore, during verification, a stability observation period is also included, during which the clock stability is continuously monitored.
[0096] If the clock remains stable during the observation period, the clock synchronization process is considered to be completed; otherwise, return to step 202 to re-synchronize the time.
[0097] For example, after the smart speaker completes the initial synchronization, it starts a 24-hour stability observation period. During this period, the clock drift is checked every hour. If the clock drift is found to exceed 100ms, resynchronization is triggered immediately. If the clock remains stable within 24 hours (the drift is always within 100ms), the clock synchronization process is considered to be completely completed.
[0098] 204. After the local time is synchronized, the network service functions of each module are started.
[0099] This step actually initializes the network services of each network module of the audio device. Specifically:
[0100] After the local time is synchronized, a network service dependency graph is constructed based on the networking priority of each network module; a network service startup sequence of each network module is determined using a topological sorting algorithm: the network service function of each module is initialized and started in turn based on the network service startup sequence.
[0101] Furthermore, before using the topological sorting algorithm to determine the network service startup sequence of each network module, the method further includes:
[0102] The association relationship between each of the network modules and other network modules is obtained, and the network service dependency graph is adjusted based on the association relationship, wherein the association relationship is a parent-child relationship of network service dependency of the network modules.
[0103] Among them, a topological sorting algorithm is used to calculate the in-degree of each network module in the network service dependency graph; the in-degree is the sum of the number of times a network module serves as the end point of an edge in the network service dependency graph; a first queue Q is constructed based on all network modules with an in-degree of zero; adjacent network modules of each network module in the first queue Q are determined from the network service dependency graph; the in-degree of the adjacent network module is reduced by 1 until the in-degree is zero, and the adjacent network module is added to the first queue Q; it is determined whether the first queue Q is empty; if not, a network service startup sequence L is constructed based on all network modules in the first queue Q.
[0104] Furthermore, after constructing the network service startup sequence L based on all network modules in the first queue Q, it also includes: determining whether the number of network modules in the network service startup sequence L is less than the number of network modules in the network service dependency graph; if so, reconstructing the network service startup sequence L.
[0105] In actual application, the logical steps to determine the order in which network services are started are as follows:
[0106] Step 1. Build a service dependency graph G;
[0107] Step 2. Add all nodes with in-degree 0 to queue Q;
[0108] Step 3. When Q is not empty:
[0109] a. Take out a node n from Q;
[0110] b. Add n to the result list L;
[0111] c. For each adjacent node m of n:
[0112] Reduce the in-degree of m by 1;
[0113] If the in-degree of m becomes 0, add m to Q;
[0114] Step 4. If the number of nodes in L is less than the number of nodes in graph G, there is a circular dependency and an error is reported;
[0115] Step 5. Otherwise, L is the correct network service startup order.
[0116] In this embodiment, based on the correct network service startup sequence, the process of starting the network services of each module also includes verifying whether the startup is successful, which is specifically achieved by setting up a service startup failure processing mechanism, which can control the rollback to the previous stable state if the service startup fails.
[0117] The specific implementation logic is as follows:
[0118] for each service in startup order:
[0119] Try starting the service
[0120] If the startup is successful:
[0121] Add the service to the started list
[0122] else:
[0123] Recording error logs
[0124] for started services in reverse order started list:
[0125] Stop service
[0126] Return failure status
[0127] After all services are started successfully, perform an overall functional test to ensure that the network functions normally.
[0128] For example, the smart speaker first starts basic network services, such as DHCP client, DNS resolver, etc. Then it starts more advanced services, such as audio streaming service, cloud synchronization service, etc. After each service is started, a simple functional test is performed, such as trying to resolve a domain name or connect to a streaming server. If a service fails to start, the system will record the error message, then shut down the started services in reverse order, and finally try to restart the entire network service initialization process.
[0129] 205. Start the duration synchronization strategy to regularly maintain the local time.
[0130] Specifically, after the network service runs normally, a background time synchronization maintenance process is implemented. For example, a dynamic time synchronization strategy is designed to adjust the synchronization frequency according to the device operation status and network conditions. The strategy is as follows:
[0131] Basic sync interval = 1 hour
[0132] If the device is active:
[0133] Synchronization interval = basic synchronization interval / 2
[0134] elif the network condition is poor:
[0135] Synchronization interval = basic synchronization interval * 2
[0136] else:
[0137] Sync interval = basic sync interval
[0138] In this embodiment, the maintenance process further includes: setting an emergency response mechanism to immediately trigger synchronization when an event that may affect the clock accuracy is detected.
[0139] Specifically, you can set a maximum tolerance deviation threshold. When the time deviation is detected to exceed this threshold, the service restart process is triggered, such as:
[0140] If the detected time deviation > maximum tolerated deviation:
[0141] Recording error logs
[0142] for all network services in reverse order startup list:
[0143] Stop service
[0144] Steps 202 to 204 are executed again.
[0145] Furthermore, after the maintenance is completed, it also includes generating a time synchronization quality report mechanism to regularly generate synchronization status reports for subsequent optimization.
[0146] For example, during normal use, the smart speaker performs time synchronization every hour. If it is detected that the device is playing audio or recording, the synchronization interval is shortened to 30 minutes to ensure higher time accuracy. If the network latency is high, the synchronization interval is extended to 2 hours. When the device is detected to wake up from sleep or the network is reconnected, a time synchronization is triggered immediately. If a synchronization finds that the time deviation exceeds 5 seconds, the system will immediately stop all network services and re-execute the complete time synchronization and service initialization process. A time synchronization quality report is generated every day, including indicators such as average deviation and synchronization success rate, which are used to further optimize the synchronization strategy.
[0147] 206. When the clock verification is abnormal, use the temperature compensated crystal oscillator and Kalman filter algorithm to adjust the local time.
[0148] That is, if it is determined based on the difference that the local clock synchronization is unqualified, the temperature compensated crystal oscillator and Kalman filter algorithm on the audio device are used to predict the local time based on the target time information and update it.
[0149] Specifically, the prediction formula is as follows:
[0150]
[0151] The updated information is as follows:
[0152]
[0153] Where x is the clock state, F is the state transition matrix, B is the control input matrix, u is the control vector, P is the error covariance matrix, Q is the process noise covariance, K is the Kalman gain, H is the observation matrix, R is the observation noise covariance, and z is the observation value.
[0154] The specific implementation steps include:
[0155] Step 1. Use a high-quality TCXO as the local clock source.
[0156] Step 2. Implement a Kalman filter to estimate and compensate for the crystal frequency deviation.
[0157] Step 3: Measure the ambient temperature periodically (eg, every hour) and update the temperature compensation parameters.
[0158] Step 4. After each successful network time synchronization, update the state of the Kalman filter.
[0159] Step 5. When network synchronization is not possible, use the prediction results of the Kalman filter to adjust the local clock.
[0160] For example, a smart speaker uses a TCXO with an accuracy of ±0.5ppm as the main clock source. A second-order Kalman filter is implemented, and the state vector includes time deviation and frequency deviation. After each successful network time synchronization, the filter state is updated with the synchronization result. When network synchronization cannot be performed, the system calls the filter prediction function once a second to estimate the current time deviation and fine-tune the system clock accordingly.
[0161] At the same time, the device measures the ambient temperature once an hour and adjusts the compensation parameters of the TCXO according to the pre-calibrated temperature-frequency curve. In this way, even if network synchronization cannot be achieved for several days, the system can still control the time error within 100ms, meeting the needs of most audio applications.
[0162] This mechanism ensures that the device can still maintain relatively accurate local time when the network is unavailable, providing a reliable foundation for various time-dependent services and functions.
[0163] In another embodiment, in order to ensure the accuracy of network time synchronization, a network time trap detection mechanism is also set during the verification process to prevent malicious time servers from providing erroneous time, and a time backtracking protection mechanism is set to prevent the system time from accidentally calling back to the past, causing service abnormalities.
[0164] The implementation steps of the network time trap detection mechanism are as follows:
[0165] 1. Record the time deviation of the last N synchronizations
[0166] 2. Calculate the mean μ and standard deviation σ of these N deviations
[0167] 3. For the new synchronization result x:
[0168] if|x-μ|>3σ:
[0169] Mark as suspicious result, do not apply immediately
[0170] Add additional verification steps (such as consulted other time sources)
[0171] else:
[0172] Accept the synchronization result
[0173] The implementation steps of the time backtracking protection mechanism are as follows:
[0174] Current time = Get system current time ()
[0175] Last recorded time = read last recorded time()
[0176] If current time < last recorded time:
[0177] Warning("Time travel detected")
[0178] Current time = max (current time, last recorded time + small increment)
[0179] Set system time (current time)
[0180] Record current time()
[0181] Furthermore, a time zone change handling mechanism can be set up to ensure that when the device time zone setting changes, all time-dependent services can adapt correctly.
[0182] For example: When the smart speaker cannot connect to the network time server, it will enable the local TCXO as the time source and use the Kalman filter algorithm to estimate and compensate for the drift of the crystal oscillator. At the same time, it will record the results of the last 10 successful synchronizations. If the new synchronization result differs too much from the historical data, it will start an additional verification process, such as trying to synchronize to other backup servers. To prevent time backtracking, the system will record the current time regularly (such as every minute). If it is detected that the new time is earlier than the recorded time, the system time will be adjusted to a position slightly later than the last recorded time. When the user changes the device time zone setting, the system will recalculate the execution time of all scheduled tasks and notify all time-dependent services to reinitialize their time-related configurations.
[0183] 207. Display the synchronized information in real time on the user interface of the audio device.
[0184] In this embodiment, the current time synchronization status is displayed on the device display screen (if any), such as "time synchronization successful", "using local time", etc.
[0185] Specifically, a simple progress indicator can be designed to show the degree of completion of the entire initialization process, such as the headquarters week number and progress ratio.
[0186] Total number of steps = 7 # Assume there are 7 main steps;
[0187] Progress percentage = (number of completed steps / total number of steps)*100.
[0188] Further, after synchronization is complete, the update displays a "System Ready" status and may play a brief audio prompt.
[0189] At the same time, a status reporting mechanism can be generated to allow the current time synchronization status of the device to be queried through the network or other interfaces; and a user notification mechanism can be set up to notify the user through the device interface or push messages when major time deviations or synchronization problems are detected.
[0190] The smart speaker has a small LED screen. When starting up, it displays "Starting". After the network is connected, it displays "Synchronizing time". After the time synchronization is successful, the current time is displayed, and a small synchronization icon is displayed next to the time. If the local time maintenance mechanism is used, a "local" logo will be displayed next to the time. After all initialization steps are completed, a soft "ding" sound is played. Users can get detailed time synchronization information through the voice command "View system status". If the system detects that the time deviation exceeds 1 minute, a warning icon will be displayed on the screen, and a reminder "The time may be detected to be inaccurate, it is recommended to connect to the network to synchronize the time" will be reminded at the next user interaction.
[0191] By implementing this method, not only the time accuracy of a single device and the reliability of network services are improved, but also a solid foundation is provided for the collaborative work of multiple devices, greatly improving the user experience. This method takes into account various possible abnormal situations, provides multi-level fault tolerance and recovery mechanisms, and ensures the robustness and reliability of the system. At the same time, through a friendly user interface and status indication, the system's availability and user experience are enhanced. This method can be widely used in various audio devices that require precise time synchronization, such as smart speakers, professional recording equipment, broadcasting systems, etc., providing new possibilities for improving product quality and user experience in the entire audio industry.
[0192] The network time synchronization method in the embodiment of the present application is described above. The network time synchronization device in the embodiment of the present application is described in detail from the perspective of modular functional entities. Figure 3 , a schematic diagram of a structure of a network time synchronization device provided in an embodiment of the present application, the device includes:
[0193] An initialization module 310, configured to initialize a module associated with a network service in the audio device using a preset initialization strategy when detecting that a time synchronization function of the audio device is triggered, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module;
[0194] The acquisition module 320 is used to establish a connection between the audio device and the network, and after the connection is successful, obtain the target time information from the time server;
[0195] The synchronization module 330 is used to perform multi-level time synchronization on the local time of the audio device according to the target time information by using a preset network time synchronization protocol, and start the network service function of each module after the local time is synchronized.
[0196] This solution uses a preset initialization strategy to initialize the modules associated with network services in the audio device when the time synchronization function of the audio device is detected to be triggered. The initialization strategy is to initialize the parameters of the module and stop the network service function of the module; establish a connection between the audio device and the network, and after the connection is successful, obtain the target time information from the time server; use the preset network time synchronization protocol to perform multi-level time synchronization on the local time of the audio device according to the target time information, and start the network service function of each module after the local time is synchronized. This solves the problem of abnormal network services caused by inaccurate internal clocks after the audio device is restarted.
[0197] See also Figure 4 , another structural diagram of the network time synchronization device provided in an embodiment of the present application, applied to an optical sensor communication base station, the device includes:
[0198] An initialization module 310, configured to initialize a module associated with a network service in the audio device using a preset initialization strategy when detecting that a time synchronization function of the audio device is triggered, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module;
[0199] The acquisition module 320 is used to establish a connection between the audio device and the network, and after the connection is successful, obtain the target time information from the time server;
[0200] The synchronization module 330 is used to perform multi-level time synchronization on the local time of the audio device according to the target time information by using a preset network time synchronization protocol, and start the network service function of each module after the local time is synchronized.
[0201] In this embodiment, the initialization module 310 includes:
[0202] A first initialization unit 311 is used to load an operating system and initialize each circuit module of the audio device using the operating system;
[0203] The second initialization unit 312 is used to extract the network modules with network functions in the audio device after the first initialization is completed, and perform secondary initialization on the network services of each of the network modules to stop the network service functions therein.
[0204] In this embodiment, the acquisition module 320 includes:
[0205] A search unit 321, configured to search for network signals in the environment where the audio device is located by using a signal traversal method to obtain a signal set;
[0206] A connecting unit 322, configured to sequentially call corresponding network interfaces to connect corresponding network signals based on signal priorities;
[0207] The acquisition unit 323 is used to acquire the target time information from the time server corresponding to the connected network signal after the connection is successful.
[0208] In this embodiment, the acquisition unit 322 is used to:
[0209] If the audio device is successfully connected to multiple network signals, then read the time information from the time server corresponding to each network signal respectively;
[0210] All the time information is averaged to obtain the target time information.
[0211] In this embodiment, the acquisition unit 322 is used to:
[0212] Read the audio device time synchronization record, and select two consecutive records closest to the current time to calculate the historical synchronization interval;
[0213] Comparing the historical synchronization interval with a preset time threshold range;
[0214] The corresponding time collection interval is determined based on the comparison result, and the time information is read from the time server corresponding to each network signal based on the time collection interval.
[0215] In this embodiment, the synchronization module 330 includes:
[0216] An extraction unit 331 is used to extract the connection priority of the network module with network function in the audio device and the accuracy level of time when starting the service;
[0217] A determination unit 332, configured to determine a synchronization logic using a preset network time synchronization protocol based on an accuracy level corresponding to a network module with the highest networking priority;
[0218] A synchronization unit 333, configured to synchronize the local time of the audio device based on the synchronization logic and the target time information;
[0219] The starting unit 334 is used to start the network service function of each module after the local time is synchronized.
[0220] In this embodiment, the determining unit 332 is used to
[0221] If the accuracy level corresponding to a network module with the highest networking priority is the first level, determine to use the one-way time difference method in the preset network time synchronization protocol as the synchronization logic;
[0222] If the accuracy level corresponding to a network module with the highest networking priority is the second level, determine to use the round-trip time difference method in the preset network time synchronization protocol as the synchronization logic;
[0223] If the accuracy level corresponding to a network module with the highest networking priority is the third level, it is determined to use the cyclic round-trip time difference method in the preset network time synchronization protocol as the synchronization logic.
[0224] In this embodiment, the synchronization unit 333 is used to:
[0225] Calculating a time difference between the target time information and the current time information of the audio device;
[0226] Determine whether the time difference is greater than a time difference threshold;
[0227] If so, determining that the local time synchronization of the audio device is complete;
[0228] If not, continue to read the target time information from the time server, and resynchronize the local time after the synchronization is completed.
[0229] In this embodiment, the startup unit 334 is used to
[0230] After the local time is synchronized, a network service dependency graph is constructed based on the networking priority of each of the network modules;
[0231] The network service startup order of each network module is determined by using a topological sorting algorithm:
[0232] The network service functions of each module are initialized and started in sequence based on the network service startup sequence.
[0233] In this embodiment, the startup unit 334 is further used for:
[0234] The association relationship between each of the network modules and other network modules is obtained, and the network service dependency graph is adjusted based on the association relationship, wherein the association relationship is a parent-child relationship of network service dependency of the network modules.
[0235] In this embodiment, the synchronization module 330 further includes a verification unit 335, which is used to:
[0236] After the local time is synchronized, a local clock verification program is started, and after the timer reaches a preset duration, a preset local clock drift detection algorithm is called to predict the predicted local time when the preset duration is reached;
[0237] The difference between the predicted local time and the real local time when the preset duration is reached is calculated, and whether the local clock synchronization is qualified is determined based on the difference.
[0238] In this embodiment, the synchronization unit 333 is used to:
[0239] If it is determined based on the difference that the local clock synchronization is unqualified, the local time is predicted based on the target time information and updated using the temperature compensated crystal oscillator and Kalman filter algorithm on the audio device.
[0240] The embodiment of the present application utilizes an improved network time synchronization protocol, and only allows network services to start after the device is connected to the network and time synchronization is completed. This can ensure the accuracy of the device's internal clock and improve system reliability. At the same time, this method takes into account a variety of network environments to ensure efficient synchronization in various situations.
[0241] above Figure 3 and 4 The network time synchronization device in the embodiment of the present application is described in detail from the perspective of modular functional entities, and the audio device in the embodiment of the present application is described in detail from the perspective of hardware processing.
[0242] See also Figure 5 As shown, the audio device includes a processor 500 and a memory 501 . The memory 501 stores machine executable instructions that can be executed by the processor 500 . The processor 500 executes the machine executable instructions to implement the network time synchronization method provided by the above implementation.
[0243] Further, Figure 5 The audio device shown further includes a bus 502 and a communication interface 503 , and the processor 500 , the communication interface 503 and the memory 501 are connected via the bus 502 .
[0244] Among them, the memory 501 may include a high-speed random access memory (RAM), and may also include a non-volatile memory (non-volatile memory), for example, at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 503 (which can be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. can be used. The bus 502 can be an ISA bus, a PCI bus or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0245] The processor 500 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 500. The above processor 500 may 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 gates or transistor logic devices, discrete hardware components. The disclosed methods, steps and logic block diagrams in the embodiments of the present disclosure can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present disclosure can be directly embodied as a hardware decoding processor to be executed, or a combination of hardware and software modules in the decoding processor can be executed. The software module can be located in a mature storage medium in the field such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 501 , and the processor 500 reads the information in the memory 501 , and completes the steps of the network time synchronization method provided in the above-mentioned embodiment in combination with its hardware.
[0246] The present application also provides a computer-readable storage medium, which may be a non-volatile computer-readable storage medium or a volatile computer-readable storage medium. Instructions are stored in the computer-readable storage medium. When the instructions are executed on a computer, the computer executes each step of the network time synchronization method provided in the above embodiments.
[0247] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the above-described equipment, devices, and units can refer to the corresponding process in the aforementioned method embodiment and will not be repeated here.
[0248] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk and other media that can store program code.
[0249] As described above, the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A network time synchronization method, applied to an audio device, characterized in that: The method comprises: When it is detected that the time synchronization function of the audio device is triggered, a module associated with the network service in the audio device is initialized using a preset initialization strategy, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module; Establishing a connection between the audio device and the network, and after the connection is successful, obtaining target time information from a time server; The preset network time synchronization protocol is used to perform multi-level time synchronization on the local time of the audio device according to the target time information, and after the local time is synchronized, the network service functions of each module are started.
2. The network time synchronization method according to claim 1, characterized in that: The step of initializing the module associated with the network service in the audio device by using a preset initialization strategy includes: By loading the operating system, each circuit module of the audio device is initialized once using the operating system; The network modules with network functions in the audio device are extracted after the primary initialization is completed, and the network services of each of the network modules are secondary initialized to stop the network service functions therein.
3. The network time synchronization method according to claim 1, characterized in that: The step of establishing a connection between the audio device and the network and obtaining target time information from a time server after the connection is successful includes: Using a signal traversal method, searching for network signals in the environment where the audio device is located to obtain a signal set; Based on the signal priority, the corresponding network interface is called in sequence to connect the corresponding network signal; After the connection is successful, the target time information is read from the time server corresponding to the connected network signal.
4. The network time synchronization method according to claim 3, characterized in that: The step of obtaining target time information from a time server corresponding to the connected network signal includes: If the audio device is successfully connected to multiple network signals, then read the time information from the time server corresponding to each network signal respectively; All the time information is averaged to obtain the target time information.
5. The network time synchronization method according to claim 3, characterized in that: The step of reading time information from a time server corresponding to each network signal comprises: Read the audio device time synchronization record, and select two consecutive records closest to the current time to calculate the historical synchronization interval; Comparing the historical synchronization interval with a preset time threshold range; The corresponding time collection interval is determined based on the comparison result, and the time information is read from the time server corresponding to each network signal based on the time collection interval.
6. The network time synchronization method according to any one of claims 1 to 5, characterized in that: The method of using a preset network time synchronization protocol to perform multi-level time synchronization on the local time of the audio device according to the target time information, and starting the network service functions of each module after the local time is synchronized, includes: Extracting the connection priority of the network module with network function in the audio device and the accuracy level of time when starting the service; Based on the accuracy level corresponding to a network module with the highest networking priority, a synchronization logic is determined using a preset network time synchronization protocol; Synchronize the local time of the audio device based on the synchronization logic and the target time information; After the local time is synchronized, the network service function of each module is started.
7. The network time synchronization method according to claim 6, characterized in that: The step of determining the synchronization logic based on the accuracy level corresponding to a network module with the highest networking priority and using a preset network time synchronization protocol includes: If the accuracy level corresponding to a network module with the highest networking priority is the first level, determine to use the one-way time difference method in the preset network time synchronization protocol as the synchronization logic; If the accuracy level corresponding to a network module with the highest networking priority is the second level, determine to use the round-trip time difference method in the preset network time synchronization protocol as the synchronization logic; If the accuracy level corresponding to a network module with the highest networking priority is the third level, it is determined to use the cyclic round-trip time difference method in the preset network time synchronization protocol as the synchronization logic.
8. The network time synchronization method according to claim 7, characterized in that: The synchronizing the local time of the audio device based on the synchronization logic and the target time information includes: Calculating a time difference between the target time information and the current time information of the audio device; Determine whether the time difference is greater than a time difference threshold; If so, determining that the local time synchronization of the audio device is complete; If not, continue to read the target time information from the time server, and resynchronize the local time after the synchronization is completed.
9. The network time synchronization method according to claim 6, characterized in that: After the local time is synchronized, the network service functions of each module are started, including: After the local time is synchronized, a network service dependency graph is constructed based on the networking priority of each of the network modules; The network service startup order of each network module is determined by using a topological sorting algorithm: The network service functions of each module are initialized and started in sequence based on the network service startup sequence.
10. The network time synchronization method according to claim 9, characterized in that: Before determining the network service startup sequence of each network module by using a topological sorting algorithm, the method further includes: The association relationship between each of the network modules and other network modules is obtained, and the network service dependency graph is adjusted based on the association relationship, wherein the association relationship is a parent-child relationship of network service dependency of the network modules.
11. The network time synchronization method according to claim 9, characterized in that: After the local time is synchronized, the method further includes: Start the local clock verification program, and after the timer reaches the preset duration, call the preset local clock drift detection algorithm to predict the predicted local time when the preset duration is reached; The difference between the predicted local time and the real local time when the preset duration is reached is calculated, and whether the local clock synchronization is qualified is determined based on the difference.
12. The network time synchronization method according to claim 11, characterized in that: After judging whether the local clock synchronization is qualified based on the difference, the method further includes: If it is determined based on the difference that the local clock synchronization is unqualified, the local time is predicted based on the target time information and updated using the temperature compensated crystal oscillator and Kalman filter algorithm on the audio device.
13. A network time synchronization device, applied to an audio device, characterized in that: The device comprises: An initialization module, configured to initialize a module associated with a network service in the audio device using a preset initialization strategy when detecting that a time synchronization function of the audio device is triggered, wherein the initialization strategy is to initialize the parameters of the module and stop the network service function of the module; An acquisition module, used to establish a connection between the audio device and the network, and after the connection is successful, obtain target time information from a time server; The synchronization module is used to perform multi-level time synchronization on the local time of the audio device according to the target time information by using a preset network time synchronization protocol, and to start the network service functions of each module after the local time is synchronized.
14. An audio device, characterized in that: The audio device comprises a memory and at least one processor, wherein the memory stores instructions; the at least one processor calls the instructions in the memory so that the audio device executes the network time synchronization method according to any one of claims 1 to 12.
15. A computer-readable storage medium having instructions stored thereon, characterized in that: When the instructions are executed by a processor, a network time synchronization method according to any one of claims 1 to 12 is implemented.