forked from upstream-mirrors/OpenTracks
Constants.TAG -> TAG
This commit is contained in:
+17
-22
@@ -15,14 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.services.sensors.ant;
|
package com.google.android.apps.mytracks.services.sensors.ant;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||||
import com.google.android.apps.mytracks.content.Sensor;
|
|
||||||
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
|
|
||||||
import com.google.android.maps.mytracks.R;
|
|
||||||
|
|
||||||
import com.dsi.ant.AntDefine;
|
import com.dsi.ant.AntDefine;
|
||||||
import com.dsi.ant.AntMesg;
|
import com.dsi.ant.AntMesg;
|
||||||
import com.dsi.ant.exception.AntInterfaceException;
|
import com.dsi.ant.exception.AntInterfaceException;
|
||||||
|
import com.google.android.apps.mytracks.Constants;
|
||||||
|
import com.google.android.apps.mytracks.content.Sensor;
|
||||||
|
import com.google.android.apps.mytracks.services.sensors.SensorUtils;
|
||||||
|
import com.google.android.maps.mytracks.R;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
@@ -85,7 +86,7 @@ public class AntSRMSensorManager extends AntSensorManager {
|
|||||||
byte recievedChannel = (byte) (antMessage[AntMesg.MESG_DATA_OFFSET]
|
byte recievedChannel = (byte) (antMessage[AntMesg.MESG_DATA_OFFSET]
|
||||||
& AntDefine.CHANNEL_NUMBER_MASK);
|
& AntDefine.CHANNEL_NUMBER_MASK);
|
||||||
if (recievedChannel != channel) {
|
if (recievedChannel != channel) {
|
||||||
Log.d(Constants.TAG, "Unexpected channel: " + recievedChannel);
|
Log.d(TAG, "Unexpected channel: " + recievedChannel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
switch (antMessage[AntMesg.MESG_ID_OFFSET]) {
|
switch (antMessage[AntMesg.MESG_ID_OFFSET]) {
|
||||||
@@ -99,18 +100,17 @@ public class AntSRMSensorManager extends AntSensorManager {
|
|||||||
handleChannelId(antMessage);
|
handleChannelId(antMessage);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e(Constants.TAG,
|
Log.e(TAG, "Unexpected message id: " + antMessage[3]);
|
||||||
"Unexpected message id: " + antMessage[3]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleBroadcastData(byte[] antMessage) {
|
private void handleBroadcastData(byte[] antMessage) {
|
||||||
if (deviceId == WILDCARD) {
|
if (deviceId == WILDCARD) {
|
||||||
try {
|
try {
|
||||||
Log.d(Constants.TAG, "Requesting channel id id.");
|
Log.d(TAG, "Requesting channel id id.");
|
||||||
getAntReceiver().ANTRequestMessage(channel, AntMesg.MESG_CHANNEL_ID_ID);
|
getAntReceiver().ANTRequestMessage(channel, AntMesg.MESG_CHANNEL_ID_ID);
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.TAG, "Failed to request channel id id", e);
|
Log.e(TAG, "Failed to request channel id id", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setSensorState(Sensor.SensorState.CONNECTED);
|
setSensorState(Sensor.SensorState.CONNECTED);
|
||||||
@@ -122,15 +122,14 @@ public class AntSRMSensorManager extends AntSensorManager {
|
|||||||
parseSensorData(antMessage);
|
parseSensorData(antMessage);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.e(Constants.TAG,
|
Log.e(TAG, "Unexpected message type: " + antMessage[MESSAGE_TYPE_INDEX]);
|
||||||
"Unexpected message type: " + antMessage[MESSAGE_TYPE_INDEX]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void handleChannelId(byte[] antMessage) {
|
private void handleChannelId(byte[] antMessage) {
|
||||||
// Store the device id.
|
// Store the device id.
|
||||||
deviceId = antMessage[3];
|
deviceId = antMessage[3];
|
||||||
Log.i(Constants.TAG, "Found device id: " + deviceId);
|
Log.i(TAG, "Found device id: " + deviceId);
|
||||||
|
|
||||||
SharedPreferences prefs = context.getSharedPreferences(
|
SharedPreferences prefs = context.getSharedPreferences(
|
||||||
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
Constants.SETTINGS_NAME, Context.MODE_PRIVATE);
|
||||||
@@ -143,38 +142,34 @@ public class AntSRMSensorManager extends AntSensorManager {
|
|||||||
if (antMessage[3] == AntMesg.MESG_EVENT_ID
|
if (antMessage[3] == AntMesg.MESG_EVENT_ID
|
||||||
&& antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
|
&& antMessage[4] == AntDefine.EVENT_RX_SEARCH_TIMEOUT) {
|
||||||
// Search timeout
|
// Search timeout
|
||||||
Log.w(Constants.TAG, "Search timed out. Unassigning channel.");
|
Log.w(TAG, "Search timed out. Unassigning channel.");
|
||||||
try {
|
try {
|
||||||
getAntReceiver().ANTUnassignChannel(channel);
|
getAntReceiver().ANTUnassignChannel(channel);
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.TAG, "Failed to unassign ANT channel", e);
|
Log.e(TAG, "Failed to unassign ANT channel", e);
|
||||||
}
|
}
|
||||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||||
} else if (antMessage[3] == AntMesg.MESG_UNASSIGN_CHANNEL_ID) {
|
} else if (antMessage[3] == AntMesg.MESG_UNASSIGN_CHANNEL_ID) {
|
||||||
setSensorState(Sensor.SensorState.DISCONNECTED);
|
setSensorState(Sensor.SensorState.DISCONNECTED);
|
||||||
Log.i(Constants.TAG,
|
Log.i(TAG, "Disconnected from the sensor: " + getSensorState());
|
||||||
"Disconnected from the sensor: " + getSensorState());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void parseSensorData(byte[] antMessage) {
|
private void parseSensorData(byte[] antMessage) {
|
||||||
if (antMessage.length != 11) {
|
if (antMessage.length != 11) {
|
||||||
Log.e(Constants.TAG,
|
Log.e(TAG, "Unexpected ant message length: " + antMessage.length);
|
||||||
"Unexpected ant message length: " + antMessage.length);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int newMessageId = antMessage[MESSAGE_ID_INDEX] & 0xFF;
|
int newMessageId = antMessage[MESSAGE_ID_INDEX] & 0xFF;
|
||||||
if (lastMessageId == newMessageId) {
|
if (lastMessageId == newMessageId) {
|
||||||
// Repeated message.
|
// Repeated message.
|
||||||
Log.i(Constants.TAG,
|
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||||
String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (newMessageId < lastMessageId) {
|
if (newMessageId < lastMessageId) {
|
||||||
if (!(newMessageId < 20 && lastMessageId > 200)) {
|
if (!(newMessageId < 20 && lastMessageId > 200)) {
|
||||||
Log.i(Constants.TAG,
|
Log.i(TAG, String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
||||||
String.format("SRM ignoring repeat: 0x%X", newMessageId));
|
|
||||||
return;
|
return;
|
||||||
} // else assume the byte overflowed to 0.
|
} // else assume the byte overflowed to 0.
|
||||||
}
|
}
|
||||||
|
|||||||
+21
-21
@@ -15,16 +15,16 @@
|
|||||||
*/
|
*/
|
||||||
package com.google.android.apps.mytracks.services.sensors.ant;
|
package com.google.android.apps.mytracks.services.sensors.ant;
|
||||||
|
|
||||||
import com.google.android.apps.mytracks.Constants;
|
import static com.google.android.apps.mytracks.Constants.TAG;
|
||||||
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.SensorManager;
|
|
||||||
|
|
||||||
import com.dsi.ant.AntDefine;
|
import com.dsi.ant.AntDefine;
|
||||||
import com.dsi.ant.AntInterface;
|
import com.dsi.ant.AntInterface;
|
||||||
import com.dsi.ant.AntInterfaceIntent;
|
import com.dsi.ant.AntInterfaceIntent;
|
||||||
import com.dsi.ant.AntMesg;
|
import com.dsi.ant.AntMesg;
|
||||||
import com.dsi.ant.exception.AntInterfaceException;
|
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.SensorManager;
|
||||||
|
|
||||||
import android.content.BroadcastReceiver;
|
import android.content.BroadcastReceiver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -84,7 +84,7 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String antAction = intent.getAction();
|
String antAction = intent.getAction();
|
||||||
Log.i(Constants.TAG, "enter status onReceive" + antAction);
|
Log.i(TAG, "enter status onReceive" + antAction);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -93,12 +93,12 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
String antAction = intent.getAction();
|
String antAction = intent.getAction();
|
||||||
Log.i(Constants.TAG, "enter data onReceive" + antAction);
|
Log.i(TAG, "enter data onReceive" + antAction);
|
||||||
|
|
||||||
if (antAction.equals(AntInterfaceIntent.ANT_RX_MESSAGE_ACTION)) {
|
if (antAction.equals(AntInterfaceIntent.ANT_RX_MESSAGE_ACTION)) {
|
||||||
byte[] antMessage = intent.getByteArrayExtra(AntInterfaceIntent.ANT_MESSAGE);
|
byte[] antMessage = intent.getByteArrayExtra(AntInterfaceIntent.ANT_MESSAGE);
|
||||||
if (DEBUGGING) {
|
if (DEBUGGING) {
|
||||||
Log.d(Constants.TAG, "Received RX message " + messageToString(antMessage));
|
Log.d(TAG, "Received RX message " + messageToString(antMessage));
|
||||||
}
|
}
|
||||||
|
|
||||||
handleMessage(antMessage);
|
handleMessage(antMessage);
|
||||||
@@ -119,7 +119,7 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServiceDisconnected() {
|
public void onServiceDisconnected() {
|
||||||
Log.d(Constants.TAG, "ANT interface reports disconnection");
|
Log.d(TAG, "ANT interface reports disconnection");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -129,14 +129,14 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
Log.i(Constants.TAG, "destroying AntSensorManager");
|
Log.i(TAG, "destroying AntSensorManager");
|
||||||
context.unregisterReceiver(statusReceiver);
|
context.unregisterReceiver(statusReceiver);
|
||||||
context.unregisterReceiver(dataReceiver);
|
context.unregisterReceiver(dataReceiver);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
antReceiver.releaseInterface();
|
antReceiver.releaseInterface();
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.TAG, "failed to release ANT interface", e);
|
Log.e(TAG, "failed to release ANT interface", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
antReceiver.destroy();
|
antReceiver.destroy();
|
||||||
@@ -177,7 +177,7 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
antReceiver = AntInterface.getInstance(context, antServiceListener);
|
antReceiver = AntInterface.getInstance(context, antServiceListener);
|
||||||
|
|
||||||
if (antReceiver == null) {
|
if (antReceiver == null) {
|
||||||
Log.e(Constants.TAG, "Failed to get ANT Receiver");
|
Log.e(TAG, "Failed to get ANT Receiver");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -190,11 +190,11 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
* to initiate any ANT commands.
|
* to initiate any ANT commands.
|
||||||
*/
|
*/
|
||||||
private synchronized void serviceConnected() {
|
private synchronized void serviceConnected() {
|
||||||
Log.d(Constants.TAG, "ANT service connected");
|
Log.d(TAG, "ANT service connected");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!antReceiver.claimInterface()) {
|
if (!antReceiver.claimInterface()) {
|
||||||
Log.e(Constants.TAG, "failed to claim ANT interface");
|
Log.e(TAG, "failed to claim ANT interface");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,14 +202,14 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
// Make sure not to call AntInterface.enable() again, if it has been
|
// Make sure not to call AntInterface.enable() again, if it has been
|
||||||
// already called before
|
// already called before
|
||||||
if (antInterrupted == false) {
|
if (antInterrupted == false) {
|
||||||
Log.i(Constants.TAG, "Powering on Radio");
|
Log.i(TAG, "Powering on Radio");
|
||||||
antReceiver.enable();
|
antReceiver.enable();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.i(Constants.TAG, "Radio already enabled");
|
Log.i(TAG, "Radio already enabled");
|
||||||
}
|
}
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.TAG, "failed to enable ANT", e);
|
Log.e(TAG, "failed to enable ANT", e);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -220,7 +220,7 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
// that message.
|
// that message.
|
||||||
antReceiver.ANTResetSystem();
|
antReceiver.ANTResetSystem();
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.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) {
|
protected void handleMessage(byte[] antMessage) {
|
||||||
int len = antMessage[0];
|
int len = antMessage[0];
|
||||||
if (len != antMessage.length - 2 || antMessage.length <= 2) {
|
if (len != antMessage.length - 2 || antMessage.length <= 2) {
|
||||||
Log.e(Constants.TAG, "Invalid message: " + messageToString(antMessage));
|
Log.e(TAG, "Invalid message: " + messageToString(antMessage));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -253,7 +253,7 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
*/
|
*/
|
||||||
protected boolean handleMessage(byte messageId, byte[] messageData) {
|
protected boolean handleMessage(byte messageId, byte[] messageData) {
|
||||||
if (messageId == AntMesg.MESG_STARTUP_MESG_ID) {
|
if (messageId == AntMesg.MESG_STARTUP_MESG_ID) {
|
||||||
Log.d(Constants.TAG, String.format(
|
Log.d(TAG, String.format(
|
||||||
"Received startup message (reason %02x); initializing channel",
|
"Received startup message (reason %02x); initializing channel",
|
||||||
new AntStartupMessage(messageData).getMessage()));
|
new AntStartupMessage(messageData).getMessage()));
|
||||||
setupAntSensorChannels();
|
setupAntSensorChannels();
|
||||||
@@ -305,13 +305,13 @@ public abstract class AntSensorManager extends SensorManager {
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
} catch (AntInterfaceException e) {
|
} catch (AntInterfaceException e) {
|
||||||
Log.e(Constants.TAG, "failed to setup ANT channel", e);
|
Log.e(TAG, "failed to setup ANT channel", e);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerForAntIntents() {
|
private void registerForAntIntents() {
|
||||||
Log.i(Constants.TAG, "Registering for ant intents.");
|
Log.i(TAG, "Registering for ant intents.");
|
||||||
// Register for ANT intent broadcasts.
|
// Register for ANT intent broadcasts.
|
||||||
IntentFilter statusIntentFilter = new IntentFilter();
|
IntentFilter statusIntentFilter = new IntentFilter();
|
||||||
statusIntentFilter.addAction(AntInterfaceIntent.ANT_ENABLED_ACTION);
|
statusIntentFilter.addAction(AntInterfaceIntent.ANT_ENABLED_ACTION);
|
||||||
|
|||||||
Reference in New Issue
Block a user