diff --git a/src/Android/Properties/AndroidManifest.xml b/src/Android/Properties/AndroidManifest.xml index c4ae8cd..e2127ec 100644 --- a/src/Android/Properties/AndroidManifest.xml +++ b/src/Android/Properties/AndroidManifest.xml @@ -9,6 +9,7 @@ + diff --git a/src/Shared/Data/SensorPack.cs b/src/Shared/Data/SensorPack.cs index f4671de..3d4578b 100644 --- a/src/Shared/Data/SensorPack.cs +++ b/src/Shared/Data/SensorPack.cs @@ -16,7 +16,8 @@ public abstract class SensorPack { #endif public const int AccelerometerDesiredHz = 100; - public const int AccelerometerDesiredDelayMs = 1000 / AccelerometerDesiredHz; + public const int AccelerometerDesiredDelayMs = (int)(1000 / AccelerometerDesiredHz); + public const int AccelerometerToleratedDelayMs = (int)(AccelerometerDesiredDelayMs * 0.8); public const int LocationDesiredHz = 1; public const int LocationDesiredDelayMs = 1000 / LocationDesiredHz; @@ -253,7 +254,7 @@ protected void ReportNewLocation(double latitude, double longitude, float speed, IsMovingSlowly = false; if (measuredSpeed >= GpsTooFastSpeed) { - Log.Warning(new ArgumentOutOfRangeException(nameof(measuredSpeed)), "Unforeseen GPS skip of {0} m in {1} ms", measuredDistance, intervalTime.TotalMilliseconds); + Log.Debug("Unforeseen GPS skip of {0} m in {1} ms", measuredDistance, intervalTime.TotalMilliseconds); ResetGpsLocation(); return; } @@ -270,6 +271,8 @@ protected void ReportNewLocation(double latitude, double longitude, float speed, _gpsLastAccuracy = accuracy; } + private DateTime? _lastAcceleration = null; + /// /// Reports new acceleration values from the sensor. /// @@ -277,6 +280,21 @@ protected void ReportNewLocation(double latitude, double longitude, float speed, /// Y-axis acceleration in m/s^2. /// Z-axis acceleration in m/s^2. protected void ReportNewAcceleration(double accX, double accY, double accZ) { + //NOTE: cannot use the sensor timestamp data, as this is HW dependent on Android + // see https://code.google.com/p/android/issues/detail?id=56561 + var timestamp = DateTime.UtcNow; + + // Check accelerometer frequency + if(_lastAcceleration.HasValue) { + int accDelayMs = (int)((timestamp - _lastAcceleration.Value).TotalMilliseconds); + if(accDelayMs < AccelerometerToleratedDelayMs) { + // Higher frequency than what was asked for, drop + Log.Debug("Dropping accelerometer sample ({0}ms delay)", accDelayMs); + return; + } + } + _lastAcceleration = timestamp; + //Scale each axis individually accX *= _accelerometerScaleFactor; accY *= _accelerometerScaleFactor; @@ -307,15 +325,6 @@ protected void ReportNewAcceleration(double accX, double accY, double accZ) { return; } - //TODO: check for acceleration sampling frequency here - - //TODO: computation is now sync-locked to the accelerometer instead of the intended - // 100 Hz frequency. This should be changed. - - //NOTE: cannot use the sensor timestamp data, as this is HW dependent on Android - // see https://code.google.com/p/android/issues/detail?id=56561 - var timestamp = DateTime.UtcNow; - //Check for unfixed GPS timeout if (timestamp - _gpsLastUpdate > GpsUnfixedTimeout) { LocationSensorStatus = LocationSensorStatus.Fixing; @@ -392,6 +401,7 @@ public void StartSensing() { _gpsLastUpdate = DateTime.UtcNow; _lastTimeFastEnough = DateTime.MinValue; _lastTimeMoved = DateTime.MinValue; + _lastAcceleration = null; _accelerometerScaleFactor = Settings.CalibrationScaleFactor; Log.Debug("Sensor pack using scale factor of {0:P2}", _accelerometerScaleFactor); @@ -435,6 +445,8 @@ private void ResetGpsLocation() { _gpsLastBearing = 0f; _gpsLastAccuracy = 0; + _lastAcceleration = null; + _engine.Reset(); } diff --git a/src/Shared/SyncManager.cs b/src/Shared/SyncManager.cs index 2221c26..e706e61 100644 --- a/src/Shared/SyncManager.cs +++ b/src/Shared/SyncManager.cs @@ -170,7 +170,10 @@ private async Task SynchronizeInner(CancellationToken token, SyncPol IList tracks = await Task.Run(() => { using(var db = DatabaseUtility.OpenConnection()) { - return db.GetAllPendingTracks(); + return (from t in db.GetAllPendingTracks() + let trackFilepath = FileNaming.GetDataTrackFilepath(t.TrackId) + where File.Exists(trackFilepath) + select t).ToList(); } }); if (tracks.Count == 0) { diff --git a/src/Shared/UserLog.cs b/src/Shared/UserLog.cs index 52d5dc5..1f83b6f 100644 --- a/src/Shared/UserLog.cs +++ b/src/Shared/UserLog.cs @@ -119,11 +119,11 @@ await Task.Run(() => { Log.Debug("Log persisted"); } - public const int MaximumLogSize = 100; + public const int MaximumLogSize = 200; private static readonly object _rootLock = new object(); - private static Queue _log = new Queue(MaximumLogSize); + private static Queue _log = new Queue(MaximumLogSize + 1); /// /// Adds an iconless message to the log. @@ -140,13 +140,17 @@ public static void Add(Icon icon, string format, params object[] args) { lock (_rootLock) { _log.Enqueue(entry); + + while(_log.Count > MaximumLogSize) { + _log.Dequeue(); + } } OnNewEntryAdded(entry); } /// - /// Gets the entries of the log. + /// Gets all entries of the log. /// public static IReadOnlyList Entries { get {