Skip to content

Commit

Permalink
Improve listing of available targets (#96)
Browse files Browse the repository at this point in the history
  • Loading branch information
josesimoes authored Nov 27, 2021
1 parent 3f7c39d commit 351240a
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 53 deletions.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,23 @@ This is convenient, for example, if this tool is being used in a automated proce
nanoff -v q
```

## List all supported boards
## List targets

You can list the supported boards, their versions, either for stable versions or preview.
You can list the supported targets, their versions, either for stable versions or preview. `--platform` allows you to filter for a platform. `--preview` filters the query to show only preview versions.

List packages available for ESP32 targets in preview version.

```console
nanoff --listboards --platform esp32 --preview
```

List packages available for STM32 targets in (stable version).

```console
nanoff --listboards --platform ESP --preview
nanoff --listboards --platform stm32
```

If you just use `--listboards` options, you'll get the list of all the stable versions for all boards. `--platform` allows you to filter.
If you just use `--listtargets` switch, you'll get the list of all the stable packages for all targets.

## Exit codes

Expand Down
7 changes: 7 additions & 0 deletions nanoFirmwareFlasher/ExitCodes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See LICENSE file in the project root for full license information.
//

using System;
using System.ComponentModel.DataAnnotations;

namespace nanoFramework.Tools.FirmwareFlasher
Expand Down Expand Up @@ -266,5 +267,11 @@ public enum ExitCodes
/// </summary>
[Display(Name = "CLR image file has wrong format.It has to be a binary file.")]
E9012 = 9012,

/// <summary>
/// Unsupported platform.
/// </summary>
[Display(Name = "Unsupported platform. Valid options are: esp32, stm32, cc13x2")]
E9013 = 9013,
}
}
97 changes: 80 additions & 17 deletions nanoFirmwareFlasher/FirmwarePackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
using System.Linq;
using System.Net.Http;
using System.Text.RegularExpressions;
using System.Web;

namespace nanoFramework.Tools.FirmwareFlasher
{
Expand Down Expand Up @@ -64,23 +63,75 @@ protected FirmwarePackage(
_preview = preview;
}

public static List<CloudSmithPackageDetail> GetBoardList(bool communityTargets, bool preview, string filter, VerbosityLevel verbosity)
/// <summary>
/// Get a list of all available targets from Cloudsmith repository.
/// </summary>
/// <param name="communityTargets"><see langword="true"/> to list community targets.<see langword="false"/> to list reference targets.</param>
/// <param name="preview">Option for preview version.</param>
/// <param name="platform">Platform code to use on search.</param>
/// <param name="verbosity">VerbosityLevel to use when outputting progress and error messages.</param>
/// <returns>List of <see cref="CloudSmithPackageDetail"/> with details on target firmware packages.</returns>
public static List<CloudSmithPackageDetail> GetTargetList(
bool communityTargets,
bool preview,
SupportedPlatform? platform,
VerbosityLevel verbosity)
{
string repoName = communityTargets ? _communityTargetsRepo : preview ? _refTargetsDevRepo : _refTargetsStableRepo;
string requestUri = $"{_cloudsmithPackages}/{repoName}/?query={filter}";
List<CloudSmithPackageDetail> boardNames = new List<CloudSmithPackageDetail>();
string queryFilter = string.Empty;

if (verbosity >= VerbosityLevel.Normal)
// build query filter according to platform using package name
if (platform != null)
{
Console.ForegroundColor = ConsoleColor.White;
Console.Write($"Trying to find list of boards in {(preview ? "development" : "stable")} repository");
if( string.IsNullOrEmpty(filter))
List<string> query = new();

switch(platform)
{
Console.Write(" without filter");
case SupportedPlatform.esp32:
query.Add("ESP");
query.Add("M5");
query.Add("FEATHER");
query.Add("KALUGA");
break;

case SupportedPlatform.stm32:
query.Add("ST");
query.Add("ORGPAL");
query.Add("NETDUINO3");
query.Add("QUAIL");
query.Add("GHI");
query.Add("IngenuityMicro");
query.Add("WeAct");
query.Add("Pyb");
break;

case SupportedPlatform.cc13x2:
query.Add("TI");
break;
}
else

queryFilter = string.Join(" OR ", query.Select(t => $"name:{t}"));
}

string repoName = communityTargets ? _communityTargetsRepo : preview ? _refTargetsDevRepo : _refTargetsStableRepo;
string requestUri = $"{_cloudsmithPackages}/{repoName}/?query={queryFilter}";
List<CloudSmithPackageDetail> targetPackages = new();

if (verbosity > VerbosityLevel.Normal)
{
Console.ForegroundColor = ConsoleColor.White;

Console.Write($"Listing {platform} targets from '{repoName}' repository");

if (!communityTargets)
{
Console.Write($" with filter {filter}");
if (preview)
{
Console.Write(" [PREVIEW]");
}
else
{
Console.Write(" [STABLE]");
}
}

Console.WriteLine("...");
Expand All @@ -99,12 +150,12 @@ public static List<CloudSmithPackageDetail> GetBoardList(bool communityTargets,
}

// can't find this target
return boardNames;
return targetPackages;
}

boardNames = JsonConvert.DeserializeObject<List<CloudSmithPackageDetail>>(responseBody);
targetPackages = JsonConvert.DeserializeObject<List<CloudSmithPackageDetail>>(responseBody);

return boardNames;
return targetPackages;
}

/// <summary>
Expand Down Expand Up @@ -223,12 +274,24 @@ protected async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync()

if (responseBody == "[]")
{
// can't find this target

Console.WriteLine("");

if (Verbosity >= VerbosityLevel.Normal)
{
// output helpful message
Console.ForegroundColor = ConsoleColor.Yellow;

Console.WriteLine("");
Console.WriteLine("*************************** ERROR **************************");
Console.WriteLine("Couldn't find this target in our Cloudsmith repositories!");
Console.WriteLine("To list the available targets use this option --listtargets.");
Console.WriteLine("************************************************************");
Console.WriteLine("");
}

// can't find this target
Console.ForegroundColor = ConsoleColor.White;
}
return ExitCodes.E9005;
}
}
Expand Down
21 changes: 18 additions & 3 deletions nanoFirmwareFlasher/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ public class Options
Required = false,
Default = null,
HelpText = "Target platform. Acceptable values are: esp32, stm32, cc13x2.")]
public string Platform { get; set; }
public SupportedPlatform? Platform { get; set; }

/// <summary>
/// Allowed values:
Expand Down Expand Up @@ -277,6 +277,14 @@ public class Options
Default = false,
HelpText = "List the available boards and versions available on CloudSmith.")]
public bool ListBoards { get; set; }

[Option(
"listtargets",
Required = false,
Default = false,
HelpText = "List the available targets and versions. --platform and --preview options apply.")]
public bool ListTargets { get; set; }

#endregion


Expand All @@ -289,9 +297,9 @@ public class Options
new("Update ESP32 device with custom firmware (local bin file)", new Options { TargetName = "ESP32_WROOM_32" , DeploymentImage = "<location of file>.bin"}),
new("Update specific STM32 device (ST_STM32F769I_DISCOVERY) with latest available firmware (preview version), using JTAG interface", new Options { TargetName = "ST_STM32F769I_DISCOVERY" , Update = true, Preview = true, JtagUpdate = true}),
new("Update specific STM32 device (NETDUINO3_WIFI) with latest available firmware (preview version), device is connected through DFU with Id 3380386D3134", new Options { TargetName = "NETDUINO3_WIFI", Update = true, Preview = true, DfuDeviceId = "3380386D3134" }),
new("List all STM32 devices connected through JTAG", new Options { Platform = "stm32", ListJtagDevices = true}),
new("List all STM32 devices connected through JTAG", new Options { Platform = SupportedPlatform.esp32, ListJtagDevices = true}),
new("Install STM32 JTAG drivers", new Options { InstallJtagDrivers = true}),
new("List all boards", new Options { ListBoards = true, Preview = true, Platform = "ESP" }),
new("List all available targets", new Options { ListTargets = true, Preview = true, Platform = SupportedPlatform.stm32 }),
};
}

Expand All @@ -311,4 +319,11 @@ public enum PartitionTableSize
_8 = 8,
_16 = 16,
}

public enum SupportedPlatform
{
esp32 = 0,
stm32 = 1,
cc13x2 = 2
}
}
Loading

0 comments on commit 351240a

Please sign in to comment.