Skip to content

Commit 1ed98c2

Browse files
authored
Global refactoring of the solution (#54)
1 parent b284e7e commit 1ed98c2

15 files changed

+278
-290
lines changed

azure-pipelines.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,10 @@ jobs:
150150
- template: azure-pipelines-templates/install-nuget.yml@templates
151151

152152
- task: UseDotNet@2
153-
displayName: Install .NET Core SDK
153+
displayName: Install .NET SDK
154154
inputs:
155155
packageType: sdk
156-
version: 3.1.101
156+
version: 5.0.300
157157

158158
- task: DotNetCoreCLI@2
159159
displayName: Restore NuGet packages
@@ -164,7 +164,7 @@ jobs:
164164
feedsToUse: config
165165
nugetConfigPath: NuGet.Config
166166

167-
- script: dotnet build -r win-x64 -c $(BuildConfiguration) /p:PublicRelease=true --no-restore /t:build,pack
167+
- script: dotnet build -c $(BuildConfiguration) /p:PublicRelease=true --no-restore /t:build,pack
168168
displayName: Build NuGet package
169169

170170
- script: dotnet pack --runtime win-x64 -c $(BuildConfiguration) -p:PublicRelease=true -p:PackGlobalTool=true --no-restore

nanoFirmwareFlasher/CC13x26x2Device.cs

Lines changed: 35 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,14 @@ public CC13x26x2Device(string configurationFile)
4242
/// Flash the HEX supplied to the connected device.
4343
/// </summary>
4444
/// <param name="files"></param>
45-
public ExitCodes FlashHexFiles(IEnumerable<string> files)
45+
public ExitCodes FlashHexFiles(IList<string> files)
4646
{
4747
// check file existence
48-
foreach (string f in files)
48+
if (files.Any(f => !File.Exists(f)))
4949
{
50-
if (!File.Exists(f))
51-
{
52-
return ExitCodes.E5003;
53-
}
50+
return ExitCodes.E5003;
5451
}
5552

56-
string cliOuput;
57-
5853
// TODO
5954
// use the -d switch
6055
//// erase flash
@@ -65,9 +60,9 @@ public ExitCodes FlashHexFiles(IEnumerable<string> files)
6560
// Console.Write("Mass erase device...");
6661
// }
6762

68-
// cliOuput = RunUniflashCli($"-c SN={DeviceId} UR -ME");
63+
// cliOutput = RunUniflashCli($"-c SN={DeviceId} UR -ME");
6964

70-
// if (!cliOuput.Contains("Flash memory erased."))
65+
// if (!cliOutput.Contains("Flash memory erased."))
7166
// {
7267
// return ExitCodes.E5005;
7368
// }
@@ -102,9 +97,9 @@ public ExitCodes FlashHexFiles(IEnumerable<string> files)
10297
Console.WriteLine($"{Path.GetFileName(hexFile)}");
10398
}
10499

105-
cliOuput = RunUniflashCli($" flash -c {ConfigurationFile} -f -v {hexFile}");
100+
var cliOutput = RunUniflashCli($" flash -c {ConfigurationFile} -f -v {hexFile}");
106101

107-
if (!cliOuput.Contains("Program verification successful"))
102+
if (!cliOutput.Contains("Program verification successful"))
108103
{
109104
return ExitCodes.E5006;
110105
}
@@ -127,21 +122,18 @@ public ExitCodes FlashHexFiles(IEnumerable<string> files)
127122
/// </summary>
128123
/// <param name="files"></param>
129124
/// <param name="addresses"></param>
130-
public ExitCodes FlashBinFiles(IEnumerable<string> files, IEnumerable<string> addresses)
125+
public ExitCodes FlashBinFiles(IList<string> files, IList<string> addresses)
131126
{
132127
// check file existence
133-
foreach (string f in files)
128+
if (files.Any(f => !File.Exists(f)))
134129
{
135-
if (!File.Exists(f))
136-
{
137-
return ExitCodes.E5003;
138-
}
130+
return ExitCodes.E5003;
139131
}
140132

141133
// check address(es)
142134

143135
// need to match files count
144-
if(files.Count() != addresses.Count())
136+
if(files.Count != addresses.Count)
145137
{
146138
return ExitCodes.E5009;
147139
}
@@ -152,26 +144,21 @@ public ExitCodes FlashBinFiles(IEnumerable<string> files, IEnumerable<string> ad
152144
{
153145
return ExitCodes.E5007;
154146
}
155-
else
147+
148+
// format too
149+
if (!address.StartsWith("0x"))
156150
{
157-
// format too
158-
if (!address.StartsWith("0x"))
159-
{
160-
return ExitCodes.E5008;
161-
}
151+
return ExitCodes.E5008;
152+
}
162153

163-
// try parse
164-
// need to remove the leading 0x and to specify that hexadecimal values are allowed
165-
int dummyAddress;
166-
if (!int.TryParse(address.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out dummyAddress))
167-
{
168-
return ExitCodes.E5008;
169-
}
154+
// try parse
155+
// need to remove the leading 0x and to specify that hexadecimal values are allowed
156+
if (!int.TryParse(address.Substring(2), System.Globalization.NumberStyles.AllowHexSpecifier, System.Globalization.CultureInfo.InvariantCulture, out int _))
157+
{
158+
return ExitCodes.E5008;
170159
}
171160
}
172161

173-
string cliOuput;
174-
175162
// TODO
176163
// use the -d switch
177164
//// erase flash
@@ -182,9 +169,9 @@ public ExitCodes FlashBinFiles(IEnumerable<string> files, IEnumerable<string> ad
182169
// Console.Write("Mass erase device...");
183170
// }
184171

185-
// cliOuput = RunUniflashCli($"-b");
172+
// cliOutput = RunUniflashCli($"-b");
186173

187-
// if (!cliOuput.Contains("Flash memory erased."))
174+
// if (!cliOutput.Contains("Flash memory erased."))
188175
// {
189176
// Console.WriteLine("");
190177
// return ExitCodes.E5005;
@@ -221,9 +208,9 @@ public ExitCodes FlashBinFiles(IEnumerable<string> files, IEnumerable<string> ad
221208
Console.WriteLine($"{Path.GetFileName(binFile)} @ {addresses.ElementAt(index)}");
222209
}
223210

224-
cliOuput = RunUniflashCli($" flash -c {ConfigurationFile} -f -v {binFile},{addresses.ElementAt(index++)}");
211+
var cliOutput = RunUniflashCli($" flash -c {ConfigurationFile} -f -v {binFile},{addresses.ElementAt(index++)}");
225212

226-
if (!cliOuput.Contains("Program verification successful"))
213+
if (!cliOutput.Contains("Program verification successful"))
227214
{
228215
return ExitCodes.E5006;
229216
}
@@ -247,9 +234,9 @@ public ExitCodes FlashBinFiles(IEnumerable<string> files, IEnumerable<string> ad
247234
public ExitCodes ResetMcu()
248235
{
249236
// try to connect to device with RESET
250-
var cliOuput = RunUniflashCli($" flash -c {ConfigurationFile} -r 0");
237+
var cliOutput = RunUniflashCli($" flash -c {ConfigurationFile} -r 0");
251238

252-
if (!cliOuput.Contains("CPU Reset is issued"))
239+
if (!cliOutput.Contains("CPU Reset is issued"))
253240
{
254241
Console.WriteLine("");
255242
return ExitCodes.E5010;
@@ -271,12 +258,15 @@ private static string RunUniflashCli(string arguments)
271258
{
272259
try
273260
{
274-
Process uniflashCli = new Process();
275-
uniflashCli.StartInfo = new ProcessStartInfo(Path.Combine(Program.ExecutingPath, "uniflash\\DebugServer\\bin", "DSLite.exe"), arguments)
261+
var uniflashCli = new Process
276262
{
277-
WorkingDirectory = Path.Combine(Program.ExecutingPath, "uniflash"),
278-
UseShellExecute = false,
279-
RedirectStandardOutput = true,
263+
StartInfo = new ProcessStartInfo(
264+
Path.Combine(Program.ExecutingPath, "uniflash\\DebugServer\\bin", "DSLite.exe"), arguments)
265+
{
266+
WorkingDirectory = Path.Combine(Program.ExecutingPath, "uniflash"),
267+
UseShellExecute = false,
268+
RedirectStandardOutput = true,
269+
}
280270
};
281271

282272

nanoFirmwareFlasher/CC13x26x2Firmware.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace nanoFramework.Tools.FirmwareFlasher
1313
/// </summary>
1414
internal class CC13x26x2Firmware : FirmwarePackage
1515
{
16-
public string nanoCLRFile { get; internal set; }
16+
public string nanoCLRFile { get; private set; }
1717

1818
public CC13x26x2Firmware(string targetName, string fwVersion, bool stable)
1919
:base(targetName, fwVersion, stable)

nanoFirmwareFlasher/CC13x26x2Operations.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
using System.Diagnostics;
99
using System.IO;
1010
using System.Linq;
11-
using System.Threading.Tasks;
1211

1312
namespace nanoFramework.Tools.FirmwareFlasher
1413
{
@@ -24,7 +23,6 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
2423
VerbosityLevel verbosity)
2524
{
2625
bool isApplicationBinFile = false;
27-
CC13x26x2Device ccDevice;
2826

2927
// if a target name wasn't specified use the default (and only available) ESP32 target
3028
if (string.IsNullOrEmpty(targetName))
@@ -101,10 +99,9 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
10199
return ExitCodes.E7000;
102100
}
103101

104-
ccDevice = new CC13x26x2Device(configFile);
102+
var ccDevice = new CC13x26x2Device(configFile) {Verbosity = verbosity};
105103

106104
// set verbosity
107-
ccDevice.Verbosity = verbosity;
108105

109106
ExitCodes programResult = ExitCodes.OK;
110107
// write HEX files to flash
@@ -116,7 +113,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
116113
if (programResult == ExitCodes.OK && isApplicationBinFile)
117114
{
118115
// now program the application file
119-
programResult = ccDevice.FlashBinFiles(new List<string>() { applicationPath }, new List<string>() { deploymentAddress });
116+
programResult = ccDevice.FlashBinFiles(new [] { applicationPath }, new [] { deploymentAddress });
120117
}
121118

122119
if (updateFw)
@@ -134,12 +131,16 @@ internal static ExitCodes InstallXds110Drivers(VerbosityLevel verbosityLevel)
134131
{
135132
string driversPath = Path.Combine(Program.ExecutingPath, "uniflash\\emulation\\windows\\xds110_drivers");
136133

137-
Process uniflashCli = new Process();
138-
uniflashCli.StartInfo = new ProcessStartInfo(Path.Combine(Program.ExecutingPath, "uniflash", "dpinst_64_eng.exe"), $"/SE /SW /SA /PATH {driversPath}")
134+
var uniflashCli = new Process
139135
{
140-
WorkingDirectory = Path.Combine(Program.ExecutingPath, "uniflash"),
141-
// need to use ShellExecute to show elevate prompt
142-
UseShellExecute = true,
136+
StartInfo = new ProcessStartInfo(
137+
Path.Combine(Program.ExecutingPath, "uniflash", "dpinst_64_eng.exe"),
138+
$"/SE /SW /SA /PATH {driversPath}")
139+
{
140+
WorkingDirectory = Path.Combine(Program.ExecutingPath, "uniflash"),
141+
// need to use ShellExecute to show elevate prompt
142+
UseShellExecute = true,
143+
}
143144
};
144145

145146
// execution command and...

nanoFirmwareFlasher/Esp32Firmware.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal class Esp32Firmware : FirmwarePackage
1919
/// <summary>
2020
/// ESP32 nanoCLR is available for 2MB, 4MB, 8MB and 16MB flash sizes
2121
/// </summary>
22-
internal List<int> SupportedFlashSizes => new List<int> { 0x200000, 0x400000, 0x800000, 0x1000000 };
22+
private List<int> SupportedFlashSizes => new() { 0x200000, 0x400000, 0x800000, 0x1000000 };
2323

2424
internal string BootloaderPath;
2525

@@ -30,7 +30,7 @@ internal class Esp32Firmware : FirmwarePackage
3030
/// <summary>
3131
/// Address of the deployment partition.
3232
/// </summary>
33-
internal int DeploymentPartionAddress => 0x110000;
33+
internal int DeploymentPartitionAddress => 0x110000;
3434

3535
public Esp32Firmware(string targetName, string fwVersion, bool stable, PartitionTableSize? partitionTableSize)
3636
:base(targetName, fwVersion, stable)
@@ -67,7 +67,7 @@ internal async System.Threading.Tasks.Task<ExitCodes> DownloadAndExtractAsync(in
6767
BootloaderPath = "bootloader.bin";
6868

6969
// get ESP32 partitions
70-
FlashPartitions = new Dictionary<int, string>()
70+
FlashPartitions = new Dictionary<int, string>
7171
{
7272
// bootloader goes to 0x1000
7373
{ 0x1000, Path.Combine(LocationPath, BootloaderPath) },

nanoFirmwareFlasher/Esp32Operations.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
9292
PartitionTableSize? partitionTableSize,
9393
VerbosityLevel verbosity)
9494
{
95-
ExitCodes operationResult = ExitCodes.OK;
95+
var operationResult = ExitCodes.OK;
9696
uint address = 0;
9797

9898
// if a target name wasn't specified use the default (and only available) ESP32 target
@@ -142,7 +142,7 @@ internal static async System.Threading.Tasks.Task<ExitCodes> UpdateFirmwareAsync
142142
firmware.FlashPartitions = new Dictionary<int, string>()
143143
{
144144
{
145-
updateFw ? firmware.DeploymentPartionAddress : (int)address,
145+
updateFw ? firmware.DeploymentPartitionAddress : (int)address,
146146
applicationBinary
147147
}
148148
};

0 commit comments

Comments
 (0)