Changeset 36122 in osm for applications/editors/josm/plugins/livegps
- Timestamp:
- 2023-08-22T17:40:36+02:00 (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r36120 r36122 16 16 import java.util.List; 17 17 18 import javax.json.Json; 19 import javax.json.JsonException; 20 import javax.json.JsonNumber; 21 import javax.json.JsonObject; 18 import jakarta.json.Json; 19 import jakarta.json.JsonException; 20 import jakarta.json.JsonNumber; 21 import jakarta.json.JsonObject; 22 import jakarta.json.JsonReader; 22 23 23 24 import org.openstreetmap.josm.spi.preferences.Config; … … 28 29 */ 29 30 public class LiveGpsAcquirer implements Runnable { 30 private String gpsdHost;31 private int gpsdPort;31 private final String gpsdHost; 32 private final int gpsdPort; 32 33 33 34 private Socket gpsdSocket; 34 35 private BufferedReader gpsdReader; 35 private boolean connected = false;36 private boolean shutdownFlag = false;36 private boolean connected; 37 private boolean shutdownFlag; 37 38 private boolean JSONProtocol = true; 38 private long skipTime = 0L;39 private int skipNum = 0;39 private long skipTime; 40 private int skipNum; 40 41 41 42 private final List<PropertyChangeListener> propertyChangeListener = new ArrayList<>(); … … 122 123 public void run() { 123 124 LiveGpsData oldGpsData = null; 124 LiveGpsData gpsData = null;125 LiveGpsData gpsData; 125 126 126 127 shutdownFlag = false; … … 131 132 connect(); 132 133 } catch (IOException iox) { 134 Logging.trace(iox); 133 135 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTION_FAILED, tr("Connection Failed")); 134 136 try { 135 137 Thread.sleep(1000); 136 } catch (InterruptedException ignore) { 137 Logging.trace(ignore); 138 } catch (InterruptedException interruptedException) { 139 Logging.trace(interruptedException); 140 Thread.currentThread().interrupt(); 138 141 } 139 142 } … … 155 158 throw new IOException(); 156 159 157 if (JSONProtocol == true)160 if (JSONProtocol) 158 161 gpsData = parseJSON(line); 159 162 else … … 173 176 try { 174 177 Thread.sleep(1000); 175 } catch (InterruptedException ignore) { 176 Logging.trace(ignore); 178 } catch (InterruptedException interruptedException) { 179 Logging.trace(interruptedException); 180 Thread.currentThread().interrupt(); 177 181 } 178 182 // send warning to layer … … 219 223 } 220 224 221 if (gpsdSocket == null || gpsdSocket.isConnected() == false) {225 if (gpsdSocket == null || !gpsdSocket.isConnected()) { 222 226 if (skipTime == 0) 223 227 skipTime = System.currentTimeMillis()+60000; … … 237 241 return; 238 242 239 try {240 greeting = Json.createReader(new StringReader(line)).readObject();243 try (JsonReader reader = Json.createReader(new StringReader(line))) { 244 greeting = reader.readObject(); 241 245 type = greeting.getString("class"); 242 if ( type.equals("VERSION")) {246 if ("VERSION".equals(type)) { 243 247 release = greeting.getString("release"); 244 248 Logging.info("LiveGps: Connected to gpsd " + release); … … 252 256 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTED, tr("Connected")); 253 257 } 254 } 255 256 if (JSONProtocol == true) { 258 Logging.trace(jex); 259 } 260 261 if (JSONProtocol) { 257 262 JsonObject watch = Json.createObjectBuilder() 258 263 .add("enable", true) … … 276 281 gpsdSocket.close(); 277 282 gpsdSocket = null; 278 } catch ( Exception e) {283 } catch (IOException e) { 279 284 Logging.warn("LiveGps: Unable to close socket; reconnection may not be possible"); 280 } 281 } 282 283 private LiveGpsData parseJSON(String line) { 285 Logging.trace(e); 286 } 287 } 288 289 private static LiveGpsData parseJSON(String line) { 284 290 JsonObject report; 285 291 double lat, lon; … … 289 295 float epy = 0; 290 296 291 try {292 report = Json.createReader(new StringReader(line)).readObject();297 try (JsonReader reader = Json.createReader(new StringReader(line))) { 298 report = reader.readObject(); 293 299 } catch (JsonException jex) { 294 300 Logging.warn("LiveGps: line read from gpsd is not a JSON object:" + line); 301 Logging.trace(jex); 295 302 return null; 296 303 } 297 if (! report.getString("class").equals("TPV") || report.getInt("mode") < 2)304 if (!"TPV".equals(report.getString("class")) || report.getInt("mode") < 2) 298 305 return null; 299 306 … … 322 329 } 323 330 324 private LiveGpsData parseOld(String line) {331 private static LiveGpsData parseOld(String line) { 325 332 String[] words; 326 double lat = 0;327 double lon = 0;333 double lat; 334 double lon; 328 335 float speed = 0; 329 336 float course = 0; 330 337 331 338 words = line.split(","); 332 if ((words.length == 0) || ! words[0].equals("GPSD"))339 if ((words.length == 0) || !"GPSD".equals(words[0])) 333 340 return null; 334 341
Note:
See TracChangeset
for help on using the changeset viewer.