void VlaknoCteniGPS() { StreamWriter GPSSoubor = new StreamWriter("GPS.txt", true); string Radek = ""; while (!StopVlaknoGPS) { try { Radek = GPSPort.ReadLine(); } catch (TimeoutException) { continue; } catch { break; } string[] Elementy = Radek.Split(',');// Parsuj(Radek,','); DateTime Cas = DateTime.Now; if (Elementy[0].Contains("$GP")) { Elementy[0] = Elementy[0].Replace("$GP", ""); switch (Elementy[0]) { case "GSA": break; case "RMC": // reálný čas byte Hod, Min, Sec = 0; int mSec = 0; string Retezec = Elementy[1]; Hod = (byte)(byte.Parse(Retezec.Substring(0, 2)) + RozdilProtiUTC); Min = byte.Parse(Retezec.Substring(2, 2)); Sec = byte.Parse(Retezec.Substring(4, 2)); try { mSec = int.Parse(Retezec.Substring(7, 3)); } catch (Exception ex) { } //textBox4.Text = Hod + ":" + Min + ":" + Sec + "," + mSec; DateTime Dnes = DateTime.Now; Retezec = Dnes.Year + "-" + ("" + Dnes.Month).PadLeft(2, '0') + "-" + ("" + Dnes.Day).PadLeft(2, '0') + "T" + ("" + Hod).PadLeft(2, '0') + ":" + ("" + Min).PadLeft(2, '0') + ":" + ("" + Sec).PadLeft(2, '0') + "." + ("" + mSec).PadLeft(7, '0') + "Z";//((string) CasGPS = DateTime.ParseExact(Retezec, "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); // rychlost GPS if (Elementy[7] != "") { speed = (int)Math.Round(double.Parse(Elementy[7].Replace('.', ',')) * 1.852); } GPSSoubor.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); break; case "GGA": if (Elementy[2] != "") { string PolohaSTR = Elementy[3] + Elementy[2] + " " + Elementy[5] + Elementy[4]; // poloha Poloha = new poloha(PolohaSTR); //string debug = Poloha.ToString(); // platnost dat polohy KvalitaSignaluGPS = (kvalitaSignaluGPS)int.Parse(Elementy[6]); // výpočet rychlosti delty polohy if (PredchoziPozice == "") { PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } else { TimeSpan delka = DateTime.Now - Zacatek; string AktualniPozice = PolohaSTR; double Vzdalenost = VypocetVzdalenosti(PredchoziPozice, AktualniPozice); RychlostGeoid = (double)(Vzdalenost / delka.TotalSeconds); PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } } GPSSoubor.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); break; case "GLL": break; case "GSV": break; case "VTG": break; } // string Debug = Elementy[0]; } } GPSSoubor.Flush(); GPSSoubor.Close(); }
public object ParseLine(Value value) { string Radek = (string)value.data; string[] Elementy = Radek.Split(',');// Parsuj(Radek,','); DateTime Cas = Time; value.date = Cas; value.data = null; if (Radek.Contains("$GP")) { Elementy[0] = Elementy[0].Replace("$GP", ""); switch (Elementy[0]) { case "GSA": break; case "RMC": // reálný čas byte Hod, Min, Sec = 0; int mSec = 0; string Retezec = Elementy[1]; Hod = (byte)(byte.Parse(Retezec.Substring(0, 2)) + RozdilProtiUTC); Min = byte.Parse(Retezec.Substring(2, 2)); Sec = byte.Parse(Retezec.Substring(4, 2)); try { mSec = int.Parse(Retezec.Substring(7, 3)); } catch (Exception ex) { } //textBox4.Text = Hod + ":" + Min + ":" + Sec + "," + mSec; DateTime Dnes = DateTime.Now; Retezec = Dnes.Year + "-" + ("" + Dnes.Month).PadLeft(2, '0') + "-" + ("" + Dnes.Day).PadLeft(2, '0') + "T" + ("" + Hod).PadLeft(2, '0') + ":" + ("" + Min).PadLeft(2, '0') + ":" + ("" + Sec).PadLeft(2, '0') + "." + ("" + mSec).PadLeft(7, '0') + "Z";//((string) CasGPS = DateTime.ParseExact(Retezec, "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); // rychlost GPS if (Elementy[7] != "") { speed = (int)Math.Round(double.Parse(Elementy[7].Replace('.', ',')) * 1.852); } if (LogFile != null) LogFile.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); break; case "GGA": if (Elementy[2] != "") { string PolohaSTR = Elementy[3] + Elementy[2] + " " + Elementy[5] + Elementy[4]; // poloha Poloha = new poloha(PolohaSTR); //string debug = Poloha.ToString(); // platnost dat polohy KvalitaSignaluGPS = (kvalitaSignaluGPS)int.Parse(Elementy[6]); // výpočet rychlosti delty polohy if (PredchoziPozice == "") { PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } else { TimeSpan delka = DateTime.Now - Zacatek; string AktualniPozice = PolohaSTR; double Vzdalenost = VypocetVzdalenosti(PredchoziPozice, AktualniPozice); RychlostGeoid = (double)(Vzdalenost / delka.TotalSeconds); PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } if (KvalitaSignaluGPS == kvalitaSignaluGPS.ZjistenaPozice) { value.data = Poloha; } GGA gga; gga.Poloha = Poloha; return gga; } if (LogFile != null) LogFile.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); break; case "GLL": break; case "GSV": break; case "VTG": break; default: break; } //value.data = ""; // string Debug = Elementy[0]; } return value; }
public object ParseLine(Value value) { string Radek = (string)value.data; string[] Elementy = Radek.Split(',');// Parsuj(Radek,','); DateTime Cas = Time; value.date = Cas; value.data = null; if (Radek.Contains("$GP")) { Elementy[0] = Elementy[0].Replace("$GP", ""); switch (Elementy[0]) { case "GSA": break; case "RMC": // reálný čas byte Hod, Min, Sec = 0; int mSec = 0; string Retezec = Elementy[1]; Hod = (byte)(byte.Parse(Retezec.Substring(0, 2)) + RozdilProtiUTC); Min = byte.Parse(Retezec.Substring(2, 2)); Sec = byte.Parse(Retezec.Substring(4, 2)); try { mSec = int.Parse(Retezec.Substring(7, 3)); } catch (Exception ex) { } //textBox4.Text = Hod + ":" + Min + ":" + Sec + "," + mSec; DateTime Dnes = DateTime.Now; Retezec = Dnes.Year + "-" + ("" + Dnes.Month).PadLeft(2, '0') + "-" + ("" + Dnes.Day).PadLeft(2, '0') + "T" + ("" + Hod).PadLeft(2, '0') + ":" + ("" + Min).PadLeft(2, '0') + ":" + ("" + Sec).PadLeft(2, '0') + "." + ("" + mSec).PadLeft(7, '0') + "Z";//((string) CasGPS = DateTime.ParseExact(Retezec, "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'", CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal | DateTimeStyles.AdjustToUniversal); // rychlost GPS if (Elementy[7] != "") { speed = (int)Math.Round(double.Parse(Elementy[7].Replace('.', ',')) * 1.852); } if (LogFile != null) { LogFile.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); } break; case "GGA": if (Elementy[2] != "") { string PolohaSTR = Elementy[3] + Elementy[2] + " " + Elementy[5] + Elementy[4]; // poloha Poloha = new poloha(PolohaSTR); //string debug = Poloha.ToString(); // platnost dat polohy KvalitaSignaluGPS = (kvalitaSignaluGPS)int.Parse(Elementy[6]); // výpočet rychlosti delty polohy if (PredchoziPozice == "") { PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } else { TimeSpan delka = DateTime.Now - Zacatek; string AktualniPozice = PolohaSTR; double Vzdalenost = VypocetVzdalenosti(PredchoziPozice, AktualniPozice); RychlostGeoid = (double)(Vzdalenost / delka.TotalSeconds); PredchoziPozice = PolohaSTR; Zacatek = DateTime.Now; } if (KvalitaSignaluGPS == kvalitaSignaluGPS.ZjistenaPozice) { value.data = Poloha; } GGA gga; gga.Poloha = Poloha; return(gga); } if (LogFile != null) { LogFile.WriteLine(Cas.ToShortDateString() + " " + Cas.ToLongTimeString() + "\t" + Radek); } break; case "GLL": break; case "GSV": break; case "VTG": break; default: break; } //value.data = ""; // string Debug = Elementy[0]; } return(value); }