Bluetooth-based time synchronization method, control device, and storage medium
A time synchronization method includes obtaining a first BLUETOOTH packet from a master device, where the first BLUETOOTH packet carries first time stamp information, and the first time stamp information indicates a sending moment t 1 that is of the first BLUETOOTH packet and that is determined based on a clock of the master device; and correcting a local time of a slave device based on the first time stamp information.
1 . A first electronic device, comprising:
a memory configured to store instructions; and
a processor coupled to the memory and configured to:
obtain, from a second electronic device, a first BLUETOOTH packet carrying first time stamp information, wherein the first time stamp information indicates a first sending moment (t 1 ) of the first BLUETOOTH packet, and wherein the first time stamp information is a field in a protocol data unit of a BLUETOOTH physical frame in the first BLUETOOTH packet;
send, to the second electronic device, a second BLUETOOTH packet carrying second time stamp information, wherein the second time stamp information indicates a second sending moment (t 2 ) of the second BLUETOOTH packet, and wherein t 2 is a sending moment of a first bit of an access address in the second BLUETOOTH packet;
obtain, from the second electronic device, a third BLUETOOTH packet carrying third time stamp information, wherein the third time stamp information indicates an average unidirectional transmission delay between the first electronic device and the second electronic device; and
correct a local time based on the first time stamp information and the average unidirectional transmission delay,
wherein the first electronic device a smart wearable device, and wherein the second electronic device is a mobile device.
2 . The first electronic device of claim 1 , wherein the field comprises:
a first field that is a time stamp indication indicating that the BLUETOOTH physical frame carries a time stamp; and
a second field that is the time stamp comprising t 1 .
3 . The first electronic device of claim 1 , wherein the processor is further configured to set t 1 as a current local time of the first electronic device.
4 . The first electronic device of claim 1 , wherein the third time stamp information further comprises a receiving moment (t 3 ), and wherein the processor is further configured to:
determine a transmission delay according to t 1 , t 2 , and t 3 ; and
further correct the local time based on the transmission delay.
5 . The first electronic device of claim 1 , wherein the processor is further configured to:
determine a receiving moment (t 4 ) of the first BLUETOOTH packet;
send, to the second electronic device, a fourth BLUETOOTH packet comprising t 4 and a third sending moment (t 5 ) of the fourth BLUETOOTH packet;
receive, from the second electronic device, a fifth BLUETOOTH packet comprising a transmission delay and a frequency offset time difference; and
further correct the local time based on the transmission delay and the frequency offset time difference.
6 . The first electronic device of claim 1 , wherein the processor is further configured to:
determine a first receiving moment (t 4 ) of the first BLUETOOTH packet;
send, to the second electronic device, a fourth BLUETOOTH packet comprising t 4 and a third sending moment (t 5 );
receive, from the second electronic device, a fifth BLUETOOTH packet comprising a second receiving moment (t 6 );
determine a transmission delay and a frequency offset time difference based on t 1 , t 4 , t 5 , and t 6 ; and
further correct the local time based on the transmission delay and the frequency offset time difference.
7 . The first electronic device of claim 1 , wherein the processor is further configured to correct the local time based on t 1 and a first processing time period.
8 . A second electronic device comprising:
a memory configured to store instructions; and
a processor coupled to the memory and configured to:
obtain clock information of the second electronic device;
determine a pre-start sending moment of a first BLUETOOTH packet based on the clock information;
determine a sending moment of a first bit of an access address in the first BLUETOOTH packet based on the pre-start sending moment;
set the sending moment as a sending moment (t 1 ) of the first BLUETOOTH packet;
send the first BLUETOOTH packet to a first electronic device at the pre-start sending moment, wherein the first BLUETOOTH packet carries first time stamp information, wherein the first time stamp information indicates t 1 , and wherein the first time stamp information is a field in a protocol data unit of a BLUETOOTH physical frame in the first BLUETOOTH packet;
obtain, from the first electronic device, a second BLUETOOTH packet carrying second time stamp information, wherein the second time stamp information indicates a sending moment (t 2 ) of the second BLUETOOTH packet;
determine, based on the clock information, a receiving moment (t 3 ) at which the second BLUETOOTH packet is received;
calculate an average unidirectional transmission delay between the second electronic device and the first electronic device based on t 1 , t 2 , and t 3 , and
send, to the first electronic device, a third BLUETOOTH packet carrying third time stamp information, wherein the third time stamp information indicates the average unidirectional transmission delay,
wherein the first electronic device is a smart wearable device, and wherein the second electronic device is a mobile device.
9 . The second electronic device of claim 8 , wherein the field comprises:
a first field that is a time stamp indication, wherein the time stamp indication indicates that the BLUETOOTH physical frame carries a time stamp; and
a second field that is the time stamp, wherein the time stamp comprises t 1 .
10 . The second electronic device of claim 8 , wherein the processor is further configured to calculate the average unidirectional transmission delay using a formula, wherein the formula is
T
1
=
t
3
-
t
1
-
(
t
2
-
t
1
)
2
,
and wherein T 1 represents the average unidirectional transmission delay.
11 . The second electronic device of claim 8 , wherein the processor is further configured to:
receive, from the first electronic device, a fourth BLUETOOTH packet carrying fourth time stamp information, wherein the fourth time stamp information indicates a sending moment (t 2 ) of the fourth BLUETOOTH packet, and wherein t 2 is a sending moment of a first bit of an access address in the fourth BLUETOOTH packet; and
send, from the first electronic device, a third BLUETOOTH packet carrying third time stamp information, wherein the third time stamp information comprises a receiving moment (t 3 ).
12 . The second electronic device of claim 8 , wherein the processor is further configured to:
receive, from the first electronic device, a fourth BLUETOOTH packet comprising a receiving moment (t 4 ) of the first BLUETOOTH packet and a sending moment (t 5 ) of the fourth BLUETOOTH packet;
determine a transmission delay and a frequency offset time difference based on t 1 , t 4 , and t 5 ; and
send, to the first electronic device, a third BLUETOOTH packet comprising the transmission delay and the frequency offset time difference.
13 . A method comprising:
obtaining, by a first electronic device, a first BLUETOOTH packet from a second electronic device, wherein the first BLUETOOTH packet carries first time stamp information, wherein the first time stamp information indicates a first sending moment (t 1 ) of the first BLUETOOTH packet, and wherein the first time stamp information is a field in a protocol data unit of a BLUETOOTH physical frame in the first BLUETOOTH packet;
sending, by the first electronic device, a second BLUETOOTH packet to the second electronic device, wherein the second BLUETOOTH packet carries second time stamp information, wherein the second time stamp information indicates a second sending moment (t 2 ) of the second BLUETOOTH packet, and wherein t 2 is a sending moment of a first bit of an access address in the second BLUETOOTH packet;
obtaining, by the first electronic device, a third BLUETOOTH packet from the second electronic device, wherein the third BLUETOOTH packet carries third time stamp information, and wherein the third time stamp information indicates an average unidirectional transmission delay between the first electronic device and the second electronic device;
correcting, by the first electronic device, a local time of the first electronic device based on the first time stamp information and the average unidirectional transmission delay;
obtaining, by the second electronic device before sending the first BLUETOOTH packet to the first electronic device, clock information of the second electronic device;
determining, by the second electronic device, a pre-start sending moment of the first BLUETOOTH packet based on the clock information;
determining, by the second electronic device, a sending moment of a first bit of an access address in the first BLUETOOTH packet based on the pre-start sending moment; and
setting, by the second electronic device, the sending moment of the first bit as t 1 , wherein the first electronic device is a smart wearable device, and wherein the second electronic device is a mobile device.
14 . The method of claim 13 , wherein the field comprises:
a first field that is a time stamp indication indicating that the BLUETOOTH physical frame carries a time stamp; and
a second field that is the time stamp comprising t 1 .
15 . The method of claim 13 , further comprising setting, by the first electronic device, t 1 as a current local time of the first electronic device.
16 . The method of claim 13 , further comprising:
sending, by the first electronic device, a fourth BLUETOOTH packet to the second electronic device, wherein the fourth BLUETOOTH packet carries fourth time stamp information, wherein the fourth time stamp information indicates a second sending moment (t 2 ) of the fourth BLUETOOTH packet, and wherein t 2 is a sending moment of a first bit of an access address in the fourth BLUETOOTH packet;
obtaining, by the first electronic device, a fifth BLUETOOTH packet from the second electronic device, wherein the fifth BLUETOOTH packet carries fifth time stamp information, and wherein the fifth time stamp information comprises a receiving moment (t 3 );
determining, by the first electronic device, a transmission delay according to t 1 , t 2 , and t 3 ; and
further correcting, by the first electronic device, the local time based on the transmission delay.
17 . The method of claim 13 , further comprising:
determining, by the first electronic device, a receiving moment (t 4 ) of the first BLUETOOTH packet;
sending, by the first electronic device, a fourth BLUETOOTH packet to the second electronic device, wherein the fourth BLUETOOTH packet comprises t 4 and a second sending moment (t 5 ) of the fourth BLUETOOTH packet;
receiving, by the first electronic device, a fifth BLUETOOTH packet from the second electronic device, wherein the fifth BLUETOOTH packet comprises a transmission delay and a frequency offset time difference; and
further correcting, by the first electronic device, the local time based on the transmission delay and the frequency offset time difference.