use of android.bluetooth.BluetoothGattDescriptor in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTServer method initialize.
boolean initialize() {
BluetoothManager bluetoothManager = (BluetoothManager) mContext.getSystemService(Context.BLUETOOTH_SERVICE);
mBluetoothGattServer = bluetoothManager.openGattServer(mContext, this);
if (mBluetoothGattServer == null) {
return false;
}
BluetoothGattService pebbleGATTService = new BluetoothGattService(SERVER_SERVICE, BluetoothGattService.SERVICE_TYPE_PRIMARY);
pebbleGATTService.addCharacteristic(new BluetoothGattCharacteristic(READ_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_READ, BluetoothGattCharacteristic.PERMISSION_READ));
writeCharacteristics = new BluetoothGattCharacteristic(WRITE_CHARACTERISTICS, BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE | BluetoothGattCharacteristic.PROPERTY_NOTIFY, BluetoothGattCharacteristic.PERMISSION_WRITE);
writeCharacteristics.addDescriptor(new BluetoothGattDescriptor(CHARACTERISTICS_CONFIGURATION_DESCRIPTOR, BluetoothGattDescriptor.PERMISSION_WRITE));
pebbleGATTService.addCharacteristic(writeCharacteristics);
mBluetoothGattServer.addService(pebbleGATTService);
return true;
}
use of android.bluetooth.BluetoothGattDescriptor in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTClient method setMTU.
private void setMTU(BluetoothGatt gatt) {
LOG.info("setting MTU");
BluetoothGattCharacteristic characteristic = gatt.getService(SERVICE_UUID).getCharacteristic(MTU_CHARACTERISTIC);
BluetoothGattDescriptor descriptor = characteristic.getDescriptor(CHARACTERISTIC_CONFIGURATION_DESCRIPTOR);
// unknown
descriptor.setValue(new byte[] { 0x0b, 0x01 });
gatt.writeCharacteristic(characteristic);
}
use of android.bluetooth.BluetoothGattDescriptor in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTClient method subscribeToMTU.
private void subscribeToMTU(BluetoothGatt gatt) {
LOG.info("subscribing to mtu characteristic");
BluetoothGattDescriptor descriptor = gatt.getService(SERVICE_UUID).getCharacteristic(MTU_CHARACTERISTIC).getDescriptor(CHARACTERISTIC_CONFIGURATION_DESCRIPTOR);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
gatt.setCharacteristicNotification(gatt.getService(SERVICE_UUID).getCharacteristic(MTU_CHARACTERISTIC), true);
}
use of android.bluetooth.BluetoothGattDescriptor in project Gadgetbridge by Freeyourgadget.
the class PebbleGATTClient method subscribeToConnectivity.
private void subscribeToConnectivity(BluetoothGatt gatt) {
LOG.info("subscribing to connectivity characteristic");
BluetoothGattDescriptor descriptor = gatt.getService(SERVICE_UUID).getCharacteristic(CONNECTIVITY_CHARACTERISTIC).getDescriptor(CHARACTERISTIC_CONFIGURATION_DESCRIPTOR);
descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
gatt.writeDescriptor(descriptor);
gatt.setCharacteristicNotification(gatt.getService(SERVICE_UUID).getCharacteristic(CONNECTIVITY_CHARACTERISTIC), true);
}
use of android.bluetooth.BluetoothGattDescriptor in project Gadgetbridge by Freeyourgadget.
the class NotifyAction method run.
@Override
public boolean run(BluetoothGatt gatt) {
boolean result = gatt.setCharacteristicNotification(getCharacteristic(), enableFlag);
if (result) {
BluetoothGattDescriptor notifyDescriptor = getCharacteristic().getDescriptor(UUID_DESCRIPTOR_GATT_CLIENT_CHARACTERISTIC_CONFIGURATION);
if (notifyDescriptor != null) {
int properties = getCharacteristic().getProperties();
if ((properties & BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) {
LOG.debug("use NOTIFICATION");
notifyDescriptor.setValue(enableFlag ? BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
result = gatt.writeDescriptor(notifyDescriptor);
} else if ((properties & BluetoothGattCharacteristic.PROPERTY_INDICATE) > 0) {
LOG.debug("use INDICATION");
notifyDescriptor.setValue(enableFlag ? BluetoothGattDescriptor.ENABLE_INDICATION_VALUE : BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
result = gatt.writeDescriptor(notifyDescriptor);
hasWrittenDescriptor = true;
} else {
hasWrittenDescriptor = false;
}
} else {
LOG.warn("Descriptor CLIENT_CHARACTERISTIC_CONFIGURATION for characteristic " + getCharacteristic().getUuid() + " is null");
hasWrittenDescriptor = false;
}
} else {
hasWrittenDescriptor = false;
LOG.error("Unable to enable notification for " + getCharacteristic().getUuid());
}
return result;
}
Aggregations