Exemplo n.º 1
0
        public override IObservable <IGattDescriptor> DiscoverDescriptors()
        {
            this.descriptorOb = this.descriptorOb ?? Observable.Create <IGattDescriptor>(ob =>
            {
                var descriptors = new Dictionary <Guid, IGattDescriptor>();

                var handler = new EventHandler <CBCharacteristicEventArgs>((sender, args) =>
                {
                    if (this.NativeCharacteristic.Descriptors == null)
                    {
                        return;
                    }

                    foreach (var dnative in this.NativeCharacteristic.Descriptors)
                    {
                        var wrap = new GattDescriptor(this, dnative);
                        if (!descriptors.ContainsKey(wrap.Uuid))
                        {
                            descriptors.Add(wrap.Uuid, wrap);
                            ob.OnNext(wrap);
                        }
                    }
                });
                this.Peripheral.DiscoveredDescriptor += handler;
                this.Peripheral.DiscoverDescriptors(this.NativeCharacteristic);

                return(() => this.Peripheral.DiscoveredDescriptor -= handler);
            })
                                .Replay()
                                .RefCount();

            return(this.descriptorOb);
        }
 public override IObservable <IGattDescriptor> DiscoverDescriptors()
 => this.descriptorOb ??= Observable.Create <IGattDescriptor>(ob =>
 {
     foreach (var nd in this.native.Descriptors)
     {
         var wrap = new GattDescriptor(this, this.context, nd);
         ob.OnNext(wrap);
     }
     return(Disposable.Empty);
 })
 .Replay()
 .RefCount();
Exemplo n.º 3
0
 public override IObservable <IGattDescriptor> DiscoverDescriptors()
 {
     this.descriptorOb = this.descriptorOb ?? Observable.Create <IGattDescriptor>(async ob =>
     {
         var result = await this.Native.GetDescriptorsAsync(BluetoothCacheMode.Uncached);
         //if (result.Status != GattCommunicationStatus.Success)
         foreach (var dnative in result.Descriptors)
         {
             var descriptor = new GattDescriptor(dnative, this);
             ob.OnNext(descriptor);
         }
         return(Disposable.Empty);
     })
                         .Replay();
     return(this.descriptorOb);
 }