Rev 264 | 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 | |||
266 | ligi | 19 | int bytes_in_count_buff=-123; |
206 | ligi | 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 | |||
219 | ligi | 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 | } |
||
51 | |||
206 | ligi | 52 | //#ifdef android |
53 | // public final static int BASE_SLEEP=50; |
||
54 | //#else |
||
219 | ligi | 55 | public final static int BASE_SLEEP=10; |
206 | ligi | 56 | //#endif |
57 | |||
58 | public void run() |
||
59 | { |
||
60 | mk.log("starting Watchdog"); |
||
61 | // get all params |
||
62 | int act_debug_name=0; |
||
219 | ligi | 63 | // int sleeper=BASE_SLEEP; |
206 | ligi | 64 | while(true) |
65 | { |
||
66 | try { |
||
219 | ligi | 67 | Thread.sleep(BASE_SLEEP); |
68 | // sleeper=BASE_SLEEP; |
||
206 | ligi | 69 | if (mk.connected&&(!mk.force_disconnect)) |
70 | { |
||
71 | |||
262 | ligi | 72 | // mk.log("watchdog pre main loop"); |
219 | ligi | 73 | if (mk.init_bootloader) |
206 | ligi | 74 | { |
75 | mk.jump_bootloader(); |
||
219 | ligi | 76 | mk.init_bootloader=false; |
206 | ligi | 77 | } |
219 | ligi | 78 | else if ( mk.version.major==-1 ) |
206 | ligi | 79 | mk.get_version(); |
80 | else if (mk.ufo_prober.is_navi()&&(mk.error_str==null)) |
||
81 | mk.get_error_str(); |
||
82 | |||
83 | else if (mk.ufo_prober.is_mk()&&(mk.params.last_parsed_paramset==-1)) |
||
84 | { |
||
85 | mk.get_params(0xFF-1); |
||
219 | ligi | 86 | Thread.sleep(150); |
87 | |||
206 | ligi | 88 | act_paramset=0; // warning - if dropped problem |
89 | } |
||
90 | else switch (mk.user_intent) |
||
91 | { |
||
92 | case USER_INTENT_PARAMS: |
||
93 | |||
94 | if ((act_paramset<5)) |
||
95 | { |
||
96 | |||
97 | if (resend_timeout==0) { |
||
98 | mk.get_params(act_paramset); |
||
213 | ligi | 99 | resend_timeout=120; |
206 | ligi | 100 | } |
101 | |||
102 | if(mk.params.field[act_paramset]!=null) |
||
103 | { |
||
104 | mk.get_params(++act_paramset); |
||
213 | ligi | 105 | resend_timeout=120; |
206 | ligi | 106 | } |
107 | else |
||
108 | resend_timeout--; |
||
109 | /* |
||
110 | // act_paramset++; |
||
111 | else |
||
112 | mk.get_params(act_paramset); |
||
113 | |||
114 | sleeper+=1200; |
||
115 | */ |
||
116 | } |
||
117 | break; |
||
118 | case USER_INTENT_RAWDEBUG: |
||
119 | if (act_debug_name<32) |
||
120 | { |
||
121 | |||
122 | if (resend_timeout==0) { |
||
123 | mk.get_debug_name(act_debug_name); |
||
124 | resend_timeout=50; |
||
125 | } |
||
126 | |||
127 | |||
128 | //sleeper+=100; |
||
129 | if (mk.debug_data.got_name[act_debug_name]) |
||
130 | { |
||
131 | mk.get_debug_name(++act_debug_name); |
||
132 | resend_timeout=50; |
||
133 | } |
||
134 | else |
||
135 | resend_timeout--; |
||
136 | |||
137 | } |
||
216 | ligi | 138 | else |
139 | if (!(mk.debug_data.got_name[0])) |
||
140 | act_debug_name=0; |
||
206 | ligi | 141 | |
142 | break; |
||
143 | |||
144 | case USER_INTENT_RCDATA: |
||
219 | ligi | 145 | if ( resend_check(mk.stats.stick_data_count) ) |
146 | mk.trigger_rcdata(); |
||
206 | ligi | 147 | break; |
219 | ligi | 148 | |
149 | case USER_INTENT_EXTERNAL_CONTROL: |
||
150 | if (resend_check(mk.stats.external_control_confirm_frame_count)) |
||
222 | ligi | 151 | { |
219 | ligi | 152 | mk.send_extern_control(); |
222 | ligi | 153 | mk.send_extern_control(); |
154 | mk.send_extern_control(); |
||
155 | mk.send_extern_control(); |
||
156 | } |
||
219 | ligi | 157 | |
158 | break; |
||
159 | |||
206 | ligi | 160 | |
161 | case USER_INTENT_LCD: |
||
219 | ligi | 162 | if (resend_check(mk.stats.lcd_data_count)) |
206 | ligi | 163 | mk.LCD.trigger_LCD(); |
219 | ligi | 164 | |
206 | ligi | 165 | break; |
166 | |||
264 | ligi | 167 | case USER_INTENT_GPSOSD: |
168 | mk.set_gpsosd_interval(1); |
||
169 | break; |
||
262 | ligi | 170 | case USER_INTENT_GRAPH: |
264 | ligi | 171 | mk.set_debug_interval(1); |
262 | ligi | 172 | break; |
264 | ligi | 173 | |
206 | ligi | 174 | default: |
175 | // mk.log("uncactched intent " +mk.root.canvas.user_intent ); |
||
176 | break; |
||
177 | } |
||
178 | |||
179 | |||
180 | |||
266 | ligi | 181 | if (bytes_in_count_buff==mk.stats.bytes_in) |
182 | if ((conn_check_timeout++)*BASE_SLEEP>3000) |
||
183 | { |
||
184 | conn_check_timeout=0; |
||
185 | mk.close_connections(false); |
||
206 | ligi | 186 | |
266 | ligi | 187 | } |
188 | else |
||
189 | conn_check_timeout=0; |
||
190 | bytes_in_count_buff=mk.stats.debug_data_count; |
||
206 | ligi | 191 | |
192 | |||
193 | } |
||
194 | |||
195 | |||
196 | } // 3000 |
||
197 | catch (Exception e) { |
||
198 | mk.log("err in watchdog:"); |
||
199 | mk.log(e.toString()); |
||
200 | |||
201 | } |
||
202 | } |
||
203 | |||
204 | |||
205 | // mk.log("watchdog quit"); |
||
206 | } |
||
207 | |||
208 | |||
209 | } |