Commit b11f8ea1 authored by Andrey Filippov's avatar Andrey Filippov

bug fix, added raw accelerometers+,magnetometers

parent c347b0fb
/*
**
** SensorsUpdate.java - Update sesnors data to be served through embedded HTTP server
** SensorsUpdate.java - Update sensors data to be served through embedded HTTP server
**
** Copyright (C) 2019 Elphel, Inc.
**
......@@ -26,6 +26,8 @@
package com.elphel.sensorserver;
import java.util.Calendar;
import android.app.Activity;
import android.content.Context;
import android.hardware.Sensor;
......@@ -101,6 +103,13 @@ public class SensorsUpdate implements SensorEventListener{
Log.i(TAG,"magneticField is NOT null");
} else {
Log.e(TAG,"magneticField is null");
}
Log.e(TAG,"Setting location manager");
LocationManager locationManager = (LocationManager) activity.getSystemService(Context.LOCATION_SERVICE);
if (locationManager != null) {
Log.d(TAG, "Requesting GPS Updates");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
Log.d(TAG, "Requested GPS Updates");
}
Log.e(TAG,"resume() done");
}
......@@ -132,12 +141,28 @@ public class SensorsUpdate implements SensorEventListener{
// "mOrientationAngles" now has up-to-date information.
}
public long getTimeStamp() {
Calendar rightNow = Calendar.getInstance();
long offset = rightNow.get(Calendar.ZONE_OFFSET) +
rightNow.get(Calendar.DST_OFFSET);
return rightNow.getTimeInMillis() + offset;
}
public float [] getOrientation() {
updateOrientationAngles(); // todo: synchronize
return mOrientationAngles;
}
public float [] getAccelerometerReading() {
updateOrientationAngles(); // todo: synchronize
return accelerometerReading;
}
public float [] getMagnetometerReading() {
updateOrientationAngles(); // todo: synchronize
return magnetometerReading;
}
public double [] getLocation() {
// double longitude = Double.NaN;
// double latitude = Double.NaN;;
......@@ -147,13 +172,17 @@ public class SensorsUpdate implements SensorEventListener{
boolean isGPSEnabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
Log.i(TAG,"Got LocationManager: "+lm.toString()+", isGPSEnabled = "+isGPSEnabled);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
/*
if (isGPSEnabled && (location == null)) {
Log.d(TAG, "Requested GPS Updates");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
}
*/
Log.i(TAG,"Got Location: "+location);
if (location != null) {
longitude = location.getLongitude();
latitude = location.getLatitude();
}
} catch (Exception e) {
Log.e(TAG,"Problem getting longitude/latitude: "+e.toString());
}
......
......@@ -97,9 +97,14 @@ public class Server {
float [] orientationAngles = sensorsUpdate.getOrientation();
double [] location = sensorsUpdate.getLocation();
float [] accelerometerReading = sensorsUpdate.getAccelerometerReading();
float [] magnetometerReading = sensorsUpdate.getMagnetometerReading();
long timestamp = sensorsUpdate.getTimeStamp();
// Date today = new Date();
String httpResponse = "HTTP/1.1 200 OK\r\n\r\n" + // today+"\r\n"+
orientationDegreeXml(orientationAngles, location);
orientationDegreeXml(timestamp, accelerometerReading, magnetometerReading, 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 {
......@@ -194,20 +199,49 @@ public class Server {
}
return orientationXml(oad, location);
}
private String orientationDegreeXml(long timestamp, float [] accelerometerReading, float [] magnetometerReading, 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(timestamp, accelerometerReading, magnetometerReading, oad, location);
}
@SuppressLint("DefaultLocale")
private String orientationXml(float [] orientationAngles, double[] location) {
return String.format(
"<?xml version=\"1.0\"?>\r\n"+
"<orientationAngles>\r\n"+
"<sensors>"+
"<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"+
"</sensors>",
orientationAngles[0],orientationAngles[1],orientationAngles[2], location[0], location[1], new Date());
}
@SuppressLint("DefaultLocale")
private String orientationXml(long timestamp, float [] accelerometerReading, float [] magnetometerReading, float [] orientationAngles, double[] location) {
return String.format(
"<?xml version=\"1.0\"?>\r\n"+
"<sensors>"+
"<timestmap>%d</timestmap>\r\n"+
"<accelerometer>%f, %f, %f</accelerometer>\r\n"+
"<magnetometer>%f, %f, %f</magnetometer>\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",
"</sensors>",
timestamp,
accelerometerReading[0], accelerometerReading[1], accelerometerReading[2],
magnetometerReading[0], magnetometerReading[1], magnetometerReading[2],
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