Skip to content

Commit 0197b28

Browse files
committed
Start openOCD automatically when connecting
1 parent 7c87062 commit 0197b28

File tree

2 files changed

+10
-52
lines changed

2 files changed

+10
-52
lines changed

META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ Bundle-SymbolicName: org.deepjava.openOCDInterface
55
Bundle-Version: 1.0.1
66
Bundle-Vendor: https://www.ost.ch/en/research-and-consulting-services/technology/system-technology/inf/
77
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
8-
Require-Bundle: org.deepjava.compiler;bundle-version="1.3.1"
8+
Require-Bundle: org.deepjava.compiler;bundle-version="1.3.1",
9+
org.eclipse.ui;bundle-version="3.114.0"
910
Export-Package: org.deepjava.openOCDInterface

src/org/deepjava/openOCDInterface/OpenOCD.java

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@
77
import org.deepjava.config.Configuration;
88
import org.deepjava.config.Parser;
99
import org.deepjava.config.Register;
10+
import org.deepjava.eclipse.DeepPlugin;
11+
import org.deepjava.eclipse.ui.preferences.PreferenceConstants;
1012
import org.deepjava.host.StdStreams;
1113
import org.deepjava.linker.TargetMemorySegment;
1214
import org.deepjava.strings.HString;
1315
import org.deepjava.target.TargetConnection;
1416
import org.deepjava.target.TargetConnectionException;
15-
1617
import java.io.File;
1718
import java.io.IOException;
1819
import java.io.InputStream;
@@ -49,14 +50,11 @@ public void openConnection() throws TargetConnectionException {
4950
in = socket.getInputStream();
5051
} catch (IOException e) {
5152
if (dbg) StdStreams.vrb.println("[TARGET] no socket connection possible, start OpenOCD");
52-
String currLoc = new File(".").getAbsolutePath();
53-
currLoc = currLoc.replace(currLoc.substring(currLoc.length()-1), "");
54-
currLoc += "\\startOpenocd-local.bat";
55-
String name = "F:\\openocd-0.10.0\\startOpenocdMicrozed.bat";
56-
if (dbg) StdStreams.log.println("run openocd: " + name);
57-
File dir = new File("F:\\openocd-0.10.0");
53+
String path = DeepPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.DEFAULT_OPENOCD_PATH);
54+
if (dbg) StdStreams.vrb.println("path: " + path);
55+
File dir = new File(path);
5856
try {
59-
Runtime.getRuntime().exec("cmd /c start \"\" " + name, null, dir);
57+
Runtime.getRuntime().exec("cmd /c start \"\" " + (path + "\\startOpenocdMicrozed.bat"), null, dir);
6058
socket = new Socket(hostname, port);
6159
socket.setSoTimeout(1000);
6260
out = socket.getOutputStream();
@@ -98,46 +96,6 @@ public void closeConnection() {
9896
@Override
9997
public boolean isConnected() {
10098
if (dbg) StdStreams.vrb.println("[TARGET] check for target connection");
101-
102-
// /* check if openocd is running */
103-
// boolean openOcdAvail = false;
104-
// StdStreams.vrb.println("get process");
105-
// Process p = null;
106-
// try {
107-
// p = Runtime.getRuntime().exec(System.getenv("windir")+"\\system32\\"+"tasklist.exe /v");
108-
// } catch (IOException e) {
109-
// // TODO Auto-generated catch block
110-
// e.printStackTrace();
111-
// }
112-
// StdStreams.vrb.println("get input stream");
113-
// BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
114-
//
115-
// StdStreams.vrb.println("add lines to pidInfo");
116-
// String line;
117-
// try {
118-
// while ((line = input.readLine()) != null) {
119-
//// StdStreams.vrb.println(line);
120-
// if (line.contains("openocd")) {
121-
// if(line.contains("Running")) {
122-
// openOcdAvail = true;
123-
// StdStreams.vrb.println("found openocd, state running");
124-
// break;
125-
// } else {
126-
// openOcdAvail = true;
127-
// StdStreams.vrb.println("found openocd, not running");
128-
// }
129-
// }
130-
// }
131-
// } catch (IOException e) {
132-
// // TODO Auto-generated catch block
133-
// e.printStackTrace();
134-
// }
135-
//
136-
// if (!openOcdAvail) {
137-
// StdStreams.vrb.println("should start openocd");
138-
// }
139-
//
140-
//// input.close();
14199
try {
142100
if (socket == null || socket.getInputStream() == null) return false;
143101
if (dbg) StdStreams.vrb.println("[TARGET] check returns " + (socket == null) + " " + socket.isConnected() + " " + socket.isClosed() + " " + socket.isOutputShutdown());
@@ -346,7 +304,7 @@ public void downloadImageFile(String filename) throws TargetConnectionException
346304
String name = file.getKey();
347305
name = name.replace('\\', '/');
348306
StdStreams.log.println("Downloading " + name);
349-
out.write((("load_image " + name + " " + file.getValue() + " \r\n").getBytes()));
307+
out.write((("load_image \"" + name + "\" " + file.getValue() + " \r\n").getBytes()));
350308
if (dbg) StdStreams.vrb.println("[TARGET] loading: " + name + " to addr 0x" + Integer.toHexString(file.getValue()));
351309
buf = new StringBuffer();
352310
while (true) {
@@ -367,7 +325,7 @@ public void downloadImageFile(String filename) throws TargetConnectionException
367325
if (file != null) {
368326
while (in.available() > 0) in.read(); // empty buffer
369327
StdStreams.log.print("Downloading bitstream " + file + " ");
370-
out.write(("pld load 0 " + file + "\r\n").getBytes());
328+
out.write(("pld load 0 \"" + file + "\"\r\n").getBytes());
371329
socket.setSoTimeout(10000);
372330
while (true) {
373331
int n = in.available();
@@ -615,7 +573,6 @@ private void waitForNL(int nofNL) throws Exception {
615573
int n = in.available();
616574
if (n <= 0) Thread.sleep(100);
617575
int c = in.read();
618-
// StdStreams.vrb.println((char)c);
619576
if ((char)c == '\n') nofNL--;
620577
if (c < 0) throw new TargetConnectionException("target not answering");
621578
if (nofNL == 0) break;

0 commit comments

Comments
 (0)