Rev 216 | Rev 222 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 216 | Rev 219 | ||
---|---|---|---|
1 | /************************************** |
1 | /************************************** |
2 | * |
2 | * |
3 | * WatchDog for MK-Connection |
3 | * WatchDog for MK-Connection |
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 | package org.ligi.ufo; |
12 | package org.ligi.ufo; |
13 | 13 | ||
14 | public class MKWatchDog |
14 | public class MKWatchDog |
15 | implements Runnable,DUBwiseDefinitions |
15 | implements Runnable,DUBwiseDefinitions |
16 | { |
16 | { |
17 | MKCommunicator mk=null; |
17 | MKCommunicator mk=null; |
18 | 18 | ||
19 | int debug_data_count_buff=-123; |
19 | int debug_data_count_buff=-123; |
20 | 20 | ||
21 | public MKWatchDog(MKCommunicator _mk) |
21 | public MKWatchDog(MKCommunicator _mk) |
22 | { |
22 | { |
23 | 23 | ||
24 | mk=_mk; |
24 | mk=_mk; |
25 | new Thread( this ).start(); // fire up main Thread |
25 | new Thread( this ).start(); // fire up main Thread |
26 | } |
26 | } |
27 | 27 | ||
28 | 28 | ||
29 | public int act_paramset=0; |
29 | public int act_paramset=0; |
30 | int conn_check_timeout=0; |
30 | int conn_check_timeout=0; |
31 | 31 | ||
32 | 32 | ||
33 | public byte resend_timeout=0; |
33 | public byte resend_timeout=0; |
34 | int last_count=0; |
34 | int last_count=0; |
35 | 35 | ||
- | 36 | ||
- | 37 | public boolean resend_check(int ref_count) |
|
- | 38 | { |
|
- | 39 | if (( last_count!=ref_count)||(resend_timeout<0)) |
|
- | 40 | { |
|
- | 41 | if (resend_timeout<0) mk.stats.resend_count++; |
|
- | 42 | last_count=ref_count; |
|
- | 43 | resend_timeout=20; |
|
- | 44 | return true; |
|
- | 45 | } |
|
- | 46 | else |
|
- | 47 | resend_timeout--; |
|
- | 48 | ||
- | 49 | return false; |
|
- | 50 | } |
|
36 | 51 | ||
37 | //#ifdef android |
52 | //#ifdef android |
38 | // public final static int BASE_SLEEP=50; |
53 | // public final static int BASE_SLEEP=50; |
39 | //#else |
54 | //#else |
40 | public final static int BASE_SLEEP=40; |
55 | public final static int BASE_SLEEP=10; |
41 | //#endif |
56 | //#endif |
42 | 57 | ||
43 | public void run() |
58 | public void run() |
44 | { |
59 | { |
45 | mk.log("starting Watchdog"); |
60 | mk.log("starting Watchdog"); |
46 | // get all params |
61 | // get all params |
47 | int act_debug_name=0; |
62 | int act_debug_name=0; |
48 | int sleeper=BASE_SLEEP; |
63 | // int sleeper=BASE_SLEEP; |
49 | while(true) |
64 | while(true) |
50 | { |
65 | { |
51 | try { |
66 | try { |
52 | Thread.sleep(sleeper); |
67 | Thread.sleep(BASE_SLEEP); |
53 | sleeper=BASE_SLEEP; |
68 | // sleeper=BASE_SLEEP; |
54 | if (mk.connected&&(!mk.force_disconnect)) |
69 | if (mk.connected&&(!mk.force_disconnect)) |
55 | { |
70 | { |
56 | 71 | ||
57 | mk.log("watchdog pre main loop"); |
72 | mk.log("watchdog pre main loop"); |
58 | /* if (mk.root.canvas.init_bootloader) |
73 | if (mk.init_bootloader) |
59 | { |
74 | { |
60 | mk.jump_bootloader(); |
75 | mk.jump_bootloader(); |
61 | mk.root.canvas.init_bootloader=false; |
76 | mk.init_bootloader=false; |
62 | } |
77 | } |
63 | else */if ( mk.version.major==-1 ) |
78 | else if ( mk.version.major==-1 ) |
64 | mk.get_version(); |
79 | mk.get_version(); |
65 | else if (mk.ufo_prober.is_navi()&&(mk.error_str==null)) |
80 | else if (mk.ufo_prober.is_navi()&&(mk.error_str==null)) |
66 | mk.get_error_str(); |
81 | mk.get_error_str(); |
67 | 82 | ||
68 | else if (mk.ufo_prober.is_mk()&&(mk.params.last_parsed_paramset==-1)) |
83 | else if (mk.ufo_prober.is_mk()&&(mk.params.last_parsed_paramset==-1)) |
69 | { |
84 | { |
70 | mk.get_params(0xFF-1); |
85 | mk.get_params(0xFF-1); |
71 | sleeper+=150; |
86 | Thread.sleep(150); |
- | 87 | ||
72 | act_paramset=0; // warning - if dropped problem |
88 | act_paramset=0; // warning - if dropped problem |
73 | } |
89 | } |
74 | else switch (mk.user_intent) |
90 | else switch (mk.user_intent) |
75 | { |
91 | { |
76 | case USER_INTENT_PARAMS: |
92 | case USER_INTENT_PARAMS: |
77 | 93 | ||
78 | if ((act_paramset<5)) |
94 | if ((act_paramset<5)) |
79 | { |
95 | { |
80 | 96 | ||
81 | if (resend_timeout==0) { |
97 | if (resend_timeout==0) { |
82 | mk.get_params(act_paramset); |
98 | mk.get_params(act_paramset); |
83 | resend_timeout=120; |
99 | resend_timeout=120; |
84 | } |
100 | } |
85 | 101 | ||
86 | if(mk.params.field[act_paramset]!=null) |
102 | if(mk.params.field[act_paramset]!=null) |
87 | { |
103 | { |
88 | mk.get_params(++act_paramset); |
104 | mk.get_params(++act_paramset); |
89 | resend_timeout=120; |
105 | resend_timeout=120; |
90 | } |
106 | } |
91 | else |
107 | else |
92 | resend_timeout--; |
108 | resend_timeout--; |
93 | /* |
109 | /* |
94 | // act_paramset++; |
110 | // act_paramset++; |
95 | else |
111 | else |
96 | mk.get_params(act_paramset); |
112 | mk.get_params(act_paramset); |
97 | |
113 | |
98 | sleeper+=1200; |
114 | sleeper+=1200; |
99 | */ |
115 | */ |
100 | } |
116 | } |
101 | break; |
117 | break; |
102 | case USER_INTENT_RAWDEBUG: |
118 | case USER_INTENT_RAWDEBUG: |
103 | if (act_debug_name<32) |
119 | if (act_debug_name<32) |
104 | { |
120 | { |
105 | 121 | ||
106 | if (resend_timeout==0) { |
122 | if (resend_timeout==0) { |
107 | mk.get_debug_name(act_debug_name); |
123 | mk.get_debug_name(act_debug_name); |
108 | resend_timeout=50; |
124 | resend_timeout=50; |
109 | } |
125 | } |
110 | 126 | ||
111 | 127 | ||
112 | //sleeper+=100; |
128 | //sleeper+=100; |
113 | if (mk.debug_data.got_name[act_debug_name]) |
129 | if (mk.debug_data.got_name[act_debug_name]) |
114 | { |
130 | { |
115 | mk.get_debug_name(++act_debug_name); |
131 | mk.get_debug_name(++act_debug_name); |
116 | resend_timeout=50; |
132 | resend_timeout=50; |
117 | } |
133 | } |
118 | else |
134 | else |
119 | resend_timeout--; |
135 | resend_timeout--; |
120 | 136 | ||
121 | } |
137 | } |
122 | else |
138 | else |
123 | if (!(mk.debug_data.got_name[0])) |
139 | if (!(mk.debug_data.got_name[0])) |
124 | act_debug_name=0; |
140 | act_debug_name=0; |
125 | 141 | ||
126 | break; |
142 | break; |
127 | 143 | ||
128 | case USER_INTENT_RCDATA: |
144 | case USER_INTENT_RCDATA: |
129 | mk.trigger_rcdata(); |
145 | if ( resend_check(mk.stats.stick_data_count) ) |
130 | sleeper+=250; |
146 | mk.trigger_rcdata(); |
131 | break; |
147 | break; |
- | 148 | ||
- | 149 | case USER_INTENT_EXTERNAL_CONTROL: |
|
- | 150 | if (resend_check(mk.stats.external_control_confirm_frame_count)) |
|
- | 151 | mk.send_extern_control(); |
|
- | 152 | ||
- | 153 | break; |
|
- | 154 | ||
132 | 155 | ||
133 | case USER_INTENT_LCD: |
156 | case USER_INTENT_LCD: |
134 | if (resend_timeout==0) |
- | |
135 | { |
157 | if (resend_check(mk.stats.lcd_data_count)) |
136 | mk.LCD.trigger_LCD(); |
- | |
137 | resend_timeout=50; |
- | |
138 | } |
158 | mk.LCD.trigger_LCD(); |
139 | - | ||
140 | if ( last_count!=mk.stats.lcd_data_count) |
- | |
141 | { |
- | |
142 | mk.LCD.trigger_LCD(); |
- | |
143 | resend_timeout=50; |
- | |
144 | } |
- | |
145 | else |
- | |
146 | resend_timeout--; |
- | |
147 | - | ||
148 | //sleeper +=250; |
159 | |
149 | break; |
160 | break; |
150 | 161 | ||
151 | default: |
162 | default: |
152 | // mk.log("uncactched intent " +mk.root.canvas.user_intent ); |
163 | // mk.log("uncactched intent " +mk.root.canvas.user_intent ); |
153 | break; |
164 | break; |
154 | } |
165 | } |
155 | 166 | ||
156 | // if ((!mk.ufo_prober.is_incompatible())) |
167 | // if ((!mk.ufo_prober.is_incompatible())) |
157 | { |
168 | { |
158 | 169 | ||
159 | mk.log("watchdog after main loop"); |
170 | mk.log("watchdog after main loop"); |
160 | if (debug_data_count_buff==mk.stats.debug_data_count) |
171 | if (debug_data_count_buff==mk.stats.debug_data_count) |
161 | { |
172 | { |
162 | mk.log("timeout:" +conn_check_timeout ); |
173 | mk.log("timeout:" +conn_check_timeout ); |
163 | conn_check_timeout++; |
174 | conn_check_timeout++; |
164 | if (conn_check_timeout==100) |
175 | if (conn_check_timeout==100) |
165 | { |
176 | { |
166 | mk.log("disconnecting"); |
177 | mk.log("disconnecting"); |
167 | mk.close_connections(false); |
178 | mk.close_connections(false); |
168 | conn_check_timeout=0; |
179 | conn_check_timeout=0; |
169 | } |
180 | } |
170 | debug_data_count_buff=mk.stats.debug_data_count; |
181 | debug_data_count_buff=mk.stats.debug_data_count; |
171 | } |
182 | } |
172 | else |
183 | else |
173 | conn_check_timeout=0; |
184 | conn_check_timeout=0; |
174 | 185 | ||
175 | 186 | ||
176 | 187 | ||
177 | /*else if ((mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG) || (mk.root.canvas.user_intent==USER_INTENT_GRAPH) ) |
188 | /*else if ((mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG) || (mk.root.canvas.user_intent==USER_INTENT_GRAPH) ) |
178 | { |
189 | { |
179 | mk.trigger_debug(); |
190 | mk.trigger_debug(); |
180 | try { Thread.sleep(100); } |
191 | try { Thread.sleep(100); } |
181 | catch (Exception e) { } |
192 | catch (Exception e) { } |
182 | } |
193 | } |
183 | */ |
194 | */ |
184 | 195 | ||
185 | 196 | ||
186 | 197 | ||
187 | 198 | ||
188 | 199 | ||
189 | 200 | ||
190 | /* |
201 | /* |
191 | 202 | ||
192 | 203 | ||
193 | if (debug_data_count_buff==mk.debug_data_count) |
204 | if (debug_data_count_buff==mk.debug_data_count) |
194 | { |
205 | { |
195 | // mk.close_connections(false); |
206 | // mk.close_connections(false); |
196 | } |
207 | } |
197 | 208 | ||
198 | */ |
209 | */ |
199 | 210 | ||
200 | /*if (mk.version.major==-1) |
211 | /*if (mk.version.major==-1) |
201 | mk.get_version(); |
212 | mk.get_version(); |
202 | else |
213 | else |
203 | */ |
214 | */ |
204 | /*for ( int cnt=0;cnt<5;cnt++) |
215 | /*for ( int cnt=0;cnt<5;cnt++) |
205 | if (mk.params.field[cnt]==null) |
216 | if (mk.params.field[cnt]==null) |
206 | { |
217 | { |
207 | mk.get_params(cnt+1); |
218 | mk.get_params(cnt+1); |
208 | break; |
219 | break; |
209 | }*/ |
220 | }*/ |
210 | /* |
221 | /* |
211 | for (int c=0;c<32;c++) |
222 | for (int c=0;c<32;c++) |
212 | if (!mk.debug_data.got_name[c]) |
223 | if (!mk.debug_data.got_name[c]) |
213 | { |
224 | { |
214 | mk.get_debug_name(c); |
225 | mk.get_debug_name(c); |
215 | break; |
226 | break; |
216 | } |
227 | } |
217 | */ |
228 | */ |
218 | 229 | ||
219 | 230 | ||
220 | } |
231 | } |
221 | 232 | ||
222 | } |
233 | } |
223 | 234 | ||
224 | 235 | ||
225 | } // 3000 |
236 | } // 3000 |
226 | catch (Exception e) { |
237 | catch (Exception e) { |
227 | mk.log("err in watchdog:"); |
238 | mk.log("err in watchdog:"); |
228 | mk.log(e.toString()); |
239 | mk.log(e.toString()); |
229 | 240 | ||
230 | } |
241 | } |
231 | } |
242 | } |
232 | 243 | ||
233 | 244 | ||
234 | // mk.log("watchdog quit"); |
245 | // mk.log("watchdog quit"); |
235 | } |
246 | } |
236 | 247 | ||
237 | 248 | ||
238 | } |
249 | } |
239 | 250 |