private async void Button_spate(object sender, EventArgs e) { IBluetoothAdapter adapter = DependencyService.Resolve <IBluetoothAdapter>(); BluetoothDeviceModel device = (BluetoothDeviceModel)BindingContext; if (device != null) { using (var connection = adapter.CreateConnection(device)) { if (await connection.RetryConnectAsync(retriesCount: 20)) { byte[] buffer = new byte[BufferSize] { (byte)'B' }; if (!await connection.RetryTransmitAsync(buffer, OffsetDefault, buffer.Length)) { await DisplayAlert("Error", "Cannot send data", "Close"); } } else { await DisplayAlert("Error", "Cannot connect.", "Close"); } connection.Dispose(); } } }
public BluetoothNetworkMedium() { _client = MonoSAMGame.CurrentInst.Bridge.Bluetooth; DebugDisplayString = new BufferedLambdaString(() => $"XBT[Enabled:{_client.IsEnabled} Discovering:{_client.IsDiscovering} MyState:{_client.State} (_scanning:{_isScanning}|{MonoSAMGame.CurrentTime.TotalElapsedSeconds - _scanStartTime:00}) AState:{_client.AdapterState} AScan:{_client.AdapterScanMode} Threads:<{_client.DebugThreadState}> Founds:{_client.FoundDevices.Count}\n" + $"RemoteDevice:<{_client.RemoteDevice?.Name}|{_client.RemoteDevice?.Address}|{_client.RemoteDevice?.DeviceClass}|{_client.RemoteDevice?.Type}|{_client.RemoteDevice?.IsBonded}|{_client.RemoteDevice?.IsBonding}> Name:{_client.AdapterName}]", 1.5f); }
public BluetoothKernel(IBluetoothAdapter bluetoothAdapter, string bluetoothServiceGuid, string bluetoothCharacteristicGuid, ILogger <BluetoothKernel> logger = default) { _bluetoothAdapter = bluetoothAdapter ?? throw new ArgumentNullException(nameof(bluetoothAdapter)); _bluetoothServiceGuid = bluetoothServiceGuid; _bluetoothCharacteristicGuid = bluetoothCharacteristicGuid; _logger = logger; }
public CampfireNetClient(Identity identity, IBluetoothAdapter bluetoothAdapter, BroadcastMessageSerializer broadcastMessageSerializer, ClientMerkleTreeFactory merkleTreeFactory) { this.identity = identity; this.bluetoothAdapter = bluetoothAdapter; this.broadcastMessageSerializer = broadcastMessageSerializer; this.merkleTreeFactory = merkleTreeFactory; this.localMerkleTree = merkleTreeFactory.CreateForLocal(); }
public async Task Scan_AdapterFound_False() { string adapterName = null; var btServiceMock = new Mock <IBluetoothService>(); IBluetoothAdapter btAdapter = null; btServiceMock.Setup(s => s.GetAdapterAsync(adapterName)).ReturnsAsync(btAdapter); var bleReader = new BleReader(btServiceMock.Object); await bleReader.ScanAsync(); }
public BluetoothNetworkMedium(IBluetoothAdapter adapter) { _client = adapter; DebugDisplayString = new BufferedLambdaString(() => $"XBT[Enabled:{_client?.IsEnabled} " + $"Discovering:{_client?.IsDiscovering} " + $"MyState:{_client?.State} " + $"(_scanning:{_isScanning}|{MonoSAMGame.CurrentTime.TotalElapsedSeconds - _scanStartTime:00}) " + $"AState:{_client?.AdapterState} " + $"AScan:{_client?.AdapterScanMode} " + $"Threads:<{_client?.DebugThreadState}> " + $"Founds:{_client?.FoundDevices.Count}\n" + $"RemoteDevice:<{_client?.RemoteDevice?.Name}|{_client?.RemoteDevice?.Address}|{_client?.RemoteDevice?.DeviceClass}|{_client?.RemoteDevice?.Type}|{_client?.RemoteDevice?.IsBonded}|{_client?.RemoteDevice?.IsBonding}> " + $"Name:{_client?.AdapterName}]", 1.5f); }
public async Task <IBluetoothAdapter> GetAdapterAsync(string name) { IBluetoothAdapter adapter = null; if (name != null) { var dnbAdapter = await BlueZManager.GetAdapterAsync(name); adapter = new DotNetBlueZAdapter(dnbAdapter); } else { var adapters = await BlueZManager.GetAdaptersAsync(); if (adapters.Count > 0) { adapter = new DotNetBlueZAdapter(adapters.First()); } } return(adapter); }
public NeighborConnectionContext( Identity identity, IBluetoothAdapter bluetoothAdapter, IBluetoothNeighbor neighbor, BroadcastMessageSerializer broadcastMessageSerializer, MerkleTree <BroadcastMessageDto> localMerkleTree, MerkleTree <BroadcastMessageDto> remoteMerkleTree ) { this.haveChannel = new DisconnectableChannel <HavePacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <HavePacket>()); this.needChannel = new DisconnectableChannel <NeedPacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <NeedPacket>()); this.giveChannel = new DisconnectableChannel <GivePacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <GivePacket>()); this.whoisChannel = new DisconnectableChannel <WhoisPacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <WhoisPacket>()); this.identChannel = new DisconnectableChannel <IdentPacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <IdentPacket>()); this.doneChannel = new DisconnectableChannel <DonePacket, NotConnectedException>(disconnectLatchChannel, ChannelFactory.Nonblocking <DonePacket>()); this.identity = identity; this.bluetoothAdapter = bluetoothAdapter; this.neighbor = neighbor; this.broadcastMessageSerializer = broadcastMessageSerializer; this.localMerkleTree = localMerkleTree; this.remoteMerkleTree = remoteMerkleTree; }
public SelectBluetoothRemoteDevicePage() { _bluetoothAdapter = DependencyService.Resolve <IBluetoothAdapter>(); InitializeComponent(); }
public BluetoothAuthorizerUI(IBluetoothAdapter adapter) { _adapter = adapter; }
public CampfireNetClientBuilder WithBluetoothAdapter(IBluetoothAdapter bluetoothAdapter) { this.bluetoothAdapter = bluetoothAdapter; return(this); }
private void InitializeBluetoothAdapter() { var bluetoothAdapter = DependencyService.Resolve <IBluetoothAdapter>(); App.BluetoothAdapter = bluetoothAdapter; }