Time synchronization method, controller, vehicle and computer program product
By interacting with time synchronization messages and peer delay messages in intelligent connected vehicles, the time elapse rate ratio and deviation stability parameters are calculated, and the stability problem of time synchronization messages is solved, and the stability of time synchronization messages is achieved, achieving more accurate and reliable Time synchronization improves the stability and success rate of the system.
Patent Information
- Application Number
- CN202411432659.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-14
- Publication Date
- 2024-12-17
AI Technical Summary
In intelligent connected vehicles, the time synchronization scheme based on the gptp protocol fails to effectively solve the problem of how the slave clock evaluates and filters normal and abnormal time synchronization packets, resulting in unstable time synchronization and it is difficult to ensure the time accuracy of the slave side.
By interacting with time synchronization messages and peer-to-peer delay messages between the active and slave terminals, the time elapse rate ratio and deviation stability parameters are calculated, and the network conditions are dynamically adapted to ensure that only synchronization is performed when the time deviation is stable, avoiding network conditions due to the network Time synchronization error caused by fluctuations and introduce follow-up messages to improve data integrity and reliability.
It improves the accuracy and reliability of time synchronization, significantly improves the success rate and stability of time synchronization, and can maintain the stable operation of the system in complex environments.
Smart Images

Figure CN119154984A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of communication technology, and in particular to a time synchronization method, a controller, a vehicle and a computer program product. Background Art
[0002] With the rapid development of electronic control and communication systems, intelligent connected vehicles, especially autonomous driving technology, are becoming more and more complex. When the car is driving in an unknown and dynamic environment, it is crucial to ensure the accurate time synchronization of data between various controllers. All OEMs (original equipment manufacturers) use a time synchronization solution based on the gptp protocol to synchronize the time between various controllers.
[0003] In the related art, in order to solve the problem of abnormal time jumps of each controller based on the gptp protocol, the dual-clock time synchronization mechanism is mainly adopted. When the first master clock fails, the second master clock is immediately switched to perform global time synchronization. However, it does not take into account how the slave end (i.e., the slave clock) evaluates and filters normal and abnormal time synchronization messages to ensure that the time of the slave end is stable and will not cause abnormal jumps on the slave end due to individual abnormal messages from the master end (i.e., the master clock). Therefore, how to complete accurate time synchronization is still a problem to be solved. Summary of the invention
[0004] The purpose of the embodiments of the present application is to provide a time synchronization method, a controller, a vehicle and a computer program product to achieve the technical effect of improving the accuracy and reliability of time synchronization.
[0005] A first aspect of an embodiment of the present application provides a time synchronization method, which is applied to a slave end to be synchronized with an active end; the method includes:
[0006] Perform time synchronization message interaction with the active end according to a preset first interaction cycle, and obtain a first interaction time set; the time synchronization message includes a first synchronization message and a second synchronization message sent by the active end to the slave end; the first interaction time set includes a first sending time and a first receiving time of the first synchronization message, and a second sending time and a second receiving time of the second synchronization message;
[0007] Determine a first rate ratio based on the first interaction time set; the first rate ratio represents a time lapse rate ratio between the active end and the passive end;
[0008] Performing peer delay message interaction with the active end, and acquiring a second interaction time set; the peer delay message includes a peer delay request message sent by the passive end to the active end, and a peer delay response message sent by the active end in response to the peer delay request message; the second interaction time set includes a third sending time and a third receiving time of the peer delay request message, and a fourth sending time and a fourth receiving time of the peer delay response message;
[0009] When the first rate ratio is within a preset rate ratio interval, a first deviation stability parameter and a delay parameter are determined based on the first rate ratio and the second interaction time set; the first deviation stability parameter represents a change in the time deviation of the slave end relative to the master end;
[0010] When the first deviation stability parameter is within a preset deviation stability parameter interval, the first rate ratio and the delay parameter are used to perform time synchronization processing with the active end.
[0011] In the above implementation process, the time passage rate ratio (i.e., the first rate ratio) between the active end and the passive end is calculated based on the message interaction data, providing a basis for time synchronization; and not only the difference in the time passage rate is taken into account, but also the stability of the network delay and time deviation (through the first deviation stability parameter) is further evaluated through the peer delay message interaction. This dynamic adaptability enables time synchronization to adapt to changes in network conditions more accurately; time synchronization processing is performed only when it is confirmed that the change in time deviation (the first deviation stability parameter characterizes this change) is within the preset stable range, ensuring that synchronization is performed only when the time deviation is relatively stable, avoiding time synchronization errors caused by network fluctuations; by combining the first rate ratio and the delay parameter for time synchronization processing, the time of the passive end can be corrected more accurately, thereby improving the accuracy and reliability of time synchronization.
[0012] Further, the time synchronization message also includes a first follow-up message carrying the first sending time and a second follow-up message carrying the second sending time sent by the active end to the slave end; the peer delay message also includes a peer delay response follow-up message carrying the fourth sending time sent by the active end to the slave end; the method also includes:
[0013] The first follow-up message, the second follow-up message, and the peer delay response follow-up message are parsed respectively to obtain the first sending time, the second sending time, and the fourth sending time.
[0014] In the above implementation process, the introduction of the follower message ensures that the sending time can be accurately transmitted to the slave end, thereby enhancing the integrity and reliability of the data.
[0015] Furthermore, the method further comprises:
[0016] When the first rate ratio is not within the rate ratio interval, a warning message is sent to the active end, and the step of performing time synchronization message interaction with the active end according to a preset first interaction period is returned until the first rate ratio is within the rate ratio interval.
[0017] In the above implementation process, by returning to the step of executing the time synchronization message interaction, an automatic correction mechanism is established. When a rate ratio abnormality is detected, instead of simply giving up synchronization or reporting an error, an attempt is made to correct the abnormality through repeated time synchronization message interactions until the rate ratio returns to the normal range. In addition, by continuously adjusting until the first rate ratio is within the rate ratio interval, it is ensured that further time synchronization processing is performed only when the time lapse rate ratio is relatively stable and in line with expectations, which significantly improves the success rate of time synchronization.
[0018] Furthermore, the method further comprises:
[0019] When the first deviation stability parameter is not within the deviation stability parameter interval, return to the step of performing peer-to-peer delay message interaction with the active end until the first deviation stability parameter is within the deviation stability parameter interval.
[0020] In the above implementation process, when the first deviation stability parameter is not within the deviation stability parameter interval, by continuously repeating the peer delay message interaction and re-evaluating the first deviation stability parameter, it is ensured that before the time synchronization processing, the time deviation change between the slave end and the active end is stable and predictable, which helps to reduce the time synchronization error caused by time deviation fluctuations and improve the stability of time synchronization.
[0021] Furthermore, before performing time synchronization message interaction with the active end according to the preset first interaction cycle, the method further includes:
[0022] Interacting the time synchronization message and the peer delay message with the active end according to a preset second interaction period, and acquiring a third interaction time set and a fourth interaction time set;
[0023] determining a second rate ratio and a second deviation stabilization parameter based on the third interaction time set and the fourth interaction time set;
[0024] The rate ratio interval and the deviation stability parameter interval are determined based on the second rate ratio and the second deviation stability parameter.
[0025] In the above implementation process, on the one hand, by first performing preliminary time synchronization message and peer delay message interaction according to the second interaction cycle, the system can calculate a more reasonable rate ratio interval and deviation stability parameter interval based on these interaction data, which provides a more accurate reference standard for the subsequent formal time synchronization process, and helps to improve the accuracy and stability of synchronization. On the other hand, the network environment and system status may change over time. Through preliminary interaction and real-time adjustment of the rate ratio interval and deviation stability parameter interval, the system can adapt to these changes more quickly and maintain the accuracy and reliability of time synchronization. This adaptive capability is crucial to ensure the stable operation of the system in a complex and changing environment.
[0026] Furthermore, the first interaction period is greater than the second interaction period.
[0027] In the above implementation process, in the initial stage and under abnormal conditions, the message interaction is performed according to the second interaction cycle, and in the stable stage, the message interaction is performed according to the first interaction cycle. The stable stage lasts longer, and setting the first interaction cycle to be greater than the second interaction cycle is beneficial to reducing the Ethernet load under normal conditions.
[0028] Further, the determining a first deviation stability parameter and a delay parameter based on the first rate ratio and the second interaction time set includes:
[0029] determining the first deviation stabilization parameter based on the second interaction time set;
[0030] When the first deviation stability parameter is within the deviation stability parameter interval, the delay parameter is determined according to the first rate ratio and the second interaction time set.
[0031] In the above implementation process, by evaluating the deviation stability first and then determining the order of the delay parameters, invalid synchronization operations are avoided when the time deviation is unstable. This sequential processing flow improves the efficiency of synchronization and reduces unnecessary resource consumption.
[0032] Further, the using the first rate ratio and the delay parameter to perform time synchronization processing with the active end includes:
[0033] Get the local time;
[0034] Determine a time to be synchronized based on the first rate ratio, the local time, the delay parameter, the second sending time, and the second receiving time;
[0035] The time synchronization process with the active end is performed according to the time to be synchronized.
[0036] In the above implementation process, by comprehensively considering the first rate ratio (reflecting the rate change during the time transmission process), the local time (the current time of the slave end), the delay parameter (compensating for the delay during the time transmission process), the second sending time (the time when the active end sends the time synchronization message) and the second receiving time (the time when the slave end receives the message), the time to be synchronized can be calculated very accurately. This comprehensive consideration of multiple factors significantly improves the accuracy of time synchronization.
[0037] A second aspect of an embodiment of the present application provides a controller, the controller comprising:
[0038] processor;
[0039] a memory for storing processor-executable instructions;
[0040] Wherein, when the processor calls the executable instruction, any method described in the first aspect is implemented.
[0041] A third aspect of an embodiment of the present application provides a vehicle, comprising the controller described in the second aspect.
[0042] A fourth aspect of the embodiments of the present application provides a computer program product, wherein the computer program product includes a computer program, and when the computer program is executed by a processor, any method described in the first aspect is implemented. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the embodiments of the present application will be briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present application and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without paying creative work.
[0044] Figure 1 A schematic diagram of a time synchronization method provided in an embodiment of the present application;
[0045] Figure 2 A flowchart of another time synchronization method provided in an embodiment of the present application;
[0046] Figure 3 A flowchart of another time synchronization method provided in an embodiment of the present application;
[0047] Figure 4 A schematic diagram of a time synchronization message interaction provided in an embodiment of the present application;
[0048] Figure 5 Another schematic diagram of time synchronization message interaction provided in an embodiment of the present application;
[0049] Figure 6 A schematic diagram of a peer-to-peer delay message interaction provided in an embodiment of the present application;
[0050] Figure 7 Another schematic diagram of peer-to-peer delay message interaction provided in an embodiment of the present application;
[0051] Figure 8 A hardware structure diagram of a controller provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] The technical solutions in the embodiments of the present application will be described below in conjunction with the drawings in the embodiments of the present application.
[0053] It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in subsequent drawings. At the same time, in the description of this application, the terms "first", "second", etc. are only used to distinguish the description and cannot be understood as indicating or implying relative importance.
[0054] In the time synchronization system, for the slave side, how to receive and judge the synchronization message sent by the master side to ensure the normal progress of the slave side time is still a problem that needs to be solved urgently.
[0055] In response to any of the above-mentioned problems, the present application provides a time synchronization method, referring to Figure 1 , Figure 1 A flowchart of a time synchronization method provided in an embodiment of the present application.
[0056] In this embodiment, the method is applied to a slave end to be synchronized with an active end; the method includes:
[0057] Step S10: performing time synchronization message interaction with the active end according to a preset first interaction cycle, and obtaining a first interaction time set; the time synchronization message includes a first synchronization message and a second synchronization message sent by the active end to the slave end; the first interaction time set includes a first sending time and a first receiving time of the first synchronization message, and a second sending time and a second receiving time of the second synchronization message;
[0058] It should be noted that the active end and the passive end may be devices, systems or modules. This embodiment and the following embodiments are described with the active end and the passive end being controllers of the vehicle.
[0059] The preset first interaction period refers to a time interval set between the active end and the passive end for periodically exchanging time synchronization messages. The setting of the first interaction period depends on multiple factors, such as the accuracy requirements of time synchronization, the tolerance of network delays, the utilization rate of system resources, etc. This embodiment does not limit the setting of the first interaction period.
[0060] This embodiment can be implemented based on the GPTP protocol (Generalized Precision Time Protocol), and the synchronization message can be a Sync message. In GPTP, the Sync message is the core component of the time synchronization process. It is sent periodically by the master clock (Master Clock, i.e., the active end) to provide an accurate time reference to the slave clock (SlaveClock, i.e., the slave end). The Sync message contains the timestamp of the time of sending (usually the hardware timestamp of the master clock), which is the basis for subsequent time calculation and synchronization.
[0061] The sync message usually contains the following key information:
[0062] Timestamp: This is the core of the sync message, indicating the precise time when the master clock sent the message.
[0063] Sequence number: used to identify the version or order of the sync message, which helps the slave clock distinguish and process duplicate or out-of-order messages.
[0064] Protocol version and message type: Indicates the gptp version followed by the message and what type of message it is (a sync message in this embodiment).
[0065] Other control information: may include some additional information used for synchronization process optimization, such as path delay measurement, etc.
[0066] It should be understood that the time synchronization message includes at least the first synchronization message and the second synchronization message, and may also include any number of synchronization messages. If the time synchronization message includes more than two synchronization messages, the two synchronization messages closest to the moment are selected as the first synchronization message and the second synchronization message.
[0067] Step S20: determining a first rate ratio based on the first interaction time set; the first rate ratio represents a time lapse rate ratio between the active end and the passive end;
[0068] It should be noted that the rate ratio (or time lapse rate ratio) is determined by comparing the time lapse speed at both ends. Ideally, the time lapse speed at both ends should be the same, but in practical applications, there may be differences between them due to various factors (such as clock offset, network delay, etc.).
[0069] As an example, assuming that the first sending time and the first receiving time of the first synchronization message in the first interaction time set are t1 and t2 respectively, and the second sending time and the second receiving time of the second synchronization message are t3 and t4 respectively, the rate ratio can be determined by calculating the ratio between the difference between the second sending time t3 and the first sending time t1, and the difference between the second receiving time t4 and the first receiving time t2.
[0070] The rate ratio is calculated as follows:
[0071] k = (t3 - t1) / (t4 - t2);
[0072] Wherein, k is the rate ratio, t3 is the second sending time, t1 is the first sending time, t4 is the second receiving time, and t2 is the first receiving time.
[0073] Step S30: performing peer delay message interaction with the active end, and acquiring a second interaction time set; the peer delay message includes a peer delay request message sent by the slave end to the active end, and a peer delay response message sent by the active end in response to the peer delay request message; the second interaction time set includes a third sending time and a third receiving time of the peer delay request message, and a fourth sending time and a fourth receiving time of the peer delay response message;
[0074] It should be noted that the peer delay request message refers to the pdelay_req message, and the peer delay response message refers to the pdelay_resp message. The exchange of peer delay messages can be performed simultaneously with the exchange of time synchronization messages, or can be performed slightly later than the exchange of time synchronization messages.
[0075] The peer delay request message and the peer delay response message may be sent once or multiple times. If the number of times is multiple times, the peer delay request message and the peer delay response message that are closest to the present time are selected, and their interaction time is taken as the second interaction time set.
[0076] Specifically, the slave end generates a pdelay_req message and records its sending timestamp when sending, that is, the third sending time. The message may contain the identification information of the slave end, a sequence number (used to match requests and responses), and possible other control information. After receiving the pdelay_req message, the active end records the receiving timestamp, that is, the third receiving time. Then, the active end generates a pdelay_resp message and records its sending timestamp when sending, that is, the fourth sending time. The pdelay_resp message usually contains the identification information of the active end, the sequence number corresponding to the pdelay_req, and a possible sending timestamp (such as the fourth sending time) or some representation of the timestamp (such as the difference between the timestamp and a reference time). The slave end records the time when the pdelay_resp message is received, that is, the fourth receiving time.
[0077] Step S40: when the first rate ratio is within a preset rate ratio interval, determining a first deviation stability parameter and a delay parameter based on the first rate ratio and the second interaction time set; the first deviation stability parameter represents a change in the time deviation of the slave end relative to the master end;
[0078] It should be noted that the first rate ratio is within the preset rate ratio interval, which means that the time synchronization state between the active end and the passive end is within an acceptable range.
[0079] The rate ratio interval may be determined based on system requirements, performance standards, and actual application scenarios. This embodiment does not limit the rate ratio interval.
[0080] The deviation stability parameter can be specifically a deviation stability value, which is used to characterize the change of the time deviation of the slave end relative to the master end. In the time synchronization system, the time deviation refers to the difference between the actual time difference and the expected time difference between the two ends. The deviation stability parameter describes the stability and predictability of this deviation over time. By calculating and analyzing this parameter, the accuracy and stability of the slave end time synchronization can be evaluated.
[0081] The delay parameter refers to the time required from the active end sending a time synchronization message to the slave end receiving it and making corresponding adjustments.
[0082] In a specific implementation, the time synchronization message is interacted according to the first interaction cycle, and the rate ratio is determined according to the interaction time of the time synchronization message. When the rate ratio is in the preset rate ratio interval, the deviation stability value (i.e., the deviation stability parameter) is determined according to the second interaction time set, and then the delay parameter is calculated according to the second interaction time set and the first rate ratio. Specifically, according to the difference between the third sending time and the fourth receiving time, and the difference between the third receiving time and the fourth sending time, the ratio between the two differences is calculated to obtain the deviation stability value (i.e., the deviation stability parameter). The difference between the fourth receiving time and the third sending time is multiplied by the first rate ratio, and then the difference between the fourth sending time and the third receiving time is subtracted, and the result is divided by two to finally obtain the delay parameter.
[0083] The calculation formula of the deviation stability parameter S is as follows:
[0084] S = (ta - td) / (tb - tc);
[0085] Wherein, S is a deviation stability parameter, td is a receiving time of a peer delay response message (i.e., a fourth receiving time), ta is a sending time of a peer delay request message (i.e., a third sending time), tc is a sending time of a peer delay response message (i.e., a fourth sending time), and tb is a receiving time of a peer delay request message (i.e., a third receiving time);
[0086] The calculation formula of the delay parameter is as follows:
[0087] delay=[(td-ta)*k–(tc-tb)] / 2;
[0088] In the formula, delay is a delay parameter, td is the reception time of the peer delay response message (i.e., the fourth reception time), ta is the sending time of the peer delay request message (i.e., the third sending time), k is the rate ratio, tc is the sending time of the peer delay response message (i.e., the fourth sending time), and tb is the reception time of the peer delay request message (i.e., the third reception time).
[0089] Step S50: When the first deviation stability parameter is within a preset deviation stability parameter interval, the first rate ratio and the delay parameter are used to perform time synchronization processing with the active end.
[0090] It should be noted that the deviation stability parameter is within the preset deviation stability parameter range, which means that the time deviation change of the slave end relative to the master end is stable and within an acceptable range. This is the prerequisite for time synchronization processing. If time synchronization is performed directly when the deviation is unstable, it may lead to larger time errors.
[0091] Exemplarily, after confirming that the deviation stability parameter is within the preset interval, the delay parameter is further analyzed. Through these two parameters, the accuracy of the current time synchronization and possible problems can be evaluated. Based on the analysis results of the deviation stability and delay, the time synchronization strategy is adjusted. This may include adjusting the sending frequency of the synchronization signal, adjusting the time compensation amount during the synchronization process, or adopting a more complex synchronization algorithm. After determining the appropriate synchronization strategy, the actual time synchronization operation is performed. In this process, the time of the slave end is adjusted according to the first rate ratio and the delay parameter to keep it consistent with the time of the active end.
[0092] In this embodiment, according to the preset first interaction cycle, the slave end and the active end interact with each other through time synchronization messages, wherein the active end sends at least two synchronization messages to the slave end, records and obtains a first interaction time set, which includes the sending and receiving time of the synchronization message; based on the first interaction time set, calculates and determines a rate ratio (i.e., a first rate ratio); the slave end and the active end interact with each other through peer delay messages, the slave end sends a peer delay request message to the active end, and the active end responds and sends a peer delay response message; records and obtains a second interaction time set, which includes the sending time and receiving time of the peer delay request message and the peer delay response message. When the first rate ratio is within the preset rate ratio interval, further based on the first rate ratio and the second interaction time set, calculates and determines a first deviation stability parameter and a delay parameter. When the first deviation stability parameter is within the preset deviation stability parameter interval, the first rate ratio and the delay parameter are used to perform time synchronization processing with the active end. By introducing deviation stability parameters and rate ratios, subsequent time synchronization processing is performed only when they are in a controllable range, otherwise no time synchronization processing is performed. This conditional judgment mechanism gives the slave end the ability to judge abnormal messages, avoiding unnecessary synchronization operations in an unstable state, thereby improving the stability and reliability of the system.
[0093] On the basis of any of the above embodiments, the time synchronization message also includes a first follow-up message carrying the first sending time and a second follow-up message carrying the second sending time sent by the active end to the slave end; the peer delay message also includes a peer delay response follow-up message carrying the fourth sending time sent by the active end to the slave end; the method also includes:
[0094] The first follow-up message, the second follow-up message, and the peer delay response follow-up message are parsed respectively to obtain the first sending time, the second sending time, and the fourth sending time.
[0095] It is understandable that this embodiment is for two-step time synchronization, which is a common time synchronization method. Unlike one-step time synchronization (One-Step Clock), two-step time synchronization does not directly carry timestamp information when sending a sync event message, but transmits the timestamp when the sync message is sent through the follow_up message sent subsequently. Although this method has one more message than one-step time synchronization, it reduces the requirements for Ethernet PHY hardware, making the implementation more flexible and extensive.
[0096] The follow-up message (i.e., follow_up message) is sent after the synchronization message, and the peer delay response follow-up message (i.e., pdelay_follow_up message) is sent after the peer delay response message. The purpose of these follow-up messages is to ensure that the slave end can accurately obtain the exact timestamp when the master end sends the synchronization message or the peer delay response message, thereby eliminating or reducing the time error caused by factors such as network delay.
[0097] In this embodiment, the introduction of follow-up messages significantly improves the accuracy of time synchronization. Since these messages directly carry the exact time (i.e., the first sending time, the second sending time, and the fourth sending time) when the active end sends the synchronization message or the peer delay response message, the slave end can directly use these timestamps to calculate time synchronization without relying on additional network delay estimates or assumptions. This eliminates the impact of network delay uncertainty on time synchronization accuracy.
[0098] Based on any of the above embodiments, the method further includes:
[0099] When the first rate ratio is not within the rate ratio interval, a warning message is sent to the active end, and the step of performing time synchronization message interaction with the active end according to a preset first interaction period is returned until the first rate ratio is within the rate ratio interval.
[0100] It should be understood that the warning message is a k_warn message.
[0101] The reason why the rate ratio is not within the rate ratio range may be that the active end suddenly changes time, or there is an abnormality in the message transmission in the middle, etc., which is essentially a time synchronization abnormality.
[0102] If the first rate ratio does not meet the preset rate ratio interval, it means that the time elapse rate difference between the active end and the passive end is too large to meet the time synchronization requirement. At this time, the passive end sends a warning message to the active end. The purpose of this warning message is to notify the active end that the current time elapse rate ratio is not within the acceptable range and that corresponding measures need to be taken to adjust it.
[0103] In a specific implementation, when the first rate ratio is not within the preset rate ratio interval, the slave end sends a k_warn message to the active end, so that the active end re-sends the synchronization message to the slave end according to the preset first interaction cycle, and the slave end records the sending and receiving time of the synchronization message and uses them as the first interaction time set. In addition, the active end can also send a follow-up message (i.e., follow_up message) once after each synchronization message is sent. The slave end re-determines the first rate ratio based on the first interaction time set, and determines whether the first rate ratio is within the preset rate ratio interval. If it is, subsequent time synchronization processing is performed. Otherwise, the step of performing time synchronization message interaction according to the first interaction cycle is returned again until the calculated first rate ratio is within the preset rate ratio interval.
[0104] In this embodiment, when the first rate ratio does not meet the preset interval, the system will not stop the time synchronization process immediately, but will try to solve the problem by sending a warning message and re-interacting the time synchronization message. This processing method enhances the robustness of the system, so that the system can still maintain the accuracy of time synchronization in the face of different network conditions and system states.
[0105] Based on any of the above embodiments, the method further includes:
[0106] When the first deviation stability parameter is not within the deviation stability parameter interval, return to the step of performing peer-to-peer delay message interaction with the active end until the first deviation stability parameter is within the deviation stability parameter interval.
[0107] In a specific implementation, when the first deviation stability parameter is not within the preset deviation stability parameter interval, it means that the time deviation between the slave end and the active end changes too much and does not meet the stability condition for time synchronization. At this time, return to the step of performing peer-to-peer delay message interaction with the active end, re-determine the second interaction time set, and then recalculate the first deviation stability parameter based on the new second interaction time set until the parameter is within the preset deviation stability parameter interval.
[0108] In this embodiment, by introducing the evaluation of the deviation stability parameter and repeatedly executing the steps of peer delay message interaction, it is possible to ensure that the time deviation between the slave end and the master end is in a stable state before time synchronization is performed. This helps to reduce the synchronization error caused by time deviation fluctuations and improve the stability of time synchronization.
[0109] Based on any of the above embodiments, before step S10, the following is also included: Figure 2 Steps S01 to S03 shown:
[0110] Step S01: performing the time synchronization message and the peer delay message interaction with the active end according to a preset second interaction cycle, and obtaining a third interaction time set and a fourth interaction time set;
[0111] Exemplarily, when the first rate ratio is not within the rate ratio interval and / or when the first deviation stability parameter is not within the deviation stability parameter interval, it is necessary not only to return to execute the step of exchanging time synchronization messages with the active end according to a preset first interaction period and / or return to execute the step of exchanging peer delay messages with the active end, but also to return to execute the step of exchanging the time synchronization messages and the peer delay messages with the active end according to a preset second interaction period provided in this embodiment, until the calculated new first rate ratio and / or the new first deviation stability parameter are within the preset interval.
[0112] It should be noted that before formally exchanging time synchronization messages with the active end according to the preset first interaction cycle, preliminary time synchronization messages and peer delay messages are exchanged with the active end according to a preset second interaction cycle. The purpose of this step is to collect sufficient data to more accurately determine the rate ratio interval and deviation stability parameter interval used in the subsequent synchronization process.
[0113] The second interaction period can be set based on network conditions, system requirements, synchronization accuracy requirements, and processing capabilities of the slave end and the master end, etc. This embodiment does not limit the second interaction period.
[0114] The third interaction time set includes the interaction time of the time synchronization message, and the fourth interaction time set includes the interaction time of the peer delay message.
[0115] Step S02: determining a second rate ratio and a second deviation stability parameter based on the third interaction time set and the fourth interaction time set;
[0116] It is understandable that the third interaction time set is a timestamp set related to the time synchronization message, and the rate ratio (i.e., the second rate ratio) can be calculated based on the timestamp information contained in this set. The fourth interaction time set is a timestamp set related to the peer delay message, and the deviation stability parameter (i.e., the second deviation stability parameter) can be calculated based on the timestamp information contained in this set.
[0117] Step S03: Based on the second rate ratio and the second deviation stability parameter, determine the rate ratio interval and the deviation stability parameter interval.
[0118] It should be noted that in the second interaction cycle, multiple interactions of time synchronization messages and peer delay messages will be performed, and a third interaction time set and the fourth interaction time set can be obtained for each interaction, and a corresponding rate ratio can be determined according to each third interaction time set, and a corresponding deviation stability parameter can be determined according to each fourth interaction time set. Therefore, the expected μ and variance σ of multiple rate ratios can be calculated. 2 At the same time, the expected μs and variance σs of multiple deviation stability parameters can also be calculated. 2 .
[0119] As an example, (-3σ 2 , μ) and / or (μ, 3σ 2 ) as the preset rate ratio interval; (-3σs 2 , μs) and / or (μs, 3σs 2 ) as the preset deviation stability parameter interval.
[0120] Optionally, this embodiment further provides a time synchronization method, which is applied to a slave end to be synchronized with an active end; the method includes:
[0121] Perform time synchronization message interaction with the active end according to a preset second interaction cycle, and obtain a third interaction time set; the time synchronization message includes a third synchronization message and a fourth synchronization message sent by the active end to the slave end; the third interaction time set includes a fifth sending time and a fifth receiving time of the third synchronization message, and a sixth sending time and a sixth receiving time of the fourth synchronization message;
[0122] Performing peer delay message interaction with the active end according to the second interaction cycle, and acquiring a fourth interaction time set; the peer delay message includes a peer delay request message sent by the slave end to the active end, and a peer delay response message sent by the active end in response to the peer delay request message; the fourth interaction time set includes a seventh sending time and a seventh receiving time of the peer delay request message, and an eighth sending time and an eighth receiving time of the peer delay response message;
[0123] Determine a second rate ratio and a second deviation stability parameter according to the third interaction time set and the fourth interaction time set; the second rate ratio represents the time lapse rate ratio between the active end and the passive end; the second deviation stability parameter represents the change of the time deviation of the passive end relative to the active end;
[0124] Determining a preset rate ratio interval and a preset deviation stability parameter interval based on the second rate ratio and the second deviation stability parameter;
[0125] The time synchronization message is interacted with the active end according to a preset first interaction cycle, and a first interaction time set is obtained; the time synchronization message includes a first synchronization message and a second synchronization message sent by the active end to the slave end; the first interaction time set includes a first sending time and a first receiving time of the first synchronization message, and a second sending time and a second receiving time of the second synchronization message;
[0126] Determine a first rate ratio based on the first interaction time set; the first rate ratio represents a time lapse rate ratio between the active end and the passive end;
[0127] Performing the peer delay message interaction with the active end, and acquiring a second interaction time set; the peer delay message includes the peer delay request message sent by the slave end to the active end, and the peer delay response message sent by the active end in response to the peer delay request message; the second interaction time set includes a third sending time and a third receiving time of the peer delay request message, and a fourth sending time and a fourth receiving time of the peer delay response message;
[0128] In the case where the first rate ratio is within the preset rate ratio interval, a first deviation stability parameter and a delay parameter are determined based on the first rate ratio and the second interaction time set; the first deviation stability parameter represents a change in the time deviation of the slave end relative to the master end;
[0129] When the first deviation stability parameter is within the preset deviation stability parameter interval, the first rate ratio and the delay parameter are used to perform time synchronization processing with the active end.
[0130] In this embodiment, by performing preliminary interaction and collecting data before formal synchronization, the parameter range used in the subsequent synchronization process can be determined more accurately; and the preliminary interaction process enables the system to dynamically adjust the synchronization parameters according to actual conditions (such as network conditions, system load, etc.). This adaptive capability enables the system to maintain stable synchronization performance in different environments.
[0131] Based on any of the above embodiments, the first interaction period is greater than the second interaction period.
[0132] It should be noted that the second interaction cycle is used to clarify the preset rate ratio range, and is only performed in the initial stage (such as the startup stage) and under abnormal conditions. The shorter the second interaction cycle, the higher the message sending frequency. In the formal stage, the message interaction is performed according to the first interaction cycle. The duration of the formal stage is usually longer than the initial stage and the abnormal state. The first interaction cycle is set to be longer than the second interaction cycle so that the message sending frequency in this cycle is lower than the message sending frequency in the second interaction cycle, which can reduce the Ethernet load under normal conditions.
[0133] In this embodiment, by setting the first interaction period to be greater than the second interaction period, the Ethernet load under normal conditions is reduced.
[0134] Based on any of the above embodiments, step S40 includes:
[0135] determining the first deviation stabilization parameter based on the second interaction time set;
[0136] When the first deviation stability parameter is within the deviation stability parameter interval, the delay parameter is determined according to the first rate ratio and the second interaction time set.
[0137] In a specific implementation, the ratio between the round-trip time difference from the slave end to the active end and then back to the slave end and the processing time difference of the slave end is the first deviation stability parameter. Specifically, according to the difference between the sending time ta (i.e., the third sending time) of the peer delay request message and the receiving time td (i.e., the fourth receiving time) of the peer delay response message, and the difference between the receiving time tb (i.e., the third receiving time) of the peer delay request message and the sending time tc (i.e., the fourth sending time) of the peer delay response message, the ratio between the two is calculated to determine the first deviation stability parameter S. The calculation formula of the deviation stability parameter S is as follows:
[0138] S = (ta - td) / (tb - tc);
[0139] Where S is the deviation stability parameter, td is the reception time of the peer delay response message, ta is the sending time of the peer delay request message, tc is the sending time of the peer delay response message, and tb is the reception time of the peer delay request message;
[0140] The first deviation stability parameter is located at (-3σs 2 , μs) or (μs, 3σs 2 ), multiply the difference between td (i.e., the fourth receiving time) and ta (i.e., the third sending time) by the first rate ratio k, and then subtract the difference between tc (i.e., the fourth sending time) and tb (i.e., the third receiving time), and divide the result by two to finally obtain the delay parameter delay. The calculation formula of the delay parameter is as follows:
[0141] delay=[(td-ta)*k–(tc-tb)] / 2;
[0142] Wherein, delay is the delay parameter, td is the reception time of the peer delay response message, ta is the sending time of the peer delay request message, k is the rate ratio, tc is the sending time of the peer delay response message, and tb is the reception time of the peer delay request message.
[0143] In this embodiment, by determining the first deviation stability parameter based on the second interaction time set, the system can accurately evaluate the stability of the time deviation between the slave end and the master end. This is a crucial step in the time synchronization process, because a stable deviation is the basis for ensuring synchronization accuracy. In addition, after confirming that the first deviation stability parameter is within the preset deviation stability parameter interval, the delay parameter is further determined based on the first rate ratio and the second interaction time set, ensuring that the setting of the delay parameter is based on a stable deviation and an accurate rate ratio, thereby reducing synchronization errors.
[0144] Based on any of the above embodiments, step S50 includes: Figure 3 Steps S51 to S53 shown:
[0145] Step S51: Obtain local time;
[0146] It is understandable that the slave end can obtain the current local time from its own clock system, but due to various reasons (such as clock drift, network delay, etc.), this local time may deviate from the time of the master end.
[0147] Step S52: determining a time to be synchronized based on the first rate ratio, the local time, the delay parameter, the second sending time, and the second receiving time;
[0148] It should be noted that the sending time of the first synchronization message is earlier than the sending time of the second synchronization message. The second synchronization message is the most recently received synchronization message. Therefore, the second sending time and the second receiving time are closer to the present moment than the first sending time and the first receiving time.
[0149] Specifically, the difference between the local time tS of the slave end and the time ts of the last received synchronization message is multiplied by the first rate ratio k, and then the delay parameter delay and the time tm of the last synchronization message are added to obtain the time point tM to be synchronized. The calculation formula of the time tM to be synchronized is as follows:
[0150] tM=k(tS-ts)+delay+tm;
[0151] Wherein, tM is the synchronization waiting time, k is the rate ratio, tS is the local time at this moment, ts is the time when the synchronization message was last received (such as the second receiving time), delay is the delay parameter, and tm is the time when the synchronization message was last sent (such as the second sending time).
[0152] Step S53: performing time synchronization processing with the active end according to the time to be synchronized.
[0153] Specifically, the slave will adjust its clock system according to the calculated synchronization time to achieve time synchronization with the master. This adjustment process may include modifying the system time, adjusting the clock frequency, etc., to ensure that the slave can maintain the consistency of the master's time in the future.
[0154] In this embodiment, high-precision time synchronization between the slave end and the master end is achieved by accurately calculating the time to be synchronized and adjusting the clock system of the slave end.
[0155] In addition, this application also provides a time synchronization method, the specific implementation process is as follows:
[0156] This embodiment aims at two-step time synchronization, and tolerates the rate ratio k and delay of the master and slave ends respectively;
[0157] The fault tolerance mechanism for the time progress rate ratio k between the master and slave ends is as follows:
[0158] The first step is to quickly send sync messages and follow_up messages from the master end at a fixed period C1 after booting up. Figure 4 , the cycle and number of times can be configured by the user;
[0159] In the second step, after receiving the slave end, the time rate progress ratio (i.e., rate ratio) k = (t3-t1) / (t4-t2) of multiple master ends and slave ends is calculated based on the time (t2, t4) of receiving the sync message in two consecutive frames and the time (t1, t3) of sending the sync message recorded in follow_up, and the expected μ and variance σ of multiple rate ratios k are obtained. 2 ;
[0160] Step 3: After the fast phase is over, the master sends sync messages and follow_up messages at a stable period C2, and C2 must be greater than C1.
[0161] Step 4: The slave side calculates the k value for each of the two sync messages and follow_up messages sent in the C2 cycle, and determines whether the value is within (-3σ 2, μ) or (μ, 3σ 2 ), if it is within the range, the k value is used for time synchronization calculation;
[0162] Step 5: If it is not within the range, the calculated k value is ignored and the slave sends a k_warn message to the master. Figure 5 , to trigger the master to resend multi-frame sync messages and follow_up messages with a period of C1, obtain the calculated rate ratio k according to the second to fourth steps, and perform time synchronization according to the stable rate ratio k;
[0163] The delay fault tolerance mechanism for the master and slave ends is as follows:
[0164] The first step is that after the salve is started, the slave end quickly sends a pdelay_req message to the master end at a fixed period C3 and number of times (both the period and the number of times are configurable). Taking the first time as an example, the time when the slave end sends the message is recorded as ta, and the time when the master end receives the pdelay_req message is recorded as tb;
[0165] Step 2: After receiving the pdelay message, the master immediately sends a pdelay_resp message to the slave. The message contains the time tb when the master receives the pdelay_req message. In addition, when the master sends the pdelay_resp message, it also sends a pdelay_follow_up message. The message must carry the time tc when the master sends the pdelay_resp message.
[0166] Step 3: The time when the slave receives pdelay_follow_up is recorded as td. For a pdelay_resp message cycle, the timestamps that the slave can obtain at this time are ta, tb, tc, and td. For details, see Figure 6 , calculate the deviation stable value S = (ta-td) / (tb-tc). Since multiple frames of pdelay_req messages are sent quickly, multiple stable values S can be obtained, and the expected μs and variance σs of the stable value S are completed. 2 calculate;
[0167] Step 4: After the fast phase is over, the slave sends pdelay_req messages at a stable cycle C4 and the master responds with pdelay_resp and pdelay_follow_up. C4 must be greater than C3 and is configured by the user.
[0168] Step 5: After the calculation of the stable value S is completed each time with the normal cycle C4, determine whether S is in (-3σs 2 , μs) or (μs, 3σs 2 ), if it is within the range, the delay calculation is completed according to the stable rate ratio k value calculated in the fourth step of the fault tolerance mechanism for the time progress rate ratio k between the master and slave ends, and the delay delay=[(td-ta)*k–(tc-tb)] / 2;
[0169] Step 6: If it is not within the range, the calculated stable value S is ignored. The slave end recalculates the expectation and variance of the stable value S by quickly completing the pdelay message cycle multiple times with the period C3 and the configured number of times, and completes the delay calculation according to the second to fifth steps. For details, see Figure 7 .
[0170] Step 7. Based on the above-obtained rate deviation value k and delay, the time synchronization between the slave and master ends can be finally achieved: tM=k(tS-ts)+delay+tm, where tM is the time to be synchronized, k is the rate ratio, tS is the local time at this moment, ts is the time when the last synchronization message was received, delay is the delay parameter, and tm is the time when the last synchronization message was sent.
[0171] Based on the method described in any of the above embodiments, the present application also provides Figure 8 A schematic diagram of the structure of a controller is shown in FIG. Figure 8 At the hardware level, the controller includes a processor, an internal bus, a network interface, a memory, and a non-volatile memory, and may also include hardware required for other services. The processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the method described in any of the above embodiments.
[0172] Based on the method described in any of the above embodiments, the present application also provides a vehicle, which includes the controller described in any of the above embodiments.
[0173] Based on the method described in any of the above embodiments, the present application also provides a computer program product, which includes one or more computer programs or instructions. The computer program or instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. When the computer program is executed by a processor, the method described in any of the above embodiments is implemented.
[0174] In several embodiments provided in the present application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and block diagrams in the accompanying drawings show the possible architecture, functions and operations of the devices, methods and computer program products according to multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of a code, and the module, a program segment or a part of a code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram and / or flowchart, and the combination of boxes in the block diagram and / or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or action, or can be implemented with a combination of dedicated hardware and computer instructions.
[0175] In addition, the functional modules in the various embodiments of the present application may be integrated together to form an independent part, or each module may exist separately, or two or more modules may be integrated to form an independent part.
[0176] If the functions are implemented in the form of software function modules 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 the present application can be essentially or partly embodied in the form of a software product that contributes to the prior art. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the methods described in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.
[0177] The above description is only an embodiment of the present application and is not intended to limit the scope of protection of the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application. It should be noted that similar reference numerals and letters represent similar items in the following drawings, so once an item is defined in one drawing, it does not need to be further defined and explained in the subsequent drawings.
[0178] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.
[0179] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.
Claims
1. A time synchronization method, characterized in that: The method is applied to a slave end to be synchronized with an active end; the method comprises: Perform time synchronization message interaction with the active end according to a preset first interaction cycle, and obtain a first interaction time set; the time synchronization message includes a first synchronization message and a second synchronization message sent by the active end to the slave end; the first interaction time set includes a first sending time and a first receiving time of the first synchronization message, and a second sending time and a second receiving time of the second synchronization message; Determine a first rate ratio based on the first interaction time set; the first rate ratio represents a time lapse rate ratio between the active end and the passive end; Performing peer delay message interaction with the active end, and acquiring a second interaction time set; the peer delay message includes a peer delay request message sent by the passive end to the active end, and a peer delay response message sent by the active end in response to the peer delay request message; the second interaction time set includes a third sending time and a third receiving time of the peer delay request message, and a fourth sending time and a fourth receiving time of the peer delay response message; When the first rate ratio is within a preset rate ratio interval, a first deviation stability parameter and a delay parameter are determined based on the first rate ratio and the second interaction time set; the first deviation stability parameter represents a change in the time deviation of the slave end relative to the master end; When the first deviation stability parameter is within a preset deviation stability parameter interval, the first rate ratio and the delay parameter are used to perform time synchronization processing with the active end.
2. The method according to claim 1, characterized in that The time synchronization message also includes a first follow-up message carrying the first sending time and a second follow-up message carrying the second sending time, which are sent by the active end to the slave end; The peer delay message also includes a peer delay response follow-up message carrying the fourth sending time sent by the active end to the slave end; the method also includes: The first follow-up message, the second follow-up message, and the peer delay response follow-up message are parsed respectively to obtain the first sending time, the second sending time, and the fourth sending time.
3. The method according to claim 1, characterized in that The method further comprises: When the first rate ratio is not within the rate ratio interval, a warning message is sent to the active end, and the step of performing time synchronization message interaction with the active end according to a preset first interaction period is returned until the first rate ratio is within the rate ratio interval.
4. The method according to claim 1, characterized in that The method further comprises: When the first deviation stability parameter is not within the deviation stability parameter interval, return to the step of performing peer-to-peer delay message interaction with the active end until the first deviation stability parameter is within the deviation stability parameter interval.
5. The method according to claim 1, characterized in that Before performing time synchronization message interaction with the active end according to the preset first interaction cycle, the method further includes: Interacting the time synchronization message and the peer delay message with the active end according to a preset second interaction period, and acquiring a third interaction time set and a fourth interaction time set; determining a second rate ratio and a second deviation stabilization parameter based on the third interaction time set and the fourth interaction time set; The rate ratio interval and the deviation stability parameter interval are determined based on the second rate ratio and the second deviation stability parameter.
6. The method according to claim 5, characterized in that The first interaction period is greater than the second interaction period.
7. The method according to claim 1, characterized in that The determining a first deviation stability parameter and a delay parameter based on the first rate ratio and the second interaction time set includes: determining the first deviation stabilization parameter based on the second interaction time set; When the first deviation stability parameter is within the deviation stability parameter interval, the delay parameter is determined according to the first rate ratio and the second interaction time set.
8. The method according to claim 1, characterized in that The using the first rate ratio and the delay parameter to perform time synchronization processing with the active end includes: Get the local time; Determine a time to be synchronized based on the first rate ratio, the local time, the delay parameter, the second sending time, and the second receiving time; The time synchronization process with the active end is performed according to the time to be synchronized.
9. A controller, characterized in that: The controller comprises: processor; a memory for storing processor-executable instructions; Wherein, when the processor calls the executable instruction, the method described in any one of claims 1-8 is implemented.
10. A vehicle, characterized in that: The vehicle comprises the controller of claim 9.
11. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 8 is implemented.
