protected async Task Initialize() { await _device.WaitForPropertyValueAsync("Connected", value : true, TIMEOUT); _properties = await _device.GetAllAsync(); Log.Debug("Waiting for services to resolve..."); await _device.WaitForPropertyValueAsync("ServicesResolved", value : true, TIMEOUT); foreach (var s in await _device.GetUUIDsAsync()) { var g = Guid.Parse(s); var svc = await _device.GetServiceAsync(s); _services[Guid.Parse(s)] = svc; if (g == DEVICE_INFORMATION_SERVICE) { Log.Debug("Found DeviceInformationService."); DeviceInformationService = new DeviceInformationService(svc); } else if (g == BATTERY_SERVICE) { Log.Debug("Found BatteryService."); BatteryService = new BatteryService(svc); } } Log.Debug("Services resolved."); await BleDeviceConnected(); Log.Information($"Connected to {this}."); }
async Task <Device> InitAsync() { propertyWatcher = await proxy.WatchPropertiesAsync(x => UpdateProperties(x.Changed)); UpdateProperties(await proxy.GetAllAsync()); await proxy.ConnectAsync(); return(this); }
private static async Task <string> GetDeviceDescriptionAsync(IDevice1 device, Device1Properties?deviceProperties = null) { if (deviceProperties == null) { deviceProperties = await device.GetAllAsync(); } return($"{deviceProperties.Alias} (Address: {deviceProperties.Address}, RSSI: {deviceProperties.RSSI})"); }
private static async Task <bool> ShouldConnect(ScanFilter filter, IDevice1 device) { var deviceProperties = await device.GetAllAsync(); if (!await filter.Check(device)) { return(false); } Log.Debug($"Device found at {deviceProperties.Address}."); return(true); }
private async Task <string> GetDeviceDescriptionAsync(IDevice1 device) { var deviceProperties = await device.GetAllAsync(); // используем Device UUID вместо GATTId в качестве идентификатора маячка, т.к. нет времени заморачиваться await _writer.SendInternal(new CTrack() { Timestamp = DateTimeOffset.Now, GATTid = deviceProperties.UUIDs[0], RSSI = deviceProperties.RSSI }); return($"{deviceProperties.Alias} (Address: {deviceProperties.Address}, RSSI: {deviceProperties.RSSI}), DeviceUUID: {deviceProperties.UUIDs[0]}"); }
public async Task <bool> Check(IDevice1 device) { var deviceProperties = await device.GetAllAsync(); if (_address == null) { return(deviceProperties?.Alias?.Contains(_name ?? "") ?? false); } else { return(deviceProperties.Address == _address); } }
private static async Task <string> GetDeviceDescriptionAsync(IDevice1 device) { var deviceProperties = await device.GetAllAsync(); return($"{deviceProperties.Address} (Alias: {deviceProperties.Alias}, RSSI: {deviceProperties.RSSI})"); }
public async Task <IBluetoothDeviceProperties> GetPropertiesAsync() { var dnbProperties = await _device.GetAllAsync(); return(new DotNetBlueZProperties(dnbProperties)); }