From 2e4e6aa93964c28bdb3aa2327c411f47c99feb62 Mon Sep 17 00:00:00 2001 From: Morten Nielsen Date: Tue, 10 Jul 2018 16:04:35 -0700 Subject: [PATCH] Various sample tweaks + added BT sample to Android. --- src/NmeaParser/NmeaParser.csproj | 9 +- src/NmeaParser/SystemNmeaDevice.Android.cs | 24 ++- src/SampleApp.Droid/MainActivity.cs | 137 +++++++++++++++--- .../Properties/AndroidManifest.xml | 1 + .../Resources/Resource.Designer.cs | 97 +++++++------ .../Resources/layout/Main.axml | 44 ++++-- src/SampleApp.Droid/SampleApp.Droid.csproj | 6 +- src/SampleApp.WinDesktop/MainWindow.xaml | 2 +- src/SampleApp.WinDesktop/MainWindow.xaml.cs | 24 +-- src/SampleApp.WinDesktop/SatelliteSnr.xaml.cs | 12 +- .../SatelliteView.xaml.cs | 15 +- 11 files changed, 264 insertions(+), 107 deletions(-) diff --git a/src/NmeaParser/NmeaParser.csproj b/src/NmeaParser/NmeaParser.csproj index 3d89797..ac4f364 100644 --- a/src/NmeaParser/NmeaParser.csproj +++ b/src/NmeaParser/NmeaParser.csproj @@ -11,7 +11,7 @@ An NMEA stream parser for serial port, bluetooth and file-based nmea simulation. nmea winrt wpf uwp xamarin gps serialport bluetooth SharpGIS.NmeaParser - 1.10.0 + 1.10.1 http://opensource.org/licenses/ms-pl.html https://github.com/dotMorten/NmeaParser https://github.com/dotMorten/NmeaParser @@ -19,9 +19,10 @@ Copyright © Morten Nielsen 2015-2018 $(MSBuildThisFileDirectory)..\Bin\$(Configuration) $(OutDir) - 1.9.0.0 - 1.9.0.0 - Added SystemNmeaDevice to the Android library, which uses the NMEA stream from the system's location provider. + 1.10.1.0 + 1.10.1.0 + Fixed missing shutdown of Android location device. +Exposed non-NMEA based Accuracy estimate on Android location device. diff --git a/src/NmeaParser/SystemNmeaDevice.Android.cs b/src/NmeaParser/SystemNmeaDevice.Android.cs index 6c7c9aa..5a5e3ca 100644 --- a/src/NmeaParser/SystemNmeaDevice.Android.cs +++ b/src/NmeaParser/SystemNmeaDevice.Android.cs @@ -23,13 +23,23 @@ namespace NmeaParser private LocationManager manager; /// - /// Initializes a new instance of the class. + /// Initializes a new instance of the class. /// public SystemNmeaDevice() { manager = Application.Context.GetSystemService(Context.LocationService) as LocationManager; } + /// + /// Gets the estimated accuracy of this location, in meters as reported by the system location provider (not NMEA based). + /// Returns NaN if no estimate is available or the active location provider isn't GPS (ie IP/WiFi/Network Provider) + /// + /// + /// Normally the **GST messages will provide the estimated accuracy, but this is not always exposed as NMEA + /// on Android devices, so this serves as a useful fallback. + /// + public float Accuracy => listener == null ? float.NaN : listener.Accuracy; + /// [Android.Runtime.RequiresPermission("android.permission.ACCESS_FINE_LOCATION")] protected override Task OpenStreamAsync() @@ -43,8 +53,7 @@ namespace NmeaParser listener = new Listener(); listener.NmeaMessage += (s, e) => stream?.Append(e); bool success = manager.AddNmeaListener(listener); - manager.RequestLocationUpdates(LocationManager.GpsProvider, 100, .1f, listener ); - + manager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0f, listener ); return Task.FromResult(stream); } @@ -81,10 +90,17 @@ namespace NmeaParser public event EventHandler NmeaMessage; + public float Accuracy = float.NaN; + void ILocationListener.OnLocationChanged(Location location) { + if (location.Provider != LocationManager.GpsProvider) + { + Accuracy = float.NaN; + return; + } + Accuracy = location.HasAccuracy ? location.Accuracy : float.NaN; if (_isNmeaSupported) return; - if (location.Provider != LocationManager.GpsProvider) return; // Not all Android devices support reporting NMEA, so we'll fallback to just generating // simple RMC and GGA message so the provider continues to work across multiple devices // $GPRMC: diff --git a/src/SampleApp.Droid/MainActivity.cs b/src/SampleApp.Droid/MainActivity.cs index 7f77db2..99a4d90 100644 --- a/src/SampleApp.Droid/MainActivity.cs +++ b/src/SampleApp.Droid/MainActivity.cs @@ -13,47 +13,148 @@ using NmeaParser.Nmea; namespace SampleApp.Droid { - [Activity(Label = "SampleApp.Droid", MainLauncher = true)] + [Activity(Label = "NMEA Parser SampleApp", MainLauncher = true)] public class MainActivity : Activity { + private Button startButton; + private Button stopButton; + protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); + startButton = FindViewById