diff options
4 files changed, 141 insertions, 111 deletions
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java index ad17857..39a0bf4 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BlueetoothGpsManager.java @@ -58,6 +58,9 @@ import android.util.Log; public class BlueetoothGpsManager {
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = BlueetoothGpsManager.class.getSimpleName();
+
private class ConnectedGps extends Thread {
private final InputStream in;
private final OutputStream out;
@@ -75,13 +78,13 @@ public class BlueetoothGpsManager { tmpOut2 = new PrintStream(tmpOut, false, "US-ASCII");
}
} catch (IOException e) {
- Log.e("BT test", "error while getting socket streams", e);
+ Log.e(LOG_TAG, "error while getting socket streams", e);
}
in = tmpIn;
out = tmpOut;
out2 = tmpOut2;
}
-
+
public boolean isReady(){
return ready;
}
@@ -95,18 +98,18 @@ public class BlueetoothGpsManager { while((enabled) && (now < lastRead+5000 )){
if (reader.ready()){
s = reader.readLine();
- Log.e("BT test", "data: "+System.currentTimeMillis()+" "+s + "xxx");
+ Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+s);
notifyNmeaSentence(s+"\r\n");
ready = true;
lastRead = SystemClock.uptimeMillis();
} else {
- Log.e("BT test", "data: not ready "+System.currentTimeMillis());
+ Log.d(LOG_TAG, "data: not ready "+System.currentTimeMillis());
SystemClock.sleep(500);
}
now = SystemClock.uptimeMillis();
}
} catch (IOException e) {
- Log.e("BT test", "error while getting data", e);
+ Log.e(LOG_TAG, "error while getting data", e);
setMockLocationProviderOutOfService();
} finally {
ready = false;
@@ -126,9 +129,9 @@ public class BlueetoothGpsManager { out.write(buffer);
out.flush();
} catch (IOException e) {
- Log.e("BT test", "Exception during write", e);
+ Log.e(LOG_TAG, "Exception during write", e);
} catch (InterruptedException e) {
- Log.e("BT test", "Exception during write", e);
+ Log.e(LOG_TAG, "Exception during write", e);
}
}
/**
@@ -145,8 +148,8 @@ public class BlueetoothGpsManager { // } catch (IOException e) {
// Log.e("BT test", "Exception during write", e);
} catch (InterruptedException e) {
- Log.e("BT test", "Exception during write", e);
- }
+ Log.e(LOG_TAG, "Exception during write", e);
+ }
}
}
@@ -216,39 +219,40 @@ public class BlueetoothGpsManager { public synchronized boolean enable() {
notificationManager.cancel(R.string.service_closed_because_connection_problem_notification_title);
if (! enabled){
+ Log.d(LOG_TAG, "enabling Bluetooth GPS manager");
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (bluetoothAdapter == null) {
// Device does not support Bluetooth
- Log.e("BT test", "Device does not support Bluetooth");
+ Log.e(LOG_TAG, "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);
- Log.e("BT test", "Bluetooth is not enabled");
+ // Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
+ // startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT);
+ Log.e(LOG_TAG, "Bluetooth is not enabled");
disable(R.string.msg_bluetooth_disabled);
} else if (Settings.Secure.getInt(callingService.getContentResolver(),Settings.Secure.ALLOW_MOCK_LOCATION, 0)==0){
- Log.e("BT test", "Mock location provider OFF");
+ Log.e(LOG_TAG, "Mock location provider OFF");
disable(R.string.msg_mock_location_disabled);
// } else if ( (! locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
// && (sharedPreferences.getBoolean(BluetoothGpsProviderService.PREF_REPLACE_STD_GPS, true))
// ) {
-// Log.e("BT test", "GPS location provider OFF");
+// Log.e(LOG_TAG, "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");
+ Log.e(LOG_TAG, "GPS device not found");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
- Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
+ Log.e(LOG_TAG, "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
try {
gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
- Log.e("BT test", "Error during connection", e);
+ Log.e(LOG_TAG, "Error during connection", e);
gpsSocket = null;
}
if (gpsSocket == null){
- Log.e("BT test", "Error while establishing connection: no socket");
+ Log.e(LOG_TAG, "Error while establishing connection: no socket");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
Runnable connectThread = new Runnable() {
@@ -256,24 +260,24 @@ public class BlueetoothGpsManager { public void run() {
try {
connected = false;
- Log.e("BT test", "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
+ Log.v(LOG_TAG, "current device: "+gpsDevice.getName() + " -- " + gpsDevice.getAddress());
if ((bluetoothAdapter.isEnabled()) && (nbRetriesRemaining > 0 )){
try {
if (gpsSocket != null){
- Log.e("BT test", "trying to close old socket");
+ Log.d(LOG_TAG, "trying to close old socket");
gpsSocket.close();
}
} catch (IOException e) {
- Log.e("BT test", "Error during disconnection", e);
+ Log.e(LOG_TAG, "Error during disconnection", e);
}
try {
gpsSocket = gpsDevice.createRfcommSocketToServiceRecord(UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"));
} catch (IOException e) {
- Log.e("BT test", "Error during connection", e);
+ Log.e(LOG_TAG, "Error during connection", e);
gpsSocket = null;
}
if (gpsSocket == null){
- Log.e("BT test", "Error while establishing connection: no socket");
+ Log.e(LOG_TAG, "Error while establishing connection: no socket");
disable(R.string.msg_bluetooth_gps_unavaible);
} else {
// Cancel discovery because it will slow down the connection
@@ -281,22 +285,26 @@ public class BlueetoothGpsManager { // we increment the number of connection try
// Connect the device through the socket. This will block
// until it succeeds or throws an exception
+ Log.v(LOG_TAG, "connecting to socket");
gpsSocket.connect();
- // connection obtained so reset the number of connection try
+ Log.d(LOG_TAG, "connected to socket");
connected = true;
// reset eventual disabling cause
// setDisableReason(0);
+ // connection obtained so reset the number of connection try
nbRetriesRemaining = 1+maxConnectionRetries ;
notificationManager.cancel(R.string.connection_problem_notification_title);
+ Log.v(LOG_TAG, "starting socket reading task");
connectedGps = new ConnectedGps(gpsSocket);
connectionAndReadingPool.execute(connectedGps);
+ Log.v(LOG_TAG, "socket reading thread started");
}
// } else if (! bluetoothAdapter.isEnabled()) {
// setDisableReason(R.string.msg_bluetooth_disabled);
}
} catch (IOException connectException) {
// Unable to connect
- Log.e("BT test", "error while connecting to socket", connectException);
+ Log.e(LOG_TAG, "error while connecting to socket", connectException);
// disable(R.string.msg_bluetooth_gps_unavaible);
} finally {
nbRetriesRemaining--;
@@ -307,8 +315,12 @@ public class BlueetoothGpsManager { }
};
this.enabled = true;
+ Log.d(LOG_TAG, "Bluetooth GPS manager enabled");
+ Log.v(LOG_TAG, "starting notification thread");
notificationPool = Executors.newSingleThreadExecutor();
+ Log.v(LOG_TAG, "starting connection and reading thread");
connectionAndReadingPool = Executors.newSingleThreadScheduledExecutor();
+ Log.v(LOG_TAG, "starting connection to socket task");
connectionAndReadingPool.scheduleWithFixedDelay(connectThread, 5000, 60000, TimeUnit.MILLISECONDS);
}
}
@@ -320,7 +332,7 @@ public class BlueetoothGpsManager { if (enabled){
if (nbRetriesRemaining > 0){
// Unable to connect
- Log.e("BT test", "Unable to establish connection");
+ Log.e(LOG_TAG, "Unable to establish connection");
connectionProblemNotification.when = System.currentTimeMillis();
String pbMessage = appContext.getResources().getQuantityString(R.plurals.connection_problem_notification, nbRetriesRemaining, nbRetriesRemaining);
connectionProblemNotification.setLatestEventInfo(appContext,
@@ -339,6 +351,7 @@ public class BlueetoothGpsManager { }
public synchronized void disable(int reasonId) {
+ Log.d(LOG_TAG, "disabling Bluetooth GPS manager reason: "+callingService.getString(reasonId));
setDisableReason(reasonId);
disable();
}
@@ -354,12 +367,13 @@ public class BlueetoothGpsManager { notificationManager.notify(R.string.service_closed_because_connection_problem_notification_title, serviceStoppedNotification);
}
if (enabled){
+ Log.d(LOG_TAG, "disabling Bluetooth GPS manager");
enabled = false;
if (gpsSocket != null){
try {
gpsSocket.close();
} catch (IOException closeException) {
- Log.e("BT test", "error while closing socket", closeException);
+ Log.e(LOG_TAG, "error while closing socket", closeException);
}
}
nmeaListeners.clear();
@@ -367,17 +381,20 @@ public class BlueetoothGpsManager { notificationPool.shutdown();
connectionAndReadingPool.shutdown();
callingService.stopSelf();
+ Log.d(LOG_TAG, "Bluetooth GPS manager disabled");
}
}
public void enableMockLocationProvider(String gpsName){
if (parser != null){
+ Log.d(LOG_TAG, "enabling mock locations provider: "+gpsName);
parser.enableMockLocationProvider(gpsName);
}
}
public void disableMockLocationProvider(){
if (parser != null){
+ Log.d(LOG_TAG, "disabling mock locations provider");
parser.disableMockLocationProvider();
}
}
@@ -411,21 +428,25 @@ public class BlueetoothGpsManager { public boolean addNmeaListener(NmeaListener listener){
if (!nmeaListeners.contains(listener)){
+ Log.d(LOG_TAG, "adding new NMEA listener");
nmeaListeners.add(listener);
}
return true;
}
public void removeNmeaListener(NmeaListener listener){
+ Log.d(LOG_TAG, "removing NMEA listener");
nmeaListeners.remove(listener);
}
private void notifyNmeaSentence(final String nmeaSentence){
if (enabled){
+ Log.v(LOG_TAG, "parsing and notifying NMEA sentence: "+nmeaSentence);
String sentence = null;
try {
sentence = parser.parseNmeaSentence(nmeaSentence);
} catch (SecurityException e){
+ Log.e(LOG_TAG, "error while parsing NMEA sentence: "+nmeaSentence, e);
// a priori Mock Location is disabled
sentence = null;
disable(R.string.msg_mock_location_disabled);
@@ -433,7 +454,7 @@ public class BlueetoothGpsManager { final String recognizedSentence = sentence;
final long timestamp = System.currentTimeMillis();
if (recognizedSentence != null){
- Log.e("BT test", "NMEA : "+timestamp+" "+recognizedSentence);
+ Log.v(LOG_TAG, "notifying NMEA sentence: "+recognizedSentence);
synchronized(nmeaListeners) {
for(final NmeaListener listener : nmeaListeners){
notificationPool.execute(new Runnable(){
@@ -449,18 +470,18 @@ public class BlueetoothGpsManager { }
public void sendPackagedNmeaCommand(final String command){
- Log.e("BT test", "sending NMEA sentence: "+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.e("BT test", "writing thread is not ready");
+ Log.v(LOG_TAG, "writing thread is not ready");
SystemClock.sleep(500);
}
if (isEnabled() && (connectedGps != null)){
connectedGps.write(command);
- Log.e("BT test", "sent NMEA sentence: "+command);
+ Log.d(LOG_TAG, "sent NMEA sentence: "+command);
}
}
});
@@ -468,19 +489,19 @@ public class BlueetoothGpsManager { }
public void sendPackagedSirfCommand(final String commandHexa){
- Log.e("BT test", "sending SIRF sentence: "+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.e("BT test", "writing thread is not ready");
+ Log.v(LOG_TAG, "writing thread is not ready");
SystemClock.sleep(500);
}
if (isEnabled() && (connectedGps != null)){
connectedGps.write(command);
- Log.e("BT test", "sent SIRF sentence: "+commandHexa);
+ Log.d(LOG_TAG, "sent SIRF sentence: "+commandHexa);
}
}
});
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java index d87c2f8..ad35864 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsActivity.java @@ -43,20 +43,24 @@ import android.util.Log; *
*/
public class BluetoothGpsActivity extends PreferenceActivity implements OnPreferenceChangeListener, OnSharedPreferenceChangeListener {
+
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = BluetoothGpsActivity.class.getSimpleName();
+
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();
+ }
- /** 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)
+ /* (non-Javadoc)
* @see android.app.Activity#onResume()
*/
@Override
@@ -66,33 +70,33 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer }
private void updateDevicePreferenceSummary(){
- // update bluetooth device summary
+ // 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));
- }
+ 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
+ // 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++;
- }
+ 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.v(LOG_TAG, "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);
@@ -107,17 +111,17 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer 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());
+ Log.v(LOG_TAG, "loc. provider: "+s);
+ Log.v(LOG_TAG, "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());
- }
+ Log.v(LOG_TAG, "loc. provider: "+s);
+ Log.v(LOG_TAG, "loc. provider: "+pref.getSummary());
+ }
this.onContentChanged();
}
-
+
@Override
protected void onDestroy() {
super.onDestroy();
@@ -138,7 +142,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer if (pref.isChecked() != val){
pref.setChecked(val);
} else if (val){
- startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER));
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_GPS_PROVIDER));
} else {
startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_GPS_PROVIDER));
}
@@ -148,7 +152,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer if (pref.isChecked() != val){
pref.setChecked(val);
} else if (val){
- startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING));
+ startService(new Intent(BluetoothGpsProviderService.ACTION_START_TRACK_RECORDING));
} else {
startService(new Intent(BluetoothGpsProviderService.ACTION_STOP_TRACK_RECORDING));
}
@@ -166,7 +170,7 @@ public class BluetoothGpsActivity extends PreferenceActivity implements OnPrefer || BluetoothGpsProviderService.PREF_SIRF_ENABLE_STATIC_NAVIGATION.equals(key)
){
enableSirfFeature(key);
- }
+ }
this.updateDevicePreferenceList();
}
private void enableSirfFeature(String key){
diff --git a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java index 34cee04..c772e94 100644 --- a/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java +++ b/src/org/broeuschmeul/android/gps/bluetooth/provider/BluetoothGpsProviderService.java @@ -70,6 +70,9 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener 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";
+
+ 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";
@@ -103,7 +106,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener String deviceAddress = sharedPreferences.getString(PREF_BLUETOOTH_DEVICE, null);
int maxConRetries = Integer.parseInt(sharedPreferences.getString(PREF_CONNECTION_RETRIES, this.getString(R.string.defaultConnectionRetries)));
if (Config.LOGD){
- Log.d(BluetoothGpsProviderService.class.getName(), "prefs device addr: "+deviceAddress);
+ Log.d(LOG_TAG, "prefs device addr: "+deviceAddress);
}
if (ACTION_START_GPS_PROVIDER.equals(intent.getAction())){
if (gpsManager == null){
@@ -418,23 +421,23 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener String trackDirName = sharedPreferences.getString(PREF_TRACK_FILE_DIR, this.getString(R.string.defaultTrackFileDirectory));
String trackFilePrefix = sharedPreferences.getString(PREF_TRACK_FILE_PREFIX, this.getString(R.string.defaultTrackFilePrefix));
trackFile = new File(trackDirName,trackFilePrefix+fmt.format(new Date()));
- Log.i(BluetoothGpsProviderService.class.getName(), "Writing the prelude of the NMEA file: "+trackFile.getAbsolutePath());
+ Log.d(LOG_TAG, "Writing the prelude of the NMEA file: "+trackFile.getAbsolutePath());
File trackDir = trackFile.getParentFile();
try {
if ((! trackDir.mkdirs()) && (! trackDir.isDirectory())){
- Log.e(BluetoothGpsProviderService.class.getName(), "Error while creating parent dir of NMEA file: "+trackDir.getAbsolutePath());
+ Log.e(LOG_TAG, "Error while creating parent dir of NMEA file: "+trackDir.getAbsolutePath());
}
writer = new PrintWriter(new BufferedWriter(new FileWriter(trackFile)));
preludeWritten = true;
} catch (IOException e) {
- Log.e(BluetoothGpsProviderService.class.getName(), "Error while writing the prelude of the NMEA file: "+trackFile.getAbsolutePath(), e);
+ Log.e(LOG_TAG, "Error while writing the prelude of the NMEA file: "+trackFile.getAbsolutePath(), e);
// there was an error while writing the prelude of the NMEA file, stopping the service...
stopSelf();
}
}
private void endTrack(){
if (trackFile != null && writer != null){
- Log.i(BluetoothGpsProviderService.class.getName(), "Ending the NMEA file: "+trackFile.getAbsolutePath());
+ Log.d(LOG_TAG, "Ending the NMEA file: "+trackFile.getAbsolutePath());
preludeWritten = false;
writer.close();
trackFile = null;
@@ -444,7 +447,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener if (! preludeWritten){
beginTrack();
}
- Log.d(BluetoothGpsProviderService.class.getName(), "Adding data in the NMEA file: "+ data);
+ Log.v(LOG_TAG, "Adding data in the NMEA file: "+ data);
if (trackFile != null && writer != null){
writer.print(data);
}
@@ -455,7 +458,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener @Override
public IBinder onBind(Intent intent) {
if (Config.LOGD){
- Log.d(BluetoothGpsProviderService.class.getName(), "trying access IBinder");
+ Log.d(LOG_TAG, "trying access IBinder");
}
return null;
}
@@ -467,7 +470,7 @@ public class BluetoothGpsProviderService extends Service implements NmeaListener @Override
public void onProviderDisabled(String provider) {
- Log.e(BluetoothGpsProviderService.class.getName(), "The GPS has been disabled.....stopping the NMEA tracker service.");
+ Log.i(LOG_TAG, "The GPS has been disabled.....stopping the NMEA tracker service.");
stopSelf();
}
diff --git a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java index dbfae17..3d89efc 100644 --- a/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java +++ b/src/org/broeuschmeul/android/gps/nmea/util/NmeaParser.java @@ -36,6 +36,9 @@ import android.text.TextUtils.SimpleStringSplitter; import android.util.Log;
public class NmeaParser {
+ private static final String LOG_TAG = "BlueGPS";
+// private static final String LOG_TAG = NmeaParser.class.getSimpleName();
+
private String fixTime = null;
private long fixTimestamp;
@@ -73,27 +76,27 @@ public class NmeaParser { if (! mockGpsEnabled){
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.addTestProvider(mockLocationProvider, false, true,false, false, true, true, true, Criteria.POWER_HIGH, Criteria.ACCURACY_FINE);
if ((prov == null)
// || (! LocationManager.GPS_PROVIDER.equals(mockLocationProvider))
){
- Log.e("BT test", "enabling Mock provider: "+mockLocationProvider);
+ Log.d(LOG_TAG, "enabling Mock provider: "+mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, true);
mockGpsAutoEnabled = true;
}
mockGpsEnabled = true;
} else {
- Log.e("BT test", "Mock provider already enabled: "+mockLocationProvider);
+ Log.d(LOG_TAG, "Mock provider already enabled: "+mockLocationProvider);
}
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.e(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
}
} catch (SecurityException e){
- Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ Log.e(LOG_TAG, "Error while enabling Mock Mocations Provider", e);
disableMockLocationProvider();
}
}
@@ -104,34 +107,34 @@ public class NmeaParser { if (mockLocationProvider != null && mockLocationProvider != "" && mockGpsEnabled){
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
mockGpsEnabled = false;
if ( mockGpsAutoEnabled ) {
- Log.e("BT test", "disabling Mock provider: "+mockLocationProvider);
+ Log.d(LOG_TAG, "disabling Mock provider: "+mockLocationProvider);
lm.setTestProviderEnabled(mockLocationProvider, false);
}
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.clearTestProviderEnabled(mockLocationProvider);
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
lm.clearTestProviderStatus(mockLocationProvider);
lm.removeTestProvider(mockLocationProvider);
prov = lm.getProvider(mockLocationProvider);
if (prov != null){
- Log.e("BT test", "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
+ Log.v(LOG_TAG, "Mock provider: "+prov.getName()+" "+prov.getPowerRequirement()+" "+prov.getAccuracy()+" "+lm.isProviderEnabled(mockLocationProvider));
}
- Log.e("BT test", "removed mock GPS");
+ Log.d(LOG_TAG, "removed mock GPS");
} else {
- Log.e("BT test", "Mock provider already disabled: "+mockLocationProvider);
+ Log.d(LOG_TAG, "Mock provider already disabled: "+mockLocationProvider);
}
} catch (SecurityException e){
- Log.e("BT test", "Error while enabling Mock Mocations Provider", e);
+ Log.e(LOG_TAG, "Error while enabling Mock Mocations Provider", e);
} finally {
mockLocationProvider = null;
mockGpsEnabled = false;
@@ -163,10 +166,10 @@ public class NmeaParser { hasGGA = false;
hasRMC=false;
if (fix != null){
- Log.e(this.getClass().getSimpleName(), "New Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "New Fix: "+System.currentTimeMillis()+" "+fix);
if (lm != null && mockGpsEnabled){
lm.setTestProviderLocation(mockLocationProvider, fix);
- Log.e(this.getClass().getSimpleName(), "New Fix notified to Location Manager: "+mockLocationProvider);
+ Log.v(LOG_TAG, "New Fix notified to Location Manager: "+mockLocationProvider);
}
this.fix = null;
}
@@ -177,12 +180,12 @@ public class NmeaParser { hasGGA = false;
hasRMC=false;
if (this.mockStatus != status){
- Log.e(this.getClass().getSimpleName(), "New mockStatus: "+System.currentTimeMillis()+" "+status);
+ Log.d(LOG_TAG, "New mockStatus: "+System.currentTimeMillis()+" "+status);
if (lm != null && mockGpsEnabled){
lm.setTestProviderStatus(mockLocationProvider, status, extras, updateTime);
// lm.setTestProviderStatus(mockLocationProvider, status, extras, SystemClock.elapsedRealtime());
// lm.setTestProviderStatus(mockLocationProvider, status, extras, 50);
- Log.e(this.getClass().getSimpleName(), "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
+ Log.v(LOG_TAG, "New mockStatus notified to Location Manager: " + status + " "+mockLocationProvider);
}
this.fix = null;
this.mockStatus = status;
@@ -192,14 +195,14 @@ public class NmeaParser { // parse NMEA Sentence
public String parseNmeaSentence(String gpsSentence) throws SecurityException {
String nmeaSentence = null;
- Log.e("BT test", "data: "+System.currentTimeMillis()+" "+gpsSentence);
+ Log.v(LOG_TAG, "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)));
+ Log.v(LOG_TAG, "data: "+System.currentTimeMillis()+" "+sentence+" cheksum; "+checkSum +" control: "+String.format("%X",computeChecksum(sentence)));
SimpleStringSplitter splitter = new TextUtils.SimpleStringSplitter(',');
splitter.setString(sentence);
String command = splitter.next();
@@ -272,7 +275,7 @@ public class NmeaParser { fixTime = time;
fixTimestamp = parseNmeaTime(time);
fix.setTime(fixTimestamp);
- Log.e(this.getClass().getSimpleName(), "Fix: "+fix);
+ Log.v(LOG_TAG, "Fix: "+fix);
}
if (lat != null && !lat.equals("")){
fix.setLatitude(parseNmeaLatitude(lat,latDir));
@@ -291,7 +294,7 @@ public class NmeaParser { extras.putInt("satellites", Integer.parseInt(nbSat));
fix.setExtras(extras);
}
- Log.e(this.getClass().getSimpleName(), "Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "Fix: "+System.currentTimeMillis()+" "+fix);
hasGGA = true;
if (hasGGA && hasRMC){
notifyFix(fix);
@@ -352,7 +355,7 @@ public class NmeaParser { fixTime = time;
fixTimestamp = parseNmeaTime(time);
fix.setTime(fixTimestamp);
- Log.e(this.getClass().getSimpleName(), "Fix: "+fix);
+ Log.v(LOG_TAG, "Fix: "+fix);
}
if (lat != null && !lat.equals("")){
fix.setLatitude(parseNmeaLatitude(lat,latDir));
@@ -366,7 +369,7 @@ public class NmeaParser { if (bearing != null && !bearing.equals("")){
fix.setBearing(Float.parseFloat(bearing));
}
- Log.e(this.getClass().getSimpleName(), "Fix: "+System.currentTimeMillis()+" "+fix);
+ Log.v(LOG_TAG, "Fix: "+System.currentTimeMillis()+" "+fix);
hasRMC = true;
if (hasGGA && hasRMC){
notifyFix(fix);
@@ -526,8 +529,7 @@ public class NmeaParser { }
}
} catch (ParseException e) {
- // TODO Auto-generated catch block
- Log.e(this.getClass().getSimpleName(), "Error while parsing NMEA time", e);
+ Log.e(LOG_TAG, "Error while parsing NMEA time", e);
}
return timestamp;
}
|