1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-01 06:22:55 +01:00

First communication test between ZeTime and GB. Ask about activitys, sleep and heart-rate infos available. ZeTime responds correctly

This commit is contained in:
Kranz 2018-06-15 11:23:44 +02:00
parent 48affad220
commit 89c8c9cdfb

View File

@ -1,5 +1,6 @@
package nodomain.freeyourgadget.gadgetbridge.service.devices.zetime; package nodomain.freeyourgadget.gadgetbridge.service.devices.zetime;
import android.bluetooth.BluetoothGatt;
import android.bluetooth.BluetoothGattCharacteristic; import android.bluetooth.BluetoothGattCharacteristic;
import android.net.Uri; import android.net.Uri;
@ -21,7 +22,9 @@ import nodomain.freeyourgadget.gadgetbridge.model.MusicStateSpec;
import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec; import nodomain.freeyourgadget.gadgetbridge.model.NotificationSpec;
import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec; import nodomain.freeyourgadget.gadgetbridge.model.WeatherSpec;
import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport; import nodomain.freeyourgadget.gadgetbridge.service.btle.AbstractBTLEDeviceSupport;
import nodomain.freeyourgadget.gadgetbridge.service.btle.GattService;
import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder; import nodomain.freeyourgadget.gadgetbridge.service.btle.TransactionBuilder;
import nodomain.freeyourgadget.gadgetbridge.service.btle.actions.SetDeviceStateAction;
/** /**
* Created by Kranz on 08.02.2018. * Created by Kranz on 08.02.2018.
@ -37,21 +40,22 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
public ZeTimeDeviceSupport(){ public ZeTimeDeviceSupport(){
super(LOG); super(LOG);
addSupportedService(GattService.UUID_SERVICE_GENERIC_ACCESS);
addSupportedService(GattService.UUID_SERVICE_GENERIC_ATTRIBUTE);
addSupportedService(ZeTimeConstants.UUID_SERVICE_BASE); addSupportedService(ZeTimeConstants.UUID_SERVICE_BASE);
addSupportedService(ZeTimeConstants.UUID_SERVICE_EXTEND);
addSupportedService(ZeTimeConstants.UUID_SERVICE_HEART_RATE);
} }
@Override @Override
protected TransactionBuilder initializeDevice(TransactionBuilder builder) { protected TransactionBuilder initializeDevice(TransactionBuilder builder) {
LOG.info("Initializing"); LOG.info("Initializing");
builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZING, getContext()));
gbDevice.setState(GBDevice.State.INITIALIZING);
gbDevice.sendDeviceUpdateIntent(getContext());
notifyCharacteristic = getCharacteristic(ZeTimeConstants.UUID_NOTIFY_CHARACTERISTIC); notifyCharacteristic = getCharacteristic(ZeTimeConstants.UUID_NOTIFY_CHARACTERISTIC);
writeCharacteristic = getCharacteristic(ZeTimeConstants.UUID_WRITE_CHARACTERISTIC); writeCharacteristic = getCharacteristic(ZeTimeConstants.UUID_WRITE_CHARACTERISTIC);
ackCharacteristic = getCharacteristic(ZeTimeConstants.UUID_ACK_CHARACTERISTIC); ackCharacteristic = getCharacteristic(ZeTimeConstants.UUID_ACK_CHARACTERISTIC);
builder.setGattCallback(this); builder.notify(ackCharacteristic, true);
builder.notify(notifyCharacteristic, true);
// do this in a function // do this in a function
builder.write(writeCharacteristic, new byte[]{ZeTimeConstants.CMD_PREAMBLE, builder.write(writeCharacteristic, new byte[]{ZeTimeConstants.CMD_PREAMBLE,
@ -63,11 +67,8 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
ZeTimeConstants.CMD_END}); ZeTimeConstants.CMD_END});
builder.write(ackCharacteristic, new byte[]{ZeTimeConstants.CMD_ACK_WRITE}); builder.write(ackCharacteristic, new byte[]{ZeTimeConstants.CMD_ACK_WRITE});
gbDevice.setState(GBDevice.State.INITIALIZED); builder.add(new SetDeviceStateAction(getDevice(), GBDevice.State.INITIALIZED, getContext()));
gbDevice.sendDeviceUpdateIntent(getContext());
LOG.info("Initialization Done"); LOG.info("Initialization Done");
return builder; return builder;
} }
@ -220,4 +221,20 @@ public class ZeTimeDeviceSupport extends AbstractBTLEDeviceSupport {
public void onNotification(NotificationSpec notificationSpec) { public void onNotification(NotificationSpec notificationSpec) {
} }
@Override
public boolean onCharacteristicChanged(BluetoothGatt gatt,
BluetoothGattCharacteristic characteristic) {
super.onCharacteristicChanged(gatt, characteristic);
UUID characteristicUUID = characteristic.getUuid();
if (ZeTimeConstants.UUID_ACK_CHARACTERISTIC.equals(characteristicUUID)) {
byte[] data = characteristic.getValue();
return true;
} else {
LOG.info("Unhandled characteristic changed: " + characteristicUUID);
logMessageContent(characteristic.getValue());
}
return false;
}
} }