From d8bf8c447f6734f0f87c8f80b1095cb0ae5ef737 Mon Sep 17 00:00:00 2001 From: Herbert von Broeuschmeul Date: Sat, 25 Sep 2010 01:09:44 +0200 Subject: add new SiIRF configuration options --- .../bluetooth/provider/BlueetoothGpsManager.java | 21 +-- .../bluetooth/provider/BluetoothGpsActivity.java | 29 +++-- .../provider/BluetoothGpsProviderService.java | 141 ++++++++++++++++----- .../android/gps/nmea/util/NmeaParser.java | 5 +- 4 files changed, 146 insertions(+), 50 deletions(-) (limited to 'src/org/broeuschmeul/android/gps') diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 4b51281..8a373b7 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -299,16 +299,19 @@ public class BlueetoothGpsManager { private void notifyNmeaSentence(final String nmeaSentence){ if (enabled){ - parser.parseNmeaSentence(nmeaSentence); + final String recognizedSentence = parser.parseNmeaSentence(nmeaSentence); final long timestamp = System.currentTimeMillis(); - synchronized(nmeaListeners) { - for(final NmeaListener listener : nmeaListeners){ - notificationPool.execute(new Runnable(){ - @Override - public void run() { - listener.onNmeaReceived(timestamp, nmeaSentence); - } - }); + if (recognizedSentence != null){ + Log.e("BT test", "NMEA : "+timestamp+" "+recognizedSentence); + synchronized(nmeaListeners) { + for(final NmeaListener listener : nmeaListeners){ + notificationPool.execute(new Runnable(){ + @Override + public void run() { + listener.onNmeaReceived(timestamp, recognizedSentence); + } + }); + } } } } diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java index d3939c5..5d079a0 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java @@ -157,16 +157,27 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer } } else if (BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE.equals(key)){ updateDevicePreferenceSummary(); - } else if (BluetoothGpsProviderService.PREF_SIRF_ENABLE_GLL.equals(key)){ - CheckBoxPreference pref = (CheckBoxPreference)(findPreference(key)); - if (pref.isChecked() != sharedPref.getBoolean(key, false)){ - pref.setChecked(sharedPref.getBoolean(key, false)); - } else { - Intent configIntent = new Intent(BluetoothGpsProviderService.ACTION_CONFIGURE_SIRF_GPS); - configIntent.putExtra(key, pref.isChecked()); - startService(configIntent); - } + } else if (BluetoothGpsProviderService.PREF_SIRF_ENABLE_GLL.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_VTG.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_GSA.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_GSV.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_ZDA.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_SBAS.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_NMEA.equals(key) + || BluetoothGpsProviderService.PREF_SIRF_ENABLE_STATIC_NAVIGATION.equals(key) + ){ + enableSirfFeature(key); } this.updateDevicePreferenceList(); } + private void enableSirfFeature(String key){ + CheckBoxPreference pref = (CheckBoxPreference)(findPreference(key)); + if (pref.isChecked() != sharedPref.getBoolean(key, false)){ + pref.setChecked(sharedPref.getBoolean(key, false)); + } else { + Intent configIntent = new Intent(BluetoothGpsProviderService.ACTION_CONFIGURE_SIRF_GPS); + configIntent.putExtra(key, pref.isChecked()); + startService(configIntent); + } + } } \ No newline at end of file diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 022823f..1fffc86 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java @@ -73,6 +73,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener public static final String PREF_TRACK_FILE_PREFIX = "trackFilePrefix"; public static final String PREF_BLUETOOTH_DEVICE = "bluetoothDevice"; + public static final String PREF_SIRF_GPS = "sirfGps"; 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"; @@ -80,6 +81,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener 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 LocationManager lm; @@ -125,19 +127,23 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener gpsManager.enableMockLocationProvider(mockProvider); // gpsManager.enableMockLocationProvider(LocationManager.GPS_PROVIDER); gpsManager.enable(); - String command1 = this.getString(R.string.sirf_nmea_gga_on); - String command2 = this.getString(R.string.sirf_nmea_gsa_off); - String command3 = this.getString(R.string.sirf_nmea_gsv_off); - String command4 = this.getString(R.string.sirf_nmea_vtg_off); - String command5 = this.getString(R.string.sirf_nmea_gll_off); - String command6 = this.getString(R.string.sirf_nmea_rmc_on); - gpsManager.sendNmeaCommand(command1); - gpsManager.sendNmeaCommand(command2); - gpsManager.sendNmeaCommand(command3); - gpsManager.sendNmeaCommand(command4); - gpsManager.sendNmeaCommand(command5); - gpsManager.sendNmeaCommand(command6); +// String command1 = this.getString(R.string.sirf_nmea_gga_on); +// String command2 = this.getString(R.string.sirf_nmea_gsa_off); +// String command3 = this.getString(R.string.sirf_nmea_gsv_off); +// String command4 = this.getString(R.string.sirf_nmea_vtg_off); +// String command5 = this.getString(R.string.sirf_nmea_gll_off); +// String command6 = this.getString(R.string.sirf_nmea_rmc_on); +// gpsManager.sendNmeaCommand(command1); +// gpsManager.sendNmeaCommand(command2); +// gpsManager.sendNmeaCommand(command3); +// gpsManager.sendNmeaCommand(command4); +// gpsManager.sendNmeaCommand(command5); +// gpsManager.sendNmeaCommand(command6); +// Bundle extras = intent.getExtras(); + if (sharedPreferences.getBoolean(PREF_SIRF_GPS, false)){ + enableSirfConfig(sharedPreferences); + } if (! sharedPreferences.getBoolean(PREF_START_GPS_PROVIDER, false)){ edit.putBoolean(PREF_START_GPS_PROVIDER,true); edit.commit(); @@ -201,25 +207,66 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener } else if (ACTION_CONFIGURE_SIRF_GPS.equals(intent.getAction())){ if (gpsManager != null){ Bundle extras = intent.getExtras(); - if (extras.containsKey(PREF_SIRF_ENABLE_GLL)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GLL, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_VTG)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_VTG, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_GSA)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GSA, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_GSV)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_GSV, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_ZDA)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_ZDA, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_SBAS)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_SBAS, false)); - } else if (extras.containsKey(PREF_SIRF_ENABLE_NMEA)){ - enableNmeaGLL(extras.getBoolean(PREF_SIRF_ENABLE_NMEA, true)); - } + enableSirfConfig(extras); } } } + private void enableSirfConfig(Bundle extras){ + 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_SBAS)){ + enableSBAS(extras.getBoolean(PREF_SIRF_ENABLE_SBAS, true)); + } + if (extras.containsKey(PREF_SIRF_ENABLE_STATIC_NAVIGATION)){ + enableStaticNavigation(extras.getBoolean(PREF_SIRF_ENABLE_STATIC_NAVIGATION, false)); + } + if (extras.containsKey(PREF_SIRF_ENABLE_NMEA)){ + enableNMEA(extras.getBoolean(PREF_SIRF_ENABLE_NMEA, 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_SBAS)){ + enableSBAS(extras.getBoolean(PREF_SIRF_ENABLE_SBAS, true)); + } + if (extras.contains(PREF_SIRF_ENABLE_STATIC_NAVIGATION)){ + enableStaticNavigation(extras.getBoolean(PREF_SIRF_ENABLE_STATIC_NAVIGATION, false)); + } + if (extras.contains(PREF_SIRF_ENABLE_NMEA)){ + enableNMEA(extras.getBoolean(PREF_SIRF_ENABLE_NMEA, true)); + } + gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_gga_on)); + gpsManager.sendNmeaCommand(this.getString(R.string.sirf_nmea_rmc_on)); + } + private void enableNmeaGLL(boolean enable){ if (gpsManager != null){ if (enable){ @@ -273,9 +320,9 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener private void enableSBAS(boolean enable){ if (gpsManager != null){ if (enable){ - gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_waas_on)); + gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_sbas_on)); } else { - gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_waas_off)); + gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_sbas_off)); } } } @@ -283,9 +330,41 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener private void enableNMEA(boolean enable){ if (gpsManager != null){ if (enable){ - gpsManager.sendNmeaCommand(getString(R.string.sirf_bin_to_nmea)); + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); +// SharedPreferences.Editor edit = sharedPreferences.edit(); + 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); +// gpsManager.sendSirfCommand(getString(R.string.sirf_bin_to_nmea)); } else { - gpsManager.sendSirfCommand(getString(R.string.sirf_nmea_to_binary)); + gpsManager.sendNmeaCommand(getString(R.string.sirf_nmea_to_binary)); + } + } + } + + private void enableStaticNavigation(boolean enable){ + if (gpsManager != null){ + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); +// SharedPreferences.Editor edit = sharedPreferences.edit(); + boolean isInNmeaMode = sharedPreferences.getBoolean(PREF_SIRF_ENABLE_NMEA, false); + if (isInNmeaMode){ + enableNMEA(false); + } + if (enable){ + gpsManager.sendNmeaCommand(getString(R.string.sirf_bin_static_nav_on)); + } else { + gpsManager.sendNmeaCommand(getString(R.string.sirf_bin_static_nav_off)); + } + if (isInNmeaMode){ + enableNMEA(true); } } } diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java index 5a3ac08..b690285 100644 --- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java +++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java @@ -178,11 +178,13 @@ public class NmeaParser { } // parse NMEA Sentence - public void parseNmeaSentence(String gpsSentence){ + public String parseNmeaSentence(String gpsSentence){ + String nmeaSentence = null; Log.e("BT test", "data: "+System.currentTimeMillis()+" "+gpsSentence); Pattern xx = Pattern.compile("\\$([^*$]*)\\*([0-9A-F][0-9A-F])?\r\n"); Matcher m = xx.matcher(gpsSentence); if (m.matches()){ + nmeaSentence = m.group(0); String sentence = m.group(1); String checkSum = m.group(2); Log.e("BT test", "data: "+System.currentTimeMillis()+" "+sentence+" cheksum; "+checkSum +" control: "+String.format("%X",computeChecksum(sentence))); @@ -448,6 +450,7 @@ public class NmeaParser { // Mode indicator, (A=autonomous, D=differential, E=Estimated, N=not valid, S=Simulator ) } } + return nmeaSentence; } public double parseNmeaLatitude(String lat,String orientation){ -- cgit v1.1