Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 98d49b0

Browse files
committed
adding contribution by Andrew Evdokimov (SAT, SKY)
fixed toString method to use StringBuilder moved project to github
1 parent c3ed39c commit 98d49b0

File tree

10 files changed

+616
-16
lines changed

10 files changed

+616
-16
lines changed

.classpath

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
33
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
4-
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources"/>
54
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
6-
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"/>
75
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
86
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"/>
97
<classpathentry kind="output" path="target/classes"/>

pom.xml

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@
3131
<timezone>+1</timezone>
3232
</developer>
3333
</developers>
34+
<contributors>
35+
<contributor>
36+
<name>Irakli Betchvaia</name>
37+
</contributor>
38+
<contributor>
39+
<name>Andrew Evdokimov</name>
40+
</contributor>
41+
</contributors>
3442

3543
<dependencies>
3644
<dependency>
@@ -47,8 +55,8 @@
4755
</dependencies>
4856

4957
<scm>
50-
<url>scm:svn:https://forge.hoegergroup.de/svn/gpsd4java/trunk/</url>
51-
<connection>scm:svn:https://forge.hoegergroup.de/svn/gpsd4java/trunk/</connection>
58+
<url>scm:git://github.com/taimos/GPSd4Java.git</url>
59+
<connection>scm:git://github.com/taimos/GPSd4Java.git</connection>
5260
</scm>
5361

5462
<distributionManagement>
@@ -141,12 +149,8 @@
141149
<configuration>
142150
<descriptorRefs>
143151
<descriptorRef>project</descriptorRef>
144-
<!--descriptorRef>test-release</descriptorRef -->
145152
</descriptorRefs>
146153
</configuration>
147-
<!-- <executions> <execution> <id>make-project-assembly</id> <phase>package</phase> <goals> <goal>single</goal> </goals>
148-
</execution> <execution> <id>test-release</id> <phase>package</phase> <goals> <goal>assembly</goal> </goals> </execution>
149-
</executions> -->
150154
</plugin>
151155
</plugins>
152156
</build>

