internal IEnumerable <BluetoothGattDescriptor> GetDescriptors(BluetoothGattCharacteristic characteristic) { List <BluetoothGattDescriptor> attribututeList = new List <BluetoothGattDescriptor>(); Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) => { BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false); BluetoothGattDescriptor descriptor = BluetoothGattDescriptorImpl.CreateBluetoothGattDescriptor(handle, ""); if (descriptor != null) { descriptor.SetParent(characteristic); attribututeList.Add(descriptor); } return(true); }; int err = Interop.Bluetooth.BtGattCharacteristicForeachDescriptors(characteristic.GetHandle(), cb, IntPtr.Zero); GattUtil.Error(err, "Failed to get all descriptor"); return(attribututeList); }
internal Task <bool> SendIndicationAsync(BluetoothGattServer server, BluetoothGattCharacteristic characteristic, string clientAddress) { TaskCompletionSource <bool> task = new TaskCompletionSource <bool>(); int requestId = 0; lock (this) { requestId = _requestId++; _sendIndicationTaskSource[requestId] = task; } int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), _sendIndicationCallback, clientAddress, (IntPtr)requestId); if (err.IsFailed()) { GattUtil.Error(err, string.Format("Failed to send value changed indication for characteristic uuid {0}", characteristic.Uuid)); task.SetResult(false); _sendIndicationTaskSource.Remove(requestId); BluetoothErrorFactory.ThrowBluetoothException(err); } return(task.Task); }
internal IEnumerable <BluetoothGattCharacteristic> GetCharacteristics(BluetoothGattService service) { List <BluetoothGattCharacteristic> attribututeList = new List <BluetoothGattCharacteristic>(); Interop.Bluetooth.BtGattForeachCallback cb = (total, index, attributeHandle, userData) => { BluetoothGattAttributeHandle handle = new BluetoothGattAttributeHandle(attributeHandle, false); BluetoothGattCharacteristic Characteristic = BluetoothGattCharacteristicImpl.CreateBluetoothGattGattCharacteristic(handle, ""); if (Characteristic != null) { Characteristic.SetParent(service); attribututeList.Add(Characteristic); } return(true); }; int err = Interop.Bluetooth.BtGattServiceForeachCharacteristics(service.GetHandle(), cb, IntPtr.Zero); GattUtil.Error(err, "Failed to get all Characteristic"); return(attribututeList); }
internal void AddCharacteristic(BluetoothGattCharacteristic characteristic) { int err = Interop.Bluetooth.BtGattServiceAddCharacteristic(_handle, characteristic.GetHandle()); GattUtil.ThrowForError(err, string.Format("Failed to add characteristic with UUID ({0})", characteristic.Uuid)); }
internal void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress) { int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), null, clientAddress, IntPtr.Zero); GattUtil.ThrowForError(err, string.Format("Failed to send value changed notification for characteristic uuid {0}", characteristic.Uuid)); }
/// <summary> /// Writes the value of a given characteristic to the remote device asynchronously. /// </summary> /// <param name="characteristic">The characteristic to be written.</param> /// <returns>true on success, false otherwise.</returns> /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled /// or when the remote device is disconnected or when the write attribute value fails.</exception> /// <since_tizen> 3 </since_tizen> public async Task <bool> WriteValueAsync(BluetoothGattCharacteristic characteristic) { return(await _impl.WriteValueAsyncTask(characteristic.GetHandle())); }
/// <summary> /// Sends the notification for the value change of the characteristic to the remote devices. /// </summary> /// <param name="characteristic">The characteristic, which has a changed value.</param> /// <param name="clientAddress">The remote device address to send, notify, or indicate and if set to NULL, then notify/indicate all is enabled.</param> /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled /// or when the remote device is disconnected, or when service is not registered, or when the CCCD is not enabled.</exception> /// <since_tizen> 3 </since_tizen> public void SendNotification(BluetoothGattCharacteristic characteristic, string clientAddress) { _impl.SendNotification(characteristic, clientAddress); }
/// <summary> /// Sends indication for the value change of the characteristic to the remote devices. /// </summary> /// <param name="characteristic">The characteristic whose the value is changed.</param> /// <param name="clientAddress">The remote device address to send, notify, or indicate and if set to NULL, then notify/indicate all is enabled.</param> /// <returns>true on success, false otherwise.</returns> /// <exception cref="InvalidOperationException">Thrown when the BT/BTLE is not enabled /// or when the remote device is disconnected, or when service is not registered, or when the CCCD is not enabled.</exception> /// <since_tizen> 3 </since_tizen> public async Task <bool> SendIndicationAsync(BluetoothGattCharacteristic characteristic, string clientAddress) { return(await _impl.SendIndicationAsync(this, characteristic, clientAddress)); }