From 1b4ca52b28f64c5d5cafe644b56b42aa375148c3 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 14 Mar 2024 22:35:17 -0700 Subject: [PATCH 1/4] Fix check when no args are passed --- Source/v2/Meadow.Cli/Commands/Current/Config/ConfigCommand.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Config/ConfigCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Config/ConfigCommand.cs index 98a1f516..a3ed56e7 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Config/ConfigCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Config/ConfigCommand.cs @@ -40,6 +40,7 @@ protected override ValueTask ExecuteCommand() { switch (Settings?.Length) { + case null: case 0: // not valid throw new CommandException($"No setting provided"); From 8c6a38bc5734173d9c70c453a6d106e1b56de790 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 14 Mar 2024 22:35:30 -0700 Subject: [PATCH 2/4] Bump version --- Source/v2/Meadow.Cli/Meadow.CLI.csproj | 2 +- Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs | 9 ++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/Source/v2/Meadow.Cli/Meadow.CLI.csproj b/Source/v2/Meadow.Cli/Meadow.CLI.csproj index 18f81835..b17e2437 100644 --- a/Source/v2/Meadow.Cli/Meadow.CLI.csproj +++ b/Source/v2/Meadow.Cli/Meadow.CLI.csproj @@ -10,7 +10,7 @@ Wilderness Labs, Inc Wilderness Labs, Inc true - 2.0.25.0 + 2.0.27.0 AnyCPU http://developer.wildernesslabs.co/Meadow/Meadow.CLI/ https://github.com/WildernessLabs/Meadow.CLI diff --git a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs index 82470def..4abd82f0 100644 --- a/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs +++ b/Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs @@ -2,10 +2,9 @@ [assembly: System.Reflection.AssemblyVersion(Meadow.CLI.Constants.CLI_VERSION)] [assembly: System.Reflection.AssemblyInformationalVersion(Meadow.CLI.Constants.CLI_VERSION)] -namespace Meadow.CLI +namespace Meadow.CLI; + +public static class Constants { - public static class Constants - { - public const string CLI_VERSION = "2.0.25.0"; - } + public const string CLI_VERSION = "2.0.27.0"; } \ No newline at end of file From 039b176994454b41ac92a8a286983c7701571c6d Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 14 Mar 2024 22:35:39 -0700 Subject: [PATCH 3/4] Minor cleanup --- Source/v2/Meadow.UsbLib/LibUsbDevice.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Source/v2/Meadow.UsbLib/LibUsbDevice.cs b/Source/v2/Meadow.UsbLib/LibUsbDevice.cs index 7b7c2233..96cb39f9 100644 --- a/Source/v2/Meadow.UsbLib/LibUsbDevice.cs +++ b/Source/v2/Meadow.UsbLib/LibUsbDevice.cs @@ -24,8 +24,6 @@ public List GetDevicesInBootloaderMode() .Select(d => new LibUsbDevice(d)) .ToList(); - UsbDevice device; - return _devices; } From 50c804056e26f875eba41742dc930727f842ee27 Mon Sep 17 00:00:00 2001 From: Adrian Stevens Date: Thu, 14 Mar 2024 22:37:38 -0700 Subject: [PATCH 4/4] Re-add passing serial number for DFU flash and isolate hack for Mark's Mac --- .../Current/Firmware/FirmwareWriteCommand.cs | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs index a426aa54..0e0f080e 100644 --- a/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs +++ b/Source/v2/Meadow.Cli/Commands/Current/Firmware/FirmwareWriteCommand.cs @@ -4,6 +4,7 @@ using Meadow.LibUsb; using Meadow.Software; using Microsoft.Extensions.Logging; +using System.Runtime.InteropServices; namespace Meadow.CLI.Commands.DeviceManagement; @@ -169,7 +170,9 @@ protected override async ValueTask ExecuteCommand() } // do we have a dfu device attached, or is DFU specified? - var dfuDevice = GetLibUsbDeviceForCurrentEnvironment(); + var provider = new LibUsbProvider(); + var dfuDevice = GetLibUsbDeviceForCurrentEnvironment(provider); + bool ignoreSerial = IgnoreSerialNumberForDfu(provider); if (dfuDevice != null) { @@ -195,7 +198,7 @@ protected override async ValueTask ExecuteCommand() try { - await WriteOsWithDfu(dfuDevice, osFileWithBootloader!); + await WriteOsWithDfu(dfuDevice!, osFileWithBootloader!, ignoreSerial); } finally { @@ -337,13 +340,7 @@ private async Task FindMeadowConnection(IList portsTo if (connection == null) { - var newPort = await WaitForNewSerialPort(initialPorts); - - if (newPort == null) - { - throw CommandException.MeadowDeviceNotFound; - } - + var newPort = await WaitForNewSerialPort(initialPorts) ?? throw CommandException.MeadowDeviceNotFound; connection = await GetCurrentConnection(true); Logger?.LogInformation($"{Strings.MeadowFoundAt} {newPort}"); @@ -401,9 +398,9 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi } } - private ILibUsbDevice? GetLibUsbDeviceForCurrentEnvironment() + private ILibUsbDevice? GetLibUsbDeviceForCurrentEnvironment(LibUsbProvider? provider) { - var provider = new LibUsbProvider(); + provider ??= new LibUsbProvider(); var devices = provider.GetDevicesInBootloaderMode(); @@ -414,8 +411,8 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi return null; } - if (meadowsInDFU.Count == 1) - { + if (meadowsInDFU.Count == 1 || IgnoreSerialNumberForDfu(provider)) + { //IgnoreSerialNumberForDfu is a macOS-specific hack for Mark's machine return meadowsInDFU.FirstOrDefault(); } @@ -451,22 +448,13 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi return package; } - private async Task WriteOsWithDfu(ILibUsbDevice? libUsbDevice, string osFile) + private async Task WriteOsWithDfu(ILibUsbDevice libUsbDevice, string osFile, bool ignoreSerialNumber = false) { - // get the device's serial number via DFU - we'll need it to find the device after it resets - if (libUsbDevice == null) - { - libUsbDevice = GetLibUsbDeviceForCurrentEnvironment(); - - if (libUsbDevice == null) - { - throw new CommandException(Strings.NoDfuDeviceDetected); - } - } + string serialNumber; try { //validate device - var serialNumber = libUsbDevice.GetDeviceSerialNumber(); + serialNumber = libUsbDevice.GetDeviceSerialNumber(); } catch { @@ -475,9 +463,14 @@ private async Task WriteOsWithDfu(ILibUsbDevice? libUsbDevice, string osFile) try { + if (ignoreSerialNumber) + { + serialNumber = string.Empty; + } + await DfuUtils.FlashFile( osFile, - string.Empty, //serial number isn't needed to flash the OS and may cause issues on MacOS + serialNumber, logger: Logger, format: DfuUtils.DfuFlashFormat.ConsoleOut); } @@ -526,4 +519,22 @@ private async Task> WaitForNewSerialPorts(IList? ignorePor return ports.FirstOrDefault(); } + + private bool IgnoreSerialNumberForDfu(LibUsbProvider provider) + { //hack check for Mark's Mac + if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) + { + var devices = provider.GetDevicesInBootloaderMode(); + + if (devices.Count == 2) + { + if (devices[0].GetDeviceSerialNumber().Length > 12 || devices[1].GetDeviceSerialNumber().Length > 12) + { + return true; + } + } + } + + return false; + } } \ No newline at end of file