0,0 → 1,161 |
/********************************************************************************** |
* |
* Probe which type of UFO we talk to |
* |
* Author: Marcus -LiGi- Bueschleb |
* |
* see README for further Infos |
* |
* |
**********************************************************************************/ |
|
package org.ligi.ufo; |
|
//#ifdef j2me |
//# import javax.microedition.io.*; |
//#endif |
|
|
import java.io.*; |
|
public class UFOProber |
|
{ |
public final static int PROBE_RESULT_NONE =0; |
public final static int PROBE_RESULT_INCOMPATIBLE =1; |
public final static int PROBE_RESULT_MK =2; |
public final static int PROBE_RESULT_NG =3; |
public final static int PROBE_RESULT_NAVCTRL =4; |
public final static int PROBE_RESULT_MK3MAG =5; |
|
|
|
|
public boolean change_notify=false; |
|
public String[] extended_names= { "No Device" , "Inkompatible Device","MK-Connection" , "NG-Connection" , "NavCtrl-Connection","MK3Mag Connection" }; |
|
public int probe_result=PROBE_RESULT_NONE; |
|
|
public void set_to(int _probe_result) |
{ |
if (_probe_result!=probe_result) |
{ |
probe_result=_probe_result; |
change_notify=true; |
} |
} |
public void set_to_navi() |
{ |
set_to(PROBE_RESULT_NAVCTRL); |
} |
|
public void set_to_mk3mag() |
{ |
set_to(PROBE_RESULT_MK3MAG); |
} |
|
public void set_to_mk() |
{ |
set_to(PROBE_RESULT_MK); |
} |
|
|
public void set_to_none() |
{ |
set_to(PROBE_RESULT_NONE); |
} |
|
public void set_to_incompatible() |
{ |
set_to(PROBE_RESULT_INCOMPATIBLE); |
} |
|
public boolean is_navi() |
{ |
return (probe_result==PROBE_RESULT_NAVCTRL); |
} |
|
public boolean is_mk() |
{ |
return (probe_result==PROBE_RESULT_MK); |
} |
|
public boolean is_mk3mag() |
{ |
return (probe_result==PROBE_RESULT_MK3MAG); |
} |
|
public boolean is_incompatible() |
{ |
return (probe_result==PROBE_RESULT_INCOMPATIBLE); |
} |
|
|
public String extended_name() |
{ |
return extended_names[probe_result]; |
} |
|
String reply=""; |
public boolean probe_error=false; |
|
// j2me |
// private javax.microedition.io.StreamConnection connection; |
// ej2me |
|
|
// private java.io.InputStream reader; |
//private java.io.OutputStream writer; |
|
public void bluetooth_probe(String url) |
{ |
try{ |
/* |
connection = (StreamConnection) Connector.open(url); |
reader=connection.openInputStream(); |
writer=connection.openOutputStream(); |
String magic="\rmk-mode\r"; |
writer.write(magic.getBytes()); |
writer.flush(); |
*/ |
|
/* |
int input=0; |
// recieve data-set |
|
// the 1st line is the echo of the command when ng |
while ((input != 13) &&(input!=-1)) |
{ |
input = reader.read() ; |
reply+=(char)input; |
} |
reply=""; |
input=0; |
while ((input != 13) &&(input!=-1)) |
if (input!=10){ |
input = reader.read() ; |
reply+=(char)input; |
} |
|
if (reply=="NG here\r") |
probe_result=PROBE_RESULT_NG; |
|
probe_result=PROBE_RESULT_MK; |
|
*/ |
// writer.close(); |
// reader.close(); |
// connection.close(); |
|
} |
catch (Exception ex) |
{ |
probe_error=true; |
} |
|
|
} |
|
} |