src/main/java/de/taimos/gpsd4java/backend/ResultParser.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import de.taimos.gpsd4java.types.IGPSObject;
3232
import de.taimos.gpsd4java.types.ParseException;
3333
import de.taimos.gpsd4java.types.PollObject;
34+
import de.taimos.gpsd4java.types.SATObject;
3435
import de.taimos.gpsd4java.types.SKYObject;
3536
import de.taimos.gpsd4java.types.TPVObject;
3637
import de.taimos.gpsd4java.types.VersionObject;
@@ -44,12 +45,13 @@
4445
public class ResultParser extends AbstractResultParser {
4546

4647
private static final Logger log = Logger.getLogger(ResultParser.class.getName());
47-
private final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"); // Don't make this static!
48+
private final DateFormat dateFormat; // Don't make this static!
4849

4950
/**
5051
* Create new ResultParser
5152
*/
5253
public ResultParser() {
54+
this.dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
5355
this.dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
5456
}
5557

@@ -89,7 +91,17 @@ public IGPSObject parse(final JSONObject json) throws ParseException {
8991
gps = tpv;
9092
} else if ("SKY".equals(clazz)) {
9193
final SKYObject sky = new SKYObject();
92-
// TODO implement SKY object
94+
sky.setTag(json.optString("tag", null));
95+
sky.setDevice(json.optString("device", null));
96+
sky.setTimestamp(json.optDouble("time", Double.NaN));
97+
sky.setLongitudeDOP(json.optDouble("xdop", Double.NaN));
98+
sky.setLatitudeDOP(json.optDouble("ydop", Double.NaN));
99+
sky.setAltitudeDOP(json.optDouble("vdop", Double.NaN));
100+
sky.setTimestampDOP(json.optDouble("tdop", Double.NaN));
101+
sky.setHorizontalDOP(json.optDouble("hdop", Double.NaN));
102+
sky.setSphericalDOP(json.optDouble("pdop", Double.NaN));
103+
sky.setHypersphericalDOP(json.optDouble("gdop", Double.NaN));
104+
sky.setSatellites(this.parseObjectArray(json.optJSONArray("satellites"), SATObject.class));
93105
gps = sky;
94106
} else if ("ATT".equals(clazz)) {
95107
// TODO implement ATT object
@@ -129,6 +141,14 @@ public IGPSObject parse(final JSONObject json) throws ParseException {
129141
poll.setFixes(this.parseObjectArray(json.optJSONArray("fixes"), TPVObject.class));
130142
poll.setSkyviews(this.parseObjectArray(json.optJSONArray("skyviews"), SKYObject.class));
131143
gps = poll;
144+
} else if (json.has("PRN")) {
145+
final SATObject sat = new SATObject();
146+
sat.setPRN(json.optInt("PRN", -1));
147+
sat.setAzimuth(json.optInt("az", -1));
148+
sat.setElevation(json.optInt("el", -1));
149+
sat.setSignalStrength(json.optInt("ss", -1));
150+
sat.setUsed(json.optBoolean("used", false));
151+
gps = sat;
132152
} else {
133153
throw new ParseException("Invalid object class: " + clazz);
134154
}

src/main/java/de/taimos/gpsd4java/types/DeviceObject.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,19 @@ public boolean equals(final Object obj) {
282282

283283
@Override
284284
public String toString() {
285-
return "DeviceObject [path=" + this.path + ", driver=" + this.driver + ", bps=" + this.bps + ", nativeMode=" + this.nativeMode + "]";
285+
final StringBuilder sb = new StringBuilder();
286+
287+
sb.append("DeviceObject{path=");
288+
sb.append(this.path);
289+
sb.append(", driver=");
290+
sb.append(this.driver);
291+
sb.append(", bps=");
292+
sb.append(this.bps);
293+
sb.append(", nativeMode=");
294+
sb.append(this.nativeMode);
295+
sb.append("}");
296+
297+
return sb.toString();
286298
}
287299

288300
}

src/main/java/de/taimos/gpsd4java/types/DevicesObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public boolean equals(final Object obj) {
7676

7777
@Override
7878
public String toString() {
79-
return "DevicesObject [devices=" + this.devices.size() + "]";
79+
return "DevicesObject{devices=" + this.devices.size() + "}";
8080
}
8181

8282
}

src/main/java/de/taimos/gpsd4java/types/PollObject.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ public boolean equals(final Object obj) {
157157

158158
@Override
159159
public String toString() {
160-
return "PollObject [timestamp=" + this.timestamp + ", active=" + this.active + ", fixes=" + this.fixes.size() + ", skyviews=" + this.skyviews.size() + "]";
160+
final StringBuilder sb = new StringBuilder();
161+
162+
sb.append("PollObject{timestamp=");
163+
sb.append(this.timestamp);
164+
sb.append(", active=");
165+
sb.append(this.active);
166+
sb.append(", fixes=");
167+
sb.append(this.fixes.size());
168+
sb.append(", skyviews=");
169+
sb.append(this.skyviews.size());
170+
sb.append("}");
171+
172+
return sb.toString();
161173
}
162174
}
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
/**
2+
* Copyright 2011 Thorsten Höger, Taimos GmbH
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5+
* use this file except in compliance with the License. You may obtain a copy of
6+
* the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations under
14+
* the License.
15+
*/
16+
package de.taimos.gpsd4java.types;
17+
18+
/**
19+
*
20+
* @author aevdokimov
21+
*/
22+
public class SATObject implements IGPSObject {
23+
24+
private int PRN = -1;
25+
26+
private int azimuth = -1;
27+
28+
private int elevation = -1;
29+
30+
private int signalStrength = -1;
31+
32+
private boolean used = false;
33+
34+
/**
35+
* PRN ID of the satellite. 1-63 are GNSS satellites, 64-96 are GLONASS satellites, 100-164 are SBAS satellites
36+
*
37+
* @return PRN
38+
*/
39+
public int getPRN() {
40+
return this.PRN;
41+
}
42+
43+
/**
44+
* PRN ID of the satellite. 1-63 are GNSS satellites, 64-96 are GLONASS satellites, 100-164 are SBAS satellites
45+
*
46+
* @param PRN
47+
* the PRN to set
48+
*/
49+
public void setPRN(final int PRN) {
50+
this.PRN = PRN;
51+
}
52+
53+
/**
54+
* Azimuth, degrees from true north.
55+
*
56+
* @return azimuth
57+
*/
58+
public int getAzimuth() {
59+
return this.azimuth;
60+
}
61+
62+
/**
63+
* Azimuth, degrees from true north.
64+
*
65+
* @param azimuth
66+
* the azimuth to set
67+
*/
68+
public void setAzimuth(final int azimuth) {
69+
this.azimuth = azimuth;
70+
}
71+
72+
/**
73+
* Elevation in degrees.
74+
*
75+
* @return elevation
76+
*/
77+
public int getElevation() {
78+
return this.elevation;
79+
}
80+
81+
/**
82+
* Elevation in degrees.
83+
*
84+
* @param elevation
85+
* the elevation to set
86+
*/
87+
public void setElevation(final int elevation) {
88+
this.elevation = elevation;
89+
}
90+
91+
/**
92+
* Signal strength in dB.
93+
*
94+
* @return signal strength
95+
*/
96+
public int getSignalStrength() {
97+
return this.signalStrength;
98+
}
99+
100+
/**
101+
* Signal strength in dB.
102+
*
103+
* @param signalStrength
104+
* the signal strength to set
105+
*/
106+
public void setSignalStrength(final int signalStrength) {
107+
this.signalStrength = signalStrength;
108+
}
109+
110+
/**
111+
* Used in current solution? (SBAS/WAAS/EGNOS satellites may be flagged used if the solution has corrections from them, but not all drivers make this information available.)
112+
*
113+
* @return used
114+
*/
115+
public boolean getUsed() {
116+
return this.used;
117+
}
118+
119+
/**
120+
* Used in current solution? (SBAS/WAAS/EGNOS satellites may be flagged used if the solution has corrections from them, but not all drivers make this information available.)
121+
*
122+
* @param used
123+
* the used flag to set
124+
*/
125+
public void setUsed(final boolean used) {
126+
this.used = used;
127+
}
128+
129+
@Override
130+
public int hashCode() {
131+
final int prime = 31;
132+
int result = 1;
133+
long temp;
134+
temp = Double.doubleToLongBits(this.PRN);
135+
result = (prime * result) + (int) (temp ^ (temp >>> 32));
136+
temp = Double.doubleToLongBits(this.azimuth);
137+
result = (prime * result) + (int) (temp ^ (temp >>> 32));
138+
temp = Double.doubleToLongBits(this.elevation);
139+
result = (prime * result) + (int) (temp ^ (temp >>> 32));
140+
temp = Double.doubleToLongBits(this.signalStrength);
141+
result = (prime * result) + (int) (temp ^ (temp >>> 32));
142+
result = (prime * result) + ((this.used) ? 1 : 0);
143+
return result;
144+
}
145+
146+
@Override
147+
public boolean equals(final Object obj) {
148+
if (this == obj) {
149+
return true;
150+
}
151+
if (obj == null) {
152+
return false;
153+
}
154+
if (this.getClass() != obj.getClass()) {
155+
return false;
156+
}
157+
final SATObject other = (SATObject) obj;
158+
if (Double.doubleToLongBits(this.PRN) != Double.doubleToLongBits(other.PRN)) {
159+
return false;
160+
}
161+
if (Double.doubleToLongBits(this.azimuth) != Double.doubleToLongBits(other.azimuth)) {
162+
return false;
163+
}
164+
if (Double.doubleToLongBits(this.elevation) != Double.doubleToLongBits(other.elevation)) {
165+
return false;
166+
}
167+
if (Double.doubleToLongBits(this.signalStrength) != Double.doubleToLongBits(other.signalStrength)) {
168+
return false;
169+
}
170+
if (this.used != other.used) {
171+
return false;
172+
}
173+
return true;
174+
}
175+
176+
@Override
177+
public String toString() {
178+
final StringBuilder sb = new StringBuilder();
179+
sb.append("SATObject{PRN=");
180+
sb.append(this.PRN);
181+
sb.append(", az=");
182+
sb.append(this.azimuth);
183+
sb.append(", el=");
184+
sb.append(this.elevation);
185+
sb.append(", ss=");
186+
sb.append(this.signalStrength);
187+
sb.append(", used=");
188+
sb.append(this.used ? "Y" : "N");
189+
sb.append("}");
190+
return sb.toString();
191+
}
192+
}

0 commit comments

Comments
 (0)