Skip to content

Commit e1982c5

Browse files
committed
Split out soft device URL's to a txt file
1 parent 043822a commit e1982c5

File tree

2 files changed

+57
-20
lines changed

2 files changed

+57
-20
lines changed

extras/ide-tools/nRF5FlashSoftDevice.java

Lines changed: 47 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.io.ByteArrayOutputStream;
1010
import java.io.InputStream;
1111
import java.io.File;
12+
import java.io.FileInputStream;
1213

1314
import java.lang.Runnable;
1415
import java.lang.Thread;
@@ -25,6 +26,7 @@
2526

2627
import java.util.HashMap;
2728
import java.util.Map;
29+
import java.util.Properties;
2830
import java.util.zip.ZipInputStream;
2931
import java.util.zip.ZipEntry;
3032

@@ -34,13 +36,10 @@
3436

3537
public class nRF5FlashSoftDevice implements Tool {
3638
private Map<String, String> urls = new HashMap<String, String>();
39+
private Map<String, String> filenames = new HashMap<String, String>();
3740
private Editor editor;
3841

3942
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-
4443
this.editor = editor;
4544
}
4645

@@ -54,6 +53,28 @@ public void run() {
5453
return;
5554
}
5655

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+
5778
String softDevice = PreferencesData.get("custom_softdevice");
5879
if (softDevice == null || softDevice.endsWith("none")) {
5980
editor.statusError("No SoftDevice selected!");
@@ -75,10 +96,11 @@ public void run() {
7596
}
7697

7798
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));
78100

79101
Runnable runnable = () -> {
80102
try {
81-
if (Files.list(softdevicePath).count() < 3) {
103+
if (Files.notExists(softdeviceHexFile)) {
82104
System.out.println("Downloading '" +url + "' ...");
83105

84106
InputStream is = new URL(url).openStream();
@@ -97,10 +119,10 @@ public void run() {
97119
ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(outputStream.toByteArray()));
98120
ZipEntry entry;
99121

100-
String licenseAgreementFilename = "";
122+
String licenseAgreementFilename = null;
101123
StringBuilder licenseAgreementBuilder = new StringBuilder();
102124

103-
String softdeviceFilename = "";
125+
String softdeviceFilename = null;
104126
StringBuilder softdeviceBuilder = new StringBuilder();
105127

106128
while ((entry = zis.getNextEntry()) != null) {
@@ -119,24 +141,29 @@ public void run() {
119141
}
120142
}
121143

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);
128151

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 ) );
131154

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");
133156

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());
136162
}
137163

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+
}
140167
}
141168

142169
Uploader uploader = new SerialUploader();

softdevices.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
names=s110,s130,s132
2+
3+
s110.url=http://www.nordicsemi.com/eng/content/download/80234/1351257/file/s110_nrf51_8.0.0.zip
4+
s110.filename=s110_nrf51_8.0.0_softdevice.hex
5+
6+
s130.url=http://www.nordicsemi.com/eng/content/download/95150/1606929/file/s130_nrf51_2.0.0.zip
7+
s130.filename=s130_nrf51_2.0.1_softdevice.hex
8+
9+
s132.url=http://www.nordicsemi.com/eng/content/download/95151/1606944/file/s132_nrf52_2.0.0.zip
10+
s132.filename=s132_nrf52_2.0.1_softdevice.hex

0 commit comments

Comments
 (0)