Disclosure of Invention
The application provides a time synchronization method and host equipment, so that the host can calculate the time difference between related equipment in an infrared transmission mode and is not influenced by a network.
A first aspect of an embodiment of the present application provides a time synchronization method, including:
the method comprises the steps that a host device obtains ambient environment information of the host device, analyzes the ambient environment information and determines infrared transmission time delta ir according to an analysis result, the ambient environment information is external factors influencing the infrared transmission time, and the host device uses a first time system;
the host equipment receives first data sent by first equipment and records second time T displayed on the host equipment when the first data is received2The first device using a second time system, the first device havingAn infrared transmission function, wherein the first data comprises a first time T displayed by the first equipment when the first equipment sends the first data1;
The host device sends a first control command to the first device, wherein the first control command indicates the first device to be at a third time T3Transmitting an infrared signal to a second device, the second device using a third time system and having an infrared transmission function;
the host equipment receives second data sent by the second equipment and records a sixth time T displayed on the host equipment when the second data is received6The second data includes a fourth time T displayed on the second device when the infrared signal is received by the second device4And a fifth moment T at which said second data is emitted being displayed on said second device5The host device, the first device, and the second device are in an infrared action area of each other;
the host device calculates a time difference between the first device and the second device.
Optionally, after the host device receives the second data sent by the second device, before the host device calculates a time difference between the first device and the second device, the method further includes:
the host device calculates a time difference between the second device and the host device.
Optionally, after the host device receives the first data sent by the first device, before the host device sends the first control command to the first device, the method further includes:
the host device calculates a time difference between the first device and the host device.
Optionally, after the host device receives the second data sent by the second device, before the host device calculates a time difference between the first device and the second device, the method further includes:
the host device calculates a time difference between the second device and the host device.
Optionally, the host device obtains the ambient environment information of the host device according to a preset time interval, analyzes the ambient environment information, and updates the infrared transmission time Δ ir according to an analysis result.
Optionally, the time used by the first device is international standard time.
A second aspect of the embodiments of the present application provides a host device, including:
an acquisition unit, configured to acquire, by the host device, ambient environment information of the host device and update an infrared transmission time Δ ir, where the host device uses a first time system;
a first receiving unit, configured to receive, by the host device, first data sent by a first device, and record a second time T of receiving2The first device uses a second time system and has an infrared transmission function, and the first data comprises a first time T when the first device sends the first data1;
A first sending unit, configured to send a first control command to the first device by the host device, where the first control command indicates that the first device is at a third time T3Transmitting an infrared signal to a second device, the second device using a third time system and having an infrared transmission function;
a second receiving unit, configured to receive, by the host device, second data sent by the second device, and record a sixth time T of reception6The second data includes a fourth time T when the infrared signal is received by the second device4And a fifth time T at which said second data is emitted5;
A first calculation unit for the host device to calculate a time difference between the first device and the second device.
Optionally, the host device further comprises:
a second calculation unit for the host device to calculate a time difference between the first device and the host device.
Optionally, the host device further comprises:
a third calculation unit for the host device to calculate a time difference between the second device and the host device.
A third aspect of the embodiments of the present application provides a host device, including:
the device comprises a processor, a memory, an input and output unit and a bus;
the processor is connected with the memory, the input and output unit and the bus;
the processor specifically performs the following operations:
the method comprises the steps that a host device obtains ambient environment information of the host device, analyzes the ambient environment information and determines infrared transmission time delta ir according to an analysis result, the ambient environment information is external factors influencing the infrared transmission time, and the host device uses a first time system;
the host equipment receives first data sent by first equipment and records second time T2 displayed on the host equipment when the first data are received, the first equipment uses a second time system, the first equipment has an infrared transmission function, and the first data comprise the first time T1 displayed by the first equipment when the first equipment sends the first data;
the host device sends a first control command to the first device, wherein the first control command is used for indicating the first device to send an infrared signal to a second device at a third time T3, and the second device uses a third time system and has an infrared transmission function;
the host device receives second data sent by the second device, and records a sixth time T6 displayed on the host device when the second data is received, the second data comprises a fourth time T4 displayed on the second device when the infrared signal is received by the second device and a fifth time T5 displayed on the second device when the second data is sent, and the host device, the first device and the second device are in infrared action areas of each other;
the host device calculates a time difference between the first device and the second device.
A fourth aspect of the embodiments of the present application provides a computer-readable storage medium, where a program is stored on the computer-readable storage medium, and when the program is executed on a computer, the program executes the foregoing service processing method.
According to the technical scheme, the host device can simply and quickly calculate the time difference between the devices connected with the host device and provided with the independent time systems, the time delta ir consumed by infrared transmission in the current environment is updated by regularly acquiring the surrounding environment information, the host device sends a control command to the first device, so that the first device sends an infrared signal to the second device at the third moment, and then the second device returns second data to correspondingly calculate the time difference between the first device and the second device.
Detailed Description
The embodiment of the application provides a time synchronization method and a host device, so that the host device can simply and quickly calculate the time difference between related devices and is not influenced by a network.
The technical solutions in the present application will be described clearly and completely with reference to the accompanying drawings in the embodiments of the present application, and it is obvious that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, an embodiment of a time synchronization method in the present application includes;
101. the method comprises the steps that a host device obtains ambient environment information of the host device, analyzes the ambient environment information and determines infrared transmission time delta ir according to an analysis result, the ambient environment information is external factors influencing the infrared transmission time, and the host device uses a first time system;
infrared transmission is a wireless transmission, and near field transmission is more advantageous, and sending an infrared signal consumes a fixed air time, which is generally between 5 and 30 milliseconds, and depends on the transmission medium, for example, the thinner the air, the higher the air, the more humid the air, the higher the air, the more particulate matter in the air, and the higher the air.
Due to certain differences of services executed by the devices, the system time used by the devices may be inconsistent. In this embodiment, the host device uses the first time system, and the used time may be international standard time or GPS time, which is not limited herein. In order to reduce the interference of external factors in the infrared transmission process, the host equipment and the related equipment are placed in the same room, the host equipment is provided with a device for detecting environmental information, the current ambient environmental information is obtained through the device and analyzed to obtain the time delta ir needed to be consumed by the infrared signal transmission in the current room, and the value is recorded.
102. The host equipment receives first data sent by first equipment and records second time T displayed on the host equipment when the first data is received2The first device uses a second time system, the first device has an infrared transmission function, and the first data comprises a first time T displayed by the first device when the first device sends the first data1;
In this embodiment, the host device receives the first data and records a receiving time T2The data is sent by the first device, wherein the first device uses the second time system to avoid time confusion during data interactionCausing a logic error, the first data including a time T displayed by the first device when the first device sends the first data1And information of a second device which needs to be processed corresponding to the service in the processing process of the first data.
103. The host device sends a first control command to the first device, wherein the first control command indicates the first device to be at a third time T3Transmitting an infrared signal to a second device, the second device using a third time system and having an infrared transmission function;
the host device sends a first control command to the first device, so that the first device sends a first control command to the first device at a third time T3Sending infrared signal to corresponding second equipment at the third time T3For the first device to reach T in its own time system3And then sending the infrared signal to the second equipment, wherein the second equipment uses a third time system due to service requirements.
104. The host equipment receives second data sent by the second equipment and records a sixth time T displayed on the host equipment when the second data is received6The second data includes a fourth time T displayed on the second device when the infrared signal is received by the second device4And a fifth moment T at which said second data is emitted being displayed on said second device5The host device, the first device, and the second device are in an infrared action area of each other;
in this embodiment, the host device receives the second data sent by the second device, and records the time T of the receiving6The sixth time T6The time displayed in the host equipment when the host equipment receives the second data comprises the fourth time T displayed on the second equipment when the second equipment receives the infrared signal sent by the first equipment4And a fifth time T displayed on the second device when the second device transmits the second data5。
In the present embodiment, in order to improve the infrared transmission effect between the devices, the devices are placed in the same clean room without impurities, and there is no barrier between the devices for blocking the infrared transmission.
105. The host device calculates a time difference between the first device and the second device.
In this embodiment, the host device calculates a time difference between the first device and the second device, and calculates Δ ir obtained instep 101 and a third time T in a subsequent step3And a fourth time T4And (3) calculating:
judging the third time T3Whether greater than the fourth time T4;
If yes, determining that the system time of the first device is ahead of the system time of the second device, wherein the time difference between the first device and the second device is as follows: t is3-T4+Δir;
If not, determining that the system time of the second device is ahead of the system time of the first device, wherein the time difference between the first device and the second device is as follows: t is4-T3+Δir。
In the embodiment of the application, the host device determines the time consumed by infrared transmission in the current environment, and calculates the time difference between the related devices by collecting the time data of sending and receiving infrared signals between other devices, so that the calculation mode is not influenced by the network condition of the host device, and the time difference between the related devices can be quickly obtained even if the network is congested.
Referring to fig. 2, another embodiment of the time synchronization method in the present application includes:
201. the method comprises the steps that host equipment obtains surrounding environment information of the host equipment and updates infrared transmission time delta ir;
step 201 in the present embodiment is similar to step 101 in the previous embodiment, and is not described herein again.
202. The first device is at a first time T1To the host deviceTransmitting the first data;
in the process of completing the service, the first device needs other devices to provide relevant data, but because different time systems are used among the devices, the host device needs to coordinate, process and forward the intermediate data. So the first device sends the first data to the host device, where the first data includes the time T displayed by the first device when the first device sends the first data1And information of a second device which needs to be processed corresponding to the service in the processing process of the first data.
203. The host equipment receives first data sent by first equipment and records and receives second time T2The first device uses a second time system and has an infrared transmission function, and the first data comprises a first time T when the first device sends the first data1;
Step 203 in the present embodiment is similar to step 102 in the previous embodiment, and is not described herein again.
204. The host device calculating a time difference between the first device and the host device;
in order to avoid that the host device causes a logical error in processing data due to a first device time contained in the data, the host device is to calculate a time difference between the first device and the host device:
judging the first time T1Whether it is greater than the second time T2;
If yes, determining that the system time of the first device is ahead of the system time of the host device, wherein the time difference between the first device and the host device is as follows: t is1-T2+Δir;
If not, determining that the system time of the host equipment is ahead of the system time of the first equipment, wherein the time difference between the first equipment and the host equipment is as follows: t is2-T1+Δir。
205. The host device sends a first control command to the first device, wherein the first control command indicates the first device to be at a third time T3Transmitting an infrared signal to a second device, the second device using a third time system and having an infrared transmission function;
step 205 in the embodiment of the present application is similar to step 103 in the previous embodiment, and is not described herein again.
206. The first device at a third time T3Transmitting an infrared signal to a second device;
the first device requires the system time at the first device to be T according to the first control command3And then transmits an infrared signal to the second device.
207. The second equipment receives the infrared signal sent by the first equipment and records and receives the fourth time T4;
The second device receives the infrared signal sent by the first device, and because different time systems are used between the two devices, the time difference between the first device and the second device is calculated for the convenience of subsequent steps, and the fourth time T of the received signal is used4And (7) recording.
208. The second device at a fifth time T5Sending second data to the host device;
209. the host equipment receives the second data sent by the second equipment and records the sixth receiving time T6The second data includes a fourth time T when the infrared signal is received by the second device4And a fifth time T at which said second data is emitted5The host device, the first device, and the second device are in an infrared action area of each other;
step 209 in the embodiment of the present application is similar to step 104 in the previous embodiment, and is not described herein again.
210. The host device calculating a time difference between the second device and the host device;
in order to avoid that the host device causes a logical error in processing data due to a second device time contained in the data, the host device is to calculate a time difference between the second device and the host device:
judging the fifth time T5Whether it is greater than the sixth time T6;
If yes, determining that the system time of the second device is ahead of the system time of the host device, wherein the time difference between the second device and the host device is as follows: t is5-T6+Δir;
If not, determining that the system time of the host equipment is ahead of the system time of the second equipment, wherein the time difference between the second equipment and the host equipment is as follows: t is6-T5+Δir。
211. The host device calculating a time difference between the first device and the second device;
step 211 in the present embodiment is similar to step 105 in the previous embodiment, and is not described herein again.
In the embodiment of the application, the host device obtains the time difference between the host device and the first device, the time difference between the second device and the host device, and the time difference between the first device and the second device by comparing and calculating the sending and receiving times among the devices, so that the method for calculating the time difference between the devices to perform time synchronization is not influenced by the network condition and is simpler and faster.
Referring to fig. 3, an embodiment of a host device in the embodiment of the present application includes:
an obtainingunit 301, configured to obtain, by the host device, ambient environment information of the host device, and update an infrared transmission time Δ ir, where the host device uses a first time system;
afirst receiving unit 302, configured to receive the first data sent by the first device and record a second time T of receiving2The first device uses a second time system and has an infrared transmission function, and the first data comprises a first time T when the first device sends the first data1;
Afirst sending unit 303, configured to send, by the host device, a first control command to the first device, where the first control command indicates that the first device is at a third time T3Sending to the second deviceAn infrared signal, the second device using a third time system and having an infrared transmission function;
asecond receiving unit 304, configured to receive, by the host device, second data sent by the second device, and record a sixth time T of reception6The second data includes a fourth time T when the infrared signal is received by the second device4And a fifth time T at which said second data is emitted5;
Afirst calculation unit 305 for the host device to calculate a time difference between the first device and the second device.
Asecond calculating unit 306, configured to calculate a time difference between the first device and the host device by the host device.
Athird calculation unit 307 for the host device to calculate a time difference between the second device and the host device.
Atiming updating unit 308, configured to obtain ambient environment information of the host device according to a preset time interval, analyze the ambient environment information, and update the infrared transmission time Δ ir according to an analysis result.
Referring to fig. 4, an embodiment of a host device in the present application includes:
aprocessor 401, amemory 402, an input-output unit 403, abus 404;
theprocessor 401 is connected to thememory 402, the input/output unit 403 and thebus 404;
theprocessor 401 specifically executes the following operations:
the host equipment acquires the ambient environment information of the host equipment and updates the infrared transmission time delta ir, wherein the host equipment uses a first time system;
the host equipment receives first data sent by first equipment and records and receives second time T2The first device uses a second time system and has an infrared transmission function, and the first data comprises a first time T when the first device sends the first data1;
The host deviceSending a first control command to the first device, where the first control command indicates that the first device is at a third time T3Transmitting an infrared signal to a second device, the second device using a third time system and having an infrared transmission function;
the host equipment receives the second data sent by the second equipment and records the sixth receiving time T6The second data includes a fourth time T when the infrared signal is received by the second device4And a fifth time T at which said second data is emitted5The host device, the first device, and the second device are in an infrared action area of each other;
the host device calculates a time difference between the first device and the second device.
It can be clearly understood by those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described device embodiments are merely illustrative, and for example, the division of the units is only one logical functional division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit.
The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present application may be substantially implemented or contributed to by the prior art, or all or part of the technical solution may be embodied in a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present application. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and the like.