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