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
Hide 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.
**
...
...
@@ -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
);
longitude
=
location
.
getLongitude
();
latitude
=
location
.
getLatitude
();
if
(
location
!=
null
)
{
longitude
=
location
.
getLongitude
();
latitude
=
location
.
getLatitude
();
}
}
catch
(
Exception
e
)
{
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 {
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
;
}
...
...
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