예제 #1
0
        public static void SetGpsState(this NmeaMessage[] nmeas, ref GpsState state)
        {
            if (!nmeas?.Any() ?? true)
            {
                return;
            }

            var lastGga = nmeas.Where(x => x is GpggaMessage)?.Cast <GpggaMessage>()?.OrderBy(x => x.FixTime)
                          ?.LastOrDefault();

            var lastGsa = nmeas.Where(x => x is GpgsaMessage)?.Cast <GpgsaMessage>()
                          ?.LastOrDefault();

            if (lastGga == null && lastGsa == null)
            {
                return;
            }

            state = state ?? new GpsState();
            state.SatelliteFix       = lastGsa?.SatelliteFix ?? state.SatelliteFix;
            state.Hdop               = lastGga?.Hdop ?? lastGsa?.Hdop ?? state.Hdop;
            state.Vdop               = lastGsa?.Vdop ?? state.Vdop;
            state.Pnrs               = lastGsa?.Pnrs ?? state.Pnrs;
            state.FixQuality         = lastGga?.FixQuality ?? state.FixQuality;
            state.NumberOfSatellites = lastGga?.NumberOfSatellites ?? state.NumberOfSatellites;
        }
예제 #2
0
        public Gps(string gpsDeviceName, BaudRate baudRate)
        {
            this.GpsDeviceName = gpsDeviceName;
            NmeaParser         = new NmeaParser();
            this.State         = new GpsState();

            GpsDevice = new SerialDevice(gpsDeviceName, baudRate);

            GpsDevice.DataReceived += (sender, bytes) =>
            {
                var nmeas = DeserializeMessages(bytes);

                nmeas.SetGpsState(ref State);

                var position = nmeas?.GetPosition();
                if (position == null)
                {
                    return;
                }
                Position = position;

                var args = new GpsUpdateEventArgs(Position, State, GpsDevice);
                OnGpsUpdate(this, args);
            };
        }
예제 #3
0
 public GpsUpdateEventArgs(GeoPosition <GeoCoordinate> position, GpsState state, SerialDevice gpsDevice)
 {
     this.Position  = position;
     this.GpsDevice = gpsDevice;
     this.State     = state;
 }