aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/broeuschmeul
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/broeuschmeul')
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java126
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java24
-rw-r--r--src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java211
-rw-r--r--src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java8
-rw-r--r--src/org/broeuschmeul/android/gps/sirf/util/SirfUtils.java50
5 files changed, 401 insertions, 18 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java
index 335539a..39a0bf4 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;
@@ -59,17 +63,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(LOG_TAG, "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"));
@@ -81,6 +100,7 @@ public class BlueetoothGpsManager {
s = reader.readLine();
Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+s);
notifyNmeaSentence(s+"\r\n");
+ ready = true;
lastRead = SystemClock.uptimeMillis();
} else {
Log.d(LOG_TAG, "data: not ready "+System.currentTimeMillis());
@@ -92,9 +112,45 @@ public class BlueetoothGpsManager {
Log.e(LOG_TAG, "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(LOG_TAG, "Exception during write", e);
+ } catch (InterruptedException e) {
+ Log.e(LOG_TAG, "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(LOG_TAG, "Exception during write", e);
+ }
+ }
}
private Service callingService;
@@ -187,15 +243,15 @@ public class BlueetoothGpsManager {
if (gpsDevice == null){
Log.e(LOG_TAG, "GPS device not found");
disable(R.string.msg_bluetooth_gps_unavaible);
- } else {
+ } else {
Log.e(LOG_TAG, "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
- try {
- gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
- } catch (IOException e) {
+ try {
+ gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
+ } catch (IOException e) {
Log.e(LOG_TAG, "Error during connection", e);
gpsSocket = null;
- }
- if (gpsSocket == null){
+ }
+ if (gpsSocket == null){
Log.e(LOG_TAG, "Error while establishing connection: no socket");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
@@ -272,7 +328,6 @@ public class BlueetoothGpsManager {
}
return this.enabled;
}
-
private synchronized void disableIfNeeded(){
if (enabled){
if (nbRetriesRemaining > 0){
@@ -315,11 +370,11 @@ public class BlueetoothGpsManager {
Log.d(LOG_TAG, "disabling Bluetooth GPS manager");
enabled = false;
if (gpsSocket != null){
- try {
- gpsSocket.close();
- } catch (IOException closeException) {
+ try {
+ gpsSocket.close();
+ } catch (IOException closeException) {
Log.e(LOG_TAG, "error while closing socket", closeException);
- }
+ }
}
nmeaListeners.clear();
disableMockLocationProvider();
@@ -412,5 +467,54 @@ public class BlueetoothGpsManager {
}
}
}
+ }
+
+ public void sendPackagedNmeaCommand(final String command){
+ Log.d(LOG_TAG, "sending NMEA sentence: "+command);
+ if (isEnabled()){
+ notificationPool.execute( new Runnable() {
+ @Override
+ public void run() {
+ while ((!enabled) || (!connected) || (connectedGps == null) || (!connectedGps.isReady())){
+ Log.v(LOG_TAG, "writing thread is not ready");
+ SystemClock.sleep(500);
+ }
+ if (isEnabled() && (connectedGps != null)){
+ connectedGps.write(command);
+ Log.d(LOG_TAG, "sent NMEA sentence: "+command);
+ }
+ }
+ });
+ }
+ }
+
+ public void sendPackagedSirfCommand(final String commandHexa){
+ Log.d(LOG_TAG, "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.v(LOG_TAG, "writing thread is not ready");
+ SystemClock.sleep(500);
+ }
+ if (isEnabled() && (connectedGps != null)){
+ connectedGps.write(command);
+ Log.d(LOG_TAG, "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 53037c1..0551913 100644
--- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
+++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java
@@ -198,7 +198,29 @@ 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)
+ || BluetoothGpsProviderService.PREF_SIRF_ENABLE_GGA.equals(key)
+ || BluetoothGpsProviderService.PREF_SIRF_ENABLE_RMC.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 41ec34e..a2f1c8d 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";
@@ -74,6 +75,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;
@@ -83,7 +96,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
@@ -105,6 +118,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();
@@ -116,8 +130,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();
}
@@ -167,6 +184,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);
+ }
}
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
index 21df4ce..3d89efc 100644
--- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
+++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java
@@ -149,7 +149,7 @@ public class NmeaParser {
public boolean isMockGpsEnabled() {
return mockGpsEnabled;
}
-
+
public void setMockLocationProviderOutOfService(){
notifyStatusChanged(LocationProvider.OUT_OF_SERVICE, null, System.currentTimeMillis());
}
@@ -160,7 +160,7 @@ public class NmeaParser {
public String getMockLocationProvider() {
return mockLocationProvider;
}
-
+
private void notifyFix(Location fix) throws SecurityException {
fixTime = null;
hasGGA = false;
@@ -174,7 +174,7 @@ public class NmeaParser {
this.fix = null;
}
}
-
+
private void notifyStatusChanged(int status, Bundle extras, long updateTime){
fixTime = null;
hasGGA = false;
@@ -191,7 +191,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();
+ }
+}