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