1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-11 20:49:25 +01:00

Zepp OS: Improve logging

- Do not log characteristic changes handled by parent class
- Log discovered service names
- Request and log supported config groups
This commit is contained in:
José Rebelo 2024-02-01 13:37:53 +00:00
parent aa4a7912ef
commit dbfb8e5c38
3 changed files with 42 additions and 5 deletions

View File

@ -2272,9 +2272,12 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
@Override @Override
public boolean onCharacteristicChanged(BluetoothGatt gatt, public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) { BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic); if (super.onCharacteristicChanged(gatt, characteristic)) {
// handled upstream
return true;
}
UUID characteristicUUID = characteristic.getUuid(); final UUID characteristicUUID = characteristic.getUuid();
if (HuamiService.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) { if (HuamiService.UUID_CHARACTERISTIC_6_BATTERY_INFO.equals(characteristicUUID)) {
handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS); handleBatteryInfo(characteristic.getValue(), BluetoothGatt.GATT_SUCCESS);
return true; return true;
@ -2317,7 +2320,10 @@ public abstract class HuamiSupport extends AbstractBTLEDeviceSupport implements
@Override @Override
public boolean onCharacteristicRead(BluetoothGatt gatt, public boolean onCharacteristicRead(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic, int status) { BluetoothGattCharacteristic characteristic, int status) {
super.onCharacteristicRead(gatt, characteristic, status); if (super.onCharacteristicRead(gatt, characteristic, status)) {
// handled upstream
return true;
}
UUID characteristicUUID = characteristic.getUuid(); UUID characteristicUUID = characteristic.getUuid();
if (GattCharacteristic.UUID_CHARACTERISTIC_DEVICE_NAME.equals(characteristicUUID)) { if (GattCharacteristic.UUID_CHARACTERISTIC_DEVICE_NAME.equals(characteristicUUID)) {

View File

@ -107,6 +107,10 @@ public class ZeppOsConfigService extends AbstractZeppOsService {
@Override @Override
public void handlePayload(final byte[] payload) { public void handlePayload(final byte[] payload) {
switch (payload[0]) { switch (payload[0]) {
case CMD_CAPABILITIES_RESPONSE:
handleCapabilitiesResponse(payload);
return;
case CMD_ACK: case CMD_ACK:
LOG.info("Configuration ACK, status = {}", payload[1]); LOG.info("Configuration ACK, status = {}", payload[1]);
return; return;
@ -125,7 +129,8 @@ public class ZeppOsConfigService extends AbstractZeppOsService {
} }
@Override @Override
public void initialize(TransactionBuilder builder) { public void initialize(final TransactionBuilder builder) {
write(builder, CMD_CAPABILITIES_REQUEST);
requestAllConfigs(builder); requestAllConfigs(builder);
} }
@ -152,6 +157,27 @@ public class ZeppOsConfigService extends AbstractZeppOsService {
return false; return false;
} }
private void handleCapabilitiesResponse(final byte[] payload) {
final int version = payload[1] & 0xFF;
LOG.info("Got config service version={}", version);
if (version > 3) {
LOG.error("Unsupported config service version {}", version);
return;
}
final int numGroups = payload[2] & 0xFF;
if (payload.length != numGroups + 3) {
LOG.error("Unexpected config capabilities response length {} for {} groups", payload.length, numGroups);
return;
}
for (int i = 0; i < numGroups; i++) {
final ConfigGroup configGroup = ConfigGroup.fromValue(payload[3 + i]);
LOG.debug("Got supported config group {}: {}", String.format("0x%02x", payload[3 + i]), configGroup);
}
// TODO: We should only request supported config groups
}
private boolean sentFitnessGoal = false; private boolean sentFitnessGoal = false;
private void handle2021ConfigResponse(final byte[] payload) { private void handle2021ConfigResponse(final byte[] payload) {

View File

@ -72,7 +72,12 @@ public class ZeppOsServicesService extends AbstractZeppOsService {
final AbstractZeppOsService service = getSupport().getService(endpoint); final AbstractZeppOsService service = getSupport().getService(endpoint);
LOG.debug("Service: endpoint={} encrypted={} known={}", String.format("%04x", endpoint), encrypted, service != null); LOG.debug(
"Zepp OS Service: endpoint={} encrypted={} name={}",
String.format("%04x", endpoint),
encrypted,
service != null ? service.getClass().getSimpleName() : "unknown"
);
if (service != null && encrypted != null) { if (service != null && encrypted != null) {
service.setEncrypted(encrypted); service.setEncrypted(encrypted);