From 83277680dab92cf7de6b1906c4b2904c45e7efa9 Mon Sep 17 00:00:00 2001 From: Florin9doi Date: Sun, 26 Jan 2020 12:30:46 +0200 Subject: [PATCH] Location: add HDOP; change speed to km/h; change altitude from geoid to sea level The speed is now close to the value obtained on original hardware but the altitude on original hardawre is too imprecise to tell if we're good --- Core/HLE/sceUsbGps.cpp | 3 +- Core/HLE/sceUsbGps.h | 2 +- android/jni/app-android.cpp | 4 +- .../src/org/ppsspp/ppsspp/LocationHelper.java | 42 ++++++++++++++++--- android/src/org/ppsspp/ppsspp/NativeApp.java | 2 +- ios/ViewController.mm | 10 +++-- 6 files changed, 48 insertions(+), 15 deletions(-) diff --git a/Core/HLE/sceUsbGps.cpp b/Core/HLE/sceUsbGps.cpp index c5c7f3d9d..05b16e5b3 100644 --- a/Core/HLE/sceUsbGps.cpp +++ b/Core/HLE/sceUsbGps.cpp @@ -141,9 +141,10 @@ void GPS::setGpsTime(time_t *time) { gpsData.second = (short)gpsTime->tm_sec; } -void GPS::setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long gpsTime) { +void GPS::setGpsData(long long gpsTime, float hdop, float latitude, float longitude, float altitude, float speed, float bearing) { setGpsTime((time_t*)&gpsTime); + gpsData.hdop = hdop; gpsData.latitude = latitude; gpsData.longitude = longitude; gpsData.altitude = altitude; diff --git a/Core/HLE/sceUsbGps.h b/Core/HLE/sceUsbGps.h index a36f23791..24c2f5ccd 100644 --- a/Core/HLE/sceUsbGps.h +++ b/Core/HLE/sceUsbGps.h @@ -65,7 +65,7 @@ typedef struct { namespace GPS { void init(); void setGpsTime(time_t *time); - void setGpsData(float latitude, float longitude, float altitude, float speed, float bearing, long long time); + void setGpsData(long long time, float hdop, float latitude, float longitude, float altitude, float speed, float bearing); void setSatInfo(short index, unsigned char id, unsigned char elevation, short azimuth, unsigned char snr, unsigned char good); GpsData *getGpsData(); SatData *getSatData(); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 78802e068..dd8058df4 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -952,8 +952,8 @@ extern "C" jint Java_org_ppsspp_ppsspp_NativeApp_getSelectedCamera(JNIEnv *, jcl } extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setGpsDataAndroid(JNIEnv *, jclass, - jfloat latitude, jfloat longitude, jfloat altitude, jfloat speed, jfloat bearing, jlong time) { - GPS::setGpsData(latitude, longitude, altitude, speed, bearing, time); + jlong time, jfloat hdop, jfloat latitude, jfloat longitude, jfloat altitude, jfloat speed, jfloat bearing) { + GPS::setGpsData(time, hdop, latitude, longitude, altitude, speed, bearing); } extern "C" void JNICALL Java_org_ppsspp_ppsspp_NativeApp_setSatInfoAndroid(JNIEnv *, jclass, diff --git a/android/src/org/ppsspp/ppsspp/LocationHelper.java b/android/src/org/ppsspp/ppsspp/LocationHelper.java index b4ccef1ef..7a02ca370 100644 --- a/android/src/org/ppsspp/ppsspp/LocationHelper.java +++ b/android/src/org/ppsspp/ppsspp/LocationHelper.java @@ -12,10 +12,12 @@ import android.util.Log; import java.util.Iterator; -class LocationHelper implements LocationListener, GpsStatus.Listener { +class LocationHelper implements LocationListener, GpsStatus.Listener, GpsStatus.NmeaListener { private static final String TAG = LocationHelper.class.getSimpleName(); private LocationManager mLocationManager; private boolean mLocationEnable; + private float mAltitudeAboveSeaLevel = 0f; + private float mHdop = 0f; LocationHelper(Context context) { mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); @@ -33,6 +35,7 @@ class LocationHelper implements LocationListener, GpsStatus.Listener { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000, 0, this); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 1000, 0, this); mLocationManager.addGpsStatusListener(this); + mLocationManager.addNmeaListener(this); mLocationEnable = true; } catch (SecurityException e) { Log.e(TAG, "Cannot start location updates: " + e.toString()); @@ -52,17 +55,20 @@ class LocationHelper implements LocationListener, GpsStatus.Listener { } } + + /* + * LocationListener + */ + @Override public void onLocationChanged(Location location) { + long time = location.getTime() / 1000; // ms to s !! float latitude = (float) location.getLatitude(); float longitude = (float) location.getLongitude(); - // Android altitude is in meters above the WGS 84 reference ellipsoid - float altitude = (float) location.getAltitude(); - float speed = location.getSpeed(); + float speed = location.getSpeed() * 3.6f; // m/s to km/h !! float bearing = location.getBearing(); - long time = location.getTime() / 1000; // ms to s !! - NativeApp.setGpsDataAndroid(latitude, longitude, altitude, speed, bearing, time); + NativeApp.setGpsDataAndroid(time, mHdop, latitude, longitude, mAltitudeAboveSeaLevel, speed, bearing); } @Override @@ -78,6 +84,10 @@ class LocationHelper implements LocationListener, GpsStatus.Listener { } + /* + * GpsStatus.Listener + */ + @Override public void onGpsStatusChanged(int i) { switch (i) { @@ -110,4 +120,24 @@ class LocationHelper implements LocationListener, GpsStatus.Listener { } } } + + + /* + * GpsStatus.Listener + */ + + @Override + public void onNmeaReceived(long timestamp, String nmea) { + String[] tokens = nmea.split(","); + Log.e(TAG, nmea); + if (tokens.length < 10 || !tokens[0].equals("$GPGGA")) { + return; + } + if (!tokens[8].isEmpty()) { + mHdop = Float.valueOf(tokens[8]); + } + if (!tokens[9].isEmpty()) { + mAltitudeAboveSeaLevel = Float.valueOf(tokens[9]); + } + } } diff --git a/android/src/org/ppsspp/ppsspp/NativeApp.java b/android/src/org/ppsspp/ppsspp/NativeApp.java index 2af23dc86..fec8c5c00 100644 --- a/android/src/org/ppsspp/ppsspp/NativeApp.java +++ b/android/src/org/ppsspp/ppsspp/NativeApp.java @@ -52,7 +52,7 @@ public class NativeApp { public static native String queryConfig(String queryName); public static native int getSelectedCamera(); - public static native void setGpsDataAndroid(float latitude, float longitude, float altitude, float speed, float bearing, long time); + public static native void setGpsDataAndroid(long time, float hdop, float latitude, float longitude, float altitude, float speed, float bearing); public static native void setSatInfoAndroid(short index, short id, short elevation, short azimuth, short snr, short good); public static native void pushCameraImageAndroid(byte[] image); } diff --git a/ios/ViewController.mm b/ios/ViewController.mm index b114aed73..7c45c27a1 100644 --- a/ios/ViewController.mm +++ b/ios/ViewController.mm @@ -698,10 +698,12 @@ void stopLocation() { } -(void) SetGpsDataIOS:(CLLocation *)newLocation { - NSLog(@"SetGpsDataIOS: speed: %f", newLocation.speed); // m/s - GPS::setGpsData(newLocation.coordinate.latitude, newLocation.coordinate.longitude, - newLocation.altitude, 0 /* speed */, 0 /* bearing */, - (long long)newLocation.timestamp.timeIntervalSince1970); + GPS::setGpsData((long long)newLocation.timestamp.timeIntervalSince1970, + newLocation.horizontalAccuracy/5.0, + newLocation.coordinate.latitude, newLocation.coordinate.longitude, + newLocation.altitude, + MAX(newLocation.speed * 3.6, 0.0), /* m/s to km/h */ + 0 /* bearing */); } @end