Time synchronization method and time synchronization equipment of embedded system and valve control system

By adopting a two-level master-slave node architecture and CAN network priority filtering mechanism in embedded systems, the communication delay problem caused by multi-node architecture is solved, time accuracy and applicability are improved, and it is suitable for embedded systems in the field of power energy storage.

CN120263327APending Publication Date: 2025-07-04CONTEMPORARY AMPEREX FUTURE ENERGY RES INST (SHANGHAI) LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410008471.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-01-02
Publication Date
2025-07-04

AI Technical Summary

Technical Problem

The multi-node architecture of the existing embedded system results in communication delays, reducing time-based accuracy, and unable to meet the diversified needs of communication between modules in the field of power energy storage.

Method used

It adopts a two-level master-slave node architecture to transmit time-based broadcast messages through the CAN network, and adds a priority filtering mechanism to reduce the architectural level and improve time-based accuracy and applicability.

Benefits of technology

It reduces communication delay between nodes, improves time accuracy and applicability, and is suitable for embedded systems in the field of power energy storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120263327A_ABST
    Figure CN120263327A_ABST
Patent Text Reader

Abstract

The invention provides a time synchronization method and time synchronization equipment of an embedded system and a valve control system. Relates to the technical field of system time synchronization. The method comprises the following steps: a time synchronization master node obtains a time synchronization request message sent by a time synchronization slave node and a second timestamp when the time synchronization request message is received; the time synchronization request message comprises a first timestamp when the time synchronization slave node sends the time synchronization request message; sending a time synchronization reply message to the time synchronization slave node based on the time synchronization request message; the time synchronization reply message comprises a first timestamp, a second timestamp and a third timestamp when the time synchronization reply message is sent; the time synchronization reply message is used for indicating the time synchronization slave node to correct the system time; according to the embodiment of the invention, by setting a two-stage time synchronization mechanism of the time synchronization master node and the time synchronization slave node, the architecture hierarchy is reduced, and the communication delay between the nodes is reduced; the time synchronization precision of each time synchronization node in the embedded system is improved by recording the timestamps in the communication process between the two stages of time synchronization nodes.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the technical field of system time synchronization, and particularly to a time synchronization method, a time synchronization device, a valve control system and a computer-readable storage medium for an embedded system. Background Art

[0002] With the continuous improvement of the modularization and softwareization levels of embedded systems in the power system, the application of embedded systems in the field of power energy storage has become increasingly widespread. For example, the valve control system in a power energy storage system collects, processes, and controls data on the operating conditions of the power energy storage system, realizing secondary control and protection of the power energy storage system.

[0003] Currently, when using an embedded system as a secondary control and protection device for a power system, its operation control and system monitoring require the internal time to be synchronized with an external clock. In the process of clock synchronization in related technologies, a multi-node architecture is adopted. Due to the large number of levels in the node architecture, it is easy to cause communication delays between multi-level nodes, reducing the time synchronization accuracy. Summary of the Invention

[0004] According to various embodiments of this application, a time synchronization method, a time synchronization device, a valve control system and a computer-readable storage medium for an embedded system are provided, which can solve the problem of communication delays between multi-level nodes and reduced time synchronization accuracy caused by the large number of levels in the node architecture.

[0005] In a first aspect, this application provides a time synchronization method for an embedded system, which is applied to a time synchronization master node. The method includes: the time synchronization master node obtains a time synchronization request message sent by a time synchronization slave node and a second timestamp when receiving the time synchronization request message; the time synchronization request message includes a first timestamp when the time synchronization slave node sends the time synchronization request message; based on the time synchronization request message, a time synchronization reply message is sent to the time synchronization slave node; the time synchronization reply message includes the first timestamp, the second timestamp, and a third timestamp when sending the time synchronization reply message; the time synchronization reply message is used to instruct the time synchronization slave node to correct the system time.

[0006] By the above method, by setting up a two-level time synchronization mechanism of a time synchronization master node and a time synchronization slave node, the number of architecture levels is reduced, and the communication delay between nodes is reduced; by recording the timestamps during the communication process between the two-level time synchronization nodes, the time synchronization accuracy of each time synchronization node in the embedded system is improved; it has strong usability and practicality.

[0007] In a possible implementation manner of the first aspect, before obtaining the time synchronization request message sent by the time synchronization slave node and the second timestamp when receiving the time synchronization request message, the method further includes:

[0008] Obtain the time synchronization signal sent by the time synchronization device, where the time synchronization signal includes the time synchronization time; based on the system time or the time synchronization time in the time synchronization signal, send a time synchronization broadcast message to the time synchronization slave node, and the time synchronization broadcast message is used to instruct the time synchronization slave node to send a time synchronization request message.

[0009] Through the above method, the time synchronization master node can perform system time synchronization based on the obtained time synchronization signal of the time synchronization device, and actively send a time synchronization broadcast message to the time synchronization slave node, providing high-precision time synchronization time for the time synchronization slave node and improving the time synchronization accuracy of the time synchronization device.

[0010] In a possible implementation manner of the first aspect, after obtaining the time synchronization signal sent by the time synchronization device, the method further includes:

[0011] If the difference between the system time and the time synchronization time is greater than or equal to a preset time threshold, update the system time and the actual time to the time synchronization time; if the difference between the system time and the time synchronization time is less than the preset time threshold, update the actual time to the system time.

[0012] Through the above method, based on the time synchronization signal provided by the time synchronization device, monitor whether the system time drifts, realize the time synchronization between the time synchronization master node and the external clock, and improve the time synchronization accuracy and efficiency.

[0013] In a possible implementation manner of the first aspect, sending a time synchronization broadcast message to the time synchronization slave node based on the system time or the time synchronization time in the time synchronization signal includes:

[0014] Based on the CAN bus, send a time synchronization broadcast message containing the time synchronization time or the system time to the time synchronization slave node.

[0015] Through the above method, the CAN network communication method is adopted between the time synchronization master node and the time synchronization slave node, with strong applicability, can be applied to embedded systems, and reduces the dependence on Ethernet communication.

