⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gpsstream.java

📁 一个可以连接gps的程序
💻 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 + -