问题
Maybe to general for SO, feel free to move to any other SO clone when needed.
I would like calculate the distance between 2 android smartphones based on how long it takes for a message send over Bluetooth Low Energy to travel back and forth.
Like:
- Device A connects over BLE to device B.
- Device A sends message
- Device A stores current nanoseconds (T0)
- Device B receives message on bluetooth radio (BT0)
- Device B process message
- Device B raises "message received" event (BT1)
- Device B stores current nanoseconds
- Device B send acknowledge message back to A with value BT1 - BTO
- Device A receives message on bluetooth radio (AT0)
- Device A process message
- Device A raises "message received" event (AT1)
- Device A stores current nanoseconds (T1)
Total travel time = distance covered = T1 - T0 - (BT1 - BT0) - (AT1 - AT0)
Is it all possible to calculate (BT1 - BT0) and (AT1 - AT0) on Android?
Thank you
回答1:
No. The clock inaccuracy is allowed to be as much as 50 ppm. Also, packets are allowed to be sent within a 4 microseconds window. These reasons are enough to say your proposal doesn't work.
A bigger reason is that the messages have to be processed by a Bluetooth stack in a non-realtime OS (Android) and must also be transferred over UART to the Bluetooth controller in the phone, which then schedules to transmit the message at the next connection event.
If you could program the firmware for a general microcontroller radio and time the radio with the accuracy of a 16 MHz clock, then you might be able to get some good enough results to measure longer ranges. With the introduction of BLE Long Range in BT5, the controller now have to take the distance into account when calculating the receiver window (which was +-2 microseconds in BT 4).
来源:https://stackoverflow.com/questions/44397982/calculate-time-of-flight-of-ble-message-between-2-android-phones