[0016] In a possible implementation manner of the first aspect, before sending a time synchronization broadcast message to the time synchronization slave node based on the system time or the time synchronization time in the time synchronization signal, the method further includes:

[0017] If the time synchronization broadcast message is the highest-priority message to be sent in the message sending queue, send the time synchronization broadcast message; if there are other messages to be sent in the message sending queue with a priority higher than the time synchronization broadcast message, send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization broadcast message.

[0018] In the above manner, by adding a network packet priority filtering mechanism and performing network communication based on the priority of the send queue, the impact on other service communications during the time synchronization process is reduced; at the same time, by means of a timeout mechanism to suspend the sending of time synchronization broadcast packets, the time synchronization error can be reduced and the time synchronization accuracy can be improved.

[0019] In a second aspect, the present application provides a time synchronization method for an embedded system, which is applied to a time synchronization slave node. The method includes: sending a time synchronization request packet to a time synchronization master node, where the time synchronization request packet includes a first timestamp when the time synchronization request packet is sent; obtaining a time synchronization response packet sent by the time synchronization master node based on the time synchronization request packet, where the time synchronization response packet includes the first timestamp, a second timestamp when the time synchronization master node receives the time synchronization request packet, and a third timestamp when the time synchronization master node sends the time synchronization response packet; and correcting the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when the time synchronization response packet is received.

[0020] In a possible implementation manner of the second aspect, correcting the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when the time synchronization response packet is received includes:

[0021] Calculating the time drift of the time synchronization slave node relative to the time synchronization master node based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp; and correcting the current system time according to the time drift.

[0022] In a possible implementation manner of the second aspect, before sending the time synchronization request packet to the time synchronization master node, the method further includes:

[0023] Obtaining service packets sent by the time synchronization master node; parsing the packet type of the service packets, where the packet type includes a time synchronization response packet or a time synchronization broadcast packet; the time synchronization response packet is used to instruct the time synchronization slave node to correct the system time, and the time synchronization broadcast packet is used to instruct the time synchronization slave node to send a time synchronization request packet.

[0024] In a possible implementation manner of the second aspect, before sending the time synchronization request packet to the time synchronization master node, the method further includes:

[0025] If the time synchronization request packet is the highest-priority packet to be sent in the packet send queue, then send the time synchronization request packet; if there are other packets to be sent in the packet send queue with a priority higher than that of the time synchronization request packet, then send the other packets to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization request packet.

[0026] In a third aspect, the present application provides a time synchronization master node, including:

[0027] A first acquisition unit, configured to acquire a time synchronization request message sent by a time synchronization slave node and a second timestamp when receiving the time synchronization request message; the time synchronization request message includes a first timestamp when the time synchronization slave node sends the time synchronization request message.

[0028] A first sending unit, configured to send a time synchronization reply message to the time synchronization slave node based on the time synchronization request message; the time synchronization reply message includes the first timestamp, the second timestamp, and a third timestamp when sending the time synchronization reply message.

[0029] In a fourth aspect, the present application provides a time synchronization slave node, including:

[0030] A second sending unit, configured to send a time synchronization request message to a time synchronization master node, the time synchronization request message includes a first timestamp when sending the time synchronization request message.

[0031] A second acquisition unit, configured to acquire a time synchronization reply message sent by the time synchronization master node based on the time synchronization request message, the time synchronization reply message includes the first timestamp, a second timestamp when the time synchronization master node receives the time synchronization request message, and a third timestamp when the time synchronization master node sends the time synchronization reply message.

[0032] A calibration unit, configured to calibrate the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when receiving the time synchronization reply message.

[0033] In a fifth aspect, the present application provides a time synchronization device, including a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, the method described in any one of the first aspect or the second aspect is implemented.

[0034] In a sixth aspect, the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the method described in any one of the first aspect or the second aspect is implemented.

[0035] In a seventh aspect, the present application provides a computer program product, when the computer program product runs on a time synchronization device, the time synchronization device is enabled to execute the method described in any one of the first aspect or the second aspect.

[0036] It can be understood that the beneficial effects of the above second aspect to the seventh aspect can refer to the relevant descriptions in the above first aspect, and will not be elaborated here. Description of the Drawings

[0037] To more clearly illustrate the technical solutions in the embodiments of the present application or in the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are only some embodiments of the present application. For those of ordinary skill in the art, without creative efforts, other drawings can be obtained based on these drawings.

[0038] Figure 1 Schematic diagram of the application scenario of the time synchronization method for the embedded system provided by the embodiment of the present application;

[0039] Figure 2 Schematic diagram of the implementation process of the time synchronization method for the embedded system provided by the embodiment of the present application;

[0040] Figure 3 Schematic diagram of the time synchronization process of the time synchronization master node provided by an embodiment of the present application;

[0041] Figure 4 Schematic diagram of the time synchronization process of the time synchronization master node provided by another embodiment of the present application;

[0042] Figure 5 Schematic diagram of the implementation process of the time synchronization method for the embedded system provided by the embodiment of the present application;

[0043] Figure 6 Schematic diagram of the implementation process of the time synchronization of the time synchronization slave node provided by an embodiment of the present application;

[0044] Figure 7 Schematic diagram of the implementation process of the time synchronization of the time synchronization slave node provided by another embodiment of the present application;

[0045] Figure 8 Schematic diagram of the structure of the time synchronization master node of the embedded system provided by the embodiment of the present application;

[0046] Figure 9 Schematic diagram of the structure of the time synchronization slave node of the embedded system provided by the embodiment of the present application;

[0047] Figure 10 Schematic diagram of the structure of the time synchronization device provided by the embodiment of the present application. Detailed implementation manners

[0048] The following will describe in detail the embodiments of the technical solutions of the present application with reference to the accompanying drawings. The following embodiments are only used to more clearly illustrate the technical solutions of the present application, so they are only examples and cannot be used to limit the protection scope of the present application.

