aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java211
1 files changed, 209 insertions, 2 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
index 8eccd7f..c772e94 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java
@@ -60,6 +60,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
public static final String ACTION_STOP_TRACK_RECORDING = "org.broeuschmeul.android.gps.bluetooth.tracker.nmea.intent.action.STOP_TRACK_RECORDING";
public static final String ACTION_START_GPS_PROVIDER = "org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.START_GPS_PROVIDER";
public static final String ACTION_STOP_GPS_PROVIDER = "org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.STOP_GPS_PROVIDER";
+ public static final String ACTION_CONFIGURE_SIRF_GPS = "org.broeuschmeul.android.gps.bluetooth.provider.nmea.intent.action.CONFIGURE_SIRF_GPS";
public static final String PREF_START_GPS_PROVIDER = "startGps";
public static final String PREF_GPS_LOCATION_PROVIDER = "gpsLocationProviderKey";
public static final String PREF_REPLACE_STD_GPS = "replaceStdtGps";
@@ -73,6 +74,18 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
private static final String LOG_TAG = "BlueGPS";
// private static final String LOG_TAG = BluetoothGpsProviderService.class.getSimpleName();
+ public static final String PREF_SIRF_GPS = "sirfGps";
+ public static final String PREF_SIRF_ENABLE_GGA = "enableGGA";
+ public static final String PREF_SIRF_ENABLE_RMC = "enableRMC";
+ public static final String PREF_SIRF_ENABLE_GLL = "enableGLL";
+ public static final String PREF_SIRF_ENABLE_VTG = "enableVTG";
+ public static final String PREF_SIRF_ENABLE_GSA = "enableGSA";
+ public static final String PREF_SIRF_ENABLE_GSV = "enableGSV";
+ public static final String PREF_SIRF_ENABLE_ZDA = "enableZDA";
+ public static final String PREF_SIRF_ENABLE_SBAS = "enableSBAS";
+ public static final String PREF_SIRF_ENABLE_NMEA = "enableNMEA";
+ public static final String PREF_SIRF_ENABLE_STATIC_NAVIGATION = "enableStaticNavigation";
+
private BlueetoothGpsManager gpsManager = null;
private PrintWriter writer;
private File trackFile;
@@ -82,7 +95,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
@Override
public void onCreate() {
super.onCreate();
- toast = Toast.makeText(getApplicationContext(), "NMEA track recording... on", Toast.LENGTH_SHORT);
+ toast = Toast.makeText(getApplicationContext(), "NMEA track recording... on", Toast.LENGTH_SHORT);
}
@Override
@@ -104,6 +117,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
}
gpsManager = new BlueetoothGpsManager(this, deviceAddress, maxConRetries);
boolean enabled = gpsManager.enable();
+// Bundle extras = intent.getExtras();
if (sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false) != enabled){
edit.putBoolean(PREF_START_GPS_PROVIDER,enabled);
edit.commit();
@@ -115,8 +129,11 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
PendingIntent myPendingIntent = PendingIntent.getActivity(this, 0, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);
notification.setLatestEventInfo(getApplicationContext(), this.getString(R.string.foreground_service_started_notification_title), this.getString(R.string.foreground_gps_provider_started_notification), myPendingIntent);
startForeground(R.string.foreground_gps_provider_started_notification, notification);
+ if (sharedPreferences.getBoolean(PREF_SIRF_GPS, false)){
+ enableSirfConfig(sharedPreferences);
+ }
toast.setText(this.getString(R.string.msg_gps_provider_started));
- toast.show();
+ toast.show();
} else {
stopSelf();
}
@@ -166,6 +183,196 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener
edit.commit();
}
stopSelf();
+ } else if (ACTION_CONFIGURE_SIRF_GPS.equals(intent.getAction())){
+ if (gpsManager != null){
+ Bundle extras = intent.getExtras();
+ enableSirfConfig(extras);
+ }
+ }
+ }
+
+ private void enableSirfConfig(Bundle extras){
+ if (extras.containsKey(PREF_SIRF_ENABLE_GGA)){
+ enableNmeaGGA(extras.getBoolean(PREF_SIRF_ENABLE_GGA, true));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_RMC)){
+ enableNmeaRMC(extras.getBoolean(PREF_SIRF_ENABLE_RMC, true));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_GLL)){
+ enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GLL, false));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_VTG)){
+ enableNmeaVTG(extras.getBoolean(PREF_SIRF_ENABLE_VTG, false));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_GSA)){
+ enableNmeaGSA(extras.getBoolean(PREF_SIRF_ENABLE_GSA, false));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_GSV)){
+ enableNmeaGSV(extras.getBoolean(PREF_SIRF_ENABLE_GSV, false));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_ZDA)){
+ enableNmeaZDA(extras.getBoolean(PREF_SIRF_ENABLE_ZDA, false));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_STATIC_NAVIGATION)){
+ enableStaticNavigation(extras.getBoolean(PREF_SIRF_ENABLE_STATIC_NAVIGATION, false));
+ } else if (extras.containsKey(PREF_SIRF_ENABLE_NMEA)){
+ enableNMEA(extras.getBoolean(PREF_SIRF_ENABLE_NMEA, true));
+ }
+ if (extras.containsKey(PREF_SIRF_ENABLE_SBAS)){
+ enableSBAS(extras.getBoolean(PREF_SIRF_ENABLE_SBAS, true));
+ }
+ }
+
+ private void enableSirfConfig(SharedPreferences extras){
+ if (extras.contains(PREF_SIRF_ENABLE_GLL)){
+ enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GLL, false));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_VTG)){
+ enableNmeaVTG(extras.getBoolean(PREF_SIRF_ENABLE_VTG, false));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_GSA)){
+ enableNmeaGSA(extras.getBoolean(PREF_SIRF_ENABLE_GSA, false));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_GSV)){
+ enableNmeaGSV(extras.getBoolean(PREF_SIRF_ENABLE_GSV, false));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_ZDA)){
+ enableNmeaZDA(extras.getBoolean(PREF_SIRF_ENABLE_ZDA, false));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_STATIC_NAVIGATION)){
+ enableStaticNavigation(extras.getBoolean(PREF_SIRF_ENABLE_STATIC_NAVIGATION, false));
+ } else if (extras.contains(PREF_SIRF_ENABLE_NMEA)){
+ enableNMEA(extras.getBoolean(PREF_SIRF_ENABLE_NMEA, true));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_SBAS)){
+ enableSBAS(extras.getBoolean(PREF_SIRF_ENABLE_SBAS, true));
+ }
+ gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_gga_on));
+ gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_rmc_on));
+ if (extras.contains(PREF_SIRF_ENABLE_GGA)){
+ enableNmeaGGA(extras.getBoolean(PREF_SIRF_ENABLE_GGA, true));
+ }
+ if (extras.contains(PREF_SIRF_ENABLE_RMC)){
+ enableNmeaRMC(extras.getBoolean(PREF_SIRF_ENABLE_RMC, true));
+ }
+ }
+
+ private void enableNmeaGGA(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gga_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gga_off));
+ }
+ }
+ }
+
+ private void enableNmeaRMC(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_rmc_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_rmc_off));
+ }
+ }
+ }
+
+ private void enableNmeaGLL(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gll_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gll_off));
+ }
+ }
+ }
+
+ private void enableNmeaVTG(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_vtg_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_vtg_off));
+ }
+ }
+ }
+
+ private void enableNmeaGSA(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gsa_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gsa_off));
+ }
+ }
+ }
+
+ private void enableNmeaGSV(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gsv_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_gsv_off));
+ }
+ }
+ }
+
+ private void enableNmeaZDA(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_zda_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_zda_off));
+ }
+ }
+ }
+
+ private void enableSBAS(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_sbas_on));
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_sbas_off));
+ }
+ }
+ }
+
+ private void enableNMEA(boolean enable){
+ if (gpsManager != null){
+ if (enable){
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ int gll = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_GLL, false)) ? 1 : 0 ;
+ int vtg = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_VTG, false)) ? 1 : 0 ;
+ int gsa = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_GSA, false)) ? 5 : 0 ;
+ int gsv = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_GSV, false)) ? 5 : 0 ;
+ int zda = (sharedPreferences.getBoolean(PREF_SIRF_ENABLE_ZDA, false)) ? 1 : 0 ;
+ int mss = 0;
+ int epe = 0;
+ int gga = 1;
+ int rmc = 1;
+ String command = getString(R.string.sirf_bin_to_nmea_38400_alt, gga, gll, gsa, gsv, rmc, vtg, mss, epe, zda);
+ gpsManager.sendSirfCommand(command);
+ } else {
+ gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_to_binary));
+ }
+ }
+ }
+
+ private void enableStaticNavigation(boolean enable){
+ if (gpsManager != null){
+ SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
+ boolean isInNmeaMode = sharedPreferences.getBoolean(PREF_SIRF_ENABLE_NMEA, true);
+ if (isInNmeaMode){
+ enableNMEA(false);
+ }
+ if (enable){
+ gpsManager.sendSirfCommand(getString(R.string.sirf_bin_static_nav_on));
+ } else {
+ gpsManager.sendSirfCommand(getString(R.string.sirf_bin_static_nav_off));
+ }
+ if (isInNmeaMode){
+ enableNMEA(true);
+ }
}
}