public GattDescriptor(IGattCharacteristic characteristic, PeripheralContext context, BluetoothGattDescriptor native) : base(characteristic, native.Uuid.ToString()) { this.context = context; this.native = native; }
public GattDescriptor(IGattCharacteristic characteristic, DeviceContext context, BluetoothGattDescriptor native) : base(characteristic, native.Uuid.ToGuid()) { this.context = context; this.native = native; }
private void _device_DescriptorRead(object sender, BluetoothGattDescriptor e) { if (e == _descriptor) { _readHandle.Set(); } }
private void OnDescriptorWritten(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { if (status == GattStatus.Success && _onSubscribed != null) { _onSubscribed?.Invoke(true); } }
private Boolean SetNotifyEnable(bool enable) { if (gatt == null || characteristic == null) { return(false); } bool isSuccess = gatt.SetCharacteristicNotification(characteristic, enable); if (!isSuccess) { return(false); } BluetoothGattDescriptor descriptor = characteristic.GetDescriptor(UUID.FromString("00002902-0000-1000-8000-00805f9b34fb")); byte[] value = new byte[BluetoothGattDescriptor.EnableNotificationValue.Count]; for (int i = 0; i < BluetoothGattDescriptor.EnableNotificationValue.Count; i++) { value[i] = BluetoothGattDescriptor.EnableNotificationValue[i]; } descriptor.SetValue(value); isSuccess = gatt.WriteDescriptor(descriptor); return(isSuccess); }
public Characteristic(Service service, BluetoothGattCharacteristic characteristic) { _service = service; _characteristic = characteristic; _uuid = new CharacteristicUuid(new Uuid(characteristic.Uuid.ToString())); _clientConfigDescriptor = characteristic.GetDescriptor(s_uuidClientConfiguration); }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status) { base.OnDescriptorWrite(gatt, descriptor, status); if (GattStatus.Success == status) { try { subscribeCharacteristicTCS.TrySetResult(true); } catch { unsubscribeCharacteristicTCS.TrySetResult(true); } } else { Debug.WriteLine("onCharacteristicRead fail"); try { subscribeCharacteristicTCS.TrySetException(new Exception("OnDescriptorWrite fail")); } catch { unsubscribeCharacteristicTCS.TrySetException(new Exception("OnDescriptorWrite fail")); } } }
public Descriptor(BluetoothGattDescriptor nativeDescriptor, BluetoothGatt gatt, IGattCallback gattCallback, ICharacteristic characteristic) : base(characteristic) { this._gattCallback = gattCallback; this._gatt = gatt; this._nativeDescriptor = nativeDescriptor; }
public Descriptor(BluetoothGattDescriptor nativeDescriptor, BluetoothGatt gatt, IGattCallback gattCallback) { _gattCallback = gattCallback; _gatt = gatt; _nativeDescriptor = nativeDescriptor; }
// Overridden from BaseLeConnection protected override bool ValidateServices() { if (gatt == null) { return(false); } readCharacteristic = null; writeCharacteristic = null; var baseService = gatt.GetService(BASE_SERVICE); if (baseService != null) { readCharacteristic = baseService.GetCharacteristic(READ_CHARACTERISTIC); if (readCharacteristic != null) { readCharacteristicDescriptor = readCharacteristic.GetDescriptor(READ_CHARACTERISTIC_DESCRIPTOR); } writeCharacteristic = baseService.GetCharacteristic(WRITE_CHARACTERISTIC); } return(readCharacteristic != null && readCharacteristicDescriptor != null && writeCharacteristic != null); }
public Descriptor(BluetoothGattDescriptor nativeDescriptor, BluetoothGatt gatt, IGattCallback gattCallback, Characteristic characteristic) : this(characteristic) { NativeDescriptor = nativeDescriptor; _gattCallback = gattCallback; _gatt = gatt; }
public Task <bool> UnsubscribeCharacteristic(string serviceGUID, string characteristicGUID, string descriptorGUID) { unsubscribeCharacteristicTCS = new TaskCompletionSource <bool>(); try { if (_gatt == null) { Debug.WriteLine("Connect to Bluetooth Device first"); unsubscribeCharacteristicTCS.TrySetException(new Exception("Connect to Bluetooth Device first")); } BluetoothGattCharacteristic chara = _gatt.GetService(UUID.FromString(serviceGUID)).GetCharacteristic(UUID.FromString(characteristicGUID)); if (null == chara) { subscribeCharacteristicTCS.TrySetException(new Exception("Characteristic Id: " + characteristicGUID + " Not Found in Service: " + serviceGUID)); } _gatt.SetCharacteristicNotification(chara, false); BluetoothGattDescriptor descriptor = chara.GetDescriptor(UUID.FromString(descriptorGUID)); descriptor.SetValue(BluetoothGattDescriptor.DisableNotificationValue.ToArray()); _gatt.WriteDescriptor(descriptor); } catch (Exception e) { Debug.WriteLine(e.Message); unsubscribeCharacteristicTCS.TrySetException(new Exception(e.Message)); } return(unsubscribeCharacteristicTCS.Task); }
/** * Enables or disables notification on a give characteristic. * * @param characteristic Characteristic to act on. * @param enabled If true, enable notification. False otherwise. */ internal void SetCharacteristicNotification(BluetoothGattCharacteristic characteristic, bool enabled) { if (bluetoothAdapter == null || bluetoothGatt == null) { logger.TraceWarning("BluetoothAdapter not initialized"); return; } if (characteristic.Uuid.Equals(UUID.FromString(SampleGattAttributes.PRESSURE_NOTIFICATION_HANDLE))) { bluetoothGatt.SetCharacteristicNotification(characteristic, enabled); logger.TraceInformation("Setting notification: Pressure Characteristic detected "); BluetoothGattDescriptor descriptor = characteristic.GetDescriptor(UUID.FromString("00002902-0000-1000-8000-00805F9B34FB")); if (descriptor != null) { logger.TraceInformation("Setting notification: Pressure Descriptor Found"); descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray <byte>()); bluetoothGatt.WriteDescriptor(descriptor); logger.TraceInformation("Setting notification: Write Pressure Descriptor"); } else { logger.TraceWarning("NOTIFICATION SET UP IGNORED"); } } }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status) { base.OnDescriptorWrite(gatt, descriptor, status); var args = new BLEGATTDescriptorStatusEventArgs(gatt, descriptor, status); _wes.RaiseEvent(nameof(DescriptorWrite), this, args); }
private Descriptor ConvertDescriptor(BluetoothGattDescriptor descriptor) { return(new Descriptor { Id = Guid.Parse(descriptor.Uuid.ToString()), //Value = descriptor.GetValue().ToString() //TODO: update }); }
public override void OnDescriptorWriteRequest(BluetoothDevice device, int requestId, BluetoothGattDescriptor descriptor, bool preparedWrite, bool responseNeeded, int offset, byte[] value) => this.DescriptorWrite.OnNext(new DescriptorWriteEventArgs(descriptor, device, requestId, offset, preparedWrite, responseNeeded, value));
public override void OnDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { base.OnDescriptorRead(gatt, descriptor, status); Trace.Message("OnDescriptorRead: {0}", descriptor.GetValue()?.ToHexString()); DescriptorValueRead?.Invoke(this, new DescriptorCallbackEventArgs(descriptor, GetExceptionFromGattStatus(status))); }
public DescriptorReadEventArgs( BluetoothGattDescriptor descriptor, BluetoothDevice device, int requestId, int offset) : base(device, requestId, offset) { this.Descriptor = descriptor; }
internal BLEDescriptor(BluetoothGatt gatt, BLEGATTCallback callback, BluetoothGattDescriptor descriptor) { _gatt = gatt; _callback = callback; _descriptor = descriptor; _callback.DescriptorRead += OnDescriptorRead; _callback.DescriptorWrite += OnDescriptorWrite; }
public override void OnDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { base.OnDescriptorRead(gatt, descriptor, status); var device = GetCommonDevice(gatt); //TODO: implement //var commonDescriptor = device.Services.SelectMany(x => x.Characteristics).SelectMany(x => x.Descriptors).Single(x => x.Id == descriptor.Uuid.) }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { var handler = DescriptorWritten; if (handler != null) { handler(gatt, descriptor, status); } }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status) { if (gatt != _btLeGattSpp._bluetoothGatt) { return; } _btLeGattSpp._gattWriteStatus = status; _btLeGattSpp._btGattWriteEvent.Set(); }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status) { BluetoothGatt = gatt; if (ConfigurationStep == ConfigurationStep.AccelerometerNotification) { ConfigureGyroscope(gatt); } base.OnDescriptorWrite(gatt, descriptor, status); }
public DescriptorWriteEventArgs( BluetoothGattDescriptor descriptor, BluetoothDevice device, int requestId, int offset, bool preparedWrite, bool responseNeeded, byte[] value) : base(device, requestId, offset, preparedWrite, responseNeeded, value) { this.Descriptor = descriptor; }
private void EnableGlucoseContextNotification(BluetoothGatt gatt) { if (_glucoseMeasurementContextCharacteristic != null) { gatt.SetCharacteristicNotification(_glucoseMeasurementContextCharacteristic, true); BluetoothGattDescriptor descriptor = _glucoseMeasurementContextCharacteristic.GetDescriptor(BLEHelpers.BLE_DESCRIPTOR); descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray()); gatt.WriteDescriptor(descriptor); } }
private void EnableTimeSyncIndication(BluetoothGatt gatt) { if (_customTimeCharacteristic == null) { return; } gatt.SetCharacteristicNotification(_customTimeCharacteristic, true); BluetoothGattDescriptor descriptor = _customTimeCharacteristic.GetDescriptor(BLEHelpers.BLE_DESCRIPTOR); descriptor.SetValue(BluetoothGattDescriptor.EnableNotificationValue.ToArray()); gatt.WriteDescriptor(descriptor); }
public override void OnDescriptorRead(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status) { base.OnDescriptorRead(gatt, descriptor, status); if (status == GattStatus.Success) { ExecuteNextCommand(); } else { ExecutePreviousCommand(); } }
private void EnableRecordAccessControlPointIndication(BluetoothGatt gatt) { if (_racpCharacteristic == null) { return; } gatt.SetCharacteristicNotification(_racpCharacteristic, true); BluetoothGattDescriptor descriptor = _racpCharacteristic.GetDescriptor(BLEHelpers.BLE_DESCRIPTOR); descriptor.SetValue(BluetoothGattDescriptor.EnableIndicationValue.ToArray()); gatt.WriteDescriptor(descriptor); }
private BluetoothGattService CreateTimeService() { BluetoothGattService service = new BluetoothGattService(TIME_SERVICE, BluetoothGattService.ServiceTypePrimary); BluetoothGattCharacteristic currentTime = new BluetoothGattCharacteristic(CURRENT_TIME, GattProperty.Read | GattProperty.Notify, GattPermission.Read); BluetoothGattDescriptor configDescriptor = new BluetoothGattDescriptor(CLIENT_CONFIG, GattDescriptorPermission.Read | GattDescriptorPermission.Write); currentTime.AddDescriptor(configDescriptor); service.AddCharacteristic(currentTime); return(service); }
public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status) { if (SensorTagConfigurationStep == SensorTagConfigurationStep.KeyData) { ConfigureMovement(gatt); } else if (SensorTagConfigurationStep == SensorTagConfigurationStep.MovementData) { ConfigureMovementPeriod(gatt); } base.OnDescriptorWrite(gatt, descriptor, status); }