So, my co-worked Adam Flater started up the Merapi Project a while back and asked me to contribute. Up until now, the only thing I've had time to contribute was the name. Well, after seeing the cool stuff that he and Jordan were doing at 360|Flex, I decided it was time to step up to the plate, get my shit together, and produce my own kick-ass Merapi demo.
Anyone who has been following the blogs knows that we at UM are real big into GIS and data visualization. Don't believe me? Take a look at SpatialKey to see what we can do with it.
I recorded a screencast where I walk you through the setups and the code of the application:
Java Code:
package com.universalmind.merapi;
import gnu.io.CommPort;
import gnu.io.CommPortIdentifier;
import gnu.io.NoSuchPortException;
import gnu.io.PortInUseException;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.IOException;
import com.diddlebits.gpslib4j.GPS;
import com.diddlebits.gpslib4j.IDate;
import com.diddlebits.gpslib4j.IGPSlistener;
import com.diddlebits.gpslib4j.IPosition;
import com.diddlebits.gpslib4j.ITime;
import com.diddlebits.gpslib4j.Position;
import com.diddlebits.gpslib4j.PositionRadians;
import com.diddlebits.gpslib4j.Garmin.GarminGPS;
import merapi.Bridge;
import merapi.MerapiObject;
import merapi.messages.Message;
public class GPSReader extends MerapiObject implements IGPSlistener{
GPS gps;
Position position = null;
IPosition current = null;
BufferedInputStream input;
BufferedOutputStream output;
public Bridge bridge;
public static void main( String[] args )
{
new GPSReader();
}
public GPSReader()
{
super();
bridge = Bridge.getInstance();
CommPort port;
try {
port = CommPortIdentifier.getPortIdentifier("/dev/tty.USA19H1d1P1.1").open("GPSReader", 3000);
} catch (NoSuchPortException e) {
System.out.println("/dev/tty.USA19H1d1P1.1 not found!");
return;
} catch (PortInUseException e) {
System.out.println("Port already in use by " + e.currentOwner);
return;
}
try {
input = new BufferedInputStream(port.getInputStream());
output = new BufferedOutputStream(port.getOutputStream());
} catch (IOException e) {
System.out.println("Error opening /dev/tty.USA19H1d1P1.1");
return;
}
gps = new GarminGPS(input, output);
gps.setAutoTransmit(true);
gps.addGPSlistener(this);
}
public double getLat() {return __lat;}
public void setLat(double lat) {
this.__lat = lat;
}
public double getLon() {return __lon;}
public void setLon(double lon) {
this.__lon = lon;
}
public String getTime() {return __time;}
public void setTime(String time) {
this.__time = time;
}
public String getDate() {return __date;}
public void setDate(String date) {
this.__date = date;
}
public void dateReceived(IDate d) {
String dateString = d.getMonth() + "/" + d.getDay() + "/" + d.getYear();
System.out.println(dateString);
this.setDate(dateString);
}
public void positionReceived(IPosition pos) {
current = pos;
this.setLat(toDecimalDegrees(current.getLatitude()));
this.setLon(toDecimalDegrees(current.getLongitude()));
Message message = new Message();
GPSPoint point = new GPSPoint();
point.lat = this.getLat();
point.lon = this.getLon();
point.date = this.getDate();
point.time = this.getTime();
message.setData(point);
try {
bridge.sendMessage(message);
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
public void timeReceived(ITime t) {
String timeString = t.getHours() + ":" + t.getMinutes() + ":" + t.getSeconds();
this.setTime(timeString);
System.out.println(timeString);
}
private double toDecimalDegrees(PositionRadians rads){
return Math.toDegrees(rads.getRadians());
}
private double __lat = 0;
private double __lon = 0;
private String __time = "";
private String __date = "";
}























8 responses so far ↓
1 Jeff Bouley // Aug 23, 2008 at 11:31 AM
2 Tom Link // Aug 23, 2008 at 3:08 PM
3 Devo // Aug 26, 2008 at 11:13 PM
4 Andrew Powell // Sep 5, 2008 at 8:54 AM
5 Andrew Trice // Sep 14, 2008 at 1:31 PM
6 Ranadheer Singh // Feb 7, 2009 at 7:58 AM
7 Andrew Powell // Feb 8, 2009 at 7:02 PM
8 John Gag // Oct 27, 2009 at 8:55 PM
Leave a Comment