private void port_PositionUpdated(object sender, EventArgs e) { InvokeSetText(latLbl, Angle2Str(port.Latitude, true)); InvokeSetText(lonLbl, Angle2Str(port.Longitude, false)); InvokeSetText(rerrLbl, port.RadialError.ToString("F03", CultureInfo.InvariantCulture)); InvokeSetText(depthLbl, port.Depth.ToString("F02", CultureInfo.InvariantCulture)); if (port.RadialError <= settingsProvider.Data.RadialErrorThreshold) { InvokeSetForeColor(rerrLbl, Color.Green); GeoPlot.GeoCoordinate2D newPoint = new GeoPlot.GeoCoordinate2D(); newPoint.Latitude = port.Latitude; newPoint.Longitude = port.Longitude; InvokeAddRNPoint(newPoint); TrackRecord trk = new TrackRecord(); trk.Location = new GeoPoint3DE(port.Latitude, port.Longitude, port.Depth, port.RadialError); trk.Buoy0Location = new GeoPoint(port.RedBASE_1.Latitude, port.RedBASE_1.Longitude); trk.Buoy1Location = new GeoPoint(port.RedBASE_2.Latitude, port.RedBASE_2.Longitude); trk.Buoy2Location = new GeoPoint(port.RedBASE_3.Latitude, port.RedBASE_3.Longitude); trk.Buoy3Location = new GeoPoint(port.RedBASE_4.Latitude, port.RedBASE_4.Longitude); track.Add(trk); } else { InvokeSetForeColor(rerrLbl, Color.Red); } locHyst = 0; onceLocated = true; }
private void ParseTrackFromFile(string fileName) { bool isOk = false; List <string> lines = new List <string>(); try { lines.AddRange(File.ReadAllLines(fileName)); isOk = true; } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); } if (isOk) { track.Clear(); foreach (var item in lines) { if (item.Contains("$PTNTC")) { int wspIdx = item.IndexOf(' '); var timeStr = item.Substring(0, wspIdx); var splits = timeStr.Split(":".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); int hrs = Convert.ToInt32(splits[0]); int mins = Convert.ToInt32(splits[1]); double secs = Convert.ToDouble(splits[2], CultureInfo.InvariantCulture); secs += mins * 60 + hrs * 3600; int sIdx = item.IndexOf("$PTNTC"); var subStr = item.Substring(sIdx); if (!subStr.EndsWith("\r\n")) { subStr = subStr + "\r\n"; } try { var pSentence = NMEAParser.Parse(subStr); if (pSentence is NMEAProprietarySentence) { var ps = (pSentence as NMEAProprietarySentence); if ((ps.Manufacturer == ManufacturerCodes.TNT) && (ps.SentenceIDString == "C")) { TrackRecord newRecord = new TrackRecord(); newRecord.Second = secs; newRecord.Location = new GeoPoint3DE((double)ps.parameters[0], (double)ps.parameters[1], (double)ps.parameters[2], (double)ps.parameters[3]); newRecord.Buoy0Location = new GeoPoint((double)ps.parameters[4], (double)ps.parameters[5]); newRecord.Buoy1Location = new GeoPoint((double)ps.parameters[6], (double)ps.parameters[7]); newRecord.Buoy2Location = new GeoPoint((double)ps.parameters[8], (double)ps.parameters[9]); newRecord.Buoy3Location = new GeoPoint((double)ps.parameters[10], (double)ps.parameters[11]); if (newRecord.Location.RadialError <= settingsProvider.Data.RadialErrorThreshold) { track.Add(newRecord); } } } } catch (Exception ex) { } } } if (track.Count > 0) { saveTrackToolStripMenuItem_Click(this, new EventArgs()); } } }