[0049] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the technical field to which this application belongs; the terms used herein are for the purpose of describing specific embodiments only and are not intended to limit this application; the terms "including" and "having" and any variations thereof in the description of the specification, claims and drawings of this application are intended to cover non-exclusive inclusion.

[0050] In the description of the embodiments of this application, technical terms such as "first" and "second" are only used to distinguish different objects and cannot be understood as indicating or implying relative importance or implicitly indicating the quantity, specific order or primary-secondary relationship of the indicated technical features. In the description of the embodiments of this application, the meaning of "a plurality" is more than two, unless otherwise specifically defined.

[0051] Referring to "embodiments" herein means that specific features, structures or characteristics described in connection with the embodiments can be included in at least one embodiment of this application. The phrase appearing in various positions in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0052] In the description of the embodiments of this application, the term "and / or" is merely a description of the association relationship of associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. In addition, the character " / " herein generally represents an "or" relationship between the associated objects before and after.

[0053] Currently, secondary control and protection devices in the power system are mostly implemented using embedded systems. For their operation control and system monitoring in the field of power energy storage, internal time needs to be synchronized with the external clock, and the internal time of the system needs to be corrected according to the time synchronization signal sent by the external time service device.

[0054] In the related art, the time synchronization method of an embedded system mostly adopts the Network Time Protocol (NTP) algorithm based on Ethernet communication. However, affected by the complexity of the actual operation scenario in the field of power energy storage, such as a complex system architecture and the use of traditional industrial communication buses for communication between modules, implementing time synchronization within the system based on the Ethernet communication mechanism without considering the limitations of the communication method between embedded systems cannot meet the diverse needs of communication between modules in the current power energy storage field, and its applicability is not strong. Moreover, the NTP algorithm mostly adopts a multi-node architecture. During the broadcast of time synchronization messages by the NTP root node, due to the large number of node levels, when other service messages are transmitted, it will seriously block the normal communication between nodes in severe cases. If the architecture level is divided into many levels, the problem of communication delay between multi-level nodes cannot be avoided, reducing the time synchronization accuracy.

[0055] In view of the above defects, the present application proposes a time synchronization method for an embedded system, which can be applicable to the precise time synchronization based on the Controller Area Network (CAN) network of an energy storage valve control and protection system. This time synchronization method adopts a two-level master-slave node architecture, which only includes a time synchronization master node and a time synchronization slave node, and transmits time synchronization broadcast messages and NTP-related messages through the CAN network. Moreover, in order to avoid affecting other service communications through the CAN network, a priority filtering mechanism is added to achieve reliable time synchronization with high precision, low latency, and strong applicability.

[0056] The following introduces the system architecture of the application scenario applicable to this time synchronization method through embodiments.

[0057] Please refer to Figure 1 , Figure 1 which is a schematic diagram of the application scenario of the time synchronization method for an embedded system provided by an embodiment of the present application. As Figure 1 shown, this embedded system can be an energy storage valve control and protection system (hereinafter referred to as the energy storage valve control and protection system), and this energy storage valve control and protection system includes two levels of time synchronization nodes (i.e., a time synchronization master node and a time synchronization slave node) and a time service device (i.e., a B-code receiving device).

[0058] Among them, there can be one time synchronization master node and multiple time synchronization slave nodes. For example, time synchronization slave node 1 and time synchronization slave node 2. The time synchronization master node is communicatively connected to each time synchronization slave node via the CAN bus; the timing device provides the time synchronization time for the time synchronization master node. The time synchronization signal board of the timing device receives the Inter Range Instrumentation Group-B (IRIG-B) signal sent by an external time source through an antenna receiver. This IRIG-B signal is a high-precision time signal, and the time source can be from a Global Positioning System (GPS) satellite, a Beidou satellite, or other time source devices, which are not specifically defined here.

[0059] Exemplarily, as Figure 1 shown, each time synchronization node includes a Real Time Clock (RTC) module, a system timekeeping module, and a CAN message priority filtering mechanism; the time synchronization master node further includes an NTP server, and the time synchronization slave node further includes an NTP client.

[0060] Among them, the embedded system reads the actual time of the RTC module when it boots up, and sets the system time according to this actual time. The time after booting is managed by the system, that is, all time call objects under the embedded system are the system time.

[0061] Among them, the RTC module is mainly used for saving the time after the system power-off and recording the time change after the system power-off; the CAN message priority filtering mechanism is mainly responsible for filtering the priority of the CAN network messages sent or received by the time synchronization node to ensure the normal communication of other services.

[0062] Exemplarily, the system timekeeping module of the time synchronization master node can periodically read the time synchronization signal of the timing device, such as Figure 1 the Inter Range Instrumentation Group-B (IRIG-B) signal sent by the B-code timing device in. The system timekeeping module is also used to periodically synchronize the system time to the RTC module to ensure the consistency of the time recorded by the RTC and the system time; the system timekeeping module is also used to periodically broadcast a time synchronization broadcast message to the time synchronization slave node via the CAN bus.

[0063] Among them, the time synchronization signal can include the time synchronization time, such as the B-code time in the IRIG-B signal. The above system timekeeping module can compare the obtained time synchronization time with the system time to determine whether there is a drift between the two, so as to determine whether to perform corresponding time synchronization operations.

[0064] Exemplarily, the NTP server of the time synchronization master node is used to receive the time synchronization request message (NTP request message) sent by the time synchronization slave node through the CAN bus, and send the time synchronization reply message (NTP reply message) to the time synchronization slave node through the CAN bus.

[0065] Exemplarily, the system timekeeping module of the time synchronization slave node can actively send a time synchronization request message (NTP request message) to the time synchronization master node during initialization, and can also synchronize the system time to the RTC module of this node periodically during normal operation to prevent the loss of time due to accidental power-off. The NTP client of the time synchronization slave node can send a time synchronization request message (NTP request message) to the time synchronization master node through the CAN bus, and receive the time synchronization reply message (NTP reply message) sent by the time synchronization master node; the NTP client can also calculate the time drift according to the time synchronization reply message sent by the time synchronization master node and correct the system time.

