Disclosure of Invention
The present invention is directed to at least one of the technical problems in the prior art, and provides a time synchronization method and apparatus.
The technical scheme adopted for solving the technical problem of the invention is a time synchronization method, which comprises the following steps:
receiving cross broadcast message packets sent by each source node, and recording the time of receiving the cross broadcast message packets; wherein the cross-broadcast packet comprises: generating time of cross broadcast message packet;
calculating timing time difference between the self node and each source node according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time of receiving the cross broadcast message packet, the sending time delay of the source node and the receiving time delay of the self node;
calculating the current timing time of each source node according to the current timing time of the node and the calculated timing time difference between the node and each source node;
calculating the current timing time of each source node according to the current timing time of the node per se to obtain synchronous time;
and generating the cross broadcast information packet according to the calculated synchronous time so as to transmit the cross broadcast information packet.
Preferably, the step of receiving the cross broadcast message packet sent by each source node and recording the time of receiving the cross broadcast message packet includes:
receiving cross broadcast information packets of each source node;
and judging whether the cross broadcast information packet is received for the first time according to the received data information of the cross broadcast information packet, and recording the time of receiving the cross broadcast information if the cross broadcast information packet is received for the first time.
Preferably, the step of calculating the timing time difference between the self node and each source node according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time of receiving the cross broadcast message packet, the sending delay of the source node and the receiving delay of the self node includes:
according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time included in the received cross broadcast information, the sending time delay of the source node and the receiving time delay of the self node, adopting a formula:
tbn=(Tn+α+β)-Tbncalculating the current timing time of each source node;
wherein, tbnRepresenting the timing time difference between the self node and the nth source node; t isnIndicating the generation time of the cross broadcast message packet sent by the nth source node; a represents the transmission delay of the nth source node; beta represents the receiving time delay of the node; t isbnThe time recorded by the self node and received by the nth sending node, wherein n is an integer greater than or equal to 1.
Preferably, the step of calculating the current timing time of each source node according to the current timing time of the own node and the calculated timing time difference between the own node and each source node includes:
according to the current timing time of the self node and the calculated timing time difference between the self node and each source node, adopting a formula:
Tn′=Tb+tbncalculating the current timing time of each source node;
wherein, Tn' represents a current timing time of the nth source node; t isbRepresenting the current timing time of the node; t is tbnRepresenting the timing time difference between the self node and the nth source node.
Preferably, the step of calculating the synchronization time according to the current timing time of each source node calculated according to the current timing time of the own node includes:
calculating the current timing time of each source node according to the current timing time of the node, and adopting a formula:
wherein, Tb' denotes a synchronization time; t isn' represents a current timing time of the nth source node; t isbAnd k is the number of the source nodes.
The technical scheme adopted for solving the technical problem of the invention is a time synchronization device, which comprises:
the receiving module is used for receiving the cross broadcast message packets sent by each source node and recording the time of receiving the cross broadcast message packets; wherein the cross-broadcast packet comprises: generating time of cross broadcast message packet;
the first calculation module is used for calculating the timing time difference between the self node and each source node according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time for receiving the cross broadcast message packet, the sending time delay of the source node and the receiving time delay of the self node;
the second calculation module is used for calculating the current timing time of each source node according to the current timing time of the node and the calculated timing time difference between the node and each source node;
the third calculation module is used for calculating the current timing time of each source node according to the current timing time of the node per se to obtain the synchronization time;
and the sending module is used for generating the cross broadcast information packet according to the calculated synchronous time so as to transmit the cross broadcast information packet.
Preferably, the receiving module is specifically configured to receive cross broadcast packets of each source node; and judging whether the cross broadcast information packet is received for the first time according to the received data information of the cross broadcast information packet, and recording the time of receiving the cross broadcast information if the cross broadcast information packet is received for the first time.
Preferably, the first calculating module is specifically configured to adopt a formula according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time included in the received cross broadcast information, and the sending delay of the source node and the receiving delay of the self node:
tbn=(Tn+α+β)-Tbncalculating the current timing time of each source node;
wherein, tbnRepresenting the timing time difference between the self node and the nth source node; t isnIndicating the generation time of the cross broadcast message packet sent by the nth source node; a represents the transmission delay of the nth source node; beta represents the receiving time delay of the node; t isbnThe time recorded by the self node and received by the nth sending node, wherein n is an integer greater than or equal to 1.
Preferably, the second calculating module is specifically configured to adopt a formula according to the current timing time of the self node and the calculated timing time difference between the self node and each source node:
Tn′=Tb+tbncalculating the current timing time of each source node;
wherein, Tn' represents a current timing time of the nth source node; t isbRepresenting the current timing time of the node; t is tbnRepresenting the timing time difference between the self node and the nth source node.
Preferably, the third calculating module is specifically configured to calculate the current timing time of each source node according to the current timing time of the own node, and adopt a formula:
wherein, Tb' denotes a synchronization time; t isn' represents a current timing time of the nth source node; t isbAnd k is the number of the source nodes.
The invention has the following beneficial effects:
the node time synchronization method does not need to refer to the step-by-step synchronization between the nodes, eliminates the time error, and does not influence the overall performance of the network when the individual node dies.
Detailed Description
In order to make the technical solutions of the present invention better understood, the present invention will be described in further detail with reference to the accompanying drawings and specific embodiments.
Example 1:
as shown in fig. 1, the present embodiment provides a time synchronization method, wherein an execution subject in the present embodiment is a receiving node, and a source node, that is, a sending node, and provides a method for performing time synchronization by the receiving node. The time synchronization method in the embodiment specifically includes the following steps:
s1, receiving the cross broadcast message packet sent by each source node, and recording the time of receiving the cross broadcast message packet; wherein the cross-broadcast packet comprises: the generation time of the cross-broadcast message packet.
Specifically, firstly, each source node generates a cross broadcast message packet, wherein the cross broadcast message packet comprises the time for generating the cross broadcast message packet by the source node; then, each source node sends the generated cross broadcast message packet to a receiving node; and finally, recording the time of receiving the cross broadcast message packet transmitted by each source node by the receiving node.
When the receiving node records the time of receiving the cross broadcast message packet sent by each source node, the receiving node firstly judges whether the cross broadcast message packet is received for the first time, if so, the time of receiving the cross broadcast message is recorded, and if not, the cross broadcast message packet is discarded, and the time of receiving the cross broadcast message is not recorded.
S2, calculating the timing time difference between the self node and each source node according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time of receiving the cross broadcast message packet, the sending time delay of the source node and the receiving time delay of the self node.
Specifically, in this step, according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time included in the received cross broadcast information, the sending delay of the source node, and the receiving delay of the self node, a formula is adopted: t is tbn=(Tn+α+β)-TbnAnd calculating the current timing time of each source node.
Wherein, tbnRepresenting the timing time difference between the self node and the nth source node; t isnIndicating the generation time of the cross broadcast message packet sent by the nth source node; a represents the transmission delay of the nth source node; beta represents the receiving time delay of the node; t isbnThe time recorded by the self node and received by the nth sending node, wherein n is an integer greater than or equal to 1.
In order to make the implementation of step S2 more clear, the following two source nodes are referred to as node a and node C, respectively; the transmitting node is represented by a node B as an example, and step S2 will be described.
The timing of generating the broadcast data packet of the node A and the node C is T respectivelyaAnd TcThe node B records the receiving timing T when receiving the broadcast message packet of the node AbaRecording a reception timing T when receiving a broadcast message packet of a node CbcThe delay alpha of the data packet at the sending end and the delay beta of the receiving end; the timing time difference between the node B and the nodes A and C is respectively as follows:
tba=(Ta+α+β)-Tba;
tbc=(Tc+α+β)-Tbc。
and S3, calculating the current timing time of each source node according to the current timing time of the self node and the calculated timing time difference between the self node and each source node.
Specifically, in this step, the current time of the self node and the calculated counts of the self node and the respective source nodes are used as the basisTime difference, using the formula: t isn′=Tb+tbnAnd calculating the current timing time of each source node.
Wherein, Tn' represents a current timing time of the nth source node; t isbRepresenting the current timing time of the node; t is tbnRepresenting the timing time difference between the self node and the nth source node.
In order to make the implementation of step S2 more clear, the following two source nodes are referred to as node a and node C, respectively; the transmitting node is represented by the node B as an example, and the description is made based on step S2.
The current timing time of the node a may be specifically represented by a formula: t isa'=Tb+tbaCalculating to obtain; the current timing time of the node C may be specifically represented by the formula: t isc'=Tb+tbcAnd (4) calculating.
And S4, calculating the current timing time of each source node according to the current timing time of the node per se to obtain the synchronization time.
Specifically, in this step, the current timing time of each source node calculated according to the current timing time of the own node adopts a formula:
wherein, Tb' denotes a synchronization time; t isn' represents a current timing time of the nth source node; t isbAnd k is the number of the source nodes.
In order to make the implementation of step S2 more clear, the following two source nodes are referred to as node a and node C, respectively; the transmitting node is represented by the node B as an example, and the description is made based on step S3.
Wherein the formula can be adopted
Calculating node B synchronization time to replace node BThe timing of point B.
And S5, generating the cross broadcast information packet according to the calculated synchronous time so as to transmit the cross broadcast information packet.
The node time synchronization method in the embodiment does not need to refer to the step-by-step synchronization between the nodes, eliminates the time error, and does not influence the overall performance of the network when the individual node dies.
Example 2:
as shown in fig. 2, the present embodiment provides a time synchronization apparatus, which can adopt the time synchronization method in embodiment 1. The time synchronization device includes: the device comprises a receiving module, a first calculating module, a second calculating module, a third calculating module and a sending module.
The receiving module is used for receiving the cross broadcast message packets sent by each source node and recording the time of receiving the cross broadcast message packets; wherein the cross-broadcast packet comprises: the generation time of the cross-broadcast message packet.
Specifically, the receiving module is specifically configured to receive a cross broadcast packet of each source node; and judging whether the cross broadcast information packet is received for the first time according to the received data information of the cross broadcast information packet, and recording the time of receiving the cross broadcast information if the cross broadcast information packet is received for the first time.
The first calculating module is used for calculating the timing time difference between the self node and each source node according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time for receiving the cross broadcast message packet, the sending time delay of the source node and the receiving time delay of the self node.
The first calculation module is specifically configured to, according to the received generation time of the cross broadcast message packet sent by each source node, the recorded time included in the received cross broadcast information, the sending delay of the source node, and the receiving delay of the own node, adopt a formula:
tbn=(Tn+α+β)-Tbncalculating the current timing time of each source node;
wherein, tbnRepresenting the timing time difference between the self node and the nth source node; t isnIndicating the generation time of the cross broadcast message packet sent by the nth source node; a represents the transmission delay of the nth source node; beta represents the receiving time delay of the node; t isbnThe time recorded by the self node and received by the nth sending node, wherein n is an integer greater than or equal to 1.
And the second calculation module is used for calculating the current timing time of each source node according to the current timing time of the node and the calculated timing time difference between the node and each source node.
The second calculating module is specifically configured to adopt a formula according to the current timing time of the self node and the calculated timing time difference between the self node and each source node:
Tn′=Tb+tbncalculating the current timing time of each source node;
wherein, Tn' represents a current timing time of the nth source node; t isbRepresenting the current timing time of the node; t is tbnRepresenting the timing time difference between the self node and the nth source node.
And the third calculation module is used for calculating the current timing time of each source node according to the current timing time of the node per se to obtain the synchronization time.
The third calculating module is specifically configured to calculate the current timing time of each source node according to the current timing time of the own node, and adopt a formula:
wherein, Tb' denotes a synchronization time; t isn' represents a current timing time of the nth source node; t isbAnd k is the number of the source nodes.
And the sending module is used for generating the cross broadcast information packet according to the calculated synchronous time so as to transmit the cross broadcast information packet.
The node time synchronization device in the embodiment does not need to reference the step-by-step synchronization between the nodes, eliminates the time error, and does not influence the overall performance of the network when the individual node dies.
It will be understood that the above embodiments are merely exemplary embodiments taken to illustrate the principles of the present invention, which is not limited thereto. It will be apparent to those skilled in the art that various modifications and improvements can be made without departing from the spirit and substance of the invention, and these modifications and improvements are also considered to be within the scope of the invention.