|
1 | 1 | using nanoFramework.Tools.Debugger; |
2 | | -using System; |
3 | | -using System.Collections.Generic; |
4 | | -using System.Linq; |
5 | | -using System.Text; |
6 | | -using System.Threading.Tasks; |
7 | | - |
8 | | -namespace nanoFramework.Tools.FirmwareFlasher |
9 | | -{ |
10 | | - /// <summary> |
11 | | - /// Class to manage different operations specific to the nano devices. |
12 | | - /// </summary> |
13 | | - public class NanoDeviceManager : IManager |
14 | | - { |
15 | | - private readonly Options _options; |
16 | | - private readonly VerbosityLevel _verbosityLevel; |
17 | | - |
18 | | - public NanoDeviceManager(Options options, VerbosityLevel verbosityLevel) |
19 | | - { |
20 | | - if (options == null) |
21 | | - { |
22 | | - throw new ArgumentNullException(nameof(options)); |
23 | | - } |
24 | | - |
25 | | - if (options.Platform != SupportedPlatform.esp32) |
26 | | - { |
27 | | - throw new NotSupportedException($"{nameof(options)} - {options.Platform}"); |
28 | | - } |
29 | | - |
30 | | - _options = options; |
31 | | - _verbosityLevel = verbosityLevel; |
32 | | - } |
33 | | - |
34 | | - /// <inheritdoc /> |
35 | | - public async Task<ExitCodes> ProcessAsync() |
36 | | - { |
37 | | - // COM port is mandatory for nano device operations |
38 | | - if (string.IsNullOrEmpty(_options.SerialPort)) |
39 | | - { |
40 | | - return ExitCodes.E6001; |
41 | | - } |
42 | | - |
43 | | - NanoDeviceOperations _nanoDeviceOperations = new NanoDeviceOperations(); |
44 | | - |
45 | | - if (_options.DeviceDetails) |
46 | | - { |
47 | | - NanoDeviceBase nanoDevice = null; |
48 | | - return _nanoDeviceOperations.GetDeviceDetails( |
49 | | - _options.SerialPort, |
50 | | - ref nanoDevice); |
51 | | - } |
52 | | - else if (_options.Update) |
53 | | - { |
54 | | - var exitCode = await _nanoDeviceOperations.UpdateDeviceClrAsync( |
55 | | - _options.SerialPort, |
56 | | - _options.FwVersion, |
57 | | - _options.ClrFile, |
58 | | - _verbosityLevel); |
59 | | - |
60 | | - if (exitCode != ExitCodes.OK) |
61 | | - { |
62 | | - return exitCode; |
63 | | - } |
64 | | - } |
65 | | - |
66 | | - if (_options.Deploy) |
67 | | - { |
68 | | - var exitCode = _nanoDeviceOperations.DeployApplication( |
69 | | - _options.SerialPort, |
70 | | - _options.DeploymentImage, |
71 | | - _verbosityLevel); |
72 | | - |
73 | | - if (exitCode != ExitCodes.OK) |
74 | | - { |
75 | | - return exitCode; |
76 | | - } |
77 | | - } |
78 | | - |
79 | | - throw new NoOperationPerformedException(); |
80 | | - } |
81 | | - } |
82 | | -} |
| 2 | +using System; |
| 3 | +using System.Collections.Generic; |
| 4 | +using System.Linq; |
| 5 | +using System.Text; |
| 6 | +using System.Threading.Tasks; |
| 7 | + |
| 8 | +namespace nanoFramework.Tools.FirmwareFlasher |
| 9 | +{ |
| 10 | + /// <summary> |
| 11 | + /// Class to manage different operations specific to the nano devices. |
| 12 | + /// </summary> |
| 13 | + public class NanoDeviceManager : IManager |
| 14 | + { |
| 15 | + private readonly Options _options; |
| 16 | + private readonly VerbosityLevel _verbosityLevel; |
| 17 | + |
| 18 | + public NanoDeviceManager(Options options, VerbosityLevel verbosityLevel) |
| 19 | + { |
| 20 | + if (options == null) |
| 21 | + { |
| 22 | + throw new ArgumentNullException(nameof(options)); |
| 23 | + } |
| 24 | + |
| 25 | + if (options.Platform != SupportedPlatform.esp32) |
| 26 | + { |
| 27 | + throw new NotSupportedException($"{nameof(options)} - {options.Platform}"); |
| 28 | + } |
| 29 | + |
| 30 | + _options = options; |
| 31 | + _verbosityLevel = verbosityLevel; |
| 32 | + } |
| 33 | + |
| 34 | + /// <inheritdoc /> |
| 35 | + public async Task<ExitCodes> ProcessAsync() |
| 36 | + { |
| 37 | + // COM port is mandatory for nano device operations |
| 38 | + if (string.IsNullOrEmpty(_options.SerialPort)) |
| 39 | + { |
| 40 | + return ExitCodes.E6001; |
| 41 | + } |
| 42 | + |
| 43 | + NanoDeviceOperations _nanoDeviceOperations = new NanoDeviceOperations(); |
| 44 | + |
| 45 | + if (_options.DeviceDetails) |
| 46 | + { |
| 47 | + NanoDeviceBase nanoDevice = null; |
| 48 | + return _nanoDeviceOperations.GetDeviceDetails( |
| 49 | + _options.SerialPort, |
| 50 | + ref nanoDevice); |
| 51 | + } |
| 52 | + else if (_options.Update) |
| 53 | + { |
| 54 | + var exitCode = await _nanoDeviceOperations.UpdateDeviceClrAsync( |
| 55 | + _options.SerialPort, |
| 56 | + _options.FwVersion, |
| 57 | + _options.ClrFile, |
| 58 | + _verbosityLevel); |
| 59 | + |
| 60 | + if (exitCode != ExitCodes.OK) |
| 61 | + { |
| 62 | + return exitCode; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + if (_options.Deploy) |
| 67 | + { |
| 68 | + var exitCode = _nanoDeviceOperations.DeployApplication( |
| 69 | + _options.SerialPort, |
| 70 | + _options.DeploymentImage, |
| 71 | + _verbosityLevel); |
| 72 | + |
| 73 | + if (exitCode != ExitCodes.OK) |
| 74 | + { |
| 75 | + return exitCode; |
| 76 | + } |
| 77 | + } |
| 78 | + |
| 79 | + throw new NoOperationPerformedException(); |
| 80 | + } |
| 81 | + } |
| 82 | +} |
0 commit comments