Skip to content

Commit 351240a

Browse files
authored
Improve listing of available targets (#96)
1 parent 3f7c39d commit 351240a

File tree

5 files changed

+184
-53
lines changed

5 files changed

+184
-53
lines changed

README.md

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,23 @@ This is convenient, for example, if this tool is being used in a automated proce
259259
nanoff -v q
260260
```
261261

262-
## List all supported boards
262+
## List targets
263263

264-
You can list the supported boards, their versions, either for stable versions or preview.
264+
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.
265+
266+
List packages available for ESP32 targets in preview version.
267+
268+
```console
269+
nanoff --listboards --platform esp32 --preview
270+
```
271+
272+
List packages available for STM32 targets in (stable version).
265273

266274
```console
267-
nanoff --listboards --platform ESP --preview
275+
nanoff --listboards --platform stm32
268276
```
269277

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

272280
## Exit codes
273281

nanoFirmwareFlasher/ExitCodes.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// See LICENSE file in the project root for full license information.
44
//
55

6+
using System;
67
using System.ComponentModel.DataAnnotations;
78

89
namespace nanoFramework.Tools.FirmwareFlasher
@@ -266,5 +267,11 @@ public enum ExitCodes
266267
/// </summary>
267268
[Display(Name = "CLR image file has wrong format.It has to be a binary file.")]
268269
E9012 = 9012,
270+
271+
/// <summary>
272+
/// Unsupported platform.
273+
/// </summary>
274+
[Display(Name = "Unsupported platform. Valid options are: esp32, stm32, cc13x2")]
275+
E9013 = 9013,
269276
}
270277
}

nanoFirmwareFlasher/FirmwarePackage.cs

Lines changed: 80 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
using System.Linq;
1212
using System.Net.Http;
1313
using System.Text.RegularExpressions;
14-
using System.Web;
1514

1615
namespace nanoFramework.Tools.FirmwareFlasher
1716
{
@@ -64,23 +63,75 @@ protected FirmwarePackage(
6463
_preview = preview;
6564
}
6665

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

73-
if (verbosity >= VerbosityLevel.Normal)
82+
// build query filter according to platform using package name
83+
if (platform != null)
7484
{
75-
Console.ForegroundColor = ConsoleColor.White;
76-
Console.Write($"Trying to find list of boards in {(preview ? "development" : "stable")} repository");
77-
if( string.IsNullOrEmpty(filter))
85+
List<string> query = new();
86+
87+
switch(platform)
7888
{
79-
Console.Write(" without filter");
89+
case SupportedPlatform.esp32:
90+
query.Add("ESP");
91+
query.Add("M5");
92+
query.Add("FEATHER");
93+
query.Add("KALUGA");
94+
break;
95+
96+
case SupportedPlatform.stm32:
97+
query.Add("ST");
98+
query.Add("ORGPAL");
99+
query.Add("NETDUINO3");
100+
query.Add("QUAIL");
101+
query.Add("GHI");
102+
query.Add("IngenuityMicro");
103+
query.Add("WeAct");
104+
query.Add("Pyb");
105+
break;
106+
107+
case SupportedPlatform.cc13x2:
108+
query.Add("TI");
109+
break;
80110
}
81-
else
111+
112+
queryFilter = string.Join(" OR ", query.Select(t => $"name:{t}"));
113+
}
114+
115+
string repoName = communityTargets ? _communityTargetsRepo : preview ? _refTargetsDevRepo : _refTargetsStableRepo;
116+
string requestUri = $"{_cloudsmithPackages}/{repoName}/?query={queryFilter}";
117+
List<CloudSmithPackageDetail> targetPackages = new();
118+
119+
if (verbosity > VerbosityLevel.Normal)
120+
{
121+
Console.ForegroundColor = ConsoleColor.White;
122+
123+
Console.Write($"Listing {platform} targets from '{repoName}' repository");
124+
125+
if (!communityTargets)
82126
{
83-
Console.Write($" with filter {filter}");
127+
if (preview)
128+
{
129+
Console.Write(" [PREVIEW]");
130+
}
131+
else
132+
{
133+
Console.Write(" [STABLE]");
134+
}
84135
}
85136

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

101152
// can't find this target
102-
return boardNames;
153+
return targetPackages;
103154
}
104155

105-
boardNames = JsonConvert.DeserializeObject<List<CloudSmithPackageDetail>>(responseBody);
156+
targetPackages = JsonConvert.DeserializeObject<List<CloudSmithPackageDetail>>(responseBody);
106157

107-
return boardNames;
158+
return targetPackages;
108159
}
109160

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

224275
if (responseBody == "[]")
225276
{
277+
// can't find this target
278+
279+
Console.WriteLine("");
280+
226281
if (Verbosity >= VerbosityLevel.Normal)
227282
{
283+
// output helpful message
284+
Console.ForegroundColor = ConsoleColor.Yellow;
285+
286+
Console.WriteLine("");
287+
Console.WriteLine("*************************** ERROR **************************");
288+
Console.WriteLine("Couldn't find this target in our Cloudsmith repositories!");
289+
Console.WriteLine("To list the available targets use this option --listtargets.");
290+
Console.WriteLine("************************************************************");
228291
Console.WriteLine("");
229-
}
230292

231-
// can't find this target
293+
Console.ForegroundColor = ConsoleColor.White;
294+
}
232295
return ExitCodes.E9005;
233296
}
234297
}

nanoFirmwareFlasher/Options.cs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ public class Options
177177
Required = false,
178178
Default = null,
179179
HelpText = "Target platform. Acceptable values are: esp32, stm32, cc13x2.")]
180-
public string Platform { get; set; }
180+
public SupportedPlatform? Platform { get; set; }
181181

182182
/// <summary>
183183
/// Allowed values:
@@ -277,6 +277,14 @@ public class Options
277277
Default = false,
278278
HelpText = "List the available boards and versions available on CloudSmith.")]
279279
public bool ListBoards { get; set; }
280+
281+
[Option(
282+
"listtargets",
283+
Required = false,
284+
Default = false,
285+
HelpText = "List the available targets and versions. --platform and --preview options apply.")]
286+
public bool ListTargets { get; set; }
287+
280288
#endregion
281289

282290

@@ -289,9 +297,9 @@ public class Options
289297
new("Update ESP32 device with custom firmware (local bin file)", new Options { TargetName = "ESP32_WROOM_32" , DeploymentImage = "<location of file>.bin"}),
290298
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}),
291299
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" }),
292-
new("List all STM32 devices connected through JTAG", new Options { Platform = "stm32", ListJtagDevices = true}),
300+
new("List all STM32 devices connected through JTAG", new Options { Platform = SupportedPlatform.esp32, ListJtagDevices = true}),
293301
new("Install STM32 JTAG drivers", new Options { InstallJtagDrivers = true}),
294-
new("List all boards", new Options { ListBoards = true, Preview = true, Platform = "ESP" }),
302+
new("List all available targets", new Options { ListTargets = true, Preview = true, Platform = SupportedPlatform.stm32 }),
295303
};
296304
}
297305

@@ -311,4 +319,11 @@ public enum PartitionTableSize
311319
_8 = 8,
312320
_16 = 16,
313321
}
322+
323+
public enum SupportedPlatform
324+
{
325+
esp32 = 0,
326+
stm32 = 1,
327+
cc13x2 = 2
328+
}
314329
}

0 commit comments

Comments
 (0)