Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dfu firmware cleanup #527

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ protected override async ValueTask ExecuteCloudCommand()
}
catch (Exception ex)
{
Logger.LogError($"Unable to download package '{Version}': {ex.Message}");
Logger.LogError($"{ex.Message}");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -403,39 +403,22 @@ private async Task WriteEspFiles(IMeadowConnection? connection, DeviceInfo? devi

private ILibUsbDevice? GetLibUsbDeviceForCurrentEnvironment()
{
ILibUsbProvider provider;

// TODO: read the settings manager to decide which provider to use (default to non-classic)
var setting = Settings.GetAppSetting(SettingsManager.PublicSettings.LibUsb);
if (setting == "classic")
{
provider = new ClassicLibUsbProvider();
}
else
{
provider = new LibUsbProvider();
}
var provider = new LibUsbProvider();

var devices = provider.GetDevicesInBootloaderMode();

if (devices.Count == 0)
var meadowsInDFU = devices.Where(device => device.IsMeadow()).ToList();

if (meadowsInDFU.Count == 0)
{
return null;
}
else if (devices.Count == 1)

if (meadowsInDFU.Count == 1)
{
return devices[0];
return meadowsInDFU.FirstOrDefault();
}
else if (devices.Count == 2)
{ //this is a workaround for a specific case when a bad 2nd device is returned by the libusb provider on MacOS
//this fix is constrained to the known reproducible case
var serial2 = devices[1].GetDeviceSerialNumber();

if (serial2.Length > 12)
{
return devices[0];
}
}
throw new CommandException(Strings.MultipleDfuDevicesFound);
}

Expand Down
3 changes: 1 addition & 2 deletions Source/v2/Meadow.Cli/Meadow.CLI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Authors>Wilderness Labs, Inc</Authors>
<Company>Wilderness Labs, Inc</Company>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>2.0.24.0</PackageVersion>
<PackageVersion>2.0.25.0</PackageVersion>
<Platforms>AnyCPU</Platforms>
<PackageProjectUrl>http://developer.wildernesslabs.co/Meadow/Meadow.CLI/</PackageProjectUrl>
<RepositoryUrl>https://github.com/WildernessLabs/Meadow.CLI</RepositoryUrl>
Expand Down Expand Up @@ -45,7 +45,6 @@
<ProjectReference Include="..\Meadow.Dfu\Meadow.Dfu.csproj" />
<ProjectReference Include="..\Meadow.Linker\Meadow.Linker.csproj" />
<ProjectReference Include="..\Meadow.Tooling.Core\Meadow.Tooling.Core.csproj" />
<ProjectReference Include="..\Meadow.UsbLibClassic\Meadow.UsbLibClassic.csproj" />
<ProjectReference Include="..\Meadow.UsbLib\Meadow.UsbLib.csproj" />
</ItemGroup>

Expand Down
2 changes: 1 addition & 1 deletion Source/v2/Meadow.Cli/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ namespace Meadow.CLI
{
public static class Constants
{
public const string CLI_VERSION = "2.0.24.0";
public const string CLI_VERSION = "2.0.25.0";
}
}
8 changes: 4 additions & 4 deletions Source/v2/Meadow.SoftwareManager/F7FirmwareDownloadManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,20 @@ public async Task<bool> DownloadRelease(string destinationRoot, string version,
{
await DownloadAndExtractFile(new Uri(meta.DownloadURL), local_path);
}
catch
catch (Exception ex)
{
Directory.Delete(local_path, true);
throw new Exception($"Unable to download OS files for {version}");
throw new Exception($"Unable to download OS files for {version}: {ex.Message}");
}

try
{
await DownloadAndExtractFile(new Uri(meta.NetworkDownloadURL), local_path);
}
catch
catch (Exception ex)
{
Directory.Delete(local_path, true);
throw new Exception($"Unable to download Coprocessor files for {version}");
throw new Exception($"Unable to download Coprocessor files for {version}: {ex.Message}");
}

return true;
Expand Down
2 changes: 2 additions & 0 deletions Source/v2/Meadow.UsbLib.Core/ILibUsbDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ public interface ILibUsbProvider
public interface ILibUsbDevice : IDisposable
{
string GetDeviceSerialNumber();

bool IsMeadow();
}
24 changes: 22 additions & 2 deletions Source/v2/Meadow.UsbLib/LibUsbDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ namespace Meadow.LibUsb;

public class LibUsbProvider : ILibUsbProvider
{
private const int _osAddress = 0x08000000;
// public const string UsbStmName = "STM32 BOOTLOADER";
private const int UsbBootLoaderVendorID = 1155;

internal static UsbContext _context;
Expand All @@ -26,6 +24,8 @@ public List<ILibUsbDevice> GetDevicesInBootloaderMode()
.Select(d => new LibUsbDevice(d))
.ToList<ILibUsbDevice>();

UsbDevice device;

return _devices;
}

Expand Down Expand Up @@ -56,5 +56,25 @@ public string GetDeviceSerialNumber()

return serialNumber;
}

public bool IsMeadow()
{
if (_device.VendorId != 1155)
{
return false;
}
if (GetDeviceSerialNumber().Length > 12)
{
return false;
}
if (_device as UsbDevice is { } usbDevice)
{
if (usbDevice.ActiveConfigDescriptor.Interfaces.Count != 4)
{
return false;
}
}
return true;
}
}
}
17 changes: 15 additions & 2 deletions Source/v2/Meadow.UsbLibClassic/ClassicLibUsbDevice.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ namespace Meadow.LibUsb;

public class ClassicLibUsbProvider : ILibUsbProvider
{
// private const int _osAddress = 0x08000000;
private const string UsbStmName = "STM32 BOOTLOADER";
private const int UsbBootLoaderVendorID = 1155;

public List<ILibUsbDevice> GetDevicesInBootloaderMode()
{
Expand Down Expand Up @@ -63,4 +63,17 @@ public string GetDeviceSerialNumber()

return string.Empty;
}
}

public bool IsMeadow()
{
if (_device.Vid != 1155)
{
return false;
}
if (GetDeviceSerialNumber().Length > 12)
{
return false;
}
return true;
}
}
Loading