Ejemplo n.º 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);
            }
        }
Ejemplo n.º 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);
			}
		}
Ejemplo n.º 3
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;
        }
Ejemplo n.º 4
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");
        }
Ejemplo n.º 5
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";
        }
Ejemplo n.º 6
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);
            }
        }