Commit fd86ff04 authored by Andrey Filippov's avatar Andrey Filippov

aded gnss

parent 16940052
......@@ -32,6 +32,8 @@ import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.location.Location;
import android.location.LocationManager;
import android.util.Log;
public class SensorsUpdate implements SensorEventListener{
......@@ -121,4 +123,21 @@ public class SensorsUpdate implements SensorEventListener{
return mOrientationAngles;
}
public double [] getLocation() {
double longitude = Double.NaN;
double latitude = Double.NaN;;
try {
LocationManager lm = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
longitude = location.getLongitude();
latitude = location.getLatitude();
} catch (Exception e) {
Log.e(TAG,"Problem getting longitude/latitude");
}
double [] thisLocation = {longitude, latitude};
return thisLocation;
}
}
......@@ -95,10 +95,11 @@ public class Server {
Log.d(TAG,"Request over");
float [] orientationAngles = sensorsUpdate.getOrientation();
double [] location = sensorsUpdate.getLocation();
// Date today = new Date();
String httpResponse = "HTTP/1.1 200 OK\r\n\r\n" + // today+"\r\n"+
orientationDegreeXml(orientationAngles);
orientationDegreeXml(orientationAngles, location);
// String.format("<p>azimuth=%f</p>\r\n<p>pitch=%f</p>\r\n<p>roll=%f</p>\r\n",
// orientationAngles[0],orientationAngles[1],orientationAngles[2]);
try {
......@@ -186,24 +187,26 @@ public class Server {
}
}
}
private String orientationDegreeXml(float [] orientationAngles) {
private String orientationDegreeXml(float [] orientationAngles, double[] location) {
float [] oad = new float[orientationAngles.length];
for (int i = 0; i < oad.length; i++) {
oad[i] = orientationAngles[i]*180/ (float)Math.PI;
}
return orientationXml(oad);
return orientationXml(oad, location);
}
@SuppressLint("DefaultLocale")
private String orientationXml(float [] orientationAngles) {
private String orientationXml(float [] orientationAngles, double[] location) {
return String.format(
"<?xml version=\"1.0\"?>\r\n"+
"<orientationAngles>\r\n"+
"<azimuth>%f</azimuth>\r\n"+
"<pitch>%f</pitch>\r\n"+
"<roll>%f</roll>\r\n"+
"<longitude>%f</longitude>\r\n"+
"<latitude>%f</latitude>\r\n"+
"<date>%s</date>\r\n"+
"</orientationAngles>\r\n",
orientationAngles[0],orientationAngles[1],orientationAngles[2], new Date());
orientationAngles[0],orientationAngles[1],orientationAngles[2], location[0], location[1], new Date());
}
public int getPort() {
return PORT;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment