Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using GMap.NET;
- using GMap.NET.MapProviders;
- using GMap.NET.WindowsForms.Markers;
- using GMap.NET.WindowsForms;
- using System.IO.Ports;
- using System.IO;
- namespace GPS
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- //string file_write = "log.txt";
- string file_read = "car1.txt";
- List<double> latitude = new List<double>();
- List<double> longitude = new List<double>();
- List<double> speed = new List<double>();
- List<int> date = new List<int>();
- List<int> hours = new List<int>();
- List<int> mins = new List<int>();
- List<int> seconds = new List<int>();
- List<double> altitude = new List<double>();
- List<int> satellites = new List<int>();
- private void Load_Click(object sender, EventArgs e)
- {
- StreamReader r = new StreamReader(@"C:\Users\ivano\Desktop\GPS\GPS\GPS\bin\Debug\" + file_read);
- string line;
- string[] line_arr;
- while ((line = r.ReadLine()) != null)
- {
- if (line != "")
- {
- line_arr = line.Split(',');
- latitude.Add(double.Parse(line_arr[0], System.Globalization.CultureInfo.InvariantCulture));
- longitude.Add(double.Parse(line_arr[1], System.Globalization.CultureInfo.InvariantCulture));
- speed.Add(double.Parse(line_arr[2], System.Globalization.CultureInfo.InvariantCulture));
- date.Add(int.Parse(line_arr[3], System.Globalization.CultureInfo.InvariantCulture));
- hours.Add(int.Parse(line_arr[4], System.Globalization.CultureInfo.InvariantCulture));
- mins.Add(int.Parse(line_arr[5], System.Globalization.CultureInfo.InvariantCulture));
- seconds.Add(int.Parse(line_arr[6], System.Globalization.CultureInfo.InvariantCulture));
- altitude.Add(double.Parse(line_arr[7], System.Globalization.CultureInfo.InvariantCulture));
- satellites.Add(int.Parse(line_arr[8], System.Globalization.CultureInfo.InvariantCulture));
- }
- }
- int year = date[0] % 100;
- int month = date[0] / 100 % 100;
- int day = date[0] / 10000 % 100;
- hours[0] += 2;
- label1.Text = ("START\n" + year + "." + month + "." + day + "\n" + hours[0] + ":" + mins[0] + ":" + seconds[0]).ToString();
- year = date[date.Count - 1] % 100;
- month = date[date.Count - 1] / 100 % 100;
- day = date[date.Count - 1] / 10000 % 100;
- hours[hours.Count - 1] += 2;
- label2.Text = ("END\n" + year + "." + month + "." + day + "\n" + hours[hours.Count - 1]
- + ":" + mins[mins.Count - 1] + ":" + seconds[seconds.Count - 1]).ToString();
- label3.Text = "Satellites:\n"+satellites.Max().ToString();
- map.MapProvider = GMapProviders.GoogleMap;
- GMapOverlay markers = new GMapOverlay("markers");
- for (int i = 0; i < latitude.Count; i++)
- {
- GMapMarker marker = new GMarkerGoogle(
- new PointLatLng(latitude[i], longitude[i]),
- GMarkerGoogleType.orange_small);
- markers.Markers.Add(marker);
- }
- map.Overlays.Add(markers);
- map.Position = new PointLatLng(latitude[0], longitude[0]);
- map.MinZoom = 5;
- map.MaxZoom = 100;
- map.Zoom = 15;
- map.DragButton = MouseButtons.Left;
- }
- SerialPort port = new SerialPort("COM5",
- 9600, Parity.None, 8, StopBits.One);
- StreamWriter w = File.CreateText("log.txt");
- private void COM_Click(object sender, EventArgs e)
- {
- port.Open();
- port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
- }
- private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
- {
- if (port.IsOpen)
- {
- string msg = port.ReadLine();
- w.WriteLine(msg);
- }
- }
- private void Graph_Click(object sender, EventArgs e)
- {
- foreach (var series in chart1.Series)
- {
- series.Points.Clear();
- }
- for (int i = 0; i < latitude.Count; i++)
- {
- string time = (hours[i]+2).ToString() + ":" + (mins[i]).ToString() + ":" + (seconds[i]).ToString();
- chart1.Series["Speed"].Points.AddXY(time, speed[i]);
- }
- chart1.Series["Speed"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
- chart1.Series["Speed"].Color = Color.Red;
- }
- private void Stop_Click(object sender, EventArgs e)
- {
- w.Flush();
- w.Close();
- port.Close();
- }
- private void Lat_Click(object sender, EventArgs e)
- {
- foreach (var series in chart1.Series)
- {
- series.Points.Clear();
- }
- for (int i = 0; i < altitude.Count; i++)
- {
- string time = (hours[i] + 2).ToString() + ":" + (mins[i]).ToString() + ":" + (seconds[i]).ToString();
- chart1.Series["Altitude"].Points.AddXY(time, altitude[i]);
- }
- chart1.Series["Altitude"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
- chart1.Series["Altitude"].Color = Color.Blue;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement