Methods Summary |
---|
private static java.lang.String | getDate(java.lang.String ddmmyy)
String year = "20" + ddmmyy.substring(4);
String month = ddmmyy.substring(2, 4);
String day = ddmmyy.substring(0, 2);
return month + "-" + day + "-" + year;
|
private static java.lang.String | getPosition(java.lang.String number, java.lang.String direction)
// need to handle two digit and three digit longitude
int point = number.indexOf('.");
String degrees = number.substring(0, point-2);
String minutes = number.substring(degrees.length(), point);
String seconds = String.valueOf(
Double.parseDouble(number.substring(point)) * 60);
return degrees + "°" + minutes + "'" + seconds + "\"" + direction;
|
private static java.lang.String | getTime(java.lang.String in)
String hours = in.substring(0, 2);
String minutes = in.substring(2, 4);
String seconds = in.substring(4, 6);
return hours + ":" + minutes + ":" + seconds;
|
public static void | main(java.lang.String[] args)
RemoteDevice logger = BlueLoggerFinder.findBlueLogger();
String address = logger.getBluetoothAddress();
String url = "btspp://" + address
+ ":1;authenticate=false;encrypt=false;master=false";
StreamConnection conn = (StreamConnection) Connector.open(url);
InputStream in = conn.openInputStream();
BufferedReader reader = new BufferedReader(
new InputStreamReader(in, "US-ASCII"));
try {
while (true) {
String s = reader.readLine();
if (s == null) break;
if (s.startsWith("$GPRMC,")) {
String[] fields = s.split(",");
String time = getTime(fields[1]);
String latitude = getPosition(fields[3], fields[4]);
String longitude = getPosition(fields[5], fields[6]);
String date = getDate(fields[9]);
System.out.println(time + "\t" + date + "\t"
+ latitude + "\t" + longitude);
}
}
}
catch (IOException ex) {
// device turned off or out of range
}
reader.close();
|