Master-slave synchronization method based on Ethernet UDP (User Datagram Protocol) communication
By adopting the master-slave synchronization method based on Ethernet UDP communication in the field of rail transit, the problems of low data transmission rate, narrow broadband and insufficient anti-interference capabilities in the prior art are solved, and more efficient data exchange and stronger Anti-interference capability expands the application field of interlocking systems.
Patent Information
- Application Number
- CN202411648738.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-18
- Publication Date
- 2025-02-18
AI Technical Summary
The existing CAN and RS-485 communications have problems in the field of rail transit, such as low data transmission rate, narrow broadband, limited data volume and susceptible to interference in high electromagnetic interference environments. At the same time, the interlocking software relies on hardware devices, and the impact can be replicated. Usability.
The master-slave synchronization method based on Ethernet UDP communication is adopted to move the exchange of master-slave synchronization information from the hardware layer to the software layer, and the synchronization is achieved by establishing communication nodes, using UDP protocol, and using SLAVE blocking and MASTER timeout waiting mechanisms. run.
It improves data transmission rate and broadband, enhances anti-interference ability, get rid of the dependence of interlocking software on hardware devices, expands the application field of interlocking systems, and improves the reusability of the system.
Smart Images

Figure CN119484553A_ABST
Abstract
Description
Technical Field
[0001] The invention relates to the field of communication technology, and in particular to a master-slave synchronization method based on Ethernet UDP communication. Background Art
[0002] In the field of rail transit, the most commonly used is the two-by-two-out-of-two platform with two-system parallel control. The two-by-two-out-of-two platform consists of two systems, System I and System II. Each system has two computing units, forming a two-out-of-two unit. At present, the operation synchronization of the two computing units in each system is mainly achieved through hardware, that is, a shared memory area is implemented on the hardware, so that both computing units can access the area, thereby realizing data interaction and ultimately achieving the purpose of synchronous operation.
[0003] Some master-slave synchronous data transmission using CAN and RS-485 has a low rate, narrow bandwidth, limited amount of data that can be processed, and in some high electromagnetic interference environments, communication will be disturbed.
[0004] If there is a method that can not only solve the problems of CAN and RS-485 in data transmission, but also free the interlocking software from dependence on hardware devices, it will greatly expand the application field of the interlocking system.
[0005] When the hardware used to implement the shared area changes, the computer interlocking software needs to be modified to adapt to the changes in the hardware, which will greatly affect the reusability of the computer interlocking software. In addition, based on the complexity of the environment in which the computer interlocking system is used, the anti-interference ability of the system also needs to be guaranteed. Summary of the invention
[0006] To solve the above technical problems, the present invention provides a master-slave synchronization method based on Ethernet UDP communication, which moves the exchange of master-slave synchronization information from the hardware layer to the software layer, while ensuring that the method is less affected by external environment interference.
[0007] The present invention adopts the following technical scheme, a master-slave synchronization method based on Ethernet UDP communication, including the steps of establishing communication:
[0008] First, a communication node is established according to the master-slave attribute of the CPU board. The master system is MASTER and the backup system is SLAVE. The master and slave boards exchange data through their respective communication nodes.
[0009] When the connection establishment begins, the MASTER sends a communication establishment request to notify the SLAVE. The SLAVE blocks and waits to receive the communication establishment request. After receiving the communication establishment request, it sends a reply to the MATER. After receiving the reply, the MATER notifies the SLAVE that the communication is successfully established. The MATER establishes communication successfully; after receiving the notification, the SLAVE establishes communication successfully.
[0010] Preferably, at the beginning of communication establishment, SLAVE waits for the connection establishment request sent by MASTER, MASTER sends the group name and its own information using UDP, and waits to receive the reply information from SLAVE. If no reply is received from SLAVE for N seconds, it times out and fails. After SLAVE receives the request, it parses the content. If the group name is the same as its own, it determines that the source of the request is its own master, saves the source information, and replies to MASTER with the request information received. After MASTER receives the reply request information from SLAVE, it stops sending requests and sends a reply to SLAVE indicating that the connection is successfully established. MASTER is successfully connected. After SLAVE receives the reply to the connection success, it also successfully establishes the connection.
[0011] Preferably, N=10.
[0012] Preferably, the message middleware implements the barrier synchronization function. The barrier synchronization adopts a three-way handshake. The MASTER first sends a synchronization start notification. The SLAVE receives the notification and sends a synchronization reply. The MASTER receives the reply and sends a synchronization success reply. The MASTER completes the synchronization. The SLAVE completes the synchronization after receiving the synchronization success reply.
[0013] Preferably, the communication network adopts non-blocking mode and reduces the priority of SLAVE, SLAVE is in blocking mode, and MASTER is in timeout waiting mode; when synchronization starts, SLAVE waits for the master's synchronization start notification message, and MASTER clears all messages in the receiving buffer area to avoid the redundant messages left over from the previous cycle blocking the synchronization process; after the buffer area is cleared, a synchronization start notification message is sent to SLAVE, and a reply from SLAVE is received. If the reception fails, the synchronization start notification continues to be sent until more than M seconds; after SLAVE receives the synchronization start notification sent by MASTER, it sends a synchronization start reply to MASTER, and then waits to receive the synchronization success notification from MASTER. During the reception period, the synchronization start reply is continuously sent until more than M seconds, and then it returns to the blocked waiting synchronization start state before the synchronization starts; if MASTER successfully receives the synchronization start reply sent by SLAVE, it sends 3 packets of synchronization success reply to SLAVE, and the synchronization is successful; after SLAVE receives the synchronization success, it clears its own receiving buffer area, and the synchronization is successful.
[0014] Preferably, M=10.
[0015] Preferably, the working process of MASTER is as follows:
[0016] Clear the receive buffer;
[0017] Send a synchronization start notification message to SLAVE;
[0018] If successful, wait for receiving sync start reply;
[0019] If the reception is successful, determine whether the message is a synchronization start reply message. If so, send a synchronization success reply to the SLAVE, and the synchronization is successful. If not, continue to send a synchronization start notification message to the SLAVE;
[0020] If the reception fails, determine whether it has timed out. If so, return synchronization failure. If not, continue to send synchronization start notification messages.
[0021] Preferably, the SLAVE working process is as follows:
[0022] Waiting to receive synchronization start notification;
[0023] If the reception is successful, determine whether the message is a synchronization start notification message. If so, send a synchronization start reply message to the MASTER; if not, wait for receiving the synchronization start notification;
[0024] If the synchronization start reply message is sent to the MASTER successfully, wait for the synchronization success reply to be received;
[0025] If the reception is successful, determine whether the message is a synchronization success reply message. If so, clear the receiving buffer and the synchronization is successful. If the reception fails, determine whether it has timed out. If so, continue to wait for receiving the synchronization start notification. If not, continue to send the synchronization start reply message to the MASTER.
[0026] A computer-readable storage medium stores a computer program, and the computer program implements the above method when executed by a computer or a processor.
[0027] The present invention adopts UDP based on Ethernet for master-slave communication, which solves the problems of high electromagnetic interference, low transmission rate and narrow bandwidth compared with CAN and RS-485 communication; the master-slave data exchange is realized by system software, which gets rid of the dependence of interlocking software on hardware. By setting the mechanism of slave system blocking and master system timeout waiting, the master-slave synchronous operation is realized. BRIEF DESCRIPTION OF THE DRAWINGS
[0028] Figure 1 This is a diagram of the hunt three-way handshake;
[0029] Figure 2 It is the hunt flow chart;
[0030] Figure 3 This is the ipc_barrier three-way handshake diagram;
[0031] Figure 4It is the master-slave ipc_barrier flow chart;
[0032] Figure 5 It is a schematic diagram of fence synchronization timing;
[0033] Figure 6 It is a dependency diagram of the platform software modules of the present invention. DETAILED DESCRIPTION
[0034] like Figure 1-6 As shown, the present invention discloses a master-slave synchronization method based on Ethernet UDP communication.
[0035] 1. Communication establishment
[0036] In this process, a communication node is first established according to the master-slave attributes of the CPU board. The main system is MASTER and the backup system is SLAVE. The master and slave boards exchange data through their respective communication nodes.
[0037] When the connection is established, the MASTER sends a communication establishment request to notify the SLAVE. The SLAVE will block and wait for the communication establishment request. After receiving the communication establishment request, it sends a reply to the MATER. After receiving the reply, the MATER notifies the SLAVE that the communication is successfully established. The MATER establishes the communication successfully and ends. After the SLAVE receives the notification, the communication is successfully established and ends. The schematic diagram is as follows Figure 1 .
[0038] like Figure 2 As shown, communication establishment begins, SLAVE will wait for the connection establishment request sent by MASTER, MASTER will send the group name and its own information using UDP, and wait to receive the reply information from SLAVE. If NS does not receive the reply from SLAVE, it will time out and fail. After receiving the request, SLAVE parses the content. If the group name is the same as its own, it will determine that the source of the request is its own master, save the source information, and reply to MASTER with the request information received. After receiving the reply request information from SLAVE, MASTER stops sending requests and sends a reply to SLAVE that the connection is successfully established. MASTER successfully establishes the connection and the hunt is successful. After receiving the reply that the connection is successful, SLAVE also successfully establishes the connection and the hunt is successful.
[0039] N is a number of seconds, for example 3 seconds, 5 seconds, 8 seconds, 9 seconds, 12 seconds, 15 seconds, etc., preferably 10 seconds. If no reply is received from SLAVE for 10 seconds, the process times out and fails.
[0040] 2. Fence synchronization
[0041] To ensure the master-slave cycle is consistent, the message middleware implements the fence synchronization function. This fence synchronization adopts the SLAVE blocking and MASTER timeout waiting mechanism to avoid the MASTER falling into a blocked state when the SLAVE device fails. The fence synchronization adopts a three-way handshake, as shown in the schematic diagram Figure 3 :
[0042] In the above three-way handshake, the MASTER first sends a synchronization start notification, the SLAVE receives the notification and sends a synchronization reply, the MASTER receives the reply and sends a synchronization success reply, the MASTER completes the synchronization, and the SLAVE completes the synchronization after receiving the synchronization success reply.
[0043] Detailed process as Figure 4 :
[0044] In order to realize the timeout synchronization function, the communication network adopts non-blocking mode and reduces the priority of SLAVE. SLAVE is in blocking mode and MASTER is in timeout waiting mode. At the beginning of synchronization, SLAVE waits for the synchronization start notification message from the master, and MASTER clears all messages in the receiving buffer to avoid the redundant messages left over from the previous cycle blocking the synchronization process. After the buffer is cleared, a synchronization start notification message is sent to SLAVE and a reply from SLAVE is received. If the reception fails, the synchronization start notification continues to be sent until more than M seconds. After SLAVE receives the synchronization start notification sent by MASTER, it sends a synchronization start reply to MASTER and waits to receive the synchronization success notification from MASTER. During the reception period, the synchronization start reply is continuously sent until more than M seconds, and then it returns to the blocking waiting synchronization start state before the synchronization starts. If MASTER successfully receives the synchronization start reply sent by SLAVE, it sends 3 packets of synchronization success reply to SLAVE, and the synchronization is successful and the synchronization ends. After SLAVE receives the synchronization success, it clears its own receiving buffer, and the synchronization is successful and the synchronization ends.
[0045] M is several seconds, such as 3 seconds, 5 seconds, 8 seconds, 9 seconds, 12 seconds, 15 seconds, etc., preferably 10 seconds. If it lasts for 10 seconds, it returns to the blocked waiting synchronization start state before the synchronization start.
[0046] Ipc master barrier process:
[0047] Clear the receive buffer;
[0048] Send a synchronization start notification message to SLAVE;
[0049] If successful, wait for receiving sync start reply;
[0050] If the message is received successfully, determine whether it is a synchronization start reply message. If so, send a synchronization success reply to the SLAVE, indicating that the synchronization is successful and the synchronization is completed; if not, continue to send a synchronization start notification message to the SLAVE;
[0051] If the reception fails, determine whether it has timed out. If so, return synchronization failure. If not, continue to send synchronization start notification messages.
[0052] Ipc slave barrier process:
[0053] Waiting to receive synchronization start notification;
[0054] If the reception is successful, determine whether the message is a synchronization start notification message. If so, send a synchronization start reply message to the MASTER; if not, wait for receiving the synchronization start notification;
[0055] If the synchronization start reply message is sent to the MASTER successfully, wait for the synchronization success reply to be received;
[0056] If the reception is successful, determine whether the message is a synchronization success reply message. If so, clear the receiving buffer area, the synchronization is successful, and the synchronization ends. If the reception fails, determine whether it has timed out. If so, continue to wait for receiving the synchronization start notification. If not, continue to send the synchronization start reply message to the MASTER.
[0057] Synchronous timing diagram Figure 5 .
[0058] The platform software module dependency diagram of the present invention is as follows: Figure 6 .
[0059] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A master-slave synchronization method based on Ethernet UDP communication, characterized in that: The steps to establish communication include: According to the master-slave attribute of the CPU board, a communication node is established respectively. The master system is MASTER and the standby system is SLAVE. The master and slave boards exchange data through their respective communication nodes. MASTER sends a communication establishment request to notify SLAVE; SLAVE blocks and waits for a communication establishment request. After receiving the communication establishment request, it sends a reply to MATER. After receiving the reply, MATER notifies SLAVE that the communication is successfully established. MATER successfully establishes communication; After receiving the notification, SLAVE establishes communication successfully.
2. The master-slave synchronization method based on Ethernet UDP communication according to claim 1, characterized in that: The steps of establishing communication specifically include: SLAVE waits for the connection establishment request sent by MASTER; MASTER sends the group name and its own information using UDP, and waits for the reply from SLAVE. If it fails to receive the reply from SLAVE within N seconds, it times out and fails. After receiving the request, SLAVE parses the content. If the group name is the same as its own, it determines that the source of the request is its own master information, saves the source information, and replies to MASTER that it has received the request information. After receiving the reply request information from SLAVE, MASTER stops sending requests and sends a reply to SLAVE indicating that the connection is successfully established. MASTER successfully establishes the connection. After receiving the successful connection reply, SLAVE also successfully established the connection.
3. The master-slave synchronization method based on Ethernet UDP communication according to claim 2, characterized in that: Said N=10.
4. The master-slave synchronization method based on Ethernet UDP communication according to claim 1 or 2, characterized in that: It also includes the fence synchronization step, which uses a three-way handshake: MASTER sends synchronization start notification; SLAVE receives the notification and sends a synchronous reply; After receiving the reply, the MASTER sends a synchronization success reply. The MASTER completes the synchronization. After receiving the synchronization success reply, the SLAVE completes the synchronization.
5. The master-slave synchronization method based on Ethernet UDP communication according to claim 4, characterized in that: The fence synchronization steps include: Synchronization starts, SLAVE waits for the master's synchronization start notification message, and MASTER clears all messages in the receive buffer; After the buffer is cleared, a synchronization start notification message is sent to the SLAVE and a reply is received from the SLAVE. If the reply fails, the synchronization start notification message continues to be sent until M seconds have passed. After receiving the synchronization start notification sent by the MASTER, the SLAVE sends a synchronization start reply to the MASTER, and then waits to receive the synchronization success notification from the MASTER. During the reception period, the SLAVE continues to send synchronization start replies until M seconds have passed, and then returns to the blocked waiting synchronization start state before the synchronization starts. If the MASTER successfully receives the synchronization start reply sent by the SLAVE, it will send 3 packets of synchronization success reply to the SLAVE, and the synchronization is successful; After SLAVE receives the synchronization success, it clears its own receive buffer and the synchronization is successful.
6. The master-slave synchronization method based on Ethernet UDP communication according to claim 5, characterized in that: The M=10.
7. The master-slave synchronization method based on Ethernet UDP communication according to claim 5, characterized in that: The working process of MASTER is as follows: Clear the receive buffer; Send a synchronization start notification message to SLAVE; If successful, wait for receiving sync start reply; If the reception is successful, determine whether the message is a synchronization start reply message. If so, send a synchronization success reply to the SLAVE, indicating that the synchronization is successful. If not, continue to send a synchronization start notification message to the SLAVE; If the reception fails, determine whether it has timed out. If so, return synchronization failure. If not, continue to send synchronization start notification messages.
8. The master-slave synchronization method based on Ethernet UDP communication according to claim 5, characterized in that: The SLAVE working process is as follows: Waiting to receive synchronization start notification; If the reception is successful, determine whether the message is a synchronization start notification message. If so, send a synchronization start reply message to the MASTER; if not, wait for receiving the synchronization start notification; If the synchronization start reply message is sent to the MASTER successfully, wait for the synchronization success reply to be received; If the reception is successful, determine whether the message is a synchronization success reply message. If so, clear the receiving buffer and the synchronization is successful; If the reception fails, determine whether it has timed out. If so, continue to wait for receiving the synchronization start notification. If not, continue to send the synchronization start reply message to the MASTER.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a computer or a processor, the method according to any one of claims 1 to 8 is implemented.