9
9
import java .io .ByteArrayOutputStream ;
10
10
import java .io .InputStream ;
11
11
import java .io .File ;
12
+ import java .io .FileInputStream ;
12
13
13
14
import java .lang .Runnable ;
14
15
import java .lang .Thread ;
25
26
26
27
import java .util .HashMap ;
27
28
import java .util .Map ;
29
+ import java .util .Properties ;
28
30
import java .util .zip .ZipInputStream ;
29
31
import java .util .zip .ZipEntry ;
30
32
34
36
35
37
public class nRF5FlashSoftDevice implements Tool {
36
38
private Map <String , String > urls = new HashMap <String , String >();
39
+ private Map <String , String > filenames = new HashMap <String , String >();
37
40
private Editor editor ;
38
41
39
42
public void init (Editor editor ) {
40
- urls .put ("s110" , "http://www.nordicsemi.com/eng/content/download/80234/1351257/file/s110_nrf51_8.0.0.zip" );
41
- urls .put ("s130" , "http://www.nordicsemi.com/eng/content/download/95150/1606929/file/s130_nrf51_2.0.0.zip" );
42
- urls .put ("s132" , "http://www.nordicsemi.com/eng/content/download/95151/1606944/file/s132_nrf52_2.0.0.zip" );
43
-
44
43
this .editor = editor ;
45
44
}
46
45
@@ -54,6 +53,28 @@ public void run() {
54
53
return ;
55
54
}
56
55
56
+ Path softdeviceTxtPath = Paths .get (PreferencesData .get ("runtime.platform.path" ), "softdevices.txt" );
57
+ Properties softdevices = new Properties ();
58
+
59
+ try {
60
+ softdevices .load (new FileInputStream (softdeviceTxtPath .toString ()));
61
+ } catch (Exception e ) {
62
+ editor .statusError ("Error while flashing SoftDevice." );
63
+ System .err .println (e );
64
+ return ;
65
+ }
66
+
67
+ String [] names = softdevices .getProperty ("names" ).split ("," );
68
+
69
+ for (int i = 0 ; i < names .length ; i ++) {
70
+ String name = names [i ];
71
+ String url = softdevices .getProperty (name + ".url" );
72
+ String filename = softdevices .getProperty (name + ".filename" );
73
+
74
+ urls .put (name , url );
75
+ filenames .put (name , filename );
76
+ }
77
+
57
78
String softDevice = PreferencesData .get ("custom_softdevice" );
58
79
if (softDevice == null || softDevice .endsWith ("none" )) {
59
80
editor .statusError ("No SoftDevice selected!" );
@@ -75,10 +96,11 @@ public void run() {
75
96
}
76
97
77
98
Path softdevicePath = Paths .get (PreferencesData .get ("runtime.platform.path" ), "cores" , "nRF5" , "SDK" , "components" , "softdevice" , softDevice , "hex" );
99
+ Path softdeviceHexFile = Paths .get (softdevicePath .toString (), filenames .get (softDevice ));
78
100
79
101
Runnable runnable = () -> {
80
102
try {
81
- if (Files .list ( softdevicePath ). count () < 3 ) {
103
+ if (Files .notExists ( softdeviceHexFile ) ) {
82
104
System .out .println ("Downloading '" +url + "' ..." );
83
105
84
106
InputStream is = new URL (url ).openStream ();
@@ -97,10 +119,10 @@ public void run() {
97
119
ZipInputStream zis = new ZipInputStream (new ByteArrayInputStream (outputStream .toByteArray ()));
98
120
ZipEntry entry ;
99
121
100
- String licenseAgreementFilename = "" ;
122
+ String licenseAgreementFilename = null ;
101
123
StringBuilder licenseAgreementBuilder = new StringBuilder ();
102
124
103
- String softdeviceFilename = "" ;
125
+ String softdeviceFilename = null ;
104
126
StringBuilder softdeviceBuilder = new StringBuilder ();
105
127
106
128
while ((entry = zis .getNextEntry ()) != null ) {
@@ -119,24 +141,29 @@ public void run() {
119
141
}
120
142
}
121
143
122
- JTextArea textArea = new JTextArea (licenseAgreementBuilder .toString ());
123
- textArea .setColumns (80 );
124
- textArea .setRows (50 );
125
- textArea .setLineWrap (true );
126
- textArea .setWrapStyleWord (true );
127
- textArea .setSize (textArea .getPreferredSize ().width , 1 );
144
+ if (licenseAgreementFilename != null ) {
145
+ JTextArea textArea = new JTextArea (licenseAgreementBuilder .toString ());
146
+ textArea .setColumns (80 );
147
+ textArea .setRows (50 );
148
+ textArea .setLineWrap (true );
149
+ textArea .setWrapStyleWord (true );
150
+ textArea .setSize (textArea .getPreferredSize ().width , 1 );
128
151
129
- JScrollPane scrollPane = new JScrollPane (textArea );
130
- scrollPane .setPreferredSize ( new Dimension (textArea .getPreferredSize ().width , 500 ) );
152
+ JScrollPane scrollPane = new JScrollPane (textArea );
153
+ scrollPane .setPreferredSize ( new Dimension (textArea .getPreferredSize ().width , 500 ) );
131
154
132
- int result = JOptionPane .showOptionDialog (null , scrollPane , "NORDIC SEMICONDUCTOR ASA SOFTDEVICE LICENSE AGREEMENT" , JOptionPane .DEFAULT_OPTION , JOptionPane .QUESTION_MESSAGE , null , new Object []{"Accept" , "Decline" }, "Decline" );
155
+ int result = JOptionPane .showOptionDialog (null , scrollPane , "NORDIC SEMICONDUCTOR ASA SOFTDEVICE LICENSE AGREEMENT" , JOptionPane .DEFAULT_OPTION , JOptionPane .QUESTION_MESSAGE , null , new Object []{"Accept" , "Decline" }, "Decline" );
133
156
134
- if (result != 0 ) {
135
- return ;
157
+ if (result != 0 ) {
158
+ return ;
159
+ }
160
+
161
+ Files .write (Paths .get (softdevicePath .toString (), licenseAgreementFilename ), String .valueOf (licenseAgreementBuilder ).getBytes ());
136
162
}
137
163
138
- Files .write (Paths .get (softdevicePath .toString (), licenseAgreementFilename ), String .valueOf (licenseAgreementBuilder ).getBytes ());
139
- Files .write (Paths .get (softdevicePath .toString (), softdeviceFilename ), String .valueOf (softdeviceBuilder ).getBytes ());
164
+ if (softdeviceFilename != null ) {
165
+ Files .write (Paths .get (softdevicePath .toString (), softdeviceFilename ), String .valueOf (softdeviceBuilder ).getBytes ());
166
+ }
140
167
}
141
168
142
169
Uploader uploader = new SerialUploader ();
0 commit comments