diff --git a/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs b/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs index 4bf7dea..1241c93 100644 --- a/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs +++ b/src/SharpBrick.PoweredUp.Cli/Commands/DevicesList.cs @@ -20,11 +20,11 @@ public DevicesList(ILegoWirelessProtocol protocol, DiscoverPorts discoverPorts) this.protocol = protocol ?? throw new ArgumentNullException(nameof(protocol)); this.discoverPorts = discoverPorts ?? throw new ArgumentNullException(nameof(discoverPorts)); } - public async Task ExecuteAsync() + public async Task ExecuteAsync(SystemType knownSystemType) { Console.WriteLine("Discover Ports. Receiving Messages ..."); - await protocol.ConnectAsync(); // registering to bluetooth notification + await protocol.ConnectAsync(knownSystemType); // registering to bluetooth notification await Task.Delay(2000); // await ports to be announced initially by device. diff --git a/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs b/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs index c81859a..6baa905 100644 --- a/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs +++ b/src/SharpBrick.PoweredUp.Cli/Commands/DumpStaticPortInfo.cs @@ -18,11 +18,11 @@ public DumpStaticPortInfo(ILegoWirelessProtocol protocol, DiscoverPorts discover this.protocol = protocol ?? throw new ArgumentNullException(nameof(protocol)); this.discoverPorts = discoverPorts ?? throw new ArgumentNullException(nameof(discoverPorts)); } - public async Task ExecuteAsync(byte portId) + public async Task ExecuteAsync(SystemType knownSystemType, byte portId) { Console.WriteLine($"Discover Port {portId}. Receiving Messages ..."); - await protocol.ConnectAsync(); // registering to bluetooth notification + await protocol.ConnectAsync(knownSystemType); // registering to bluetooth notification await Task.Delay(2000); // await ports to be announced initially by device. diff --git a/src/SharpBrick.PoweredUp.Cli/Program.cs b/src/SharpBrick.PoweredUp.Cli/Program.cs index a73583c..0641356 100644 --- a/src/SharpBrick.PoweredUp.Cli/Program.cs +++ b/src/SharpBrick.PoweredUp.Cli/Program.cs @@ -34,7 +34,7 @@ static async Task Main(string[] args) var enableTrace = bool.TryParse(traceOption.Value(), out var x) ? x : false; var serviceProvider = CreateServiceProvider(enableTrace); - ulong bluetoothAddress = FindAndSelectHub(serviceProvider.GetService()); + (ulong bluetoothAddress, SystemType systemType) = FindAndSelectHub(serviceProvider.GetService()); if (bluetoothAddress == 0) return; @@ -50,7 +50,7 @@ static async Task Main(string[] args) var deviceListCli = scopedServiceProvider.GetService(); // ServiceLocator ok: transient factory - await deviceListCli.ExecuteAsync(); + await deviceListCli.ExecuteAsync(systemType); } }); }); @@ -67,7 +67,7 @@ static async Task Main(string[] args) var enableTrace = bool.TryParse(traceOption.Value(), out var x) ? x : false; var serviceProvider = CreateServiceProvider(enableTrace); - ulong bluetoothAddress = FindAndSelectHub(serviceProvider.GetService()); + (ulong bluetoothAddress, SystemType systemType) = FindAndSelectHub(serviceProvider.GetService()); if (bluetoothAddress == 0) return; @@ -85,7 +85,7 @@ static async Task Main(string[] args) var port = byte.Parse(portOption.Value()); - await dumpStaticPortInfoCommand.ExecuteAsync(port); + await dumpStaticPortInfoCommand.ExecuteAsync(systemType, port); } }); }); @@ -125,9 +125,10 @@ public static async Task AddTraceWriterAsync(IServiceProvider serviceProvider, b } } - private static ulong FindAndSelectHub(IPoweredUpBluetoothAdapter poweredUpBluetoothAdapter) + private static (ulong bluetoothAddress, SystemType systemType) FindAndSelectHub(IPoweredUpBluetoothAdapter poweredUpBluetoothAdapter) { - ulong result = 0; + ulong resultBluetooth = 0; + SystemType resultSystemType = default; var devices = new ConcurrentBag<(int key, ulong bluetoothAddresss, PoweredUpHubManufacturerData deviceType)>(); var cts = new CancellationTokenSource(); int idx = 1; @@ -155,15 +156,16 @@ private static ulong FindAndSelectHub(IPoweredUpBluetoothAdapter poweredUpBlueto { var selected = devices.FirstOrDefault(kv => kv.key == key); - result = selected.bluetoothAddresss; // default is 0 + resultBluetooth = selected.bluetoothAddresss; // default is 0 + resultSystemType = (SystemType)selected.deviceType; - if (result != default) + if (resultBluetooth != default) { Console.WriteLine($"Selected {selected.deviceType} with key {selected.key}"); } } - return result; + return (resultBluetooth, resultSystemType); } } }