mirror of
https://github.com/oliexdev/openScale.git
synced 2025-08-21 07:51:46 +02:00
Improve bluetooth debug logging
This commit is contained in:
@@ -111,7 +111,7 @@ public abstract class BluetoothCommunication {
|
|||||||
* @param msg the string id to be send
|
* @param msg the string id to be send
|
||||||
* @param value the value to be used
|
* @param value the value to be used
|
||||||
*/
|
*/
|
||||||
protected void sendMessage(int msg, Object value) {
|
protected void sendMessage(int msg, Object value) {
|
||||||
callbackBtHandler.obtainMessage(BT_STATUS_CODE.BT_SCALE_MESSAGE.ordinal(), msg, 0, value).sendToTarget();
|
callbackBtHandler.obtainMessage(BT_STATUS_CODE.BT_SCALE_MESSAGE.ordinal(), msg, 0, value).sendToTarget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,6 +240,8 @@ public abstract class BluetoothCommunication {
|
|||||||
* @param characteristic the Bluetooth UUID characteristic
|
* @param characteristic the Bluetooth UUID characteristic
|
||||||
*/
|
*/
|
||||||
protected void setIndicationOn(UUID service, UUID characteristic, UUID descriptor) {
|
protected void setIndicationOn(UUID service, UUID characteristic, UUID descriptor) {
|
||||||
|
Timber.d("Set indication on for %s", characteristic);
|
||||||
|
|
||||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||||
.getCharacteristic(characteristic);
|
.getCharacteristic(characteristic);
|
||||||
|
|
||||||
@@ -260,6 +262,8 @@ public abstract class BluetoothCommunication {
|
|||||||
* @param characteristic the Bluetooth UUID characteristic
|
* @param characteristic the Bluetooth UUID characteristic
|
||||||
*/
|
*/
|
||||||
protected void setNotificationOn(UUID service, UUID characteristic, UUID descriptor) {
|
protected void setNotificationOn(UUID service, UUID characteristic, UUID descriptor) {
|
||||||
|
Timber.d("Set notification on for %s", characteristic);
|
||||||
|
|
||||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||||
.getCharacteristic(characteristic);
|
.getCharacteristic(characteristic);
|
||||||
|
|
||||||
@@ -280,6 +284,8 @@ public abstract class BluetoothCommunication {
|
|||||||
* @param characteristic the Bluetooth UUID characteristic
|
* @param characteristic the Bluetooth UUID characteristic
|
||||||
*/
|
*/
|
||||||
protected void setNotificationOff(UUID service, UUID characteristic, UUID descriptor) {
|
protected void setNotificationOff(UUID service, UUID characteristic, UUID descriptor) {
|
||||||
|
Timber.d("Set notification off for %s", characteristic);
|
||||||
|
|
||||||
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
BluetoothGattCharacteristic gattCharacteristic = bluetoothGatt.getService(service)
|
||||||
.getCharacteristic(characteristic);
|
.getCharacteristic(characteristic);
|
||||||
|
|
||||||
@@ -305,7 +311,7 @@ public abstract class BluetoothCommunication {
|
|||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
final StringBuilder stringBuilder = new StringBuilder(data.length);
|
final StringBuilder stringBuilder = new StringBuilder(3 * data.length);
|
||||||
for (byte byteChar : data) {
|
for (byte byteChar : data) {
|
||||||
stringBuilder.append(String.format("%02X ", byteChar));
|
stringBuilder.append(String.format("%02X ", byteChar));
|
||||||
}
|
}
|
||||||
@@ -341,6 +347,8 @@ public abstract class BluetoothCommunication {
|
|||||||
* @param hwAddress the Bluetooth address to connect to
|
* @param hwAddress the Bluetooth address to connect to
|
||||||
*/
|
*/
|
||||||
public void connect(String hwAddress) {
|
public void connect(String hwAddress) {
|
||||||
|
Timber.i("Connecting to [%s] (driver: %s)", hwAddress, driverName());
|
||||||
|
|
||||||
btAdapter.cancelDiscovery();
|
btAdapter.cancelDiscovery();
|
||||||
|
|
||||||
// Don't do any cleanup if disconnected before fully connected
|
// Don't do any cleanup if disconnected before fully connected
|
||||||
@@ -358,6 +366,8 @@ public abstract class BluetoothCommunication {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Timber.i("Disconnecting%s", doCleanup ? " (with cleanup)" : "");
|
||||||
|
|
||||||
if (doCleanup) {
|
if (doCleanup) {
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
if (btMachineState != BT_MACHINE_STATE.BT_CLEANUP_STATE) {
|
if (btMachineState != BT_MACHINE_STATE.BT_CLEANUP_STATE) {
|
||||||
@@ -378,7 +388,7 @@ public abstract class BluetoothCommunication {
|
|||||||
protected void nextMachineStateStep() {
|
protected void nextMachineStateStep() {
|
||||||
switch (btMachineState) {
|
switch (btMachineState) {
|
||||||
case BT_INIT_STATE:
|
case BT_INIT_STATE:
|
||||||
Timber.d("INIT STATE: " + initStepNr);
|
Timber.d("INIT STATE: %d", initStepNr);
|
||||||
if (!nextInitCmd(initStepNr)) {
|
if (!nextInitCmd(initStepNr)) {
|
||||||
btMachineState = BT_MACHINE_STATE.BT_CMD_STATE;
|
btMachineState = BT_MACHINE_STATE.BT_CMD_STATE;
|
||||||
nextMachineStateStep();
|
nextMachineStateStep();
|
||||||
@@ -386,12 +396,12 @@ public abstract class BluetoothCommunication {
|
|||||||
initStepNr++;
|
initStepNr++;
|
||||||
break;
|
break;
|
||||||
case BT_CMD_STATE:
|
case BT_CMD_STATE:
|
||||||
Timber.d("CMD STATE: " + cmdStepNr);
|
Timber.d("CMD STATE: %d", cmdStepNr);
|
||||||
nextBluetoothCmd(cmdStepNr);
|
nextBluetoothCmd(cmdStepNr);
|
||||||
cmdStepNr++;
|
cmdStepNr++;
|
||||||
break;
|
break;
|
||||||
case BT_CLEANUP_STATE:
|
case BT_CLEANUP_STATE:
|
||||||
Timber.d("CLEANUP STATE: " + cleanupStepNr);
|
Timber.d("CLEANUP STATE: %d", cleanupStepNr);
|
||||||
nextCleanUpCmd(cleanupStepNr);
|
nextCleanUpCmd(cleanupStepNr);
|
||||||
cleanupStepNr++;
|
cleanupStepNr++;
|
||||||
break;
|
break;
|
||||||
@@ -408,8 +418,11 @@ public abstract class BluetoothCommunication {
|
|||||||
// handle descriptor requests first
|
// handle descriptor requests first
|
||||||
BluetoothGattDescriptor descriptorRequest = descriptorRequestQueue.poll();
|
BluetoothGattDescriptor descriptorRequest = descriptorRequestQueue.poll();
|
||||||
if (descriptorRequest != null) {
|
if (descriptorRequest != null) {
|
||||||
|
Timber.d("Write descriptor %s: %s",
|
||||||
|
descriptorRequest.getUuid(), byteInHex(descriptorRequest.getValue()));
|
||||||
if (!bluetoothGatt.writeDescriptor(descriptorRequest)) {
|
if (!bluetoothGatt.writeDescriptor(descriptorRequest)) {
|
||||||
Timber.d("Descriptor Write failed(" + byteInHex(descriptorRequest.getValue()) + ")");
|
Timber.e("Failed to initiate write of descriptor %s",
|
||||||
|
descriptorRequest.getUuid());
|
||||||
}
|
}
|
||||||
openRequest = true;
|
openRequest = true;
|
||||||
return;
|
return;
|
||||||
@@ -418,8 +431,11 @@ public abstract class BluetoothCommunication {
|
|||||||
// handle characteristics requests second
|
// handle characteristics requests second
|
||||||
BluetoothGattCharacteristic characteristicRequest = characteristicRequestQueue.poll();
|
BluetoothGattCharacteristic characteristicRequest = characteristicRequestQueue.poll();
|
||||||
if (characteristicRequest != null) {
|
if (characteristicRequest != null) {
|
||||||
|
Timber.d("Write characteristic %s: %s",
|
||||||
|
characteristicRequest.getUuid(), byteInHex(characteristicRequest.getValue()));
|
||||||
if (!bluetoothGatt.writeCharacteristic(characteristicRequest)) {
|
if (!bluetoothGatt.writeCharacteristic(characteristicRequest)) {
|
||||||
Timber.d("Characteristic Write failed(" + byteInHex(characteristicRequest.getValue()) + ")");
|
Timber.e("Failed to initiate write of characteristic %s",
|
||||||
|
characteristicRequest.getUuid());
|
||||||
}
|
}
|
||||||
openRequest = true;
|
openRequest = true;
|
||||||
return;
|
return;
|
||||||
@@ -436,6 +452,8 @@ public abstract class BluetoothCommunication {
|
|||||||
protected class GattCallback extends BluetoothGattCallback {
|
protected class GattCallback extends BluetoothGattCallback {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChange(final BluetoothGatt gatt, int status, int newState) {
|
public void onConnectionStateChange(final BluetoothGatt gatt, int status, int newState) {
|
||||||
|
Timber.d("onConnectionStateChange: status=%d, newState=%d", status, newState);
|
||||||
|
|
||||||
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
if (newState == BluetoothProfile.STATE_CONNECTED) {
|
||||||
connectionEstablished = true;
|
connectionEstablished = true;
|
||||||
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_ESTABLISHED);
|
setBtStatus(BT_STATUS_CODE.BT_CONNECTION_ESTABLISHED);
|
||||||
@@ -451,6 +469,8 @@ public abstract class BluetoothCommunication {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
|
public void onServicesDiscovered(final BluetoothGatt gatt, int status) {
|
||||||
|
Timber.d("onServicesDiscovered: status=%d", status);
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
cmdStepNr = 0;
|
cmdStepNr = 0;
|
||||||
initStepNr = 0;
|
initStepNr = 0;
|
||||||
@@ -500,6 +520,9 @@ public abstract class BluetoothCommunication {
|
|||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public void onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic,
|
BluetoothGattCharacteristic characteristic,
|
||||||
int status) {
|
int status) {
|
||||||
|
Timber.d("onCharacteristicRead %s: %s",
|
||||||
|
characteristic.getUuid(), byteInHex(characteristic.getValue()));
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
onBluetoothDataRead(gatt, characteristic, status);
|
onBluetoothDataRead(gatt, characteristic, status);
|
||||||
openRequest = false;
|
openRequest = false;
|
||||||
@@ -510,6 +533,9 @@ public abstract class BluetoothCommunication {
|
|||||||
@Override
|
@Override
|
||||||
public void onCharacteristicChanged(BluetoothGatt gatt,
|
public void onCharacteristicChanged(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic) {
|
BluetoothGattCharacteristic characteristic) {
|
||||||
|
Timber.d("onCharacteristicChanged %s: %s",
|
||||||
|
characteristic.getUuid(), byteInHex(characteristic.getValue()));
|
||||||
|
|
||||||
synchronized (lock) {
|
synchronized (lock) {
|
||||||
onBluetoothDataChange(gatt, characteristic);
|
onBluetoothDataChange(gatt, characteristic);
|
||||||
}
|
}
|
||||||
|
@@ -106,6 +106,7 @@ public class BluetoothPreferences extends PreferenceFragment {
|
|||||||
getActivity().registerReceiver(mReceiver, filter);
|
getActivity().registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
// Do classic bluetooth discovery first and BLE scan afterwards
|
// Do classic bluetooth discovery first and BLE scan afterwards
|
||||||
|
Timber.d("Start discovery");
|
||||||
btAdapter.startDiscovery();
|
btAdapter.startDiscovery();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,10 +140,13 @@ public class BluetoothPreferences extends PreferenceFragment {
|
|||||||
}
|
}
|
||||||
}, 10 * 1000);
|
}, 10 * 1000);
|
||||||
|
|
||||||
|
Timber.d("Start LE scan");
|
||||||
btAdapter.startLeScan(leScanCallback);
|
btAdapter.startLeScan(leScanCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void stopDiscoveryAndLeScan() {
|
private void stopDiscoveryAndLeScan() {
|
||||||
|
Timber.d("Stop discovery and LE scan");
|
||||||
|
|
||||||
if (handler != null) {
|
if (handler != null) {
|
||||||
handler.removeCallbacksAndMessages(null);
|
handler.removeCallbacksAndMessages(null);
|
||||||
handler = null;
|
handler = null;
|
||||||
@@ -171,6 +175,8 @@ public class BluetoothPreferences extends PreferenceFragment {
|
|||||||
|
|
||||||
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getActivity(), device.getName());
|
BluetoothCommunication btDevice = BluetoothFactory.createDeviceDriver(getActivity(), device.getName());
|
||||||
if (btDevice != null) {
|
if (btDevice != null) {
|
||||||
|
Timber.d("Found supported device '%s' (driver: %s, type: %d) [%s]",
|
||||||
|
device.getName(), btDevice.driverName(), device.getType(), device.getAddress());
|
||||||
prefBtDevice.setOnPreferenceClickListener(new onClickListenerDeviceSelect());
|
prefBtDevice.setOnPreferenceClickListener(new onClickListenerDeviceSelect());
|
||||||
prefBtDevice.setKey(device.getAddress());
|
prefBtDevice.setKey(device.getAddress());
|
||||||
prefBtDevice.setIcon(R.drawable.ic_bluetooth_connection_lost);
|
prefBtDevice.setIcon(R.drawable.ic_bluetooth_connection_lost);
|
||||||
@@ -180,6 +186,8 @@ public class BluetoothPreferences extends PreferenceFragment {
|
|||||||
prefBtDevice.getIcon().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
|
prefBtDevice.getIcon().setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Timber.d("Found unsupported device '%s' (type: %d) [%s]",
|
||||||
|
device.getName(), device.getType(), device.getAddress());
|
||||||
prefBtDevice.setIcon(R.drawable.ic_bluetooth_disabled);
|
prefBtDevice.setIcon(R.drawable.ic_bluetooth_disabled);
|
||||||
prefBtDevice.setSummary(R.string.label_bt_device_no_support);
|
prefBtDevice.setSummary(R.string.label_bt_device_no_support);
|
||||||
prefBtDevice.setEnabled(false);
|
prefBtDevice.setEnabled(false);
|
||||||
|
Reference in New Issue
Block a user