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

📄 parser.java

📁 read GPS information from the commport installed in PDA
💻 JAVA
字号:
package Reader;


import java.util.NoSuchElementException;


public class Parser {

	public static final int TYPE_NA = -1;


	public static final int TYPE_START = -2;


	public static final int TYPE_GPRMC = 0;


	public static final int TYPE_GPGGA = 1;

	public static int parse(String s, Record record)
			throws UnsupportedTypeException, ParseException {

		// Tokenizer to separate tokens
		Tokenizer tokenizer = new Tokenizer(s);
		// Type of record
		int type;

		try {
			String token = tokenizer.next();
			System.out.print("++++++++++++");
			if (token.equals("$GPRMC")) {
				type = TYPE_GPRMC;

				token = tokenizer.next();
				record.dateTimeOfFix = token.substring(0, 2) + ":"
						+ token.substring(2, 4) + ":" + token.substring(4, 6);

				record.warning = tokenizer.next().equals(Record.WARNING);

				record.lattitude = tokenizer.next();

				record.lattitudeDirection = tokenizer.next();

				record.longitude = tokenizer.next();

				record.longitudeDirection = tokenizer.next();

				record.groundSpeed = tokenizer.next();

				record.courseMadeGood = tokenizer.next();

				token = tokenizer.next();
				record.dateTimeOfFix += "/" + token.substring(0, 2) + "."
						+ token.substring(2, 4) + "." + token.substring(4, 6);

				record.magneticVariation = tokenizer.next();
			} else if (token.equals("$GPGGA")) {
				type = TYPE_GPGGA;

				// Time of fix
				tokenizer.next();

				// Lattitude
				tokenizer.next();

				// Lattitude direction
				tokenizer.next();

				// Longitude
				tokenizer.next();

				// Longitude direction
				tokenizer.next();

				record.quality = tokenizer.next();

				record.satelliteCount = tokenizer.next();

				// Ignore rest
			}
			// Type is not supported.
			else {
				throw new UnsupportedTypeException("Type " + token
						+ " is not supported.");
			}
		}
		// Parsing exception.
		catch (NoSuchElementException e) {
			throw new ParseException("Unexpected end of input.");
		}
		return type;
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -