A time correction method and apparatus
By acquiring time information from both the time synchronization end and the time being synchronized end, calculating and compensating for time deviations, the problem of low clock calibration accuracy and high load in SCADA systems with low-performance CPUs is solved, achieving high-precision clock calibration and low CPU load.
Patent Information
- Application Number
- CN202311356298.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-19
- Publication Date
- 2026-11-24
- Estimated Expiration
- 2043-10-19
AI Technical Summary
In the existing technology, SCADA systems with low-performance CPUs have problems with low time calibration accuracy and high CPU load during the clock calibration process, making it difficult to ensure the real-time performance and accuracy of clock data while reducing CPU load.
By obtaining the sending time, network transmission time, time difference, and receiving time between the time synchronization end and the time receiving end, the time deviation is calculated, and the local time is compensated based on this, thus optimizing the time synchronization method to reduce the CPU scan cycle requirement.
It improves the accuracy of clock calibration, reduces the load on low-performance CPUs, and ensures the real-time performance and accuracy of clock data.
Smart Images

Figure CN117278166B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of clock calibration, and in particular to a calibration method and apparatus. Background Technology
[0002] Supervisory Control and Data Acquisition (SCADA) systems typically require an external master clock to correct their own clock. This external master clock is usually connected through the SCADA system's front-end processor (FEP), typically via Ethernet or serial port. Ethernet or serial ports can usually receive data promptly at the communication layer through interrupt requests (IRQs). The biggest difference between clock data and other data is that clock data must have a high degree of real-time performance, otherwise it will be distorted. However, although clock data can be ensured to be received promptly at the lower level through IRQ technology of Ethernet or serial ports, the processing of clock data can only be achieved through specific applications at the application layer.
[0003] In recent years, a common method for application layer to acquire data is to scan the underlying communication layer for available data at a fixed scan cycle. Obviously, the shorter the scan cycle, the higher the real-time performance of the clock data obtained by the application layer, but the higher the CPU consumption. Currently, FEPs typically use a fanless configuration, thus limiting CPU processing power (otherwise, overheating would occur). Systems using low-performance CPUs are highly sensitive to the number of active threads and scheduling frequency (the shorter the delay between two scheduling operations, the higher the scheduling frequency). In conventional processing, for FEPs with low-performance CPUs, a fixed scan cycle is often used as a compromise to balance data real-time performance and CPU load. While this effectively reduces the system CPU load, it still leads to a decrease in time synchronization accuracy.
[0004] Given the above-mentioned technologies, finding a time synchronization method applicable to low-performance CPUs is a problem that urgently needs to be solved by those skilled in the art. Summary of the Invention
[0005] The purpose of this application is to provide a time synchronization method and apparatus. This method can reduce the requirements for CPU scan cycles and effectively reduce the load on low-performance CPUs. Simultaneously, by compensating for local time deviations, it improves time synchronization accuracy.
[0006] To address the aforementioned technical problems, this application provides a time synchronization method applied to the synchronized end, comprising:
[0007] Obtain the transmission time of the message sent by the time synchronization terminal;
[0008] Obtain the reception time of the message received by the application layer of the target device;
[0009] Obtain the network transmission time of the message between the time synchronization end and the time-repairing end;
[0010] Obtain the time difference between the time the message is received by the communication layer of the receiving end and the time the message is received by the application layer;
[0011] The time deviation is determined based on the sending time, network transmission time, time difference, and receiving time.
[0012] The local time is compensated for based on the time deviation to determine the target time.
[0013] Preferably, the time deviation is determined based on the sending time, network transmission time, time difference, and receiving time, including:
[0014] The time deviation is calculated by subtracting the time determined by the receiving time from the sum of the sending time, network transmission time, and time difference.
[0015] Preferably, it further includes:
[0016] Multiple time deviations are obtained, and the time deviations are verified by an algorithm to obtain the target time deviation;
[0017] The local time is compensated based on the target time deviation to determine the target time.
[0018] Preferably, the time synchronization end and the time-receiving end transmit data via a serial port. Therefore, obtaining the network transmission time of the message between the time synchronization end and the time-receiving end includes:
[0019] The network transmission time is determined based on the message's byte length, the number of data bits, parity bits, stop bits, and baud rate used during data link layer transmission.
[0020] Preferably, the time synchronization end and the time-receiving end transmit data via a network port. Therefore, obtaining the network transmission time of the message between the time synchronization end and the time-receiving end includes:
[0021] Obtain the round-trip time from multiple time synchronization terminals;
[0022] Obtain the average of the round-trip times from multiple time synchronization terminals;
[0023] The product of the average value and the preset value is used as the network transmission time.
[0024] Preferably, obtaining the time difference between the time the message is received from the communication layer and the time the message is received by the application layer includes:
[0025] Obtain the reception period of the message received by the communication layer;
[0026] The reception time of the message by the application layer is determined based on the reception period;
[0027] The time difference is determined based on the reception time.
[0028] Preferably, if a response-type protocol is used between the time synchronization end and the synchronization end, then obtaining the reception period of the received message at the communication layer includes:
[0029] Obtain the sending period of the message sent by the time synchronization terminal;
[0030] Use the sending period as the receiving period.
[0031] Preferably, if a non-acknowledgment protocol is used between the time synchronization end and the synchronization end, then obtaining the reception period of the received message at the communication layer includes:
[0032] The application layer scans the communication layer at preset time intervals during multiple rounds of scanning to obtain the period of the messages;
[0033] Adjust the periods obtained from multiple rounds of scanning into a periodic sequence;
[0034] Determine the coefficient of variation based on the periodic sequence;
[0035] If the coefficient of variation is not greater than the preset coefficient, then any period in the periodic sequence is selected as the receiving period.
[0036] If the coefficient of variation is greater than the preset coefficient, the receiving period is within the period range corresponding to the period sequence.
[0037] Preferably, determining the reception time of the message by the application layer based on the reception period includes:
[0038] Obtain the preset scanning cycle, pre-scan coefficient, and cutting coefficient;
[0039] The receiving time is determined based on the preset scanning period, the pre-scanning coefficient, the cutting coefficient, and the receiving period.
[0040] Preferably, determining the time difference based on the reception time includes:
[0041] Obtain the target period corresponding to the receiving time;
[0042] Determine the interval corresponding to the time difference based on the target period;
[0043] Obtain the expected value corresponding to the interval and use the expected value as the time difference.
[0044] To address the aforementioned technical problems, this application also provides a time synchronization device, applied to the end being synchronized, comprising:
[0045] The first acquisition module is used to acquire the transmission time of the message sent by the time synchronization end;
[0046] The second acquisition module is used to acquire the time when the application layer of the end being verified receives the message;
[0047] The third acquisition module is used to acquire the network transmission time of the message between the time synchronization end and the time being synchronized end;
[0048] The fourth acquisition module is used to acquire the time difference between the time when the message is received by the communication layer of the receiving end and the time when the message is received by the application layer.
[0049] The determination module is used to determine the time deviation based on the sending time, network transmission time, time difference, and receiving time.
[0050] The compensation module is used to compensate the local time based on the time deviation in order to determine the target time.
[0051] To address the aforementioned technical problems, this application also provides an electronic device, including a memory for storing computer programs;
[0052] A processor is used to implement the steps of the time synchronization method described above when executing a computer program.
[0053] To address the aforementioned technical problems, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of the aforementioned time synchronization method.
[0054] This application provides a time synchronization method applied to the synchronized end, comprising: obtaining the transmission time of a message sent by the time synchronization end; obtaining the reception time of the message received by the application layer of the synchronized end; obtaining the network transmission time of the message between the time synchronization end and the synchronized end; obtaining the time difference between the time the message is received by the communication layer of the synchronized end and the time the message is received by the application layer; determining a time deviation based on the transmission time, network transmission time, time difference, and reception time; and compensating the local time based on the time deviation to determine a target time. This application determines the compensation level by acquiring different message transmission times to compensate the local time and determine the target time. Simultaneously, this application reduces the CPU scan cycle requirement in the device, effectively reducing the load on low-performance CPUs. Attached Figure Description
[0055] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0056] Figure 1A flowchart of a time synchronization method provided in an embodiment of this application;
[0057] Figure 2 A schematic diagram of a time synchronization method provided in an embodiment of this application;
[0058] Figure 3 A schematic diagram of the time synchronization method provided by the prior art;
[0059] Figure 4 A time synchronization device module diagram provided for another embodiment of this application;
[0060] Figure 5 A structural diagram of an electronic device provided in another embodiment of this application. Detailed Implementation
[0061] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, all other embodiments obtained by those of ordinary skill in the art without creative effort are within the protection scope of this application.
[0062] The core of this application is to provide a time synchronization method and apparatus.
[0063] To enable those skilled in the art to better understand the present application, the present application will be further described in detail below with reference to the accompanying drawings and specific embodiments.
[0064] Figure 1 A time synchronization method flowchart provided in this application embodiment, applied to the end being synchronized, includes the following steps as shown in the figure:
[0065] S10: Obtain the sending time of the message sent by the time synchronization terminal.
[0066] In specific embodiments, SCADA systems cannot perform time calibration independently and typically require an external master clock to correct their own clock. This external master clock is usually accessed through the SCADA system's FEP (Front End Pointer). The calibrated end is the SCADA system, and the time-providing end is the external master clock, which is a relatively accurate timekeeping system like the BeiDou system.
[0067] The acquisition process involves two scenarios: First, the time-synchronized end sends a time request to the time-synchronized end. The time-synchronized end then sends a message back to the time-synchronized end based on the time request, allowing the time-synchronized end to obtain the transmission time of the message. Second, the time-synchronized end sends messages to the time-synchronized end intermittently. The time-synchronized end scans at a preset scanning period to see if it has received any messages from the time-synchronized end, thus obtaining the transmission time of the message. The time-synchronized end obtains the transmission time of the message sent by the time-synchronized end, which is essentially the point in time when the message was sent.
[0068] S11: Get the reception time of the message received by the application layer of the terminal being checked.
[0069] In a specific embodiment, the message is sent by the time synchronization end, and received by the communication layer of the synchronization end. Then, the application layer of the synchronization end probes the communication layer to determine whether the message has been received. If the message is received, it is acquired; otherwise, the probe continues in the next round to acquire the message sent by the time synchronization end. Once the application layer of the synchronization end detects the message, it acquires it, and the moment when the application layer of the synchronization end acquires the message can be determined. The moment when the application layer receives the message is the exact time point in time when the message is received.
[0070] S12: Obtain the network transmission time of the message between the time synchronization end and the time synchronization end.
[0071] In a specific embodiment, the time synchronization end and the time being synchronized end are two different devices, and there will be a certain distance between the different devices. The transmission of the message between the time synchronization end and the time being synchronized end takes a certain amount of time. Therefore, the network transmission time of the message between the time synchronization end and the time being synchronized end is obtained.
[0072] S13: Obtain the time difference between the time the message is received by the communication layer of the receiving end and the time the message is received by the application layer.
[0073] In a specific embodiment, the end being calibrated is divided into a communication layer and an application layer. The communication layer of the end being calibrated receives the message, and then the application layer of the end being calibrated determines whether the communication layer has received the message by probing the communication layer of the end being calibrated. There is also a time difference between the communication layer receiving the message and the application layer probing the communication layer. Therefore, it is necessary to obtain the time difference between the time when the message is received by the communication layer of the end being calibrated and the time when the message is received by the application layer.
[0074] If a message is received, the message is retrieved. If no message is received, the probe continues in the next round of probing to obtain the time when the message sent by the time synchronization end is received by the communication layer of the synchronization end and the time when the message is received by the application layer. The corresponding time difference is determined based on the two times.
[0075] S14: Determine the time deviation based on the sending time, network transmission time, time difference, and receiving time.
[0076] In a specific embodiment, two distinct time points can determine a time deviation. However, to ensure the accuracy of the time deviation, this application determines the time deviation by combining the sending time, network transmission time, time difference, and receiving time. The specific calculation method is not limited in this application and can be set according to the user's needs.
[0077] S15: Compensate for local time based on time deviation to determine the target time.
[0078] In a specific embodiment, after determining the time deviation according to S14, the time of the device being calibrated can be compensated according to the time deviation. The compensation can be to increase or decrease the value of the local time according to the time deviation, thereby achieving the calibration of the local time of the device being calibrated.
[0079] This application provides a time synchronization method applied to the synchronized end, comprising: obtaining the transmission time of a message sent by the time synchronization end; obtaining the reception time of the message received by the application layer of the synchronized end; obtaining the network transmission time of the message between the time synchronization end and the synchronized end; obtaining the time difference between the time the message is received by the communication layer of the synchronized end and the time the message is received by the application layer; determining a time deviation based on the transmission time, network transmission time, time difference, and reception time; and compensating the local time based on the time deviation to determine a target time. This application determines the compensation level by acquiring different message transmission times to compensate the local time and determine the target time. Simultaneously, this application reduces the CPU scan cycle requirement in the device, effectively reducing the load on low-performance CPUs.
[0080] Based on the above embodiments, as a preferred embodiment, the time deviation is determined according to the sending time, network transmission time, time difference, and receiving time, including:
[0081] The time deviation is calculated by subtracting the time determined by the receiving time from the sum of the sending time, network transmission time, and time difference.
[0082] In a specific embodiment, to ensure the accuracy of the calculated time deviation, four time parameters are used: the network transmission time of the message between the time synchronization end and the time being synchronized end, the time difference between the time the message is received from the communication layer and the time the message is received by the application layer, the sending time, and the receiving time. These four time parameters are used to calculate a more accurate time deviation.
[0083] The formula for calculating the time deviation is as follows:
[0084] T1 + DelayA = T2 + offset
[0085] T2 + DelayB = T3
[0086] offset = T1 - T3 + DelayA + DelayB
[0087] Where T1 is the sending time (the time when the time synchronization end sends the message), T2 is the time when the message is received by the communication layer, T3 is the receiving time (the time when the application layer receives the message), DelayA is the network transmission time (the network transmission time of the message between the time synchronization end and the synchronization end), DelayB is the time difference (the time difference between the time when the message is received by the communication layer and the time when the message is received by the application layer), and offset is the time deviation.
[0088] Among them, such as Figure 2 and Figure 3 As shown, Figure 2 This is a schematic diagram of a time synchronization method provided in an embodiment of this application. Figure 3 The diagram illustrates the time synchronization method provided by the existing technology. It is clear from the diagram that there is a time deviation variable in the middle.
[0089] It should be noted that T2 is an intermediate variable and is eliminated in the final offset formula. Therefore, T2 is not a mandatory variable and users can decide whether to include it based on their needs.
[0090] It should also be noted that the time deviation calculation formula provided in this application embodiment is only one possible method, but it is not limited to this calculation method. Users can choose a calculation formula according to their needs to obtain the time deviation.
[0091] In this embodiment of the application, by obtaining the network transmission time and time difference, and by calculating the initially determined sending and receiving times using the formula, a more accurate time deviation is obtained, thereby improving the accuracy of time calibration.
[0092] Based on the above embodiments, as a preferred embodiment, it further includes:
[0093] Multiple time deviations are obtained, and the time deviations are verified by an algorithm to obtain the target time deviation;
[0094] The local time is compensated based on the target time deviation to determine the target time.
[0095] In a specific embodiment, time is compensated based on a single time deviation. When network fluctuations or failures occur, the time deviation may have a large error. Therefore, as a preferred method, multiple time deviations are obtained and the algorithm is used to verify the multiple time deviations in order to obtain a final target time deviation that is more profitable. Accordingly, the local time is compensated using the target time deviation.
[0096] The algorithm verification includes various testing methods, which users can choose according to their needs. For example, if five time deviations are obtained, namely 0.01, 0.013, 0.012, 0.3, and 0.012, the data shows that the value of 0.3 is significantly different from the other four values, indicating a large error. Therefore, during calibration, the value of 0.3 is discarded, and the average of the remaining four values is taken as the target time deviation. Alternatively, the average of all five values can be used as the target time deviation.
[0097] In this embodiment of the application, by verifying the time deviation multiple times, a more accurate target time deviation can be obtained, which helps to improve the accuracy of time calibration.
[0098] Based on the above embodiments, as a preferred embodiment:
[0099] If the time synchronization device and the time-receiving device communicate via serial port, then the network transmission time of the message between the time synchronization device and the time-receiving device is obtained, including:
[0100] The network transmission time is determined based on the message's byte length, the number of data bits, parity bits, stop bits, and baud rate used during data link layer transmission.
[0101] If the time synchronization device and the time-receiving device transmit data via a network interface, then the network transmission time of the message between the time synchronization device and the time-receiving device is obtained, including:
[0102] Obtain the round-trip time from multiple time synchronization terminals;
[0103] Obtain the average of the round-trip times from multiple time synchronization terminals;
[0104] The product of the average value and the preset value is used as the network transmission time.
[0105] In a specific embodiment, the calculation method of DelayA (network transmission time) depends on the communication method between the time transmitter and the time receiver. If the time transmitter and the time receiver transmit data via serial port, the calculation formula for DelayA is as follows:
[0106] DelayA=L·(1+z+p+q)·1000 / r;
[0107] Where L is the length of the message in bytes; z is the number of data bits used in the data link layer transmission, usually 8; p is the number of parity bits, usually 1; q is the number of stop bits, usually 1 or 2; and r is the baud rate, such as 9600 (bps).
[0108] For example, when the communication protocol is Modbus RTU, assuming the message length L = 5 + 2·3 = 11, and the serial port parameters are 9600bps (r = 9600), 8 data bits (z = 8), 1 stop bit (q = 1), and even parity (p = 1), then...
[0109] L·(1+z+p+q)·1000 / r=11·(1+8+1+1)·1000 / 9600=12.6 (milliseconds);
[0110] If the time synchronization endpoint and the synchronized endpoint transmit data via a network interface (i.e., TCP / IP LAN transmission), then obtain the round-trip time (RTT) from the time synchronization endpoint multiple times, and discard the first i minimum values and the first j maximum values, where i and j are both not less than 1 and kij ≥ 3. Calculate the algebraic average of the remaining (kij) RTTs to obtain the final RTT. avg The formula for calculating DelayA is as follows:
[0111] DelayA = RTT avg / 2;
[0112] It should be noted that the calculation of network transmission time for Ethernet port transmission and serial port transmission provided in this application embodiment is only one possible method, and users can set it themselves according to their needs.
[0113] This application provides a method for calculating network transmission time for different transmission methods, which makes the clock deviation obtained by the calibrated end more accurate than conventional methods, thereby providing a universal and more accurate optimized time calibration scheme for the entire series of calibration messages.
[0114] Based on the above embodiments, as a preferred embodiment, obtaining the time difference between the time the message is received from the communication layer and the time the message is received by the application layer includes:
[0115] Obtain the reception period of the message received by the communication layer;
[0116] The reception time of the message by the application layer is determined based on the reception period;
[0117] The time difference is determined based on the reception time.
[0118] In a specific embodiment, the calculation of the time difference needs to be determined based on the reception period and the reception time. In the process of obtaining the reception period of the received message at the communication layer, there are two cases.
[0119] In the first scenario, if the time synchronization end and the time-receiving end use a response-based protocol, in reality, the time-receiving end is usually the message request initiator, and the time synchronization end is the message responder. That is, the message sending period (denoted as TS0) is actively controlled by the time-receiving end. During normal communication, the message receiving period is equal to the message sending period, P = TS0.
[0120] The second type: The time synchronization end and the synchronization end adopt a non-acknowledgment protocol, that is, the synchronization end cannot directly control the message transmission period by initiating a request through the active period. In this case, the message reception period or minimum reception interval can be marked in the following way: where, the time interval from the start of the scan to the receipt of the complete message by the application layer is denoted as a.
[0121] In the first round of scanning, application layer 'a' is used as the time interval to periodically scan for available packets. Assuming a complete packet is received after k1 scans, let T be the local time of the first scan in the first round. 11 The local time of the k1th scan in the first round is T. 1k1 ,remember:
[0122] P1 = T 1k1 -T 11 -a / 2;
[0123] There should be 0 ≤ DelayB1 ≤ a, where DelayB1 is the time difference corresponding to the first round of scanning.
[0124] In the second round of scanning, the application layer uses 'a' as the time interval to periodically scan for any available packets. Assuming a complete packet is received after k2 scans, let T be the local time of the first scan in the second round. 21 The local time for the k2th scan in the second round is T. 2k2 ,remember:
[0125] P2 = T 2k2 -T 21 -a / 2;
[0126] There should be 0 ≤ DelayB2 ≤ a, where DelayB2 is the time difference corresponding to the second round of scanning.
[0127] ...
[0128] In the nth round of scanning, the application processing layer uses 'a' as the time interval to periodically scan for any available packets. Assuming a complete packet is received after kn scans, let T be the local time of the first scan in the nth round. n1 The local time of the k1th scan in the nth round is T. nkn ,remember:
[0129] Pn = T nkn -Tn1 -a / 2;
[0130] There should be 0 ≤ DelayBn ≤ a, where DelayBn is the time difference corresponding to the nth round of scanning.
[0131] For n≥3, let the sequence SP{P1,P2,…,Pn} be denoted as P. Let the minimum value of SP be P. min The maximum value of SP is P. max Let Cv be the coefficient of variation of SP, and:
[0132]
[0133]
[0134] Where n is the number of scan rounds, i is the current scan round, and Pi 2 It is the square of the receiving period corresponding to the i-th scan.
[0135] There are two scenarios at this point, where the preset coefficient is Cv0;
[0136] Case 1: When Cv≤Cv0, SP is considered to be a near-identical sequence. Let P1≈P2≈……≈Pn, which means that the message receiving period is a fixed period P0, and P0≈{Pi}, where {Pi} represents any value in SP, i.e., P=P0.
[0137] Case 2: When Cv > Cv0, it is assumed that SP is in the interval [P min ,P max A fluctuating non-identical sequence indicates that the message reception period is non-fixed, and the reception interval between adjacent messages is within the interval [P]. min ,P max Fluctuation, i.e., P∈[P min ,P max ].
[0138] In a specific embodiment, the reception time of the message being received by the application layer is determined according to the reception period. First, the preset scanning period, the pre-coefficient, and the segmentation coefficient are obtained; then, the reception time is determined according to the preset scanning period, the pre-coefficient, the segmentation coefficient, and the reception period.
[0139] In the case of response type or non-response type 1, P can be considered a constant, and the method for obtaining the value of P has been detailed above. In this case, the formula for the receiving time is:
[0140]
[0141] Where T0 is the receiving time, P is the message receiving period, S0 is the preset scanning period under the conventional method, m is the cutting coefficient (m≥2), and λ is the pre-coefficient (λ≥1).
[0142] If it is case 2 in the non-acknowledgment type, the reception interval between adjacent messages is in the interval [P]. min ,P max Fluctuation, i.e., P∈[P min ,P max At this point, the formula for determining the receiving time is:
[0143]
[0144] Where P min S0 is the minimum value among the above message reception period calibration values, m is the preset scanning period under the above conventional method, m is the cutting coefficient (m≥2), and λ is the pre-coefficient (λ≥1).
[0145] In a specific embodiment, the time difference is determined based on the reception time. First, the target period corresponding to the reception time is obtained; the interval corresponding to the time difference is determined based on the target period; the expected value corresponding to the interval is obtained, and the expected value is used as the time difference.
[0146] In this case, after obtaining T0 according to the two scenarios described above, it is equivalent to the application layer taking a fixed rest period of T0 during each round of calibration message detection and reading cycle. The corresponding target period is Sa = S0 / m. When the application layer detects data in the communication layer buffer of the calibration end, it immediately records the local real-time T. rcv Simultaneously, data is read from the communication layer buffer of the target end and the data stream is parsed in real time. If a complete verification message is parsed from the data stream and T1 can be obtained from the message, and T1 = T rcv Since DelayB ∈ [0, S0 / m], its expected value within the interval can be directly taken.
[0147] Based on the above, we can conclude that:
[0148] The formula for calculating time deviation during serial communication is as follows:
[0149]
[0150] The formula for calculating time deviation during network communication is as follows:
[0151]
[0152] This application provides corresponding calculation methods for acknowledgment-type or non-acknowledgment-type synchronization messages of serial port or network port transmission media. It takes into account the delay at each level with a more refined algorithm, which makes the clock deviation obtained by the synchronized end more accurate than conventional methods. Thus, it provides a universal and more accurate optimized synchronization scheme for the entire series of synchronization messages.
[0153] This application provides a time synchronization method applied to the synchronized end, comprising: obtaining the transmission time of a message sent by the time synchronization end; obtaining the reception time of the message received by the application layer of the synchronized end; obtaining the network transmission time of the message between the time synchronization end and the synchronized end; obtaining the time difference between the time the message is received by the communication layer of the synchronized end and the time the message is received by the application layer; determining a time deviation based on the transmission time, network transmission time, time difference, and reception time; and compensating the local time based on the time deviation to determine a target time. This application determines the compensation level by acquiring different message transmission times to compensate the local time and determine the target time. Simultaneously, this application reduces the CPU scan cycle requirement in the device, effectively reducing the load on low-performance CPUs.
[0154] In the above embodiments, the time synchronization method has been described in detail. This application also provides embodiments corresponding to the time synchronization device. It should be noted that this application describes the embodiments of the device part from two perspectives: one is based on the functional module, and the other is based on the hardware.
[0155] Figure 4 A time synchronization device module diagram provided for another embodiment of this application, applied to the end being synchronized, is shown in the figure, including:
[0156] The first acquisition module 11 is used to acquire the transmission time of the message sent by the time synchronization end;
[0157] The second acquisition module 12 is used to acquire the reception time of the application layer received message at the end being verified;
[0158] The third acquisition module 13 is used to acquire the network transmission time of the message between the time synchronization end and the time being synchronized end;
[0159] The fourth acquisition module 14 is used to acquire the time difference between the time when the message is received by the communication layer of the calibration end and the time when the message is received by the application layer.
[0160] The determination module 15 is used to determine the time deviation based on the sending time, network transmission time, time difference, and receiving time.
[0161] The compensation module 16 is used to compensate the local time based on the time deviation in order to determine the target time.
[0162] Since the embodiments of the apparatus and the embodiments of the method correspond to each other, please refer to the description of the embodiments of the method for the embodiments of the apparatus, which will not be repeated here.
[0163] Figure 5 A structural diagram of an electronic device provided in another embodiment of this application, such as... Figure 5 As shown, the electronic device includes: a memory 20 for storing computer programs;
[0164] The processor 21 is used to implement the steps of the time synchronization method mentioned in the above embodiments when executing a computer program.
[0165] The electronic devices provided in this embodiment may include, but are not limited to, smartphones, tablets, laptops, or desktop computers.
[0166] The processor 21 may include one or more processing cores, such as a quad-core processor or an octa-core processor. The processor 21 may be implemented using at least one of the following hardware forms: Digital Signal Processor (DSP), Field-Programmable Gate Array (FPGA), or Programmable Logic Array (PLA). The processor 21 may also include a main processor and a coprocessor. The main processor, also known as the Central Processing Unit (CPU), is used to process data in the wake-up state; the coprocessor is a low-power processor used to process data in the standby state. In some embodiments, the processor 21 may integrate a Graphics Processing Unit (GPU), which is responsible for rendering and drawing the content to be displayed on the screen. In some embodiments, the processor 21 may also include an Artificial Intelligence (AI) processor, which is used to handle computational operations related to machine learning.
[0167] The memory 20 may include one or more computer-readable storage media, which may be non-transitory. The memory 20 may also include high-speed random access memory and non-volatile memory, such as one or more disk storage devices or flash memory devices. In this embodiment, the memory 20 is used to store at least the following computer program 201, which, after being loaded and executed by the processor 21, is capable of implementing the relevant steps of the time synchronization method disclosed in any of the foregoing embodiments. In addition, the resources stored in the memory 20 may also include an operating system 202 and data 203, and the storage method may be temporary storage or permanent storage. The operating system 202 may include Windows, Unix, Linux, etc.
[0168] In some embodiments, the electronic device may further include a display screen 22, an input / output interface 23, a communication interface 24, a power supply 25, and a communication bus 26.
[0169] Those skilled in the art will understand that Figure 5 The structures shown do not constitute a limitation on electronic devices and may include more or fewer components than those shown.
[0170] The electronic device provided in this application includes a memory and a processor. When the processor executes the program stored in the memory, it can implement the time synchronization method provided in the above embodiments, determine the time deviation, reduce the system's requirements for the CPU scan cycle, and effectively reduce the load on low-performance CPUs. At the same time, it compensates for the local time through the time deviation, thereby improving the time synchronization accuracy.
[0171] Finally, this application also provides an embodiment corresponding to a computer-readable storage medium. The computer-readable storage medium stores a computer program, which, when executed by a processor, implements the steps described in the above method embodiments.
[0172] It is understood that if the methods in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, 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. This computer software product is stored in a storage medium and executes all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0173] The foregoing has provided a detailed description of a time synchronization method and apparatus provided in this application. The various embodiments in the specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to in the method section. It should be noted that those skilled in the art can make several improvements and modifications to this application without departing from the principles of this application, and these improvements and modifications also fall within the protection scope of the claims of this application.
[0174] It should also be noted that, in this specification, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
Claims
1. A time synchronization method, characterized in that, Applied to the end being calibrated, including: Obtain the transmission time of the message sent by the time synchronization terminal; Obtain the time when the application layer of the target device receives the message; Obtain the network transmission time of the message between the time synchronization terminal and the time-synchronized terminal; Obtain the reception period of the communication layer of the target device receiving the message; Obtain the preset scanning cycle, pre-scan coefficient, and cutting coefficient; The reception time of the message being received by the application layer is determined based on the preset scanning period, the pre-coefficient, the segmentation coefficient, and the reception period. Obtain the target period corresponding to the receiving time; Determine the interval corresponding to the time difference based on the target period; Obtain the expected value corresponding to the interval, and use the expected value as the time difference; The time deviation is determined based on the sending time, the network transmission time, the time difference, and the receiving time; The local time is compensated based on the time deviation to determine the target time.
2. The time synchronization method according to claim 1, characterized in that, Determining the time deviation based on the sending time, the network transmission time, the time difference, and the receiving time includes: The time deviation is the sum of the sending time, the network transmission time, and the time difference, minus the time determined by the receiving time.
3. The time synchronization method according to claim 1 or 2, characterized in that, Also includes: The time deviations are obtained multiple times, and the time deviations are verified by an algorithm to obtain the target time deviation. The local time is compensated based on the target time deviation to determine the target time.
4. The time synchronization method according to claim 1, characterized in that, The time synchronization terminal and the time-receiving terminal transmit data via a serial port. Therefore, obtaining the network transmission time of the message between the time synchronization terminal and the time-receiving terminal includes: The network transmission time is determined based on the byte length of the message, the number of data bits, the number of parity bits, the number of stop bits, and the baud rate used during data link layer transmission.
5. The time synchronization method according to claim 1, characterized in that, The time synchronization terminal and the time-receiving terminal transmit data via a network port. Therefore, obtaining the network transmission time of the message between the time synchronization terminal and the time-receiving terminal includes: Obtain the round-trip time of the time synchronization terminal multiple times; Obtain the average value of the round-trip time of the time synchronization terminal multiple times; The product of the average value and the preset value is used as the network transmission time.
6. The time synchronization method according to claim 1, characterized in that, If the timing receiver and the synchronized receiver use a response-type protocol, then obtaining the reception period of the message received by the communication layer includes: Obtain the transmission period of the message sent by the timing terminal; The sending period is used as the receiving period.
7. The time synchronization method according to claim 1, characterized in that, If a non-acknowledgment protocol is used between the time synchronization end and the synchronization end, then obtaining the reception period of the message received by the communication layer includes: The application layer scans the communication layer at preset time intervals during multiple rounds of scanning to obtain the period of the message; Adjust the periods obtained from multiple rounds of scanning into a periodic sequence; The coefficient of variation is determined based on the periodic sequence; If the coefficient of variation is not greater than a preset coefficient, then any one period in the periodic sequence is selected as the receiving period; If the coefficient of variation is greater than the preset coefficient, then the receiving period is within the period range corresponding to the period sequence.
8. A time synchronization device, characterized in that, Applied to the end being calibrated, including: The first acquisition module is used to acquire the transmission time of the message sent by the time synchronization end; The second acquisition module is used to acquire the time when the application layer of the end being verified receives the message; The third acquisition module is used to acquire the network transmission time of the message between the time synchronization terminal and the time-synchronized terminal; The fourth acquisition module is used to acquire the reception period of the communication layer of the target end receiving the message; acquire a preset scanning period, a pre-coefficient, and a segmentation coefficient; determine the reception time of the message being received by the application layer based on the preset scanning period, the pre-coefficient, the segmentation coefficient, and the reception period; acquire the target period corresponding to the reception time; determine the interval corresponding to the time difference based on the target period; acquire the expected value corresponding to the interval, and use the expected value as the time difference; The determining module is used to determine the time deviation based on the sending time, the network transmission time, the time difference, and the receiving time; The compensation module is used to compensate the local time based on the time deviation in order to determine the target time.
Citation Information
Patent Citations
High-precision process layer Ethernet switch system time synchronization method and system
CN110492961A
Corrrecting time synchronization inaccuracy caused by asymmetric delay on a communication link
US20070147562A1
