Time calibration method, device, terminal and storage medium

文档序号:1711702 发布日期:2019-12-13 浏览:10次 中文

阅读说明:本技术 校准时间的方法、装置、终端及存储介质 (Time calibration method, device, terminal and storage medium ) 是由 马亚辉 方攀 陈岩 于 2019-09-09 设计创作,主要内容包括:本申请实施例公开了一种校准时间的方法、装置、终端及存储介质,属于计算机技术领域,本申请实施例能够令终端与网络连接设备建立通信连接,当通过该网络连接设备访问互联网失败时,将重连阈值由n增加到m,当终端从目标授时服务器获取到的标准时间对应的重连次数不大于m时,终端能够根据标准时间校准终端中的系统时间。由于当终端与网络连接设备连接后,无论终端是否能否访问互联网,终端都将立即开始向授时服务器申请获取标准时间,本申请能够在网络连接设备访问互联网失败时,通过增加重连阈值,使得终端增加尝试获取标准时间的次数,提高了获取标准时间的可能性,增强了终端同步标准时间的能力。(The embodiment of the application discloses a method, a device, a terminal and a storage medium for calibrating time, and belongs to the technical field of computers. After the terminal is connected with the network connection equipment, the terminal immediately starts to apply for obtaining the standard time from the time service server no matter whether the terminal can access the internet or not.)

1. A method for time calibration, applied in a terminal, the method comprising:

establishing communication connection with a network connection device;

When the internet access through the network connection equipment fails, increasing a reconnection threshold from n to m, wherein the reconnection threshold is used for indicating the maximum times of allowing the terminal to acquire the standard time, m is greater than n, and m and n are positive integers;

And when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m, calibrating the system time of the terminal according to the standard time.

2. the method of claim 1, wherein increasing the reconnection threshold from n to m when access to the internet via the network connection device fails comprises:

When the internet access through the network connection equipment fails, obtaining m by multiplying the reconnection threshold n by a first preset constant k, wherein k is a positive integer greater than 1;

Or the like, or, alternatively,

And when the internet access through the network connection equipment fails, summing the reconnection threshold n and a second preset constant p to obtain m, wherein p is a positive integer.

3. The method of claim 2, wherein before increasing the reconnection threshold from n to m when accessing the internet via the network connection device fails, the method further comprises:

acquiring the standard time from a target object, wherein the target object is an object which is operated in the terminal and is used for caching the standard time;

When the effective standard time does not exist in the target object, applying to an ith time service server for obtaining the standard time, wherein i is a positive integer;

When the application time length is not less than an overtime threshold value, applying to a jth time service server to obtain the standard time, wherein the application time length is used for indicating the time length spent on obtaining the standard time from the ith time service server, the ith time service server and the jth time service server belong to time service servers, and j is a positive integer;

and when the number of the time service servers which are tried to access is equal to n, detecting whether the internet access through the network connection equipment is successful.

4. The method according to claim 3, wherein the jth time service server is an (i + 1) th time service server or the time service server determined according to a preset circulation rule.

5. The method according to claim 3, wherein the applying for obtaining the standard time from an ith time service server when the effective standard time does not exist in the target object comprises:

Acquiring a historical time setting record, wherein the historical time setting record is used for indicating the terminal to successfully acquire the information of the standard time from the time service server;

According to the historical time setting record, determining the time service server which has the maximum number of times of successfully obtaining the standard time from the time service servers which are not accessed in the time setting process as the ith time service server;

And applying for obtaining the standard time from the ith time service server.

6. The method of claim 3, further comprising:

Acquiring the longest application duration in the historical time setting record;

And if the longest application duration in the historical time setting records is smaller than the timeout threshold, determining the longest application duration in the historical time setting records as a new timeout threshold.

7. The method of claim 1, further comprising:

when the reconnection times are larger than m, starting a timer, wherein the overtime duration of the timer is a target query interval;

When the timer times out, resetting i to 1 and performing the step of establishing a communication connection with a network connection device after the target polling interval.

8. The method of claim 7, wherein the target query interval is smaller than a query interval native to a system provided in the terminal.

9. An apparatus for calibrating time, which is applied in a terminal, the apparatus comprising:

The communication connection module is used for establishing communication connection with the network connection equipment;

The threshold increasing module is used for increasing a reconnection threshold from n to m when the internet access through the network connection equipment fails, the reconnection threshold is used for indicating the maximum times of allowing the terminal to obtain the standard time, m is larger than n, and m and n are positive integers;

And the time calibration module is used for calibrating the system time of the terminal according to the standard time when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m.

10. A terminal, characterized in that the terminal comprises a processor, a memory connected to the processor, and program instructions stored on the memory, which when executed by the processor implement the method of calibrating time according to any one of claims 1 to 8.

11. A computer readable storage medium having stored thereon program instructions which, when executed by a processor, implement a method of calibrating time according to any one of claims 1 to 8.

Technical Field

The embodiment of the application relates to the technical field of computers, in particular to a time calibration method, a time calibration device, a terminal and a storage medium.

background

In the field of daily use of mobile terminals, the terminals need to perform data interaction with a cloud server. In order to confirm the order of transmitting and receiving data, the mobile terminal needs to be calibrated with a standard time.

Disclosure of Invention

The embodiment of the application provides a time calibration method, a time calibration device, a terminal and a storage medium, which can be used for solving the problem that the standard time acquisition fails because the mobile terminal is successfully connected with a network connection device but cannot be connected with the Internet. The technical scheme is as follows:

According to an aspect of the present application, there is provided a method of calibrating time, the method comprising:

Establishing communication connection with a network connection device;

When the internet access through the network connection equipment fails, increasing a reconnection threshold from n to m, wherein the reconnection threshold is used for indicating the maximum times of allowing the terminal to acquire the standard time, m is greater than n, and m and n are positive integers;

And when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m, calibrating the system time of the terminal according to the standard time.

According to another aspect of the present application, there is provided an apparatus for calibrating time, the apparatus including:

The communication connection module is used for establishing communication connection with the network connection equipment;

The threshold increasing module is used for increasing a reconnection threshold from n to m when the internet access through the network connection equipment fails, the reconnection threshold is used for indicating the maximum times of allowing the terminal to obtain the standard time, m is larger than n, and m and n are positive integers;

And the time calibration module is used for calibrating the system time of the terminal according to the standard time when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m.

According to another aspect of the present application, there is provided a terminal comprising a processor and a memory, the memory having stored therein at least one instruction, the instruction being loaded and executed by the processor to implement the method of calibrating time as provided in the practice of the present application.

According to another aspect of the present application, there is provided a computer readable storage medium having stored therein at least one instruction that is loaded and executed by a processor to implement a method of calibrating time as provided in the practice of the present application.

The beneficial effects brought by the technical scheme provided by the embodiment of the application can include:

According to the method and the device, the terminal can be in communication connection with the network connection device, when the internet access through the network connection device fails, the reconnection threshold is increased to m from n, the reconnection threshold is used for indicating the maximum number of times that the terminal is allowed to acquire the standard time, and when the reconnection number of times corresponding to the standard time acquired by the terminal from the target time service server is not more than m, the terminal can calibrate the system time in the terminal according to the standard time. Because the reconnection times of the terminal for applying for acquiring the standard time from the target time service server are limited by the reconnection threshold m, after the terminal is connected with the network connection equipment, the terminal immediately starts to apply for acquiring the standard time from the time service server no matter whether the terminal can access the internet or not.

Drawings

In order to more clearly describe the technical solutions in the embodiments of the present application, the drawings needed to be used in the description of the embodiments of the present application will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art that other drawings can be obtained according to these drawings without creative efforts.

Fig. 1 is a block diagram of a terminal according to an exemplary embodiment of the present application;

FIG. 2 is a flow chart of a method of calibrating time provided by an exemplary embodiment of the present application;

FIG. 3 is a flow chart of another method for calibrating time provided by another exemplary embodiment of the present application;

FIG. 4 is a flow chart of a calibration time provided by an embodiment of the present application;

Fig. 5 is a block diagram of an apparatus for calibrating time according to an exemplary embodiment of the present application.

Detailed Description

To make the objects, technical solutions and advantages of the present application more clear, embodiments of the present application will be described in further detail below with reference to the accompanying drawings.

When the following description refers to the accompanying drawings, like numbers in different drawings represent the same or similar elements unless otherwise indicated. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present application. Rather, they are merely examples of apparatus and methods consistent with certain aspects of the present application, as detailed in the appended claims.

In the description of the present application, it is to be understood that the terms "first," "second," and the like are used for descriptive purposes only and are not to be construed as indicating or implying relative importance. In the description of the present application, it is to be noted that, unless otherwise explicitly specified or limited, the terms "connected" and "connected" are to be interpreted broadly, e.g., as being fixed or detachable or integrally connected; can be mechanically or electrically connected; may be directly connected or indirectly connected through an intermediate. The specific meaning of the above terms in the present application can be understood in a specific case by those of ordinary skill in the art. Further, in the description of the present application, "a plurality" means two or more unless otherwise specified. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. The character "/" generally indicates that the former and latter associated objects are in an "or" relationship.

in order to make the solution shown in the embodiments of the present application easy to understand, several terms appearing in the embodiments of the present application will be described below.

Network connection equipment (english): for indicating a device provided for the terminal to connect to an internet communication service. In one possible implementation, the network connection device may be at least one of a switch, a router, a repeater, and a hub.

In one possible application scenario, the terminal is in steps during the process of accessing the internet. First, the terminal establishes a communication connection with the network connection device. Subsequently, if the network connection device is capable of providing the terminal with available internet services, the terminal accesses the internet through the network connection device. If the network connection device is unable to provide the terminal with available internet services, the terminal is only able to connect to the network connection device and is unable to access the internet.

When the terminal can only be connected to the network connection device and cannot access the internet, several possible implementation scenarios are included. In a possible implementation scenario, the network connection device sets a networking right limit for the terminal, and when the terminal does not obtain the right, the terminal can only keep connected with the network connection device and cannot access the internet. For example, when a terminal is connected to a Wi-Fi network provided by a wireless router having a captive portal authentication (english) function, the terminal needs to be connectable to the internet by a login authenticator after establishing a communication connection with the wireless router. In another possible scenario, the network connection device is disconnected from the network connection of the internet.

