Changeset 32649 in osm for applications/editors/josm/plugins/globalsat
- Timestamp:
- 2016-07-13T08:41:57+02:00 (8 years ago)
- Location:
- applications/editors/josm/plugins/globalsat
- Files:
-
- 2 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/globalsat/.project
r32286 r32649 16 16 </arguments> 17 17 </buildCommand> 18 <buildCommand> 19 <name>net.sf.eclipsecs.core.CheckstyleBuilder</name> 20 <arguments> 21 </arguments> 22 </buildCommand> 18 23 </buildSpec> 19 24 <natures> 20 25 <nature>org.eclipse.jdt.core.javanature</nature> 26 <nature>net.sf.eclipsecs.core.CheckstyleNature</nature> 21 27 </natures> 22 28 </projectDescription> -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatConfigDialog.java
r30532 r32649 1 // License: GPL v2 or later (v3 preferred). Copyright 2008 by Raphael Mack1 // License: GPL. For details, see LICENSE file. 2 2 3 3 //TODO: check input for numbers in text fields … … 28 28 * Configuration download dialog. 29 29 * 30 * @author Raphael Mack <ramack@raphael-mack.de> 31 * 30 * @author Raphael Mack <ramack@raphael-mack.de> 32 31 */ 33 32 public class GlobalsatConfigDialog extends JPanel { 34 33 35 36 34 public class IntegerTextField extends JTextField { 37 35 38 final static String badchars = "-`~!@#$%^&*()_+=\\|\"':;?/>.<, "; 39 36 static final String badchars = "-`~!@#$%^&*()_+=\\|\"':;?/>.<, "; 37 38 @Override 40 39 public void processKeyEvent(KeyEvent ev) { 41 40 42 41 char c = ev.getKeyChar(); 43 if ((Character.isLetter(c) && !ev.isAltDown())42 if ((Character.isLetter(c) && !ev.isAltDown()) 44 43 || badchars.indexOf(c) > -1) { 45 44 ev.consume(); … … 79 78 80 79 Dimension xx = aSeconds.getPreferredSize(); 81 aSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));80 aSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 82 81 aSeconds.setHorizontalAlignment(JTextField.RIGHT); 83 aMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));82 aMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 84 83 aMeters.setHorizontalAlignment(JTextField.RIGHT); 85 bSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));84 bSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 86 85 bSeconds.setHorizontalAlignment(JTextField.RIGHT); 87 bMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));86 bMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 88 87 bMeters.setHorizontalAlignment(JTextField.RIGHT); 89 cSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));88 cSeconds.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 90 89 cSeconds.setHorizontalAlignment(JTextField.RIGHT); 91 cMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int)xx.getHeight()));90 cMeters.setPreferredSize(new Dimension((int) xx.getWidth() + 50, (int) xx.getHeight())); 92 91 cMeters.setHorizontalAlignment(JTextField.RIGHT); 93 92 … … 106 105 logPanel.add(formatPosTDSA); 107 106 108 c.insets = new Insets(4, 4,0,4);107 c.insets = new Insets(4, 4, 0, 4); 109 108 c.gridwidth = 1; 110 109 c.weightx = 1.8; … … 116 115 117 116 disableLogSpeed = new JCheckBox(tr("Disable data logging if speed falls below")); 118 c.insets = new Insets(4, 4,0,4);117 c.insets = new Insets(4, 4, 0, 4); 119 118 c.gridwidth = 1; 120 119 c.weightx = 0.8; … … 127 126 minLogSpeed = new IntegerTextField(); 128 127 minLogSpeed.setHorizontalAlignment(JTextField.RIGHT); 129 c.insets = new Insets(4, 4,0,4);128 c.insets = new Insets(4, 4, 0, 4); 130 129 c.gridwidth = 1; 131 130 c.weightx = 1.5; … … 135 134 add(minLogSpeed, c); 136 135 137 disableLogSpeed.addActionListener(new ActionListener(){ 138 public void actionPerformed(java.awt.event.ActionEvent e){ 136 disableLogSpeed.addActionListener(new ActionListener() { 137 @Override 138 public void actionPerformed(java.awt.event.ActionEvent e) { 139 139 minLogSpeed.setEnabled(disableLogSpeed.isSelected()); 140 140 } … … 142 142 143 143 disableLogDist = new JCheckBox(tr("Disable data logging if distance falls below")); 144 c.insets = new Insets(0, 4,4,4);144 c.insets = new Insets(0, 4, 4, 4); 145 145 c.gridwidth = 1; 146 146 c.weightx = 0.8; … … 152 152 minLogDist = new IntegerTextField(); 153 153 minLogDist.setHorizontalAlignment(JTextField.RIGHT); 154 c.insets = new Insets(0, 4,4,4);154 c.insets = new Insets(0, 4, 4, 4); 155 155 c.gridwidth = 1; 156 156 c.weightx = 1.5; … … 160 160 add(minLogDist, c); 161 161 Dimension x = minLogDist.getPreferredSize(); 162 minLogDist.setPreferredSize(new Dimension((int)x.getWidth() + 50, (int)x.getHeight())); 163 164 disableLogDist.addActionListener(new ActionListener(){ 165 public void actionPerformed(java.awt.event.ActionEvent e){ 162 minLogDist.setPreferredSize(new Dimension((int) x.getWidth() + 50, (int) x.getHeight())); 163 164 disableLogDist.addActionListener(new ActionListener() { 165 @Override 166 public void actionPerformed(java.awt.event.ActionEvent e) { 166 167 minLogDist.setEnabled(disableLogDist.isSelected()); 167 168 } … … 180 181 group.add(aDist); 181 182 182 c.insets = new Insets(4, 4,0,4);183 c.insets = new Insets(4, 4, 0, 4); 183 184 c.gridwidth = 1; 184 185 c.weightx = 1; … … 187 188 c.gridy = 3; 188 189 add(aTime, c); 189 c.insets = new Insets(0, 4,4,4);190 c.insets = new Insets(0, 4, 4, 4); 190 191 c.gridy = 4; 191 192 add(aDist, c); 192 193 193 c.insets = new Insets(4, 4,0,4);194 c.insets = new Insets(4, 4, 0, 4); 194 195 c.gridwidth = 1; 195 196 c.weightx = 1; … … 198 199 c.gridy = 3; 199 200 add(aSeconds, c); 200 c.insets = new Insets(0, 4,4,4);201 c.insets = new Insets(0, 4, 4, 4); 201 202 c.gridy = 4; 202 203 add(aMeters, c); … … 206 207 group.add(bDist); 207 208 208 c.insets = new Insets(4, 4,0,4);209 c.insets = new Insets(4, 4, 0, 4); 209 210 c.gridwidth = 1; 210 211 c.weightx = 1; … … 213 214 c.gridy = 5; 214 215 add(bTime, c); 215 c.insets = new Insets(0, 4,4,4);216 c.insets = new Insets(0, 4, 4, 4); 216 217 c.gridy = 6; 217 218 add(bDist, c); 218 219 219 c.insets = new Insets(4, 4,0,4);220 c.insets = new Insets(4, 4, 0, 4); 220 221 c.gridwidth = 1; 221 222 c.weightx = 1; … … 224 225 c.gridy = 5; 225 226 add(bSeconds, c); 226 c.insets = new Insets(0, 4,4,4);227 c.insets = new Insets(0, 4, 4, 4); 227 228 c.gridy = 6; 228 229 add(bMeters, c); … … 232 233 group.add(cDist); 233 234 234 c.insets = new Insets(4, 4,0,4);235 c.insets = new Insets(4, 4, 0, 4); 235 236 c.gridwidth = 1; 236 237 c.weightx = 1; … … 239 240 c.gridy = 7; 240 241 add(cTime, c); 241 c.insets = new Insets(0, 4,4,4);242 c.insets = new Insets(0, 4, 4, 4); 242 243 c.gridy = 8; 243 244 add(cDist, c); 244 245 245 c.insets = new Insets(4, 4,0,4);246 c.insets = new Insets(4, 4, 0, 4); 246 247 c.gridwidth = 1; 247 248 c.weightx = 1; … … 250 251 c.gridy = 7; 251 252 add(cSeconds, c); 252 c.insets = new Insets(0, 4,4,4);253 c.insets = new Insets(0, 4, 4, 4); 253 254 c.gridy = 8; 254 255 add(cMeters, c); … … 258 259 //add ID textbox 259 260 260 261 262 switch(conf.getLogFormat()){ 261 switch(conf.getLogFormat()) { 263 262 case 0: 264 263 formatPosOnly.setSelected(true); … … 274 273 } 275 274 276 if (conf.getSwATimeOrDist() == 0){275 if (conf.getSwATimeOrDist() == 0) { 277 276 aTime.setSelected(true); 278 277 aDist.setSelected(false); 279 } else{278 } else { 280 279 aTime.setSelected(false); 281 280 aDist.setSelected(true); 282 281 } 283 282 284 if (conf.getSwBTimeOrDist() == 0){283 if (conf.getSwBTimeOrDist() == 0) { 285 284 bTime.setSelected(true); 286 285 bDist.setSelected(false); 287 } else{286 } else { 288 287 bTime.setSelected(false); 289 288 bDist.setSelected(true); 290 289 } 291 290 292 if (conf.getSwCTimeOrDist() == 0){291 if (conf.getSwCTimeOrDist() == 0) { 293 292 cTime.setSelected(true); 294 293 cDist.setSelected(false); 295 } else{294 } else { 296 295 cTime.setSelected(false); 297 296 cDist.setSelected(true); … … 306 305 cSeconds.setText("" + conf.getSwCTime() / 1000); 307 306 cMeters.setText("" + conf.getSwCDist()); 308 309 307 } 310 308 … … 312 310 * Get the selected configuration. 313 311 */ 314 public Dg100Config getConfig() {312 public Dg100Config getConfig() { 315 313 conf.setDisableLogDist(disableLogDist.isSelected()); 316 314 conf.setDisableLogSpeed(disableLogSpeed.isSelected()); … … 318 316 conf.setSpeedThres(Integer.parseInt(minLogSpeed.getText())); 319 317 320 if (formatPosOnly.isSelected()){321 conf.setLogFormat((byte) 0);322 } else if(formatPosTDS.isSelected()){323 conf.setLogFormat((byte) 1);324 } else if(formatPosTDSA.isSelected()){325 conf.setLogFormat((byte) 2);326 } 327 328 conf.setSwATimeOrDist((byte) (aDist.isSelected() ? 1 : 0));329 conf.setSwBTimeOrDist((byte) (bDist.isSelected() ? 1 : 0));330 conf.setSwCTimeOrDist((byte) (cDist.isSelected() ? 1 : 0));318 if (formatPosOnly.isSelected()) { 319 conf.setLogFormat((byte) 0); 320 } else if (formatPosTDS.isSelected()) { 321 conf.setLogFormat((byte) 1); 322 } else if (formatPosTDSA.isSelected()) { 323 conf.setLogFormat((byte) 2); 324 } 325 326 conf.setSwATimeOrDist((byte) (aDist.isSelected() ? 1 : 0)); 327 conf.setSwBTimeOrDist((byte) (bDist.isSelected() ? 1 : 0)); 328 conf.setSwCTimeOrDist((byte) (cDist.isSelected() ? 1 : 0)); 331 329 332 330 conf.setSwATime(Integer.parseInt(aSeconds.getText()) * 1000); -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatDg100.java
r30737 r32649 1 // License: GPL. For details, see LICENSE file. 1 2 /** 2 3 * Communicate with a GlobalSat DG-100 GPS mouse and data logger. … … 5 6 */ 6 7 package org.openstreetmap.josm.plugins.globalsat; 7 8 import gnu.io.CommPortIdentifier;9 import gnu.io.PortInUseException;10 import gnu.io.SerialPort;11 import gnu.io.UnsupportedCommOperationException;12 8 13 9 import java.io.IOException; … … 31 27 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 32 28 29 import gnu.io.CommPortIdentifier; 30 import gnu.io.PortInUseException; 31 import gnu.io.SerialPort; 32 import gnu.io.UnsupportedCommOperationException; 33 33 34 /** 34 35 * @author ramack 35 36 * 36 37 */ 37 public class GlobalsatDg100 38 { 39 public class ConnectionException extends Exception {40 ConnectionException(Exception cause) {38 public class GlobalsatDg100 { 39 40 public class ConnectionException extends Exception { 41 ConnectionException(Exception cause) { 41 42 super(cause); 42 43 } 43 ConnectionException(String msg){ 44 45 ConnectionException(String msg) { 44 46 super(msg); 45 47 } … … 65 67 };*/ 66 68 /** delete file: A0 A2 00 03 BA FF FF 02 B8 B0 B3 */ 67 private static byte dg100CmdDelFile[]=68 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBA69 ,(byte) 0xFF, (byte) 0xFF, (byte) 0x02, (byte) 0xB8, (byte) 0xB0, (byte) 0xB369 private static byte[] dg100CmdDelFile = 70 {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBA, 71 (byte) 0xFF, (byte) 0xFF, (byte) 0x02, (byte) 0xB8, (byte) 0xB0, (byte) 0xB3 70 72 }; 71 73 /** get file info: A0 A2 00 03 BB 00 00 00 BB B0 B3 */ 72 private static byte dg100CmdGetFileInfo[]=73 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBB74 ,(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBB, (byte) 0xB0, (byte) 0xB374 private static byte[] dg100CmdGetFileInfo = 75 {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xBB, 76 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xBB, (byte) 0xB0, (byte) 0xB3 75 77 }; 76 78 /** get gps recs: A0 A2 00 03 B5 00 02 00 B7 B0 B3 */ 77 private static byte dg100CmdGetGpsRecs[]=78 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xB579 ,(byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB379 private static byte[] dg100CmdGetGpsRecs = 80 {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x03, (byte) 0xB5, 81 (byte) 0x00, (byte) 0x02, (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3 80 82 }; 81 83 /** read config: A0 A2 00 01 B7 00 B7 B0 B3 */ 82 private static byte dg100CmdGetConfig[]=83 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x01, (byte) 0xB784 ,(byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3 };84 private static byte[] dg100CmdGetConfig = 85 {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x01, (byte) 0xB7, 86 (byte) 0x00, (byte) 0xB7, (byte) 0xB0, (byte) 0xB3 }; 85 87 /** set config: A0 A2 00 2A B8 jj kk ll ll ll ll mm nn nn nn nn 86 88 aa aa aa aa bb bb bb bb cc cc cc cc 00 00 gg hh 87 89 ii dd dd dd dd ee ee ee ee ff ff ff ff 01 xx xx 88 90 B0 B3 */ 89 private static byte dg100CmdSetConfig[]=90 { (byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x2A, (byte) 0xB891 , (byte) 0x0292 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0093 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x0094 , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE895 , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE896 , (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE897 , (byte) 0x00, (byte) 0x0098 , (byte) 0x00, (byte) 0x00, (byte) 0x0099 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00100 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00101 , (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00102 , (byte) 0x01103 ,(byte) 0x00, (byte) 0x00, (byte) 0xB0, (byte) 0xB391 private static byte[] dg100CmdSetConfig = 92 {(byte) 0xA0, (byte) 0xA2, (byte) 0x00, (byte) 0x2A, (byte) 0xB8, 93 (byte) 0x02, 94 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 95 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 96 (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8, 97 (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8, 98 (byte) 0x00, (byte) 0x00, (byte) 0x03, (byte) 0xE8, 99 (byte) 0x00, (byte) 0x00, 100 (byte) 0x00, (byte) 0x00, (byte) 0x00, 101 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 102 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 103 (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, 104 (byte) 0x01, 105 (byte) 0x00, (byte) 0x00, (byte) 0xB0, (byte) 0xB3 104 106 }; 105 107 /** read config: A0 A2 00 01 BF 00 BF B0 B3 */ … … 121 123 private boolean canceled = false; 122 124 123 public GlobalsatDg100(CommPortIdentifier portId) {125 public GlobalsatDg100(CommPortIdentifier portId) { 124 126 this.portIdentifier = portId; 125 127 } 126 128 127 public void cancel() {129 public void cancel() { 128 130 canceled = true; 129 131 disconnect(); … … 139 141 GpxData result = null; 140 142 canceled = false; 141 if (port == null){143 if (port == null) { 142 144 connect(); 143 145 } … … 147 149 148 150 progressMonitor.setTicksCount(gpsRecList.size()); 149 if (gpsRecList.size() > 0){151 if (gpsRecList.size() > 0) { 150 152 GpsRec last = null; 151 153 result = new GpxData(); 152 154 Collection<WayPoint> seg = new ArrayList<>(100); 153 for (GpsRec r:gpsRecList){154 if (canceled){155 for (GpsRec r:gpsRecList) { 156 if (canceled) { 155 157 return result; 156 158 } 157 159 WayPoint p = wayPointFrom(r); 158 if (r.equals(last)){160 if (r.equals(last)) { 159 161 result.waypoints.add(p); 160 } else{162 } else { 161 163 seg.add(p); 162 164 } … … 172 174 } 173 175 174 private WayPoint wayPointFrom(GpsRec r) {176 private WayPoint wayPointFrom(GpsRec r) { 175 177 LatLon l = new LatLon(r.getLatitude(), r.getLongitude()); 176 178 WayPoint result = new WayPoint(l); 177 179 result.attr.put("time", "" + r.getStringZuluTime()); 178 180 result.attr.put("speed", "" + r.getSpeed()); 179 if (r.getDg100TypeOfCurRec() > 1)181 if (r.getDg100TypeOfCurRec() > 1) 180 182 result.attr.put("ele", "" + r.getAltitude()); 181 183 return result; 182 184 } 183 185 184 public void deleteData() throws ConnectionException {185 if (port == null){186 public void deleteData() throws ConnectionException { 187 if (port == null) { 186 188 connect(); 187 189 } 188 try {190 try { 189 191 sendCmdDelFiles(); 190 } catch(Exception e){191 throw new ConnectionException(e); 192 } 193 } 194 195 public void disconnect() {196 if (port != null){192 } catch (Exception e) { 193 throw new ConnectionException(e); 194 } 195 } 196 197 public void disconnect() { 198 if (port != null) { 197 199 port.close(); 198 200 port = null; … … 200 202 } 201 203 202 private void connect() throws ConnectionException {203 try {204 port = (SerialPort) portIdentifier.open("DG100", TIMEOUT);204 private void connect() throws ConnectionException { 205 try { 206 port = (SerialPort) portIdentifier.open("DG100", TIMEOUT); 205 207 port.setSerialPortParams(115200, SerialPort.DATABITS_8, 206 208 SerialPort.STOPBITS_2, SerialPort.PARITY_NONE); 207 209 port.notifyOnOutputEmpty(false); 208 210 209 }catch(PortInUseException e){ 210 throw new ConnectionException(e); 211 }catch(UnsupportedCommOperationException e){ 212 throw new ConnectionException(e); 213 } 214 } 215 216 private List<FileInfoRec> readFileInfoList() throws ConnectionException 217 { 211 } catch (PortInUseException e) { 212 throw new ConnectionException(e); 213 } catch (UnsupportedCommOperationException e) { 214 throw new ConnectionException(e); 215 } 216 } 217 218 private List<FileInfoRec> readFileInfoList() throws ConnectionException { 218 219 int nextIdx = 0; 219 220 List<FileInfoRec> result = new ArrayList<>(64); 220 try {221 do {221 try { 222 do { 222 223 Response<FileInfoRec> response = sendCmdGetFileInfo(nextIdx); 223 224 nextIdx = response.getNextIdx(); … … 225 226 } while (nextIdx > 0); 226 227 return result; 227 }catch(Exception e){ 228 throw new ConnectionException(e); 229 } 230 } 231 232 public List<GpsRec> readGpsRecList(List<FileInfoRec> fileInfoList) throws ConnectionException 233 { 228 } catch (Exception e) { 229 throw new ConnectionException(e); 230 } 231 } 232 233 public List<GpsRec> readGpsRecList(List<FileInfoRec> fileInfoList) throws ConnectionException { 234 234 List<GpsRec> result = new ArrayList<>(200); 235 235 236 try {237 for (FileInfoRec fileInfoRec:fileInfoList){236 try { 237 for (FileInfoRec fileInfoRec:fileInfoList) { 238 238 Response<GpsRec> response = sendCmdGetGpsRecs(fileInfoRec.getIdx()); 239 239 result.addAll(response.getRecs()); 240 240 } 241 241 return result; 242 }catch(Exception e){ 243 throw new ConnectionException(e); 244 } 245 } 246 247 private Response<?> sendCmdDelFiles() throws IOException, UnsupportedCommOperationException 248 { 242 } catch (Exception e) { 243 throw new ConnectionException(e); 244 } 245 } 246 247 private Response<?> sendCmdDelFiles() throws IOException, UnsupportedCommOperationException { 249 248 System.out.println("deleting data..."); 250 249 int len = sendCmd(dg100CmdDelFile, response, -1); … … 253 252 254 253 @SuppressWarnings("unchecked") 255 private Response<FileInfoRec> sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException 256 { 254 private Response<FileInfoRec> sendCmdGetFileInfo(int idx) throws IOException, UnsupportedCommOperationException { 257 255 byte[] src = dg100CmdGetFileInfo; 258 256 ByteBuffer buf = ByteBuffer.wrap(src); 259 257 buf.position(5); 260 buf.putShort((short) idx); // index of first file info rec to be read258 buf.putShort((short) idx); // index of first file info rec to be read 261 259 updateCheckSum(buf); 262 260 int len = sendCmd(src, response, -1); … … 264 262 } 265 263 266 private Response<?> sendCmdGetConfig() throws IOException, UnsupportedCommOperationException 267 { 264 private Response<?> sendCmdGetConfig() throws IOException, UnsupportedCommOperationException { 268 265 byte[] src = dg100CmdGetConfig; 269 266 int len = sendCmd(src, response, -1); … … 271 268 } 272 269 273 public Dg100Config getConfig() throws ConnectionException {274 try {275 if (port == null){270 public Dg100Config getConfig() throws ConnectionException { 271 try { 272 if (port == null) { 276 273 connect(); 277 274 } 278 275 return sendCmdGetConfig().getConfig(); 279 }catch(Exception e){ 280 throw new ConnectionException(e); 281 } 282 } 283 284 private void sendCmdSetConfig(Dg100Config config) throws IOException, UnsupportedCommOperationException 285 { 276 } catch (Exception e) { 277 throw new ConnectionException(e); 278 } 279 } 280 281 private void sendCmdSetConfig(Dg100Config config) throws IOException, UnsupportedCommOperationException { 286 282 byte[] src = dg100CmdSetConfig; 287 283 ByteBuffer buf = ByteBuffer.wrap(src); 288 if (config != null) {284 if (config != null) { 289 285 config.write(buf); 290 286 } … … 295 291 } 296 292 297 public void setConfig(Dg100Config conf) throws ConnectionException {298 try {293 public void setConfig(Dg100Config conf) throws ConnectionException { 294 try { 299 295 sendCmdSetConfig(conf); 300 } catch(Exception e){301 throw new ConnectionException(e); 302 } 303 } 304 305 public boolean isCanceled() {296 } catch (Exception e) { 297 throw new ConnectionException(e); 298 } 299 } 300 301 public boolean isCanceled() { 306 302 return canceled; 307 303 } 308 304 309 305 @SuppressWarnings("unchecked") 310 private Response<GpsRec> sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException 311 { 306 private Response<GpsRec> sendCmdGetGpsRecs(int idx) throws IOException, UnsupportedCommOperationException { 312 307 byte[] src = dg100CmdGetGpsRecs; 313 308 ByteBuffer buf = ByteBuffer.wrap(src); 314 309 buf.position(5); 315 buf.putShort((short) idx); // index of first chunk of gps recs to be read310 buf.putShort((short) idx); // index of first chunk of gps recs to be read 316 311 updateCheckSum(buf); 317 312 int len = sendCmd(src, response, 2074); … … 319 314 } 320 315 321 /** 322 * 323 * @param buf 324 */ 325 private void updateCheckSum(ByteBuffer buf) 326 { 316 private void updateCheckSum(ByteBuffer buf) { 327 317 buf.position(2); 328 318 short len = buf.getShort(); 329 319 int sum = 0; 330 for (int ii = 0 ; ii < len ; ++ii){320 for (int ii = 0; ii < len; ++ii) { 331 321 sum += ByteHelper.byte2IntUnsigned(buf.get()); 332 322 } 333 323 sum = sum & 0x7FFF; 334 buf.putShort((short)sum); 335 } 336 337 private int sendCmd(byte cmdAndArgs[], byte response[], int bytesToRead) throws IOException, UnsupportedCommOperationException 338 { 324 buf.putShort((short) sum); 325 } 326 327 private int sendCmd(byte[] cmdAndArgs, byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException { 339 328 340 329 int cntBytTot = 0; … … 349 338 } 350 339 351 352 private int readResponse(byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException 353 { 340 private int readResponse(byte[] response, int bytesToRead) throws IOException, UnsupportedCommOperationException { 354 341 byte[] readBuffer = new byte[200]; 355 342 int responsePos = 0; … … 359 346 int cntBytTot = 0; 360 347 InputStream inputStream = port.getInputStream(); 361 if (inputStream != null) {348 if (inputStream != null) { 362 349 ByteBuffer buf = ByteBuffer.wrap(response); 363 350 port.enableReceiveThreshold(2); // read at least 2 byte 364 351 boolean a0A2Received = false; 365 while (! a0A2Received){352 while (!a0A2Received) { 366 353 response[0] = response[1]; 367 354 int rcvd = inputStream.read(response, 1, 1); 368 if (rcvd == 0) {355 if (rcvd == 0) { 369 356 return 0; 370 357 } 371 a0A2Received = (response[0] == (byte) 0xa0 && response[1] == (byte)0xa2);358 a0A2Received = (response[0] == (byte) 0xa0 && response[1] == (byte) 0xa2); 372 359 } 373 360 // we already have read 2 bytes … … 376 363 // read interesting data 377 364 port.enableReceiveThreshold(2); // read at least 2 bytes 378 while (bytesToRead < 0 || (bytesToRead >= 0 && cntBytTot < bytesToRead)) {365 while (bytesToRead < 0 || (bytesToRead >= 0 && cntBytTot < bytesToRead)) { 379 366 int cntBytAct = 0; 380 367 cntBytAct = inputStream.read(readBuffer); … … 382 369 // copy readBuffer to response 383 370 responsePos = ByteHelper.copyByteArr2ByteArr(readBuffer, 0, cntBytAct, response, responsePos); 384 if (!headerReceived && cntBytTot >= 4) {371 if (!headerReceived && cntBytTot >= 4) { 385 372 // do we have enough bytes to extract bytesToRead 386 if (bytesToRead == -1) {373 if (bytesToRead == -1) { 387 374 // get bytesToRead from response 388 375 buf.position(2); // here starts length of payload … … 392 379 headerReceived = true; 393 380 } 394 if (cntBytAct == 0) {381 if (cntBytAct == 0) { 395 382 break; 396 383 } -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatImportDialog.java
r30532 r32649 1 // License: GPL v2 or later. Copyright 2007 by Raphael Mack, Immanuel Scholz and others1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.plugins.globalsat; 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import gnu.io.CommPortIdentifier;6 5 7 6 import java.awt.GridBagConstraints; … … 23 22 import org.openstreetmap.josm.Main; 24 23 24 import gnu.io.CommPortIdentifier; 25 25 26 /** 26 27 * Main download dialog. 27 28 * 28 * @author Raphael Mack <ramack@raphael-mack.de>29 * @author Raphael Mack <ramack@raphael-mack.de> 29 30 * 30 31 */ … … 41 42 42 43 portCombo = new JComboBox<>(); 43 portCombo.setRenderer(new ListCellRenderer<CommPortIdentifier>(){ 44 public java.awt.Component getListCellRendererComponent(JList<? extends CommPortIdentifier> list, CommPortIdentifier o, int x, boolean a, boolean b){ 44 portCombo.setRenderer(new ListCellRenderer<CommPortIdentifier>() { 45 @Override 46 public java.awt.Component getListCellRendererComponent(JList<? extends CommPortIdentifier> list, 47 CommPortIdentifier o, int x, boolean a, boolean b) { 45 48 String value = o.getName(); 46 if (value == null){49 if (value == null) { 47 50 value = "null"; 48 51 } … … 50 53 } 51 54 }); 52 portCombo.addActionListener(new ActionListener(){ 53 public void actionPerformed(java.awt.event.ActionEvent e){ 55 portCombo.addActionListener(new ActionListener() { 56 @Override 57 public void actionPerformed(java.awt.event.ActionEvent e) { 54 58 Object i = portCombo.getSelectedItem(); 55 if (i instanceof CommPortIdentifier){56 GlobalsatPlugin.setPortIdent((CommPortIdentifier) i);57 Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier) i).getName());59 if (i instanceof CommPortIdentifier) { 60 GlobalsatPlugin.setPortIdent((CommPortIdentifier) i); 61 Main.pref.put("globalsat.portIdentifier", ((CommPortIdentifier) i).getName()); 58 62 } 59 63 } … … 61 65 62 66 refreshPorts(); 63 c.insets = new Insets(4, 4,4,4);67 c.insets = new Insets(4, 4, 4, 4); 64 68 c.gridwidth = 1; 65 69 c.weightx = 0.8; … … 76 80 77 81 refreshBtn = new JButton(tr("Refresh")); 78 refreshBtn.addActionListener(new ActionListener(){ 79 public void actionPerformed(java.awt.event.ActionEvent e){ 82 refreshBtn.addActionListener(new ActionListener() { 83 @Override 84 public void actionPerformed(java.awt.event.ActionEvent e) { 80 85 refreshPorts(); 81 86 } … … 90 95 91 96 configBtn = new JButton(tr("Configure")); 92 configBtn.addActionListener(new ActionListener(){ 93 public void actionPerformed(java.awt.event.ActionEvent e){ 97 configBtn.addActionListener(new ActionListener() { 98 @Override 99 public void actionPerformed(java.awt.event.ActionEvent e) { 94 100 System.out.println("configureing the device"); 95 try {101 try { 96 102 97 103 GlobalsatConfigDialog dialog = new GlobalsatConfigDialog(GlobalsatPlugin.dg100().getConfig()); … … 99 105 JDialog dlg = pane.createDialog(Main.parent, tr("Configure Device")); 100 106 dlg.setVisible(true); 101 if (((Integer)pane.getValue()) == JOptionPane.OK_OPTION){107 if (((Integer) pane.getValue()) == JOptionPane.OK_OPTION) { 102 108 GlobalsatPlugin.dg100().setConfig(dialog.getConfig()); 103 109 } 104 110 dlg.dispose(); 105 111 106 } catch(GlobalsatDg100.ConnectionException ex){112 } catch (GlobalsatDg100.ConnectionException ex) { 107 113 JOptionPane.showMessageDialog(Main.parent, tr("Connection Error.") + " " + ex.toString()); 108 114 } … … 129 135 } 130 136 131 public void refreshPorts() {137 public void refreshPorts() { 132 138 String sel = Main.pref.get("globalsat.portIdentifier"); 133 139 portCombo.setVisible(false); … … 135 141 136 142 Enumeration<?> e = CommPortIdentifier.getPortIdentifiers(); 137 for (e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements(); ){138 CommPortIdentifier port = (CommPortIdentifier) e.nextElement();139 if (port.getPortType() == CommPortIdentifier.PORT_SERIAL){143 for (e = CommPortIdentifier.getPortIdentifiers(); e.hasMoreElements();) { 144 CommPortIdentifier port = (CommPortIdentifier) e.nextElement(); 145 if (port.getPortType() == CommPortIdentifier.PORT_SERIAL) { 140 146 portCombo.addItem(port); 141 if (sel != null && port.getName() == sel){147 if (sel != null && port.getName() == sel) { 142 148 portCombo.setSelectedItem(port); 143 149 GlobalsatPlugin.setPortIdent(port); … … 150 156 } 151 157 152 public boolean deleteFilesAfterDownload() {158 public boolean deleteFilesAfterDownload() { 153 159 return delete.isSelected(); 154 160 } 155 161 156 public CommPortIdentifier getPort() {157 return (CommPortIdentifier) portCombo.getSelectedItem();162 public CommPortIdentifier getPort() { 163 return (CommPortIdentifier) portCombo.getSelectedItem(); 158 164 } 159 165 } -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/GlobalsatPlugin.java
r32486 r32649 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.globalsat; 2 3 /// @author Raphael Mack <ramack@raphael-mack.de> 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 import gnu.io.CommPortIdentifier;5 5 6 6 import java.awt.GraphicsEnvironment; … … 23 23 import org.xml.sax.SAXException; 24 24 25 import gnu.io.CommPortIdentifier; 26 25 27 public class GlobalsatPlugin extends Plugin { 26 28 private static GlobalsatDg100 device = null; 27 public static GlobalsatDg100 dg100() {29 public static GlobalsatDg100 dg100() { 28 30 return device; 29 31 } 30 32 31 public static void setPortIdent(CommPortIdentifier port) {32 if (device != null){33 public static void setPortIdent(CommPortIdentifier port) { 34 if (device != null) { 33 35 device.disconnect(); 34 36 } … … 41 43 private boolean deleteAfter; 42 44 43 public ImportTask(boolean delete){45 ImportTask(boolean delete) { 44 46 super(tr("Importing data from device.")); 45 47 deleteAfter = delete; … … 48 50 @Override public void realRun() throws IOException, SAXException { 49 51 progressMonitor.subTask(tr("Importing data from DG100...")); 50 try {52 try { 51 53 data = GlobalsatPlugin.dg100().readData(progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, true)); 52 } catch(Exception e){54 } catch (Exception e) { 53 55 eee = e; 54 56 } … … 56 58 57 59 @Override protected void finish() { 58 if (deleteAfter && GlobalsatPlugin.dg100().isCanceled() == false){60 if (deleteAfter && GlobalsatPlugin.dg100().isCanceled() == false) { 59 61 Main.pref.put("globalsat.deleteAfterDownload", true); 60 try {62 try { 61 63 GlobalsatPlugin.dg100().deleteData(); 62 } catch(Exception ex){64 } catch (Exception ex) { 63 65 JOptionPane.showMessageDialog(Main.parent, tr("Error deleting data.") + " " + ex.toString()); 64 66 } 65 } else{67 } else { 66 68 Main.pref.put("globalsat.deleteAfterDownload", false); 67 69 } 68 if (data != null && data.hasTrackPoints()){70 if (data != null && data.hasTrackPoints()) { 69 71 Main.getLayerManager().addLayer(new GpxLayer(data, tr("imported data from {0}", "DG 100"))); 70 72 Main.map.repaint(); 71 } else{73 } else { 72 74 JOptionPane.showMessageDialog(Main.parent, tr("No data found on device.")); 73 75 } 74 if (eee != null){76 if (eee != null) { 75 77 eee.printStackTrace(); 76 78 System.out.println(eee.getMessage()); … … 94 96 } catch (UnsatisfiedLinkError e) { 95 97 error = true; 98 // CHECKSTYLE.OFF: LineLength 96 99 String msg = tr("Cannot load library rxtxSerial. If you need support to install it try Globalsat homepage at http://www.raphael-mack.de/josm-globalsat-gpx-import-plugin/"); 100 // CHECKSTYLE.ON: LineLength 97 101 Main.error(msg); 98 102 if (!GraphicsEnvironment.isHeadless()) { 99 103 JOptionPane.showMessageDialog(Main.parent, "<html>" + msg + "</html>"); 100 104 } 101 105 } … … 106 110 } 107 111 108 class GlobalsatImportAction extends JosmAction {109 public GlobalsatImportAction(){112 class GlobalsatImportAction extends JosmAction { 113 GlobalsatImportAction() { 110 114 super(tr("Globalsat Import"), "globalsatImport", 111 115 tr("Import Data from Globalsat Datalogger DG100 into GPX layer."), … … 113 117 KeyEvent.VK_G, Shortcut.ALT_CTRL), false); 114 118 } 115 public void actionPerformed(ActionEvent e){ 119 120 @Override 121 public void actionPerformed(ActionEvent e) { 116 122 GlobalsatImportDialog dialog = new GlobalsatImportDialog(); 117 123 JOptionPane pane = new JOptionPane(dialog, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION); 118 124 JDialog dlg = pane.createDialog(Main.parent, tr("Import")); 119 125 dlg.setVisible(true); 120 if (((Integer)pane.getValue()) == JOptionPane.OK_OPTION){126 if (((Integer) pane.getValue()) == JOptionPane.OK_OPTION) { 121 127 setPortIdent(dialog.getPort()); 122 128 ImportTask task = new ImportTask(dialog.deleteFilesAfterDownload()); -
applications/editors/josm/plugins/globalsat/src/org/openstreetmap/josm/plugins/globalsat/SingleSegmentGpxTrack.java
r29222 r32649 1 // License: GPL. For details, see LICENSE file. 1 2 package org.openstreetmap.josm.plugins.globalsat; 2 3 … … 19 20 } 20 21 22 @Override 21 23 public Map<String, Object> getAttributes() { 22 24 return attr; 23 25 } 24 26 27 @Override 25 28 public Bounds getBounds() { 26 29 return trackSegment.getBounds(); 27 30 } 28 31 32 @Override 29 33 public Collection<GpxTrackSegment> getSegments() { 30 34 return Collections.singleton(trackSegment); 31 35 } 32 36 37 @Override 33 38 public double length() { 34 39 return trackSegment.length();
Note:
See TracChangeset
for help on using the changeset viewer.