public void UpdateDevice(string id, string name) { DeviceDiscovered?.Invoke(new BluetoothDeviceInfo() { Name = name, Address = id }); }
private BluetoothLEAdvertisementWatcher InitBleWatcher() { var bleWatcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active }; bleWatcher.Received += async(w, btAdv) => { var bleDevice = await ExtractBleDeviceByBluetoothAddress(btAdv.BluetoothAddress); if (bleDevice == null) { return; } var bleDeviceId = bleDevice.DeviceId; lock (lockObj) { if (!_devices.ContainsKey(bleDeviceId)) { _devices[bleDeviceId] = bleDevice; } } DeviceDiscovered?.Invoke(this, new BleDeviceEventArgs(bleDevice.ToDomainModel())); bleDevice.ConnectionStatusChanged += UpdateByConnectionStatusAndPublishEvent; }; return(bleWatcher); }
/// <summary> /// Set the current state of the chat connection. /// </summary> /// <param name='context'> /// The current environment where the action was do it. /// </param> /// <param name='intent'> /// The type of action happened. /// </param> public override void OnReceive(Context context, Intent intent) { string action = intent.Action; if (BluetoothDevice.ActionFound.Equals(action)) { BluetoothDevice device = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); device = _service._myadapter.GetRemoteDevice(device.Address); var a = new RemoteDevice(); a.BluetoothType = device.Type.ToString(); a.Name = device.Name; a.DeviceAddress = device.Address; a.State = device.BondState.ToString(); a.Class = device.Class; //Esto no está validando nada. Hay que arreglarlo. if (_service._listdevices.Select(p => p.Address == a.DeviceAddress).Count() == 0) { GloVa.DevicesDiscovered.Add(a); _service._listdevices.Add(device); } DeviceDiscovered.Invoke(); } }
public void DiscoverDevice(IDevice device) { var args = new DeviceDiscoveredEventArgs(); args.Device = device; DeviceDiscovered?.Invoke(this, args); }
protected void OnDeviceDiscovered(BluetoothDevice device, ScanRecord scanRecord, int rssi) { if (!_discoveredDevices.Any(d => device.Address == d.Address)) { _discoveredDevices.Add(device); DeviceDiscovered?.Invoke(this, new DeviceDiscoveredEventArgs(device, scanRecord, rssi)); } }
private void OnEventReceived(EventPdu eventPdu) { if (eventPdu?.Header.EventCode == EventCode.DeviceDiscovered) { var pdu = eventPdu.As <DeviceDiscoveredEvent>(); DeviceDiscovered?.Invoke(this, new DeviceDiscoveredEventArgs(pdu)); } }
private static void OnBluetoothDeviceActionFound(Intent intent) { var bluetoothDevice = (BluetoothDevice)intent.GetParcelableExtra(BluetoothDevice.ExtraDevice); if (!BluetoothDevices.Any(x => x.Address.Equals(bluetoothDevice.Address))) { BluetoothDevices.Add(bluetoothDevice); DeviceDiscovered?.Invoke(BluetoothDevices); } }
/// <summary> /// /// </summary> /// <param name="portName"></param> private void RaiseDeviceDiscovered(string portName) { if (_synchronizationContext != SynchronizationContext.Current) { _synchronizationContext.Post(o => DeviceDiscovered?.Invoke(this, portName), null); } else { DeviceDiscovered?.Invoke(this, portName); } }
private async Task RegisterDevice(Device device) { if (DeviceDiscovered != null) { await dispatcher.RunAsync(CoreDispatcherPriority.Normal, new DispatchedHandler(() => { DeviceDiscovered?.Invoke(this, device); })); } }
private void SerialDeviceDiscovered(string serialNumber, SerialConnectionInfo obj) { ConnectionSearchResult connectionSearchResult = new ConnectionSearchResult(serialNumber, obj); lock (autoConnectionInfoListSyncLock) { connectionSearchResults.Add(connectionSearchResult); } DeviceDiscovered?.Invoke(connectionSearchResult); }
static void OnManagerDiscoveredPeripheral(object sender, CBDiscoveredPeripheralEventArgs e) { if (peripheral != null) { return; } Console.WriteLine("Discovered peripheral"); DeviceDiscovered?.Invoke(null, e); }
private void StartScannerThread() { EndPoint localEp = _localEp; _cancellationTokenSource = new CancellationTokenSource(); CancellationToken ct = _cancellationTokenSource.Token; _scannerThread = Task.Run(async() => { while (!ct.IsCancellationRequested) { try { byte[] response = new byte[8000]; int no = _socket.ReceiveFrom(response, ref localEp); string str = Encoding.UTF8.GetString(Decrypt(response.Take(no).ToArray())); JObject obj = ParserHelpers.ParseGetSysInfo(str); if (obj == null) { continue; } DeviceType deviceType = ParserHelpers.GetDeviceType(obj); if (GetDeviceTypeFilter()?.Contains(deviceType) == false) { Debug.WriteLine("Excluded device"); continue; } var requestContext = new RequestContext(obj, (localEp as IPEndPoint)?.Address); DeviceStateInfo state = await _deviceManager.AddOrUpdate(requestContext).ConfigureAwait(false); switch (state.State) { case DeviceState.Added: DeviceDiscovered?.Invoke(this, new DeviceEventArgs(state.Device)); break; case DeviceState.Updated: DeviceUpdated?.Invoke(this, new DeviceEventArgs(state.Device)); break; } } catch (Exception e) { Debug.WriteLine(e); } } }, ct); }
public override void OnScanResult([GeneratedEnum] ScanCallbackType callbackType, ScanResult result) { try { DeviceDiscovered?.Invoke(result); base.OnScanResult(callbackType, result); } catch (System.Exception ex) { string title = this.GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name; BalizaFacil.App.Instance.UnhandledException(title, ex); } }
public BleAdapter(IAdapter adapter) { _adapter = adapter; _adapter.DeviceDiscovered += (sender, args) => DeviceDiscovered?.Invoke(sender, BleDevice.Wrap(args.Device)); _adapter.DeviceConnected += (sender, args) => DeviceConnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.DeviceDisconnected += (sender, args) => DeviceDisconnected?.Invoke(sender, args.Adapt <DeviceConnectionEventArgs>()); _adapter.ScanTimeoutElapsed += (sender, args) => ScanTimeoutElapsed?.Invoke(sender, args); }
protected void AddDevice(string deviceId, object device) { var evtArgs = new AdapterDiscoveryEventArgs() { DeviceId = deviceId, Device = device, LastSeen = DateTime.Now }; _deviceMap.Add(deviceId, evtArgs); DeviceDiscovered?.Invoke(this, evtArgs); }
private void AdvertisementRecieved(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs args) { var device = new Device(args.BluetoothAddress, args.Advertisement.LocalName, args.RawSignalStrengthInDBm); if (DeviceFilter(device)) { if (!_devicesDiscovered.Contains(device.BluetoothAddress)) { DeviceDiscovered?.Invoke(this, device); } else { DeviceAdvertised?.Invoke(this, device); } } }
public override void OnScanResult(ScanCallbackType callbackType, ScanResult result) { base.OnScanResult(callbackType, result); var device = new Device(result.Device, null, null, result.Rssi); if (result.ScanRecord != null) { device.AdvertismentData = ProcessData(result.ScanRecord); if (result.ScanRecord.ServiceUuids != null) { device.AdvertisedServiceUuids = result.ScanRecord.ServiceUuids.Select(x => Guid.Parse(x.Uuid.ToString())).ToList(); } } var eventArgs = new DeviceDiscoveredEventArgs(device); DeviceDiscovered?.Invoke(this, eventArgs); }
private void AdvertisementRecieved(BluetoothLEAdvertisementWatcher watcher, BluetoothLEAdvertisementReceivedEventArgs args) { var device = new Device(args.BluetoothAddress, args.Advertisement.LocalName, args.RawSignalStrengthInDBm); if (DeviceFilter(device)) { if (!_devicesDiscovered.Contains(device.BluetoothAddress)) { DeviceDiscovered?.Invoke(this, device); DeviceAdvertised?.Invoke(this, device); // !!! TODO: Check this (setup program does not work otherwise, as nothing gets added to devices-discovered) } else { DeviceAdvertised?.Invoke(this, device); } } }
public LifxLocalClient() { ReceivedPacket += async(sender, message) => { var bulbId = message.Address.Target.MacAddressToString(); var isNew = false; var bulb = _bulbs.AddOrUpdate( bulbId, _ => { isNew = true; return(new LifxLocalLight { Id = bulbId, Mac = message.Address.Target }); }, (_, b) => b); bulb.Endpoint = new IPEndPoint(message.IpAddress, 56700); if (isNew) { await SendAsync(bulb, new LifxMessageGetColor()); DeviceDiscovered?.Invoke(this, bulb); } var lifxMessageState = message as LifxMessageState; if (lifxMessageState != null) { bulb.Name = lifxMessageState.Label; bulb.IsOn = lifxMessageState.IsPower; bulb.Color = lifxMessageState.Color; VariableChanged?.Invoke(bulb, Tuple.Create(bulb, "Color", (object)bulb.Color.ToRgb().ToString())); VariableChanged?.Invoke(bulb, Tuple.Create(bulb, "Brightness", (object)Math.Round(bulb.Color.Brightness, 2))); VariableChanged?.Invoke(bulb, Tuple.Create(bulb, "Kelvin", (object)(double)bulb.Color.Kelvin)); VariableChanged?.Invoke(bulb, Tuple.Create(bulb, "Name", (object)bulb.Name)); VariableChanged?.Invoke(bulb, Tuple.Create(bulb, "IsOn", (object)bulb.IsOn)); } }; }
public override void OnBatchScanResults(IList <ScanResult> results) { base.OnBatchScanResults(results); foreach (var result in results) { var device = new Device(result.Device, null, null, result.Rssi); if (result.ScanRecord != null) { device.AdvertismentData = ProcessData(result.ScanRecord); if (result.ScanRecord.ServiceUuids != null) { device.AdvertisedServiceUuids = result.ScanRecord.ServiceUuids.Select(x => Guid.Parse(x.Uuid.ToString())).ToList(); } } var eventArgs = new DeviceDiscoveredEventArgs(device); DeviceDiscovered?.Invoke(this, eventArgs); } }
private void Lookup(string m_Url) { WebRequest request = WebRequest.Create(m_Url); using (WebResponse response = request.GetResponse()) { try { Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); XmlSerializer serializer = new XmlSerializer(typeof(SSDPDeviceDescription)); SSDPDeviceDescription deserialized = (SSDPDeviceDescription)serializer.Deserialize(reader); DeviceDiscovered?.Invoke(m_Url, deserialized.Device); } catch (Exception) { } } }
private async void IInitDevice(DeviceID id, DeviceEventType e, HidDevice hid = null) { ResponseDevice device = DeviceFactory.Create(id); if (device != null) { m_log.Trace("ResponseDevice detected..."); if (hid == null) { HidDeviceLoader loader = new HidDeviceLoader(); for (int i = 0; i < 10; i++) { hid = loader.GetDeviceOrDefault(vendorID: id.Vendor, productID: id.Product); if (hid == null) { m_log.Trace("... HID device matching USB insert not found, retrying in 50ms"); Thread.Sleep(50); // :( } else { break; } } if (hid == null) { m_log.Warn("Could not find HID device [V:{0:X}] [P:{1:X}] [S:{2}] after USB insert", id.Vendor, id.Product, id.Serial); return; } } m_log.Info("Discovered `{0}` [V:{1:X}] [P:{2:X}] [S:{3}]", hid.ProductName, id.Vendor, id.Product, id.Serial); if (await device.Initialize(hid)) { m_devices.Add(id, device); DeviceDiscovered?.Invoke(this, new DeviceEventArgs(device, e)); } else { m_log.Warn("Failed to init `{0}` [V:{1:X}] [P:{2:X}] [S:{3}]", hid.ProductName, id.Vendor, id.Product, id.Serial); } } }
private void ProcessDeviceDiscoveryMessage(IPEndPoint remoteEndpoint, LifxMessage msg) { string id = msg.Header.FrameAddress.TargetMacAddressName; //remoteAddress.ToString() if (DiscoveredBulbs.ContainsKey(id)) //already discovered { DiscoveredBulbs[id].LastSeen = DateTime.UtcNow; //Update datestamp DiscoveredBulbs[id].Endpoint = remoteEndpoint; return; } if (msg.Header.Frame.SourceIdentifier != discoverSourceID || //did we request the discovery? _DiscoverCancellationSource == null || _DiscoverCancellationSource.IsCancellationRequested) //did we cancel discovery? { return; } if (!(msg.Payload is StateServiceResponse stateServiceResponse)) { return; // not the message we were expecting } var device = new LightBulb() { Endpoint = remoteEndpoint, Service = stateServiceResponse.Service, LastSeen = DateTime.UtcNow, MacAddress = msg.Header.FrameAddress.TargetMacAddress, SendClient = msg.RespondClient, }; DiscoveredBulbs[id] = device; devices.Add(device); DeviceDiscovered?.Invoke(this, new DeviceDiscoveryEventArgs() { Device = device }); }
public void OnDeviceDiscovered(Android.Bluetooth.LE.ScanResult obj) { try { //Debug.Write(obj.Rssi); //if (obj.Rssi >= -50) //{ DeviceDiscovered?.Invoke(new BluetoothDeviceInfo() { Name = obj.Device.Name, Address = obj.Device.Address }); //} //else //{ // DeviceDiscovered?.Invoke(new BluetoothDeviceInfo() { Name = obj.Device.Name, Address = obj.Device.Address }); //} } catch (System.Exception ex) { string title = this.GetType().Name + " - " + System.Reflection.MethodBase.GetCurrentMethod().Name; BalizaFacil.App.Instance.UnhandledException(title, ex); } }
/// <summary> /// Called when a BLE device has been discovered /// </summary> /// <param name="sender">Device watcher which discovered the device</param> /// <param name="device_info">BLE device information</param> private void DeviceWatcher_Added(DeviceWatcher sender, DeviceInformation device_info) { // Retrieve device information BleDeviceInformation ble_device_info = new BleDeviceInformation(); ble_device_info.Id = device_info.Id; ble_device_info.Name = device_info.Name; try { ble_device_info.MacAddress = device_info.Properties["System.Devices.Aep.DeviceAddress"].ToString(); } catch (KeyNotFoundException) { ble_device_info.MacAddress = ""; } try { ble_device_info.IsConnected = (bool)device_info.Properties["System.Devices.Aep.IsConnected"]; } catch (KeyNotFoundException) { ble_device_info.IsConnected = false; } try { ble_device_info.IsConnectable = (bool)device_info.Properties["System.Devices.Aep.Bluetooth.Le.IsConnectable"]; } catch (KeyNotFoundException) { ble_device_info.IsConnectable = false; } ble_device_info.Context = device_info; // Notify device discovery DeviceDiscovered?.Invoke(this, ble_device_info); }
private void BeginSearchUdp() { // Set service expiery period to 5 seconds to deal with IMU wifi send delays queriesList.Add(AhoyQuery.CreateQuery(5000)); foreach (IAhoyQuery query in queriesList) { query.ServiceDiscovered += delegate(AhoyServiceInfo serviceInfo) { NetworkInterface networkInterface = GetInterfaceFor(serviceInfo.NetworkAdapterIPAddress); string adapterName = "Unknown adapter"; if (networkInterface != null) { adapterName = networkInterface.Description; } ConnectionSearchResult connectionSearchResult = new ConnectionSearchResult(serviceInfo.Descriptor, new UdpConnectionInfo() { AdapterName = adapterName, NetworkAdapter = networkInterface, AdapterIPAddress = serviceInfo.NetworkAdapterIPAddress, SendIPAddress = serviceInfo.Address, SendPort = serviceInfo.SendPort, ReceivePort = serviceInfo.ListenPort, }); lock (autoConnectionInfoListSyncLock) { connectionSearchResults.Add(connectionSearchResult); } DeviceDiscovered?.Invoke(connectionSearchResult); }; query.ServiceExpired += delegate(AhoyServiceInfo serviceInfo) { NetworkInterface networkInterface = GetInterfaceFor(serviceInfo.NetworkAdapterIPAddress); string adapterName = "Unknown adapter"; if (networkInterface != null) { adapterName = networkInterface.Description; } ConnectionSearchResult connectionSearchResult = new ConnectionSearchResult(serviceInfo.Descriptor, new UdpConnectionInfo() { AdapterName = adapterName, NetworkAdapter = networkInterface, AdapterIPAddress = serviceInfo.NetworkAdapterIPAddress, SendIPAddress = serviceInfo.Address, SendPort = serviceInfo.SendPort, ReceivePort = serviceInfo.ListenPort, }); lock (autoConnectionInfoListSyncLock) { connectionSearchResults.Remove(connectionSearchResult); } DeviceExpired?.Invoke(connectionSearchResult); }; query.BeginSearch(SendInterval); } }
protected virtual void OnDeviceDiscovered(IDevice e) { DeviceDiscovered?.Invoke(this, e); }
// Fired when a new device was found during // Bluetooth discovery procedure private void JavaDeviceDiscoveredHandler(string deviceAddress) { DeviceDiscovered?.Invoke(GetDeviceFromAddress(deviceAddress)); }
private void RaiseDeviceDiscovered(string portName) { DeviceDiscovered?.Invoke(this, portName); }
private void RaiseDeviceDiscovered(BLEDevice device, int rssi, IList <BLEAdvertisement> advertisements) => DeviceDiscovered?.Invoke(this, new BLEDeviceEventArgs(device, rssi, advertisements));