Reconnection threshold: for indicating the maximum number of times the terminal is allowed to acquire the standard time. In one possible approach, the reconnect threshold is used to indicate the maximum number of times the terminal is allowed to acquire the standard time within one cycle. In another possible approach, the reconnect threshold is used to indicate the maximum number of times the terminal is allowed to acquire the standard time within a specified time period.

The terminal identifies a target time service server from a plurality of time service servers by adopting a polling method, and can successfully acquire the standard time from the target time service server. If the reconnection threshold value stored in the terminal is 8, and the timeout threshold value of the terminal for initiating the connection with the target time service server every time is 5 seconds, when the terminal initiates the connection with the target time service server every time and no response is achieved for 5 seconds, another time service server is determined again, and the next connection with the re-determined time service server is entered. If the number of times of connection with the time service server reaches 8 times in total, the terminal enters a waiting period with a longer time length, for example, 8 hours, and then initiates the operation of obtaining the standard time from the target time service server in the time service server after 8 hours.

The target time service server: and the time service server is used for successfully providing standard time for the terminal. In a possible scenario, when the operating system used by the terminal is an android operating system or a system developed based on the android operating system, the target Time service server may be an NTP (Network Time Protocol, chinese) server. It should be noted that NTP is a network protocol for clock synchronization between computer systems with variable data network delay through packet switching.

in one possible implementation manner, the time service server may include a plurality of time service servers, or a plurality of time service satellites, or a plurality of time service centers. The terminal can sequentially try to initiate an application for acquiring the standard time to different time service servers in a polling mode until the standard time is acquired. The terminal can specify one time service server from among the plurality of time service servers and apply for acquisition of the standard time to the time service server. In the present application, the time service server of the standard time successfully provided to the terminal is named as a target time service server.

For example, the method for calibrating time shown in the embodiment of the present application may be applied to a terminal, where the terminal has a display screen and a function of calibrating time. The terminal may include a mobile phone, a tablet computer, a laptop computer, a desktop computer, a computer all-in-one machine, a server, a workstation, a television, a set-top box, smart glasses, a smart watch, a digital camera, an MP4 player terminal, an MP5 player terminal, a learning machine, a point-and-read machine, an electronic book, an electronic dictionary, a vehicle-mounted terminal, a Virtual Reality (VR) player terminal, an Augmented Reality (AR) player terminal, or the like.

It should be noted that, in a possible implementation manner of the embodiment of the present application, the terminal may be a terminal that carries an android operating system, an IOS operating system, or an operating system that is deeply developed based on the android operating system, which is not limited in the embodiment of the present application.

Referring to fig. 1, fig. 1 is a block diagram of a terminal according to an exemplary embodiment of the present application, and as shown in fig. 1, the terminal includes a processor 120 and a memory 140, where the memory 140 stores at least one instruction, and the instruction is loaded and executed by the processor 120 to implement a method for calibrating time according to various method embodiments of the present application.

in the present application, the terminal 100 is an electronic device having an automatic time setting function. When the terminal 100 establishes communication connection with a network connection device, the terminal 100 can detect whether the terminal can access the internet through the network connection device, when the terminal 100 fails to access the internet through the network access device, a reconnection threshold is increased to m from n, the reconnection threshold is used for indicating the maximum number of times that the terminal is allowed to acquire standard time, m is greater than n, m and n are positive integers, and when the number of reconnection times corresponding to the standard time acquired by the terminal from a target time service server is not greater than m, the system time of the terminal is calibrated according to the standard time.

Processor 120 may include one or more processing cores. The processor 120 connects various parts within the overall terminal 100 using various interfaces and lines, and performs various functions of the terminal 100 and processes data by executing or executing instructions, programs, code sets, or instruction sets stored in the memory 140 and calling data stored in the memory 140. Optionally, the processor 120 may be implemented in at least one hardware form of Digital Signal Processing (DSP), Field-Programmable Gate Array (FPGA), and Programmable Logic Array (PLA). The processor 120 may integrate one or more of a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), a modem, and the like. Wherein, the CPU mainly processes an operating system, a user interface, an application program and the like; the GPU is used for rendering and drawing the content required to be displayed by the display screen; the modem is used to handle wireless communications. It is understood that the modem may not be integrated into the processor 120, but may be implemented by a single chip.

The Memory 140 may include a Random Access Memory (RAM) or a Read-Only Memory (Read-Only Memory). Optionally, the memory 140 includes a non-transitory computer-readable medium. The memory 140 may be used to store instructions, programs, code sets, or instruction sets. The memory 140 may include a stored program area and a stored data area, wherein the stored program area may store instructions for implementing an operating system, instructions for at least one function (such as a touch function, a sound playing function, an image playing function, etc.), instructions for implementing various method embodiments described below, and the like; the storage data area may store data and the like referred to in the following respective method embodiments.

referring to fig. 2, fig. 2 is a flowchart illustrating a method for calibrating time according to an exemplary embodiment of the present application. The method for calibrating time can be applied to the terminal shown above. In fig. 2, the method of calibrating time includes:

