Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sensor_server
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Elphel
sensor_server
Commits
b11f8ea1
Commit
b11f8ea1
authored
Oct 09, 2019
by
Andrey Filippov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bug fix, added raw accelerometers+,magnetometers
parent
c347b0fb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
6 deletions
+69
-6
SensorsUpdate.java
src/com/elphel/sensorserver/SensorsUpdate.java
+32
-3
Server.java
src/com/elphel/sensorserver/Server.java
+37
-3
No files found.
src/com/elphel/sensorserver/SensorsUpdate.java
View file @
b11f8ea1
/*
/*
**
**
** SensorsUpdate.java - Update se
sn
ors data to be served through embedded HTTP server
** SensorsUpdate.java - Update se
ns
ors data to be served through embedded HTTP server
**
**
** Copyright (C) 2019 Elphel, Inc.
** Copyright (C) 2019 Elphel, Inc.
**
**
...
@@ -26,6 +26,8 @@
...
@@ -26,6 +26,8 @@
package
com
.
elphel
.
sensorserver
;
package
com
.
elphel
.
sensorserver
;
import
java.util.Calendar
;
import
android.app.Activity
;
import
android.app.Activity
;
import
android.content.Context
;
import
android.content.Context
;
import
android.hardware.Sensor
;
import
android.hardware.Sensor
;
...
@@ -101,6 +103,13 @@ public class SensorsUpdate implements SensorEventListener{
...
@@ -101,6 +103,13 @@ public class SensorsUpdate implements SensorEventListener{
Log
.
i
(
TAG
,
"magneticField is NOT null"
);
Log
.
i
(
TAG
,
"magneticField is NOT null"
);
}
else
{
}
else
{
Log
.
e
(
TAG
,
"magneticField is null"
);
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"
);
Log
.
e
(
TAG
,
"resume() done"
);
}
}
...
@@ -132,12 +141,28 @@ public class SensorsUpdate implements SensorEventListener{
...
@@ -132,12 +141,28 @@ public class SensorsUpdate implements SensorEventListener{
// "mOrientationAngles" now has up-to-date information.
// "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
()
{
public
float
[]
getOrientation
()
{
updateOrientationAngles
();
// todo: synchronize
updateOrientationAngles
();
// todo: synchronize
return
mOrientationAngles
;
return
mOrientationAngles
;
}
}
public
float
[]
getAccelerometerReading
()
{
updateOrientationAngles
();
// todo: synchronize
return
accelerometerReading
;
}
public
float
[]
getMagnetometerReading
()
{
updateOrientationAngles
();
// todo: synchronize
return
magnetometerReading
;
}
public
double
[]
getLocation
()
{
public
double
[]
getLocation
()
{
// double longitude = Double.NaN;
// double longitude = Double.NaN;
// double latitude = Double.NaN;;
// double latitude = Double.NaN;;
...
@@ -147,13 +172,17 @@ public class SensorsUpdate implements SensorEventListener{
...
@@ -147,13 +172,17 @@ public class SensorsUpdate implements SensorEventListener{
boolean
isGPSEnabled
=
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
boolean
isGPSEnabled
=
lm
.
isProviderEnabled
(
LocationManager
.
GPS_PROVIDER
);
Log
.
i
(
TAG
,
"Got LocationManager: "
+
lm
.
toString
()+
", isGPSEnabled = "
+
isGPSEnabled
);
Log
.
i
(
TAG
,
"Got LocationManager: "
+
lm
.
toString
()+
", isGPSEnabled = "
+
isGPSEnabled
);
Location
location
=
lm
.
getLastKnownLocation
(
LocationManager
.
GPS_PROVIDER
);
Location
location
=
lm
.
getLastKnownLocation
(
LocationManager
.
GPS_PROVIDER
);
/*
if (isGPSEnabled && (location == null)) {
if (isGPSEnabled && (location == null)) {
Log.d(TAG, "Requested GPS Updates");
Log.d(TAG, "Requested GPS Updates");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, locationListener);
}
}
*/
Log
.
i
(
TAG
,
"Got Location: "
+
location
);
Log
.
i
(
TAG
,
"Got Location: "
+
location
);
if
(
location
!=
null
)
{
longitude
=
location
.
getLongitude
();
longitude
=
location
.
getLongitude
();
latitude
=
location
.
getLatitude
();
latitude
=
location
.
getLatitude
();
}
}
catch
(
Exception
e
)
{
}
catch
(
Exception
e
)
{
Log
.
e
(
TAG
,
"Problem getting longitude/latitude: "
+
e
.
toString
());
Log
.
e
(
TAG
,
"Problem getting longitude/latitude: "
+
e
.
toString
());
}
}
...
...
src/com/elphel/sensorserver/Server.java
View file @
b11f8ea1
...
@@ -97,9 +97,14 @@ public class Server {
...
@@ -97,9 +97,14 @@ public class Server {
float
[]
orientationAngles
=
sensorsUpdate
.
getOrientation
();
float
[]
orientationAngles
=
sensorsUpdate
.
getOrientation
();
double
[]
location
=
sensorsUpdate
.
getLocation
();
double
[]
location
=
sensorsUpdate
.
getLocation
();
float
[]
accelerometerReading
=
sensorsUpdate
.
getAccelerometerReading
();
float
[]
magnetometerReading
=
sensorsUpdate
.
getMagnetometerReading
();
long
timestamp
=
sensorsUpdate
.
getTimeStamp
();
// Date today = new Date();
// Date today = new Date();
String
httpResponse
=
"HTTP/1.1 200 OK\r\n\r\n"
+
// today+"\r\n"+
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",
// 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]);
// orientationAngles[0],orientationAngles[1],orientationAngles[2]);
try
{
try
{
...
@@ -194,20 +199,49 @@ public class Server {
...
@@ -194,20 +199,49 @@ public class Server {
}
}
return
orientationXml
(
oad
,
location
);
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"
)
@SuppressLint
(
"DefaultLocale"
)
private
String
orientationXml
(
float
[]
orientationAngles
,
double
[]
location
)
{
private
String
orientationXml
(
float
[]
orientationAngles
,
double
[]
location
)
{
return
String
.
format
(
return
String
.
format
(
"<?xml version=\"1.0\"?>\r\n"
+
"<?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"
+
"<azimuth>%f</azimuth>\r\n"
+
"<pitch>%f</pitch>\r\n"
+
"<pitch>%f</pitch>\r\n"
+
"<roll>%f</roll>\r\n"
+
"<roll>%f</roll>\r\n"
+
"<longitude>%f</longitude>\r\n"
+
"<longitude>%f</longitude>\r\n"
+
"<latitude>%f</latitude>\r\n"
+
"<latitude>%f</latitude>\r\n"
+
"<date>%s</date>\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
());
orientationAngles
[
0
],
orientationAngles
[
1
],
orientationAngles
[
2
],
location
[
0
],
location
[
1
],
new
Date
());
}
}
public
int
getPort
()
{
public
int
getPort
()
{
return
PORT
;
return
PORT
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment