diff options
Diffstat (limited to 'src')
5 files changed, 519 insertions, 171 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 5f1860b..ad17857 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -24,9 +24,12 @@ import java.io.BufferedReader; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.io.PrintStream;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
+import java.util.Locale;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -34,6 +37,7 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit;
import org.broeuschmeul.android.gps.nmea.util.NmeaParser;
+import org.broeuschmeul.android.gps.sirf.util.SirfUtils;
import android.app.Notification;
import android.app.NotificationManager;
@@ -56,17 +60,32 @@ public class BlueetoothGpsManager { private class ConnectedGps extends Thread {
private final InputStream in;
+ private final OutputStream out;
+ private final PrintStream out2;
+ private boolean ready = false;
public ConnectedGps(BluetoothSocket socket) {
InputStream tmpIn = null;
+ OutputStream tmpOut = null;
+ PrintStream tmpOut2 = null;
try {
tmpIn = socket.getInputStream();
+ tmpOut = socket.getOutputStream();
+ if (tmpOut != null){
+ tmpOut2 = new PrintStream(tmpOut, false, "US-ASCII");
+ }
} catch (IOException e) {
Log.e("BT test", "error while getting socket streams", e);
}
in = tmpIn;
+ out = tmpOut;
+ out2 = tmpOut2;
}
-
+
+ public boolean isReady(){
+ return ready;
+ }
+
public void run() {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(in,"US-ASCII"));
@@ -78,6 +97,7 @@ public class BlueetoothGpsManager { s = reader.readLine();
Log.e("BT test", "data: "+System.currentTimeMillis()+" "+s + "xxx");
notifyNmeaSentence(s+"\r\n");
+ ready = true;
lastRead = SystemClock.uptimeMillis();
} else {
Log.e("BT test", "data: not ready "+System.currentTimeMillis());
@@ -89,9 +109,45 @@ public class BlueetoothGpsManager { Log.e("BT test", "error while getting data", e);
setMockLocationProviderOutOfService();
} finally {
+ ready = false;
disableIfNeeded();
}
}
+
+ /**
+ * Write to the connected OutStream.
+ * @param buffer The bytes to write
+ */
+ public void write(byte[] buffer) {
+ try {
+ do {
+ Thread.sleep(100);
+ } while (! ready);
+ out.write(buffer);
+ out.flush();
+ } catch (IOException e) {
+ Log.e("BT test", "Exception during write", e);
+ } catch (InterruptedException e) {
+ Log.e("BT test", "Exception during write", e);
+ }
+ }
+ /**
+ * Write to the connected OutStream.
+ * @param buffer The data to write
+ */
+ public void write(String buffer) {
+ try {
+ do {
+ Thread.sleep(100);
+ } while (! ready);
+ out2.print(buffer);
+ out2.flush();
+ // } catch (IOException e) {
+ // Log.e("BT test", "Exception during write", e);
+ } catch (InterruptedException e) {
+ Log.e("BT test", "Exception during write", e);
+ }
+ }
}
private Service callingService;
@@ -166,8 +222,8 @@ public class BlueetoothGpsManager { Log.e("BT test", "Device does not support Bluetooth");
disable(R.string.msg_bluetooth_unsupported);
} else if (!bluetoothAdapter.isEnabled()) {
- // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
- // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+ // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
Log.e("BT test", "Bluetooth is not enabled");
disable(R.string.msg_bluetooth_disabled);
} else if (Settings.Secure.getInt(callingService.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 0)==0){
@@ -178,7 +234,7 @@ public class BlueetoothGpsManager { // ) {
// Log.e("BT test", "GPS location provider OFF");
// disable(R.string.msg_gps_provider_disabled);
- } else {
+ } else {
final BluetoothDevice gpsDevice = bluetoothAdapter.getRemoteDevice(gpsDeviceAddress);
if (gpsDevice == null){
Log.e("BT test", "GPS device not found");
@@ -260,7 +316,6 @@ public class BlueetoothGpsManager { }
return this.enabled;
}
-
private synchronized void disableIfNeeded(){
if (enabled){
if (nbRetriesRemaining > 0){
@@ -392,4 +447,53 @@ public class BlueetoothGpsManager { }
}
}
+
+ public void sendPackagedNmeaCommand(final String command){
+ Log.e("BT test", "sending NMEA sentence: "+command);
+ if (isEnabled()){
+ notificationPool.execute( new Runnable() {
+ @Override
+ public void run() {
+ while ((!enabled) || (!connected) || (connectedGps == null) || (!connectedGps.isReady())){
+ Log.e("BT test", "writing thread is not ready");
+ SystemClock.sleep(500);
+ }
+ if (isEnabled() && (connectedGps != null)){
+ connectedGps.write(command);
+ Log.e("BT test", "sent NMEA sentence: "+command);
+ }
+ }
+ });
+ }
+ }
+
+ public void sendPackagedSirfCommand(final String commandHexa){
+ Log.e("BT test", "sending SIRF sentence: "+commandHexa);
+ if (isEnabled()){
+ final byte[] command = SirfUtils.genSirfCommand(commandHexa);
+ notificationPool.execute( new Runnable() {
+ @Override
+ public void run() {
+ while ((!enabled) || (!connected) || (connectedGps == null) || (!connectedGps.isReady())){
+ Log.e("BT test", "writing thread is not ready");
+ SystemClock.sleep(500);
+ }
+ if (isEnabled() && (connectedGps != null)){
+ connectedGps.write(command);
+ Log.e("BT test", "sent SIRF sentence: "+commandHexa);
+ }
+ }
+ });
+ }
+ }
+
+ public void sendNmeaCommand(String sentence){
+ String command = String.format((Locale)null,"$%s*%X\r\n", sentence, parser.computeChecksum(sentence));
+ sendPackagedNmeaCommand(command);
+ }
+
+ public void sendSirfCommand(String payload){
+ String command = SirfUtils.createSirfCommandFromPayload(payload);
+ sendPackagedSirfCommand(command);
+ }
}
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java index e09ae34..a398e19 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java @@ -1,160 +1,180 @@ -/* - * Copyright (C) 2010 Herbert von Broeuschmeul - * Copyright (C) 2010 BluetoothGPS4Droid Project - * - * This file is part of BluetoothGPS4Droid. - * - * BluetoothGPS4Droid is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * BluetoothGPS4Droid is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with BluetoothGPS4Droid. If not, see <http://www.gnu.org/licenses/>. - */ - -package org.broeuschmeul.android.gps.bluetooth.provider; - -import java.util.Set; - -import android.bluetooth.BluetoothAdapter; -import android.bluetooth.BluetoothDevice; -import android.content.Intent; -import android.content.SharedPreferences; -import android.content.SharedPreferences.OnSharedPreferenceChangeListener; -import android.os.Bundle; -import android.preference.CheckBoxPreference; -import android.preference.ListPreference; -import android.preference.Preference; -import android.preference.PreferenceActivity; -import android.preference.PreferenceManager; -import android.preference.Preference.OnPreferenceChangeListener; -import android.util.Log; - -/** - * A PreferenceActivity Class used to configure, start and stop the NMEA tracker service. - * - * @author Herbert von Broeuschmeul - * - */ -public class BluetoothGpsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSharedPreferenceChangeListener { - private SharedPreferences sharedPref ; - private BluetoothAdapter bluetoothAdapter = null; - - /** Called when the activity is first created. */ - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - addPreferencesFromResource(R.xml.pref); - sharedPref = PreferenceManager.getDefaultSharedPreferences(this); - sharedPref.registerOnSharedPreferenceChangeListener(this); - bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); - } - - /* (non-Javadoc) - * @see android.app.Activity#onResume() - */ - @Override - protected void onResume() { - this.updateDevicePreferenceList(); - super.onResume(); - } - - private void updateDevicePreferenceSummary(){ - // update bluetooth device summary - String deviceName = ""; - ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); - String deviceAddress = sharedPref.getString(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE, null); - if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){ - deviceName = bluetoothAdapter.getRemoteDevice(deviceAddress).getName(); - } - prefDevices.setSummary(getString(R.string.pref_bluetooth_device_summary, deviceName)); - } - - private void updateDevicePreferenceList(){ - // update bluetooth device summary - updateDevicePreferenceSummary(); - // update bluetooth device list - ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE); - Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices(); - String[] entryValues = new String[pairedDevices.size()]; - String[] entries = new String[pairedDevices.size()]; - int i = 0; - // Loop through paired devices - for (BluetoothDevice device : pairedDevices) { - // Add the name and address to the ListPreference enties and entyValues - Log.e("BT test", "device: "+device.getName() + " -- " + device.getAddress()); - entryValues[i] = device.getAddress(); - entries[i] = device.getName(); - i++; - } - prefDevices.setEntryValues(entryValues); - prefDevices.setEntries(entries); - Preference pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_TRACK_RECORDING); - pref.setEnabled(sharedPref.getBoolean(BluetoothGpsProviderService.PREF_START_GPS_PROVIDER, false)); - pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME); - String mockProvider = sharedPref.getString(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName)); - pref.setSummary(getString(R.string.pref_mock_gps_name_summary,mockProvider)); - pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES); - String maxConnRetries = sharedPref.getString(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES, getString(R.string.defaultConnectionRetries)); - pref.setSummary(getString(R.string.pref_connection_retries_summary,maxConnRetries)); - pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_GPS_LOCATION_PROVIDER); - if (sharedPref.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true)){ - String s = getString(R.string.pref_gps_location_provider_summary); - pref.setSummary(s); - Log.e("BT test", "loc. provider: "+s); - Log.e("BT test", "loc. provider: "+pref.getSummary()); - } else { - String s = getString(R.string.pref_mock_gps_name_summary, mockProvider); - pref.setSummary(s); - Log.e("BT test", "loc. provider: "+s); - Log.e("BT test", "loc. provider: "+pref.getSummary()); - } - this.onContentChanged(); - } - - @Override - protected void onDestroy() { - super.onDestroy(); - sharedPref.unregisterOnSharedPreferenceChangeListener(this); - } - - @Override - public boolean onPreferenceChange(Preference preference, Object newValue) { - // TODO Auto-generated method stub - return false; - } - - @Override - public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { - if (BluetoothGpsProviderService.PREF_START_GPS_PROVIDER.equals(key)){ - boolean val = sharedPreferences.getBoolean(key, false); - CheckBoxPreference pref = (CheckBoxPreference)findPreference(key); - if (pref.isChecked() != val){ - pref.setChecked(val); - } else if (val){ - startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER)); - } else { - startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER)); - } - } else if (BluetoothGpsProviderService.PREF_TRACK_RECORDING.equals(key)){ - boolean val = sharedPreferences.getBoolean(key, false); - CheckBoxPreference pref = (CheckBoxPreference)findPreference(key); - if (pref.isChecked() != val){ - pref.setChecked(val); - } else if (val){ - startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING)); - } else { - startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING)); - } - } else if (BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE.equals(key)){ - updateDevicePreferenceSummary(); - } - this.updateDevicePreferenceList(); - } -}
\ No newline at end of file +/*
+ * Copyright (C) 2010 Herbert von Broeuschmeul
+ * Copyright (C) 2010 BluetoothGPS4Droid Project
+ *
+ * This file is part of BluetoothGPS4Droid.
+ *
+ * BluetoothGPS4Droid is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * BluetoothGPS4Droid is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with BluetoothGPS4Droid. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+package org.broeuschmeul.android.gps.bluetooth.provider;
+
+import java.util.Set;
+
+import android.bluetooth.BluetoothAdapter;
+import android.bluetooth.BluetoothDevice;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
+import android.os.Bundle;
+import android.preference.CheckBoxPreference;
+import android.preference.ListPreference;
+import android.preference.Preference;
+import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
+import android.preference.Preference.OnPreferenceChangeListener;
+import android.util.Log;
+
+/**
+ * A PreferenceActivity Class used to configure, start and stop the NMEA tracker service.
+ *
+ * @author Herbert von Broeuschmeul
+ *
+ */
+public class BluetoothGpsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSharedPreferenceChangeListener {
+ private SharedPreferences sharedPref ;
+ private BluetoothAdapter bluetoothAdapter = null;
+
+ /** Called when the activity is first created. */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ addPreferencesFromResource(R.xml.pref);
+ sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
+ sharedPref.registerOnSharedPreferenceChangeListener(this);
+ bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
+ }
+
+ /* (non-Javadoc)
+ * @see android.app.Activity#onResume()
+ */
+ @Override
+ protected void onResume() {
+ this.updateDevicePreferenceList();
+ super.onResume();
+ }
+
+ private void updateDevicePreferenceSummary(){
+ // update bluetooth device summary
+ String deviceName = "";
+ ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE);
+ String deviceAddress = sharedPref.getString(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE, null);
+ if (BluetoothAdapter.checkBluetoothAddress(deviceAddress)){
+ deviceName = bluetoothAdapter.getRemoteDevice(deviceAddress).getName();
+ }
+ prefDevices.setSummary(getString(R.string.pref_bluetooth_device_summary, deviceName));
+ }
+
+ private void updateDevicePreferenceList(){
+ // update bluetooth device summary
+ updateDevicePreferenceSummary();
+ // update bluetooth device list
+ ListPreference prefDevices = (ListPreference)findPreference(BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE);
+ Set<BluetoothDevice> pairedDevices = bluetoothAdapter.getBondedDevices();
+ String[] entryValues = new String[pairedDevices.size()];
+ String[] entries = new String[pairedDevices.size()];
+ int i = 0;
+ // Loop through paired devices
+ for (BluetoothDevice device : pairedDevices) {
+ // Add the name and address to the ListPreference enties and entyValues
+ Log.e("BT test", "device: "+device.getName() + " -- " + device.getAddress());
+ entryValues[i] = device.getAddress();
+ entries[i] = device.getName();
+ i++;
+ }
+ prefDevices.setEntryValues(entryValues);
+ prefDevices.setEntries(entries);
+ Preference pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_TRACK_RECORDING);
+ pref.setEnabled(sharedPref.getBoolean(BluetoothGpsProviderService.PREF_START_GPS_PROVIDER, false));
+ pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME);
+ String mockProvider = sharedPref.getString(BluetoothGpsProviderService.PREF_MOCK_GPS_NAME, getString(R.string.defaultMockGpsName));
+ pref.setSummary(getString(R.string.pref_mock_gps_name_summary,mockProvider));
+ pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES);
+ String maxConnRetries = sharedPref.getString(BluetoothGpsProviderService.PREF_CONNECTION_RETRIES, getString(R.string.defaultConnectionRetries));
+ pref.setSummary(getString(R.string.pref_connection_retries_summary,maxConnRetries));
+ pref = (Preference)findPreference(BluetoothGpsProviderService.PREF_GPS_LOCATION_PROVIDER);
+ if (sharedPref.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true)){
+ String s = getString(R.string.pref_gps_location_provider_summary);
+ pref.setSummary(s);
+ Log.e("BT test", "loc. provider: "+s);
+ Log.e("BT test", "loc. provider: "+pref.getSummary());
+ } else {
+ String s = getString(R.string.pref_mock_gps_name_summary, mockProvider);
+ pref.setSummary(s);
+ Log.e("BT test", "loc. provider: "+s);
+ Log.e("BT test", "loc. provider: "+pref.getSummary());
+ }
+ this.onContentChanged();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+ sharedPref.unregisterOnSharedPreferenceChangeListener(this);
+ }
+
+ @Override
+ public boolean onPreferenceChange(Preference preference, Object newValue) {
+ // TODO Auto-generated method stub
+ return false;
+ }
+
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (BluetoothGpsProviderService.PREF_START_GPS_PROVIDER.equals(key)){
+ boolean val = sharedPreferences.getBoolean(key, false);
+ CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
+ if (pref.isChecked() != val){
+ pref.setChecked(val);
+ } else if (val){
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER));
+ } else {
+ startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER));
+ }
+ } else if (BluetoothGpsProviderService.PREF_TRACK_RECORDING.equals(key)){
+ boolean val = sharedPreferences.getBoolean(key, false);
+ CheckBoxPreference pref = (CheckBoxPreference)findPreference(key);
+ if (pref.isChecked() != val){
+ pref.setChecked(val);
+ } else if (val){
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING));
+ } else {
+ startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING));
+ }
+ } else if (BluetoothGpsProviderService.PREF_BLUETOOTH_DEVICE.equals(key)){
+ updateDevicePreferenceSummary();
+ } 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);
+ }
+ }
+}
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 5146d1d..37ce43a 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java @@ -60,16 +60,29 @@ 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";
public static final String PREF_MOCK_GPS_NAME = "mockGpsName";
public static final String PREF_CONNECTION_RETRIES = "connectionRetries";
public static final String PREF_TRACK_RECORDING = "trackRecording";
+ public static final String PREF_TRACK_MIN_DISTANCE = "trackMinDistance";
+ public static final String PREF_TRACK_MIN_TIME = "trackMinTime";
public static final String PREF_TRACK_FILE_DIR = "trackFileDirectory";
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";
+ 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;
@@ -79,7 +92,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
@@ -101,6 +114,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();
@@ -112,8 +126,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();
}
@@ -163,6 +180,163 @@ 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_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));
+ }
+
+ 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);
+ }
}
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java index 5b06c62..dbfae17 100644 --- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java +++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java @@ -146,7 +146,7 @@ public class NmeaParser { public boolean isMockGpsEnabled() {
return mockGpsEnabled;
}
-
+
public void setMockLocationProviderOutOfService(){
notifyStatusChanged(LocationProvider.OUT_OF_SERVICE, null, System.currentTimeMillis());
}
@@ -157,7 +157,7 @@ public class NmeaParser { public String getMockLocationProvider() {
return mockLocationProvider;
}
-
+
private void notifyFix(Location fix) throws SecurityException {
fixTime = null;
hasGGA = false;
@@ -171,7 +171,7 @@ public class NmeaParser { this.fix = null;
}
}
-
+
private void notifyStatusChanged(int status, Bundle extras, long updateTime){
fixTime = null;
hasGGA = false;
@@ -188,7 +188,7 @@ public class NmeaParser { this.mockStatus = status;
}
}
-
+
// parse NMEA Sentence
public String parseNmeaSentence(String gpsSentence) throws SecurityException {
String nmeaSentence = null;
diff --git a/src/org/broeuschmeul/android/gps/sirf/util/SirfUtils.java b/src/org/broeuschmeul/android/gps/sirf/util/SirfUtils.java new file mode 100644 index 0000000..cff60f7 --- /dev/null +++ b/src/org/broeuschmeul/android/gps/sirf/util/SirfUtils.java @@ -0,0 +1,50 @@ +package org.broeuschmeul.android.gps.sirf.util;
+
+import java.math.BigInteger;
+import java.nio.ByteBuffer;
+import java.util.Formatter;
+import java.util.Locale;
+
+public class SirfUtils {
+
+ private static final String start ="A0A2";
+ private static final String end ="B0B3";
+
+ public static byte[] genSirfCommand(String commandHexa){
+ int length = commandHexa.length()/2;
+ ByteBuffer command = ByteBuffer.allocate(length);
+ command.put(new BigInteger(commandHexa,16).toByteArray(), 1,length);
+ return command.array();
+ }
+
+ public static byte[] genSirfCommandFromPayload(String payload){
+ String commandHexa = createSirfCommandFromPayload(payload);
+ return genSirfCommand(commandHexa);
+ }
+
+ public static String createSirfCommandFromPayload(String payload){
+ int length = payload.length()/2;
+ String res;
+
+ byte[] command = new BigInteger(payload,16).toByteArray();
+
+ int checkSum = 0;
+ for (byte b : command){
+ checkSum += (b & 0xff);
+ }
+ checkSum &= 0x7FFF;
+
+ res = String.format((Locale)null, "%s%04X%s%04X%s", start, length, payload, checkSum, end);
+ return res;
+ }
+
+ public static String showSirfCommandFromPayload(String payload){
+ byte[] command = genSirfCommandFromPayload(payload);
+ StringBuilder out = new StringBuilder(payload.length()+16);
+ Formatter fmt = new Formatter(out, null);
+ for (byte b : command){
+ fmt.format("%02X", b);
+ }
+ return out.toString();
+ }
+}
|