step 210, establishing a communication connection with the network connection device.

In the embodiment of the application, the standard time has a plurality of important purposes of marking the receiving time and the sending time of the information, recording a log, storing data and the like in the operation process of the terminal. Therefore, it is very important for the terminal to accurately and timely acquire the standard time.

In one possible approach, there are devices that cannot access the internet through a mobile data network, but only through a wireless local area network. In this case, when the terminal accesses the internet, it is necessary to first establish a communication connection with the network connection device.

In the embodiment of the application, the terminal can perform network connection in a mode of scanning surrounding wireless network signals. In one possible approach, the terminal can automatically connect to the network connection device with the strongest signal.

And step 220, when the internet access through the network connection equipment fails, increasing the reconnection threshold from n to m, wherein the reconnection threshold is used for indicating the maximum times of allowing the terminal to acquire the standard time, m is greater than n, and m and n are positive integers.

In the embodiment of the application, after the terminal is successfully connected to the network connection device, the terminal can verify whether the terminal can successfully access the internet. Alternatively, the terminal can verify in various ways whether it has been able to successfully access the internet, as described below.

In one possible implementation manner, the terminal can determine whether the terminal can successfully receive and transmit the data packet by sending and/or receiving the data packet with a verification server designated by the cloud. When the terminal can successfully receive and/or send the data packet, the terminal determines that the terminal can successfully access the Internet; when the terminal cannot receive and/or transmit the data packet, the terminal itself fails to access the internet through the network connection device.

In another possible implementation, the terminal can invoke a system-native network connectivity validation service that can determine whether the terminal is indeed able to access the internet through the current communication path. When the native network connectivity confirmation service of the system confirms that the terminal fails or succeeds in accessing the internet through the network connection equipment, the terminal obtains corresponding information.

It should be noted that, in a possible implementation manner, after establishing a communication connection with the network connection device, the terminal will immediately start to attempt to access the time service server through the network connection device to acquire the standard time. The terminal can poll the standard time according to the appointed time service server list until the standard time is obtained from the target time service server.

In this process, since the terminal fails to access the internet through the network connection device, it indicates that the terminal may temporarily fail to acquire the authorization of the network connection device to access the internet. Therefore, the original reconnection threshold is increased from n to m, so that the terminal can determine a new time service server from the time service servers by more times and initiate access to the time service server to acquire the standard time.

For example, when the terminal is connected to a router in fast food restaurant a, a login page for captive portal authentication provided by the router is displayed in the terminal. Meanwhile, after the terminal establishes communication connection with the network connection equipment, the terminal can start to sequentially access a plurality of time service servers until standard time is obtained. When the terminal is not authenticated by the login page of the forced portal authentication provided by the router, the terminal cannot access the internet, so that the application of the terminal to access the time service server to obtain the standard time fails. Therefore, the method and the device increase the upper limit of the reconnection times of the terminal for applying the standard time to the time service server, namely increase the reconnection threshold value, so that the terminal has more attempts to acquire the standard time.

And step 230, when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m, calibrating the system time of the terminal according to the standard time.

In the embodiment of the application, the terminal can poll a plurality of time service servers until the standard time is obtained. In the embodiment of the application, the terminal names the time service server which successfully returns the standard time as a target time service server. That is, when the number of reconnection times corresponding to the standard time acquired by the terminal from the target time service server is not greater than the adjusted reconnection threshold, the terminal calibrates the system time of the terminal according to the acquired standard time.

in summary, the method for calibrating time provided in this embodiment can enable the terminal to establish a communication connection with the network connection device, and when the internet access through the network connection device fails, increase the reconnection threshold from n to m, where the reconnection threshold is used to indicate the maximum number of times that the terminal is allowed to acquire the standard time, and when the reconnection number corresponding to the standard time acquired by the terminal from the target time service server is not greater than m, the terminal can calibrate the system time in the terminal according to the standard time. Because the reconnection times of the terminal for applying for acquiring the standard time from the time service server are limited by the threshold m, after the terminal is connected with the network connection equipment, the terminal immediately starts to apply for acquiring the standard time from the time service server no matter whether the terminal can access the internet or not.

Based on the scheme disclosed in the previous embodiment, the terminal can also change the priority of the time service server so as to improve the possibility that the terminal successfully acquires the standard time. Please refer to the following examples.

referring to fig. 3, fig. 3 is a flowchart of another method for calibrating time according to another exemplary embodiment of the present application. The method for calibrating time can be applied to the terminal shown above. In fig. 3, the method for calibrating time includes:

step 310, establishing a communication connection with a network connection device.

In the embodiment of the present application, the execution process of step 310 is the same as the execution process of step 210, and is not described herein again.

step 321, obtaining the standard time from the target object, where the target object is an object running in the terminal for caching the standard time.

In the embodiment of the application, the terminal can acquire the standard time from the target object. It should be noted that the target object may be an ntptruttedtime object, which is used to store the standard time last obtained from the target time service server. When the terminal acquires the standard time from the target object, the terminal can check whether the standard time acquired from the target time service server at the last time in the NtpTrutestTime object is available or not and check whether the standard time is valid or not.

In another possible implementation manner, the standard times stored in the target object are all valid standard times. When the standard time expires, the standard time will not be retained in the target object.

