private void btn_RT2NMEA_Click(object sender, EventArgs e) { RT2NMEA rT2NMEA = new RT2NMEA(); this.Hide(); rT2NMEA.ShowDialog(); this.Show(); }
private void File2ReadThread(List <string> file2Source, string file) { string file2DealBuffer = ""; File2SuperBuffer.Clear(); try { string Dir = Path.GetDirectoryName(file) + "\\" + Path.GetFileNameWithoutExtension(file); string file2CmpString = ""; bool start = false; bool firstRMCTime = false; bool end = false; DateTime startTime = new DateTime(); while (file2ReadLines < file2TotalLines) { if (file2ReadLines == file2TotalLines) { File2Wait = false; } if (File2Wait) { continue; } if (MatchFlag && LostMatch)//存储匹配前的,开始匹配到的时候 { //RMC已经存入在读一行 file2CmpString = file2Source[file2ReadLines]; while (!file2CmpString.Contains("GGA")) { file2DealBuffer += file2CmpString + '\n'; file2ReadLines++; file2CmpString = file2Source[file2ReadLines]; } string outPutFileName = Path.GetFileNameWithoutExtension(file); string date = startTime.Year.ToString("D2") + "-" + startTime.Month.ToString("D2") + "-" + startTime.Day.ToString("D2"); string outputDir = (Dir + "\\" + date) + "\\"; if (!System.IO.File.Exists(outputDir)) { DirectoryInfo dir = new DirectoryInfo(outputDir); dir.Create();//自行判断一下是否存在。 } string startTimeHour = String.Format("{0:D2}", startTime.TimeOfDay.Hours.ToString("D2")); string startTimeMin = String.Format("{0:D2}", startTime.TimeOfDay.Minutes.ToString("D2")); string startTimeSec = String.Format("{0:D2}", startTime.TimeOfDay.Seconds.ToString("D2")); string startTimeMs = String.Format("{0:D2}", startTime.TimeOfDay.Milliseconds.ToString("D2")); string startTimeStr = startTimeHour + "-" + startTimeMin + "-" + startTimeSec + "-" + startTimeMs; string File2NowTimeHour = String.Format("{0:D2}", File1NowTime.TimeOfDay.Hours.ToString("D2")); string File2NowTimeMin = String.Format("{0:D2}", File1NowTime.TimeOfDay.Minutes.ToString("D2")); string File2NowTimeSec = String.Format("{0:D2}", File1NowTime.TimeOfDay.Seconds.ToString("D2")); string File2NowTimeMs = String.Format("{0:D2}", File1NowTime.TimeOfDay.Milliseconds.ToString("D2")); string File2NowTimeStr = File2NowTimeHour + "-" + File2NowTimeMin + "-" + File2NowTimeSec + "-" + File2NowTimeMs; string outPutFileNameWithPath = outputDir + startTimeStr + " " + File2NowTimeStr + ".NMEA"; outPutFileNameWithPath = RT2NMEA.ConfirmFile(outPutFileNameWithPath, FileAttributes.Normal, true); File.AppendAllText(outPutFileNameWithPath, ""); File.AppendAllLines(outPutFileNameWithPath, File2SuperBuffer); File.AppendAllText(outPutFileNameWithPath, file2DealBuffer); LostMatch = false; firstRMCTime = false; start = false; file2DealBuffer = ""; File2SuperBuffer.Clear(); } if (!File2Wait) { file2CmpString = file2Source[file2ReadLines]; file2ReadLines++; if (file2CmpString.Contains("GGA") && start == false) { start = true; firstRMCTime = false; } if (start) { file2DealBuffer += file2CmpString + '\n'; } if (file2CmpString.Contains("RMC") && start == true) { file2TimeIsOK = false; string[] RmcGps = file2CmpString.Split(','); string time = ""; string date = ""; bool isNewDay = false; if (RmcGps[1] != "")//UTC时间 { string msg = RmcGps[1]; if (RmcGps[1].Contains(".")) { int index = msg.IndexOf('.'); if (index > 0) { msg = msg.Substring(index + 1, msg.Length - index - 1); } } double d = Double.Parse(RmcGps[1]); int t = (int)d; int h = t / 10000; int m = (t - h * 10000) / 100; int s = t % 100; int ms = int.Parse(msg); h = h + 8; if (h >= 24) { isNewDay = true; h = h - 24; } time = string.Format("{0:D2}", h) + ":" + string.Format("{0:D2}", m) + ":" + string.Format("{0:D2}", s) + "." + string.Format("{0:D2}", ms); } if (RmcGps[9] != "")//日期 { int t = Int32.Parse(RmcGps[9]); int dd = t / 10000; int mm = (t - dd * 10000) / 100; int yy = t % 100; if (isNewDay) { dd += 1; } if (mm == 2) { if (yy / 4 == 0 && yy / 100 != 0 || yy / 400 == 0) { if (dd > 29) { mm += 1; dd -= 29; } } else { if (dd > 28) { mm += 1; dd -= 28; } } } else if (mm == 1 || mm == 3 || mm == 5 || mm == 7 || mm == 8 || mm == 10) { if (dd > 31) { mm += 1; dd -= 31; } } else if (mm == 12) { } else { if (dd > 30) { mm += 1; dd -= 30; } } date = string.Format("{0:D2}", 2000 + yy) + "-" + string.Format("{0:D2}", mm) + "-" + string.Format("{0:D2}", dd); } if (date != "" && time != "") { if (DateTime.TryParse(date + " " + time, out File2NowTime)) { file2TimeIsOK = true; if (!firstRMCTime) { firstRMCTime = true; startTime = File2NowTime; } if (file2ReadLines < file2TotalLines) { CheckMatch(); } } } } if (file2DealBuffer.Length > 10000) { File2SuperBuffer.Add(file2DealBuffer); file2DealBuffer = ""; } } } Thread.Sleep(50); MessageBox.Show("文件2匹配结束"); if (file2DealBuffer != "" || File2SuperBuffer.Count == 0) { string date = startTime.Year.ToString("D2") + "-" + startTime.Month.ToString("D2") + "-" + startTime.Day.ToString("D2"); string outputDir = (Dir + "\\" + date) + "\\"; string startTimeHour = String.Format("{0:D2}", startTime.TimeOfDay.Hours.ToString("D2")); string startTimeMin = String.Format("{0:D2}", startTime.TimeOfDay.Minutes.ToString("D2")); string startTimeSec = String.Format("{0:D2}", startTime.TimeOfDay.Seconds.ToString("D2")); string startTimeMs = String.Format("{0:D2}", startTime.TimeOfDay.Milliseconds.ToString("D2")); string startTimeStr = startTimeHour + "-" + startTimeMin + "-" + startTimeSec + "-" + startTimeMs; string File2NowTimeHour = String.Format("{0:D2}", File1NowTime.TimeOfDay.Hours.ToString("D2")); string File2NowTimeMin = String.Format("{0:D2}", File1NowTime.TimeOfDay.Minutes.ToString("D2")); string File2NowTimeSec = String.Format("{0:D2}", File1NowTime.TimeOfDay.Seconds.ToString("D2")); string File2NowTimeMs = String.Format("{0:D2}", File1NowTime.TimeOfDay.Milliseconds.ToString("D2")); string File2NowTimeStr = File2NowTimeHour + "-" + File2NowTimeMin + "-" + File2NowTimeSec + "-" + File2NowTimeMs; string outPutFileNameWithPath = outputDir + startTimeStr + " " + File2NowTimeStr + ".NMEA"; outPutFileNameWithPath = RT2NMEA.ConfirmFile(outPutFileNameWithPath, FileAttributes.Normal, true); File.AppendAllText(outPutFileNameWithPath, ""); File.AppendAllLines(outPutFileNameWithPath, File2SuperBuffer); File.AppendAllText(outPutFileNameWithPath, file2DealBuffer); } } catch (Exception) { throw; } }