forked from upstream-mirrors/OpenTracks
import static MyTracksConstants.TAG
This commit is contained in:
+4
-4
@@ -16,16 +16,16 @@
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.dsi.ant.AntDefine;
|
||||
import com.dsi.ant.AntMesg;
|
||||
import com.dsi.ant.exception.AntInterfaceException;
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntChannelIdMessage;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntChannelResponseMessage;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import com.dsi.ant.AntDefine;
|
||||
import com.dsi.ant.AntMesg;
|
||||
import com.dsi.ant.exception.AntInterfaceException;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
+18
-24
@@ -15,14 +15,14 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.dsi.ant.AntDefine;
|
||||
import com.dsi.ant.AntMesg;
|
||||
import com.dsi.ant.exception.AntInterfaceException;
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -82,10 +82,10 @@ public class AntSRMSensorManager extends AntSensorManager {
|
||||
@Override
|
||||
public void handleMessage(byte[] antMessage) {
|
||||
// Parse channel number
|
||||
byte recievedChannel = (byte) (antMessage[AntMesg.MESG_DATA_OFFSET]
|
||||
byte receivedChannel = (byte) (antMessage[AntMesg.MESG_DATA_OFFSET]
|
||||
& AntDefine.CHANNEL_NUMBER_MASK);
|
||||
if (recievedChannel != channel) {
|
||||
Log.d(MyTracksConstants.TAG, "Unexpected channel: " + recievedChannel);
|
||||
if (receivedChannel != channel) {
|
||||
Log.d(TAG, "Unexpected channel: " + receivedChannel);
|
||||
return;
|
||||
}
|
||||
switch (antMessage[AntMesg.MESG_ID_OFFSET]) {
|
||||
@@ -99,18 +99,17 @@ public class AntSRMSensorManager extends AntSensorManager {
|
||||
handleChannelId(antMessage);
|
||||
break;
|
||||
default:
|
||||
Log.e(MyTracksConstants.TAG,
|
||||
"Unexpected message id: " + antMessage[3]);
|
||||
Log.e(TAG, "Unexpected message id: " + antMessage[3]);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleBroadcastData(byte[] antMessage) {
|
||||
if (deviceId == WILDCARD) {
|
||||
try {
|
||||
Log.d(MyTracksConstants.TAG, "Requesting channel id id.");
|
||||
Log.d(TAG, "Requesting channel id id.");
|
||||
getAntReceiver().ANTRequestMessage(channel, AntMesg.MESG_CHANNEL_ID_ID);
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Failed to request channel id id", e);
|
||||
Log.e(TAG, "Failed to request channel id id", e);
|
||||
}
|
||||
}
|
||||
setSensorState(Sensor.SensorState.CONNECTED);
|
||||
@@ -122,15 +121,14 @@ public class AntSRMSensorManager extends AntSensorManager {
|
||||
parseSensorData(antMessage);
|
||||
break;
|
||||
default:
|
||||
Log.e(MyTracksConstants.TAG,
|
||||
"Unexpected message type: " + antMessage[MESSAGE_TYPE_INDEX]);
|
||||
Log.e(TAG, "Unexpected message type: " + antMessage[MESSAGE_TYPE_INDEX]);
|
||||
}
|
||||
}
|
||||
|
||||
private void handleChannelId(byte[] antMessage) {
|
||||
// Store the device id.
|
||||
deviceId = antMessage[3];
|
||||
Log.i(MyTracksConstants.TAG, "Found device id: " + deviceId);
|
||||
Log.i(TAG, "Found device id: " + deviceId);
|
||||
|
||||
SharedPreferences prefs = context.getSharedPreferences(
|
||||
MyTracksSettings.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||
@@ -143,38 +141,34 @@ public class AntSRMSensorManager extends AntSensorManager {
|
||||
if (antMessage[3] == AntMesg.MESG_EVENT_ID
|
||||
&& antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
|
||||
// Search timeout
|
||||
Log.w(MyTracksConstants.TAG, "Search timed out. Unassigning channel.");
|
||||
Log.w(TAG, "Search timed out. Unassigning channel.");
|
||||
try {
|
||||
getAntReceiver().ANTUnassignChannel(channel);
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Failed to unassign ANT channel", e);
|
||||
Log.e(TAG, "Failed to unassign ANT channel", e);
|
||||
}
|
||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||
} else if (antMessage[3] == AntMesg.MESG_UNASSIGN_CHANNEL_ID) {
|
||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"Disconnected from the sensor: " + getSensorState());
|
||||
Log.i(TAG, "Disconnected from the sensor: " + getSensorState());
|
||||
}
|
||||
}
|
||||
|
||||
private void parseSensorData(byte[] antMessage) {
|
||||
if (antMessage.length != 11) {
|
||||
Log.e(MyTracksConstants.TAG,
|
||||
"Unexpected ant message length: " + antMessage.length);
|
||||
Log.e(TAG, "Unexpected ant message length: " + antMessage.length);
|
||||
return;
|
||||
}
|
||||
|
||||
int newMessageId = antMessage[MESSAGE_ID_INDEX] & 0xFF;
|
||||
if (lastMessageId == newMessageId) {
|
||||
// Repeated message.
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||
return;
|
||||
}
|
||||
if (newMessageId < lastMessageId) {
|
||||
if (!(newMessageId < 20 && lastMessageId > 200)) {
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||
return;
|
||||
} // else assume the byte overflowed to 0.
|
||||
}
|
||||
|
||||
+21
-22
@@ -15,16 +15,16 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntStartupMessage;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.dsi.ant.AntDefine;
|
||||
import com.dsi.ant.AntInterface;
|
||||
import com.dsi.ant.AntInterfaceIntent;
|
||||
import com.dsi.ant.AntMesg;
|
||||
import com.dsi.ant.exception.AntInterfaceException;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.apps.mytracks.content.Sensor.SensorDataSet;
|
||||
import com.google.android.apps.mytracks.services.sensors.ant.AntStartupMessage;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
@@ -84,7 +84,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String antAction = intent.getAction();
|
||||
Log.i(MyTracksConstants.TAG, "enter status onReceive" + antAction);
|
||||
Log.i(TAG, "enter status onReceive" + antAction);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -93,12 +93,12 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String antAction = intent.getAction();
|
||||
Log.i(MyTracksConstants.TAG, "enter data onReceive" + antAction);
|
||||
Log.i(TAG, "enter data onReceive" + antAction);
|
||||
|
||||
if (antAction.equals(AntInterfaceIntent.ANT_RX_MESSAGE_ACTION)) {
|
||||
byte[] antMessage = intent.getByteArrayExtra(AntInterfaceIntent.ANT_MESSAGE);
|
||||
if (DEBUGGING) {
|
||||
Log.d(MyTracksConstants.TAG, "Received RX message " + messageToString(antMessage));
|
||||
Log.d(TAG, "Received RX message " + messageToString(antMessage));
|
||||
}
|
||||
|
||||
handleMessage(antMessage);
|
||||
@@ -119,7 +119,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
|
||||
@Override
|
||||
public void onServiceDisconnected() {
|
||||
Log.d(MyTracksConstants.TAG, "ANT interface reports disconnection");
|
||||
Log.d(TAG, "ANT interface reports disconnection");
|
||||
}
|
||||
};
|
||||
|
||||
@@ -129,14 +129,14 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Log.i(MyTracksConstants.TAG, "destroying AntSensorManager");
|
||||
Log.i(TAG, "destroying AntSensorManager");
|
||||
context.unregisterReceiver(statusReceiver);
|
||||
context.unregisterReceiver(dataReceiver);
|
||||
|
||||
try {
|
||||
antReceiver.releaseInterface();
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "failed to release ANT interface", e);
|
||||
Log.e(TAG, "failed to release ANT interface", e);
|
||||
}
|
||||
|
||||
antReceiver.destroy();
|
||||
@@ -177,7 +177,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
antReceiver = AntInterface.getInstance(context, antServiceListener);
|
||||
|
||||
if (antReceiver == null) {
|
||||
Log.e(MyTracksConstants.TAG, "Failed to get ANT Receiver");
|
||||
Log.e(TAG, "Failed to get ANT Receiver");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -190,11 +190,11 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
* to initiate any ANT commands.
|
||||
*/
|
||||
private synchronized void serviceConnected() {
|
||||
Log.d(MyTracksConstants.TAG, "ANT service connected");
|
||||
Log.d(TAG, "ANT service connected");
|
||||
|
||||
try {
|
||||
if (!antReceiver.claimInterface()) {
|
||||
Log.e(MyTracksConstants.TAG, "failed to claim ANT interface");
|
||||
Log.e(TAG, "failed to claim ANT interface");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -202,14 +202,14 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
// Make sure not to call AntInterface.enable() again, if it has been
|
||||
// already called before
|
||||
if (antInterrupted == false) {
|
||||
Log.i(MyTracksConstants.TAG, "Powering on Radio");
|
||||
Log.i(TAG, "Powering on Radio");
|
||||
antReceiver.enable();
|
||||
}
|
||||
} else {
|
||||
Log.i(MyTracksConstants.TAG, "Radio already enabled");
|
||||
Log.i(TAG, "Radio already enabled");
|
||||
}
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "failed to enable ANT", e);
|
||||
Log.e(TAG, "failed to enable ANT", e);
|
||||
}
|
||||
|
||||
try {
|
||||
@@ -220,7 +220,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
// that message.
|
||||
antReceiver.ANTResetSystem();
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "failed to reset ANT (expected exception)", e);
|
||||
Log.e(TAG, "failed to reset ANT (expected exception)", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
protected void handleMessage(byte[] antMessage) {
|
||||
int len = antMessage[0];
|
||||
if (len != antMessage.length - 2 || antMessage.length <= 2) {
|
||||
Log.e(MyTracksConstants.TAG, "Invalid message: " + messageToString(antMessage));
|
||||
Log.e(TAG, "Invalid message: " + messageToString(antMessage));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,8 +253,7 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
*/
|
||||
protected boolean handleMessage(byte messageId, byte[] messageData) {
|
||||
if (messageId == AntMesg.MESG_STARTUP_MESG_ID) {
|
||||
Log.d(MyTracksConstants.TAG, String.format(
|
||||
"Received startup message (reason %02x); initializing channel",
|
||||
Log.d(TAG, String.format("Received startup message (reason %02x); initializing channel",
|
||||
new AntStartupMessage(messageData).getMessage()));
|
||||
setupAntSensorChannels();
|
||||
return true;
|
||||
@@ -305,13 +304,13 @@ public abstract class AntSensorManager extends SensorManager {
|
||||
return true;
|
||||
|
||||
} catch (AntInterfaceException e) {
|
||||
Log.e(MyTracksConstants.TAG, "failed to setup ANT channel", e);
|
||||
Log.e(TAG, "failed to setup ANT channel", e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void registerForAntIntents() {
|
||||
Log.i(MyTracksConstants.TAG, "Registering for ant intents.");
|
||||
Log.i(TAG, "Registering for ant intents.");
|
||||
// Register for ANT intent broadcasts.
|
||||
IntentFilter statusIntentFilter = new IntentFilter();
|
||||
statusIntentFilter.addAction(AntInterfaceIntent.ANT_ENABLED_ACTION);
|
||||
|
||||
+26
-27
@@ -16,7 +16,8 @@
|
||||
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
@@ -85,7 +86,7 @@ public class BluetoothConnectionManager {
|
||||
*/
|
||||
private synchronized void setState(Sensor.SensorState state) {
|
||||
// TODO pretty print this.
|
||||
Log.d(MyTracksConstants.TAG, "setState(" + state + ")");
|
||||
Log.d(TAG, "setState(" + state + ")");
|
||||
this.state = state;
|
||||
|
||||
// Give the new state to the Handler so the UI Activity can update
|
||||
@@ -104,7 +105,7 @@ public class BluetoothConnectionManager {
|
||||
* in listening (server) mode. Called by the Activity onResume()
|
||||
*/
|
||||
public synchronized void start() {
|
||||
Log.d(MyTracksConstants.TAG, "BluetoothConnectionManager.start()");
|
||||
Log.d(TAG, "BluetoothConnectionManager.start()");
|
||||
|
||||
// Cancel any thread attempting to make a connection
|
||||
if (connectThread != null) {
|
||||
@@ -127,7 +128,7 @@ public class BluetoothConnectionManager {
|
||||
* @param device The BluetoothDevice to connect
|
||||
*/
|
||||
public synchronized void connect(BluetoothDevice device) {
|
||||
Log.d(MyTracksConstants.TAG, "connect to: " + device);
|
||||
Log.d(TAG, "connect to: " + device);
|
||||
|
||||
// Cancel any thread attempting to make a connection
|
||||
if (state == Sensor.SensorState.CONNECTING) {
|
||||
@@ -157,7 +158,7 @@ public class BluetoothConnectionManager {
|
||||
*/
|
||||
public synchronized void connected(BluetoothSocket socket,
|
||||
BluetoothDevice device) {
|
||||
Log.d(MyTracksConstants.TAG, "connected");
|
||||
Log.d(TAG, "connected");
|
||||
|
||||
// Cancel the thread that completed the connection
|
||||
if (connectThread != null) {
|
||||
@@ -189,7 +190,7 @@ public class BluetoothConnectionManager {
|
||||
* Stop all threads
|
||||
*/
|
||||
public synchronized void stop() {
|
||||
Log.d(MyTracksConstants.TAG, "stop()");
|
||||
Log.d(TAG, "stop()");
|
||||
if (connectThread != null) {
|
||||
connectThread.cancel();
|
||||
connectThread = null;
|
||||
@@ -226,7 +227,7 @@ public class BluetoothConnectionManager {
|
||||
*/
|
||||
private void connectionFailed() {
|
||||
setState(Sensor.SensorState.DISCONNECTED);
|
||||
Log.i(MyTracksConstants.TAG, "Bluetooth connection failed.");
|
||||
Log.i(TAG, "Bluetooth connection failed.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -234,7 +235,7 @@ public class BluetoothConnectionManager {
|
||||
*/
|
||||
private void connectionLost() {
|
||||
setState(Sensor.SensorState.DISCONNECTED);
|
||||
Log.i(MyTracksConstants.TAG, "Bluetooth connection lost.");
|
||||
Log.i(TAG, "Bluetooth connection lost.");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -255,7 +256,7 @@ public class BluetoothConnectionManager {
|
||||
try {
|
||||
tmp = getSocket();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "create() failed", e);
|
||||
Log.e(TAG, "create() failed", e);
|
||||
}
|
||||
socket = tmp;
|
||||
}
|
||||
@@ -268,22 +269,22 @@ public class BluetoothConnectionManager {
|
||||
insecure.setAccessible(true);
|
||||
return (BluetoothSocket) insecure.invoke(device, 1);
|
||||
} catch (SecurityException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get insecure connect.", e);
|
||||
Log.e(TAG, "Unable to get insecure connect.", e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get insecure connect.", e);
|
||||
Log.e(TAG, "Unable to get insecure connect.", e);
|
||||
} catch (IllegalArgumentException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get insecure connect.", e);
|
||||
Log.e(TAG, "Unable to get insecure connect.", e);
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get insecure connect.", e);
|
||||
Log.e(TAG, "Unable to get insecure connect.", e);
|
||||
} catch (InvocationTargetException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Unable to get insecure connect.", e);
|
||||
Log.e(TAG, "Unable to get insecure connect.", e);
|
||||
}
|
||||
return device.createRfcommSocketToServiceRecord(SPP_UUID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d(MyTracksConstants.TAG, "BEGIN mConnectThread");
|
||||
Log.d(TAG, "BEGIN mConnectThread");
|
||||
|
||||
// Always cancel discovery because it will slow down a connection
|
||||
adapter.cancelDiscovery();
|
||||
@@ -299,8 +300,7 @@ public class BluetoothConnectionManager {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e2) {
|
||||
Log.e(MyTracksConstants.TAG,
|
||||
"unable to close() socket during connection failure", e2);
|
||||
Log.e(TAG, "unable to close() socket during connection failure", e2);
|
||||
}
|
||||
// Start the service over to restart listening mode
|
||||
BluetoothConnectionManager.this.start();
|
||||
@@ -320,7 +320,7 @@ public class BluetoothConnectionManager {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "close() of connect socket failed", e);
|
||||
Log.e(TAG, "close() of connect socket failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -335,7 +335,7 @@ public class BluetoothConnectionManager {
|
||||
private final OutputStream mmOutStream;
|
||||
|
||||
public ConnectedThread(BluetoothSocket socket) {
|
||||
Log.d(MyTracksConstants.TAG, "create ConnectedThread");
|
||||
Log.d(TAG, "create ConnectedThread");
|
||||
btSocket = socket;
|
||||
InputStream tmpIn = null;
|
||||
OutputStream tmpOut = null;
|
||||
@@ -345,7 +345,7 @@ public class BluetoothConnectionManager {
|
||||
tmpIn = socket.getInputStream();
|
||||
tmpOut = socket.getOutputStream();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "temp sockets not created", e);
|
||||
Log.e(TAG, "temp sockets not created", e);
|
||||
}
|
||||
|
||||
mmInStream = tmpIn;
|
||||
@@ -354,7 +354,7 @@ public class BluetoothConnectionManager {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(MyTracksConstants.TAG, "BEGIN mConnectedThread");
|
||||
Log.i(TAG, "BEGIN mConnectedThread");
|
||||
byte[] buffer = new byte[parser.getFrameSize()];
|
||||
int bytes;
|
||||
int offset = 0;
|
||||
@@ -383,11 +383,10 @@ public class BluetoothConnectionManager {
|
||||
// re-align
|
||||
offset = parser.getFrameSize() - index;
|
||||
System.arraycopy(buffer, index, buffer, 0, offset);
|
||||
Log.w(MyTracksConstants.TAG, "Misaligned data, found new message at " +
|
||||
index + " recovering...");
|
||||
Log.w(TAG, "Misaligned data, found new message at " + index + " recovering...");
|
||||
continue;
|
||||
}
|
||||
Log.w(MyTracksConstants.TAG, "Could not find valid data, dropping data");
|
||||
Log.w(TAG, "Could not find valid data, dropping data");
|
||||
offset = 0;
|
||||
continue;
|
||||
}
|
||||
@@ -398,7 +397,7 @@ public class BluetoothConnectionManager {
|
||||
handler.obtainMessage(MESSAGE_READ, bytes, -1, buffer)
|
||||
.sendToTarget();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "disconnected", e);
|
||||
Log.e(TAG, "disconnected", e);
|
||||
connectionLost();
|
||||
break;
|
||||
}
|
||||
@@ -417,7 +416,7 @@ public class BluetoothConnectionManager {
|
||||
// Share the sent message back to the UI Activity
|
||||
handler.obtainMessage(MESSAGE_WRITE, -1, -1, buffer).sendToTarget();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "Exception during write", e);
|
||||
Log.e(TAG, "Exception during write", e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,7 +424,7 @@ public class BluetoothConnectionManager {
|
||||
try {
|
||||
btSocket.close();
|
||||
} catch (IOException e) {
|
||||
Log.e(MyTracksConstants.TAG, "close() of connect socket failed", e);
|
||||
Log.e(TAG, "close() of connect socket failed", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+11
-11
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
@@ -50,7 +51,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
private Sensor.SensorDataSet sensorDataSet = null;
|
||||
|
||||
private MessageParser parser;
|
||||
|
||||
|
||||
public BluetoothSensorManager(
|
||||
Context context, MessageParser parser) {
|
||||
this.context = context;
|
||||
@@ -66,7 +67,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
}
|
||||
|
||||
private void setupSensor() {
|
||||
Log.d(MyTracksConstants.TAG, "setupSensor()");
|
||||
Log.d(TAG, "setupSensor()");
|
||||
|
||||
// Initialize the BluetoothSensorAdapter to perform bluetooth connections.
|
||||
connectionManager = new BluetoothConnectionManager(messageHandler, parser);
|
||||
@@ -78,7 +79,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
|
||||
public void setupChannel() {
|
||||
if (!isEnabled() || connectionManager == null) {
|
||||
Log.w(MyTracksConstants.TAG, "Disabled manager onStartTrack");
|
||||
Log.w(TAG, "Disabled manager onStartTrack");
|
||||
return;
|
||||
}
|
||||
SharedPreferences prefs =
|
||||
@@ -88,7 +89,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
if (address == null) {
|
||||
return;
|
||||
}
|
||||
Log.w(MyTracksConstants.TAG, "Connecting to bluetooth sensor: " + address);
|
||||
Log.w(TAG, "Connecting to bluetooth sensor: " + address);
|
||||
// Get the BluetoothDevice object
|
||||
BluetoothDevice device = bluetoothAdapter.getRemoteDevice(address);
|
||||
// Attempt to connect to the device
|
||||
@@ -102,7 +103,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
// already
|
||||
if (connectionManager.getState() == Sensor.SensorState.NONE) {
|
||||
// Start the Bluetooth sensor services
|
||||
Log.w(MyTracksConstants.TAG, "Disabled manager onStartTrack");
|
||||
Log.w(TAG, "Disabled manager onStartTrack");
|
||||
connectionManager.start();
|
||||
}
|
||||
}
|
||||
@@ -132,7 +133,7 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
switch (msg.what) {
|
||||
case BluetoothConnectionManager.MESSAGE_STATE_CHANGE:
|
||||
// TODO should we update the SensorManager state var?
|
||||
Log.i(MyTracksConstants.TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
|
||||
Log.i(TAG, "MESSAGE_STATE_CHANGE: " + msg.arg1);
|
||||
break;
|
||||
case BluetoothConnectionManager.MESSAGE_WRITE:
|
||||
break;
|
||||
@@ -141,15 +142,14 @@ public class BluetoothSensorManager extends SensorManager {
|
||||
try {
|
||||
readBuf = (byte[]) msg.obj;
|
||||
sensorDataSet = parser.parseBuffer(readBuf);
|
||||
Log.d(MyTracksConstants.TAG, "MESSAGE_READ: " + sensorDataSet.toString());
|
||||
Log.d(TAG, "MESSAGE_READ: " + sensorDataSet.toString());
|
||||
} catch (IllegalArgumentException iae) {
|
||||
sensorDataSet = null;
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"Got bad sensor data: " + new String(readBuf, 0, readBuf.length),
|
||||
Log.i(TAG, "Got bad sensor data: " + new String(readBuf, 0, readBuf.length),
|
||||
iae);
|
||||
} catch (RuntimeException re) {
|
||||
sensorDataSet = null;
|
||||
Log.i(MyTracksConstants.TAG, "Unexpected exception on read.", re);
|
||||
Log.i(TAG, "Unexpected exception on read.", re);
|
||||
}
|
||||
break;
|
||||
case BluetoothConnectionManager.MESSAGE_DEVICE_NAME:
|
||||
|
||||
@@ -15,13 +15,14 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
/**
|
||||
* Manage the connection to a sensor.
|
||||
@@ -50,19 +51,17 @@ public abstract class SensorManager {
|
||||
private TimerTask checkSensorManager = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"SensorManager state: " + getSensorState());
|
||||
Log.i(TAG, "SensorManager state: " + getSensorState());
|
||||
switch (getSensorState()) {
|
||||
case CONNECTING:
|
||||
long age = System.currentTimeMillis() - getSensorStateTimestamp();
|
||||
if (age > 2 * RETRY_PERIOD) {
|
||||
Log.i(MyTracksConstants.TAG, "Retrying connecting SensorManager.");
|
||||
Log.i(TAG, "Retrying connecting SensorManager.");
|
||||
setupChannel();
|
||||
}
|
||||
break;
|
||||
case DISCONNECTED:
|
||||
Log.i(MyTracksConstants.TAG,
|
||||
"Re-registering disconnected SensoManager.");
|
||||
Log.i(TAG, "Re-registering disconnected SensorManager.");
|
||||
setupChannel();
|
||||
break;
|
||||
}
|
||||
|
||||
+9
-10
@@ -1,12 +1,12 @@
|
||||
/*
|
||||
* Copyright 2009 Google Inc.
|
||||
*
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||
* use this file except in compliance with the License. You may obtain a copy of
|
||||
* the License at
|
||||
*
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
@@ -15,7 +15,8 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksSettings;
|
||||
import com.google.android.maps.mytracks.R;
|
||||
|
||||
@@ -29,9 +30,7 @@ import android.util.Log;
|
||||
* @author Sandor Dornbush
|
||||
*/
|
||||
public class SensorManagerFactory {
|
||||
|
||||
private SensorManagerFactory() {
|
||||
}
|
||||
private SensorManagerFactory() {}
|
||||
|
||||
/**
|
||||
* Get a new sensor manager.
|
||||
@@ -44,9 +43,9 @@ public class SensorManagerFactory {
|
||||
if (prefs == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
String sensor = prefs.getString(context.getString(R.string.sensor_type_key), null);
|
||||
Log.i(MyTracksConstants.TAG, "Creating sensor of type: " + sensor);
|
||||
Log.i(TAG, "Creating sensor of type: " + sensor);
|
||||
|
||||
if (sensor == null) {
|
||||
return null;
|
||||
@@ -57,7 +56,7 @@ public class SensorManagerFactory {
|
||||
} else if (sensor.equals(context.getString(R.string.zephyr_sensor_type))) {
|
||||
return new ZephyrSensorManager(context);
|
||||
} else {
|
||||
Log.w(MyTracksConstants.TAG, "Unable to find sensor type: " + sensor);
|
||||
Log.w(TAG, "Unable to find sensor type: " + sensor);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+5
-4
@@ -15,11 +15,12 @@
|
||||
*/
|
||||
package com.google.android.apps.mytracks.services.sensors;
|
||||
|
||||
import android.util.Log;
|
||||
import static com.google.android.apps.mytracks.MyTracksConstants.TAG;
|
||||
|
||||
import com.google.android.apps.mytracks.MyTracksConstants;
|
||||
import com.google.android.apps.mytracks.content.Sensor;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* An implementation of a SensorData parser for Zephyr HRM.
|
||||
*
|
||||
@@ -33,7 +34,7 @@ public class ZephyrMessageParser implements MessageParser {
|
||||
for (int i = 0; i < buffer.length; i++) {
|
||||
sb.append(String.format("%02X", buffer[i]));
|
||||
}
|
||||
Log.w(MyTracksConstants.TAG, "Got zephyr data: " + sb);
|
||||
Log.w(TAG, "Got zephyr data: " + sb);
|
||||
// The provided units are 1/16 strides per minute.
|
||||
// TODO: Fix the cadence calculation.
|
||||
// int cadence = SensorUtils.unsignedShortToInt(buffer, 56);
|
||||
@@ -49,7 +50,7 @@ public class ZephyrMessageParser implements MessageParser {
|
||||
.setCreationTime(System.currentTimeMillis())
|
||||
.setHeartRate(b)
|
||||
.build();
|
||||
|
||||
|
||||
return sds;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user