📄 gpsstream.java
字号:
package GPSreader;
import java.io.*;
import java.util.*;
import javax.microedition.io.*;
public class GpsStream
{
private btGPSreader host = null;
private Timer timer;
private StreamConnection conn;
private InputStream is;
private String url;
private ReadStream rs;
private NmeaParser np;
private boolean stop = false;
public GpsStream(btGPSreader host, String url)
{
this.host = host;
this.url = url;
timer = new Timer();
np = new NmeaParser();
}
public boolean isStop()
{
return this.stop;
}
public void stop()
{
if(timer != null)
{
timer.cancel();
rs.cancel();
}
try
{
is.close();
conn.close();
}
catch(IOException e){}
stop = true;
}
public void start()
{
try
{
np.nmea.removeAllElements();
conn = (StreamConnection)Connector.open(url);
is = conn.openInputStream();
rs = new ReadStream();
stop = false;
timer.schedule(rs, 500, 10);
}
catch(IOException e){}
}
private class ReadStream extends TimerTask
{
private String data;
private int buffer;
public void run()
{
try
{
data="";
while(((buffer=is.read()) != 13) && (buffer != 10))
{
data += (char)buffer;
}
if(data.startsWith("$GPRMC"))
{
np.splitString(data);
host.log(np.getParsedData());
}
}
catch(IOException e){}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -