Rev 221 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 221 | Rev 403 | ||
---|---|---|---|
1 | /********************************************************************************************************************************** |
1 | /******************************************************************************** |
2 | * Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) * |
2 | * Statistics from MK-Connection ( needed for 2. Thread and Readability of Code ) |
3 | * * |
- | |
- | 3 | * |
|
4 | * Author: Marcus -LiGi- Bueschleb * |
4 | * Author: Marcus -LiGi- Bueschleb |
5 | * Project-Start: 9/2007 * |
- | |
6 | * Version: 0.07 * |
- | |
7 | * Mailto: ligi@smart4mobile.de * |
- | |
- | 5 | * |
|
8 | * Licence: Creative Commons / Non Commercial * |
6 | * see README for further Infos |
9 | * Big Up: Holger&Ingo * |
- | |
- | 7 | * |
|
10 | *********************************************************************************************************************************/ |
8 | ********************************************************************************/ |
11 | 9 | ||
12 | public class MKStatistics |
10 | public class MKStatistics |
13 | implements Runnable |
11 | implements Runnable |
14 | { |
12 | { |
15 | public long motor_on_time=-1; |
13 | public long motor_on_time=-1; |
16 | public long motor_stand_time=-1; |
14 | public long motor_stand_time=-1; |
17 | public long motor_sum=-1; |
15 | public long motor_sum=-1; |
18 | 16 | ||
19 | MKCommunicator mk=null; |
17 | MKCommunicator mk=null; |
20 | 18 | ||
21 | public MKStatistics(MKCommunicator _mk) |
19 | public MKStatistics(MKCommunicator _mk) |
22 | { |
20 | { |
23 | mk=_mk; |
21 | mk=_mk; |
24 | new Thread( this ).start(); // fire up main Thread |
22 | new Thread( this ).start(); // fire up main Thread |
25 | } |
23 | } |
26 | 24 | ||
27 | 25 | ||
28 | 26 | ||
29 | 27 | ||
30 | private long last_run_ms=0; |
28 | private long last_run_ms=0; |
31 | private long last_step=-1; |
29 | private long last_step=-1; |
32 | 30 | ||
33 | public void run() |
31 | public void run() |
34 | { |
32 | { |
35 | while(true) |
33 | while(true) |
36 | { |
34 | { |
37 | 35 | ||
38 | if (mk.connected) |
36 | if (mk.connected) |
39 | { |
37 | { |
40 | 38 | ||
41 | 39 | ||
42 | if (last_run_ms!=0) |
40 | if (last_run_ms!=0) |
43 | { |
41 | { |
44 | last_step=System.currentTimeMillis()-last_run_ms; |
42 | last_step=System.currentTimeMillis()-last_run_ms; |
45 | 43 | ||
46 | if (mk.debug_data.motor_complete>0) |
44 | if (mk.debug_data.motor_complete>0) |
47 | motor_sum+=mk.debug_data.motor_complete; |
45 | motor_sum+=mk.debug_data.motor_complete; |
48 | if (mk.debug_data.motor_complete>60) |
46 | if (mk.debug_data.motor_complete>60) |
49 | motor_on_time+=last_step; |
47 | motor_on_time+=last_step; |
50 | if (mk.debug_data.motor_complete==60) |
48 | if (mk.debug_data.motor_complete==60) |
51 | motor_stand_time+=last_step; |
49 | motor_stand_time+=last_step; |
52 | } |
50 | } |
53 | last_run_ms=System.currentTimeMillis(); |
51 | last_run_ms=System.currentTimeMillis(); |
54 | 52 | ||
55 | 53 | ||
56 | } |
54 | } |
57 | else |
55 | else |
58 | { |
56 | { |
59 | last_run_ms=-1; |
57 | last_run_ms=-1; |
60 | motor_on_time=-1; |
58 | motor_on_time=-1; |
61 | motor_stand_time=-1; |
59 | motor_stand_time=-1; |
62 | } |
60 | } |
63 | try { Thread.sleep(500); } |
61 | try { Thread.sleep(500); } |
64 | catch (Exception e) { } |
62 | catch (Exception e) { } |
65 | } |
63 | } |
66 | } |
64 | } |
67 | 65 | ||
68 | 66 | ||
69 | } |
67 | } |
70 | 68 |