com.partnersoft.gps.nmea
Class NmeaParser

java.lang.Object
  extended by com.partnersoft.gps.nmea.NmeaParser

public class NmeaParser
extends java.lang.Object

This handles generic Nmea sentence parsing for NmeaGps and LaserRangefinder. Both classes read messages exactly the same way and have the same configuration, but they both uses totally separate messages. It has a reader thread. All the methods are thread-safe, and the reader thread never blocks when it reads from the serial port. To use this class, add a NmeaParserListener to handle the sentences. Be aware of potential race conditions between the Swing event thread and the NmeaParser's reader thread. All of the listener methods run from the reader thread.

Author:
Russell Cagle Copyright 2007 Partner Software, Inc.

Constructor Summary
NmeaParser()
           
 
Method Summary
 void addNmeaParserListener(NmeaParserListener l)
           Usually called from the GUI thread.
 void close()
           Close() waits for the NMEA thread to stop before it closes the port, so the NMEA thread can depend on the port being open while it's running.
 int getBaudRate()
           
 javax.swing.JPanel getConfigutron()
           
 java.lang.String getPortName()
           
 boolean isOpen()
           
 void open()
           Notes about thread safety: when open() is called, it stops the NMEA thread if it is still running by calling close().
static java.lang.String[] parseFields(java.lang.String s)
          Handles the asterisk at the end.
 void removeNmeaParserListener(NmeaParserListener l)
           Usually called from the GUI thread.
 void setPortName(java.lang.String portName)
           Calls open() and close(), which do not contend with any threads.
 void setSerialPortParams(int baudRate, int dataBits, int stopBits, int parity)
           Contends with readLine(), which is called from the NMEA thread.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NmeaParser

public NmeaParser()
Method Detail

parseFields

public static java.lang.String[] parseFields(java.lang.String s)
Handles the asterisk at the end.

Parameters:
s -
Returns:

addNmeaParserListener

public void addNmeaParserListener(NmeaParserListener l)

Usually called from the GUI thread. Contends with event dispatching, which iterates over the list, called from the NMEA thread.

Parameters:
l -

close

public void close()
           throws java.io.IOException

Close() waits for the NMEA thread to stop before it closes the port, so the NMEA thread can depend on the port being open while it's running.

Open() and close() are not thread-safe in general, just with respect to the NMEA thread. Both functions should be called from the same thread, usually the GUI.

Throws:
java.io.IOException

isOpen

public boolean isOpen()

open

public void open()
          throws java.io.IOException

Notes about thread safety: when open() is called, it stops the NMEA thread if it is still running by calling close(). It starts the NMEA thread after setting all the parameters, so there is no chance of the thread reading an incomplete state.

Open() and close() are not thread-safe in general, just with respect to the NMEA thread. Both functions should be called from the same thread, usually the GUI.

Throws:
java.io.IOException

removeNmeaParserListener

public void removeNmeaParserListener(NmeaParserListener l)

Usually called from the GUI thread. Contends with event dispatching, which iterates over the list, called from the NMEA thread.

Parameters:
l -

setPortName

public void setPortName(java.lang.String portName)
                 throws java.io.IOException

Calls open() and close(), which do not contend with any threads.

Parameters:
portName -
Throws:
java.io.IOException

setSerialPortParams

public void setSerialPortParams(int baudRate,
                                int dataBits,
                                int stopBits,
                                int parity)
                         throws java.io.IOException

Contends with readLine(), which is called from the NMEA thread.

Parameters:
baudRate -
dataBits -
stopBits -
parity -
Throws:
java.io.IOException

getBaudRate

public int getBaudRate()

getPortName

public java.lang.String getPortName()

getConfigutron

public javax.swing.JPanel getConfigutron()