@@ -43,24 +43,29 @@ public static TargetConnection getInstance() {
43
43
public void openConnection () throws TargetConnectionException {
44
44
if (dbg ) StdStreams .vrb .println ("[TARGET] Open connection" );
45
45
try {
46
- // String currLoc = new File(".").getAbsolutePath();
47
- // currLoc = currLoc.replace(currLoc.substring(currLoc.length()-1), "");
48
- // currLoc += "\\startOpenocd-local.bat";
49
- // String name = "F:\\openocd-0.10.0\\startOpenocdMicrozed.bat";
50
- //// StdStreams.vrb.println("run openocd: " + name);
51
- // File dir = new File("F:\\openocd-0.10.0");
52
- // Process p = Runtime.getRuntime().exec("cmd /c start \"\" " + name, null, dir);
53
- // if (p != null) {
54
- // if (dbg) StdStreams.vrb.println("OpenOCD process not null, " + p.toString());
55
- // } else {
56
- // if (dbg) StdStreams.vrb.println("OpenOCD process null");
57
- // }
58
-
59
46
socket = new Socket (hostname , port );
60
47
socket .setSoTimeout (1000 );
61
48
out = socket .getOutputStream ();
62
49
in = socket .getInputStream ();
63
- if (dbg ) StdStreams .vrb .println ("[TARGET] Connected " );
50
+ } catch (IOException e ) {
51
+ 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" );
58
+ try {
59
+ Runtime .getRuntime ().exec ("cmd /c start \" \" " + name , null , dir );
60
+ socket = new Socket (hostname , port );
61
+ socket .setSoTimeout (1000 );
62
+ out = socket .getOutputStream ();
63
+ in = socket .getInputStream ();
64
+ if (dbg ) StdStreams .vrb .println ("[TARGET] started" );
65
+ } catch (IOException e1 ) {
66
+ if (dbg ) StdStreams .vrb .println ("[TARGET] Cannot start OpenOCD server" );
67
+ throw new TargetConnectionException (e1 .getMessage (), e1 );
68
+ }
64
69
} catch (Exception e ) {
65
70
if (dbg ) StdStreams .vrb .println ("[TARGET] Connection failed on " + hostname );
66
71
throw new TargetConnectionException (e .getMessage (), e );
@@ -142,8 +147,6 @@ public boolean isConnected() {
142
147
return false ;
143
148
}
144
149
} catch (IOException e ) {
145
- // TODO Auto-generated catch block
146
- // e.printStackTrace();
147
150
return false ;
148
151
}
149
152
return (socket .isConnected () && !socket .isClosed ());
0 commit comments