Rev 206 | Rev 216 | 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 | } |
||
122 | |||
123 | break; |
||
124 | |||
125 | case USER_INTENT_RCDATA: |
||
126 | mk.trigger_rcdata(); |
||
127 | sleeper+=250; |
||
128 | break; |
||
129 | |||
130 | case USER_INTENT_LCD: |
||
131 | if (resend_timeout==0) |
||
132 | { |
||
133 | mk.LCD.trigger_LCD(); |
||
134 | resend_timeout=50; |
||
135 | } |
||
136 | |||
137 | if ( last_count!=mk.stats.lcd_data_count) |
||
138 | { |
||
139 | mk.LCD.trigger_LCD(); |
||
140 | resend_timeout=50; |
||
141 | } |
||
142 | else |
||
143 | resend_timeout--; |
||
144 | |||
145 | //sleeper +=250; |
||
146 | break; |
||
147 | |||
148 | default: |
||
149 | // mk.log("uncactched intent " +mk.root.canvas.user_intent ); |
||
150 | break; |
||
151 | } |
||
152 | |||
153 | // if ((!mk.ufo_prober.is_incompatible())) |
||
154 | { |
||
155 | |||
156 | mk.log("watchdog after main loop"); |
||
157 | if (debug_data_count_buff==mk.stats.debug_data_count) |
||
158 | { |
||
159 | mk.log("timeout:" +conn_check_timeout ); |
||
160 | conn_check_timeout++; |
||
161 | if (conn_check_timeout==100) |
||
162 | { |
||
163 | mk.log("disconnecting"); |
||
164 | mk.close_connections(false); |
||
165 | conn_check_timeout=0; |
||
166 | } |
||
167 | debug_data_count_buff=mk.stats.debug_data_count; |
||
168 | } |
||
169 | else |
||
170 | conn_check_timeout=0; |
||
171 | |||
172 | |||
173 | |||
174 | /*else if ((mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG) || (mk.root.canvas.user_intent==USER_INTENT_GRAPH) ) |
||
175 | { |
||
176 | mk.trigger_debug(); |
||
177 | try { Thread.sleep(100); } |
||
178 | catch (Exception e) { } |
||
179 | } |
||
180 | */ |
||
181 | |||
182 | |||
183 | |||
184 | |||
185 | |||
186 | |||
187 | /* |
||
188 | |||
189 | |||
190 | if (debug_data_count_buff==mk.debug_data_count) |
||
191 | { |
||
192 | // mk.close_connections(false); |
||
193 | } |
||
194 | |||
195 | */ |
||
196 | |||
197 | /*if (mk.version.major==-1) |
||
198 | mk.get_version(); |
||
199 | else |
||
200 | */ |
||
201 | /*for ( int cnt=0;cnt<5;cnt++) |
||
202 | if (mk.params.field[cnt]==null) |
||
203 | { |
||
204 | mk.get_params(cnt+1); |
||
205 | break; |
||
206 | }*/ |
||
207 | /* |
||
208 | for (int c=0;c<32;c++) |
||
209 | if (!mk.debug_data.got_name[c]) |
||
210 | { |
||
211 | mk.get_debug_name(c); |
||
212 | break; |
||
213 | } |
||
214 | */ |
||
215 | |||
216 | |||
217 | } |
||
218 | |||
219 | } |
||
220 | |||
221 | |||
222 | } // 3000 |
||
223 | catch (Exception e) { |
||
224 | mk.log("err in watchdog:"); |
||
225 | mk.log(e.toString()); |
||
226 | |||
227 | } |
||
228 | } |
||
229 | |||
230 | |||
231 | // mk.log("watchdog quit"); |
||
232 | } |
||
233 | |||
234 | |||
235 | } |