A Technology Blog About Code Development, Architecture, Operating System, Hardware, Tips and Tutorials for Developers.

Saturday, November 6, 2010

GPS with JGPS - Setup Testing

3:12:00 PM Posted by Satish , , No comments
I am playing around the GPS module since quite some time and got a new JGPS java api to interact with. I have a serial out put GPS module. Check out my GPS setup. This particular API has got a very good interface for USB, Serial and bluetooth GPS devides.This has native API for both Unix and windows platform. In unix plat form this supports both linux and solaris. This API has got a very meaning full instruction to setup in unix environment. As I have my java comm API already setup to windows and I have the USB - Serial driver for windows, I tested in windows rather than ubuntu.

This api works on the top of java comm api. I was controlling my GSM/ GPRS modem through  the IO channels using java comm api. In the older versions of jGPS, the io interaction to the GPS module was through Java comm api and the jGPS was only the formatter. But this new release integrated the Java comm api with it again with some additional interface like bluetooth.

So general architecture is as follows.

GPS Module - Serial/ USB/ Bluetooth Interface - Java Comm API (JAVA+Native API[OS specific]) - jGPS API (JAVA)

Following is a simple program to register to one of the event and get notified for the lat/lng.

Source


package org.satish.practice;



import com.uf.gps.Descriptor;
import com.uf.gps.GPSListener; 
import com.uf.gps.GPSEvent; 
import com.uf.gps.Position;
import com.uf.gps.protocols.NMEA.NMEAHandler; 
import com.uf.gps.Connection; 
import com.uf.gps.ConnectException; 
import javax.comm.SerialPort;

public class myApp implements GPSListener { 
public myApp () { 

NMEAHandler nh = null; 
/* Initialize a connection handler on the RS232 interface */ 
try { 
nh = new NMEAHandler(1,"myApp","COM6",9600, SerialPort.DATABITS_8, SerialPort.STOPBITS_1, SerialPort.PARITY_NONE); 
} catch (ConnectException x) { 
// Something is going wrong

/* Enable reception of GPSEvents */ 
nh.registerListener( this ); 
}

public static void main(String[] args) throws ConnectException { 
myApp my = new myApp(); 
}

public void actionPerformed(GPSEvent ev) { 
Position p = null; 
/*
* public GPSEvent (Connection src, int transactiontype, int datatype, Object
* data)
*/ 
/* src: connection handler, maybe there's more than one defined */
/* transactiontype: is one of BEGIN_TRANS, END_TRANS, _TRANS */ 
/* datatype: one of the _CLASS constants, which classifies a data type */ 
/* data: the GPSObject */ 

if (ev.getTransType() == GPSEvent.POS_TRANS) { 
p = (Position) ev.getData(); 

/* Every high level class has lots of properties */
Descriptor wa = p.getProperty("LONGITUDE"); 
Descriptor wb = p.getProperty("LATITUDE"); 

/* wa.getValue of class Double */ 
String lon = wa == null ? "" : (String) wa.getValue().toString(); 

/* wb.getValue of class Double */ 
String lat = wb == null ? "" : (String) wb.getValue().toString(); System.out.println( "Latitude/Longitude = [" + lat + "][" + lon + "]" ); 
} else if (ev.getTransType() == GPSEvent.WPT_TRANS) { 
// .................................................. 
}
}
}


Output

Latitude/Longitude = [12.957963999999999][77.67056266666667]

Latitude/Longitude = [12.957963999999999][77.67056266666667]
Latitude/Longitude = [12.957967][77.67056366666667]
Latitude/Longitude = [12.957967][77.67056366666667]
Latitude/Longitude = [12.957972][77.67056166666667]
Latitude/Longitude = [12.957972][77.67056166666667]
Latitude/Longitude = [12.95797][77.67056366666667]
Latitude/Longitude = [12.95797][77.67056366666667]
Latitude/Longitude = [12.957965][77.67056366666667]
Latitude/Longitude = [12.957965][77.67056366666667]
Latitude/Longitude = [12.957963][77.67056366666667]
Latitude/Longitude = [12.957963][77.67056366666667]
Latitude/Longitude = [12.957961999999998][77.67056466666668]
Latitude/Longitude = [12.957961999999998][77.67056466666668]
Latitude/Longitude = [12.957961999999998][77.67056466666668]
Latitude/Longitude = [12.957961999999998][77.67056466666668]
Latitude/Longitude = [12.95796][77.67056666666667]
Latitude/Longitude = [12.95796][77.67056666666667]
Latitude/Longitude = [12.957958999999999][77.67056866666667]
Latitude/Longitude = [12.957958999999999][77.67056866666667]
Latitude/Longitude = [12.957958999999999][77.67056966666667]
Latitude/Longitude = [12.957958999999999][77.67056966666667]
Latitude/Longitude = [12.957961999999998][77.67057066666668]
Latitude/Longitude = [12.957961999999998][77.67057066666668]
Latitude/Longitude = [12.957958999999999][77.67057266666667]
Latitude/Longitude = [12.957958999999999][77.67057266666667]


I will still be playing around the API and keep posting too.

0 comments:

Post a Comment