Subversion Repositories Projects

Rev

Rev 135 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 ligi 1
/**************************************
2
 *
3
 * WatchDog for MK-Connection
4
 *                      
5
 * Author:        Marcus -LiGi- Bueschleb
6
 *
7
 * see README for further Infos
8
 *
9
 *
10
 **************************************/
11
 
12
public class MKWatchDog
135 ligi 13
    implements Runnable,DUBwiseDefinitions
4 ligi 14
{
15
 
16
    MKCommunicator mk=null;
17
 
18
    int debug_data_count_buff=-123;
19
    int lcd_data_count_buff=-123;
20
 
21
 
22
    public MKWatchDog(MKCommunicator _mk)
23
    {
24
 
25
        mk=_mk;
26
        new Thread( this ).start(); // fire up main Thread 
27
    }
28
 
135 ligi 29
    int lcd_timeout=0; // detect if we lost packets
30
 
31
    public int act_paramset=0;
149 ligi 32
    int conn_check_timeout=0;
135 ligi 33
 
4 ligi 34
    public void run()
35
    {
135 ligi 36
        // get all params
37
        int act_debug_name=0;
38
 
4 ligi 39
        while(true)
40
            {
135 ligi 41
 
149 ligi 42
                try { Thread.sleep(100); } // 3000
4 ligi 43
                catch (Exception e)  {   }
44
 
45
                if (mk.connected&&(!mk.force_disconnect))
46
                    {
135 ligi 47
 
149 ligi 48
                        if (debug_data_count_buff==mk.debug_data_count)
49
                            {
50
                                mk.debug.log("timeout:" +conn_check_timeout );         
51
                                conn_check_timeout++;
52
                                if  (conn_check_timeout==100)
53
                                    {
54
                                        mk.debug.log("disconnecting");         
55
                                        mk.close_connections(false);
56
                                        conn_check_timeout=0;
57
                                    }
58
                                debug_data_count_buff=mk.debug_data_count;
59
 
60
                            }
61
                        else
62
                            conn_check_timeout=0;
63
 
64
 
135 ligi 65
                        if ( mk.version.major==-1 )
66
                            {
67
                                try { Thread.sleep(150); }
68
                                catch (Exception e)  {   }
69
                                mk.get_version();
70
                            }
71
                        else  if ((act_paramset<5)&&(mk.root.canvas.user_intent==USER_INTENT_PARAMS) &&(! mk.root.canvas.ufo_prober.is_navi()))
72
                            {
73
                                mk.get_params(act_paramset+1);
74
 
149 ligi 75
                                try { Thread.sleep(350); }
135 ligi 76
                                catch (Exception e)  {   }
77
 
78
                                if(mk.params.field[act_paramset]!=null)
79
                                    act_paramset++;
80
                            }
81
                        else if (( act_debug_name<32)&&(mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG))
82
                            {
83
                                mk.get_debug_name(act_debug_name);
84
 
149 ligi 85
                                try { Thread.sleep(150); }
135 ligi 86
                                catch (Exception e)  {   }
87
 
88
 
89
                                if (mk.debug_data.got_name[act_debug_name]) act_debug_name++;
90
                            }
149 ligi 91
                        /*else  if ((mk.root.canvas.user_intent==USER_INTENT_RAWDEBUG) || (mk.root.canvas.user_intent==USER_INTENT_GRAPH) )
92
                                    {
93
                                        mk.trigger_debug();
94
                                        try { Thread.sleep(100); }
95
                                        catch (Exception e)  {   }
96
                                    }
97
                        */  
135 ligi 98
 
99
 
100
 
101
 
102
 
103
 
104
                        /*
105
 
106
 
4 ligi 107
                        if (debug_data_count_buff==mk.debug_data_count)
108
                            {
81 ligi 109
                                //                              mk.close_connections(false);
4 ligi 110
                            }
62 ligi 111
 
135 ligi 112
                        */
62 ligi 113
 
135 ligi 114
                        /*if (mk.version.major==-1)
4 ligi 115
                            mk.get_version();
135 ligi 116
                        else
117
                        */  
118
                        /*for ( int cnt=0;cnt<5;cnt++)
62 ligi 119
                            if (mk.params.field[cnt]==null)
120
                                {
121
                                    mk.get_params(cnt+1);
122
                                    break;
135 ligi 123
                                    }*/
124
                        /*
4 ligi 125
                        for (int c=0;c<32;c++)
126
                            if (!mk.debug_data.got_name[c])
127
                                {
128
                                    mk.get_debug_name(c);
129
                                    break;
130
                                }
135 ligi 131
                        */
132
 
149 ligi 133
                        else
135 ligi 134
                            {
149 ligi 135
                                if ((lcd_data_count_buff!=mk.lcd_data_count)||(mk.lcd_data_count==0)||(lcd_timeout==23))
136
                                    {
137
                                        lcd_timeout=0;
138
                                        lcd_data_count_buff=mk.lcd_data_count;
139
                                        mk.LCD.trigger_LCD();
140
                                        try { Thread.sleep(50); }
141
                                        catch (Exception e)  {   }
142
                                        //debug_data_count_buff=mk.debug_data_count;
135 ligi 143
 
149 ligi 144
                                    }
145
                                else
146
                                    {
147
                                        lcd_timeout++;
148
                                    }
135 ligi 149
                            }
4 ligi 150
 
135 ligi 151
 
4 ligi 152
 
153
                    }
154
 
155
 
156
            }
157
    }
158
 
159
 
160
}