internal Task <bool> SendIndicationAsync(BluetoothGattServer server, BluetoothGattCharacteristic characteristic, string clientAddress)
        {
            TaskCompletionSource <bool> tcs = new TaskCompletionSource <bool>();

            Interop.Bluetooth.BtGattServerNotificationSentCallback cb = (result, address, serverHandle, characteristicHandle, completed, userData) =>
            {
                _notificationSent?.Invoke(characteristic, new NotificationSentEventArg(server, address, result, completed));
                if (completed)
                {
                    tcs.SetResult(true);
                }
            };

            int err = Interop.Bluetooth.BtGattServerNotify(characteristic.GetHandle(), cb, clientAddress, IntPtr.Zero);

            GattUtil.ThrowForError(err, string.Format("Failed to send value changed indication for characteristic uuid {0}", characteristic.Uuid));

            return(tcs.Task);
        }
        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);
        }
Exemple #3
0
        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 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));
        }
Exemple #6
0
 /// <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()));
 }