Rev 59 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 59 | Rev 70 | ||
---|---|---|---|
1 | /******************************************************************************************************************************** |
1 | /******************************************************************************************************************************** |
2 | * |
2 | * |
3 | * Abstaction Layer to Communicate via J2ME and Bluetooth with the FlightCtrl of the MikroKopter Project (www.mikrokopter.de ) |
3 | * Abstaction Layer to Communicate via J2ME and Bluetooth with the FlightCtrl of the MikroKopter Project (www.mikrokopter.de ) |
4 | * |
4 | * |
5 | * Author: Marcus -LiGi- Bueschleb |
5 | * Author: Marcus -LiGi- Bueschleb |
6 | * |
6 | * |
7 | * see README for further Infos |
7 | * see README for further Infos |
8 | * |
8 | * |
9 | * |
9 | * |
10 | *******************************************************************************************************************************/ |
10 | *******************************************************************************************************************************/ |
11 | 11 | ||
12 | import javax.microedition.io.*; |
12 | import javax.microedition.io.*; |
13 | import java.io.*; |
13 | import java.io.*; |
14 | 14 | ||
15 | public class MKCommunicator |
15 | public class MKCommunicator |
16 | implements Runnable |
16 | implements Runnable |
17 | { |
17 | { |
18 | /***************** Section: public Attributes **********************************************/ |
18 | /***************** Section: public Attributes **********************************************/ |
19 | public boolean connected=false; // flag for the connection state |
19 | public boolean connected=false; // flag for the connection state |
20 | public boolean fatal=false; // flag which is set when an error is so fatal that reconnecting won't be tried - e.g. unknown version number. |
20 | public boolean fatal=false; // flag which is set when an error is so fatal that reconnecting won't be tried - e.g. unknown version number. |
21 | 21 | ||
22 | 22 | ||
23 | public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
23 | public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
24 | 24 | ||
25 | public MKLCD LCD; |
25 | public MKLCD LCD; |
26 | public MKVersion version; |
26 | public MKVersion version; |
27 | public MKDebugData debug_data; |
27 | public MKDebugData debug_data; |
28 | public MKParamsParser params; |
28 | public MKParamsParser params; |
29 | public MKWatchDog watchdog; |
29 | public MKWatchDog watchdog; |
30 | public MKProxy proxy=null; |
30 | public MKProxy proxy=null; |
31 | 31 | ||
32 | public long connection_start_time=-1; |
32 | public long connection_start_time=-1; |
33 | 33 | ||
34 | 34 | ||
35 | /****************** Section: private Attributes **********************************************/ |
35 | /****************** Section: private Attributes **********************************************/ |
36 | private javax.microedition.io.StreamConnection connection; |
36 | private javax.microedition.io.StreamConnection connection; |
37 | private java.io.InputStream reader; |
37 | private java.io.InputStream reader; |
38 | private java.io.OutputStream writer; |
38 | private java.io.OutputStream writer; |
39 | 39 | ||
40 | 40 | ||
41 | // temp - to be removed |
41 | // temp - to be removed |
42 | String p_msg="--"; |
42 | String p_msg="--"; |
43 | public String msg="BT_INIT"; |
43 | public String msg="BT_INIT"; |
44 | 44 | ||
45 | public int debug_data_count=0; |
45 | public int debug_data_count=0; |
46 | public int version_data_count=0; |
46 | public int version_data_count=0; |
47 | public int other_data_count=0; |
47 | public int other_data_count=0; |
48 | public int lcd_data_count=0; |
48 | public int lcd_data_count=0; |
49 | public int params_data_count=0; |
49 | public int params_data_count=0; |
50 | 50 | ||
51 | 51 | ||
52 | 52 | ||
53 | String name; |
53 | String name; |
54 | DUBwise root; |
54 | DUBwise root; |
55 | 55 | ||
56 | /****************** Section: public Methods ************************************************/ |
56 | /****************** Section: public Methods ************************************************/ |
57 | public MKCommunicator(DUBwise root_) |
57 | public MKCommunicator(DUBwise root_) |
58 | { |
58 | { |
59 | root=root_; |
59 | root=root_; |
60 | version=new MKVersion(); |
60 | version=new MKVersion(); |
61 | debug_data=new MKDebugData(); |
61 | debug_data=new MKDebugData(); |
62 | params=new MKParamsParser(); |
62 | params=new MKParamsParser(); |
63 | LCD= new MKLCD(this); |
63 | LCD= new MKLCD(this); |
64 | watchdog=new MKWatchDog(this); |
64 | watchdog=new MKWatchDog(this); |
65 | new Thread( this ).start(); // fire up main Thread |
65 | new Thread( this ).start(); // fire up main Thread |
66 | } |
66 | } |
67 | 67 | ||
68 | 68 | ||
69 | public void do_proxy(String proxy_url) |
69 | public void do_proxy(String proxy_url) |
70 | { |
70 | { |
71 | proxy=new MKProxy(proxy_url); |
71 | proxy=new MKProxy(proxy_url); |
72 | } |
72 | } |
73 | 73 | ||
74 | // URL string: "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
74 | // URL string: "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
75 | public void connect_to(String _url,String _name) |
75 | public void connect_to(String _url,String _name) |
76 | { |
76 | { |
77 | mk_url=_url; // remember URL for connecting / reconnecting later |
77 | mk_url=_url; // remember URL for connecting / reconnecting later |
78 | name=_name; |
78 | name=_name; |
79 | force_disconnect=false; |
79 | force_disconnect=false; |
80 | connected=false; |
80 | connected=false; |
81 | } |
81 | } |
82 | 82 | ||
83 | /****************** Section: private Methods ************************************************/ |
83 | /****************** Section: private Methods ************************************************/ |
84 | private void connect() |
84 | private void connect() |
85 | { |
85 | { |
86 | System.out.println("trying to connect to" + mk_url); |
86 | System.out.println("trying to connect to" + mk_url); |
87 | try{ |
87 | try{ |
88 | connection = (StreamConnection) Connector.open(mk_url); |
88 | connection = (StreamConnection) Connector.open(mk_url); |
89 | // old call |
89 | // old call |
90 | // connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
90 | // connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
91 | reader=connection.openInputStream(); |
91 | reader=connection.openInputStream(); |
92 | writer=connection.openOutputStream(); |
92 | writer=connection.openOutputStream(); |
93 | 93 | ||
94 | connection_start_time=System.currentTimeMillis(); |
94 | connection_start_time=System.currentTimeMillis(); |
95 | connected=true; // if we get here everything seems to be OK |
95 | connected=true; // if we get here everything seems to be OK |
96 | get_version(); |
96 | get_version(); |
97 | lcd_data_count=0; |
97 | lcd_data_count=0; |
98 | debug_data_count=0; |
98 | debug_data_count=0; |
99 | version_data_count=0; |
99 | version_data_count=0; |
100 | 100 | ||
101 | 101 | ||
102 | } |
102 | } |
103 | catch (Exception ex) |
103 | catch (Exception ex) |
104 | { |
104 | { |
105 | // TODO difference fatal errors from those which will lead to reconnection |
105 | // TODO difference fatal errors from those which will lead to reconnection |
106 | msg="Problem connecting" + "\n" + ex; |
106 | msg="Problem connecting" + "\n" + ex; |
107 | System.out.println("problem connecting " + ex); |
107 | System.out.println("problem connecting " + ex); |
108 | } |
108 | } |
109 | 109 | ||
110 | 110 | ||
111 | 111 | ||
112 | } |
112 | } |
113 | 113 | ||
114 | 114 | ||
115 | 115 | ||
116 | public int[] Decode64(int[] in_arr, int offset,int len) |
116 | public int[] Decode64(int[] in_arr, int offset,int len) |
117 | { |
117 | { |
118 | int ptrIn=offset; |
118 | int ptrIn=offset; |
119 | int a,b,c,d,x,y,z; |
119 | int a,b,c,d,x,y,z; |
120 | int ptr=0; |
120 | int ptr=0; |
121 | 121 | ||
122 | int[] out_arr=new int[len]; |
122 | int[] out_arr=new int[len]; |
123 | 123 | ||
124 | while(len!=0) |
124 | while(len!=0) |
125 | { |
125 | { |
126 | a = in_arr[ptrIn++] - '='; |
126 | a = in_arr[ptrIn++] - '='; |
127 | b = in_arr[ptrIn++] - '='; |
127 | b = in_arr[ptrIn++] - '='; |
128 | c = in_arr[ptrIn++] - '='; |
128 | c = in_arr[ptrIn++] - '='; |
129 | d = in_arr[ptrIn++] - '='; |
129 | d = in_arr[ptrIn++] - '='; |
130 | //if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
130 | //if(ptrIn > max - 2) break; // nicht mehr Daten verarbeiten, als empfangen wurden |
131 | 131 | ||
132 | x = (a << 2) | (b >> 4); |
132 | x = (a << 2) | (b >> 4); |
133 | y = ((b & 0x0f) << 4) | (c >> 2); |
133 | y = ((b & 0x0f) << 4) | (c >> 2); |
134 | z = ((c & 0x03) << 6) | d; |
134 | z = ((c & 0x03) << 6) | d; |
135 | 135 | ||
136 | if((len--)!=0) out_arr[ptr++] = x; else break; |
136 | if((len--)!=0) out_arr[ptr++] = x; else break; |
137 | if((len--)!=0) out_arr[ptr++] = y; else break; |
137 | if((len--)!=0) out_arr[ptr++] = y; else break; |
138 | if((len--)!=0) out_arr[ptr++] = z; else break; |
138 | if((len--)!=0) out_arr[ptr++] = z; else break; |
139 | } |
139 | } |
140 | 140 | ||
141 | return out_arr; |
141 | return out_arr; |
142 | 142 | ||
143 | } |
143 | } |
144 | 144 | ||
145 | // FC - Function Mappers |
145 | // FC - Function Mappers |
146 | 146 | ||
147 | // send a version Request to the FC - the reply to this request will be processed in process_data when it arrives |
147 | // send a version Request to the FC - the reply to this request will be processed in process_data when it arrives |
148 | public void get_version() |
148 | public void get_version() |
149 | { |
149 | { |
150 | send_command(0,'v',new int[0]); |
150 | send_command(0,'v',new int[0]); |
151 | } |
151 | } |
152 | 152 | ||
153 | // send a MotorTest request - params are the speed for each Motor |
153 | // send a MotorTest request - params are the speed for each Motor |
154 | public void motor_test(int[] params) |
154 | public void motor_test(int[] params) |
155 | { |
155 | { |
156 | send_command(0,'t',params); |
156 | send_command(0,'t',params); |
157 | } |
157 | } |
158 | 158 | ||
159 | public void send_keys(int[] params) |
159 | public void send_keys(int[] params) |
160 | { |
160 | { |
161 | send_command(0,'k',params); |
161 | send_command(0,'k',params); |
162 | } |
162 | } |
163 | 163 | ||
164 | // get params |
164 | // get params |
165 | public void get_params(int id) |
165 | public void get_params(int id) |
166 | { |
166 | { |
167 | int[] params=new int[1]; |
167 | int[] params=new int[1]; |
168 | params[0]=id; |
168 | params[0]=id; |
169 | 169 | ||
170 | while(sending) |
170 | while(sending) |
171 | {try { Thread.sleep(50); } |
171 | {try { Thread.sleep(50); } |
172 | catch (Exception e) { } |
172 | catch (Exception e) { } |
173 | } |
173 | } |
174 | 174 | ||
175 | send_command(0,'q',params); |
175 | send_command(0,'q',params); |
176 | } |
176 | } |
177 | 177 | ||
178 | 178 | ||
179 | public void get_debug_name(int id) |
179 | public void get_debug_name(int id) |
180 | { |
180 | { |
181 | int[] params=new int[1]; |
181 | int[] params=new int[1]; |
182 | params[0]=id; |
182 | params[0]=id; |
183 | 183 | ||
184 | while(sending) |
184 | while(sending) |
185 | {try { Thread.sleep(50); } |
185 | {try { Thread.sleep(50); } |
186 | catch (Exception e) { } |
186 | catch (Exception e) { } |
187 | } |
187 | } |
188 | 188 | ||
189 | send_command(0,'a',params); |
189 | send_command(0,'a',params); |
190 | } |
190 | } |
191 | 191 | ||
192 | 192 | ||
193 | 193 | ||
194 | 194 | ||
195 | public void trigger_LCD(int key) |
195 | public void trigger_LCD(int key) |
196 | { |
196 | { |
197 | if (sending) return; |
197 | if (sending) return; |
198 | 198 | ||
199 | 199 | ||
200 | int[] params=new int[3]; |
200 | int[] params=new int[3]; |
201 | params[0]=key; |
201 | params[0]=key; |
202 | params[1]=0; |
202 | params[1]=0; |
203 | params[2]=0; |
203 | params[2]=0; |
204 | 204 | ||
205 | send_command(0,'h',params); |
205 | send_command(0,'h',params); |
206 | 206 | ||
207 | } |
207 | } |
208 | 208 | ||
209 | 209 | ||
210 | public void write_params() |
210 | public void write_params() |
211 | { |
211 | { |
212 | while(sending) |
212 | while(sending) |
213 | {try { Thread.sleep(50); } |
213 | {try { Thread.sleep(50); } |
214 | catch (Exception e) { } |
214 | catch (Exception e) { } |
215 | } |
215 | } |
216 | 216 | ||
217 | send_command(0,(char)('l'+params.act_paramset),params.field[params.act_paramset]); |
217 | send_command(0,(char)('l'+params.act_paramset),params.field[params.act_paramset]); |
218 | } |
218 | } |
219 | 219 | ||
220 | 220 | ||
221 | boolean sending=false; |
221 | boolean sending=false; |
222 | 222 | ||
223 | // send command to FC ( add crc and pack into pseudo Base64 |
223 | // send command to FC ( add crc and pack into pseudo Base64 |
224 | public void send_command(int modul,char cmd,int[] params) |
224 | public void send_command(int modul,char cmd,int[] params) |
225 | { |
225 | { |
226 | sending=true; |
226 | sending=true; |
227 | char[] send_buff=new char[5 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
227 | char[] send_buff=new char[5 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
228 | send_buff[0]='#'; |
228 | send_buff[0]='#'; |
229 | send_buff[1]=(char)modul; |
229 | send_buff[1]=(char)modul; |
230 | send_buff[2]=cmd; |
230 | send_buff[2]=cmd; |
231 | 231 | ||
232 | for(int param_pos=0;param_pos<(params.length/3 + (params.length%3==0?0:1)) ;param_pos++) |
232 | for(int param_pos=0;param_pos<(params.length/3 + (params.length%3==0?0:1)) ;param_pos++) |
233 | { |
233 | { |
234 | int a = (param_pos*3<params.length)?params[param_pos*3]:0; |
234 | int a = (param_pos*3<params.length)?params[param_pos*3]:0; |
235 | int b = ((param_pos*3+1)<params.length)?params[param_pos*3+1]:0; |
235 | int b = ((param_pos*3+1)<params.length)?params[param_pos*3+1]:0; |
236 | int c = ((param_pos*3+2)<params.length)?params[param_pos*3+2]:0; |
236 | int c = ((param_pos*3+2)<params.length)?params[param_pos*3+2]:0; |
237 | 237 | ||
238 | send_buff[3+param_pos*4] = (char)((a >> 2)+'=' ); |
238 | send_buff[3+param_pos*4] = (char)((a >> 2)+'=' ); |
239 | send_buff[3+param_pos*4+1] = (char)('=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4))); |
239 | send_buff[3+param_pos*4+1] = (char)('=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4))); |
240 | send_buff[3+param_pos*4+2] = (char)('=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6))); |
240 | send_buff[3+param_pos*4+2] = (char)('=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6))); |
241 | send_buff[3+param_pos*4+3] = (char)('=' + ( c & 0x3f)); |
241 | send_buff[3+param_pos*4+3] = (char)('=' + ( c & 0x3f)); |
242 | 242 | ||
243 | //send_buff[3+foo]='='; |
243 | //send_buff[3+foo]='='; |
244 | } |
244 | } |
245 | 245 | ||
246 | /* for(int foo=0;foo<(params.length/3 + (params.length%3==0?0:1) )*4;foo++) |
246 | /* for(int foo=0;foo<(params.length/3 + (params.length%3==0?0:1) )*4;foo++) |
247 | { |
247 | { |
248 | int a = (foo<params.length) params[foo]; |
248 | int a = (foo<params.length) params[foo]; |
249 | int a = params[foo]; |
249 | int a = params[foo]; |
250 | |
250 | |
251 | //send_buff[3+foo]='='; |
251 | //send_buff[3+foo]='='; |
252 | } |
252 | } |
253 | */ |
253 | */ |
254 | try |
254 | try |
255 | { |
255 | { |
256 | int tmp_crc=0; |
256 | int tmp_crc=0; |
257 | for ( int tmp_i=0; tmp_i<send_buff.length;tmp_i++) |
257 | for ( int tmp_i=0; tmp_i<send_buff.length;tmp_i++) |
258 | { |
258 | { |
259 | tmp_crc+=(int)send_buff[tmp_i]; |
259 | tmp_crc+=(int)send_buff[tmp_i]; |
260 | writer.write(send_buff[tmp_i]); |
260 | writer.write(send_buff[tmp_i]); |
261 | } |
261 | } |
262 | tmp_crc%=4096; |
262 | tmp_crc%=4096; |
263 | writer.write( (char)(tmp_crc/64 + '=')); |
263 | writer.write( (char)(tmp_crc/64 + '=')); |
264 | writer.write( (char)(tmp_crc%64 + '=')); |
264 | writer.write( (char)(tmp_crc%64 + '=')); |
265 | writer.write('\r'); |
265 | writer.write('\r'); |
266 | writer.flush(); |
266 | writer.flush(); |
267 | } |
267 | } |
268 | catch (Exception e) |
268 | catch (Exception e) |
269 | { // problem sending data to FC |
269 | { // problem sending data to FC |
270 | } |
270 | } |
271 | 271 | ||
272 | sending=false; |
272 | sending=false; |
273 | } |
273 | } |
274 | 274 | ||
275 | 275 | ||
276 | public void process_data(int[] data,int len) |
276 | public void process_data(int[] data,int len) |
277 | { |
277 | { |
278 | int[] decoded_data; |
278 | int[] decoded_data; |
279 | 279 | ||
280 | 280 | ||
281 | switch((char)data[2]) |
281 | switch((char)data[2]) |
282 | { |
282 | { |
283 | 283 | ||
284 | case 'D': // debug Data |
284 | case 'D': // debug Data |
285 | debug_data_count++; |
285 | debug_data_count++; |
286 | debug_data.set_by_mk_data(Decode64(data,3,len-3),version); |
286 | debug_data.set_by_mk_data(Decode64(data,3,len-3),version); |
287 | break; |
287 | break; |
288 | 288 | ||
289 | case 'A': // debug Data Names |
289 | case 'A': // debug Data Names |
290 | //debug_data_count++; |
290 | //debug_data_count++; |
291 | debug_data.set_names_by_mk_data(data[1]-'0',Decode64(data,3,len-3)); |
291 | debug_data.set_names_by_mk_data(data[1]-'0',Decode64(data,3,len-3)); |
292 | break; |
292 | break; |
293 | 293 | ||
294 | case 'V': // Version Info |
294 | case 'V': // Version Info |
295 | version_data_count++; |
295 | version_data_count++; |
296 | version.set_by_mk_data(Decode64(data,3,6)); |
296 | version.set_by_mk_data(Decode64(data,3,6)); |
297 | break; |
297 | break; |
298 | 298 | ||
299 | case '0': |
299 | case '0': |
300 | case '1': |
300 | case '1': |
301 | case '2': |
301 | case '2': |
302 | case '3': |
302 | case '3': |
303 | LCD.handle_lcd_data(Decode64(data,3,20),data[2]-(int)'0'); |
303 | LCD.handle_lcd_data(Decode64(data,3,20),data[2]-(int)'0'); |
304 | lcd_data_count++; |
304 | lcd_data_count++; |
305 | break; |
305 | break; |
306 | 306 | ||
307 | case 'L': |
307 | case 'L': |
308 | case 'M': |
308 | case 'M': |
309 | case 'N': |
309 | case 'N': |
310 | case 'O': |
310 | case 'O': |
311 | case 'P': |
311 | case 'P': |
312 | params.set_by_mk_data((int)(data[2]-'L'),Decode64(data,3,len-3),version); |
312 | params.set_by_mk_data((int)(data[2]-'L'),Decode64(data,3,len-3),version); |
313 | params_data_count++; |
313 | params_data_count++; |
314 | break; |
314 | break; |
315 | 315 | ||
316 | default: |
316 | default: |
317 | other_data_count++; |
317 | other_data_count++; |
318 | break; |
318 | break; |
319 | 319 | ||
320 | } |
320 | } |
321 | 321 | ||
322 | 322 | ||
323 | 323 | ||
324 | 324 | ||
325 | } |
325 | } |
326 | 326 | ||
327 | String o_msg=""; |
327 | String o_msg=""; |
328 | 328 | ||
329 | public boolean force_disconnect=true; |
329 | public boolean force_disconnect=true; |
330 | 330 | ||
331 | public void close_connections(boolean force) |
331 | public void close_connections(boolean force) |
332 | { |
332 | { |
333 | if (!force) root.vibrate(500); |
333 | if ((!force)&&root.canvas.do_vibra) root.vibrate(500); |
334 | force_disconnect=force; |
334 | force_disconnect=force; |
335 | try{ reader.close(); } |
335 | try{ reader.close(); } |
336 | catch (Exception inner_ex) { } |
336 | catch (Exception inner_ex) { } |
337 | 337 | ||
338 | try{ writer.close(); } |
338 | try{ writer.close(); } |
339 | catch (Exception inner_ex) { } |
339 | catch (Exception inner_ex) { } |
340 | 340 | ||
341 | try{ connection.close(); } |
341 | try{ connection.close(); } |
342 | catch (Exception inner_ex) { } |
342 | catch (Exception inner_ex) { } |
343 | 343 | ||
344 | connected=false; |
344 | connected=false; |
345 | } |
345 | } |
346 | 346 | ||
347 | // Thread to recieve data from Connection |
347 | // Thread to recieve data from Connection |
348 | public void run() |
348 | public void run() |
349 | { |
349 | { |
350 | int[] data_set=new int[150]; |
350 | int[] data_set=new int[150]; |
351 | int input; |
351 | int input; |
352 | int pos=0; |
352 | int pos=0; |
353 | msg+="!!run started!!"; |
353 | msg+="!!run started!!"; |
354 | while(true) |
354 | while(true) |
355 | { |
355 | { |
356 | if (!connected) |
356 | if (!connected) |
357 | { |
357 | { |
358 | if (!force_disconnect) connect(); |
358 | if (!force_disconnect) connect(); |
359 | } |
359 | } |
360 | else |
360 | else |
361 | try{ |
361 | try{ |
362 | 362 | ||
363 | pos=0; |
363 | pos=0; |
364 | input=0; |
364 | input=0; |
365 | // recieve data-set |
365 | // recieve data-set |
366 | while ((input != 13)) // &&(input!=-1)) |
366 | while ((input != 13)) // &&(input!=-1)) |
367 | { |
367 | { |
368 | 368 | ||
369 | input = reader.read() ; |
369 | input = reader.read() ; |
370 | if (proxy!=null) |
370 | if (proxy!=null) |
371 | proxy.writer.write(input); |
371 | proxy.writer.write(input); |
372 | if (input==-1) throw new Exception("test"); |
372 | if (input==-1) throw new Exception("test"); |
373 | data_set[pos]=input; |
373 | data_set[pos]=input; |
374 | pos++; |
374 | pos++; |
375 | 375 | ||
376 | } |
376 | } |
377 | 377 | ||
378 | if (proxy!=null) |
378 | if (proxy!=null) |
379 | { |
379 | { |
380 | proxy.writer.write('\r'); |
380 | proxy.writer.write('\r'); |
381 | proxy.writer.write('\n'); |
381 | proxy.writer.write('\n'); |
382 | proxy.writer.flush(); |
382 | proxy.writer.flush(); |
383 | } |
383 | } |
384 | 384 | ||
385 | process_data(data_set,pos); |
385 | process_data(data_set,pos); |
386 | 386 | ||
387 | } |
387 | } |
388 | catch (Exception ex) |
388 | catch (Exception ex) |
389 | { |
389 | { |
390 | msg="Problem reading from MK"; |
390 | msg="Problem reading from MK"; |
391 | // close the connection |
391 | // close the connection |
392 | close_connections(false); |
392 | close_connections(false); |
393 | 393 | ||
394 | 394 | ||
395 | } |
395 | } |
396 | 396 | ||
397 | // sleep a bit to get someting more done |
397 | // sleep a bit to get someting more done |
398 | try { Thread.sleep(50); } |
398 | try { Thread.sleep(50); } |
399 | catch (Exception e) { } |
399 | catch (Exception e) { } |
400 | 400 | ||
401 | } // while |
401 | } // while |
402 | 402 | ||
403 | 403 | ||
404 | } // run() |
404 | } // run() |
405 | 405 | ||
406 | 406 | ||
407 | } |
407 | } |
408 | 408 |