diff options
author | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-22 20:51:51 +0200 |
---|---|---|
committer | Herbert von Broeuschmeul <Herbert.Broeuschmeul@gmail.com> | 2010-09-22 20:51:51 +0200 |
commit | e04d8c993fc79fe9394b5d6938484037c11ed0c3 (patch) | |
tree | 6ba4c7379dce1361214c31c4d1b23586f102acbc | |
parent | 987fa33bf9ccb4afcc4504555616bc52d3ec1a79 (diff) | |
download | BlueGPS-e04d8c993fc79fe9394b5d6938484037c11ed0c3.zip BlueGPS-e04d8c993fc79fe9394b5d6938484037c11ed0c3.tar.gz BlueGPS-e04d8c993fc79fe9394b5d6938484037c11ed0c3.tar.bz2 |
add status notification
change mockGps status to
* LocationProvider.TEMPORARILY_UNAVAILABLE,
* LocationProvider.OUT_OF_SERVICE,
* LocationProvider.AVAILABLE
when the gps loses the fix or when the connection is lost or ...
Remark: on the Galaxy S it doesn't work :(
* either LocationManager.setTestProviderStatus is not used properly
* either the method is buggy
-rw-r--r-- | src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java | 24 | ||||
-rw-r--r-- | src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java | 45 |
2 files changed, 67 insertions, 2 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 6ea58bf..d156e82 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -42,6 +42,7 @@ import android.bluetooth.BluetoothSocket; import android.content.Context;
import android.location.LocationManager;
import android.location.GpsStatus.NmeaListener;
+import android.os.Bundle;
import android.util.Log;
public class BlueetoothGpsManager {
@@ -83,6 +84,7 @@ public class BlueetoothGpsManager { }
} catch (IOException e) {
Log.e("BT test", "error while getting data", e);
+ setMockLocationProviderOutOfService();
} finally {
disable();
}
@@ -277,6 +279,11 @@ public class BlueetoothGpsManager { return mockLocationProvider;
}
+ private void setMockLocationProviderOutOfService(){
+ if (parser != null){
+ parser.setMockLocationProviderOutOfService();
+ }
+ }
public boolean addNmeaListener(NmeaListener listener){
if (!nmeaListeners.contains(listener)){
@@ -304,5 +311,20 @@ public class BlueetoothGpsManager { }
}
}
- }
+ }
+
+ public void sendPackagedNmeaCommand(String s){
+ }
+ public void sendPackagedSirfCommand(String s){
+ }
+ public void sendNmeaCommand(String s){
+ if (isEnabled()){
+
+ }
+ }
+ public void sendSirfCommand(String payload){
+ if (isEnabled()){
+
+ }
+ }
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java index be4e973..5a3ac08 100644 --- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java +++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java @@ -46,6 +46,8 @@ public class NmeaParser { private boolean mockGpsEnabled = false;
private String mockLocationProvider = null;
+ private int mockStatus = LocationProvider.OUT_OF_SERVICE;
+
private Location fix = new Location(mockLocationProvider);
public NmeaParser(){
@@ -121,6 +123,7 @@ public class NmeaParser { }
mockLocationProvider = null;
mockGpsEnabled = false;
+ mockStatus = LocationProvider.OUT_OF_SERVICE;
}
/**
@@ -130,6 +133,10 @@ public class NmeaParser { return mockGpsEnabled;
}
+ public void setMockLocationProviderOutOfService(){
+ notifyStatusChanged(LocationProvider.OUT_OF_SERVICE, null, System.currentTimeMillis());
+ }
+
/**
* @return the mockLocationProvider
*/
@@ -152,6 +159,24 @@ public class NmeaParser { }
}
+ private void notifyStatusChanged(int status, Bundle extras, long updateTime){
+ //R.drawable.stat
+ fixTime = null;
+ hasGGA = false;
+ hasRMC=false;
+ if (this.mockStatus != status){
+ Log.e(this.getClass().getSimpleName(), "New mockStatus: "+System.currentTimeMillis()+" "+status);
+ if (lm != null && mockGpsEnabled){
+ lm.setTestProviderStatus(mockLocationProvider, status, extras, updateTime);
+// lm.setTestProviderStatus(mockLocationProvider, status, extras, SystemClock.elapsedRealtime());
+// lm.setTestProviderStatus(mockLocationProvider, status, extras, 50);
+ Log.e(this.getClass().getSimpleName(), "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
+ }
+ this.fix = null;
+ this.mockStatus = status;
+ }
+ }
+
// parse NMEA Sentence
public void parseNmeaSentence(String gpsSentence){
Log.e("BT test", "data: "+System.currentTimeMillis()+" "+gpsSentence);
@@ -223,6 +248,10 @@ public class NmeaParser { // time in seconds since last DGPS update
// DGPS station ID number
if (quality != null && !quality.equals("") && !quality.equals("0") ){
+ if (this.mockStatus != LocationProvider.AVAILABLE){
+ long updateTime = parseNmeaTime(time);
+ notifyStatusChanged(LocationProvider.AVAILABLE, null, updateTime);
+ }
if (! time.equals(fixTime)){
notifyFix(fix);
fix = new Location(mockLocationProvider);
@@ -253,7 +282,12 @@ public class NmeaParser { if (hasGGA && hasRMC){
notifyFix(fix);
}
- }
+ } else if(quality.equals("0")){
+ if (this.mockStatus != LocationProvider.TEMPORARILY_UNAVAILABLE){
+ long updateTime = parseNmeaTime(time);
+ notifyStatusChanged(LocationProvider.TEMPORARILY_UNAVAILABLE, null, updateTime);
+ }
+ }
} else if (command.equals("GPRMC")){
/* $GPRMC,123519,A,4807.038,N,01131.000,E,022.4,084.4,230394,003.1,W*6A
@@ -294,6 +328,10 @@ public class NmeaParser { // for NMEA 0183 version 3.00 active the Mode indicator field is added
// Mode indicator, (A=autonomous, D=differential, E=Estimated, N=not valid, S=Simulator )
if (status != null && !status.equals("") && status.equals("A") ){
+ if (this.mockStatus != LocationProvider.AVAILABLE){
+ long updateTime = parseNmeaTime(time);
+ notifyStatusChanged(LocationProvider.AVAILABLE, null, updateTime);
+ }
if (! time.equals(fixTime)){
notifyFix(fix);
fix = new Location(mockLocationProvider);
@@ -319,6 +357,11 @@ public class NmeaParser { if (hasGGA && hasRMC){
notifyFix(fix);
}
+ } else if(status.equals("V")){
+ if (this.mockStatus != LocationProvider.TEMPORARILY_UNAVAILABLE){
+ long updateTime = parseNmeaTime(time);
+ notifyStatusChanged(LocationProvider.TEMPORARILY_UNAVAILABLE, null, updateTime);
+ }
}
} else if (command.equals("GPGSA")){
/* $GPGSA,A,3,04,05,,09,12,,,24,,,,,2.5,1.3,2.1*39
|