NMEA Java APIsA Java Parser for NMEA Streams |
Check out the project page, where you can download sources and binaries from.
Check out the javadoc.
This package provides a smooth way to read the NMEA stream from a device.
Related to:
Description |
Table of Content |
$IIMWV,273,R,24.3,N,A*10 $IIVHW,,,347,M,0.00,N,,*64 $IIVLW,1958.64,N,1958.64,N*4D $IIVPW,00.00,N,,*31 $IIVTG,,T,312,M,0.0,N,,*0C $IIVWR,088,L,24.5,N,12.6,M,,*2A $IIVWT,088,L,24.7,N,12.6,M,,*2E $IIXTE,A,A,5.36,R,N*67 $IIDBT,013.4,f,04.1,M,02.2,F*12 $IIGLL,3748.4051,N,12226.618,W,,A*1D
$IIMWV,273,R,24.3,N,A*10\r\n$IIVHW,,,347,M,0.00,N,,*64\r\n$IIVLW,1958.64,N,1958.64,N*4D\r\n$IIVPW,00.00,N,,*31\r\n $IIVTG,,T,312,M,0.0,N,,*0C\r\n$IIVWR,088,L,24.5,N,12.6,M,,*2A\r\n$IIVWT,088,L,24.7,N,12.6,M,,*2E\r\n$IIXTE,A,A,5.3 6,R,N*67\r\n$IIDBT,013.4,f,04.1,M,02.2,F*12\r\n$IIGLL,3748.4051,N,12226.618,W,,A*1D\r\n$IIHDM,348,M*33\r\n$IIMTA,3 9.4,C*0B\r\n$IIMTW,016,C*3A\r\n$IIMWD,,T,258,M,24.6,N,12.6,M*7E\r\n$IIMWV,272,R,24.6,N,A*14\r\n$IIVHW,,,348,M,0.00 ,N,,*6B\r\n$IIVLW,1958.64,N,1958.64,N*4D\r\n$IIVPW,00.00,N,,*31\r\n$IIVTG,,T,315,M,0.0,N,,*0B\r\n$IIVWR,091,L,24.9 ,N,12.8,M,,*20\r\n$IIVWT,090,L,24.6,N,12.6,M,,*26\r\n$IIXTE,A,A,5.36,R,N*67\r\n$IIDBT,013.2,f,04.0,M,02.2,F*15\r\n $IIGLL,3748.4052,N,12226.618,W,,A*1E\r\n$IIHDM,348,M*33\r\n$IIMTA,17.9,C*0A\r\n$IIMTW,016,C*3A\r\n$IIMWD,,T,254,M, 26.4,N,13.5,M*70\r\n$IIMWV,267,R,26.0,N,A*14\r\n$IIVHW,,,348,M,0.00,N,,*6B\r\n$IIVLW,1958.64,N,1958.64,N*4D\r\n$II VPW,00.00,N,,*31\r\n$IIVTG,,T,295,M,0.0,N,,*02\r\n$IIVWR,093,L,26.5,N,13.6,M,,*23\r\n$IIVWT,094,L,26.7,N,13.7,M,,* 21\r\n$IIXTE,A,A,5.36,R,N*67\r\n$IIDBT,013.3,f,04.0,M,02.2,F*14\r\n$IIGLL,3748.4051,N,12226.618,W,,A*1D\r\n$IIHDM, 348,M*33\r\n$IIMTA,3.6,C*30\r\n$IIMTW,016,C*3A\r\n$IIMWD,,T,250,M,27.0,N,13.8,M*7C\r\n$IIMWV,265,R,26.4,N,A*12\r\n ...
Architecture |
Table of Content |
Examples |
Table of Content |
package ui.sampleclient; import ocss.nmea.api.NMEAReader; import ocss.nmea.api.NMEAEvent; import java.util.ArrayList; import java.io.FileInputStream; /** * A Simulator, taking its inputs from a file */ public class CustomReader extends NMEAReader // Notice the extended class { public CustomReader(ArrayList al) { super(al); } public void read() // The read() method must be overwritten { // Simulation super.enableReading(); // Then, canRead() will return true String fileName = "hydra2.nmea"; try { FileInputStream fis = new FileInputStream(fileName); while (canRead()) // canRead() is a method of the super class { double size = Math.random(); int dim = (int)(750 * size); byte[] ba = new byte[dim]; int l = fis.read(ba); if (l != -1 && dim > 0) { fireDataRead(new NMEAEvent(this, new String(ba))); // Broadcast the event try { Thread.sleep(500); } catch (Exception ignore) {} } else { System.out.println("===== Reseting Reader ====="); fis.close(); fis = new FileInputStream(fileName); } } } catch (Exception e) { e.printStackTrace(); } } }
package ui.sampleclient; import ocss.nmea.api.NMEAReader; import ocss.nmea.api.NMEAEvent; import java.util.ArrayList; import javax.comm.*; import java.util.*; import java.io.*; public class CustomSerialClient extends NMEAReader // Notice the extended class { public CustomSerialClient(ArrayList al) { super(al); } public void read() { super.enableReading(); // Opening Serial port COM1 CommPortIdentifier com = null; try { com = CommPortIdentifier.getPortIdentifier("COM1"); } catch (NoSuchPortException nspe) { System.err.println("No Such Port"); return; } CommPort thePort = null; try { thePort = com.open("PortOpener", 10); } catch (PortInUseException piue) { System.err.println("Port In Use"); return; } int portType = com.getPortType(); if (portType == com.PORT_PARALLEL) System.out.println("This is a parallel port"); else if (portType == com.PORT_SERIAL) System.out.println("This is a serial port"); else System.out.println("This is an unknown port:" + portType); if (portType == com.PORT_SERIAL) { SerialPort sp = (SerialPort)thePort; try { // Settings for B&G Hydra sp.setSerialPortParams(4800, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); } catch (UnsupportedCommOperationException ucoe) { System.err.println("Unsupported Comm Operation"); return; } } // Reading on Serial Port try { byte[] buffer = new byte[4096]; InputStream theInput = thePort.getInputStream(); System.out.println("Reading serial port..."); while (canRead()) // Loop { int bytesRead = theInput.read(buffer); if (bytesRead == -1) break; System.out.println("Read " + bytesRead + " characters"); // Count up to the first not null int nn = bytesRead; for (int i=0; i<Math.min(buffer.length, bytesRead); i++) { if (buffer[i] == 0) { nn = i; break; } } byte[] toPrint = new byte[nn]; for (int i=0; i<nn; i++) toPrint[i] = buffer[i]; // Broadcast event super.fireDataRead(new NMEAEvent(this, new String(toPrint))); // Broadcast the event } System.out.println("Stop Reading serial port."); } catch (Exception e) { e.printStackTrace(); } } }
package ui.sampleclient; import ocss.nmea.api.NMEAClient; import ocss.nmea.api.NMEAEvent; /** * The simplest you can write */ public class CustomClient extends NMEAClient { public CustomClient(String s, String[] sa) { super(s, sa); } public void dataDetectedEvent(NMEAEvent e) { System.out.println("Received:" + e.getContent()); } public static void main(String[] args) { String prefix = "II"; String[] array = {"HDM", "GLL", "XTE", "MWV", "VHW"}; CustomClient customClient = new CustomClient(prefix, array); customClient.initClient(); customClient.setReader(new CustomReader(customClient.getListeners())); // Simulator // customClient.setReader(new CustomSerialClient(customClient.getListeners())); // Serial Port reader customClient.startWorking(); } }