예제 #1
0
        /// <summary>
        /// Unloads the current device, and opens the next device
        /// </summary>
        /// <param name="device"></param>
        private void StartDevice(NmeaParser.NmeaDevice device)
        {
            //Clean up old device
            if (currentDevice != null)
            {
                currentDevice.MessageReceived -= device_MessageReceived;
                currentDevice.Dispose();
            }
            output.Text = "";
            messages.Clear();
            gprmcView.Message     = null;
            gpggaView.Message     = null;
            gpgsaView.Message     = null;
            gpgllView.Message     = null;
            pgrmeView.Message     = null;
            satView.GpgsvMessages = null;
            //Start new device
            currentDevice = device;
            currentDevice.MessageReceived += device_MessageReceived;
            var _ = currentDevice.OpenAsync();

            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);
            }
        }
예제 #2
0
		/// <summary>
		/// Unloads the current device, and opens the next device
		/// </summary>
		/// <param name="device"></param>
		private void StartDevice(NmeaParser.NmeaDevice device)
		{
			//Clean up old device
			if (currentDevice != null)
			{
				currentDevice.MessageReceived -= device_MessageReceived;
				currentDevice.Dispose();
			}
			output.Text = "";
			messages.Clear();
			gprmcView.Message = null;
			gpggaView.Message = null;
			gpgsaView.Message = null;
			gpgllView.Message = null;
			pgrmeView.Message = null;
			satView.GpgsvMessages = null;
			//Start new device
			currentDevice = device;
			currentDevice.MessageReceived += device_MessageReceived;
			var _ = currentDevice.OpenAsync();
			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);
			}
		}
 public NmeaLocationProvider(NmeaParser.NmeaDevice device)
 {
     this.device = device;
     if (device != null)
     {
         device.MessageReceived += device_MessageReceived;
     }
 }
 public NmeaLocationProvider(NmeaParser.NmeaDevice device)
 {
     if (device is null)
     {
         throw new ArgumentNullException(nameof(device));
     }
     this.m_device           = device;
     device.MessageReceived += Device_MessageReceived;
 }
예제 #5
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;
        }
예제 #6
0
 private void Stop()
 {
     if (listener != null)
     {
         listener.MessageReceived -= Listener_MessageReceived;
     }
     socket?.Close();
     socket?.Dispose();
     socket = null;
     listener?.CloseAsync();
     listener = null;
 }
		private void LoadDevice(NmeaParser.NmeaDevice device)
		{
			if (mapView.LocationDisplay.DataSource != null)
				mapView.LocationDisplay.DataSource.LocationChanged -= LocationProvider_LocationChanged;
			if (currentNmeaDevice != null)
			{
				currentNmeaDevice.MessageReceived -= device_MessageReceived;
			}

			currentNmeaDevice = device;
			currentNmeaDevice.MessageReceived += device_MessageReceived;
			mapView.LocationDisplay.DataSource = new NmeaLocationDataSource(currentNmeaDevice);
			mapView.LocationDisplay.IsEnabled = true;
			mapView.LocationDisplay.DataSource.LocationChanged += LocationProvider_LocationChanged;
		}
		private void LoadDevice(NmeaParser.NmeaDevice device)
		{
			if (mapView.LocationDisplay.LocationProvider != null)
				mapView.LocationDisplay.LocationProvider.LocationChanged -= LocationProvider_LocationChanged;
			if (currentNmeaDevice != null)
			{
				currentNmeaDevice.MessageReceived -= device_MessageReceived;
			}

			currentNmeaDevice = device;
			currentNmeaDevice.MessageReceived += device_MessageReceived;
			mapView.LocationDisplay.LocationProvider = new NmeaLocationProvider(currentNmeaDevice);
			mapView.LocationDisplay.IsEnabled = true;
			mapView.LocationDisplay.LocationProvider.LocationChanged += LocationProvider_LocationChanged;
		}
예제 #9
0
        private void StartDevice(NmeaParser.NmeaDevice device)
        {
            //Clean up old device
            if (_currentDevice != null)
            {
                _currentDevice.MessageReceived -= Device_MessageReceived;
                _currentDevice.Dispose();
            }
            _currentDevice = device;
            _currentDevice.MessageReceived += Device_MessageReceived;
            var _ = _currentDevice.OpenAsync();

            if (device is NmeaParser.NmeaFileDevice)
            {
                _currentDeviceInfo = $"NmeaFileDevice( file={((NmeaParser.NmeaFileDevice)device).FileName} )";
            }
            else if (device is NmeaParser.SerialPortDevice)
            {
                _currentDeviceInfo =
                    $"SerialPortDevice( port={((NmeaParser.SerialPortDevice)device).Port.PortName}, baud={((NmeaParser.SerialPortDevice)device).Port.BaudRate} )";
            }
            LoggingService.AddInfo(_currentDeviceInfo, "nmea");
        }
