Rev 231 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 231 | Rev 303 | ||
---|---|---|---|
Line 25... | Line 25... | ||
25 | public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
25 | public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes |
Line 26... | Line 26... | ||
26 | 26 | ||
27 | public MKLCD LCD; |
27 | public MKLCD LCD; |
28 | public MKVersion version; |
28 | public MKVersion version; |
- | 29 | public MKDebugData debug_data; |
|
29 | public MKDebugData debug_data; |
30 | public MKParamsParser params; |
Line 30... | Line 31... | ||
30 | public MKWatchDog watchdog; |
31 | public MKWatchDog watchdog; |
Line 44... | Line 45... | ||
44 | 45 | ||
45 | public int debug_data_count=0; |
46 | public int debug_data_count=0; |
46 | public int version_data_count=0; |
47 | public int version_data_count=0; |
47 | public int other_data_count=0; |
48 | public int other_data_count=0; |
- | 49 | public int lcd_data_count=0; |
|
Line -... | Line 50... | ||
- | 50 | public int params_data_count=0; |
|
- | 51 | ||
48 | public int lcd_data_count=0; |
52 | |
49 | 53 | String name; |
|
50 | 54 | ||
51 | /****************** Section: public Methods ************************************************/ |
55 | /****************** Section: public Methods ************************************************/ |
52 | public MKCommunicator(String url) // Constructor with URL string e.g. "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
56 | public MKCommunicator() |
- | 57 | { |
|
53 | { |
58 | version=new MKVersion(); |
Line -... | Line 59... | ||
- | 59 | debug_data=new MKDebugData(); |
|
- | 60 | params=new MKParamsParser(); |
|
54 | version=new MKVersion(); |
61 | // mk_url=url; // remember URL for connecting / reconnecting later |
55 | debug_data=new MKDebugData(); |
62 | |
Line -... | Line 63... | ||
- | 63 | LCD= new MKLCD(this); |
|
- | 64 | watchdog=new MKWatchDog(this); |
|
- | 65 | new Thread( this ).start(); // fire up main Thread |
|
- | 66 | } |
|
- | 67 | ||
- | 68 | ||
- | 69 | ||
- | 70 | // URL string: "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control |
|
- | 71 | public void connect_to(String _url,String _name) |
|
- | 72 | { |
|
56 | mk_url=url; // remember URL for connecting / reconnecting later |
73 | mk_url=_url; |
57 | 74 | name=_name; |
|
58 | new Thread( this ).start(); // fire up main Thread |
75 | force_disconnect=false; |
- | 76 | connected=false; |
|
59 | } |
77 | } |
60 | 78 | ||
61 | 79 | /****************** Section: private Methods ************************************************/ |
|
62 | /****************** Section: private Methods ************************************************/ |
80 | private void connect() |
Line 72... | Line 90... | ||
72 | get_version(); |
90 | get_version(); |
73 | lcd_data_count=0; |
91 | lcd_data_count=0; |
74 | debug_data_count=0; |
92 | debug_data_count=0; |
75 | version_data_count=0; |
93 | version_data_count=0; |
Line 76... | Line -... | ||
76 | - | ||
77 | LCD= new MKLCD(this); |
- | |
- | 94 | ||
78 | watchdog=new MKWatchDog(this); |
95 | |
79 | } |
96 | } |
80 | catch (Exception ex) |
97 | catch (Exception ex) |
81 | { |
98 | { |
82 | // TODO difference fatal errors from those which will lead to reconnection |
99 | // TODO difference fatal errors from those which will lead to reconnection |
Line 123... | Line 140... | ||
123 | public void get_version() |
140 | public void get_version() |
124 | { |
141 | { |
125 | send_command(0,'v',new int[0]); |
142 | send_command(0,'v',new int[0]); |
126 | } |
143 | } |
Line 127... | Line -... | ||
127 | - | ||
- | 144 | ||
128 | 145 | // send a MotorTest request - params are the speed for each Motor |
|
129 | public void motor_test(int[] params) |
146 | public void motor_test(int[] params) |
130 | { |
147 | { |
131 | send_command(0,'t',params); |
148 | send_command(0,'t',params); |
Line -... | Line 149... | ||
- | 149 | } |
|
- | 150 | ||
- | 151 | // get params |
|
- | 152 | public void get_params(int id) |
|
- | 153 | { |
|
- | 154 | int[] params=new int[1]; |
|
- | 155 | params[0]=id; |
|
- | 156 | ||
- | 157 | send_command(0,'q',params); |
|
- | 158 | } |
|
- | 159 | ||
Line 132... | Line 160... | ||
132 | } |
160 | |
133 | 161 | ||
134 | 162 | ||
135 | // send command to FC ( add crc and pack into pseudo Base64 |
163 | // send command to FC ( add crc and pack into pseudo Base64 |
Line 207... | Line 235... | ||
207 | case '3': |
235 | case '3': |
208 | LCD.handle_lcd_data(Decode64(data,3,20),data[2]-(int)'0'); |
236 | LCD.handle_lcd_data(Decode64(data,3,20),data[2]-(int)'0'); |
209 | lcd_data_count++; |
237 | lcd_data_count++; |
210 | break; |
238 | break; |
Line -... | Line 239... | ||
- | 239 | ||
- | 240 | case 'L': |
|
- | 241 | case 'M': |
|
- | 242 | case 'N': |
|
- | 243 | case 'O': |
|
- | 244 | case 'P': |
|
- | 245 | params.set_by_mk_data(Decode64(data,3,58),version); |
|
- | 246 | params_data_count++; |
|
- | 247 | break; |
|
211 | 248 | ||
212 | default: |
249 | default: |
213 | other_data_count++; |
250 | other_data_count++; |
Line 214... | Line 251... | ||
214 | break; |
251 | break; |
Line 220... | Line 257... | ||
220 | 257 | ||
Line 221... | Line 258... | ||
221 | } |
258 | } |
Line 222... | Line 259... | ||
222 | 259 | ||
Line 223... | Line 260... | ||
223 | String o_msg=""; |
260 | String o_msg=""; |
224 | 261 | ||
225 | public boolean force_disconnect=false; |
262 | public boolean force_disconnect=true; |
226 | 263 |