[0066] Based on the above system architecture, the specific implementation process of the time synchronization method is further introduced below.

[0067] Please refer to Figure 2 , Figure 2 which is a schematic diagram of the implementation process of the time synchronization method for the embedded system provided by the embodiment of the present application. The implementation process of the time synchronization method can include two scenarios. One is the process of passive time correction of the time synchronization slave node triggered by the time synchronization master node, and the other is the process of the time synchronization slave node actively initiating time synchronization to the time synchronization master node. As Figure 2 shown, taking the time synchronization master node as the execution subject, the implementation process of the time synchronization method can include the following steps:

[0068] S201, the time synchronization master node obtains the time synchronization request message sent by the time synchronization slave node and the second timestamp when receiving the time synchronization request message.

[0069] In the embodiment of the present application, the time synchronization request message includes the first timestamp when the time synchronization slave node sends the time synchronization request message.

[0070] In one case, the time synchronization master node can receive the time synchronization request message actively sent by the time synchronization slave node, such as an NTP request message, and the time synchronization request message can be sent periodically by the time synchronization slave node.

[0071] In another case, it can also be the time synchronization request message passively sent by the time synchronization slave node triggered after the time synchronization master node sends a time synchronization broadcast message to the time synchronization slave node; the time synchronization master node can send the time synchronization broadcast message to the time synchronization slave node periodically; among them, as Figure 1 shown, the system timekeeping module in the time synchronization master node can send a time synchronization broadcast message to the time synchronization slave node.

[0072] Exemplarily, asFigure 4 As shown in the figure, the NTP server of the time synchronization master node can receive the time synchronization request message sent by the NTP client of the time synchronization slave node, and the message filtering mechanism can receive the time synchronization request message according to the priority of the message receiving queue. For example, if there are no other service messages in the current CAN message receiving queue with a higher priority than the time synchronization request message, the time synchronization request message is received; otherwise, it is further determined whether the timeout mechanism is triggered. After the timeout mechanism is triggered and ends, the time synchronization request message is continuously received and the time stamp corresponding to the moment when the time synchronization request message is received is obtained. Since signal transmission takes time, when the time synchronization master node receives the time synchronization request message, the time stamp corresponding to the moment when the time synchronization request message is received, that is, the second time stamp T2, is obtained together, so as to ensure the time synchronization accuracy during subsequent system time correction.

[0073] In some embodiments, before obtaining the time synchronization request message sent by the time synchronization slave node and the second time stamp when the time synchronization request message is received, the method further includes:

[0074] Obtain the time synchronization signal sent by the time service device, where the time synchronization signal includes the time synchronization time; based on the system time or the time synchronization time in the time synchronization signal, send a time synchronization broadcast message to the time synchronization slave node, and the time synchronization broadcast message is used to instruct the time synchronization slave node to send a time synchronization request message.

[0075] As Figure 3 shown in the figure, the system timekeeping module of the time synchronization master node has two working modes, one is the initialization mode and the other is the general mode of normal operation. In the initialization mode, the system timekeeping module can read the actual time of the RTC module and set the system time with the actual time of the RTC module; then, by obtaining the time synchronization signal (IRIG-B code time synchronization signal) of the time service device (i.e., Figure 1 the B code time service device in the figure), reading the time synchronization time in the time synchronization signal, when the time synchronization signal is obtained for the first time, the time synchronization time is synchronized to the system time and the actual time of the RTC module, and a time synchronization broadcast message containing the time synchronization time is broadcast to the time synchronization slave node through the CAN network.

[0076] As Figure 3 shown in the figure, in the general mode of normal operation of the system timekeeping module of the time synchronization master node, the time synchronization signal of the B code time service device is obtained at a fixed period, that is, when the time synchronization signal is not obtained for the first time, the time synchronization time in the time synchronization signal is compared with the current system time, and the time information included in the time synchronization broadcast message is determined according to the comparison result.

[0077] In some embodiments, after obtaining the time synchronization signal sent by the timing device, the method further includes: if the difference between the system time and the time synchronization time is greater than or equal to a preset time threshold, updating the system time and the actual time to the time synchronization time; if the difference between the system time and the time synchronization time is less than the preset time threshold, updating the actual time to the system time.

[0078] As Figure 3 shown, after the system timekeeping module obtains the time synchronization signal, it compares the time synchronization time in the time synchronization signal with the system time. When the difference between the two is greater than or equal to the preset time threshold, it indicates that there is a large drift in the system time relative to the time synchronization time. Based on the time synchronization time, the system time is adjusted, and the actual time recorded by the RTC module is updated based on the time synchronization time; when the difference between the two is less than the preset time threshold, the actual time of the RTC module can be continuously updated based on the current system time.

[0079] It should be noted that the system timekeeping module of the time synchronization master node can periodically obtain the time synchronization signal, and after comparing it with the system time each time it obtains the time synchronization signal, it synchronizes the system time and the actual time of the RTC module periodically, so that the system time inside the embedded system and the actual time recorded by the RTC module are both consistent with the external time provided by the B-code timing device, improving the timeliness and accuracy of time synchronization.

[0080] In some embodiments, based on the system time or the time synchronization time in the time synchronization signal, sending a time synchronization broadcast message to the time synchronization slave node includes: sending a time synchronization broadcast message containing the time synchronization time or the system time to the time synchronization slave node based on the CAN bus.

[0081] Exemplarily, in order to be applicable to the diversity of communication between various modules in the embedded system in the energy storage field, the embodiment of the present application uses the CAN network bus to implement the communication interaction between two-level time synchronization nodes. As Figure 3 shown, a time synchronization broadcast message is broadcast to the time synchronization slave node through the CAN network. When the difference between the time synchronization time in the time synchronization signal and the system time is greater than or equal to the preset time threshold, the system timekeeping module of the time synchronization master node periodically sends a time synchronization broadcast message containing the time synchronization time to the time synchronization slave node through the CAN network; when the difference between the time synchronization time in the time synchronization signal and the system time is less than the preset time threshold, the system timekeeping module of the time synchronization master node periodically sends a time synchronization broadcast message containing the system time to the time synchronization slave node through the CAN network.

[0082] In some embodiments, before sending a time synchronization broadcast message to a time synchronization slave node based on the system time or the time synchronization time in the time synchronization signal, the method further includes: if the time synchronization broadcast message is the highest-priority message to be sent in the message sending queue, send the time synchronization broadcast message; if there are other messages to be sent in the message sending queue with a priority higher than that of the time synchronization broadcast message, send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization broadcast message.

[0083] As Figure 3 shown, in order to reduce the impact of time synchronization communication between time synchronization nodes on other service communications, when the time synchronization master node sends information to the time synchronization slave node, a message priority filtering mechanism is added, and messages are sent sequentially based on the message sorting in the message sending queue; correspondingly, when a time synchronization broadcast message needs to be sent, if the time synchronization broadcast message is at the top of the message sending queue, immediately send the time synchronization broadcast message. If there are other service messages to be sent before the time synchronization broadcast message, determine whether to trigger a timeout response mechanism; and continue to send after the triggered timeout response mechanism ends.

[0084] Among them, the timeout response mechanism can select an appropriate execution process based on the actual operation scenario. For example, when there are service messages to be sent before the time synchronization broadcast message in the message sending queue, send the previous service messages to be sent sequentially based on the message sending queue, and record the timeout time generated between sending the service message and sending the time synchronization broadcast message through the triggered timeout response mechanism, and then send the time synchronization broadcast message based on the timeout time; or suspend the sending of the time synchronization broadcast message this time, and after processing the events of other service messages, periodically send the time synchronization broadcast message to the time synchronization slave node based on the above process.

[0085] S202. Send a time synchronization reply message to the time synchronization slave node based on the time synchronization request message.

[0086] In the embodiments of the present application, the time synchronization reply message includes a first timestamp, a second timestamp, and a third timestamp when the time synchronization reply message is sent; the time synchronization reply message is used to instruct the time synchronization slave node to correct the system time.

[0087] As Figure 4 shown, after the NTP server of the time synchronization master node receives the time synchronization request message, it parses the time synchronization request message and extracts the timestamp T1 when the time synchronization slave node sends the time synchronization request message. When sending a time synchronization reply message to the time synchronization slave node, obtain the current system time, denoted as the third timestamp T3, encapsulate the first timestamp T1, the second timestamp T2, and the third timestamp T3 into the time synchronization reply message, and send it to the time synchronization slave node.

[0088] It should be noted that the second timestamp and the third timestamp are determined by the time synchronization master node based on the system time synchronized by the B-code time service device. For example, the time synchronization master node periodically obtains the time synchronization time, synchronizes the system time periodically based on the time synchronization time, and periodically sends time synchronization broadcast messages to the time synchronization slave nodes. Furthermore, it can periodically receive time synchronization request messages sent by the time synchronization slave nodes based on the time synchronization broadcast messages, and periodically send time synchronization response messages based on the time synchronization request messages. Additionally, the time synchronization master node periodically obtains the time synchronization time of the time service device, and synchronizes the system time periodically based on the time synchronization time; after receiving the time synchronization request message actively sent by the time synchronization slave node, the time synchronization master node can send a time synchronization response message to the time synchronization slave node based on the synchronized system time.

[0089] As Figure 4 shown, when the NTP server of the time synchronization master node sends a time synchronization response message through the CAN network, based on the CAN message priority filtering mechanism, it determines whether there is a service message with a higher priority in the current CAN message sending queue. If not, it encapsulates the timestamps T1, T2, and T3 into the time synchronization response message and sends it through the CAN network; if there is, it further determines whether the timeout mechanism is triggered. If the timeout mechanism is triggered, after the timeout mechanism processing ends, it records the third timestamp T3 based on the current system time and sends the time synchronization response message.

[0090] Among them, the timeout mechanism is based on the same implementation principle as the above embodiment. The specific processing flow can be determined based on the actual operation scenario, or the sending of this time synchronization response message can be suspended. After other service events corresponding to the timeout mechanism end, the time synchronization response message is sent in the next cycle based on the same implementation principle as above; or based on the timeout mechanism, the timeout time is recorded, and after other service messages with a priority higher than that of the time synchronization response message are sent, a time synchronization response message is sent to the time synchronization slave node based on the recorded timeout time and the current system time (the third timestamp).

[0091] In a possible implementation manner, after the time synchronization master node sends a time synchronization broadcast message to the time synchronization slave node, the time synchronization slave node can directly correct the system time based on the time information in the time synchronization broadcast message.

[0092] In another possible implementation, to improve the accuracy of time synchronization, after the time synchronization master node sends a time synchronization broadcast message to the time synchronization slave node, the time synchronization slave node may, based on the trigger of the time synchronization broadcast message, send a time synchronization request message to the time synchronization master node. After the time synchronization slave node receives the time synchronization reply message sent by the time synchronization master node, it corrects the system time based on the timestamp in the time synchronization reply message. Alternatively, in the absence of a time synchronization broadcast message sent by the time synchronization master node, the time synchronization slave node actively and periodically sends a time synchronization request message to the time synchronization master node to obtain a time synchronization reply message containing a timestamp sent by the time synchronization master node.

[0093] Please refer to Figure 5 , Figure 5 which is a schematic diagram of the implementation process of the time synchronization method for the embedded system provided in the embodiments of the present application. As Figure 5 shown, taking the time synchronization slave node as the execution entity, the implementation process of this time synchronization method may include the following steps:

[0094] S501, send a time synchronization request message to the time synchronization master node, where the time synchronization request message includes a first timestamp when the time synchronization request message is sent.

[0095] In the embodiments of the present application, based on the same implementation principle as the above embodiments, the time synchronization slave node may actively and periodically send a time synchronization request message to the time synchronization master node; it may also send a time synchronization request message based on the time synchronization broadcast message sent by the time synchronization master node.

