source: liacs/se/RouteGUI/src/routegui/GPRMC.java@ 52

Last change on this file since 52 was 2, checked in by Rick van der Zwet, 15 years ago

Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)

File size: 3.9 KB
RevLine 
[2]1/*
2 * To change this template, choose Tools | Templates
3 * and open the template in the editor.
4 */
5
6package routegui;
7
8import java.io.IOException;
9import java.util.Calendar;
10import org.jdesktop.swingx.mapviewer.GeoPosition;
11
12/**
13 *
14 * @author rick
15 * http://www.codepedia.com/1/The+GPRMC+Sentence
16 */
17public class GPRMC {
18 /* 0: The Command Word */
19 /**
20 * 1: Satellite-Derived Time in UTC, in a compressed form "HHMMSS.XXX,"
21 * 9: UTC Date, to be put into calendar format DDMMYY
22 */
23 public Calendar calendar;
24 /**
25 * 2: Satelite fix status
26 */
27 public Boolean sateliteFixStatus;
28 /**
29 * 3: latitudeDecimalDegrees HHMM.M
30 * 4: latitudeHemisphere [N|S]
31 * 5: DoubleitudeDecimalDegrees HHHMM.M
32 * 6: DoubleitudeHemisphere [E|W]
33 * converted to Geoposition
34 */
35 public GeoPosition position;
36 /**
37 * 7: speed in knobs
38 */
39 public Double speed;
40 /**
41 * 8: bearing, measured as an "azimuth.", where 0 represents north,
42 * 90 represents east, 180 represents south and 270 represents west.
43 */
44 public Double bearing;
45 /* 10: Empty */
46 /* 11: Empty */
47 /* 12: Empty */
48 /* 13: Checksum field */
49
50 private String getChecksum(String strLine) {
51 int checksum = strLine.charAt(1);
52 for (int i = 2; i < strLine.length() - 3; i++ ){
53 checksum = checksum ^ strLine.charAt(i);
54 }
55 return String.format("%1x", checksum);
56 }
57
58 GPRMC() {
59
60 }
61
62
63 GPRMC(String strLine) {
64 boolean result = process(strLine);
65 }
66
67 public boolean process(String strLine) {
68 String[] strSub = strLine.split("[,*]");
69
70 /* Checking sentence is valid using checksum */
71 if (! getChecksum(strLine).equals(strSub[13])) {
72 return false;
73 }
74
75
76 /* Set calendar */
77 calendar = Calendar.getInstance();
78 calendar.set(Calendar.DAY_OF_MONTH,
79 Integer.parseInt(strSub[9].substring(0,2)));
80 calendar.set(Calendar.MONTH,
81 Integer.parseInt(strSub[9].substring(2,4)));
82 calendar.set(Calendar.YEAR,
83 Integer.parseInt(strSub[9].substring(4,6)) + 2000);
84 calendar.set(Calendar.HOUR,
85 Integer.parseInt(strSub[1].substring(0,2)));
86 calendar.set(Calendar.MINUTE,
87 Integer.parseInt(strSub[1].substring(2,4)));
88 calendar.set(Calendar.SECOND,
89 Integer.parseInt(strSub[1].substring(4,6)));
90 calendar.set(Calendar.MILLISECOND,
91 Integer.parseInt(strSub[1].substring(7,9)));
92
93 /* Set fix status */
94 sateliteFixStatus = strSub[2].equalsIgnoreCase("A");
95
96 if (sateliteFixStatus) {
97 /**
98 * Set position,
99 * see: http://en.wikipedia.org/wiki/Geographic_coordinate_conversion
100 * @todo: Milliseconds are ignored in calculation
101 */
102
103 Double latitude = Double.parseDouble(strSub[3].substring(0, 2));
104 latitude += Double.parseDouble(strSub[3].substring(2)) / 60;
105 if (strSub[4].equalsIgnoreCase("S")) {
106 latitude = latitude * -1;
107 }
108
109 Double longitude = Double.parseDouble(strSub[5].substring(0, 3));
110 longitude += Double.parseDouble(strSub[5].substring(3)) / 60;
111 if (strSub[6].equalsIgnoreCase("W")) {
112 longitude = longitude * -1;
113 }
114
115 position = new GeoPosition(latitude, longitude);
116
117 /* Set speed in knobs */
118 speed = Double.parseDouble(strSub[7]);
119
120 /* Set bearing if available */
121 if (strSub[8].isEmpty()) {
122 bearing = null;
123 } else {
124 bearing = Double.parseDouble(strSub[8]);
125 }
126 }
127 return true;
128 }
129}
Note: See TracBrowser for help on using the repository browser.