in one way of calibrating the system time, when the standard time included in the target object is valid, the terminal will calibrate the system time in the terminal according to the standard time.

and 322, when the valid standard time does not exist in the target object, applying to the ith time service server for obtaining the standard time, wherein i is a positive integer.

In a possible implementation manner of the application, the terminal can apply to the ith time service server for obtaining the standard time when the valid standard time does not exist in the target object, wherein i is a positive integer. That is, in the implementation process of the embodiment of the present application, when i is equal to 1, the terminal applies for obtaining the standard time to the time service server 1 st time, and the applied server is the 1 st time service server.

In the embodiment of the application, the terminal may further perform the operation of applying for obtaining the standard time from the ith time service server by performing the step (a1), the step (a2) and the step (a3) instead of the step 322.

And a step (a1) of acquiring a historical time setting record, wherein the historical time setting record is used for indicating that the terminal successfully acquires the standard time from the time service server.

in the embodiment of the application, the terminal acquires the historical time tick record. The historical time setting record can be stored in the local of the terminal, and the historical time setting record is used for indicating that the terminal successfully obtains the information of the standard time from the time service server. In other words, after the terminal successfully acquires the standard time from the time service server, the terminal records the relevant parameters for acquiring the standard time in the historical time pair record. Optionally, the historical time tick record may record an identifier of the time server that successfully obtains the standard time each time. Alternatively, different time service servers may be used as the statistical objects, and the number of times that each time service server successfully provides the standard time for the terminal may be counted.

For example, in a possible display mode of the historical time tick record, the historical time tick record may provide the statistical times of the standard time successfully provided by each time server for the terminal. Illustratively, the table one shows statistical data of the times of successful provision of standard time by the time service server.

Watch 1

server identification Time service server 1 Time service server 2 Time service server 3 Time service server 4
Number of successful time service 3504 1912 1635 2311

In the historical time tick records shown in table one, data corresponding to 4 time service servers are recorded in total. The number of times that the time service server 1 successfully provides time to the terminal is 3504 times, the number of times that the time service server 2 successfully provides time to the terminal is 1912 times, the number of times that the time service server 3 successfully provides time to the terminal is 1635 times, and the number of times that the time service server 4 successfully provides time to the terminal is 2311.

And (a2) determining the time service server with the largest number of times of successfully acquiring the standard time from the time service servers which are not accessed in the time service process at the current time service process as the ith time service server according to the historical time service record.

In the embodiment of the application, the terminal determines the time service server with the largest number of times of successfully acquiring the standard time from the time service servers which are not accessed in the time service process at this time as the ith time service server according to the historical time service record.

schematically, the history time record shown in the table one is taken as an example for explanation. If the terminal does not apply to access any time service server, the terminal determines that the time service server 1 is the 1 st time service server. If the terminal has applied for accessing the time service server 1 and the time service server 4, the terminal determines the time service server 2 as the 3 rd time service server from the rest of the time service servers 2 and 3. The reason is that the number 1912 of successful time transfer corresponding to the time transfer server 2 is larger than the number 1635 of successful time transfer corresponding to the time transfer server 3.

In another possible implementation manner, the terminal may further set a priority for each time service server according to the number of times of common time service, and the terminal will perform polling on the time service servers according to the order of the priority.

for example, please refer to table two, which shows a historical time tick record with priority information provided by a time server.

Watch two

Server identification Time service server 1 time service server 2 Time service server 3 Time service server 4
Number of successful time service 3504 1912 1635 2311
priority level 1 3 4 2

According to the data shown in the second table, after the terminal establishes communication connection with the network connection device, the terminal can sequentially access the time service servers according to the sequence from high priority to low priority. In the embodiment of the present application, the smaller the numerical value, the higher the priority of the positive integer. Taking the data in the table shown in the second table as an example, the terminal will poll the time service server 1, the time service server 4, the time service server 2 and the time service server 3 in sequence to obtain the standard time.

And (a3) applying for obtaining the standard time from the ith time service server.

In the embodiment of the application, the terminal applies for obtaining the standard time to the determined ith time service server.

In the application, when the application duration is not less than the timeout threshold, the terminal can apply for obtaining the standard time from the jth time service server, and the application duration is used for indicating the duration taken for obtaining the standard time from the ith time service server. Wherein j is a positive integer, and the jth time service server is one of the time service servers. The present application can achieve the effect of acquiring the standard time from one server after the ith time service server by executing step 323a or step 323 b.

Step 323a, when the application duration is not less than the overtime threshold, applying for obtaining the standard time from the jth time service server, wherein the application duration is used for indicating the duration spent on obtaining the standard time from the ith time service server.

In the embodiment of the application, when the application duration is not less than the overtime threshold, the terminal applies for obtaining the standard time to the (i + 1) th time service server. It should be noted that the timeout threshold is a constant value preset in the system, and is intended to prevent the terminal from waiting for the designated time service server for too long, thereby affecting the efficiency of the terminal in obtaining the standard time. When the application duration is not less than the overtime threshold, it indicates that the current ith time service server fails to provide standard time for the terminal, and the terminal can replace the next time service server to continuously obtain the standard time, wherein the time service server is the (i + 1) th time service server.

