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