Rev 135 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 135 | Rev 149 | ||
---|---|---|---|
Line 43... | Line 43... | ||
43 | 43 | ||
44 | // temp - to be removed |
44 | // temp - to be removed |
45 | String p_msg="--"; |
45 | String p_msg="--"; |
Line 46... | Line -... | ||
46 | public String msg="BT_INIT"; |
- | |
47 | - | ||
48 | 46 | public String msg="BT_INIT"; |
|
49 | 47 | ||
50 | // for statistics |
48 | // for statistics |
51 | public int debug_data_count=0; |
49 | public int debug_data_count=0; |
52 | public int debug_names_count=0; |
50 | public int debug_names_count=0; |
Line 56... | Line 54... | ||
56 | public int lcd_data_count=0; |
54 | public int lcd_data_count=0; |
57 | public int params_data_count=0; |
55 | public int params_data_count=0; |
58 | public int navi_data_count=0; |
56 | public int navi_data_count=0; |
Line -... | Line 57... | ||
- | 57 | ||
- | 58 | ||
- | 59 | public int bytes_in_count=0; |
|
- | 60 | public int bytes_out_count=0; |
|
59 | 61 | ||
60 | 62 | ||
Line 61... | Line 63... | ||
61 | String name; |
63 | String name; |
Line 73... | Line 75... | ||
73 | stick_data=new MKStickData(); |
75 | stick_data=new MKStickData(); |
74 | params=new MKParamsParser(); |
76 | params=new MKParamsParser(); |
75 | LCD= new MKLCD(this); |
77 | LCD= new MKLCD(this); |
76 | watchdog=new MKWatchDog(this); |
78 | watchdog=new MKWatchDog(this); |
77 | gps_position=new MKGPSPosition(); |
79 | gps_position=new MKGPSPosition(); |
- | 80 | proxy =new MKProxy(); |
|
78 | new Thread( this ).start(); // fire up main Thread |
81 | new Thread( this ).start(); // fire up main Thread |
79 | } |
82 | } |
Line -... | Line 83... | ||
- | 83 | ||
80 | 84 | ||
81 | 85 | ||
82 | public void do_proxy(String proxy_url) |
86 | public void do_proxy(String proxy_url) |
83 | { |
87 | { |
Line 84... | Line 88... | ||
84 | proxy=new MKProxy(proxy_url); |
88 | proxy.connect(proxy_url); |
85 | } |
89 | } |
Line 108... | Line 112... | ||
108 | // connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
112 | // connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE); |
109 | reader=connection.openInputStream(); |
113 | reader=connection.openInputStream(); |
110 | writer=connection.openOutputStream(); |
114 | writer=connection.openOutputStream(); |
Line 111... | Line 115... | ||
111 | 115 | ||
112 | // |
116 | // |
113 | String magic="\rmk-mode\r"; |
117 | //String magic="\rmk-mode\r"; |
114 | writer.write(magic.getBytes()); |
118 | //writer.write(magic.getBytes()); |
115 | writer.flush(); |
119 | //writer.flush(); |
Line 116... | Line 120... | ||
116 | // |
120 | // |
117 | 121 | ||
Line 180... | Line 184... | ||
180 | int[] target=new int[8]; |
184 | int[] target=new int[8]; |
181 | target[0]= (0xFF)&(longitude<<24); |
185 | target[0]= (0xFF)&(longitude<<24); |
182 | target[1]= (0xFF)&(longitude<<16); |
186 | target[1]= (0xFF)&(longitude<<16); |
183 | target[2]= (0xFF)&(longitude<<8); |
187 | target[2]= (0xFF)&(longitude<<8); |
184 | target[3]= (0xFF)&(longitude); |
188 | target[3]= (0xFF)&(longitude); |
185 | - | ||
186 | send_command(0,'s',target); |
189 | // send_command(0,'s',target); |
187 | } |
190 | } |
Line 188... | Line 191... | ||
188 | 191 | ||
189 | 192 | ||
Line 230... | Line 233... | ||
230 | 233 | ||
231 | send_command(0,'a',params); |
234 | send_command(0,'a',params); |
Line -... | Line 235... | ||
- | 235 | } |
|
- | 236 | ||
- | 237 | ||
- | 238 | ||
- | 239 | ||
- | 240 | public void trigger_debug() |
|
- | 241 | { |
|
- | 242 | if (sending||recieving) return; // its not that important - can be dropped |
|
- | 243 | ||
- | 244 | int[] params=new int[0]; |
|
- | 245 | send_command(0,'c',params); |
|
- | 246 | } |
|
- | 247 | ||
- | 248 | ||
- | 249 | ||
- | 250 | public void switch_to_fc() |
|
- | 251 | { |
|
- | 252 | ||
- | 253 | ||
- | 254 | while(sending||recieving) |
|
- | 255 | { |
|
- | 256 | try { Thread.sleep(50); } |
|
- | 257 | catch (Exception e) { } |
|
- | 258 | } |
|
- | 259 | ||
- | 260 | ||
- | 261 | ||
- | 262 | int[] params=new int[1]; |
|
- | 263 | params[0]=0; |
|
- | 264 | send_command(0,'u',params); |
|
- | 265 | ||
- | 266 | try { Thread.sleep(50); } |
|
- | 267 | catch (Exception e) { } |
|
- | 268 | ||
- | 269 | version=new MKVersion(); |
|
- | 270 | LCD= new MKLCD(this); |
|
- | 271 | ||
- | 272 | } |
|
- | 273 | ||
- | 274 | ||
- | 275 | public void switch_to_navi() |
|
- | 276 | ||
- | 277 | { |
|
- | 278 | ||
- | 279 | while(sending||recieving) |
|
- | 280 | {try { Thread.sleep(50); } |
|
- | 281 | catch (Exception e) { } |
|
- | 282 | } |
|
- | 283 | ||
- | 284 | ||
- | 285 | sending=true; |
|
- | 286 | try |
|
- | 287 | { |
|
- | 288 | writer.write( 27); |
|
- | 289 | writer.write( 27); |
|
- | 290 | writer.write( 0x55); |
|
- | 291 | writer.write( 0xaa); |
|
- | 292 | writer.write( 0); |
|
- | 293 | writer.write('\r'); |
|
- | 294 | bytes_out_count+=6; |
|
- | 295 | writer.flush(); |
|
- | 296 | } |
|
- | 297 | catch (Exception e) { } |
|
- | 298 | sending=false; |
|
- | 299 | ||
- | 300 | try { Thread.sleep(50); } |
|
- | 301 | catch (Exception e) { } |
|
- | 302 | version=new MKVersion(); |
|
Line 232... | Line 303... | ||
232 | } |
303 | LCD= new MKLCD(this); |
233 | 304 | } |
|
234 | 305 | ||
235 | 306 | ||
236 | 307 | ||
237 | public void trigger_LCD(int key) |
308 | public void trigger_LCD(int key) |
Line 238... | Line 309... | ||
238 | { |
309 | { |
Line 252... | Line 323... | ||
252 | } |
323 | } |
Line 253... | Line 324... | ||
253 | 324 | ||
254 | 325 | ||
- | 326 | public void write_params() |
|
255 | public void write_params() |
327 | { |
256 | { |
328 | params.update_backup(); |
257 | while(sending||recieving) |
329 | while(sending||recieving) |
258 | {try { Thread.sleep(50); } |
330 | {try { Thread.sleep(50); } |
Line 267... | Line 339... | ||
267 | boolean recieving=false; |
339 | boolean recieving=false; |
Line 268... | Line 340... | ||
268 | 340 | ||
269 | // send command to FC ( add crc and pack into pseudo Base64 |
341 | // send command to FC ( add crc and pack into pseudo Base64 |
270 | public void send_command(int modul,char cmd,int[] params) |
342 | public void send_command(int modul,char cmd,int[] params) |
- | 343 | { |
|
271 | { |
344 | |
272 | // if (modul==0) return; |
345 | // if (modul==0) return; |
- | 346 | sending=true; |
|
- | 347 | // 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 |
|
273 | sending=true; |
348 | |
274 | 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 |
349 | char[] send_buff=new char[3 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
275 | send_buff[0]='#'; |
350 | send_buff[0]='#'; |
276 | send_buff[1]=(char)modul; |
351 | send_buff[1]=(char)modul; |
Line 277... | Line 352... | ||
277 | send_buff[2]=cmd; |
352 | send_buff[2]=cmd; |
Line 303... | Line 378... | ||
303 | int tmp_crc=0; |
378 | int tmp_crc=0; |
304 | for ( int tmp_i=0; tmp_i<send_buff.length;tmp_i++) |
379 | for ( int tmp_i=0; tmp_i<send_buff.length;tmp_i++) |
305 | { |
380 | { |
306 | tmp_crc+=(int)send_buff[tmp_i]; |
381 | tmp_crc+=(int)send_buff[tmp_i]; |
307 | writer.write(send_buff[tmp_i]); |
382 | writer.write(send_buff[tmp_i]); |
- | 383 | bytes_out_count++; |
|
308 | } |
384 | } |
309 | tmp_crc%=4096; |
385 | tmp_crc%=4096; |
310 | writer.write( (char)(tmp_crc/64 + '=')); |
386 | writer.write( (char)(tmp_crc/64 + '=')); |
311 | writer.write( (char)(tmp_crc%64 + '=')); |
387 | writer.write( (char)(tmp_crc%64 + '=')); |
312 | writer.write('\r'); |
388 | writer.write('\r'); |
- | 389 | bytes_out_count+=3; |
|
313 | writer.flush(); |
390 | writer.flush(); |
314 | } |
391 | } |
315 | catch (Exception e) |
392 | catch (Exception e) |
316 | { // problem sending data to FC |
393 | { // problem sending data to FC |
317 | } |
394 | } |
Line 341... | Line 418... | ||
341 | break; |
418 | break; |
Line 342... | Line 419... | ||
342 | 419 | ||
343 | case 'V': // Version Info |
420 | case 'V': // Version Info |
344 | version_data_count++; |
421 | version_data_count++; |
- | 422 | version.set_by_mk_data(Decode64(data,3,6)); |
|
- | 423 | if (version.minor>60) // FIXME - NO good detection |
|
345 | version.set_by_mk_data(Decode64(data,3,6)); |
424 | root.canvas.ufo_prober.set_to_mk(); |
Line 346... | Line 425... | ||
346 | break; |
425 | break; |
347 | 426 | ||
348 | case '0': |
427 | case '0': |
Line 388... | Line 467... | ||
388 | break; |
467 | break; |
Line 389... | Line 468... | ||
389 | 468 | ||
390 | 469 | ||
391 | case 'w': |
470 | case 'w': |
392 | angle_data_count++; |
471 | angle_data_count++; |
Line 393... | Line 472... | ||
393 | root.canvas.ufo_prober.set_to_mk(); |
472 | // root.canvas.ufo_prober.set_to_mk(); |
Line 394... | Line 473... | ||
394 | debug.log("got angle data:"); |
473 | debug.log("got angle data"); |
Line 450... | Line 529... | ||
450 | if (!force_disconnect) connect(); |
529 | if (!force_disconnect) connect(); |
451 | } |
530 | } |
452 | else |
531 | else |
453 | try{ |
532 | try{ |
Line 454... | Line 533... | ||
454 | 533 | ||
455 | 534 | /* |
|
456 | while(sending) |
535 | while(sending) |
457 | {try { Thread.sleep(50); } |
536 | {try { Thread.sleep(50); } |
458 | catch (Exception e) { } |
537 | catch (Exception e) { } |
459 | } |
538 | } |
Line 460... | Line 539... | ||
460 | 539 | */ |
|
461 | 540 | ||
462 | 541 | ||
463 | recieving=true; |
542 | recieving=true; |
464 | debug.log("Connected - reading data"); |
543 | debug.log("Connected - reading data"); |
465 | pos=0; |
544 | pos=0; |
466 | input=0; |
545 | input=0; |
Line -... | Line 546... | ||
- | 546 | // recieve data-set |
|
467 | // recieve data-set |
547 | while ((input != 13)) //&&(input!=-1)) |
468 | while ((input != 13)) //&&(input!=-1)) |
548 | { |
- | 549 | ||
469 | { |
550 | debug.log("pre read"); |
- | 551 | input = reader.read() ; |
|
470 | 552 | debug.log("Byte rcv" + input); |
|
471 | input = reader.read() ; |
553 | |
472 | if (proxy!=null) |
554 | proxy.write(input); |
- | 555 | ||
473 | proxy.writer.write(input); |
556 | if (input==-1) throw new Exception("disconnect"); |
474 | if (input==-1) throw new Exception("test"); |
557 | if (input!=-1) |
475 | if (input!=-1) |
558 | { |
- | 559 | bytes_in_count++; |
|
- | 560 | data_set[pos]=input; |
|
Line 476... | Line 561... | ||
476 | { |
561 | pos++; |
477 | data_set[pos]=input; |
562 | } |
478 | pos++; |
563 |