It should be noted that, when the application duration is less than the timeout threshold, the application duration is used to instruct the terminal to apply for the duration from the time when the standard time is acquired to the ith time service server to the time when the standard time is received. When the application duration is not less than the timeout threshold, the application duration may be a duration from the time when the instruction terminal applies for obtaining the standard time to the ith time service server to the current system time.

for example, when the timeout threshold is 5 seconds, the terminal starts to count at the time when the standard time acquisition to the ith time service server starts, and when the application time length exceeds 5 seconds, the terminal applies for the acquisition standard time to the (i + 1) th time service server of the next time service server.

In the present embodiment, a description will be given taking an example in which 5 time servers, that is, a1 st time server, a2 nd time server, a3 rd time server, a 4 th time server, and a 5 th time server, are shared as a time server. And when the application duration after the terminal accesses the No. 3 time service server is not less than the overtime threshold, the terminal accesses the No. 4 time service server and continues to apply for obtaining the standard time.

Step 323b, when the application duration is not less than the overtime threshold, applying for obtaining the standard time from the time service server determined according to the preset circulation rule.

In the embodiment of the application, the preset cycle rule is a set of sequence rule for circularly accessing the time service server, which is preset in the terminal, when the number of the time service servers is less than m. According to the preset circulation rule, the terminal can successfully access the corresponding time service server when accessing the time service server for m times.

For example, if the number of time service servers is limited, the terminal will access a plurality of time service servers in a cycle to acquire the standard time. For example, when m is equal to 5 and the number of time service servers is only 3, the terminal may repeatedly access 2 servers out of the 3 servers. For example, the terminal will attempt to acquire the standard time in the order of the 1 st time service server, the 2 nd time service server, the 3 rd time service server, the 1 st time service server, and the 2 nd time service server. If the ith time service server is the 3 rd time service server, the terminal accesses a time service server behind the 3 rd time service server according to a preset cycle rule, namely the 1 st time service server, so as to obtain the standard time.

in the embodiment of the present application, the terminal can further implement the updating process of the timeout threshold through the steps (b1) and (b 2). Wherein, the steps (b1) and (b2) are introduced as follows:

And (b1) acquiring the longest application duration in the historical time pair records.

in the embodiment of the application, the terminal can obtain the longest application duration in the historical time setting records. It should be noted that the application duration lasts up to the timeout threshold. Thus, the longest value of the application duration is the timeout threshold. In addition, since all records in the historical time-setting record are records of successfully obtaining the standard time, the corresponding application time length is less than or equal to the timeout threshold. Therefore, the longest application duration in the history time-setting record obtained in the step (b1) is less than or equal to the timeout threshold.

And (b2), if the longest application duration in the historical time setting record is less than the timeout threshold, determining the longest application duration in the historical time setting record as a new timeout threshold.

In this embodiment of the application, if the longest application duration in the historical time tick record is less than the timeout threshold, the terminal determines the longest application duration in the historical time tick record as a new timeout threshold, and may perform the subsequent steps.

in a possible implementation manner, taking 5 seconds as an example of the timeout threshold, when the longest application duration in the history time-tick record is 1.2 seconds, the terminal determines the new timeout threshold to be 1.2 seconds.

And step 324, when the number of the time service servers which are tried to access is equal to n, detecting whether the internet access through the network connection device is successful.

In the embodiment of the application, when the terminal applies for acquiring the standard time from the n previous time service servers, whether the internet access is successful through the network connection equipment does not need to be detected. After the terminal tries to apply for the standard time from the n time service servers, the terminal starts a detection process and detects whether the internet is successfully accessed through the network connection equipment.

It should be noted that, according to the present application, after an attempt to apply for the standard time to n time service servers has been made, a scheme for detecting whether the internet access through the network connection device is successful is started, and a flow for the native system to obtain the standard time can be retained to a greater extent, thereby reducing the implementation difficulty of the scheme.

In another possible implementation manner, the terminal may detect whether the device connected to the time service server via the network can successfully access the internet before applying for obtaining the standard time from the time service server.

In this embodiment of the application, when the terminal completes step 324, the terminal may select to execute step 331 or may select to execute step 332, which is not limited in this embodiment of the application.

step 331, when the internet access through the network connection device fails, obtaining m by multiplying the reconnection threshold n by a first preset constant k, where k is a positive integer greater than 1.

In the embodiment of the application, when the terminal fails to access the internet through the network connection device, the terminal multiplies the reconnection threshold n by the first preset parameter k to obtain m. It should be noted that the first preset parameter k is a positive integer greater than 1. Since n and k are both positive integers, m is also a positive integer.

And 332, when the internet access through the network connection equipment fails, summing the reconnection threshold n and a second preset constant p to obtain m, wherein p is a positive integer.

in this embodiment of the application, the terminal may further sum the reconnection threshold n and a second preset parameter p to obtain m when the access to the internet through the network connection device fails, where p is a positive integer. It should be noted that the second preset parameter p may be a constant value set empirically.

