Exemplo n.º 1
0
        internal int StartScan()
        {
            _adapterLeScanResultChangedCallback = (int result, ref BluetoothLeScanDataStruct scanData, IntPtr userData) =>
            {
                Log.Info(Globals.LogTag, "Inside Le scan callback ");
                BluetoothLeScanData scanDataInfo = BluetoothUtils.ConvertStructToLeScanData(scanData);

                BluetoothLeDevice device = new BluetoothLeDevice(scanDataInfo);
                BluetoothError    res    = (BluetoothError)result;

                AdapterLeScanResultChangedEventArgs e = new AdapterLeScanResultChangedEventArgs(res,
                                                                                                device);
                _adapterLeScanResultChanged?.Invoke(null, e);
            };

            IntPtr data = IntPtr.Zero;
            int    ret  = Interop.Bluetooth.StartScan(_adapterLeScanResultChangedCallback, data);

            if (ret != (int)BluetoothError.None)
            {
                Log.Error(Globals.LogTag, "Failed to start BLE scan - " + (BluetoothError)ret);
                BluetoothErrorFactory.ThrowBluetoothException(ret);
            }
            _scanStarted = true;
            return(ret);
        }
Exemplo n.º 2
0
 public BluetoothDevice(BluetoothLeDevice leDevice)
 {
     RemoteDeviceAddress = leDevice?.RemoteAddress;
 }
Exemplo n.º 3
0
 internal AdapterLeScanResultChangedEventArgs(BluetoothError result, BluetoothLeDevice deviceData)
 {
     _deviceData = deviceData;
     _result     = result;
 }