public BeaconManager(IBleManager centralManager, IMessageBus messageBus, IRepository repository) : base(repository) { this.centralManager = centralManager; this.messageBus = messageBus; }
public CentralExtensionsViewModel(IBleManager centralManager, IDialogs dialogs) { this.Tasks = new List <TaskViewModel> { new TaskViewModel( "Scan Find Peripheral", ct => centralManager .ScanUntilPeripheralFound(this.PeripheralName) .ToTask(ct), this.WhenAny( x => x.PeripheralName, x => !x.GetValue().IsEmpty() ) ), new TaskViewModel( "Scan For Unique Peripherals", ct => centralManager .ScanForUniquePeripherals() .ToTask(ct) ), new TaskViewModel( "Scan Interval", ct => centralManager .ScanInterval( TimeSpan.FromSeconds(10), TimeSpan.FromSeconds(10) ) .ToTask(ct) ) }; }
public TestViewModel(IBleManager bleManager) { this.bleManager = bleManager; this.Start = ReactiveCommand.CreateFromTask( async ct => { try { this.IsBusy = true; await this.GeneralTest(ct); } finally { this.IsBusy = false; } //await this.ObdTest(); }, this.WhenAny(x => x.IsBusy, x => !x.GetValue()) ); this.Stop = ReactiveCommand.Create( () => { this.disp?.Dispose(); this.peripheral?.CancelConnection(); this.Append("Stopped"); this.IsBusy = false; }, this.WhenAny(x => x.IsBusy, x => x.GetValue()) ); }
/// <summary> /// This will scan until the peripheral a specific peripheral is found, then cancel the scan /// </summary> /// <param name="bleManager"></param> /// <param name="peripheralName"></param> /// <param name="includeLocalName"></param> /// <returns></returns> public static IObservable <IPeripheral> ScanUntilPeripheralFound(this IBleManager bleManager, string peripheralName, bool includeLocalName = true) => bleManager .Scan() .Where(x => x.Peripheral.Name?.Equals(peripheralName, StringComparison.OrdinalIgnoreCase) ?? false || (includeLocalName && (x.AdvertisementData?.LocalName?.Equals(peripheralName, StringComparison.InvariantCultureIgnoreCase) ?? false)) ) .Take(1) .Select(x => x.Peripheral);
public BeaconRangingManager(IBleManager centralManager) { this.centralManager = centralManager; this.scanner = this.centralManager .ScanForBeacons(null) .Publish() .RefCount(); }
/// <summary> /// This method wraps the traditional scan, but waits for the bleManager to be ready before initiating scan /// </summary> /// <param name="bleManager">The bleManager to scan with</param> /// <param name="restart">Stops any current scan running</param> /// <param name="config">ScanConfig parameters you would like to use</param> /// <returns></returns> public static IObservable <ScanResult> Scan(this IBleManager bleManager, ScanConfig?config = null, bool restart = false) { if (restart && bleManager.IsScanning) { bleManager.StopScan(); // need a pause to wait for scan to end } return(bleManager.Scan(config)); }
public MainPageViewModel() { _manager = ShinyHost.Resolve <IBleManager>(); Search = new Command(async() => await StartSearch()); Stop = new Command(StopSearch); ReadFromDeviceCommand = new Command <IPeripheral>(async(peripheral) => await ReadFromDevice(peripheral)); }
public PeripheralTests() { ShinyHost.Init(TestStartup.CurrentPlatform, new ActionStartup { BuildServices = x => x.UseBleClient() }); this.manager = ShinyHost.Resolve <IBleManager>(); }
public static bool TrySetAdapterState(this IBleManager centralManager, bool enable) { if (centralManager is ICanControlAdapterState state) { state.SetAdapterState(enable); return(true); } return(false); }
public ConnectedPeripheralsViewModel(IBleManager centralManager) { this.Load = ReactiveCommand.CreateFromTask(async() => { var peripherals = await centralManager.GetConnectedPeripherals(); //peripherals.Select(x => x // TODO: get TBD connected devices too }); }
public TestViewModel(IBleManager bleManager, IGeofenceManager geofenceManager, IDialogs dialogs) { this.bleManager = bleManager; this.geofenceManager = geofenceManager; this.dialogs = dialogs; this.Start = ReactiveCommand.CreateFromTask <string>( async arg => { this.disp = new CompositeDisposable(); this.cancelSrc = new CancellationTokenSource(); this.Logs = String.Empty; switch (arg) { case "managedbleperipheral": await this.DoManagedPeripheral(); break; case "managedblescan": await this.DoManagedScan(); break; case "locationpermission": await this.DoLocationPermissionTest(); break; case "blepairing": await this.PairingTest(); break; case "bledeviceinfo": await this.BleDeviceInfo(); break; default: await dialogs.Snackbar("Invalid Test - " + arg); break; } } ); this.BindBusyCommand(this.Start); this.Stop = ReactiveCommand.Create( () => { this.disp?.Dispose(); this.cancelSrc?.Cancel(); this.peripheral?.CancelConnection(); this.Append("Stopped"); this.IsBusy = false; }, this.WhenAny(x => x.IsBusy, x => x.GetValue()) ); }
public BleManagerTests(ITestOutputHelper output) { ShinyHost.Init(TestStartup.CurrentPlatform, new ActionStartup { BuildServices = x => x.UseBleClient(), BuildLogging = x => x.AddXUnit(output) }); this.manager = ShinyHost.Resolve <IBleManager>(); }
public static IObservable <Beacon> ScanForBeacons(this IBleManager manager, bool forMonitoring = false) => manager .Scan(new ScanConfig { //AndroidUseScanBatching = true, ScanType = forMonitoring ? BleScanType.LowPowered : BleScanType.Balanced }) .Where(x => x.IsBeacon()) .Select(x => x.AdvertisementData.ManufacturerData.Data.Parse(x.Rssi));
public static IObservable<bool> TrySetAdapterState(this IBleManager bleManager, bool enable) { var result = false; if (bleManager is ICanControlAdapterState state) { state.SetAdapterState(enable); result = true; } return Observable.Return(result); }
public DeviceListViewModel() { ble = (IBleManager)ShinyHost.Container.GetService(typeof(IBleManager)); Title = "Devices"; Devices = new ObservableCollection <DeviceModel>(); ScanButtonCommand = new Command(async() => await ExecuteScanButtonCommand()); DeviceTapped = new Command <DeviceModel>(OnDeviceSelected); }
public BackgroundTask(ShinyCoreServices core, IBleManager centralManager, IBeaconMonitoringManager beaconManager, ILogger <IBeaconMonitorDelegate> logger) { this.bleManager = centralManager; this.beaconManager = beaconManager; this.logger = logger; this.core = core; this.states = new Dictionary <string, BeaconRegionStatus>(); }
public BackgroundTask(IBleManager centralManager, IBeaconManager beaconManager, IMessageBus messageBus, IBeaconDelegate beaconDelegate) { this.centralManager = centralManager; this.beaconManager = beaconManager; this.messageBus = messageBus; this.beaconDelegate = beaconDelegate; this.states = new Dictionary <string, BeaconRegionStatus>(); }
public BackgroundTask(IMessageBus messageBus, IBleManager centralManager, IBeaconMonitoringManager beaconManager, IEnumerable <IBeaconMonitorDelegate> delegates, ILogger <IBeaconMonitorDelegate> logger) { this.messageBus = messageBus; this.bleManager = centralManager; this.beaconManager = beaconManager; this.logger = logger; this.delegates = delegates; this.states = new Dictionary <string, BeaconRegionStatus>(); }
public static async Task <BleGattService> GetGattServiceById(this IBleManager bleManager, string deviceId, string gattServiceId) { try { var allGattServices = await bleManager.GetDeviceGattServices(deviceId); return(allGattServices?.FirstOrDefault(g => g.Uuid == Guid.Parse(gattServiceId))); } catch (Exception) { return(null); } }
public ManagedScanViewModel(IBleManager bleManager) { this.scanner = bleManager .CreateManagedScanner( RxApp.MainThreadScheduler, TimeSpan.FromSeconds(10) ) .DisposedBy(this.DeactivateWith); this.Toggle = ReactiveCommand.CreateFromTask(async() => this.IsBusy = await this.scanner.Toggle() ); }
public ScanViewModel() { try { manager = DependencyService.Get <IBleManager>(); manager.BleDeviceFound += HandleBleDeviceFound; } catch (Exception ex) { string s = ex.ToString(); Debug.WriteLine(s); // return null; } }
public ExtractorManager(IBleManager bleManager, IEventAggregator aggregator, ILoggerFacade logger, INotifyManager notifyManager, IStateManager stateManager) { _bleManager = bleManager; _aggregator = aggregator; _logger = logger; _notifyManager = notifyManager; _stateManager = stateManager; _aggregator.GetEvent <PrismEvents.CharacteristicUpdatedEvent>().Subscribe(OnCharacteristicNotify, ThreadOption.UIThread); }
public ScanViewModel(IBleManager bleManager) { this.Start = ReactiveCommand.CreateFromTask(async() => { bleManager //.ScanForUniquePeripherals() // this gives you the peripheral, not the scan results .Scan() .SubOnMainThread(result => // scan results duplicate per device as the RSSI and device name is read/changed this.Results.Add(result) ); }); this.Stop = ReactiveCommand.Create(() => bleManager.StopScan()); }
public BeaconMonitoringManager(IBleManager bleManager, #if __ANDROID__ IAndroidContext context, #endif IMessageBus messageBus, IRepository repository) { this.bleManager = bleManager; #if __ANDROID__ this.context = context; #endif this.messageBus = messageBus; this.repository = repository; }
public BeaconMonitoringManager(IBleManager bleManager, IRepository repository, IMessageBus messageBus #if __ANDROID__ , IAndroidContext context #endif ) { this.bleManager = bleManager; this.messageBus = messageBus; this.repository = repository; #if __ANDROID__ this.context = context; #endif }
public QuickIdeasViewModel(IBleManager bleManager) { this.FindItAndRead = ReactiveCommand.Create(() => { bleManager .ScanUntilPeripheralFound("My Peripheral Name", true) .Select(x => x.WithConnectIf()) .Switch() .Select(x => x.ReadCharacteristic("ServiceUUID", "CharUUID")) .Switch() .Take(1) .SubOnMainThread( data => this.ReadText = Encoding.ASCII.GetString(data) ); }); }
/// <summary> /// This will scan until the peripheral a specific peripheral is found, then cancel the scan /// </summary> /// <param name="bleManager"></param> /// <param name="peripheralName"></param> /// <returns></returns> public static IObservable <IPeripheral> ScanUntilPeripheralFound(this IBleManager bleManager, string peripheralName) => bleManager .Scan() .Where(scanResult => { if (scanResult.Peripheral.Name?.Equals(peripheralName, StringComparison.InvariantCultureIgnoreCase) ?? false) { return(true); } if (scanResult.AdvertisementData?.LocalName?.Equals(peripheralName, StringComparison.CurrentCultureIgnoreCase) ?? false) { return(true); } return(false); }) .Take(1) .Select(x => x.Peripheral);
void HandleBleDeviceFound(IBleManager sender, BleDevice deviceFound) { foreach (XBleDevice dev in devices) { if (dev.ID == deviceFound.ID) { return; } } if (deviceFound.Name == "Speed and Cadence" || deviceFound.Name == "CSC Sensor") { devices.Add(new BleCyclingSensor(deviceFound)); } else { devices.Add(new XBleDevice(deviceFound)); } }
public static IObservable <Beacon> ScanForBeacons(this IBleManager manager, BeaconMonitorConfig?config) { var scanType = config == null ? BleScanType.LowLatency : BleScanType.LowPowered; var cfg = new ScanConfig { ScanType = scanType }; if (config?.ScanServiceUuids?.Any() ?? false) { cfg.ServiceUuids = config.ScanServiceUuids; } return(manager .Scan(cfg) .Where(x => x.IsBeacon()) .Select(x => x.AdvertisementData.ManufacturerData.Data.Parse(x.Rssi))); }
public ManagedScanViewModel(IBleManager bleManager, INavigationService navigator) { this.scanner = bleManager .CreateManagedScanner(RxApp.MainThreadScheduler, TimeSpan.FromSeconds(10)) .DisposedBy(this.DeactivateWith); this.Toggle = ReactiveCommand.CreateFromTask(async() => this.IsBusy = await this.scanner.Toggle() ); this.WhenAnyValue(x => x.SelectedPeripheral) .Skip(1) .Where(x => x != null) .Subscribe(async x => { this.SelectedPeripheral = null; this.scanner.Stop(); await navigator.Navigate("ManagedPeripheral", ("Peripheral", x.Peripheral)); }); }