From 2358dc14d7cffac55ec297f335a433f9a73df146 Mon Sep 17 00:00:00 2001 From: Herbert von Broeuschmeul Date: Fri, 1 Oct 2010 07:18:26 +0200 Subject: verify we are ready to write, before really writing --- .../gps/bluetooth/provider/BlueetoothGpsManager.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index 4db6d65..c1ad6bc 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -78,7 +78,11 @@ public class BlueetoothGpsManager { out = tmpOut; out2 = tmpOut2; } - + + public boolean isReady(){ + return ready; + } + public void run() { try { BufferedReader reader = new BufferedReader(new InputStreamReader(in,"US-ASCII")); @@ -102,6 +106,7 @@ public class BlueetoothGpsManager { Log.e("BT test", "error while getting data", e); setMockLocationProviderOutOfService(); } finally { + ready = false; disableIfNeeded(); } } @@ -396,6 +401,10 @@ public class BlueetoothGpsManager { 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); @@ -412,6 +421,10 @@ public class BlueetoothGpsManager { 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); -- cgit v1.1