In an alternative manner, the terminal may be capable of obtaining the target duration T from the time of establishing the communication connection with the network connection device to the time of successfully accessing the internet through the network connection device, and the second preset parameter p may be (T/timeout threshold). Alternatively, if (T/timeout threshold) is not an integer, then p may be an integer value of (T/timeout threshold).

And 340, when the reconnection times corresponding to the standard time acquired from the target time service server are not more than m, calibrating the system time of the terminal according to the standard time.

In the embodiment of the present application, the execution process of step 340 is the same as the execution process of step 230, and is not described herein again.

Step 351, when the reconnection number is greater than m, starting a timer, wherein the overtime length of the timer is the target query interval.

In the embodiment of the application, when the number of reconnection times is greater than m, the terminal starts a timer, and the timeout duration of the timer is a target query interval. For example, in one possible embodiment of the present application, the target query interval may be a longer time such as 2 hours.

In one possible implementation of the present application, the target query interval is smaller than a standard query interval, which is a query interval native to a system set in the terminal.

In the embodiment of the application, the target query interval adopted by the terminal replaces the system native target query interval set by the terminal. Because the target query interval is smaller than the standard query interval, the method and the device for acquiring the standard time shorten the time interval for acquiring the standard time again after the terminal does not successfully acquire the standard time, and improve the capability of acquiring the standard time by the terminal.

Step 352, when the timer times out, resets i to 1 and executes step 310 after the target query interval.

In the embodiment of the present application, the terminal will end the process of obtaining the standard time in the present application, reset i to 1, and execute step 310 after the target query interval.

In summary, according to the embodiment, the terminal can be controlled, the time service servers are polled according to the sequence from high priority to low priority of the time service servers, and since the server with the largest standard time is successfully provided to the terminal in the history of the prior access, the possibility that the terminal can successfully acquire the standard time in a short time is improved, and the efficiency of the terminal calibrating the system time according to the standard time is improved.

The method for calibrating time provided by the embodiment can also enable the terminal to automatically adjust the overtime threshold in the using process, so that the terminal does not need to wait for the time service server to return to the standard time length according to the specified invariable threshold, and the efficiency of successfully obtaining the standard time length by the terminal is improved.

Referring to fig. 4, fig. 4 is a flowchart illustrating a calibration time according to an embodiment of the present disclosure. The method of calibrating time shown in fig. 4 can be applied to the terminal shown in fig. 1. In fig. 4, the flow of the calibration time includes:

And step 401, establishing a communication connection with the Wi-Fi network connection device.

Step 402 determines if a standard time in the ntptrutesttime object has been obtained for a valid NTP server.

In step 403, the system time is updated when the standard time in the ntptruttedtime object has been obtained for the active NTP server.

In step 404, when a valid standard time in the ntptruttedtime object is not obtained, the standard time is obtained from the NTP server.

step 405 sets the timeout threshold to 1 second.

Step 406, determine whether the standard time is successfully obtained.

In step 407, when the standard time is not successfully obtained, the reconnection count value tryaaincounter is incremented by 1.

step 408, detecting whether the reconnection count value tryaaincounter is greater than the reconnection threshold tryamaxmax.

In step 409, when the reconnection count value tryaaincounter is greater than the reconnection threshold tryaagaimmax, the reconnection count value tryaaincounter is set to 0.

And step 410, when the reconnection count value TryAgainCounter is not more than the reconnection threshold TryAgaimMax, detecting whether the Wi-Fi network connection equipment can access the Internet or not.

In step 411, when the Wi-Fi network connection device cannot access the internet, it is detected whether the reconnection count value tryaaincounter is greater than N × reconnection threshold tryamammax.

In step 412, when the reconnection count value tryaiencounter is not greater than N × reconnection threshold tryamammax, an alarm clock of polingintervalshort length is set.

Step 413, after the system time is successfully updated, or after the reconnection count value tryaaincounter is set to 0, or when the Wi-Fi network connection device can access the internet, or when the reconnection count value tryaaincounter is greater than N × reconnection threshold tryaagaimmax, an alarm clock with the duration of polinginterval is set.

In the embodiment of the application, when the reconnection count value TryAgainCounter reaches the reconnection threshold tryagaimmmax, the terminal adds the network detection module. The network detection module is used for detecting whether a network provided by the Wi-Fi network connection equipment is really available or not, and if the network provided by the Wi-Fi network connection equipment is detected to be unavailable, the network provided by the Wi-Fi network connection equipment is possibly a Wi-Fi network needing login verification. At this time, the present application will increase the number of times the terminal attempts to acquire the standard time. In the present application, the parameter N is set to be greater than 1. And after the times of trying to acquire the NTP time are increased to N times TryAgaimMax times by the terminal, the time of the NTP server cannot be acquired successfully, and then an alarm clock with the duration of polingInterval is set. In one possible approach, the polinginterval is a longer alarm clock such as 8 hours.

in the embodiment of the application, the terminal can also increase the priority of the time service server with high success rate of acquiring the standard time, reduce the priority of the time service server with low success rate of acquiring the standard time, and preferentially use the time service server with high success rate when the standard time is acquired subsequently.

In the embodiment of the application, in a data testing process, if the standard time is successfully acquired from the NTP server at a single time, the timeout duration is less than 1 second, so the timeout duration (english: timeout) can be set to 1 second, and the waiting duration when the standard time is unsuccessfully acquired from the time service server at a single time is shortened.

