Example #1
0
        public Wrapper([NotNull] IScheduler scheduler,
                       [NotNull] IDeviceFactory deviceFactory,
                       [NotNull] Func <DateTimeOffset, IDateTimeOffset> dateTimeFactory,
                       [NotNull] ISubject <IDevice> received,
                       [NotNull] ISubject <DateTime> stopped,
                       [NotNull] IStatusMapper statusMapper)
        {
            Guard.ArgumentNotNull(scheduler,
                                  nameof(scheduler));
            Guard.ArgumentNotNull(deviceFactory,
                                  nameof(deviceFactory));
            Guard.ArgumentNotNull(dateTimeFactory,
                                  nameof(dateTimeFactory));
            Guard.ArgumentNotNull(received,
                                  nameof(received));
            Guard.ArgumentNotNull(stopped,
                                  nameof(stopped));
            Guard.ArgumentNotNull(statusMapper,
                                  nameof(statusMapper));

            _deviceFactory   = deviceFactory;
            _dateTimeFactory = dateTimeFactory;
            _received        = received;
            _stopped         = stopped;
            _statusMapper    = statusMapper;

            _watcher = new AdvertisementWatcher
            {
                ScanningMode = BluetoothLEScanningMode.Active
            };
        }
Example #2
0
        private void Scan_Click(object sender, RoutedEventArgs e)
        {
            if (watcher != null)
            {
                watcher.Stop();
            }
            watcher = new BluetoothLEAdvertisementWatcher();
            var manufacturerData = new BluetoothLEManufacturerData {
                CompanyId = CUSTOM_ID
            };

            watcher.AdvertisementFilter.Advertisement.ManufacturerData.Add(manufacturerData);
            watcher.Received += Watcher_Received;
            watcher.Start();
        }
Example #3
0
        private async void Watcher_Received(Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher sender,
                                            Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementReceivedEventArgs args)
        {
            ushort identifier = args.Advertisement.ManufacturerData.First().CompanyId;

            byte[] data   = args.Advertisement.ManufacturerData.First().Data.ToArray();
            var    ignore = Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                latitude  = BitConverter.ToDouble(data, 0);
                longitude = BitConverter.ToDouble(data, 8);

                TextBlock.Text = latitude.ToString();
                /* GPS Data Parsing / UI integration goes here */
            });
        }
Example #4
0
        static BleWatcher()
        {
            Devices = new ConcurrentDictionary <ulong, DeviceModel>();
            Watcher = new AdvWatcher
            {
                ScanningMode = BluetoothLEScanningMode.Active,
                //AdvertisementFilter = new BluetoothLEAdvertisementFilter(){ }.Advertisement.ManufacturerData.Add(new BluetoothLEManufacturerData() { })
            };

            Watcher.Received += (sender, args) =>
            {
                if (args.Advertisement.LocalName.Contains(SENSI))
                {
                    if (!Devices.ContainsKey(args.BluetoothAddress))
                    {
                        var device = new DeviceModel()
                        {
                            Name             = args.Advertisement.LocalName,
                            BluetoothAddress = args.BluetoothAddress
                        };
                        if (Devices.TryAdd(args.BluetoothAddress, device))
                        {
                            Changed?.Invoke();
                        }
                    }
                }
            };


            //Watcher.Removed += (DeviceWatcher sender, DeviceInformationUpdate args) =>
            //{
            //    DeviceInformation info;
            //    if (Devices.TryRemove(args.Id, out info))
            //        Changed?.Invoke();
            //};
        }
Example #5
0
 private void OnStoppedHandler(AdvertisementWatcher sender,
                               BluetoothLEAdvertisementWatcherStoppedEventArgs args)
 {
     _stopped.OnNext(DateTime.Now);
 }