Changeset 36107 in osm for applications/editors/josm/plugins
- Timestamp:
- 2023-08-01T14:17:03+02:00 (16 months ago)
- Location:
- applications/editors/josm/plugins/livegps
- Files:
-
- 6 added
- 4 deleted
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/livegps/build.xml
r35993 r36107 2 2 <project name="livegps" default="dist" basedir="."> 3 3 <property name="commit.message" value="Changed the constructor signature of the plugin main class"/> 4 <property name="plugin.main.version" value="18 494"/>5 4 <property name="plugin.main.version" value="18788"/> 5 6 6 <!-- Configure these properties (replace "..." accordingly). 7 7 See https://josm.openstreetmap.de/wiki/DevelopersGuide/DevelopingPlugins … … 10 10 <property name="plugin.class" value="livegps.LiveGpsPlugin"/> 11 11 <property name="plugin.description" value="Support live GPS input (moving dot) through a connection to gpsd server."/> 12 <property name="plugin.icon" value="images/dialogs/livegps. png"/>12 <property name="plugin.icon" value="images/dialogs/livegps.svg"/> 13 13 <property name="plugin.link" value="https://wiki.openstreetmap.org/index.php/JOSM/Plugins/LiveGPS"/> 14 14 <property name="plugin.stage" value="50"/> 15 15 16 16 <!-- ** include targets that all plugins have in common ** --> 17 17 <import file="../build-common.xml"/> -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java
r34526 r36107 25 25 26 26 public class LiveGpsAcquirer implements Runnable { 27 private static final String DEFAULT_HOST = "localhost"; 28 private static final int DEFAULT_PORT = 2947; 29 private static final String C_HOST = "livegps.gpsd.host"; 30 private static final String C_PORT = "livegps.gpsd.port"; 27 /* default gpsd host address */ 28 public static final String DEFAULT_HOST = "localhost"; 29 /* default gpsd port number */ 30 public static final int DEFAULT_PORT = 2947; 31 /* option to use specify gpsd host address */ 32 public static final String C_HOST = "livegps.gpsd.host"; 33 /* option to use specify gpsd port number */ 34 public static final String C_PORT = "livegps.gpsd.port"; 31 35 private String gpsdHost; 32 36 private int gpsdPort; … … 37 41 private boolean shutdownFlag = false; 38 42 private boolean JSONProtocol = true; 43 private long skipTime = 0L; 44 private int skipNum = 0; 39 45 40 46 private final List<PropertyChangeListener> propertyChangeListener = new ArrayList<>(); … … 139 145 } 140 146 141 assert (connected);147 assert connected; 142 148 143 149 try { … … 191 197 String line, type, release; 192 198 193 Logging.info("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" + gpsdPort); 199 long t = System.currentTimeMillis(); 200 if (skipTime == 0 || t > skipTime) { 201 skipTime = 0; 202 Logging.info("LiveGps: trying to connect to gpsd at " + gpsdHost + ":" 203 + gpsdPort + (skipNum != 0 ? " (skipped " + skipNum + " notices)" : "")); 204 skipNum = 0; 205 } else { 206 ++skipNum; 207 } 194 208 fireGpsStatusChangeEvent(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 195 209 … … 200 214 break; 201 215 } catch (IOException e) { 202 Logging.warn("LiveGps: Could not open connection to gpsd: " + e); 216 if (skipTime == 0) { 217 Logging.warn("LiveGps: Could not open connection to gpsd ("+addrs[i]+"): " + e); 218 } 203 219 gpsdSocket = null; 204 220 } 205 221 } 206 222 207 if (gpsdSocket == null || gpsdSocket.isConnected() == false) 223 if (gpsdSocket == null || gpsdSocket.isConnected() == false) { 224 if (skipTime == 0) 225 skipTime = System.currentTimeMillis()+60000; 208 226 throw new IOException(); 227 } 228 skipTime = 0; 229 skipNum = 0; 209 230 210 231 /* … … 311 332 312 333 words = line.split(","); 313 if ((words.length == 0) || (!words[0].equals("GPSD")))334 if ((words.length == 0) || !words[0].equals("GPSD")) 314 335 return null; 315 336 -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsData.java
r33739 r36107 7 7 8 8 import org.openstreetmap.josm.data.coor.LatLon; 9 import org.openstreetmap.josm.data.gpx.WayPoint; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 11 import org.openstreetmap.josm.data.osm.Way; … … 13 14 14 15 /** 16 * Representation of a single LiveGPS data epoch 15 17 * @author cdaller 16 *17 18 */ 18 19 public class LiveGpsData { … … 24 25 private String wayString; 25 26 private Way way; 27 private WayPoint wp; 26 28 27 29 public LiveGpsData(double latitude, double longitude, float course, float speed) { … … 42 44 43 45 /** 44 * @return the course 46 * Return the waypoint associated with this data set (can be {@code null}) 47 * @return waypoint with additional information or {@code null} 48 */ 49 public WayPoint getWaypoint() { 50 return this.wp; 51 } 52 53 /** 54 * Set the waypoint to transfer additional data form NMEA input 55 * @param wp waypoint to set 56 */ 57 public void setWaypoint(WayPoint wp) { 58 this.wp = wp; 59 } 60 61 /** 62 * Return the course value 63 * @return course value in degree 45 64 */ 46 65 public float getCourse() { … … 49 68 50 69 /** 51 * @param course the course to set 70 * Set the course value in degree 71 * @param course course to set 52 72 */ 53 73 public void setCourse(float course) { … … 56 76 57 77 /** 58 * @return the haveFix 78 * Return the fix status (whether there is a position solution or not) 79 * @return fix status 59 80 */ 60 81 public boolean isFix() { … … 63 84 64 85 /** 86 * Set the fix status (whether there is a position solution or not) 65 87 * @param haveFix the haveFix to set 66 88 */ … … 70 92 71 93 /** 72 * @return the latitude 94 * Return the latitude part of the position 95 * @return latitude of position 73 96 */ 74 97 public double getLatitude() { … … 77 100 78 101 /** 79 * @return the longitude 102 * Return the longitude part of the position 103 * @return longitude of position 80 104 */ 81 105 public double getLongitude() { … … 84 108 85 109 /** 86 * @return the speed in metres per second! 110 * Return the speed (m/s) 111 * @return speed in metres per second! 87 112 */ 88 113 public float getSpeed() { … … 91 116 92 117 /** 118 * Set the speed (m/s) 93 119 * @param speed the speed to set 94 120 */ … … 98 124 99 125 /** 100 * @return the latlon 126 * Return the position with latitude and logitude combined 127 * @return both position components 101 128 */ 102 129 public LatLon getLatLon() { … … 104 131 } 105 132 133 /** 134 * Set the position with latitude and logitude combined 135 * @param latLon position to set 136 */ 106 137 public void setLatLon(LatLon latLon) { 107 138 this.latLon = latLon; … … 202 233 if (this == obj) 203 234 return true; 204 if (obj == null) 205 return false; 206 if (getClass() != obj.getClass()) 235 if (!(obj instanceof LiveGpsData)) 207 236 return false; 208 237 final LiveGpsData other = (LiveGpsData) obj; -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java
r33078 r36107 14 14 import javax.swing.SwingUtilities; 15 15 16 import org.openstreetmap.josm.data.coor.conversion.CoordinateFormatManager; 17 import org.openstreetmap.josm.data.coor.conversion.ICoordinateFormat; 16 18 import org.openstreetmap.josm.gui.MapFrame; 17 19 import org.openstreetmap.josm.gui.dialogs.ToggleDialog; 20 import org.openstreetmap.josm.spi.preferences.Config; 18 21 import org.openstreetmap.josm.tools.Shortcut; 19 22 20 23 /** 24 * The LiveGPS dialog window showing the current data and status 21 25 * @author cdaller 22 *23 26 */ 24 27 public class LiveGpsDialog extends ToggleDialog implements PropertyChangeListener { 25 28 private static final long serialVersionUID = 6183400754671501117L; 26 29 private JLabel statusLabel; 30 private JLabel nmeaStatusLabel; 27 31 private JLabel wayLabel; 28 32 private JLabel latLabel; … … 31 35 private JLabel speedLabel; 32 36 private JPanel panel; 33 private LiveGpsStatus status; 37 private LiveGpsStatus status = new LiveGpsStatus(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 38 private LiveGpsStatus nmeaStatus = new LiveGpsStatus(LiveGpsStatus.GpsStatus.CONNECTING, tr("Connecting")); 34 39 private LiveGpsData data; 35 40 … … 39 44 KeyEvent.VK_G, Shortcut.ALT_CTRL_SHIFT), 100); 40 45 panel = new JPanel(); 41 panel.setLayout(new GridLayout( 6, 2));42 panel.add(new JLabel(tr("Status ")));46 panel.setLayout(new GridLayout(7, 2)); 47 panel.add(new JLabel(tr("Status gpsd"))); 43 48 panel.add(statusLabel = new JLabel()); 49 if (!Config.getPref().get(LiveGpsAcquirerNMEA.C_SERIAL).isEmpty()) { 50 panel.add(new JLabel(tr("Status NMEA"))); 51 panel.add(nmeaStatusLabel = new JLabel()); 52 } 44 53 panel.add(new JLabel(tr("Way Info"))); 45 54 panel.add(wayLabel = new JLabel()); … … 68 77 if (data.isFix()) { 69 78 panel.setBackground(Color.WHITE); 70 latLabel.setText(data.getLatitude() + "deg"); 71 longLabel.setText(data.getLongitude() + "deg"); 79 ICoordinateFormat mCord = CoordinateFormatManager.getDefaultFormat(); 80 latLabel.setText(mCord.latToString(data.getLatLon())); 81 longLabel.setText(mCord.lonToString(data.getLatLon())); 72 82 double mySpeed = data.getSpeed() * 3.6f; 73 speedLabel.setText( (Math.round(mySpeed*100)/100) + "km/h");74 courseLabel.setText( data.getCourse() + "deg");83 speedLabel.setText(tr("{0} km/h", Math.round(mySpeed*100)/100)); 84 courseLabel.setText(tr("{0} deg", data.getCourse())); 75 85 76 86 String wayString = data.getWayInfo(); … … 89 99 } }); 90 100 } else if ("gpsstatus".equals(evt.getPropertyName())) { 101 LiveGpsStatus oldStatus = status; 91 102 status = (LiveGpsStatus) evt.getNewValue(); 92 103 … … 94 105 @Override 95 106 public void run() { 96 statusLabel.setText(status.getStatusMessage()); 97 if (status.getStatus() != LiveGpsStatus.GpsStatus.CONNECTED) { 107 /* prevent flickering - skip the connecting message when NMEA input is working */ 108 if (!(oldStatus.getStatus() == LiveGpsStatus.GpsStatus.CONNECTION_FAILED && status.getStatus() == LiveGpsStatus.GpsStatus.CONNECTING && nmeaStatus.getStatus() == LiveGpsStatus.GpsStatus.CONNECTED)) 109 statusLabel.setText(status.getStatusMessage()); 110 if (status.getStatus() != LiveGpsStatus.GpsStatus.CONNECTED && nmeaStatus.getStatus() != LiveGpsStatus.GpsStatus.CONNECTED) { 98 111 panel.setBackground(Color.RED); 99 112 } else { … … 101 114 } 102 115 } }); 116 } else if ("nmeastatus".equals(evt.getPropertyName())) { 117 nmeaStatus = (LiveGpsStatus) evt.getNewValue(); 118 119 SwingUtilities.invokeLater(new Runnable() { 120 @Override 121 public void run() { 122 nmeaStatusLabel.setText(nmeaStatus.getStatusMessage()); 123 } }); 103 124 } 104 125 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java
r35975 r36107 63 63 } 64 64 65 void setCurrentPosition(double lat, double lon ) {65 void setCurrentPosition(double lat, double lon, WayPoint wp) { 66 66 LatLon thisPos = new LatLon(lat, lon); 67 67 if (lastPos != null && thisPos.equalsEpsilon(lastPos, ILatLon.MAX_SERVER_PRECISION)) … … 71 71 72 72 lastPos = thisPos; 73 lastPoint = new WayPoint(thisPos); 74 lastPoint.attr.put("time", dateFormat.format(new Date())); 73 if (wp != null) { 74 lastPoint = wp; 75 } else { 76 lastPoint = new WayPoint(thisPos); 77 lastPoint.attr.put("time", dateFormat.format(new Date())); 78 } 75 79 trackSegment.addWaypoint(lastPoint); 76 80 … … 110 114 lastData = (LiveGpsData) evt.getNewValue(); 111 115 if (lastData.isFix()) { 112 setCurrentPosition(lastData.getLatitude(), lastData.getLongitude() );116 setCurrentPosition(lastData.getLatitude(), lastData.getLongitude(), lastData.getWaypoint()); 113 117 if (allowRedraw()) 114 118 this.setFilterStateChanged(); -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java
r35583 r36107 23 23 import org.openstreetmap.josm.gui.layer.LayerManager.LayerOrderChangeEvent; 24 24 import org.openstreetmap.josm.gui.layer.LayerManager.LayerRemoveEvent; 25 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 25 26 import org.openstreetmap.josm.plugins.Plugin; 26 27 import org.openstreetmap.josm.plugins.PluginInformation; 28 import org.openstreetmap.josm.spi.preferences.Config; 27 29 import org.openstreetmap.josm.tools.Shortcut; 28 30 … … 31 33 private LiveGpsAcquirer acquirer = null; 32 34 private Thread acquirerThread = null; 35 private LiveGpsAcquirerNMEA acquirerNMEA = null; 36 private Thread acquirerNMEAThread = null; 33 37 private JMenu lgpsmenu = null; 34 38 private JCheckBoxMenuItem lgpscapture; … … 186 190 acquirerThread.start(); 187 191 192 assert (acquirerNMEA == null); 193 assert (acquirerNMEAThread == null); 194 195 if (!Config.getPref().get(LiveGpsAcquirerNMEA.C_SERIAL).isEmpty()) { 196 acquirerNMEA = new LiveGpsAcquirerNMEA(); 197 acquirerNMEAThread = new Thread(acquirerNMEA); 198 acquirerNMEA.addPropertyChangeListener(lgpslayer); 199 acquirerNMEA.addPropertyChangeListener(lgpsdialog); 200 201 for (PropertyChangeListener listener : listenerQueue) { 202 acquirerNMEA.addPropertyChangeListener(listener); 203 } 204 205 acquirerNMEAThread.start(); 206 } 207 188 208 enabled = true; 189 190 209 } else if (!enable && enabled) { 191 210 assert (lgpslayer != null); … … 197 216 acquirerThread = null; 198 217 218 if (acquirerNMEAThread != null) { 219 acquirerNMEA.shutdown(); 220 acquirerNMEA = null; 221 acquirerNMEAThread = null; 222 } 223 199 224 enabled = false; 200 225 } … … 211 236 if (acquirer != null) 212 237 acquirer.addPropertyChangeListener(listener); 238 if (acquirerNMEA != null) 239 acquirerNMEA.addPropertyChangeListener(listener); 213 240 } 214 241 … … 223 250 if (acquirer != null) 224 251 acquirer.removePropertyChangeListener(listener); 252 if (acquirerNMEA != null) 253 acquirerNMEA.removePropertyChangeListener(listener); 225 254 } 226 255 … … 232 261 233 262 /** 234 * @return the lgpsmenu 263 * Return the LiveGPS menu 264 * @return the {@code JMenu} entry 235 265 */ 236 266 public JMenu getLgpsMenu() { 237 267 return this.lgpsmenu; 238 268 } 269 270 @Override 271 public PreferenceSetting getPreferenceSetting() { 272 return new LiveGPSPreferences(); 273 } 239 274 } -
applications/editors/josm/plugins/livegps/src/livegps/LiveGpsStatus.java
r33078 r36107 3 3 4 4 /** 5 * Representation of the LiveGPS connection status 5 6 * @author cdaller 6 *7 7 */ 8 8 public class LiveGpsStatus { … … 14 14 private GpsStatus status; 15 15 16 /** 17 * Create a status representation 18 * @param status current status code 19 * @param statusMessage current status description message 20 */ 16 21 public LiveGpsStatus(GpsStatus status, String statusMessage) { 17 22 super(); … … 21 26 22 27 /** 23 * @return the status 28 * Retrieve the current status 29 * @return current status 24 30 */ 25 31 public GpsStatus getStatus() { … … 28 34 29 35 /** 36 * Set the current status 30 37 * @param status the status to set 31 38 */ … … 35 42 36 43 /** 37 * @return the statusMessage 44 * Access the status message 45 * @return status message 38 46 */ 39 47 public String getStatusMessage() { … … 42 50 43 51 /** 44 * @param statusMessage the statusMessage to set 52 * Set the current status message 53 * @param statusMessage the status message to set 45 54 */ 46 55 public void setStatusMessage(String statusMessage) {
Note:
See TracChangeset
for help on using the changeset viewer.