|
1 |
| -using System; |
2 |
| -using System.Threading.Tasks; |
3 |
| -using Microsoft.Extensions.Logging; |
4 |
| -using InTheHand.BluetoothLE; |
5 |
| -using System.Collections.Generic; |
| 1 | +// using System; |
| 2 | +// using System.Threading.Tasks; |
| 3 | +// using Microsoft.Extensions.Logging; |
| 4 | +// using InTheHand.BluetoothLE; |
| 5 | +// using System.Collections.Generic; |
6 | 6 |
|
7 |
| -namespace Meshtastic.Connections; |
| 7 | +// namespace Meshtastic.Connections; |
8 | 8 |
|
9 |
| -// Placeholder for BluetoothConnection using Plugin.BLE or similar library |
10 |
| -public class BluetoothConnection : DeviceConnection |
11 |
| -{ |
12 |
| - private IDevice? _device; |
13 |
| - private IGattCharacteristic? _writeCharacteristic; |
14 |
| - private IGattCharacteristic? _readCharacteristic; |
15 |
| - private BluetoothLEScan? _scan; |
| 9 | +// // Placeholder for BluetoothConnection using Plugin.BLE or similar library |
| 10 | +// public class BluetoothConnection : DeviceConnection |
| 11 | +// { |
| 12 | +// private IDevice? _device; |
| 13 | +// private IGattCharacteristic? _writeCharacteristic; |
| 14 | +// private IGattCharacteristic? _readCharacteristic; |
| 15 | +// private BluetoothLEScan? _scan; |
16 | 16 |
|
17 |
| - public BluetoothConnection(ILogger logger) : base(logger) { } |
| 17 | +// public BluetoothConnection(ILogger logger) : base(logger) { } |
18 | 18 |
|
19 |
| - // Example: Discover and connect to a device by name (adjust as needed) |
20 |
| - public async Task<bool> ConnectAsync(string deviceName) |
21 |
| - { |
22 |
| - var devices = new List<IDevice>(); |
23 |
| - _scan = Bluetooth.ScanForDevices(async dev => |
24 |
| - { |
25 |
| - if (dev.Name == deviceName) |
26 |
| - { |
27 |
| - devices.Add(dev); |
28 |
| - await _scan.StopAsync(); |
29 |
| - } |
30 |
| - }); |
31 |
| - await _scan.Task; |
32 |
| - if (devices.Count == 0) return false; |
33 |
| - _device = devices[0]; |
34 |
| - await _device.Gatt.ConnectAsync(); |
35 |
| - // TODO: Discover and assign _writeCharacteristic and _readCharacteristic |
36 |
| - return true; |
37 |
| - } |
| 19 | +// // Example: Discover and connect to a device by name (adjust as needed) |
| 20 | +// public async Task<bool> ConnectAsync(string deviceName) |
| 21 | +// { |
| 22 | +// var devices = new List<IDevice>(); |
| 23 | +// _scan = Bluetooth.ScanForDevices(async dev => |
| 24 | +// { |
| 25 | +// if (dev.Name == deviceName) |
| 26 | +// { |
| 27 | +// devices.Add(dev); |
| 28 | +// await _scan.StopAsync(); |
| 29 | +// } |
| 30 | +// }); |
| 31 | +// await _scan.Task; |
| 32 | +// if (devices.Count == 0) return false; |
| 33 | +// _device = devices[0]; |
| 34 | +// await _device.Gatt.ConnectAsync(); |
| 35 | +// // TODO: Discover and assign _writeCharacteristic and _readCharacteristic |
| 36 | +// return true; |
| 37 | +// } |
38 | 38 |
|
39 |
| - public async Task<bool> DiscoverCharacteristicsAsync(Guid serviceUuid, Guid writeCharUuid, Guid readCharUuid) |
40 |
| - { |
41 |
| - if (_device == null) throw new InvalidOperationException("Device not connected."); |
42 |
| - var services = await _device.Gatt.GetPrimaryServicesAsync(); |
43 |
| - var service = services?.Find(s => s.Uuid == serviceUuid); |
44 |
| - if (service == null) return false; |
45 |
| - var characteristics = await service.GetCharacteristicsAsync(); |
46 |
| - _writeCharacteristic = characteristics?.Find(c => c.Uuid == writeCharUuid); |
47 |
| - _readCharacteristic = characteristics?.Find(c => c.Uuid == readCharUuid); |
48 |
| - return _writeCharacteristic != null && _readCharacteristic != null; |
49 |
| - } |
| 39 | +// public async Task<bool> DiscoverCharacteristicsAsync(Guid serviceUuid, Guid writeCharUuid, Guid readCharUuid) |
| 40 | +// { |
| 41 | +// if (_device == null) throw new InvalidOperationException("Device not connected."); |
| 42 | +// var services = await _device.Gatt.GetPrimaryServicesAsync(); |
| 43 | +// var service = services?.Find(s => s.Uuid == serviceUuid); |
| 44 | +// if (service == null) return false; |
| 45 | +// var characteristics = await service.GetCharacteristicsAsync(); |
| 46 | +// _writeCharacteristic = characteristics?.Find(c => c.Uuid == writeCharUuid); |
| 47 | +// _readCharacteristic = characteristics?.Find(c => c.Uuid == readCharUuid); |
| 48 | +// return _writeCharacteristic != null && _readCharacteristic != null; |
| 49 | +// } |
50 | 50 |
|
51 |
| - public override async Task<DeviceStateContainer> WriteToRadio(ToRadio toRadio, Func<FromRadio, DeviceStateContainer, Task<bool>> isComplete) |
52 |
| - { |
53 |
| - if (_writeCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
54 |
| - var data = toRadio.ToByteArray(); |
55 |
| - await _writeCharacteristic.WriteValueWithResponseAsync(data); |
56 |
| - // Optionally, wait for a response using ReadFromRadio |
57 |
| - return DeviceStateContainer; |
58 |
| - } |
| 51 | +// public override async Task<DeviceStateContainer> WriteToRadio(ToRadio toRadio, Func<FromRadio, DeviceStateContainer, Task<bool>> isComplete) |
| 52 | +// { |
| 53 | +// if (_writeCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
| 54 | +// var data = toRadio.ToByteArray(); |
| 55 | +// await _writeCharacteristic.WriteValueWithResponseAsync(data); |
| 56 | +// // Optionally, wait for a response using ReadFromRadio |
| 57 | +// return DeviceStateContainer; |
| 58 | +// } |
59 | 59 |
|
60 |
| - public override async Task WriteToRadio(ToRadio toRadio) |
61 |
| - { |
62 |
| - if (_writeCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
63 |
| - var data = toRadio.ToByteArray(); |
64 |
| - await _writeCharacteristic.WriteValueWithResponseAsync(data); |
65 |
| - } |
| 60 | +// public override async Task WriteToRadio(ToRadio toRadio) |
| 61 | +// { |
| 62 | +// if (_writeCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
| 63 | +// var data = toRadio.ToByteArray(); |
| 64 | +// await _writeCharacteristic.WriteValueWithResponseAsync(data); |
| 65 | +// } |
66 | 66 |
|
67 |
| - public override void Disconnect() |
68 |
| - { |
69 |
| - _device?.Gatt.Disconnect(); |
70 |
| - _device = null; |
71 |
| - _writeCharacteristic = null; |
72 |
| - _readCharacteristic = null; |
73 |
| - } |
| 67 | +// public override void Disconnect() |
| 68 | +// { |
| 69 | +// _device?.Gatt.Disconnect(); |
| 70 | +// _device = null; |
| 71 | +// _writeCharacteristic = null; |
| 72 | +// _readCharacteristic = null; |
| 73 | +// } |
74 | 74 |
|
75 |
| - public override async Task ReadFromRadio(Func<FromRadio?, DeviceStateContainer, Task<bool>> isComplete, int readTimeoutMs = Resources.DEFAULT_READ_TIMEOUT) |
76 |
| - { |
77 |
| - if (_readCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
78 |
| - var value = await _readCharacteristic.ReadValueAsync(); |
79 |
| - if (value != null && value.Length > 0) |
80 |
| - { |
81 |
| - // Example: parse value into FromRadio |
82 |
| - var fromRadioMsg = new FromDeviceMessage(Logger); |
83 |
| - var fromRadio = fromRadioMsg.ParsedFromRadio(value); |
84 |
| - await isComplete(fromRadio, DeviceStateContainer); |
85 |
| - } |
86 |
| - } |
87 |
| -} |
| 75 | +// public override async Task ReadFromRadio(Func<FromRadio?, DeviceStateContainer, Task<bool>> isComplete, int readTimeoutMs = Resources.DEFAULT_READ_TIMEOUT) |
| 76 | +// { |
| 77 | +// if (_readCharacteristic == null) throw new InvalidOperationException("Not connected to a Bluetooth device."); |
| 78 | +// var value = await _readCharacteristic.ReadValueAsync(); |
| 79 | +// if (value != null && value.Length > 0) |
| 80 | +// { |
| 81 | +// // Example: parse value into FromRadio |
| 82 | +// var fromRadioMsg = new FromDeviceMessage(Logger); |
| 83 | +// var fromRadio = fromRadioMsg.ParsedFromRadio(value); |
| 84 | +// await isComplete(fromRadio, DeviceStateContainer); |
| 85 | +// } |
| 86 | +// } |
| 87 | +// } |
0 commit comments