Ignore:
Timestamp:
2023-08-10T13:26:23+02:00 (14 months ago)
Author:
stoecker
Message:

bug fixes, allow to disable GPSD totally

Location:
applications/editors/josm/plugins/livegps/src/livegps
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGPSPreferences.java

    r36107 r36111  
    88
    99import javax.swing.Box;
     10import javax.swing.JCheckBox;
    1011import javax.swing.JLabel;
    1112import javax.swing.JPanel;
     
    2425    private final JTextField gpsdPort = new JTextField(30);
    2526    private final JTextField serialDevice = new JTextField(30);
     27    private final JCheckBox disableGPSD = new JCheckBox(tr("Disable GPSD"));
    2628
    2729    public LiveGPSPreferences() {
     
    4850        panel.add(serialDevice, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
    4951
     52        disableGPSD.setSelected(Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED));
     53        panel.add(disableGPSD, GBC.eol().fill(GridBagConstraints.HORIZONTAL).insets(5, 0, 0, 5));
     54
    5055        panel.add(Box.createVerticalGlue(), GBC.eol().fill(GridBagConstraints.VERTICAL));
    5156        createPreferenceTabWithScrollPane(gui, panel);
     
    5762        Config.getPref().put(LiveGpsAcquirer.C_PORT, gpsdPort.getText());
    5863        Config.getPref().put(LiveGpsAcquirerNMEA.C_SERIAL, serialDevice.getText());
     64        Config.getPref().putBoolean(LiveGpsAcquirer.C_DISABLED, disableGPSD.isSelected());
    5965        return false;
    6066    }
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirer.java

    r36107 r36111  
    3333    /* option to use specify gpsd port number */
    3434    public static final String C_PORT = "livegps.gpsd.port";
     35    /* option to use specify gpsd disabling */
     36    public static final String C_DISABLED = "livegps.gpsd.disabled";
    3537    private String gpsdHost;
    3638    private int gpsdPort;
     
    132134        while (!shutdownFlag) {
    133135
    134             while (!connected) {
     136            while (!connected && !shutdownFlag) {
    135137                try {
    136138                    connect();
     
    144146                }
    145147            }
     148            if (shutdownFlag)
     149              break;
    146150
    147151            assert connected;
     
    190194
    191195    public void shutdown() {
     196        Logging.info("LiveGps: Shutdown gpsd");
    192197        shutdownFlag = true;
    193198    }
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsAcquirerNMEA.java

    r36107 r36111  
    115115        shutdownFlag = false;
    116116        while (!shutdownFlag) {
    117             while (!connected) {
     117            while (!connected && !shutdownFlag) {
    118118                try {
    119119                    connect();
     
    123123                        Thread.sleep(1000);
    124124                    } catch (InterruptedException ignore) {
    125                         Logging.trace(ignore);
     125                        Logging.info(ignore);
    126126                    }
    127127                }
     
    137137                sb.append((char) loopstartChar);
    138138                Instant lasttime = null;
    139                 while (true) {
     139                while (!shutdownFlag) {
    140140                    // handle long useless data
    141141                    if (sb.length() >= 1020) {
     
    144144                    int c = serReader.read();
    145145                    if (c == '$') {
     146                        Logging.trace("Parsing NMEA: " + sb.toString().replaceAll("[\r\n]",""));
    146147                        parser.parseNMEASentence(sb.toString());
    147148                        sb.delete(0, sb.length());
     
    151152                    } else {
    152153                        sb.append((char) c);
    153                     }
    154                     if (!serReader.ready()) {
    155                         try {
    156                             Thread.sleep(50);
    157                         } catch (InterruptedException ignore) {
    158                             Logging.trace(ignore);
    159                         }
    160154                    }
    161155                    if (!serReader.ready()) {
     
    175169                                if (w.getString("speed") != null)
    176170                                    speed = Float.valueOf(w.getString("speed"));
     171                                Logging.trace("New LiveGPS entry: " + w);
    177172                                LiveGpsData gpsData = new LiveGpsData(w.lat(), w.lon(), course, speed, 0.0f, 0.0f);
    178173                                gpsData.setWaypoint(w);
     
    183178                        if (last != null) {
    184179                            lasttime = last.getInstant();
     180                        }
     181                        if (!serReader.ready()) {
     182                            try {
     183                                Thread.sleep(50);
     184                            } catch (InterruptedException ignore) {
     185                                Logging.info(ignore);
     186                            }
    185187                        }
    186188                    }
     
    195197                    Thread.sleep(1000);
    196198                } catch (InterruptedException ignore) {
    197                     Logging.trace(ignore);
     199                    Logging.info(ignore);
    198200                }
    199201            } catch (IllegalDataException ex) {
     
    209211
    210212    public void shutdown() {
     213        Logging.info("LiveGps: Shutdown NMEA");
    211214        shutdownFlag = true;
    212215    }
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsDialog.java

    r36107 r36111  
    2727public class LiveGpsDialog extends ToggleDialog implements PropertyChangeListener {
    2828    private static final long serialVersionUID = 6183400754671501117L;
     29    private boolean statusGPSD;
     30    private boolean statusNMEA;
     31    private JLabel statusText;
    2932    private JLabel statusLabel;
     33    private JLabel nmeaStatusText;
    3034    private JLabel nmeaStatusLabel;
    3135    private JLabel wayLabel;
     
    4549        panel = new JPanel();
    4650        panel.setLayout(new GridLayout(7, 2));
    47         panel.add(new JLabel(tr("Status gpsd")));
     51        panel.add(statusText = new JLabel(tr("Status gpsd")));
    4852        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         }
     53        panel.add(nmeaStatusText = new JLabel(tr("Status NMEA")));
     54        panel.add(nmeaStatusLabel = new JLabel());
    5355        panel.add(new JLabel(tr("Way Info")));
    5456        panel.add(wayLabel = new JLabel());
     
    6163        panel.add(new JLabel(tr("Course")));
    6264        panel.add(courseLabel = new JLabel());
     65        setStatusVisibility(true);
    6366        createLayout(panel, true, null);
     67    }
     68
     69    /**
     70     * Set the visibility of the status fields
     71     * @param init initialize the values (don't check previous state)
     72     */
     73    private void setStatusVisibility(boolean init) {
     74        boolean statusGPSDNew = !Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED);
     75        if (init || statusGPSD != statusGPSDNew) {
     76            statusText.setVisible(statusGPSDNew);
     77            statusLabel.setVisible(statusGPSDNew);
     78            statusGPSD = statusGPSDNew;
     79        }
     80        boolean statusNMEANew = !Config.getPref().get(LiveGpsAcquirerNMEA.C_SERIAL).isEmpty();
     81        if (init || statusNMEA != statusNMEANew) {
     82            nmeaStatusText.setVisible(statusNMEANew);
     83            nmeaStatusLabel.setVisible(statusNMEANew);
     84            statusNMEA = statusNMEANew;
     85        }
    6486    }
    6587
     
    102124            status = (LiveGpsStatus) evt.getNewValue();
    103125
     126            setStatusVisibility(false);
     127
    104128            SwingUtilities.invokeLater(new Runnable() {
    105129            @Override
     
    117141            nmeaStatus = (LiveGpsStatus) evt.getNewValue();
    118142
     143            setStatusVisibility(false);
     144
    119145            SwingUtilities.invokeLater(new Runnable() {
    120146            @Override
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsLayer.java

    r36107 r36111  
    4242    WayPoint lastPoint;
    4343    private final AppendableGpxTrackSegment trackSegment;
     44    private final GpxData gpxData;
    4445    boolean autocenter;
    4546    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
     
    5455        IGpxTrack trackBeingWritten = new SingleSegmentGpxTrack(trackSegment, attr);
    5556        data.tracks.add(trackBeingWritten);
     57        gpxData = data;
    5658
    5759        initIntervals();
     
    7880        }
    7981        trackSegment.addWaypoint(lastPoint);
     82        gpxData.invalidate();
    8083
    8184        if (autocenter)
  • applications/editors/josm/plugins/livegps/src/livegps/LiveGpsPlugin.java

    r36107 r36111  
    169169
    170170        if (enable && !enabled) {
    171             assert (acquirer == null);
    172             assert (acquirerThread == null);
    173 
    174             acquirer = new LiveGpsAcquirer();
    175             acquirerThread = new Thread(acquirer);
    176 
    177171            if (lgpslayer == null) {
    178172                lgpslayer = new LiveGpsLayer(data);
     
    182176            }
    183177
    184             acquirer.addPropertyChangeListener(lgpslayer);
    185             acquirer.addPropertyChangeListener(lgpsdialog);
    186             for (PropertyChangeListener listener : listenerQueue) {
    187                 acquirer.addPropertyChangeListener(listener);
    188             }
    189 
    190             acquirerThread.start();
     178            assert (acquirer == null);
     179            assert (acquirerThread == null);
     180
     181            if (!Config.getPref().getBoolean(LiveGpsAcquirer.C_DISABLED)) {
     182
     183                acquirer = new LiveGpsAcquirer();
     184                acquirerThread = new Thread(acquirer);
     185
     186                acquirer.addPropertyChangeListener(lgpslayer);
     187                acquirer.addPropertyChangeListener(lgpsdialog);
     188                for (PropertyChangeListener listener : listenerQueue) {
     189                    acquirer.addPropertyChangeListener(listener);
     190                }
     191
     192                acquirerThread.start();
     193            }
    191194
    192195            assert (acquirerNMEA == null);
     
    212215            assert (acquirerThread != null);
    213216
    214             acquirer.shutdown();
    215             acquirer = null;
    216             acquirerThread = null;
     217            if (acquirerThread != null) {
     218                acquirer.shutdown();
     219                acquirer = null;
     220                acquirerThread = null;
     221            }
    217222
    218223            if (acquirerNMEAThread != null) {
Note: See TracChangeset for help on using the changeset viewer.