[0096] As Figure 6 shown, the system timekeeping module of the time synchronization slave node corresponds to two working modes, one is the initialization mode, and the other is the normal mode, that is, the general mode of normal operation. In the initialization mode, the system timekeeping module of the time synchronization slave node reads the actual time in the RTC module and sets the system time with this actual time; in the normal mode, the system time of itself is synchronized to the RTC module at a fixed period to prevent the situation of accidental power-off.

[0097] In some embodiments, before sending the time synchronization request message to the time synchronization master node, the method further includes: if the time synchronization request message is the highest-priority message to be sent in the message sending queue, then send the time synchronization request message; if there are other messages to be sent in the message sending queue with a priority higher than that of the time synchronization request message, then send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization request message.

[0098] Exemplarily, as Figure 6As shown, when the slave node sends a time synchronization request message to the master node for time synchronization, based on the CAN message priority filtering mechanism, it determines whether there is a service message with a higher priority in the current CAN message sending queue. If not, it obtains the timestamp T1 of the current system time at a fixed period, encapsulates it into a time synchronization request message, and sends it through the CAN network. If there is, it further determines whether to trigger the timeout mechanism. After triggering the timeout mechanism, based on the same processing principle as above, according to the actual operation situation, it determines the method and timing for sending the time synchronization request message. For example, it sends the time synchronization request message after the timeout mechanism ends, or suspends the sending of the time synchronization request message in the current period and sends the time synchronization request message in the next period based on the above implementation process.

[0099] In some embodiments, before sending a time synchronization request message to the master node for time synchronization, the method further includes: obtaining the service message sent by the master node for time synchronization; parsing the message type of the service message, where the message type includes a time synchronization reply message or a time synchronization broadcast message; the time synchronization reply message is used to instruct the slave node for time synchronization to correct the system time, and the time synchronization broadcast message is used to instruct the slave node for time synchronization to send a time synchronization request message.

[0100] Exemplarily, the slave node for time synchronization can passively send a time synchronization request message to the master node for time synchronization, that is, a time synchronization request message sent based on receiving the time synchronization broadcast message from the master node for time synchronization. Thus, when receiving the time synchronization message sent by the master node for time synchronization, by parsing the type of the time synchronization message, the subsequent execution process is determined.

[0101] As Figure 7 shown, the NTP client of the slave node for time synchronization can receive the time synchronization message sent by the NTP server of the master node for time synchronization. The time synchronization message can be received based on the filtering mechanism according to the priority. If there is no service message with a higher priority currently, it parses the type of the time synchronization message from the master node for time synchronization; otherwise, it triggers the timeout mechanism and parses the type of the time synchronization message after the timeout mechanism ends.

[0102] S502, obtain the time synchronization reply message sent by the master node for time synchronization based on the time synchronization request message. The time synchronization reply message includes a first timestamp, a second timestamp when the master node for time synchronization receives the time synchronization request message, and a third timestamp when the master node for time synchronization sends the time synchronization reply message.

[0103] In the embodiments of the present application, as Figure 7 shown, if the message type is a time synchronization reply message (NTP reply message), obtain the timestamp T4 at the moment of receiving the time synchronization reply message, and parse the timestamps T1, T2, and T3 in the time synchronization reply message.

[0104] S503, correct the system time based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp when receiving the time synchronization reply message.

[0105] In the embodiments of the present application, the NTP client of the slave node for time synchronization calculates the time drift between the slave node for time synchronization and the master node for time synchronization according to timestamps T1, T2, T3, and T4, corrects the current system time, and synchronizes it to the RTC module.

[0106] In some embodiments, based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp when receiving the time synchronization response message, correcting the system time includes: calculating the time drift of the slave node for time synchronization relative to the master node for time synchronization based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp; and correcting the current system time according to the time drift.

[0107] Exemplarily, the NTP client of the slave node for time synchronization calculates the round-trip delay delay of the NTP message from the NTP client to the NTP server based on the above four timestamps, delay = (T4 - T1) - (T3 - T2), and the time difference (i.e., time drift) between the NTP client and the NTP server.

[0108] Among them, according to the equations:

[0109]

[0110] The time difference offset can be solved as:

[0111]

[0112] Therefore, the NTP client of the slave node for time synchronization adjusts its own system time according to the calculated time drift offset to achieve clock synchronization with the NTP server, and at the same time synchronizes the corrected system time to the RTC module of the slave node for time synchronization to prevent the situation of accidental power-off.

[0113] It should be noted that the slave node for time synchronization that sends the time synchronization request message can be any one of multiple slave nodes for time synchronization that communicate with the master node for time synchronization.

[0114] Through the embodiments of the present application, a two-level master-slave node architecture is adopted to reduce the architecture level, reduce the communication pressure between nodes in extreme cases, reduce the communication delay problem between nodes, and improve the time synchronization accuracy; a general CAN network communication method is adopted, which has strong applicability and can be applied to the time synchronization of embedded systems; a CAN network message priority filtering mechanism is added to avoid affecting other service communications through the CAN network.

[0115] It should be understood that the magnitudes of the sequence numbers of the steps in the above embodiments do not mean the order of execution. The execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.

[0116] Corresponding to the time synchronization method provided in the above embodiment, Figure 8 FIG. shows a schematic structural diagram of a time synchronization master node provided by an embodiment of the present application. For ease of description, only parts related to the embodiment of the present application are shown.

[0117] Referring to Figure 8 , the time synchronization master node includes:

[0118] A first acquisition unit 81, configured to acquire a time synchronization request message sent by a time synchronization slave node and a second timestamp when the time synchronization request message is received; the time synchronization request message includes a first timestamp when the time synchronization slave node sends the time synchronization request message;

[0119] A first sending unit 82, configured to send a time synchronization reply message to the time synchronization slave node based on the time synchronization request message; the time synchronization reply message includes the first timestamp, the second timestamp, and a third timestamp when the time synchronization reply message is sent.

[0120] In a possible implementation manner, the first acquisition unit 81 is further configured to acquire a time synchronization signal sent by a timing device, where the time synchronization signal includes a time synchronization time; based on the system time or the time synchronization time in the time synchronization signal, send a time synchronization broadcast message to the time synchronization slave node, and the time synchronization broadcast message is used to instruct the time synchronization slave node to send a time synchronization request message.

