Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.97 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using GMap.NET;
  11. using GMap.NET.MapProviders;
  12. using GMap.NET.WindowsForms.Markers;
  13. using GMap.NET.WindowsForms;
  14. using System.IO.Ports;
  15. using System.IO;
  16.  
  17. namespace GPS
  18. {
  19.     public partial class Form1 : Form
  20.     {
  21.         public Form1()
  22.         {
  23.             InitializeComponent();
  24.         }
  25.  
  26.         //string file_write = "log.txt";
  27.         string file_read = "car1.txt";
  28.  
  29.         List<double> latitude = new List<double>();
  30.         List<double> longitude = new List<double>();
  31.         List<double> speed = new List<double>();
  32.         List<int> date = new List<int>();
  33.         List<int> hours = new List<int>();
  34.         List<int> mins = new List<int>();
  35.         List<int> seconds = new List<int>();
  36.         List<double> altitude = new List<double>();
  37.         List<int> satellites = new List<int>();
  38.  
  39.         private void Load_Click(object sender, EventArgs e)
  40.         {
  41.             StreamReader r = new StreamReader(@"C:\Users\ivano\Desktop\GPS\GPS\GPS\bin\Debug\" + file_read);
  42.  
  43.             string line;
  44.             string[] line_arr;
  45.  
  46.             while ((line = r.ReadLine()) != null)
  47.             {
  48.                 if (line != "")
  49.                 {
  50.                     line_arr = line.Split(',');
  51.                     latitude.Add(double.Parse(line_arr[0], System.Globalization.CultureInfo.InvariantCulture));
  52.                     longitude.Add(double.Parse(line_arr[1], System.Globalization.CultureInfo.InvariantCulture));
  53.                     speed.Add(double.Parse(line_arr[2], System.Globalization.CultureInfo.InvariantCulture));
  54.                     date.Add(int.Parse(line_arr[3], System.Globalization.CultureInfo.InvariantCulture));
  55.                     hours.Add(int.Parse(line_arr[4], System.Globalization.CultureInfo.InvariantCulture));
  56.                     mins.Add(int.Parse(line_arr[5], System.Globalization.CultureInfo.InvariantCulture));
  57.                     seconds.Add(int.Parse(line_arr[6], System.Globalization.CultureInfo.InvariantCulture));
  58.                     altitude.Add(double.Parse(line_arr[7], System.Globalization.CultureInfo.InvariantCulture));
  59.                     satellites.Add(int.Parse(line_arr[8], System.Globalization.CultureInfo.InvariantCulture));
  60.                 }
  61.             }
  62.  
  63.             int year = date[0] % 100;
  64.             int month = date[0] / 100 % 100;
  65.             int day = date[0] / 10000 % 100;
  66.             hours[0] += 2;
  67.             label1.Text = ("START\n" + year + "." + month + "." + day + "\n" + hours[0] + ":" + mins[0] + ":" + seconds[0]).ToString();
  68.  
  69.             year = date[date.Count - 1] % 100;
  70.             month = date[date.Count - 1] / 100 % 100;
  71.             day = date[date.Count - 1] / 10000 % 100;
  72.             hours[hours.Count - 1] += 2;
  73.             label2.Text = ("END\n" + year + "." + month + "." + day + "\n" + hours[hours.Count - 1]
  74.                             + ":" + mins[mins.Count - 1] + ":" + seconds[seconds.Count - 1]).ToString();
  75.  
  76.             label3.Text = "Satellites:\n"+satellites.Max().ToString();
  77.  
  78.             map.MapProvider = GMapProviders.GoogleMap;
  79.             GMapOverlay markers = new GMapOverlay("markers");
  80.             for (int i = 0; i < latitude.Count; i++)
  81.             {
  82.                 GMapMarker marker = new GMarkerGoogle(
  83.                                     new PointLatLng(latitude[i], longitude[i]),
  84.                                     GMarkerGoogleType.orange_small);
  85.                 markers.Markers.Add(marker);
  86.             }
  87.  
  88.             map.Overlays.Add(markers);
  89.             map.Position = new PointLatLng(latitude[0], longitude[0]);
  90.             map.MinZoom = 5;
  91.             map.MaxZoom = 100;
  92.             map.Zoom = 15;
  93.             map.DragButton = MouseButtons.Left;
  94.         }
  95.  
  96.         SerialPort port = new SerialPort("COM5",
  97.                     9600, Parity.None, 8, StopBits.One);
  98.         StreamWriter w = File.CreateText("log.txt");
  99.         private void COM_Click(object sender, EventArgs e)
  100.         {
  101.             port.Open();
  102.             port.DataReceived += new SerialDataReceivedEventHandler(port_DataReceived);
  103.         }
  104.         private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
  105.         {
  106.             if (port.IsOpen)
  107.             {
  108.                 string msg = port.ReadLine();
  109.                 w.WriteLine(msg);
  110.             }
  111.         }
  112.  
  113.         private void Graph_Click(object sender, EventArgs e)
  114.         {
  115.             foreach (var series in chart1.Series)
  116.             {
  117.                 series.Points.Clear();
  118.             }
  119.  
  120.             for (int i = 0; i < latitude.Count; i++)
  121.             {
  122.                 string time = (hours[i]+2).ToString() + ":" + (mins[i]).ToString() + ":" + (seconds[i]).ToString();
  123.                 chart1.Series["Speed"].Points.AddXY(time, speed[i]);
  124.                
  125.             }
  126.             chart1.Series["Speed"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
  127.             chart1.Series["Speed"].Color = Color.Red;
  128.         }
  129.  
  130.         private void Stop_Click(object sender, EventArgs e)
  131.         {
  132.             w.Flush();
  133.             w.Close();
  134.             port.Close();
  135.         }
  136.  
  137.         private void Lat_Click(object sender, EventArgs e)
  138.         {
  139.             foreach (var series in chart1.Series)
  140.             {
  141.                 series.Points.Clear();
  142.             }
  143.             for (int i = 0; i < altitude.Count; i++)
  144.             {
  145.                 string time = (hours[i] + 2).ToString() + ":" + (mins[i]).ToString() + ":" + (seconds[i]).ToString();
  146.                 chart1.Series["Altitude"].Points.AddXY(time, altitude[i]);
  147.             }
  148.             chart1.Series["Altitude"].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine;
  149.             chart1.Series["Altitude"].Color = Color.Blue;
  150.         }
  151.     }
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement