示例#1
0
        internal BluetoothGattServerImpl()
        {
            _sendIndicationCallback = SendIndicationCallback;

            int err = Interop.Bluetooth.BtGattServerInitialize();

            GattUtil.ThrowForError(err, "Failed to initialize server");

            err = Interop.Bluetooth.BtGattServerCreate(out _handle);
            GattUtil.ThrowForError(err, "Failed to create server");
        }
示例#2
0
        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);
        }