Rev 266 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 266 | Rev 381 | ||
---|---|---|---|
Line 27... | Line 27... | ||
27 | 27 | ||
28 | 28 | ||
29 | public class MKCommunicator |
29 | public class MKCommunicator |
- | 30 | implements Runnable,DUBwiseDefinitions |
|
- | 31 | { |
|
- | 32 | public byte slave_addr=-1; |
|
- | 33 | ||
- | 34 | public int primary_abo; |
|
Line 30... | Line 35... | ||
30 | implements Runnable,DUBwiseDefinitions |
35 | public int secondary_abo; |
31 | { |
36 | public int default_abo; |
32 | 37 | ||
33 | public int angle_nick=-4242; |
- | |
Line 34... | Line 38... | ||
34 | public int angle_roll=-4242; |
38 | public int angle_nick=-4242; |
Line 35... | Line 39... | ||
35 | public byte bl_retrys=0; |
39 | public int angle_roll=-4242; |
36 | public boolean init_bootloader=false; |
40 | public byte bl_retrys=0; |
Line 37... | Line 41... | ||
37 | 41 | ||
Line -... | Line 42... | ||
- | 42 | public boolean disconnect_notify=false; |
|
- | 43 | ||
- | 44 | public byte lib_version_major=0; |
|
- | 45 | public byte lib_version_minor=9; |
|
- | 46 | ||
- | 47 | public byte last_navi_error=0; |
|
38 | public boolean disconnect_notify=false; |
48 | |
39 | 49 | public boolean mixer_change_notify=false; |
|
40 | public byte lib_version_major=0; |
50 | public boolean mixer_change_success=false; |
41 | public byte lib_version_minor=7; |
51 | |
Line 42... | Line 52... | ||
42 | 52 | public boolean change_notify=false; |
|
43 | public byte last_navi_error=0; |
53 | public boolean thread_running=true; |
44 | 54 | ||
45 | public String lib_version_str() |
55 | public String lib_version_str() |
46 | { |
56 | { |
47 | return "V"+lib_version_major+"."+lib_version_minor; |
57 | return "V"+lib_version_major+"."+lib_version_minor; |
48 | } |
58 | } |
Line 49... | Line 59... | ||
49 | 59 | ||
Line 50... | Line 60... | ||
50 | 60 | ||
51 | public int AngleNick() |
61 | public int AngleNick() |
52 | { |
62 | { |
53 | if (ufo_prober.is_mk()) |
63 | if (is_mk()) |
54 | return angle_nick; |
64 | return angle_nick; |
55 | else if (ufo_prober.is_navi()) |
65 | else if (is_navi()) |
56 | return debug_data.analog[0]; |
66 | return debug_data.analog[0]; |
57 | return -1; |
67 | return -1; |
58 | 68 | ||
59 | } |
69 | } |
Line 60... | Line 70... | ||
60 | 70 | ||
Line 78... | Line 88... | ||
78 | { |
88 | { |
79 | return "" + Alt()/10 + "m"; |
89 | return "" + Alt()/10 + "m"; |
80 | } |
90 | } |
81 | public int AngleRoll() |
91 | public int AngleRoll() |
82 | { |
92 | { |
83 | if (ufo_prober.is_mk()) |
93 | if (is_mk()) |
84 | return angle_roll; |
94 | return angle_roll; |
- | 95 | else |
|
85 | else if (ufo_prober.is_navi()) |
96 | if (is_navi()) |
Line 86... | Line 97... | ||
86 | 97 | ||
87 | return debug_data.analog[1]; |
98 | return debug_data.analog[1]; |
Line 88... | Line 99... | ||
88 | return -1; |
99 | return -1; |
Line 108... | Line 119... | ||
108 | // public final static int DATA_IN_BUFF_SIZE=512; |
119 | // public final static int DATA_IN_BUFF_SIZE=512; |
109 | public final static int DATA_IN_BUFF_SIZE=2048; |
120 | public final static int DATA_IN_BUFF_SIZE=2048; |
110 | // public final static int DATA_IN_BUFF_SIZE=4096; |
121 | // public final static int DATA_IN_BUFF_SIZE=4096; |
Line 111... | Line 122... | ||
111 | 122 | ||
112 | public byte user_intent=0; |
- | |
113 | public final static int[] crc16_table = { |
- | |
114 | 0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7, |
- | |
115 | 0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF, |
- | |
116 | 0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6, |
- | |
117 | 0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE, |
- | |
118 | 0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485, |
- | |
119 | 0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D, |
- | |
120 | 0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4, |
- | |
121 | 0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC, |
- | |
122 | 0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823, |
- | |
123 | 0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B, |
- | |
124 | 0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12, |
- | |
125 | 0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A, |
- | |
126 | 0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41, |
- | |
127 | 0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49, |
- | |
128 | 0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70, |
- | |
129 | 0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78, |
- | |
130 | 0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F, |
- | |
131 | 0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067, |
- | |
132 | 0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E, |
- | |
133 | 0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256, |
- | |
134 | 0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D, |
- | |
135 | 0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405, |
- | |
136 | 0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C, |
- | |
137 | 0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634, |
- | |
138 | 0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB, |
- | |
139 | 0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3, |
- | |
140 | 0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A, |
- | |
141 | 0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92, |
- | |
142 | 0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9, |
- | |
143 | 0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1, |
- | |
144 | 0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8, |
- | |
145 | 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0 |
- | |
Line 146... | Line 123... | ||
146 | }; |
123 | public byte user_intent=0; |
147 | 124 | ||
148 | public void log(String str) |
125 | public void log(String str) |
149 | { |
126 | { |
150 | //#ifdef android |
127 | //#ifdef android |
151 | if (do_log) Log.d("MK-Comm",str); |
128 | if (do_log) Log.d("MK-Comm",str); |
152 | //#endif |
129 | //#endif |
153 | // canvas.debug.log(str); |
130 | // canvas.debug.log(str); |
Line 154... | Line -... | ||
154 | // System.out.println(str); |
- | |
155 | } |
- | |
156 | - | ||
157 | public int CRC16(int ch, int crc) |
- | |
158 | { |
- | |
159 | return crc16_table[((crc >> 8) ^ (ch)) & 0xFF] ^ (crc << 8); |
- | |
160 | } |
131 | // System.out.println(str); |
161 | 132 | } |
|
162 | 133 | ||
163 | public int conn_time_in_s() |
134 | public int conn_time_in_s() |
164 | { |
135 | { |
165 | if (connected) |
136 | if (connected) |
166 | return (int)((System.currentTimeMillis()-connection_start_time)/1000); |
137 | return (int)((System.currentTimeMillis()-connection_start_time)/1000); |
167 | else |
- | |
168 | return 0; |
- | |
Line -... | Line 138... | ||
- | 138 | else |
|
169 | } |
139 | return 0; |
Line 170... | Line 140... | ||
170 | public final static byte BOOTLOADER_STAGE_NONE=0; |
140 | } |
171 | public final static byte BOOTLOADER_STAGE_GOT_MKBL=1; |
141 | |
172 | 142 | ||
Line 185... | Line 155... | ||
185 | public MKWatchDog watchdog; |
155 | public MKWatchDog watchdog; |
186 | public MKProxy proxy=null; |
156 | public MKProxy proxy=null; |
187 | public MKStatistics stats ; |
157 | public MKStatistics stats ; |
188 | // public DUBwiseDebug debug; |
158 | // public DUBwiseDebug debug; |
Line 189... | Line 159... | ||
189 | 159 | ||
190 | public UFOProber ufo_prober; |
160 | // public UFOProber ufo_prober; |
Line 191... | Line 161... | ||
191 | public long connection_start_time=-1; |
161 | public long connection_start_time=-1; |
Line 192... | Line 162... | ||
192 | 162 | ||
193 | 163 | ||
194 | public String error_str = null; |
164 | public String error_str = null; |
- | 165 | ||
- | 166 | ||
- | 167 | public final static byte FC_SLAVE_ADDR = 1; |
|
- | 168 | public final static byte NAVI_SLAVE_ADDR = 2; |
|
- | 169 | public final static byte MK3MAG_SLAVE_ADDR = 3; |
|
- | 170 | public final static byte FOLLOWME_SLAVE_ADDR = 10; |
|
- | 171 | public final static byte RE_SLAVE_ADDR = 23; |
|
- | 172 | ||
- | 173 | ||
- | 174 | ||
- | 175 | ||
- | 176 | public boolean is_navi() |
|
- | 177 | { |
|
- | 178 | return (slave_addr==NAVI_SLAVE_ADDR); |
|
- | 179 | } |
|
- | 180 | ||
- | 181 | ||
- | 182 | public boolean is_mk() |
|
- | 183 | { |
|
- | 184 | return (slave_addr==FC_SLAVE_ADDR); |
|
- | 185 | } |
|
- | 186 | ||
- | 187 | public boolean is_mk3mag() |
|
- | 188 | { |
|
- | 189 | return (slave_addr==MK3MAG_SLAVE_ADDR); |
|
- | 190 | } |
|
- | 191 | ||
- | 192 | public boolean is_rangeextender() |
|
- | 193 | { |
|
- | 194 | return (slave_addr==RE_SLAVE_ADDR); |
|
- | 195 | } |
|
- | 196 | ||
- | 197 | public boolean is_followme() |
|
- | 198 | { |
|
- | 199 | return (slave_addr==FOLLOWME_SLAVE_ADDR); |
|
- | 200 | } |
|
- | 201 | ||
- | 202 | ||
- | 203 | ||
- | 204 | public boolean is_incompatible() |
|
- | 205 | { |
|
- | 206 | switch (slave_addr) |
|
- | 207 | { |
|
- | 208 | case FC_SLAVE_ADDR: |
|
- | 209 | case NAVI_SLAVE_ADDR: |
|
- | 210 | case MK3MAG_SLAVE_ADDR: |
|
- | 211 | case FOLLOWME_SLAVE_ADDR: |
|
- | 212 | case RE_SLAVE_ADDR: |
|
Line -... | Line 213... | ||
- | 213 | return false; |
|
- | 214 | default: |
|
- | 215 | return true; |
|
- | 216 | } |
|
- | 217 | } |
|
- | 218 | ||
- | 219 | public String extended_name() |
|
- | 220 | { |
|
- | 221 | switch (slave_addr) |
|
Line -... | Line 222... | ||
- | 222 | { |
|
- | 223 | case -1: |
|
Line -... | Line 224... | ||
- | 224 | return "No Device"; |
|
- | 225 | ||
- | 226 | case FC_SLAVE_ADDR: |
|
- | 227 | return "MK-Connection"; |
|
- | 228 | ||
- | 229 | case NAVI_SLAVE_ADDR: |
|
- | 230 | return "Navi-Connection"; |
|
- | 231 | ||
- | 232 | case MK3MAG_SLAVE_ADDR: |
|
- | 233 | return "MK3MAG-Connection"; |
|
- | 234 | ||
- | 235 | case FOLLOWME_SLAVE_ADDR: |
|
Line 195... | Line 236... | ||
195 | 236 | return "FollowMe Connection"; |
|
196 | 237 | case RE_SLAVE_ADDR: |
|
197 | public final static int FC_SLAVE_ADDR = 'a'+1; |
238 | return "RangeExtender Connection"; |
198 | public final static int NAVI_SLAVE_ADDR = 'a'+2; |
239 | |
Line 246... | Line 287... | ||
246 | LCD= new MKLCD(this); |
287 | LCD= new MKLCD(this); |
247 | watchdog=new MKWatchDog(this); |
288 | watchdog=new MKWatchDog(this); |
248 | gps_position=new MKGPSPosition(); |
289 | gps_position=new MKGPSPosition(); |
249 | stats = new MKStatistics(); |
290 | stats = new MKStatistics(); |
250 | proxy =new MKProxy(this); |
291 | proxy =new MKProxy(this); |
251 | ufo_prober=new UFOProber(); |
292 | // ufo_prober=new UFOProber(); |
252 | new Thread( this ).start(); // fire up main Thread |
293 | new Thread( this ).start(); // fire up main Thread |
253 | } |
294 | } |
Line 379... | Line 420... | ||
379 | 420 | ||
Line 380... | Line 421... | ||
380 | return out_arr; |
421 | return out_arr; |
Line -... | Line 422... | ||
- | 422 | ||
- | 423 | } |
|
381 | 424 | ||
382 | } |
425 | |
383 | 426 | ||
384 | public void wait4send() |
427 | public void wait4send() |
385 | { |
428 | { |
Line 418... | Line 461... | ||
418 | { |
461 | { |
419 | stats.motortest_request_count++; |
462 | stats.motortest_request_count++; |
420 | send_command(FC_SLAVE_ADDR,'t',params); |
463 | send_command(FC_SLAVE_ADDR,'t',params); |
421 | } |
464 | } |
Line -... | Line 465... | ||
- | 465 | ||
- | 466 | public void set_mixer_table(int[] params) |
|
- | 467 | { |
|
- | 468 | ||
- | 469 | send_command(FC_SLAVE_ADDR,'m',params); |
|
- | 470 | } |
|
- | 471 | ||
- | 472 | ||
- | 473 | public long lon; |
|
- | 474 | public long lat; |
|
- | 475 | ||
- | 476 | public void send_follow_me(int time) |
|
- | 477 | { |
|
- | 478 | long alt=0; |
|
- | 479 | ||
- | 480 | int[] params=new int[29]; |
|
- | 481 | ||
- | 482 | ||
- | 483 | params[0]=(int)((lon)&0xFF) ; |
|
- | 484 | params[1]=(int)((lon>>8)&0xFF) ; |
|
- | 485 | params[2]=(int)((lon>>16)&0xFF) ; |
|
- | 486 | params[3]=(int)((lon>>24)&0xFF) ; |
|
- | 487 | ||
- | 488 | params[4]=(int)((lat)&0xFF) ; |
|
- | 489 | params[5]=(int)((lat>>8)&0xFF) ; |
|
- | 490 | params[6]=(int)((lat>>16)&0xFF) ; |
|
- | 491 | params[7]=(int)((lat>>24)&0xFF) ; |
|
- | 492 | ||
- | 493 | params[8]=(int)((alt)&0xFF ); |
|
- | 494 | params[9]=(int)((alt>>8)&0xFF ); |
|
- | 495 | params[10]=(int)((alt>>16)&0xFF); |
|
- | 496 | params[11]=(int)((alt>>24)&0xFF ); |
|
- | 497 | ||
- | 498 | params[12]=2; // newdata |
|
- | 499 | ||
- | 500 | params[13]=0; // heading |
|
- | 501 | params[14]=0; // heading |
|
- | 502 | ||
- | 503 | params[15]=1; // tolerance |
|
- | 504 | ||
- | 505 | params[16]=time; // time |
|
- | 506 | params[17]=0; // event |
|
- | 507 | ||
- | 508 | send_command(NAVI_SLAVE_ADDR,'s',params); |
|
- | 509 | } |
|
Line 422... | Line 510... | ||
422 | 510 | ||
423 | 511 | ||
Line 424... | Line 512... | ||
424 | public void send_extern_control() |
512 | public void send_extern_control() |
Line 504... | Line 592... | ||
504 | 592 | ||
Line 505... | Line 593... | ||
505 | switch_todo(); |
593 | switch_todo(); |
Line 506... | Line -... | ||
506 | - | ||
- | 594 | ||
507 | } |
595 | } |
Line 508... | Line 596... | ||
508 | 596 | ||
Line 509... | Line 597... | ||
509 | public String[] flash_msgs; |
597 | |
Line 510... | Line -... | ||
510 | int msg_pos=0; |
- | |
511 | - | ||
Line -... | Line 598... | ||
- | 598 | int msg_pos=0; |
|
- | 599 | ||
- | 600 | ||
512 | 601 | // public boolean bootloader_intension_flash=false; |
|
513 | public boolean bootloader_intension_flash=false; |
602 | |
514 | 603 | // public boolean bootloader_finish_ok=false; |
|
515 | public boolean bootloader_finish_ok=false; |
604 | |
516 | 605 | ||
517 | public void jump_bootloader() |
606 | // public void jump_bootloader() |
518 | { |
607 | // { |
Line 519... | Line 608... | ||
519 | 608 | /* |
|
520 | bootloader_finish_ok=false; |
609 | bootloader_finish_ok=false; |
Line 554... | Line 643... | ||
554 | flash_msgs[msg_pos++]="Exception:" +e.getMessage() ; |
643 | flash_msgs[msg_pos++]="Exception:" +e.getMessage() ; |
555 | flash_msgs[msg_pos++]=e.toString() ; |
644 | flash_msgs[msg_pos++]=e.toString() ; |
556 | } |
645 | } |
Line 557... | Line 646... | ||
557 | 646 | ||
- | 647 | new Thread( this ).start(); // fire up main Thread |
|
558 | new Thread( this ).start(); // fire up main Thread |
648 | */ |
Line 559... | Line 649... | ||
559 | } |
649 | // } |
560 | 650 | ||
561 | 651 | ||
Line 613... | Line 703... | ||
613 | { |
703 | { |
614 | // 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 |
704 | // 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 |
Line 615... | Line 705... | ||
615 | 705 | ||
616 | byte[] send_buff=new byte[3 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
706 | byte[] send_buff=new byte[3 + (params.length/3 + (params.length%3==0?0:1) )*4]; // 5=1*start_char+1*addr+1*cmd+2*crc |
617 | send_buff[0]='#'; |
707 | send_buff[0]='#'; |
618 | send_buff[1]=modul; |
708 | send_buff[1]=(byte)(modul+'a'); |
Line 619... | Line 709... | ||
619 | send_buff[2]=(byte)cmd; |
709 | send_buff[2]=(byte)cmd; |
620 | 710 | ||
621 | for(int param_pos=0;param_pos<(params.length/3 + (params.length%3==0?0:1)) ;param_pos++) |
711 | for(int param_pos=0;param_pos<(params.length/3 + (params.length%3==0?0:1)) ;param_pos++) |
Line 668... | Line 758... | ||
668 | send_command_nocheck((byte)modul,cmd,params); |
758 | send_command_nocheck((byte)modul,cmd,params); |
669 | sending=false; |
759 | sending=false; |
670 | } |
760 | } |
Line 671... | Line -... | ||
671 | - | ||
- | 761 | ||
Line 672... | Line 762... | ||
672 | 762 | ||
673 | public int slave_addr=-1; |
763 | |
- | 764 | ||
- | 765 | ||
- | 766 | public int UBatt() |
|
674 | 767 | { |
|
675 | 768 | ||
- | 769 | switch (slave_addr) |
|
676 | public int UBatt() |
770 | { |
677 | { |
771 | case FC_SLAVE_ADDR: |
- | 772 | return debug_data.analog[8]; |
|
- | 773 | ||
- | 774 | case NAVI_SLAVE_ADDR: |
|
- | 775 | return gps_position.UBatt; |
|
- | 776 | ||
- | 777 | case FOLLOWME_SLAVE_ADDR: |
|
- | 778 | return debug_data.analog[8]; |
|
- | 779 | ||
- | 780 | default: |
|
- | 781 | return -1; // No Info |
|
- | 782 | } |
|
- | 783 | ||
- | 784 | } |
|
- | 785 | ||
- | 786 | ||
- | 787 | ||
- | 788 | public int SatsInUse() |
|
- | 789 | { |
|
- | 790 | ||
- | 791 | switch (slave_addr) |
|
- | 792 | { |
|
- | 793 | case NAVI_SLAVE_ADDR: |
|
678 | if (ufo_prober.is_mk()) |
794 | return gps_position.SatsInUse; |
- | 795 | ||
679 | return debug_data.UBatt(); |
796 | case FOLLOWME_SLAVE_ADDR: |
- | 797 | return debug_data.analog[12]; |
|
Line 680... | Line 798... | ||
680 | else if (ufo_prober.is_navi()) |
798 | |
Line 681... | Line 799... | ||
681 | return gps_position.UBatt; |
799 | default: |
682 | 800 | return -1; // No Info |
|
683 | return -1; |
801 | } |
684 | 802 | ||
685 | } |
803 | } |
686 | 804 | ||
687 | 805 | ||
- | 806 | ||
688 | 807 | public int SenderOkay() |
|
Line -... | Line 808... | ||
- | 808 | { |
|
- | 809 | switch (slave_addr) |
|
- | 810 | { |
|
689 | public int SenderOkay() |
811 | case FC_SLAVE_ADDR: |
Line 690... | Line 812... | ||
690 | { |
812 | return debug_data.analog[10]; |
691 | if (ufo_prober.is_mk()) |
813 | |
Line 736... | Line 858... | ||
736 | } |
858 | } |
Line 737... | Line 859... | ||
737 | 859 | ||
738 | public void process_data(byte[] data,int len) |
860 | public void process_data(byte[] data,int len) |
Line -... | Line 861... | ||
- | 861 | { |
|
- | 862 | ||
- | 863 | // check crc |
|
- | 864 | int tmp_crc=0; |
|
- | 865 | for ( int i=0 ; i<len-2 ; i++) |
|
- | 866 | tmp_crc+=(int)data[i]; |
|
- | 867 | ||
- | 868 | tmp_crc%=4096; |
|
- | 869 | ||
- | 870 | if (!((data[len-2]==(char)(tmp_crc/64 + '=')) |
|
- | 871 | && |
|
- | 872 | (data[len-1]==(char)(tmp_crc%64 + '=')))) |
|
- | 873 | { |
|
- | 874 | stats.crc_fail++; |
|
- | 875 | return; |
|
- | 876 | } |
|
739 | { |
877 | // end of c |
740 | 878 | ||
- | 879 | // slave_addr=data[1]; |
|
- | 880 | log("command " +(char)data[2] ); |
|
- | 881 | ||
- | 882 | ||
741 | slave_addr=data[1]; |
883 | int[] decoded_data=Decode64(data,3,len-5); |
742 | log("command " +(char)data[2] ); |
884 | |
Line 743... | Line 885... | ||
743 | switch((char)data[2]) |
885 | switch((char)data[2]) |
744 | { |
886 | { |
745 | 887 | ||
746 | case 'A': // debug Data Names |
888 | case 'A': // debug Data Names |
Line 747... | Line 889... | ||
747 | stats.debug_names_count++; |
889 | stats.debug_names_count++; |
748 | debug_data.set_names_by_mk_data(Decode64(data,3,len-3)); |
890 | debug_data.set_names_by_mk_data(decoded_data); |
749 | break; |
891 | break; |
Line 750... | Line 892... | ||
750 | 892 | ||
751 | case 'B': // external_control confirm frames |
893 | case 'B': // external_control confirm frames |
752 | stats.external_control_confirm_frame_count++; |
894 | stats.external_control_confirm_frame_count++; |
Line 753... | Line 895... | ||
753 | break; |
895 | break; |
Line 754... | Line 896... | ||
754 | 896 | ||
755 | case 'L': // LCD Data |
897 | case 'L': // LCD Data |
756 | stats.lcd_data_count++; |
898 | stats.lcd_data_count++; |
757 | LCD.handle_lcd_data(Decode64(data,3,len-3)); |
899 | LCD.handle_lcd_data(decoded_data); |
Line 758... | Line 900... | ||
758 | 900 | ||
759 | break; |
901 | break; |
760 | 902 | ||
761 | case 'D': // debug Data |
903 | case 'D': // debug Data |
762 | log("got debug data"); |
904 | log("got debug data"); |
763 | stats.debug_data_count++; |
905 | stats.debug_data_count++; |
Line 781... | Line 923... | ||
781 | log("processed debug data"); |
923 | log("processed debug data"); |
782 | break; |
924 | break; |
Line 783... | Line 925... | ||
783 | 925 | ||
784 | case 'V': // Version Info |
926 | case 'V': // Version Info |
785 | stats.version_data_count++; |
927 | stats.version_data_count++; |
- | 928 | if (slave_addr!=data[1]-'a') |
|
- | 929 | { |
|
- | 930 | slave_addr=(byte)(data[1]-'a'); |
|
- | 931 | change_notify=true; |
|
Line -... | Line 932... | ||
- | 932 | } |
|
786 | slave_addr=data[1]; |
933 | |
787 | 934 | /* |
|
788 | switch(slave_addr) |
935 | switch(slave_addr) |
789 | { |
936 | { |
790 | case FC_SLAVE_ADDR: |
937 | case FC_SLAVE_ADDR: |
Line 794... | Line 941... | ||
794 | case NAVI_SLAVE_ADDR: |
941 | case NAVI_SLAVE_ADDR: |
795 | ufo_prober.set_to_navi(); |
942 | ufo_prober.set_to_navi(); |
796 | break; |
943 | break; |
Line 797... | Line 944... | ||
797 | 944 | ||
798 | case MK3MAG_SLAVE_ADDR: |
- | |
799 | // ufo_prober.set_to_mk(); |
945 | case MK3MAG_SLAVE_ADDR: |
800 | ufo_prober.set_to_mk3mag(); |
946 | ufo_prober.set_to_mk3mag(); |
Line -... | Line 947... | ||
- | 947 | break; |
|
- | 948 | ||
- | 949 | case RE_SLAVE_ADDR: |
|
- | 950 | ufo_prober.set_to_rangeextender(); |
|
801 | break; |
951 | break; |
802 | 952 | ||
803 | default: |
953 | default: |
804 | ufo_prober.set_to_incompatible(); |
954 | ufo_prober.set_to_incompatible(); |
- | 955 | break; |
|
Line 805... | Line -... | ||
805 | break; |
- | |
806 | } |
956 | } |
807 | 957 | */ |
|
Line 808... | Line 958... | ||
808 | 958 | ||
809 | version.set_by_mk_data(Decode64(data,3,len-3)); |
- | |
810 | break; |
959 | version.set_by_mk_data(decoded_data); |
811 | 960 | break; |
|
812 | case 'w': |
961 | |
813 | int[] dec=Decode64(data,3,len-3); |
- | |
814 | angle_nick=MKHelper.parse_signed_int_2(dec[0],dec[1]); |
962 | case 'w': |
Line 815... | Line 963... | ||
815 | angle_roll=MKHelper.parse_signed_int_2(dec[2],dec[3]); |
963 | angle_nick=MKHelper.parse_signed_int_2(decoded_data[0],decoded_data[1]); |
816 | stats.angle_data_count++; |
964 | angle_roll=MKHelper.parse_signed_int_2(decoded_data[2],decoded_data[3]); |
817 | 965 | stats.angle_data_count++; |
|
818 | break; |
966 | break; |
819 | 967 | ||
820 | 968 | ||
821 | case 'Q': |
969 | case 'Q': |
822 | if (ufo_prober.is_mk()) |
970 | if (is_mk()) |
- | 971 | { |
|
- | 972 | stats.params_data_count++; |
|
- | 973 | params.set_by_mk_data(decoded_data); |
|
- | 974 | } |
|
823 | { |
975 | break; |
824 | stats.params_data_count++; |
976 | |
825 | params.set_by_mk_data(Decode64(data,3,len-3)); |
977 | case 'M': |
826 | } |
978 | mixer_change_notify=true; |
Line 827... | Line -... | ||
827 | break; |
- | |
828 | 979 | mixer_change_success=(decoded_data[0]==1); |
|
829 | case 'P': |
980 | break; |
830 | stats.stick_data_count++; |
981 | case 'P': |
831 | stick_data.set_by_mk_data(Decode64(data,3,20)); |
982 | stats.stick_data_count++; |
832 | break; |
983 | stick_data.set_by_mk_data(decoded_data); |
833 | 984 | break; |
|
Line 834... | Line 985... | ||
834 | 985 | ||
835 | case 'E': |
986 | |
836 | int[] dec_data=Decode64(data,3,len-3); |
987 | case 'E': // Error Str from Navi |
837 | error_str=""; |
988 | error_str=""; |
Line 838... | Line 989... | ||
838 | for(int foo=0;foo<20;foo++) |
989 | for(int foo=0;foo<20;foo++) |
Line 839... | Line 990... | ||
839 | if (dec_data[foo]!=0) |
990 | if (decoded_data[foo]!=0) |
840 | error_str+=(char)dec_data[foo]; |
991 | error_str+=(char)decoded_data[foo]; |
841 | break; |
992 | break; |
842 | 993 | ||
843 | - | ||
844 | case 'O': |
- | |
Line 845... | Line 994... | ||
845 | stats.navi_data_count++; |
994 | |
Line 846... | Line -... | ||
846 | log("got navi data(" + len +"):"); |
- | |
847 | - | ||
848 | gps_position.set_by_mk_data(Decode64(data,3,len-3),version); |
- | |
849 | 995 | case 'O': // OSD Values Str from Navi |
|
850 | stats.process_mkflags(gps_position.MKFlags); |
996 | stats.navi_data_count++; |
851 | stats.process_compas(gps_position.CompasHeading); |
997 | log("got navi data(" + len +"):"); |
Line 852... | Line 998... | ||
852 | stats.process_speed(gps_position.GroundSpeed); |
998 | |
Line 874... | Line 1020... | ||
874 | 1020 | ||
875 | public void close_connections(boolean force) |
1021 | public void close_connections(boolean force) |
Line 876... | Line 1022... | ||
876 | { |
1022 | { |
877 | 1023 | ||
878 | // if ((!force)&&root.canvas.do_vibra) root.vibrate(500); |
1024 | // if ((!force)&&root.canvas.do_vibra) root.vibrate(500); |
879 | force_disconnect=force; |
1025 | force_disconnect|=force; |
Line 880... | Line 1026... | ||
880 | try{ reader.close(); } |
1026 | try{ reader.close(); } |
881 | catch (Exception inner_ex) { } |
1027 | catch (Exception inner_ex) { } |
Line 882... | Line 1028... | ||
882 | 1028 | ||
883 | try{ writer.close(); } |
1029 | try{ writer.close(); } |
884 | catch (Exception inner_ex) { } |
1030 | catch (Exception inner_ex) { } |
885 | 1031 | ||
- | 1032 | //#ifdef j2me |
|
886 | //#ifdef j2me |
1033 | //# try{ connection.close(); } |
887 | //# try{ connection.close(); } |
1034 | //# catch (Exception inner_ex) { } |
888 | //# catch (Exception inner_ex) { } |
1035 | //#endif |
889 | //#endif |
1036 | slave_addr=-1; |
- | 1037 | // ufo_prober.set_to_none(); |
|
890 | ufo_prober.set_to_none(); |
1038 | stats.reset(); |
891 | stats.reset(); |
1039 | connected=false; |
Line -... | Line 1040... | ||
- | 1040 | version.reset(); |
|
- | 1041 | // if (bootloader_stage==BOOTLOADER_STAGE_NONE) |
|
892 | connected=false; |
1042 | disconnect_notify=true; |
893 | version.reset(); |
1043 | } |
894 | disconnect_notify=true; |
1044 | |
895 | } |
1045 | |
896 | 1046 | int last_avr_sig=-1; |
|
897 | // Thread to recieve data from Connection |
1047 | // Thread to recieve data from Connection |
898 | public void run() |
1048 | public void run() |
899 | { |
- | |
900 | boolean sigfail=false; |
- | |
901 | if (bootloader_stage==BOOTLOADER_STAGE_GOT_MKBL) |
- | |
902 | { |
- | |
903 | try { |
- | |
904 | flash_msgs[msg_pos++]="reading avr_sig"; |
- | |
Line 905... | Line -... | ||
905 | - | ||
906 | writer.write( 't'); |
- | |
907 | writer.flush(); |
- | |
908 | - | ||
909 | int avr_sig=reader.read(); |
- | |
910 | - | ||
911 | //while (avr_sig==63) |
- | |
912 | // avr_sig=reader.read(); |
- | |
913 | - | ||
914 | flash_msgs[msg_pos++]="got avr sig " + avr_sig; |
- | |
915 | - | ||
916 | int avrsig_suff=reader.read(); |
- | |
917 | if (avrsig_suff!=0) |
- | |
918 | throw new Exception("val after avrsig is" +avrsig_suff +"should b 0"); |
- | |
919 | - | ||
920 | if ((avr_sig!=0x74)&&(avr_sig!=224)&&(avr_sig!=120)) |
- | |
921 | { |
- | |
922 | sigfail=true; |
- | |
923 | throw new Exception("avr sig" + avr_sig + " unknown"); |
- | |
924 | } |
- | |
925 | - | ||
926 | writer.write('T'); |
- | |
927 | // writer.flush(); |
- | |
928 | writer.write(avr_sig); // set devicetyp = 0x74 oder 0x76 |
- | |
929 | writer.flush(); |
- | |
930 | - | ||
931 | if (reader.read()!=0x0d) |
- | |
932 | throw new Exception("cant get buffer size"); |
- | |
933 | - | ||
934 | writer.write('V'); |
- | |
935 | writer.flush(); |
- | |
936 | - | ||
937 | int bl_version_major=reader.read(); |
- | |
938 | int bl_version_minor=reader.read(); |
- | |
939 | - | ||
940 | flash_msgs[msg_pos++]="BL Version " + bl_version_major+"."+bl_version_minor; |
- | |
941 | - | ||
942 | - | ||
943 | writer.write('b'); |
- | |
944 | writer.flush(); |
- | |
945 | - | ||
946 | if (reader.read()!='Y') |
- | |
947 | throw new Exception("cant get buffer size"); |
- | |
948 | 1049 | { |
|
949 | int send_buff_size1=reader.read(); |
1050 | // boolean sigfail=false; |
Line 950... | Line 1051... | ||
950 | int send_buff_size2=reader.read(); |
1051 | /* if (bootloader_stage==BOOTLOADER_STAGE_GOT_MKBL) |
951 | int send_buff_size=send_buff_size1*0x100+send_buff_size2; |
1052 | { |
952 | 1053 | try { |
|
Line 953... | Line 1054... | ||
953 | flash_msgs[msg_pos++]="BUFF Size:" + send_buff_size; |
1054 | |
Line 954... | Line 1055... | ||
954 | // if (send_buff_size>128) |
1055 | // if (send_buff_size>128) |
Line 975... | Line 1076... | ||
975 | 1076 | |
|
976 | firmware_size= ((int)in.read()<<24) |((int)in.read()<<16) | ((int)in.read()<<8) | ((int)in.read()&0xff) ; |
1077 | firmware_size= ((int)in.read()<<24) |((int)in.read()<<16) | ((int)in.read()<<8) | ((int)in.read()&0xff) ; |
977 | } |
1078 | } |
Line 978... | Line -... | ||
978 | catch (Exception e) { throw new Exception(" .. cant read size"); } |
- | |
979 | - | ||
980 | 1079 | catch (Exception e) { throw new Exception(" .. cant read size"); } |
|
981 | 1080 | |
|
Line 982... | Line -... | ||
982 | int blocks2write=((firmware_size/send_buff_size)); |
- | |
983 | flash_msgs[msg_pos++]=".. open("+blocks2write+" blocks," + firmware_size + "bytes)"; |
1081 | int blocks2write=((firmware_size/send_buff_size)); |
Line 984... | Line 1082... | ||
984 | 1082 | flash_msgs[msg_pos++]=".. open("+blocks2write+" blocks," + firmware_size + "bytes)"; |
|
Line 985... | Line 1083... | ||
985 | 1083 | |
|
Line 1050... | Line 1148... | ||
1050 | 1148 | |
|
1051 | 1149 | |
|
- | 1150 | |
|
- | 1151 | // sleep(1000); |
|
- | 1152 | } |
|
1052 | 1153 | ||
1053 | // sleep(1000); |
1154 | |
Line 1054... | Line 1155... | ||
1054 | } |
1155 | */ |
1055 | // flash_msgs[msg_pos]="bl:" + block + "/" + blocks2write + " si:"+hex_bytes_read ; |
1156 | // flash_msgs[msg_pos]="bl:" + block + "/" + blocks2write + " si:"+hex_bytes_read ; |
Line 1117... | Line 1218... | ||
1117 | |
1218 | |
Line 1118... | Line 1219... | ||
1118 | } |
1219 | } |
1119 | 1220 | ||
- | 1221 | } |
|
- | 1222 | */ |
|
- | 1223 | ||
- | 1224 | ||
1120 | } |
1225 | |
1121 | */ |
1226 | /** |
1122 | flash_msgs[++msg_pos]="written last block "; |
1227 | flash_msgs[++msg_pos]="written last block "; |
Line 1123... | Line 1228... | ||
1123 | msg_pos++; |
1228 | msg_pos++; |
Line 1184... | Line 1289... | ||
1184 | 1289 | ||
1185 | 1290 | ||
Line -... | Line 1291... | ||
- | 1291 | sending=false; |
|
Line 1186... | Line 1292... | ||
1186 | sending=false; |
1292 | } |
1187 | } |
1293 | |
Line 1188... | Line -... | ||
1188 | - | ||
1189 | - | ||
1190 | byte[] data_set=new byte[1024]; |
- | |
1191 | int data_set_pos=0; |
1294 | **/ |
Line 1192... | Line 1295... | ||
1192 | 1295 | ||
1193 | 1296 | byte[] data_set=new byte[1024]; |
|
Line 1194... | Line -... | ||
1194 | - | ||
1195 | - | ||
1196 | byte[] data_in_buff=new byte[DATA_IN_BUFF_SIZE]; |
- | |
1197 | - | ||
1198 | int input; |
1297 | int data_set_pos=0; |
1199 | int pos=0; |
1298 | |
1200 | 1299 | byte[] data_in_buff=new byte[DATA_IN_BUFF_SIZE]; |
|
Line 1201... | Line 1300... | ||
1201 | 1300 | ||
1202 | 1301 | int input; |
|
- | 1302 | int pos=0; |
|
1203 | 1303 | ||
1204 | - | ||
1205 | log("Thread started"); |
1304 | log("Thread started"); |
1206 | while(true) |
1305 | while(thread_running) |
1207 | { |
1306 | { |
Line 1208... | Line 1307... | ||
1208 | 1307 | ||
Line 1273... | Line 1372... | ||
1273 | */ |
1372 | */ |
1274 | data_set_pos=0; |
1373 | data_set_pos=0; |
Line 1275... | Line 1374... | ||
1275 | 1374 | ||
1276 | } |
1375 | } |
1277 | else |
1376 | else |
1278 | { |
1377 | // { |
Line 1279... | Line 1378... | ||
1279 | data_set[data_set_pos++]=data_in_buff[pos]; |
1378 | data_set[data_set_pos++]=data_in_buff[pos]; |
Line 1280... | Line 1379... | ||
1280 | 1379 | ||
- | 1380 | /* |
|
1281 | 1381 | ||
- | 1382 | if ( (data_set_pos>4) && (data_set[data_set_pos-4]==(byte)'M') && (data_set[data_set_pos-3]==(byte)'K') && (data_set[data_set_pos-2]==(byte)'B') && (data_set[data_set_pos-1]==(byte)'L')) |
|
1282 | 1383 | ||
1283 | if ( (data_set_pos>4) && (data_set[data_set_pos-4]==(byte)'M') && (data_set[data_set_pos-3]==(byte)'K') && (data_set[data_set_pos-2]==(byte)'B') && (data_set[data_set_pos-1]==(byte)'L')) |
1384 | { |
1284 | { |
1385 | |
Line 1285... | Line 1386... | ||
1285 | bootloader_stage= BOOTLOADER_STAGE_GOT_MKBL; |
1386 | bootloader_stage= BOOTLOADER_STAGE_GOT_MKBL; |
Line 1286... | Line 1387... | ||
1286 | return; |
1387 | return; |
Line 1287... | Line 1388... | ||
1287 | } |
1388 | } |