[0121] In a possible implementation manner, the time synchronization master node further includes a time synchronization unit, configured to update the system time and the actual time to the time synchronization time if the difference between the system time and the time synchronization time is greater than or equal to a preset time threshold; and update the actual time to the system time if the difference between the system time and the time synchronization time is less than the preset time threshold.

[0122] In a possible implementation manner, the first sending unit 82 is further configured to send a time synchronization broadcast message including the time synchronization time or the system time to the time synchronization slave node based on the CAN bus.

[0123] In a possible implementation manner, the first sending unit 82 is further configured to send the time synchronization broadcast message if the time synchronization broadcast message is the highest-priority message to be sent in the message sending queue; if there are other messages to be sent in the message sending queue with a priority higher than the time synchronization broadcast message, send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization broadcast message.

[0124] Corresponding to the time synchronization method provided in the above embodiment, Figure 9 FIG. shows a schematic structural diagram of a time synchronization slave node provided by an embodiment of the present application. For ease of description, only parts related to the embodiment of the present application are shown.

[0125] Reference Figure 9 , the slave node for time synchronization includes:

[0126] A second sending unit 91, configured to send a time synchronization request message to the master node for time synchronization, where the time synchronization request message includes a first timestamp when the time synchronization request message is sent;

[0127] A second obtaining unit 92, configured to obtain a time synchronization response message sent by the master node for time synchronization based on the time synchronization request message, where the time synchronization response message includes the first timestamp, a second timestamp when the master node for time synchronization receives the time synchronization request message, and a third timestamp when the master node for time synchronization sends the time synchronization response message;

[0128] A calibration unit 93, configured to calibrate the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when the time synchronization response message is received.

[0129] In a possible implementation manner, the calibration unit 93 is further configured to calculate the time drift of the slave node for time synchronization relative to the master node for time synchronization based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp; and calibrate the current system time according to the time drift.

[0130] In a possible implementation manner, the second obtaining unit 92 is further configured to obtain a service message sent by the master node for time synchronization; analyze the message type of the service message, where the message type includes a time synchronization response message or a time synchronization broadcast message; the time synchronization response message is used to instruct the slave node for time synchronization to calibrate the system time, and the time synchronization broadcast message is used to instruct the slave node for time synchronization to send a time synchronization request message.

[0131] In a possible implementation manner, the second sending unit 91 is further configured to, if the time synchronization request message is the highest-priority message to be sent in the message sending queue, send the time synchronization request message; if there are other messages to be sent in the message sending queue with a priority higher than that of the time synchronization request message, send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to pause the sending of the time synchronization request message.

[0132] Through the embodiments of the present application, a two-level master-slave node architecture is adopted, reducing the architecture level, reducing the communication pressure between nodes in extreme cases, reducing the communication delay problem between nodes, and improving the time synchronization accuracy; a general CAN network communication method is adopted, with strong applicability and can be applied to the time synchronization of embedded systems; a CAN network message priority filtering mechanism is added to avoid affecting other service communications through the CAN network.

[0133] Figure 10 Shows a schematic hardware structure diagram of the time synchronization device 10.

[0134] AsFigure 10 As shown, the time synchronization device 10 of this embodiment includes: at least one processor 100 ( Figure 10 only one is shown in the figure), a memory 101, and a computer program 102 that can run on the processor 100 is stored in the memory 101. When the processor 100 executes the computer program 102, the steps in the above method embodiment are implemented, for example Figure 2 S201 to S202 as shown, or as Figure 5 S501 to S503 as shown. Alternatively, when the processor 100 executes the computer program 102, the functions of each module / unit in the above device embodiments are implemented.

[0135] It can be understood that the structure schematically shown in the embodiments of the present application does not constitute a specific limitation on the time synchronization device 10. In other embodiments of the present application, the time synchronization device 10 may include more or fewer components than shown in the figure, or combine certain components, or split certain components, or have different component arrangements. The components shown in the figure can be implemented in hardware, software, or a combination of software and hardware.

[0136] The time synchronization device 10 may be a camera device. The time synchronization device 10 may include, but is not limited to, a processor 100 and a memory 101. Those skilled in the art can understand that Figure 10 this is only an example of the time synchronization device 10 and does not constitute a limitation on the time synchronization device 10. It may include more or fewer components than shown in the figure, or combine certain components, or have different components. For example, the server may further include an input and sending device, a network access device, a bus, etc.

[0137] The above-mentioned processor 100 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor or the processor may also be any conventional processor, etc.

[0138] A memory may also be provided in the processor 100 for storing instructions and data. In some embodiments, the memory in the processor 100 is a cache memory. This memory can store the instructions or data that the processor 100 has just used or recycled. If the processor 100 needs to use the instruction or data again, it can be directly called from the said memory. This avoids repeated accesses, reduces the waiting time of the processor 100, and thus improves the efficiency of the system.

[0139] In some embodiments, the above-mentioned memory 101 may be an internal storage unit of the time synchronization device 10, such as the hard disk or memory of the time synchronization device 10. The memory 101 may also be an external storage device of the time synchronization device 10, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) card, a Flash Card, etc. equipped on the time synchronization device 10. Further, the memory 101 may also include both the internal storage unit and the external storage device of the time synchronization device 10. The memory 101 is used to store an operating system, application programs, a BootLoader, data, and other programs, such as the program code of a computer program. The memory 101 may also be used to temporarily store data that has been sent or will be sent.

[0140] In addition, in each embodiment of the present application, each functional unit may be integrated in a processing unit, or each unit may exist physically alone, or two or more units may be integrated in one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of a software functional unit.

[0141] It should be noted that the above structure of the time synchronization device is only an exemplary illustration. Based on different application scenarios, it may also include other entity structures, and the entity structure of the time synchronization device is not limited herein.

