Пример #1
0
        public ListeningSpeedProbe()
        {
            _positionChangedHandler = (o, e) =>
            {
                if (e.Position == null)
                {
                    return;
                }

                Datum datum = null;

                lock (_locker)
                {
                    SensusServiceHelper.Get().Logger.Log("Received position change notification.", LoggingLevel.Verbose, GetType());

                    if (_previousPosition == null)
                    {
                        _previousPosition = e.Position;
                    }
                    else if (e.Position.Timestamp > _previousPosition.Timestamp)  // it has happened (rarely) that positions come in out of order...drop any such positions.
                    {
                        datum             = new SpeedDatum(e.Position.Timestamp, _previousPosition, e.Position);
                        _previousPosition = e.Position;
                    }
                }

                if (datum != null)
                {
                    StoreDatum(datum);
                }
            };
        }
Пример #2
0
        protected override IEnumerable <Datum> Poll(CancellationToken cancellationToken)
        {
            SpeedDatum datum = null;

            Position currentPosition = GpsReceiver.Get().GetReading(cancellationToken, false);

            if (currentPosition == null)
            {
                throw new Exception("Failed to get GPS reading.");
            }
            else
            {
                lock (_previousPositionLocker)
                {
                    if (_previousPosition == null)
                    {
                        _previousPosition = currentPosition;
                    }
                    else if (currentPosition.Timestamp > _previousPosition.Timestamp)  // it has happened (rarely) that positions come in out of order...drop any such positions.
                    {
                        datum             = new SpeedDatum(currentPosition.Timestamp, _previousPosition, currentPosition);
                        _previousPosition = currentPosition;
                    }
                }
            }

            if (datum == null)
            {
                return(new Datum[] { });  // datum will be null on the first poll and where polls return locations out of order (rare). these should count toward participation.
            }
            else
            {
                return(new Datum[] { datum });
            }
        }
Пример #3
0
        public SpeedDatum(DateTimeOffset timestamp, Position previousPosition, Position currentPosition)
            : base(timestamp, 0)
        {
            double distanceKM;
            double timeHours;

            _kph = SpeedDatum.CalculateSpeedKPH(previousPosition, currentPosition, out distanceKM, out timeHours);

            if (previousPosition.Accuracy >= 0 && currentPosition.Accuracy >= 0)
            {
                double maximumDistanceKM = distanceKM + previousPosition.Accuracy / 1000f + currentPosition.Accuracy / 1000f;
                double maximumSpeedKPH   = maximumDistanceKM / timeHours;
                Accuracy = (float)(maximumSpeedKPH - _kph);
            }
        }