예제 #10
0
        public void serialFunc()
        {
            messages.Clear();
            gprmcView.Message = null;
            gpggaView.Message = null;
            if (autoSerialPort == null && _continue == false)
            {
                return;
            }

            if (autoSerialPort != null)
            {
                serialPort = autoSerialPort;
            }
            else if (Properties.Settings.Default.useManualGPSComPort && Properties.Settings.Default.manualGpsComPortName.Length > 0 && Properties.Settings.Default.manualGpsComPortBaud > 0)
            {
                serialPort = new System.IO.Ports.SerialPort(Properties.Settings.Default.manualGpsComPortName, Properties.Settings.Default.manualGpsComPortBaud);
            }
            else if (Properties.Settings.Default.gpsCommPortName.Length > 0 && Properties.Settings.Default.gpsComBaudRate > 0)
            {
                serialPort = new System.IO.Ports.SerialPort(Properties.Settings.Default.gpsCommPortName, Properties.Settings.Default.gpsComBaudRate); //use settings from last Autoset if manual is disabled
            }
            else
            {
                _statusLabel.Text = "No Serial Ports Found";
                return;
            }
            Properties.Settings.Default.gpsCommPortName      = serialPort.PortName;
            Properties.Settings.Default.gpsComBaudRate       = serialPort.BaudRate;
            Properties.Settings.Default.autoCheckGPSCommPort = false;       // disable after port is found to prevent autoscanning at every launch
            Properties.Settings.Default.Save();

            gpsSerialDevice = new NmeaParser.SerialPortDevice(serialPort);
            gpsSerialDevice.MessageReceived += gpsdevice_MessageReceived;
            gpsSerialDevice.OpenAsync();
            _statusLabel.Text = serialPort.PortName + " Connected";
        }
예제 #11
0
        private async void Start()
        {
            startButton.Enabled = false;
            status = FindViewById <TextView>(Resource.Id.output);
            var devicePicker = FindViewById <Spinner>(Resource.Id.device_picker);
            var id           = devicePicker.SelectedItem.ToString();
            var btAddress    = devices[id];

            if (btAddress == null)
            {
                if (ContextCompat.CheckSelfPermission(this, Manifest.Permission.AccessFineLocation) != Permission.Granted)
                {
                    ActivityCompat.RequestPermissions(this, new[] { Manifest.Permission.AccessFineLocation }, 1000);
                    return;
                }
                if (launched)
                {
                    return;
                }

                launched = true;
                listener = new NmeaParser.SystemNmeaDevice(ApplicationContext);
            }
            else //Bluetooth
            {
                try
                {
                    status.Text = "Opening bluetooth...";
                    var            adapter     = Android.Bluetooth.BluetoothAdapter.DefaultAdapter;
                    var            bt          = Android.Bluetooth.BluetoothAdapter.DefaultAdapter.GetRemoteDevice(btAddress);
                    Java.Util.UUID SERIAL_UUID = Java.Util.UUID.FromString("00001101-0000-1000-8000-00805F9B34FB"); //UUID for Serial Device Service
                    socket = bt.CreateRfcommSocketToServiceRecord(SERIAL_UUID);
                    try
                    {
                        await socket.ConnectAsync();
                    }
                    catch (Java.IO.IOException)
                    {
                        // This sometimes fails. Use fallback approach to open socket
                        // Based on https://stackoverflow.com/a/41627149
                        socket.Dispose();
                        var m = bt.Class.GetMethod("createRfcommSocket", new Java.Lang.Class[] { Java.Lang.Integer.Type });
                        socket = m.Invoke(bt, new Java.Lang.Object[] { 1 }) as Android.Bluetooth.BluetoothSocket;
                        socket.Connect();
                    }
                    listener = new NmeaParser.StreamDevice(socket.InputStream);
                }
                catch (System.Exception ex)
                {
                    socket?.Dispose();
                    socket       = null;
                    status.Text += "\nError opening Bluetooth device:\n" + ex.Message;
                }
            }

            if (listener != null)
            {
                listener.MessageReceived += Listener_MessageReceived;
                status.Text += "\nOpening device...";
                await listener.OpenAsync();

                status.Text        += "\nConnected!";
                startButton.Enabled = !(stopButton.Enabled = true);
            }
            else
            {
                startButton.Enabled = !(stopButton.Enabled = false);
            }
        }
예제 #12
0
        private double lastCourse = 0; // Course can fallback to NaN, but ArcGIS Datasource don't allow NaN course, so we cache last known as a fallback

        /// <summary>
        /// Initializes a new instance of the <see cref="NmeaLocationDataSource"/> class.
        /// </summary>
        /// <param name="device">The NMEA device to monitor</param>
        /// <param name="startStopDevice">Whether starting this datasource also controls the underlying NMEA device</param>
        public NmeaLocationDataSource(NmeaParser.NmeaDevice device, bool startStopDevice = true) : this(MainWindow.monitor, startStopDevice)
        {
        }
        private double lastCourse = 0; // Course can fallback to NaN, but ArcGIS Datasource don't allow NaN course, so we cache last known as a fallback

        /// <summary>
        /// Initializes a new instance of the <see cref="NmeaLocationDataSource"/> class.
        /// </summary>
        /// <param name="device">The NMEA device to monitor</param>
        /// <param name="startStopDevice">Whether starting this datasource also controls the underlying NMEA device</param>
        public NmeaLocationDataSource(NmeaParser.NmeaDevice device, bool startStopDevice = true) : this(new GnssMonitor(device), startStopDevice)
        {
        }
		public NmeaLocationProvider(NmeaParser.NmeaDevice device)
		{
			this.device = device;
			device.MessageReceived += device_MessageReceived;
		}