Пример #1
0
        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)));
        }
Пример #2
0
            public override void OnServicesDiscovered(BluetoothGatt gatt, [GeneratedEnum] GattStatus status)
            {
                base.OnServicesDiscovered(gatt, status);

                foreach (BluetoothGattService service in gatt.Services)
                {
                    string uuid = service.Uuid.ToString().ToUpper();

                    if (uuid != "")
                    {
                        foreach (BluetoothGattCharacteristic characteristic in service.Characteristics)
                        {
                            string c_uuid = characteristic.Uuid.ToString().ToUpper();

                            if (c_uuid != "")
                            {
                                gatt.SetCharacteristicNotification(characteristic, true);

                                BluetoothGattDescriptor descriptor = new BluetoothGattDescriptor(UUID.FromString("00002A25-0000-1000-8000-00805F9B34FB"), GattDescriptorPermission.Read | GattDescriptorPermission.Write);
                                characteristic.AddDescriptor(descriptor);
                                gatt.SetCharacteristicNotification(characteristic, true);
                                gatt.ReadDescriptor(descriptor);
                                byte[] data = descriptor.GetValue();
                                descriptor.SetValue(data);
                                gatt.WriteDescriptor(descriptor);
                                byte[] chara = characteristic.GetValue();

                                if (data != null)
                                {
                                    Log.Debug(tag, "VALOR AQUI: " + data.ToString());
                                    Log.Debug(tag, "Chara: " + chara[0].ToString());
                                }
                                Log.Debug(tag, "Chara: " + chara[0].ToString());
                                Log.Debug(tag, "VALOR AQUI: " + data.ToString());


                                //Log.Debug(tag, "VALOR AQUI: " + data.ToString());
                            }
                        }
                    }
                }
            }
Пример #3
0
        public void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status)
        {
            var uuid = descriptor.Characteristic.Uuid.ToString().ToLower();

            // Check if its a subscribe or unsubscribe descriptor
            if (descriptor.Uuid.ToString().ToLower() == "00002902-0000-1000-8000-00805f9b34fb")
            {
                var descriptorValue = descriptor.GetValue();

                if (descriptorValue.SequenceEqual(BluetoothGattDescriptor.EnableNotificationValue.ToArray()))
                {
                    if (_subscribeQueue.ContainsKey(uuid))
                    {
                        var subscribeItem = _subscribeQueue[uuid];
                        _subscribeQueue.Remove(uuid);
                        subscribeItem.SetResult(descriptorValue);
                    }
                }
                else if (descriptorValue.SequenceEqual(BluetoothGattDescriptor.DisableNotificationValue.ToArray()))
                {
                    if (_unsubscribeQueue.ContainsKey(uuid))
                    {
                        var unsubscribeItem = _unsubscribeQueue[uuid];
                        _unsubscribeQueue.Remove(uuid);
                        unsubscribeItem.SetResult(descriptorValue);
                    }
                }
                else
                {
                    Debug.WriteLine($"OnDescriptorWrite Error: Unhandled descriptor of {descriptor.Uuid} on {uuid}.");
                }
            }
            else
            {
                Debug.WriteLine($"OnDescriptorWrite Error: Unhandled descriptor of {descriptor.Uuid} on {uuid}.");
            }

            _gattOperationQueueProcessing = false;
            ProcessQueue();
        }
Пример #4
0
 Task <byte[]> DoGetValue()
 {
     return(Task.FromResult(_descriptor.GetValue()));
 }
 public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, [GeneratedEnum] GattStatus status)
 {
     base.OnDescriptorWrite(gatt, descriptor, status);
     Debug.WriteLine("Descriptor written to: " + descriptor.Uuid + " get value: " + descriptor.GetValue() + " status: " + status);
     if (status == GattStatus.Success)
     {
         ExecuteNextCommand();
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Got gatt descriptor write failure: " + status);
         ExecutePreviousCommand();
     }
 }
 public override void OnDescriptorWrite(BluetoothGatt gatt, BluetoothGattDescriptor descriptor, GattStatus status)
 {
     base.OnDescriptorWrite(gatt, descriptor, status);
     System.Diagnostics.Debug.WriteLine("Descriptor written to: " + descriptor.Uuid + " get value: " + descriptor.GetValue() + " status: " + status);
     if (status == GattStatus.Success)
     {
         Bluetooth_CMD.poll_queue();
     }
     else
     {
         System.Diagnostics.Debug.WriteLine("Got gatt descriptor write failure: " + status);
         Bluetooth_CMD.retry_last_command((int)status);
     }
 }
Пример #7
0
        private async Task <GattReadResult> DoReadValueAsync(BluetoothCacheMode cacheMode)
        {
            bool success = true;

            if (cacheMode == BluetoothCacheMode.Uncached)
            {
                success = _characteristic.Service.Device._bluetoothGatt.ReadDescriptor(_descriptor);
                _readHandle.WaitOne();
            }

            return(new GattReadResult(success ? GattCommunicationStatus.Success : GattCommunicationStatus.Unreachable, _descriptor.GetValue()));
        }