using System;
using System.Collections.Generic;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using NmeaParser;

namespace skyscraper5.NmeaSharpWrapper
{
	internal class SerialDevice : NmeaSharpWrapper
	{
		public SerialDevice(string portname, int baudrate)
		{
			this.portname = portname;
			this.baudrate = baudrate;
		}

		private string portname;
		private int baudrate;

		protected override void ProcessorThread()
		{
			SerialPort sp = new SerialPort(this.portname, this.baudrate);
			SerialPortDevice spd = new SerialPortDevice(sp);
			spd.MessageReceived += HandleNmeaMessage;
			spd.OpenAsync().Wait();
			CancelRequest = false;
			while (!CancelRequest)
			{
				Thread.Sleep(1000);
			}

			spd.CloseAsync().Wait();
		}
	}
}
