Skip to content

Commit

Permalink
Use gps time from flysight2
Browse files Browse the repository at this point in the history
  • Loading branch information
platypii committed Oct 22, 2024
1 parent 0ed1d06 commit 1d830c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ private void updateViews() {
} else {
binding.btSatStatus.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.status_yellow, 0, 0);
}
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d satellite %d Hz", sats, hz));
if (sats >= 0) {
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d satellite %d Hz", sats, hz));
} else {
binding.btSatStatus.setText(String.format(Locale.getDefault(), "%d Hz", hz));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class Flysight2Protocol extends BleProtocol {
private static final UUID flysightCharacteristicTX = UUID.fromString("00000001-8e22-4541-9d4c-21edae82ed19");
private static final UUID flysightCharacteristicRX = UUID.fromString("00000002-8e22-4541-9d4c-21edae82ed19");

private static final long gpsEpochMilliseconds = 315964800000L - 18000L; // January 6, 1980 - 18s
private static final long millisecondsPerWeek = 604800000L;

public Flysight2Protocol(@NonNull PubSub<MLocation> locationUpdates) {
this.locationUpdates = locationUpdates;
}
Expand Down Expand Up @@ -56,14 +59,21 @@ public void onMtuChanged(@NonNull BluetoothPeripheral peripheral, int mtu, @NonN
public void processBytes(@NonNull BluetoothPeripheral peripheral, @NonNull byte[] value) {
try {
final ByteBuffer buf = ByteBuffer.wrap(value).order(ByteOrder.LITTLE_ENDIAN);
final int iTow = buf.getInt(0); // gps time of week
final int tow = buf.getInt(0); // gps time of week
final double lng = buf.getInt(4) * 1e-7;
final double lat = buf.getInt(8) * 1e-7;
final double alt = buf.getInt(12) * 1e-3;
final double vN = buf.getInt(16) * 1e-3;
final double vE = buf.getInt(20) * 1e-3;
final double climb = buf.getInt(24) * -1e-3;
final long millis = System.currentTimeMillis(); // TODO

// Calculate gps week from current system time
final long now = System.currentTimeMillis();
final long gpsTime = now - gpsEpochMilliseconds;
final long gpsWeek = gpsTime / millisecondsPerWeek;
// TODO: Check if near the start or end of the week
// Calculate epoch time from time-of-week
final long millis = gpsWeek * millisecondsPerWeek + tow + gpsEpochMilliseconds;

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

0 comments on commit 1d830c4

Please sign in to comment.