Esempio n. 1
0
        public IObservable <IScanResult> ScanListen()
        {
            this.scanListenOb = this.scanListenOb ?? Observable.Create <IScanResult>(ob =>
            {
                this.deviceManager.Clear();

                var adHandler = new TypedEventHandler <BluetoothLEAdvertisementWatcher, BluetoothLEAdvertisementReceivedEventArgs>
                                (
                    (sender, args) =>
                {
                    var adData     = new AdvertisementData(args);
                    var device     = this.deviceManager.GetDevice(adData);
                    var scanResult = new ScanResult(device, args.RawSignalStrengthInDBm, adData);
                    ob.OnNext(scanResult);
                }
                                );
                this.watcher.Received += adHandler;

                return(() => this.watcher.Received -= adHandler);
            })
                                .Publish()
                                .RefCount();

            return(this.scanListenOb);
        }
Esempio n. 2
0
 public IDevice GetDevice(AdvertisementData data)
 {
     return(this.devices.GetOrAdd(
                data.BluetoothAddress,
                x => new Device(this.adapter, data)
                ));
 }
Esempio n. 3
0
        public Device(IAdapter adapter, AdvertisementData adData)
        {
            this.adapter       = adapter;
            this.adData        = adData;
            this.deviceSubject = new Subject <bool>();

            this.Name = adData.Native.GetDeviceName();
            var mac  = this.ToMacAddress(adData.BluetoothAddress);
            var uuid = this.ToDeviceId(mac);

            this.Uuid = uuid;
        }