package com.dcu.project.server;
import com.dcu.project.model.NMEAData;
import com.dcu.project.server.Tokenizer;
public class Manager {
public NMEAData ParseData(String Data)
{
NMEAData gpsData = new NMEAData();
Tokenizer tokenizer = new Tokenizer(Data);
String token = tokenizer.next();
while(token.endsWith("$GPRMC") == false){
token = tokenizer.next();
}
if (token.endsWith("$GPRMC")) {
// Time of fix
String theTime = tokenizer.next();
String Hour = theTime.substring(0, 2);
String Minutes = theTime.substring(2, 4);
String Seconds = theTime.substring(4, 6);
String newTime = (Hour+ ":" + Minutes +":" +Seconds+" UTC");
// Latitude
String Status = tokenizer.next();
String raw_lat = tokenizer.next();
String lat_deg = raw_lat.substring(0, 2);
String lat_min1 = raw_lat.substring(2, 4);
String lat_min2 = raw_lat.substring(5);
String lat_min3 = "0." + lat_min1 + lat_min2;
double lat_dec = Float.parseFloat(lat_min3)/.6f;
double lat_val = Float.parseFloat(lat_deg) + lat_dec;
// Latitude direction
String lat_direction = tokenizer.next();
if (lat_direction == "S"){
lat_val = (lat_val * -1);
}
// Longitude
String raw_lon = tokenizer.next();
String lon_deg = raw_lon.substring(0, 3);
String lon_min1 = raw_lon.substring(3, 5);
String lon_min2 = raw_lon.substring(6);
String lon_min3 = "0." + lon_min1 + lon_min2;
double lon_dec = Float.parseFloat(lon_min3)/.6f;
double lon_val = Float.parseFloat(lon_deg) + lon_dec;
// Longitude direction
String lon_direction = tokenizer.next();
if (lon_direction == "W")
{
lon_val = (lon_val * -1);
}
//Speed
String speedknots = tokenizer.next();
double speed_knots = Float.parseFloat(speedknots);
double speedmpers = (speed_knots * 0.51);
//Course
String course = tokenizer.next();
//Date
String theDate = tokenizer.next();
String day = theDate.substring(0, 2);
String month = theDate.substring(2, 4);
String year = theDate.substring(4, 6);
String newDate = (day+"-"+month+"-"+year);
gpsData.setTime(newTime);
gpsData.setDate(newDate);
gpsData.setLat(lat_val);
gpsData.setLongitude(lon_val);
gpsData.setSpeed(speedmpers);
gpsData.setCourse(course);
}
return gpsData;
}
}
|