Rev 82 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 82 | Rev 135 | ||
---|---|---|---|
1 | /********************************************************************************** |
1 | /********************************************************************************** |
2 | * |
2 | * |
3 | * Probe which type of UFO we talk to |
3 | * Probe which type of UFO we talk to |
4 | * |
4 | * |
5 | * Author: Marcus -LiGi- Bueschleb |
5 | * Author: Marcus -LiGi- Bueschleb |
6 | * |
6 | * |
7 | * see README for further Infos |
7 | * see README for further Infos |
8 | * |
8 | * |
9 | * |
9 | * |
10 | **********************************************************************************/ |
10 | **********************************************************************************/ |
11 | 11 | ||
12 | import javax.microedition.io.*; |
12 | import javax.microedition.io.*; |
13 | import java.io.*; |
13 | import java.io.*; |
14 | 14 | ||
15 | public class UFOProber |
15 | public class UFOProber |
16 | 16 | ||
17 | { |
17 | { |
18 | public final static int PROBE_RESULT_NONE=0; |
18 | public final static int PROBE_RESULT_NONE =0; |
19 | public final static int PROBE_RESULT_MK=1; |
19 | public final static int PROBE_RESULT_MK =1; |
20 | public final static int PROBE_RESULT_NG=2; |
20 | public final static int PROBE_RESULT_NG =2; |
- | 21 | public final static int PROBE_RESULT_NAVCTRL =3; |
|
- | 22 | ||
- | 23 | ||
- | 24 | public boolean change_notify=false; |
|
- | 25 | ||
- | 26 | public String[] extended_names= { "No Device" , "MK-Connection" , "NG-Connection" , "NavCtrl-Connection" }; |
|
21 | 27 | ||
- | 28 | public int probe_result=PROBE_RESULT_NONE; |
|
- | 29 | ||
- | 30 | ||
- | 31 | public void set_to_navi() |
|
- | 32 | { |
|
- | 33 | if (probe_result!=PROBE_RESULT_NAVCTRL); |
|
- | 34 | { |
|
- | 35 | probe_result=PROBE_RESULT_NAVCTRL; |
|
- | 36 | change_notify=true; |
|
- | 37 | } |
|
- | 38 | } |
|
- | 39 | ||
- | 40 | public void set_to_mk() |
|
- | 41 | { |
|
- | 42 | if (probe_result!=PROBE_RESULT_MK) |
|
- | 43 | { |
|
- | 44 | probe_result=PROBE_RESULT_MK; |
|
- | 45 | change_notify=true; |
|
- | 46 | } |
|
- | 47 | } |
|
- | 48 | ||
- | 49 | public boolean is_navi() |
|
- | 50 | { |
|
- | 51 | return (probe_result==PROBE_RESULT_NAVCTRL); |
|
- | 52 | } |
|
- | 53 | ||
- | 54 | public boolean is_mk() |
|
- | 55 | { |
|
- | 56 | return (probe_result==PROBE_RESULT_MK); |
|
- | 57 | } |
|
- | 58 | ||
- | 59 | ||
- | 60 | public String extended_name() |
|
- | 61 | { |
|
- | 62 | return extended_names[probe_result]; |
|
- | 63 | } |
|
22 | public int probe_result=PROBE_RESULT_NONE; |
64 | |
23 | String reply=""; |
65 | String reply=""; |
24 | public boolean probe_error=false; |
66 | public boolean probe_error=false; |
25 | 67 | ||
26 | private javax.microedition.io.StreamConnection connection; |
68 | private javax.microedition.io.StreamConnection connection; |
27 | private java.io.InputStream reader; |
69 | private java.io.InputStream reader; |
28 | private java.io.OutputStream writer; |
70 | private java.io.OutputStream writer; |
29 | 71 | ||
30 | public void bluetooth_probe(String url) |
72 | public void bluetooth_probe(String url) |
31 | { |
73 | { |
32 | try{ |
74 | try{ |
33 | connection = (StreamConnection) Connector.open(url); |
75 | connection = (StreamConnection) Connector.open(url); |
34 | reader=connection.openInputStream(); |
76 | reader=connection.openInputStream(); |
35 | writer=connection.openOutputStream(); |
77 | writer=connection.openOutputStream(); |
36 | String magic="\rmk-mode\r"; |
78 | String magic="\rmk-mode\r"; |
37 | writer.write(magic.getBytes()); |
79 | writer.write(magic.getBytes()); |
38 | writer.flush(); |
80 | writer.flush(); |
39 | /* |
81 | /* |
40 | int input=0; |
82 | int input=0; |
41 | // recieve data-set |
83 | // recieve data-set |
42 | 84 | ||
43 | // the 1st line is the echo of the command when ng |
85 | // the 1st line is the echo of the command when ng |
44 | while ((input != 13) &&(input!=-1)) |
86 | while ((input != 13) &&(input!=-1)) |
45 | { |
87 | { |
46 | input = reader.read() ; |
88 | input = reader.read() ; |
47 | reply+=(char)input; |
89 | reply+=(char)input; |
48 | } |
90 | } |
49 | reply=""; |
91 | reply=""; |
50 | input=0; |
92 | input=0; |
51 | while ((input != 13) &&(input!=-1)) |
93 | while ((input != 13) &&(input!=-1)) |
52 | if (input!=10){ |
94 | if (input!=10){ |
53 | input = reader.read() ; |
95 | input = reader.read() ; |
54 | reply+=(char)input; |
96 | reply+=(char)input; |
55 | } |
97 | } |
56 | 98 | ||
57 | if (reply=="NG here\r") |
99 | if (reply=="NG here\r") |
58 | probe_result=PROBE_RESULT_NG; |
100 | probe_result=PROBE_RESULT_NG; |
59 | 101 | ||
60 | probe_result=PROBE_RESULT_MK; |
102 | probe_result=PROBE_RESULT_MK; |
61 | |
103 | |
62 | */ |
104 | */ |
63 | writer.close(); |
105 | writer.close(); |
64 | reader.close(); |
106 | reader.close(); |
65 | connection.close(); |
107 | connection.close(); |
66 | 108 | ||
67 | } |
109 | } |
68 | catch (Exception ex) |
110 | catch (Exception ex) |
69 | { |
111 | { |
70 | probe_error=true; |
112 | probe_error=true; |
71 | } |
113 | } |
72 | 114 | ||
73 | 115 | ||
74 | } |
116 | } |
75 | 117 | ||
76 | } |
118 | } |
77 | 119 |