示例#1
0
        public override IObservable <IGattService> DiscoverServices() => Observable.Create <IGattService>(ob =>
        {
            Log.Write("BluetoothLe-Device", "service discovery hooked for peripheral " + this.Uuid);
            var services = new Dictionary <Guid, IGattService>();

            var handler = new EventHandler <NSErrorEventArgs>((sender, args) =>
            {
                if (args.Error != null)
                {
                    ob.OnError(new BleException(args.Error.LocalizedDescription));
                    return;
                }

                if (this.Native.Services == null)
                {
                    return;
                }

                foreach (var native in this.Native.Services)
                {
                    var service = new GattService(this, native);
                    if (!services.ContainsKey(service.Uuid))
                    {
                        services.Add(service.Uuid, service);
                        ob.OnNext(service);
                    }
                }
                ob.OnCompleted();
            });
            this.Native.DiscoveredService += handler;
            this.Native.DiscoverServices();

            return(() => this.Native.DiscoveredService -= handler);
        });
示例#2
0
        public override IObservable <IGattService> GetKnownService(Guid serviceUuid)
        => Observable.Create <IGattService>(ob =>
        {
            var handler = new EventHandler <NSErrorEventArgs>((sender, args) =>
            {
                if (this.Native.Services == null)
                {
                    return;
                }

                foreach (var native in this.Native.Services)
                {
                    var service = new GattService(this, native);
                    if (service.Uuid.Equals(serviceUuid))
                    {
                        ob.Respond(service);
                        break;
                    }
                }
            });
            this.Native.DiscoveredService += handler;
            this.Native.DiscoverServices(new[] { serviceUuid.ToCBUuid() });

            return(() => this.Native.DiscoveredService -= handler);
        });
示例#3
0
        public override IObservable <IGattService> GetKnownService(Guid serviceUuid) => Observable.FromAsync(async ct =>
        {
            var result = await this.context.NativeDevice.GetGattServicesForUuidAsync(serviceUuid, BluetoothCacheMode.Cached);
            if (result.Status != GattCommunicationStatus.Success)
            {
                throw new ArgumentException("Could not find GATT service - " + result.Status);
            }

            var wrap = new GattService(this.context, result.Services.First());
            return(wrap);
        });
示例#4
0
        public override IObservable <IGattService> DiscoverServices() => Observable.Create <IGattService>(async ob =>
        {
            var result = await this.context.NativeDevice.GetGattServicesAsync(BluetoothCacheMode.Uncached);
            foreach (var nservice in result.Services)
            {
                var service = new GattService(this.context, nservice);
                ob.OnNext(service);
            }
            ob.OnCompleted();

            return(Disposable.Empty);
        });
示例#5
0
        public override IObservable <IGattService> DiscoverServices()
        => Observable.Create <IGattService>(ob =>
        {
            var sub = this.context.Callbacks.ServicesDiscovered.Subscribe(cb =>
            {
                foreach (var ns in cb.Gatt.Services)
                {
                    var service = new GattService(this, this.context, ns);
                    ob.OnNext(service);
                }
                ob.OnCompleted();
            });

            //this.context.RefreshServices();
            this.context.Gatt.DiscoverServices();

            return(sub);
        });
示例#6
0
        public override IObservable <IGattService> DiscoverServices()
        => Observable.Create <IGattService>(ob =>
        {
            var sub = this.context
                      .Callbacks
                      .ServicesDiscovered
                      .Where(x => x.Gatt.Device.Equals(this.context.NativeDevice))
                      .Subscribe(args =>
            {
                foreach (var ns in args.Gatt.Services)
                {
                    var service = new GattService(this, this.context, ns);
                    ob.OnNext(service);
                }
                ob.OnCompleted();
            });

            this.context.RefreshServices();
            this.context.Gatt.DiscoverServices();

            return(sub);
        });
示例#7
0
 public GattCharacteristic(GattService service, CBCharacteristic native) : base(service, native.UUID.ToGuid(), (CharacteristicProperties)(int)native.Properties)
 {
     this.serivceObj           = service;
     this.NativeCharacteristic = native;
 }