Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
403 | ligi | 1 | /******************************************************************************** |
2 | * Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) |
||
3 | * |
||
4 | * Author: Marcus -LiGi- Bueschleb |
||
5 | * |
||
6 | * see README for further Infos |
||
7 | * |
||
8 | ********************************************************************************/ |
||
181 | ligi | 9 | |
10 | public class MKStatistics |
||
11 | implements Runnable |
||
12 | { |
||
208 | ligi | 13 | public long motor_on_time=-1; |
14 | public long motor_stand_time=-1; |
||
15 | public long motor_sum=-1; |
||
16 | |||
181 | ligi | 17 | MKCommunicator mk=null; |
18 | |||
19 | public MKStatistics(MKCommunicator _mk) |
||
20 | { |
||
21 | mk=_mk; |
||
22 | new Thread( this ).start(); // fire up main Thread |
||
23 | } |
||
24 | |||
25 | |||
26 | |||
27 | |||
221 | ligi | 28 | private long last_run_ms=0; |
208 | ligi | 29 | private long last_step=-1; |
30 | |||
181 | ligi | 31 | public void run() |
32 | { |
||
33 | while(true) |
||
34 | { |
||
35 | |||
36 | if (mk.connected) |
||
37 | { |
||
221 | ligi | 38 | |
208 | ligi | 39 | |
221 | ligi | 40 | if (last_run_ms!=0) |
181 | ligi | 41 | { |
221 | ligi | 42 | last_step=System.currentTimeMillis()-last_run_ms; |
208 | ligi | 43 | |
44 | if (mk.debug_data.motor_complete>0) |
||
45 | motor_sum+=mk.debug_data.motor_complete; |
||
46 | if (mk.debug_data.motor_complete>60) |
||
47 | motor_on_time+=last_step; |
||
48 | if (mk.debug_data.motor_complete==60) |
||
49 | motor_stand_time+=last_step; |
||
181 | ligi | 50 | } |
221 | ligi | 51 | last_run_ms=System.currentTimeMillis(); |
208 | ligi | 52 | |
181 | ligi | 53 | |
54 | } |
||
55 | else |
||
56 | { |
||
57 | last_run_ms=-1; |
||
58 | motor_on_time=-1; |
||
208 | ligi | 59 | motor_stand_time=-1; |
181 | ligi | 60 | } |
61 | try { Thread.sleep(500); } |
||
62 | catch (Exception e) { } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | |||
67 | } |