Subversion Repositories FlightCtrl

Rev

Rev 164 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 164 Rev 181
Line 30... Line 30...
30
    public boolean fatal=false; // flag which is set when an error is so fatal that reconnecting won't be tried - e.g. unknown version number.
30
    public boolean fatal=false; // flag which is set when an error is so fatal that reconnecting won't be tried - e.g. unknown version number.
Line 31... Line 31...
31
 
31
 
Line 32... Line -...
32
 
-
 
33
    public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes
32
 
34
   
33
    public String mk_url=""; // buffer the url which is given in the constuctor for reconnectin purposes
35
 
34
   
36
   
35
   
37
    // version Info from Flight Control
36
    // version Info from Flight Control
Line -... Line 37...
-
 
37
    public int version_major=-1;
Line 38... Line 38...
38
    public int version_major=-1;
38
    public int version_minor=-1;
39
    public int version_minor=-1;
39
    public int version_compatible=-1;
40
    public int version_compatible=-1;
40
   
Line 50... Line 50...
50
   
50
   
51
    // temp - to be removed
51
    // temp - to be removed
52
    String p_msg="--";
52
    String p_msg="--";
Line 53... Line 53...
53
    public String msg="BT_INIT";
53
    public String msg="BT_INIT";
Line 54... Line 54...
54
 
54
 
55
    int data_count=0;
55
    public int data_count=0;
56
 
56
 
-
 
57
 
57
 
58
    /******************  Section: public Methods ************************************************/
-
 
59
    public MKCommunicator(String url)     // Constructor with URL string e.g. "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control
58
    /******************  Section: public Methods ************************************************/
60
    {
59
    public MKCommunicator(String url)     // Constructor with URL string e.g. "btspp://XXXXXXXXXXXX:1" - the X-Part is the MAC-Adress of the Bluetooth-Device connected to the Fligth-Control
61
        debug_data=new MKDebugData();
Line 60... Line 62...
60
    {
62
        mk_url=url; // remember URL for connecting / reconnecting later
Line 68... Line 70...
68
    {
70
    {
69
        try{
71
        try{
70
                connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE);
72
                connection = (StreamConnection) Connector.open(mk_url, Connector.READ_WRITE);
71
                reader=connection.openInputStream();
73
                reader=connection.openInputStream();
72
                writer=connection.openOutputStream();
74
                writer=connection.openOutputStream();
-
 
75
               
-
 
76
                connection_start_time=System.currentTimeMillis();
73
                connected=true; // if we get here everything seems to be OK
77
                connected=true; // if we get here everything seems to be OK
-
 
78
                get_version();
74
           }
79
           }
75
        catch (Exception ex)
80
        catch (Exception ex)
76
            {
81
            {
77
                // TODO difference fatal errors from those which will lead to reconnection
82
                // TODO difference fatal errors from those which will lead to reconnection
78
                msg="Problem connecting" + "\n" + ex;
83
                msg="Problem connecting" + "\n" + ex;
79
            }  
84
            }  
-
 
85
 
80
       
86
 
81
        get_version();
87
 
82
    }
88
    }
Line 83... Line 89...
83
 
89
 
Line 150... Line 156...
150
    MKDebugData debug_data;
156
    MKDebugData debug_data;
151
    public void process_data(int[] data,int len)
157
    public void process_data(int[] data,int len)
152
    {
158
    {
153
        int[] decoded_data;
159
        int[] decoded_data;
Line -... Line 160...
-
 
160
 
154
 
161
       
155
        switch((char)data[2])
162
        switch((char)data[2])
Line 156... Line 163...
156
            {
163
            {
157
           
164
           
Line 182... Line 189...
182
        msg+="OK";
189
        msg+="OK";
183
        data_count++;
190
        data_count++;
Line 184... Line 191...
184
       
191
       
Line -... Line 192...
-
 
192
    }
-
 
193
 
-
 
194
 
185
    }
195
 
186
 
196
 
187
    // Thread to recieve data from Connection
197
    // Thread to recieve data from Connection
188
    public void run()
198
    public void run()
189
    {
199
    {
190
        int[] data_set=new int[150];
200
        int[] data_set=new int[150];
191
        int input;
201
        int input;
192
        int pos=0;
202
        int pos=0;
193
        msg+="!!run started!!";
203
        msg+="!!run started!!";
194
        while(true)
204
        while(true)
-
 
205
            {
195
            {
206
            if (!connected)
-
 
207
                {
196
            if (!connected)
208
                    connect();
197
                connect();
209
                }
-
 
210
            else
198
            else
211
                try{
199
                try{
212
               
200
                    pos=0;
213
                    pos=0;
201
                    input=0;
214
                    input=0;
202
                    // recieve data-set
215
                    // recieve data-set