@@ -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
0 commit comments