7
7
import org .deepjava .config .Configuration ;
8
8
import org .deepjava .config .Parser ;
9
9
import org .deepjava .config .Register ;
10
+ import org .deepjava .eclipse .DeepPlugin ;
11
+ import org .deepjava .eclipse .ui .preferences .PreferenceConstants ;
10
12
import org .deepjava .host .StdStreams ;
11
13
import org .deepjava .linker .TargetMemorySegment ;
12
14
import org .deepjava .strings .HString ;
13
15
import org .deepjava .target .TargetConnection ;
14
16
import org .deepjava .target .TargetConnectionException ;
15
-
16
17
import java .io .File ;
17
18
import java .io .IOException ;
18
19
import java .io .InputStream ;
@@ -49,14 +50,11 @@ public void openConnection() throws TargetConnectionException {
49
50
in = socket .getInputStream ();
50
51
} catch (IOException e ) {
51
52
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 );
58
56
try {
59
- Runtime .getRuntime ().exec ("cmd /c start \" \" " + name , null , dir );
57
+ Runtime .getRuntime ().exec ("cmd /c start \" \" " + ( path + " \\ startOpenocdMicrozed.bat" ) , null , dir );
60
58
socket = new Socket (hostname , port );
61
59
socket .setSoTimeout (1000 );
62
60
out = socket .getOutputStream ();
@@ -98,46 +96,6 @@ public void closeConnection() {
98
96
@ Override
99
97
public boolean isConnected () {
100
98
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();
141
99
try {
142
100
if (socket == null || socket .getInputStream () == null ) return false ;
143
101
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
346
304
String name = file .getKey ();
347
305
name = name .replace ('\\' , '/' );
348
306
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 ()));
350
308
if (dbg ) StdStreams .vrb .println ("[TARGET] loading: " + name + " to addr 0x" + Integer .toHexString (file .getValue ()));
351
309
buf = new StringBuffer ();
352
310
while (true ) {
@@ -367,7 +325,7 @@ public void downloadImageFile(String filename) throws TargetConnectionException
367
325
if (file != null ) {
368
326
while (in .available () > 0 ) in .read (); // empty buffer
369
327
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 ());
371
329
socket .setSoTimeout (10000 );
372
330
while (true ) {
373
331
int n = in .available ();
@@ -615,7 +573,6 @@ private void waitForNL(int nofNL) throws Exception {
615
573
int n = in .available ();
616
574
if (n <= 0 ) Thread .sleep (100 );
617
575
int c = in .read ();
618
- // StdStreams.vrb.println((char)c);
619
576
if ((char )c == '\n' ) nofNL --;
620
577
if (c < 0 ) throw new TargetConnectionException ("target not answering" );
621
578
if (nofNL == 0 ) break ;
0 commit comments