In the embodiment of the present application, the terminal can shorten the time length of the polinginterval. For example, polingInterval is shortened from 8 hours to 2 hours.

the following are embodiments of the apparatus of the present application that may be used to perform embodiments of the method of the present application. For details which are not disclosed in the embodiments of the apparatus of the present application, reference is made to the embodiments of the method of the present application.

referring to fig. 5, fig. 5 is a block diagram illustrating a time calibration apparatus according to an exemplary embodiment of the present application. The means for time calibration may be implemented as all or part of the terminal in software, hardware or a combination of both. The device includes:

A communication connection module 510, configured to establish a communication connection with a network connection device;

a threshold increasing module 520, configured to increase, when access to the internet through the network connection device fails, a reconnection threshold from n to m, where the reconnection threshold is used to indicate a maximum number of times that the terminal is allowed to acquire the standard time, m is greater than n, and m and n are positive integers;

And the time calibration module 530 is configured to calibrate the system time of the terminal according to the standard time when the reconnection number corresponding to the standard time acquired from the target time service server is not greater than m.

in an optional embodiment, the threshold increasing module 520 is configured to, when internet access through the network connection device fails, obtain m by multiplying the reconnection threshold n by a first preset constant k, where k is a positive integer greater than 1; or, when the internet access through the network connection equipment fails, summing the reconnection threshold n and a second preset constant p to obtain m, wherein p is a positive integer.

In an optional embodiment, the apparatus includes a first acquisition module, a second acquisition module, a third acquisition module, and a first detection module. A first obtaining module, configured to obtain the standard time from a target object, where the target object is an object that is operated in the terminal and used for caching the standard time; the second acquisition module is used for applying to an ith time service server for acquiring the standard time when the effective standard time does not exist in the target object, wherein i is a positive integer; the third acquisition module is used for applying for acquiring the standard time from an (i + 1) th time service server when the application time length is not less than an overtime threshold, wherein the application time length is used for indicating the time length spent on acquiring the standard time from the (i) th time service server, the (i) th time service server and the (j) th time service server belong to the time service servers, and j is a positive integer; and the first detection module is used for detecting whether the internet is successfully accessed through the network connection equipment when the number of the time service servers which are tried to be accessed is equal to n.

In an optional embodiment, the jth time service server related to the device is an i +1 th time service server, or the time service server is determined according to a preset circulation rule.

In an optional embodiment, the second obtaining module is configured to obtain a historical time setting record, where the historical time setting record is used to indicate that the terminal successfully obtains the information of the standard time from the time service server; according to the historical time setting record, determining the time service server which has the maximum number of times of successfully obtaining the standard time from the time service servers which are not accessed in the time setting process as the ith time service server; and applying for obtaining the standard time from the ith time service server.

in an optional embodiment, the apparatus further includes a duration obtaining module and a threshold determining module, where the duration obtaining module is configured to obtain the longest application duration in the historical time pair record; and the threshold value determining module is used for determining the longest application duration in the historical time setting record as a new overtime threshold value if the longest application duration in the historical time setting record is smaller than the overtime threshold value.

In an optional embodiment, the apparatus further includes a timer starting module and a resetting module, the timer starting module is configured to start a timer when the number of reconnection times is greater than m, and an overtime length of the timer is a target query interval; and the resetting module is used for resetting i to 1 when the timer is over. A communication connection module 510, configured to establish a communication connection with the network connection device after the target query interval.

In an alternative embodiment, in the apparatus, the target query interval is smaller than a standard query interval, which is a system-native query interval set in the terminal.

for the corresponding content in the present apparatus, please refer to the description in the method embodiment, which is not described herein again.

The present embodiments also provide a computer-readable medium, which stores at least one instruction, where the at least one instruction is loaded and executed by the processor to implement the method for calibrating time according to the above embodiments.

It should be noted that: in the method for calibrating time provided by the above embodiment, only the division of the functional modules is taken as an example to illustrate when the time calibrating device executes the method for calibrating time, and in practical applications, the function distribution may be completed by different functional modules according to needs, that is, the internal structure of the device is divided into different functional modules to complete all or part of the functions described above. In addition, the time calibration device and the time calibration method provided by the above embodiments belong to the same concept, and specific implementation processes thereof are described in the method embodiments and are not described herein again.

The above-mentioned serial numbers of the embodiments of the present application are merely for description and do not represent the merits of the embodiments.

It will be understood by those skilled in the art that all or part of the steps for implementing the above embodiments may be implemented by hardware, or may be implemented by a program instructing relevant hardware, where the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a magnetic disk or an optical disk, etc.

The above description is only exemplary of the implementation of the present application and is not intended to limit the present application, and any modifications, equivalents, improvements, etc. made within the spirit and principle of the present application should be included in the protection scope of the present application.

19页详细技术资料下载
上一篇:一种医用注射器针头装配设备
下一篇:一种用于实现时间同步的修正方法及装置

网友询问留言

已有0条留言

还没有人留言评论。精彩留言会获得点赞!

精彩留言,会给你点赞!