mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-11-12 21:19:25 +01:00
Improve logging
This commit is contained in:
parent
75b9fe4c4d
commit
11884d8073
@ -215,7 +215,7 @@ public class GBDevice implements Parcelable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setBatteryLevel(short batteryLevel) {
|
public void setBatteryLevel(short batteryLevel) {
|
||||||
if (batteryLevel >= 0 && batteryLevel <= 100) {
|
if ((batteryLevel >= 0 && batteryLevel <= 100) || batteryLevel == BATTERY_UNKNOWN) {
|
||||||
mBatteryLevel = batteryLevel;
|
mBatteryLevel = batteryLevel;
|
||||||
} else {
|
} else {
|
||||||
LOG.error("Battery level musts be within range 0-100: " + batteryLevel);
|
LOG.error("Battery level musts be within range 0-100: " + batteryLevel);
|
||||||
|
@ -203,7 +203,6 @@ public final class BtLEQueue {
|
|||||||
if (!transaction.isEmpty()) {
|
if (!transaction.isEmpty()) {
|
||||||
mTransactions.add(transaction);
|
mTransactions.add(transaction);
|
||||||
}
|
}
|
||||||
LOG.debug("adding done: " + transaction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
@ -237,7 +236,7 @@ public final class BtLEQueue {
|
|||||||
private final BluetoothGattCallback internalGattCallback = new BluetoothGattCallback() {
|
private final BluetoothGattCallback internalGattCallback = new BluetoothGattCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
|
public void onConnectionStateChange(BluetoothGatt gatt, int status, int newState) {
|
||||||
LOG.debug("connection state change: status: " + status + ", newState: " + newState);
|
LOG.debug("connection state change, newState: " + newState + getStatusString(status));
|
||||||
|
|
||||||
if (!checkCorrectGattInstance(gatt, "connection state event")) {
|
if (!checkCorrectGattInstance(gatt, "connection state event")) {
|
||||||
return;
|
return;
|
||||||
@ -269,7 +268,7 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
public void onServicesDiscovered(BluetoothGatt gatt, int status) {
|
||||||
if (!checkCorrectGattInstance(gatt, "services discovered")) {
|
if (!checkCorrectGattInstance(gatt, "services discovered: " + getStatusString(status))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -285,15 +284,10 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
public void onCharacteristicWrite(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int status) {
|
||||||
LOG.debug("characteristic write: " + characteristic.getUuid());
|
LOG.debug("characteristic write: " + characteristic.getUuid() + getStatusString(status));
|
||||||
if (!checkCorrectGattInstance(gatt, "characteristic write")) {
|
if (!checkCorrectGattInstance(gatt, "characteristic write")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status == BluetoothGatt.GATT_SUCCESS) {
|
|
||||||
LOG.debug("Writing characteristic " + characteristic.getUuid() + " succeeded.");
|
|
||||||
} else {
|
|
||||||
LOG.debug("Writing characteristic " + characteristic.getUuid() + " failed: " + status);
|
|
||||||
}
|
|
||||||
if (mExternalGattCallback != null) {
|
if (mExternalGattCallback != null) {
|
||||||
mExternalGattCallback.onCharacteristicWrite(gatt, characteristic, status);
|
mExternalGattCallback.onCharacteristicWrite(gatt, characteristic, status);
|
||||||
}
|
}
|
||||||
@ -304,13 +298,10 @@ public final class BtLEQueue {
|
|||||||
public void onCharacteristicRead(BluetoothGatt gatt,
|
public void onCharacteristicRead(BluetoothGatt gatt,
|
||||||
BluetoothGattCharacteristic characteristic,
|
BluetoothGattCharacteristic characteristic,
|
||||||
int status) {
|
int status) {
|
||||||
LOG.debug("characteristic read: " + characteristic.getUuid());
|
LOG.debug("characteristic read: " + characteristic.getUuid() + getStatusString(status));
|
||||||
if (!checkCorrectGattInstance(gatt, "characteristic read")) {
|
if (!checkCorrectGattInstance(gatt, "characteristic read")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
|
||||||
LOG.error("Reading characteristic " + characteristic.getUuid() + " failed: " + status);
|
|
||||||
}
|
|
||||||
if (mExternalGattCallback != null) {
|
if (mExternalGattCallback != null) {
|
||||||
mExternalGattCallback.onCharacteristicRead(gatt, characteristic, status);
|
mExternalGattCallback.onCharacteristicRead(gatt, characteristic, status);
|
||||||
}
|
}
|
||||||
@ -319,13 +310,10 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public void onDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
LOG.debug("descriptor read: " + descriptor.getUuid());
|
LOG.debug("descriptor read: " + descriptor.getUuid() + getStatusString(status));
|
||||||
if (!checkCorrectGattInstance(gatt, "descriptor read")) {
|
if (!checkCorrectGattInstance(gatt, "descriptor read")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
|
||||||
LOG.error("Reading descriptor " + descriptor.getUuid() + " failed: " + status);
|
|
||||||
}
|
|
||||||
if (mExternalGattCallback != null) {
|
if (mExternalGattCallback != null) {
|
||||||
mExternalGattCallback.onDescriptorRead(gatt, descriptor, status);
|
mExternalGattCallback.onDescriptorRead(gatt, descriptor, status);
|
||||||
}
|
}
|
||||||
@ -334,13 +322,10 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
public void onDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, int status) {
|
||||||
LOG.debug("descriptor write: " + descriptor.getUuid());
|
LOG.debug("descriptor write: " + descriptor.getUuid() + getStatusString(status));
|
||||||
if (!checkCorrectGattInstance(gatt, "descriptor write")) {
|
if (!checkCorrectGattInstance(gatt, "descriptor write")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
|
||||||
LOG.error("Writing descriptor " + descriptor.getUuid() + " failed: " + status);
|
|
||||||
}
|
|
||||||
if (mExternalGattCallback != null) {
|
if (mExternalGattCallback != null) {
|
||||||
mExternalGattCallback.onDescriptorWrite(gatt, descriptor, status);
|
mExternalGattCallback.onDescriptorWrite(gatt, descriptor, status);
|
||||||
}
|
}
|
||||||
@ -365,7 +350,7 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
|
public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
|
||||||
LOG.debug("remote rssi: " + rssi);
|
LOG.debug("remote rssi: " + rssi + getStatusString(status));
|
||||||
if (!checkCorrectGattInstance(gatt, "remote rssi")) {
|
if (!checkCorrectGattInstance(gatt, "remote rssi")) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -380,6 +365,7 @@ public final class BtLEQueue {
|
|||||||
|
|
||||||
private void checkWaitingCharacteristic(BluetoothGattCharacteristic characteristic, int status) {
|
private void checkWaitingCharacteristic(BluetoothGattCharacteristic characteristic, int status) {
|
||||||
if (status != BluetoothGatt.GATT_SUCCESS) {
|
if (status != BluetoothGatt.GATT_SUCCESS) {
|
||||||
|
LOG.debug("failed btle action, aborting transaction: " + characteristic.getUuid() + getStatusString(status));
|
||||||
mAbortTransaction = true;
|
mAbortTransaction = true;
|
||||||
}
|
}
|
||||||
if (characteristic != null && BtLEQueue.this.mWaitCharacteristic != null && characteristic.getUuid().equals(BtLEQueue.this.mWaitCharacteristic.getUuid())) {
|
if (characteristic != null && BtLEQueue.this.mWaitCharacteristic != null && characteristic.getUuid().equals(BtLEQueue.this.mWaitCharacteristic.getUuid())) {
|
||||||
@ -393,4 +379,8 @@ public final class BtLEQueue {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private String getStatusString(int status) {
|
||||||
|
return status == BluetoothGatt.GATT_SUCCESS ? " (success)" : " (failed: " + status + ")";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -55,7 +55,11 @@ public class MiBandSupport extends AbstractBTLEDeviceSupport {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
|
||||||
pair(builder).sendUserInfo(builder).enableNotifications(builder, true).setCurrentTime(builder).requestBatteryInfo(builder);
|
pair(builder)
|
||||||
|
.sendUserInfo(builder)
|
||||||
|
.enableNotifications(builder, true)
|
||||||
|
.setCurrentTime(builder)
|
||||||
|
.requestBatteryInfo(builder);
|
||||||
|
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user