Skip to content

Commit 1d830c4

Browse files
committed
Use gps time from flysight2
1 parent 0ed1d06 commit 1d830c4

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

app/src/main/java/com/platypii/baseline/views/bluetooth/BluetoothActivity.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,11 @@ private void updateViews() {
8888
} else {
8989
binding.btSatStatus.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.status_yellow, 0, 0);
9090
}
91-
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d satellite %d Hz", sats, hz));
91+
if (sats >= 0) {
92+
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d satellite %d Hz", sats, hz));
93+
} else {
94+
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d Hz", hz));
95+
}
9296
}
9397
}
9498

common/src/main/java/com/platypii/baseline/bluetooth/Flysight2Protocol.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public class Flysight2Protocol extends BleProtocol {
2929
private static final UUID flysightCharacteristicTX = UUID.fromString("00000001-8e22-4541-9d4c-21edae82ed19");
3030
private static final UUID flysightCharacteristicRX = UUID.fromString("00000002-8e22-4541-9d4c-21edae82ed19");
3131

32+
private static final long gpsEpochMilliseconds = 315964800000L - 18000L; // January 6, 1980 - 18s
33+
private static final long millisecondsPerWeek = 604800000L;
34+
3235
public Flysight2Protocol(@NonNull PubSub<MLocation> locationUpdates) {
3336
this.locationUpdates = locationUpdates;
3437
}
@@ -56,14 +59,21 @@ public void onMtuChanged(@NonNull BluetoothPeripheral peripheral, int mtu, @NonN
5659
public void processBytes(@NonNull BluetoothPeripheral peripheral, @NonNull byte[] value) {
5760
try {
5861
final ByteBuffer buf = ByteBuffer.wrap(value).order(ByteOrder.LITTLE_ENDIAN);
59-
final int iTow = buf.getInt(0); // gps time of week
62+
final int tow = buf.getInt(0); // gps time of week
6063
final double lng = buf.getInt(4) * 1e-7;
6164
final double lat = buf.getInt(8) * 1e-7;
6265
final double alt = buf.getInt(12) * 1e-3;
6366
final double vN = buf.getInt(16) * 1e-3;
6467
final double vE = buf.getInt(20) * 1e-3;
6568
final double climb = buf.getInt(24) * -1e-3;
66-
final long millis = System.currentTimeMillis(); // TODO
69+
70+
// Calculate gps week from current system time
71+
final long now = System.currentTimeMillis();
72+
final long gpsTime = now - gpsEpochMilliseconds;
73+
final long gpsWeek = gpsTime / millisecondsPerWeek;
74+
// TODO: Check if near the start or end of the week
75+
// Calculate epoch time from time-of-week
76+
final long millis = gpsWeek * millisecondsPerWeek + tow + gpsEpochMilliseconds;
6777

6878
final int locationError = LocationCheck.validate(lat, lng);
6979
if (locationError == LocationCheck.VALID) {

0 commit comments

Comments
 (0)