Пример #1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="NmeaLocationDataSource"/> class.
 /// </summary>
 /// <param name="monitor">The NMEA device to monitor</param>
 /// <param name="startStopDevice">Whether starting this datasource also controls the underlying NMEA device</param>
 public NmeaLocationDataSource(NmeaParser.Gnss.GnssMonitor monitor, bool startStopDevice = true)
 {
     if (monitor == null)
     {
         throw new ArgumentNullException(nameof(monitor));
     }
     this.m_gnssMonitor = monitor;
     m_startStopDevice  = startStopDevice;
 }
Пример #2
0
        /// <summary>
        /// Unloads the current device, and opens the next device
        /// </summary>
        /// <param name="device"></param>
        private async Task StartDevice(NmeaParser.NmeaDevice device)
        {
            //Clean up old device
            if (currentDevice != null)
            {
                currentDevice.MessageReceived -= device_MessageReceived;
                if (currentDevice.IsOpen)
                {
                    await currentDevice.CloseAsync();
                }
                currentDevice.Dispose();
                if (gnssMonitorView.Monitor != null)
                {
                    gnssMonitorView.Monitor.LocationChanged -= Monitor_LocationChanged;
                    gnssMonitorView.Monitor = monitor = null;
                }
                mapplot.Clear();
            }
            output.Text = "";
            messages.Clear();
            gprmcView.Message = null;
            gpggaView.Message = null;
            gpgsaView.Message = null;
            gpgllView.Message = null;
            pgrmeView.Message = null;
            satView.ClearGsv();
            satSnr.ClearGsv();
            //Start new device
            currentDevice = device;
            foreach (var child in MessagePanel.Children.OfType <UnknownMessageControl>().ToArray())
            {
                MessagePanel.Children.Remove(child);
            }
            currentDevice.MessageReceived += device_MessageReceived;

            if (device is NmeaParser.NmeaFileDevice)
            {
                currentDeviceInfo.Text = string.Format("NmeaFileDevice( file={0} )", ((NmeaParser.NmeaFileDevice)device).FileName);
            }
            else if (device is NmeaParser.SerialPortDevice)
            {
                currentDeviceInfo.Text = string.Format("SerialPortDevice( port={0}, baud={1} )",
                                                       ((NmeaParser.SerialPortDevice)device).Port.PortName,
                                                       ((NmeaParser.SerialPortDevice)device).Port.BaudRate);
            }
            else if (device is BluetoothDevice bd)
            {
                currentDeviceInfo.Text = $"Bluetooth {bd.Service.Device.Name}";
            }
            await device.OpenAsync();

            gnssMonitorView.Monitor = monitor = new GnssMonitor(device);
            gnssMonitorView.Monitor.LocationChanged += Monitor_LocationChanged;
            view2d.GnssMonitor = monitor;
            view3d.GnssMonitor = monitor;
        }