Skip to content

Commit ffcffec

Browse files
authored
Merge pull request #20 from scottlandis/master
Added some real-time GNSS tools
2 parents 3156b01 + f88dc5a commit ffcffec

47 files changed

Lines changed: 2086 additions & 140 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

torgi/build.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "org.sofwerx.torgi"
77
minSdkVersion 24
88
targetSdkVersion 27
9-
versionCode 3
10-
versionName "0.4"
9+
versionCode 4
10+
versionName "1.0"
1111
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
1212
externalNativeBuild {
1313
cmake {
@@ -50,8 +50,10 @@ dependencies {
5050
//implementation fileTree(include: ['*.jar'], dir: 'libs')
5151
//implementation project(':geopackage-sdk')
5252

53+
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
5354
viewerImplementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' //for charts
5455
viewerImplementation 'org.osmdroid:osmdroid-android:6.0.2'
56+
implementation 'org.apache.commons:commons-math3:3.0' //for statistical analysis
5557
implementation 'mil.nga.geopackage:geopackage-android:3.0.2'
5658
implementation 'com.android.support:appcompat-v7:27.1.1'
5759
viewerImplementation 'com.android.support.constraint:constraint-layout:1.1.3'
@@ -60,4 +62,4 @@ dependencies {
6062
testImplementation 'junit:junit:4.12'
6163
androidTestImplementation 'com.android.support.test:runner:1.0.2'
6264
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
63-
}
65+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
xmlns:tools="http://schemas.android.com/tools"
4+
tools:context="org.sofwerx.signalmonitor.MainActivity">
5+
<item
6+
android:id="@+id/action_settings"
7+
android:orderInCategory="100"
8+
android:title="@string/action_settings"
9+
app:showAsAction="never" />
10+
</menu>

torgi/src/main/AndroidManifest.xml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.sofwerx.torgi">
4+
45
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
56
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
67
<uses-permission android:name="android.permission.INTERNET" />
@@ -13,16 +14,28 @@
1314
android:roundIcon="@mipmap/ic_launcher_round"
1415
android:supportsRtl="true"
1516
android:theme="@style/AppTheme">
16-
17-
<service android:name="org.sofwerx.torgi.service.TorgiService"/>
18-
17+
<service android:name=".service.TorgiService" />
18+
<provider
19+
android:name=".GeoPackageFileProvider"
20+
android:authorities="${applicationId}.geopackage.provider"
21+
android:exported="false"
22+
android:grantUriPermissions="true">
23+
<meta-data
24+
android:name="android.support.FILE_PROVIDER_PATHS"
25+
android:resource="@xml/provider_paths"/>
26+
</provider>
1927
<activity
2028
android:name=".ui.MainActivity"
21-
android:label="@string/app_name">
29+
android:label="@string/app_name"
30+
android:launchMode="singleTask">
2231
<intent-filter>
2332
<action android:name="android.intent.action.MAIN" />
33+
2434
<category android:name="android.intent.category.LAUNCHER" />
2535
</intent-filter>
2636
</activity>
37+
<activity android:name=".ui.SettingsActivity" />
38+
2739
</application>
40+
2841
</manifest>
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
package org.sofwerx.torgi;
2+
3+
import android.content.Context;
4+
import android.content.SharedPreferences;
5+
import android.os.Environment;
6+
import android.preference.PreferenceManager;
7+
8+
import java.io.File;
9+
10+
public class Config {
11+
public final static String PREFS_SAVE_DIR = "savedir";
12+
13+
private static Config instance = null;
14+
private String savedDir = null;
15+
private SharedPreferences prefs = null;
16+
private Context context;
17+
18+
private Config(Context context) {
19+
this.context = context;
20+
prefs = PreferenceManager.getDefaultSharedPreferences(context);
21+
}
22+
23+
public static Config getInstance(Context context) {
24+
if (instance == null)
25+
instance = new Config(context);
26+
return instance;
27+
}
28+
29+
public String getSavedDir() {
30+
if (savedDir == null) {
31+
/*savedDir = prefs.getString(PREFS_SAVE_DIR, null);
32+
if (savedDir != null) {
33+
try {
34+
Uri savedDirUri = Uri.parse(savedDir);
35+
if (savedDirUri != null) {
36+
context.getContentResolver().takePersistableUriPermission(savedDirUri,
37+
Intent.FLAG_GRANT_READ_URI_PERMISSION |
38+
Intent.FLAG_GRANT_WRITE_URI_PERMISSION); //Keep the permissions to access this location up to date across reboots
39+
}
40+
} catch (NullPointerException ignore) {}
41+
}
42+
if (savedDir == null)
43+
savedDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();*/
44+
if (savedDir == null) {
45+
File folder = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS), "TORGI");
46+
folder.mkdirs();
47+
savedDir = folder.getAbsolutePath();
48+
}
49+
}
50+
return savedDir;
51+
}
52+
53+
public void setSavedDir(String savedDir) {
54+
SharedPreferences.Editor edit = prefs.edit();
55+
if (savedDir == null)
56+
edit.remove(PREFS_SAVE_DIR);
57+
else
58+
edit.putString(PREFS_SAVE_DIR,savedDir);
59+
edit.commit();
60+
}
61+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package org.sofwerx.torgi;
2+
3+
import android.support.v4.content.FileProvider;
4+
5+
public class GeoPackageFileProvider extends FileProvider {}

torgi/src/main/java/org/sofwerx/torgi/gnss/Constellation.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ public enum Constellation {
1414

1515
private int value;
1616

17-
public static int size() { return Constellation.size(); }
17+
private static final int size = values().length;
18+
19+
public static int size() { return size; }
1820

1921
Constellation(int value) {
2022
this.value = value;

torgi/src/main/java/org/sofwerx/torgi/gnss/DataPoint.java

Lines changed: 86 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
package org.sofwerx.torgi.gnss;
22

3+
import android.util.Log;
4+
5+
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
6+
37
import java.util.ArrayList;
48

59
/**
610
* Represents relevant EW indicator values at one place in spacetime
711
*/
812
public class DataPoint {
13+
private final static String TAG="TORGI.EW";
914
private SpaceTime spaceTime;
1015
private ArrayList<SatMeasurement> measurements = null;
1116

17+
public DataPoint() {}
18+
1219
public DataPoint(SpaceTime spaceTime, ArrayList<SatMeasurement> measurements) {
1320
this.spaceTime = spaceTime;
1421
this.measurements = measurements;
@@ -26,15 +33,91 @@ public GNSSEWValues getAverageMeasurements() {
2633
return SatMeasurement.getAverage(measurements);
2734
}
2835

29-
//TODO hey dummy! maybe calculate the difference from baseline as well
36+
public ArrayList<GNSSEWValues> getAllGNSSEWValues() {
37+
if ((measurements == null) || measurements.isEmpty())
38+
return null;
39+
ArrayList<GNSSEWValues> valuesList = new ArrayList<>();
40+
for (SatMeasurement measurement:measurements) {
41+
if (measurement.getValues() != null)
42+
valuesList.add(measurement.getValues());
43+
}
44+
if (valuesList.isEmpty())
45+
valuesList = null;
46+
return valuesList;
47+
}
48+
49+
/**
50+
* Gets the average difference between values and baseline
51+
* @return
52+
*/
53+
public GNSSEWValues getAverageDifference() {
54+
return SatMeasurement.getAverageDifference(measurements);
55+
}
56+
57+
public ArrayList<SatMeasurement> getMeasurementsByConstellation(Constellation con) {
58+
if ((measurements != null) && !measurements.isEmpty() && (con != null)) {
59+
ArrayList<SatMeasurement> conMeas = null;
60+
for (SatMeasurement measurement:measurements) {
61+
if ((measurement.getSat() != null) && (measurement.getSat().getConstellation() == con)) {
62+
if (conMeas == null)
63+
conMeas = new ArrayList<>();
64+
conMeas.add(measurement);
65+
}
66+
}
67+
return conMeas;
68+
}
69+
return null;
70+
}
3071

3172
/**
3273
* Gets the average GNSSEWValues for each constellation
33-
* @return array with index corresponding to the constellation number of the constellation
74+
* @return array with the average value with index corresponding to the constellation number of the constellation
3475
*/
3576
public GNSSEWValues[] getAverageMeasurementsByConstellation() {
3677
GNSSEWValues[] values = new GNSSEWValues[Constellation.size()];
3778

79+
if ((measurements != null) && !measurements.isEmpty()) {
80+
Constellation con;
81+
ArrayList<SatMeasurement> conMeas;
82+
for (int i=0;i<values.length;i++) {
83+
con = Constellation.get(i);
84+
conMeas = getMeasurementsByConstellation(con);
85+
values[i] = SatMeasurement.getAverage(conMeas);
86+
}
87+
}
88+
89+
return values;
90+
}
91+
92+
public float getAllBaselinesCN0SD() {
93+
if ((measurements != null) && !measurements.isEmpty()) {
94+
ArrayList<GNSSEWValues> valuesWithCN0s = new ArrayList<>();
95+
for (SatMeasurement measurement:measurements) {
96+
if ((measurement.getValues() != null) && !Float.isNaN(measurement.getValues().getCn0()))
97+
valuesWithCN0s.add(measurement.getValues());
98+
}
99+
if (!valuesWithCN0s.isEmpty()) {
100+
double[] values = new double[valuesWithCN0s.size()];
101+
for (int i=0;i<values.length;i++) {
102+
values[i] = valuesWithCN0s.get(i).getCn0();
103+
}
104+
StandardDeviation devCal = new StandardDeviation();
105+
float stdDev = (float)devCal.evaluate(values);
106+
Log.d(TAG,"C/N0 stdDev across all satellites == "+Float.toString(stdDev));
107+
return stdDev;
108+
}
109+
}
110+
Log.d(TAG,"Could not compute C/N0 stdDev across all satellites");
111+
return Float.NaN;
112+
}
113+
114+
/**
115+
* Gets the difference between baseline and current GNSSEWValues for each constellation
116+
* @return array with the average difference between value and baseline with index corresponding to the constellation number of the constellation
117+
*/
118+
public GNSSEWValues[] getAverageDifferenceFromBaselineByConstellation() {
119+
GNSSEWValues[] values = new GNSSEWValues[Constellation.size()];
120+
38121
if ((measurements != null) && !measurements.isEmpty()) {
39122
Constellation con;
40123
ArrayList<SatMeasurement> conMeas;
@@ -48,7 +131,7 @@ public GNSSEWValues[] getAverageMeasurementsByConstellation() {
48131
conMeas.add(measurement);
49132
}
50133
}
51-
values[i] = SatMeasurement.getAverage(conMeas);
134+
values[i] = SatMeasurement.getAverageDifference(conMeas);
52135
}
53136
}
54137

0 commit comments

Comments
 (0)