示例#1
0
        public IObservable <IScanResult> Scan(ScanConfig config)
        {
            if (this.IsScanning)
            {
                throw new ArgumentException("There is already an active scan");
            }

            return(Observable.Create <IScanResult>(ob =>
            {
                var sub = this.ScanListen().Subscribe(ob.OnNext);
                this.watcher.Start();
                this.scanStatusSubject.OnNext(true);

                return () =>
                {
                    this.watcher.Stop();
                    this.scanStatusSubject.OnNext(false);
                    sub.Dispose();
                };
            }));
            //        .Where(x => x
            //            .AdvertisementData
            //            .ServiceUuids?
            //            .Any(uuid => uuid.Equals(serviceUuid)) ?? false
            //        );
        }
示例#2
0
        public IObservable <IScanResult> Scan(ScanConfig config)
        {
            if (this.IsScanning)
            {
                throw new ArgumentException("There is already an existing scan");
            }

            config = config ?? new ScanConfig();
            return(Observable.Create <IScanResult>(ob =>
            {
                this.context.Clear();
                var scan = this.ScanListen().Subscribe(ob.OnNext);

                if (config.ServiceUuid == null)
                {
                    this.context.Manager.ScanForPeripherals(null, new PeripheralScanningOptions {
                        AllowDuplicatesKey = true
                    });
                }
                else
                {
                    var uuid = config.ServiceUuid.Value.ToCBUuid();
                    this.context.Manager.ScanForPeripherals(uuid);
                }
                this.ToggleScanStatus(true);

                return () =>
                {
                    this.context.Manager.StopScan();
                    scan.Dispose();
                    this.ToggleScanStatus(false);
                };
            }));
        }
示例#3
0
        public IObservable <IScanResult> Scan(ScanConfig config)
        {
            if (this.IsScanning)
            {
                throw new ArgumentException("There is already an active scan");
            }

            config = config ?? new ScanConfig();
            return(Observable.Create <IScanResult>(ob =>
            {
                this.context.Devices.Clear();

                var scan = this.ScanListen().Subscribe(ob.OnNext);
                this.context.StartScan(AndroidConfig.ForcePreLollipopScanner, config);
                this.scanStatusChanged.OnNext(true);

                return () =>
                {
                    this.context.StopScan();
                    scan.Dispose();
                    this.scanStatusChanged.OnNext(false);
                };
            }));
        }