Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4 | 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 | ********************************************************************************/ |
||
9 | |||
10 | public class MKStatistics |
||
11 | implements Runnable |
||
12 | { |
||
13 | public long motor_on_time=-1; |
||
14 | public long motor_stand_time=-1; |
||
15 | public long motor_sum=-1; |
||
16 | |||
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 | |||
28 | private long last_run_ms=0; |
||
29 | private long last_step=-1; |
||
30 | |||
31 | public void run() |
||
32 | { |
||
33 | while(true) |
||
34 | { |
||
35 | |||
36 | if (mk.connected) |
||
37 | { |
||
38 | |||
39 | |||
40 | if (last_run_ms!=0) |
||
41 | { |
||
42 | last_step=System.currentTimeMillis()-last_run_ms; |
||
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; |
||
50 | } |
||
51 | last_run_ms=System.currentTimeMillis(); |
||
52 | |||
53 | |||
54 | } |
||
55 | else |
||
56 | { |
||
57 | last_run_ms=-1; |
||
58 | motor_on_time=-1; |
||
59 | motor_stand_time=-1; |
||
60 | } |
||
61 | try { Thread.sleep(500); } |
||
62 | catch (Exception e) { } |
||
63 | } |
||
64 | } |
||
65 | |||
66 | |||
67 | } |