-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGPSLocations.java
More file actions
131 lines (96 loc) · 3.47 KB
/
GPSLocations.java
File metadata and controls
131 lines (96 loc) · 3.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import java.time.LocalTime;
import java.util.List;
import javax.swing.table.DefaultTableModel;
import org.json.JSONObject;
/*
GPSLocations class takes in vehicle ID, GPS location string, and is supposed to be able to edit vehicle list..
It can perform all conversions as requested, 24hr time not yet tested.
*/
public class GPSLocations {
String locstring;
String ident;
String status;
float latitude;
float longitude;
float speed;
float heading;
String datetime;
String gpsColNames[] = {"ID", "A/V","Time","Lat","Lon","Speed","Heading"};
DefaultTableModel dtm = new DefaultTableModel(gpsColNames, 0);
Object [] rowData = new Object[8];
List<Object> list;
GPSLocations(String vehID, String GPSloc, List<Object> list) {
ident = vehID;
locstring = GPSloc;
this.list = list;
}
// public JSONObject splitter(){
public List<Object> splitter(){
String[] values = locstring.split(","); //puts values of GPS location into an array
getStatus(values); //reads status of vehicle
lat2dec(values); //converts latitude to dec
long2dec(values); //convert longitude to dec
toMPH(values); //converts knots to mph
to24hr(); //converts current reading time to 24 HR format
rowData[0] = ident;
rowData[1] = status;
rowData[3] = datetime;
rowData[4] = latitude;
rowData[5] = longitude;
rowData[6] = speed;
rowData[7] = heading;
// THIS RETURNS FINAL JSON MESSAGE TO SEND BACK AS RESPONSE !!!!!!! why wont it work
list.add(dtm);
return list;
// return rowData;
}
public void getStatus(String[] values){
String AV = values[2];
status = AV;
}
public void getHeading(String[] values){
float direction = Float.parseFloat(values[8]);
heading = direction; //updates heading to float
}
public float lat2dec(String[] values){
String lat = values[3];
String NS = values[4];
float med = Float.parseFloat(lat.substring(2))/60.0f;
med -= Float.parseFloat(lat.substring(0, 2));
if(NS.startsWith("S")) {
med = -med;
}
latitude = med; //update latitude
return med;
}
public float long2dec(String[] values) {
String lon = values[5];
String WE = values[6];
float med = Float.parseFloat(lon.substring(3))/60.0f;
med -= Float.parseFloat(lon.substring(0, 3));
if(WE.startsWith("W")) {
med = -med;
}
longitude = med; //update longitude
return med;
}
public float toMPH(String[] values){
float a = (float) 1.152; //1 knot is 1.152 mph
float b = Float.parseFloat(values[7]); //the amount of knots in data received
float mph = a*b;
speed = mph; //update speed to mph
return mph;
}
public String to24hr(){
LocalTime t = LocalTime.now();
// DateTimeFormatter tf = DateTimeFormatter.ofPattern("m/d/y");
// datetime = t.format(tf); //24HR m/d/y format of current date and time
datetime = "idk why this wont work";
return datetime;
}
/* public JSONObject sendBack(DefaultTableModel dtm){
JSONObject json1 = new JSONObject(dtm);
return json1;
}
*/
}