[0142] In the above embodiments, the descriptions of the respective embodiments have their own emphases. For parts not detailed or recorded in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0143] The embodiments of the present application also provide a valve control system, including a timing device and the above-mentioned time synchronization device, and the timing device is used to provide a time synchronization time for the time synchronization device. The valve control system may be an energy storage valve control and protection system.

[0144] The embodiments of the present application also provide a computer-readable storage medium, which stores a computer program, and when the computer program is executed by a processor, the steps in the above-mentioned various method embodiments can be implemented.

[0145] An embodiment of the present application provides a computer program product. When the computer program product runs on a server, it enables the server to execute the steps in the above-mentioned method embodiments when executed.

[0146] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above-mentioned method embodiments of the present application can also be completed by instructing relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording medium, USB flash drive, mobile hard disk, magnetic disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal, and software distribution medium, etc.

[0147] The time synchronization master node, time synchronization slave node, time synchronization device, valve control system, computer storage medium, and computer program product provided in the above embodiments of the present application are all used to execute the methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects corresponding to the methods provided above, and will not be elaborated here.

[0148] It should be understood that the above is only to help those skilled in the art better understand the embodiments of the present application, rather than to limit the scope of the embodiments of the present application. Those skilled in the art can obviously make various equivalent modifications or changes according to the above examples. For example, some steps in the above embodiments of the detection method may not be necessary, or some steps may be newly added, etc. Or any combination of any two or any more of the above embodiments. The solutions after such modifications, changes or combinations also fall within the scope of the embodiments of the present application.

[0149] The unit described as a separated component may or may not be physically separated, and the component shown as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0150] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions recorded in the foregoing embodiments, or perform equivalent replacements for some of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

[0151] Finally, it should be noted that the above is only the specific implementation manner of the present application, but the protection scope of the present application is not limited thereto. Any changes or replacements within the technical scope disclosed in the present application should be covered by the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims described.

Claims

1. A time synchronization method for an embedded system, characterized in that Applied to the time synchronization master node, the method includes: Obtain a time synchronization request message sent by a time synchronization slave node and a second timestamp when receiving the time synchronization request message; the time synchronization request message includes a first timestamp when the time synchronization slave node sends the time synchronization request message; Send a time synchronization response message to the time synchronization slave node based on the time synchronization request message; the time synchronization response message includes the first timestamp, the second timestamp, and a third timestamp when sending the time synchronization response message.

2. The method according to claim 1, wherein Before obtaining the time synchronization request message sent by the time synchronization slave node and the second timestamp when receiving the time synchronization request message, the method further includes: Obtain a time synchronization signal sent by a time synchronization device, the time synchronization signal including a time synchronization time; Based on the system time or the time synchronization time in the time synchronization signal, send a time synchronization broadcast message to the time synchronization slave node, the time synchronization broadcast message being used to instruct the time synchronization slave node to send a time synchronization request message.

3. The method according to claim 2, wherein After obtaining the time synchronization signal sent by the time synchronization device, the method further includes: If the difference between the system time and the time synchronization time is greater than or equal to a preset time threshold, update the system time and the actual time to the time synchronization time; If the difference between the system time and the time synchronization time is less than the preset time threshold, update the actual time to the system time.

4. The method according to claim 2, wherein The sending a time synchronization broadcast message to the time synchronization slave node based on the system time or the time synchronization time in the time synchronization signal includes: Based on the CAN bus, send a time synchronization broadcast message including the time synchronization time or the system time to the time synchronization slave node.

5. The method according to any one of claims 2 to 4, characterized in that Before sending a time synchronization broadcast message to the time synchronization slave node based on the system time or the time synchronization time in the time synchronization signal, the method further includes: If the time synchronization broadcast message is the highest-priority message to be sent in the message sending queue, send the time synchronization broadcast message; If there are other messages to be sent in the message sending queue with a priority higher than that of the time synchronization broadcast message, send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization broadcast message.

6. A time synchronization method for an embedded system, characterized in that, Applied to the time synchronization slave node, the method includes: Send a time synchronization request message to the time synchronization master node, the time synchronization request message including a first timestamp when sending the time synchronization request message; Obtain a time synchronization response message sent by the time synchronization master node based on the time synchronization request message, the time synchronization response message including the first timestamp, a second timestamp when the time synchronization master node receives the time synchronization request message, and a third timestamp when the time synchronization master node sends the time synchronization response message; Correct the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when receiving the time synchronization response message.

7. The method according to claim 6, wherein The correcting the system time based on the first timestamp, the second timestamp, the third timestamp, and a fourth timestamp when receiving the time synchronization response message includes: Calculate the time drift of the time synchronization slave node relative to the time synchronization master node based on the first timestamp, the second timestamp, the third timestamp, and the fourth timestamp; Correct the current system time according to the time drift.

8. The method according to claim 6, wherein Before sending the time synchronization request message to the time synchronization master node, the method further includes: Obtain the service message sent by the time synchronization master node; Analyze the message type of the service message, where the message type includes a time synchronization reply message or a time synchronization broadcast message; the time synchronization reply message is used to instruct the time synchronization slave node to correct the system time, and the time synchronization broadcast message is used to instruct the time synchronization slave node to send the time synchronization request message.

9. The method according to any one of claims 6 to 8, characterized in that, Before sending the time synchronization request message to the time synchronization master node, the method further includes: If the time synchronization request message is the highest-priority message to be sent in the message sending queue, then send the time synchronization request message; If there are other messages to be sent in the message sending queue with a priority higher than the time synchronization request message, then send the other messages to be sent and start a timeout mechanism; the timeout mechanism is used to suspend the sending of the time synchronization request message.

10. A time synchronization device, characterized in that, It includes a memory and a processor, the memory stores a computer program, and when the processor executes the computer program, it implements the method according to any one of claims 1 to 5 or 6 to 9.

11. A valve control system, characterized in that, It includes a timing device and the time synchronization device according to claim 10, and the timing device is used to provide the time synchronization time for the time synchronization device.

12. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the method according to any one of claims 1 to 5 or 6 to 9.