private int searchforProtocolAndBaud_sub(ref CommunicationManager comm) { string[] strArray = new string[10]; string[] strArray2 = new string[10]; string str = string.Empty; string str2 = string.Empty; comm.portDataInit(); if (comm.MessageProtocol == "NMEA") { comm.RxType = CommunicationManager.ReceiverType.NMEA; if (comm.waitforNMEAMsg()) { comm.AutoDetectProtocolAndBaudDone = true; return 1; } str = "OSP,NMEA,OSP,NMEA,OSP,OSP,OSP,OSP,OSP,OSP,OSP,OSP,NMEA,NMEA,NMEA,NMEA,NMEA"; str2 = "115200,4800,4800,115200,38400,9600,57600,19200,230400,460800,912600,1228800,38400,9600,57600,19200,115200"; } else if (comm.MessageProtocol == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; if (comm.waitforSSBMsg()) { comm.AutoDetectProtocolAndBaudDone = true; return 1; } str = "NMEA,OSP,NMEA,OSP,NMEA,NMEA,NMEA,NMEA,NMEA,OSP,OSP,OSP,OSP,OSP,OSP,OSP,OSP"; str2 = "4800,115200,115200,4800,38400,9600,57600,19200,115200,38400,9600,57600,19200,230400,460800,912600,1228800"; } else { comm.AutoDetectProtocolAndBaudDone = true; return 2; } strArray = str2.Split(new char[] { ',' }); strArray2 = str.Split(new char[] { ',' }); frmSimpleDialog dialog = new frmSimpleDialog("Auto Detect Baud"); dialog.Show(); for (int i = 0; i < strArray2.Length; i++) { comm.AutoDetectProtocolAndBaudDone = false; dialog.DisplayMessage = string.Format("\tDetecting {0} - {1}\n\n\t\tPlease wait...", strArray2[i], strArray[i]); dialog.ShowMessage(); if ((comm.CurrentProtocol != strArray2[i]) || (comm.CurrentBaud != strArray[i])) { comm.BaudRate = strArray[i]; comm.MessageProtocol = strArray2[i]; if (strArray2[i] == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; comm.RxTransType = CommunicationManager.TransmissionType.GPS; } else { comm.RxType = CommunicationManager.ReceiverType.NMEA; comm.RxTransType = CommunicationManager.TransmissionType.Text; } Refresh(); comm.SetupRxCtrl(); uint baud = uint.Parse(comm.BaudRate); bool flag = false; int num3 = 0; while (num3++ < 5) { flag = comm.comPort.UpdateBaudSettings(baud); if (flag) { break; } } if (!flag) { dialog.Close(); comm.ErrorPrint("Error updating port"); return 3; } comm.portDataInit(); Thread.Sleep(5); if (comm.MessageProtocol == "OSP") { if (comm.waitforSSBMsg()) { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } } else if (comm.MessageProtocol == "NMEA") { if (comm.waitforNMEAMsg()) { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 1; } } else { comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 2; } } } comm.AutoDetectProtocolAndBaudDone = true; dialog.Close(); return 3; }
private void convertFiles() { EventHandler method = null; EventHandler handler3 = null; EventHandler handler4 = null; EventHandler handler5 = null; EventHandler handler6 = null; EventHandler handler7 = null; EventHandler handler8 = null; EventHandler handler9 = null; EventHandler handler10 = null; EventHandler handler11 = null; EventHandler handler12 = null; CommunicationManager manager = new CommunicationManager(); manager.RxCtrl = new OSPReceiver(); manager.RxCtrl.ResetCtrl = new OSPReset(); StreamWriter writer = null; StreamWriter writer2 = null; StreamReader reader = null; LargeFileHandler handler = null; Thread.CurrentThread.CurrentCulture = clsGlobal.MyCulture; try { foreach (string str in this.toRunList) { if (!File.Exists(str)) { this._convertedFilesCount++; if (method == null) { method = delegate { this.convertedFilesLabel.Text = string.Format("Files converted: {0}", this._convertedFilesCount); }; } this.convertedFilesLabel.BeginInvoke(method); continue; } string str2 = string.Empty; string path = string.Empty; string str4 = string.Empty; if (str.EndsWith(".gp2")) { path = str.Replace(".gp2", ".gps"); } else if (str.EndsWith(".gpx")) { path = str.Replace(".gpx", ".gps"); } else if (str.EndsWith(".bin")) { path = str.Replace(".bin", ".gps"); str4 = str.Replace(".bin", ".gp2"); } else if (str.EndsWith(".gps")) { if (this._conversionType == ConversionType.GPSToNMEA) { if (this.useSSBMsg41RadioBtn.Checked) { path = str.Replace(".gps", "_msg41.nmea"); } else if (this.useOspMsg69RadioBtn.Checked) { path = str.Replace(".gps", "_msg69.nmea"); } else if (this.autoDetectRadioBtn.Checked) { path = str.Replace(".gps", "_auto.nmea"); str4 = str.Replace(".gps", ".msg69parse"); } else { path = str.Replace(".gps", ".nmea"); } } else if (this._conversionType == ConversionType.GPSToKML) { path = str.Replace(".gps", ".kml"); } else { path = str.Replace(".gps", ".convert"); } } else if (str.EndsWith(".nmea")) { path = str.Replace(".nmea", ".gps"); } else { path = str.Substring(0, str.Length - 4) + ".gps"; } writer = new StreamWriter(path); reader = new StreamReader(str); FileInfo info = new FileInfo(str); double length = info.Length; if (length == 0.0) { this._convertedFilesCount++; if (handler3 == null) { handler3 = delegate { this.convertedFilesLabel.Text = string.Format("Files converted: {0}", this._convertedFilesCount); }; } this.convertedFilesLabel.BeginInvoke(handler3); continue; } if (handler4 == null) { handler4 = delegate { this.progressBar1.Value = 0; this.progressBar1.Maximum = 100; this.progressBar1.Minimum = 0; }; } this.progressBar1.BeginInvoke(handler4); long num2 = 0L; switch (this._conversionType) { case ConversionType.GP2ToGPS: if (handler6 == null) { handler6 = delegate { this.fileConversionStatusLabel.Text = "Status: converting..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler6); while ((str2 = reader.ReadLine()) != null) { num2 += str2.Length; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); try { if (str2.Contains("A0 A2")) { int index = str2.IndexOf("A0 A2"); byte[] comByte = HelperFunctions.HexToByte(str2.Substring(index)); string str9 = manager.m_Protocols.ConvertRawToFields(comByte); if (this.includeDateTimeChkBox.Checked) { writer.WriteLine(str2.Substring(0, index) + " " + str9); } else { writer.WriteLine(str9); } } else { writer.WriteLine(str2); } } catch { writer.WriteLine(str2); continue; } if (this._abort) { break; } } goto Label_1731; case ConversionType.BinToGPS_GP2: break; case ConversionType.GPSToNMEA: { reader.Close(); Queue<uint> queue = new Queue<uint>(); Queue<long> queue2 = new Queue<long>(); handler = new LargeFileHandler(str); long item = 0L; if (this.autoDetectRadioBtn.Checked) { writer2 = new StreamWriter(str4); if (handler7 == null) { handler7 = delegate { this.fileConversionStatusLabel.Text = "Status: scanning..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler7); str2 = handler[item]; while (str2 != "EOF") { str2 = str2.Replace(" ", ""); if (str2.StartsWith("69,1")) { try { string[] strArray3 = str2.Split(new char[] { ',' }); if (strArray3.Length > 9) { uint num8 = Convert.ToUInt32(strArray3[9]); writer2.WriteLine(string.Format("{0} -- {1}", num8, strArray3[5])); if ((strArray3[3] != "0") && (strArray3[5] == "1")) { queue.Enqueue(num8); queue2.Enqueue(item); } } } catch { } } item = handler.Index + 1L; str2 = handler[item]; } writer2.Close(); item = 0L; str2 = handler[item]; } if (handler8 == null) { handler8 = delegate { this.fileConversionStatusLabel.Text = "Status: converting..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler8); while (str2 != "EOF") { string str11; num2 += str2.Length; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); str2 = str2.TrimEnd(new char[] { '\n' }).TrimEnd(new char[] { '\r' }).Replace(" ", ""); if (str2.StartsWith("4,")) { string[] strArray4 = str2.Split(new char[] { ',' }); string str10 = this.GPS_NMEA_OutputGSV(strArray4); if (str10 != string.Empty) { writer.Write(str10); } goto Label_0AFE; } if (!str2.StartsWith("41,")) { goto Label_0A08; } if (!this.useSSBMsg41RadioBtn.Checked && !this.autoDetectRadioBtn.Checked) { goto Label_0AFE; } string[] msgArray = str2.Split(new char[] { ',' }); if (msgArray.Length < 0x22) { item = handler.Index + 1L; str2 = handler[item]; continue; } if ((queue.Count > 0) && this.autoDetectRadioBtn.Checked) { uint num9 = Convert.ToUInt32(msgArray[4]); uint num10 = queue.Peek(); long num11 = queue2.Peek(); if (num9 == num10) { queue.Dequeue(); queue2.Dequeue(); } else { if (num9 > num10) { if (item > num11) { while (item > num11) { queue.Dequeue(); queue2.Dequeue(); num10 = queue.Peek(); num11 = queue2.Peek(); if (num9 == num10) { break; } } if (item > num11) { goto Label_0960; } continue; } item = handler.Index + 1L; str2 = handler[item]; continue; } item = handler.Index + 1L; str2 = handler[item]; continue; } } Label_0960: str11 = this.GPS_NMEA_OutputGGA(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputRMC(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputGLL(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputGSA(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputVTG(msgArray); if (str11 != string.Empty) { writer.Write(str11); } goto Label_0AFE; Label_0A08: if (str2.StartsWith("69,1") && this.useOspMsg69RadioBtn.Checked) { string[] strArray6 = new string[0x24]; if (this.msg69ToMsg4AndMsg41Format(str2, ref strArray6) != 0) { item = handler.Index + 1L; str2 = handler[item]; continue; } string str12 = this.GPS_NMEA_OutputGGA(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputRMC(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputGLL(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputGSA(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputVTG(strArray6); if (str12 != string.Empty) { writer.Write(str12); } } Label_0AFE: if (this._abort) { break; } item = handler.Index + 1L; str2 = handler[item]; } goto Label_1731; } case ConversionType.GPSToKML: { if (handler10 == null) { handler10 = delegate { this.fileConversionStatusLabel.Text = "Status: converting..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler10); PortManager manager2 = new PortManager(); manager.MessageProtocol = "OSP"; manager2.comm.SetupRxCtrl(); writer.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); writer.WriteLine("<kml xmlns=\"http://earth.google.com/kml/2.0\">"); writer.WriteLine("\t<Document>"); writer.WriteLine("\t\t<Style id=\"red\">"); writer.WriteLine("\t\t\t<IconStyle>"); writer.WriteLine("\t\t\t\t<Icon><href>http://maps.google.com/mapfiles/kml/pal3/icon63.png</href></Icon>"); writer.WriteLine("\t\t\t\t<color>ff0000ff</color>"); writer.WriteLine("\t\t\t\t<scale>.3</scale>"); writer.WriteLine("\t\t\t</IconStyle>"); writer.WriteLine("\t\t</Style>"); writer.WriteLine("\t\t<Style id=\"green\">"); writer.WriteLine("\t\t\t<IconStyle>"); writer.WriteLine("\t\t\t\t<Icon><href>http://maps.google.com/mapfiles/kml/pal3/icon63.png</href></Icon>"); writer.WriteLine("\t\t\t\t<color>ff00ff00</color>"); writer.WriteLine("\t\t\t\t<scale>.3</scale>"); writer.WriteLine("\t\t\t</IconStyle>"); writer.WriteLine("\t\t</Style>"); writer.WriteLine("\t\t<Style id=\"blue\">"); writer.WriteLine("\t\t\t<IconStyle>"); writer.WriteLine("\t\t\t\t<Icon><href>http://maps.google.com/mapfiles/kml/pal3/icon63.png</href></Icon>"); writer.WriteLine("\t\t\t\t<color>ffff0000</color>"); writer.WriteLine("\t\t\t\t<scale>.3</scale>"); writer.WriteLine("\t\t\t</IconStyle>"); writer.WriteLine("\t\t</Style>"); writer.WriteLine("\t\t<Style id=\"cyan\">"); writer.WriteLine("\t\t\t<IconStyle>"); writer.WriteLine("\t\t\t\t<Icon><href>http://maps.google.com/mapfiles/kml/pal3/icon63.png</href></Icon>"); writer.WriteLine("\t\t\t\t<color>ffff41b0</color>"); writer.WriteLine("\t\t\t\t<scale>.3</scale>"); writer.WriteLine("\t\t\t</IconStyle>"); writer.WriteLine("\t\t</Style>"); bool flag4 = false; double num21 = 0.0; while ((str2 = reader.ReadLine()) != null) { num2 += str2.Length; num21++; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); if (str2.StartsWith("41,")) { Hashtable hashtable = manager2.comm.getSatellitesDataForGUIFromCSV(0x29, 0, "SSB", str2); if (hashtable != null) { double num22 = 0.0; int num23 = 0; double num24 = 0.0; double num25 = 0.0; double num26 = 0.0; double num27 = 0.0; double num28 = 0.0; double num29 = 0.0; double num30 = 0.0; int num31 = 0; uint num32 = 0; int num33 = 0; int num34 = 0; int num35 = 0; int num36 = 0; int num37 = 0; int num38 = 0; double num39 = 0.0; try { if (hashtable.ContainsKey("NAV Type")) { num23 = Convert.ToUInt16((string) hashtable["NAV Type"]); } if (num23 > 0) { if (hashtable.ContainsKey("TOW")) { num22 = Convert.ToDouble((string) hashtable["TOW"]) / 1000.0; } if (hashtable.ContainsKey("Latitude")) { num24 = Convert.ToDouble((string) hashtable["Latitude"]) / 10000000.0; } if (hashtable.ContainsKey("Longitude")) { num25 = Convert.ToDouble((string) hashtable["Longitude"]) / 10000000.0; } if (hashtable.ContainsKey("Altitude from Ellipsoid")) { double num1 = Convert.ToDouble((string) hashtable["Altitude from Ellipsoid"]) / 100.0; } if (hashtable.ContainsKey("Altitude from MSL")) { num26 = Convert.ToDouble((string) hashtable["Altitude from MSL"]) / 100.0; } if (hashtable.ContainsKey("UTC Hour")) { num37 = Convert.ToInt32((string) hashtable["UTC Hour"]); } if (hashtable.ContainsKey("UTC Minute")) { num38 = Convert.ToInt32((string) hashtable["UTC Minute"]); } if (hashtable.ContainsKey("UTC Second")) { num39 = Convert.ToDouble((string) hashtable["UTC Second"]) / 1000.0; } if (hashtable.ContainsKey("UTC Year")) { num34 = Convert.ToInt32((string) hashtable["UTC Year"]); } if (hashtable.ContainsKey("UTC Month")) { num36 = Convert.ToInt32((string) hashtable["UTC Month"]); } if (hashtable.ContainsKey("UTC Day")) { num35 = Convert.ToInt32((string) hashtable["UTC Day"]); } if (hashtable.ContainsKey("HDOP")) { num30 = Convert.ToDouble((string) hashtable["HDOP"]) / 5.0; } if (hashtable.ContainsKey("Speed Over Ground (SOG)")) { num27 = Convert.ToDouble((string) hashtable["Speed Over Ground (SOG)"]) / 100.0; } if (hashtable.ContainsKey("Course Over Ground (COG True)")) { num28 = Convert.ToDouble((string) hashtable["Course Over Ground (COG True)"]) / 100.0; } if (hashtable.ContainsKey("Extended Week Number")) { num32 = Convert.ToUInt16((string) hashtable["Extended Week Number"]); } if (hashtable.ContainsKey("Number of SVs in Fix")) { num33 = Convert.ToInt32((string) hashtable["Number of SVs in Fix"]); } if (hashtable.ContainsKey("AdditionalModelInfor")) { num31 = Convert.ToInt32((string) hashtable["AdditionalModelInfor"]); } if (hashtable.ContainsKey("Estimated Horizontal Position Error")) { num29 = Convert.ToDouble((string) hashtable["Estimated Horizontal Position Error"]) / 100.0; } writer.WriteLine("\t\t<Placemark>"); if (!flag4) { writer.WriteLine("\t\t\t<name>Start</name>"); flag4 = true; } writer.WriteLine("\t\t\t<description>Nav mode = 0x{0}<br/> GPS Week = {1}<br/> TOW = {2:F3} s<br/>UTC = {3}/{4}/{5} {6}:{7}:{8:F3}<br/> SV Cnt = {9}<br/> Lat = {10:F7} deg<br/> Lon = {11:F7} deg<br/> Alt (msl)= {12:F2} m<br/> Sog = {13:F2} m/s<br/> Hdg = {14:F2} deg<br/> Ehpe = {15:F2} m<br/> Hdop = {16:F2}<br/> Additional Mode Info = 0x{17}<br/></description>", new object[] { num23.ToString("X"), num32, num22, num36, num35, num34, num37, num38, num39, num33, num24, num25, num26, num27, num28, num29, num30, num31.ToString("X") }); writer.WriteLine("\t\t\t<styleUrl>red</styleUrl>"); writer.WriteLine("\t\t\t<Point><coordinates>{0:F7},{1:F7},0</coordinates></Point>", num25, num24); writer.WriteLine("\t\t</Placemark>"); } continue; } catch { writer.WriteLine("Error encounters! {0}", num21); continue; } } } } manager2 = null; writer.WriteLine("\t</Document>"); writer.WriteLine("</kml>"); goto Label_1731; } case ConversionType.NMEAToGPS: { if (handler9 == null) { handler9 = delegate { this.fileConversionStatusLabel.Text = "Status: converting..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler9); string str16 = "0"; string str17 = string.Empty; string str18 = string.Empty; string str19 = string.Empty; string nS = string.Empty; string eW = string.Empty; string str22 = string.Empty; string str23 = string.Empty; double num13 = 0.0; double num14 = 0.0; int fixPosIndicator = 0; int lat = 0; int lon = 0; int num18 = 0; int gpsWeek = 0; double gpsTOW = 0.0; bool flag = false; bool flag2 = false; bool flag3 = false; while ((str2 = reader.ReadLine()) != null) { num2 += str2.Length; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); if (str2.Contains("GPRMC")) { string str24 = string.Empty; try { if (flag && flag2) { if (flag3) { str24 = string.Format("41,0,{0},{1},{2},{3},{4},{5},{6},{7},{8},0,{9},{10},0,0,0,{11:F2},{12:F2},0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", new object[] { num18, gpsWeek, gpsTOW * 1000.0, str19.Substring(4, 2), str19.Substring(2, 2), str19.Substring(0, 2), str16.Substring(0, 2), str16.Substring(2, 2), str16.Substring(4, 2), lat, lon, num14, num13 }); } else { str24 = string.Format("41,0,{0},{1},{2},{3},{4},{5},{6},{7},{8},0,{9},{10},0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0", new object[] { num18, gpsWeek, gpsTOW * 1000.0, str19.Substring(4, 2), str19.Substring(2, 2), str19.Substring(0, 2), str16.Substring(0, 2), str16.Substring(2, 2), str16.Substring(4, 2), lat, lon }); } } writer.WriteLine(str24); flag = false; flag2 = false; flag3 = false; } catch (Exception exception) { MessageBox.Show("Exception in file conversion NMEA to SB: " + exception.ToString()); } string[] strArray7 = str2.Split(new char[] { ',' }); str16 = strArray7[1]; str17 = strArray7[3]; nS = strArray7[4]; str18 = strArray7[5]; eW = strArray7[6]; str19 = strArray7[9]; try { this.ConvertRMCDateToWeekAndSeconds(str16, str19, ref gpsWeek, ref gpsTOW); this.ConvertRMCLatLontoSBmsg41LatLon(str17, nS, str18, eW, ref lat, ref lon); } catch (Exception exception2) { MessageBox.Show("Exception in file conversion NMEA to SB: " + exception2.ToString()); } flag = true; } else if (str2.Contains("GPGGA")) { string[] strArray8 = str2.Split(new char[] { ',' }); string text1 = strArray8[1]; try { fixPosIndicator = Convert.ToInt32(strArray8[6]); num18 = this.ConvertGGAPosFixIndiToSBmsg41NavType(fixPosIndicator); } catch (Exception exception3) { MessageBox.Show("Exception in file conversion NMEA to SB: " + exception3.ToString()); } flag2 = true; } else if (str2.Contains("GPVTG")) { string[] strArray9 = str2.Split(new char[] { ',' }); str22 = strArray9[1]; str23 = strArray9[7]; try { num13 = Convert.ToDouble(str22); num14 = Convert.ToDouble(str23); } catch (Exception exception4) { MessageBox.Show("Exception in file conversion NMEA to SB: " + exception4.ToString()); } num13 *= 100.0; num14 = (num14 * 1000.0) / 36.0; flag3 = true; } else { writer.WriteLine(str2); } if (this._abort) { break; } } goto Label_1731; } default: goto Label_1731; } reader.Close(); FileStream stream = File.OpenRead(str); writer2 = new StreamWriter(str4); if (handler5 == null) { handler5 = delegate { this.fileConversionStatusLabel.Text = "Status: converting..."; }; } this.fileConversionStatusLabel.BeginInvoke(handler5); int offset = 0; int count = 0x1000; byte[] buffer = new byte[count]; int len = stream.Read(buffer, offset, count); manager.SetupRxCtrl(); while (len > 0) { manager.PopulateData(buffer, len); string str5 = manager.ByteToMsgQueue(new byte[1]); string[] separator = new string[] { "\r\n" }; foreach (string str6 in str5.Split(separator, StringSplitOptions.None)) { string str7 = manager.m_Protocols.ConvertRawToFields(HelperFunctions.HexToByte(str6)); writer.WriteLine(str7); writer2.WriteLine(CommonUtilsClass.LogToGP2(str6, string.Empty)); } offset += len; int percent = (int) ((((double) offset) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); len = stream.Read(buffer, 0, count); if (this._abort) { break; } } stream.Close(); writer2.Close(); Label_1731: if (this._abort) { break; } reader.Close(); writer.Close(); if (handler != null) { handler.Close(); } this._convertedFilesCount++; if (handler11 == null) { handler11 = delegate { this.convertedFilesLabel.Text = string.Format("Files converted: {0}", this._convertedFilesCount); }; } this.convertedFilesLabel.BeginInvoke(handler11); } if (this._abort) { MessageBox.Show("Conversion Aborted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (reader != null) { reader.Close(); } if (writer != null) { writer.Close(); } if (writer2 != null) { writer2.Close(); } if (handler != null) { handler.Close(); } } else { MessageBox.Show("Conversion Done", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } this._conversionStatus = false; } catch (Exception exception5) { if (reader != null) { reader.Close(); } if (writer != null) { writer.Close(); } if (writer2 != null) { writer2.Close(); } if (handler != null) { handler.Close(); } this._conversionStatus = false; this._abort = false; MessageBox.Show("Error: " + exception5.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } try { if (handler12 == null) { handler12 = delegate { this.fileConversionStatusLabel.Text = "Status: idle"; }; } this.fileConversionStatusLabel.BeginInvoke(handler12); } catch { } manager.Dispose(); manager = null; }
private int searchforProtocolAndBaud(ref CommunicationManager comm) { comm.AutoDetectProtocolAndBaudDone = false; comm.CurrentProtocol = comm.MessageProtocol; comm.CurrentBaud = comm.BaudRate; Refresh(); if (!comm.OpenPort()) { return 0; } Thread.Sleep(10); int num = searchforProtocolAndBaud_sub(ref comm); if (num == 3) { comm.BaudRate = comm.CurrentBaud; comm.MessageProtocol = comm.CurrentProtocol; if (comm.CurrentProtocol == "OSP") { comm.RxType = CommunicationManager.ReceiverType.SLC; comm.RxTransType = CommunicationManager.TransmissionType.GPS; } else { comm.RxType = CommunicationManager.ReceiverType.NMEA; comm.RxTransType = CommunicationManager.TransmissionType.Text; } comm.SetupRxCtrl(); comm.comPort.BaudRate = int.Parse(comm.BaudRate); comm.comPort.UpdateSetttings(); comm.portDataInit(); } comm.AutoDetectProtocolAndBaudDone = true; return num; }
private void convertFiles() { EventHandler method = null; EventHandler handler3 = null; EventHandler handler4 = null; EventHandler handler5 = null; EventHandler handler6 = null; EventHandler handler7 = null; EventHandler handler8 = null; EventHandler handler9 = null; EventHandler handler10 = null; CommunicationManager manager = new CommunicationManager(); manager.RxCtrl = new OSPReceiver(); manager.RxCtrl.ResetCtrl = new OSPReset(); StreamWriter writer = null; StreamWriter writer2 = null; StreamReader reader = null; LargeFileHandler handler = null; Thread.CurrentThread.CurrentCulture = clsGlobal.MyCulture; try { foreach (string str in this.toRunList) { if (!File.Exists(str)) { this._processesdFilesCount++; if (method == null) { method = delegate { this.processedFilesLabel.Text = string.Format("Files Processed: {0}", this._processesdFilesCount); }; } this.processedFilesLabel.BeginInvoke(method); continue; } string str2 = string.Empty; string path = string.Empty; string str4 = string.Empty; if (str.EndsWith(".gp2")) { path = str.Replace(".gp2", ".gps"); } else if (str.EndsWith(".gpx")) { path = str.Replace(".gpx", ".gps"); } else if (str.EndsWith(".bin")) { path = str.Replace(".bin", ".gps"); str4 = str.Replace(".bin", ".gp2"); } else if (str.EndsWith(".gps")) { if (this.useSSBMsg41) { path = str.Replace(".gps", "_msg41.nmea"); } else if (this.useOspMsg69) { path = str.Replace(".gps", "_msg69.nmea"); } else if (this.autoDetect) { path = str.Replace(".gps", "_auto.nmea"); str4 = str.Replace(".gps", ".msg69parse"); } else { path = str.Replace(".gps", ".nmea"); } } else { path = str.Substring(0, str.Length - 4) + ".gps"; } writer = new StreamWriter(path); reader = new StreamReader(str); FileInfo info = new FileInfo(str); double length = info.Length; if (length == 0.0) { this._processesdFilesCount++; if (handler3 == null) { handler3 = delegate { this.processedFilesLabel.Text = string.Format("Files Processed: {0}", this._processesdFilesCount); }; } this.processedFilesLabel.BeginInvoke(handler3); continue; } if (handler4 == null) { handler4 = delegate { this.progressBar1.Value = 0; this.progressBar1.Maximum = 100; this.progressBar1.Minimum = 0; }; } this.progressBar1.BeginInvoke(handler4); long num2 = 0L; string str13 = this._fileType; if (str13 != null) { if (!(str13 == ".bin")) { if (str13 == ".gpx") { goto Label_042F; } if (str13 == ".gps") { goto Label_055C; } } else { reader.Close(); FileStream stream = File.OpenRead(str); writer2 = new StreamWriter(str4); if (handler5 == null) { handler5 = delegate { this.fileProcessedStatusLabel.Text = "Status: converting..."; }; } this.fileProcessedStatusLabel.BeginInvoke(handler5); int offset = 0; int count = 0x1000; byte[] buffer = new byte[count]; int len = stream.Read(buffer, offset, count); while (len > 0) { manager.SetupRxCtrl(); manager.PopulateData(buffer, len); string str5 = manager.ByteToMsgQueue(new byte[1]); string[] separator = new string[] { "\r\n" }; foreach (string str6 in str5.Split(separator, StringSplitOptions.None)) { string str7 = manager.m_Protocols.ConvertRawToFields(HelperFunctions.HexToByte(str6)); writer.WriteLine(str7); writer2.WriteLine(CommonUtilsClass.LogToGP2(str6, string.Empty)); } offset += len; int percent = (int) ((((double) offset) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); len = stream.Read(buffer, 0, count); if (this._abort) { break; } } stream.Close(); writer2.Close(); } } goto Label_0A75; Label_042F: if (handler6 == null) { handler6 = delegate { this.fileProcessedStatusLabel.Text = "Status: converting..."; }; } this.fileProcessedStatusLabel.BeginInvoke(handler6); while ((str2 = reader.ReadLine()) != null) { num2 += str2.Length; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); try { if (str2.Contains("A0 A2")) { int index = str2.IndexOf("A0 A2"); byte[] comByte = HelperFunctions.HexToByte(str2.Substring(index)); string str9 = manager.m_Protocols.ConvertRawToFields(comByte); if (this.includeDateTimeChkBox.Checked) { writer.WriteLine(str2.Substring(0, index) + " " + str9); } else { writer.WriteLine(str9); } } else { writer.WriteLine(str2); } } catch { writer.WriteLine(str2); continue; } if (this._abort) { break; } } goto Label_0A75; Label_055C: reader.Close(); Queue<uint> queue = new Queue<uint>(); Queue<long> queue2 = new Queue<long>(); reader = new StreamReader(str); long item = 0L; if (this.autoDetect) { writer2 = new StreamWriter(str4); if (handler7 == null) { handler7 = delegate { this.fileProcessedStatusLabel.Text = "Status: scanning..."; }; } this.fileProcessedStatusLabel.BeginInvoke(handler7); str2 = reader.ReadLine(); while (str2 != null) { str2 = str2.Replace(" ", ""); if (str2.StartsWith("69,1")) { try { string[] strArray3 = str2.Split(new char[] { ',' }); if (strArray3.Length > 9) { uint num8 = Convert.ToUInt32(strArray3[9]); writer2.WriteLine(string.Format("{0} -- {1}", num8, strArray3[5])); if ((strArray3[3] != "0") && (strArray3[5] == "1")) { queue.Enqueue(num8); queue2.Enqueue(item); } } } catch { } } str2 = reader.ReadLine(); } writer2.Close(); reader.Close(); reader = new StreamReader(str); } if (handler8 == null) { handler8 = delegate { this.fileProcessedStatusLabel.Text = "Status: converting..."; }; } this.fileProcessedStatusLabel.BeginInvoke(handler8); while ((str2 = reader.ReadLine()) != null) { string str11; num2 += str2.Length; int percent = (int) ((((double) num2) / length) * 100.0); if (percent > 100) { percent = 100; } this.progressBar1.BeginInvoke((MethodInvoker)delegate { this.progressBar1.Value = percent; }); str2 = str2.TrimEnd(new char[] { '\n' }).TrimEnd(new char[] { '\r' }).Replace(" ", ""); if (str2.StartsWith("4,")) { string[] strArray4 = str2.Split(new char[] { ',' }); string str10 = this.GPS_NMEA_OutputGSV(strArray4); if (str10 != string.Empty) { writer.Write(str10); } goto Label_0A5F; } if (!str2.StartsWith("41,")) { goto Label_096E; } if (!this.useSSBMsg41 && !this.autoDetect) { goto Label_0A5F; } string[] msgArray = str2.Split(new char[] { ',' }); if (msgArray.Length < 0x22) { item = handler.Index + 1L; str2 = handler[item]; continue; } if ((queue.Count > 0) && this.autoDetect) { uint num9 = Convert.ToUInt32(msgArray[4]); uint num10 = queue.Peek(); long num11 = queue2.Peek(); if (num9 == num10) { queue.Dequeue(); queue2.Dequeue(); } else { if (num9 > num10) { if (item > num11) { while (item > num11) { queue.Dequeue(); queue2.Dequeue(); num10 = queue.Peek(); num11 = queue2.Peek(); if (num9 == num10) { break; } } if (item > num11) { goto Label_08C6; } continue; } item = handler.Index + 1L; str2 = handler[item]; continue; } item = handler.Index + 1L; str2 = handler[item]; continue; } } Label_08C6: str11 = this.GPS_NMEA_OutputGGA(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputRMC(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputGLL(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputGSA(msgArray); if (str11 != string.Empty) { writer.Write(str11); } str11 = this.GPS_NMEA_OutputVTG(msgArray); if (str11 != string.Empty) { writer.Write(str11); } goto Label_0A5F; Label_096E: if (str2.StartsWith("69,1") && this.useOspMsg69) { string[] strArray6 = new string[0x24]; if (this.msg69ToMsg4AndMsg41Format(str2, ref strArray6) != 0) { item = handler.Index + 1L; str2 = handler[item]; continue; } string str12 = this.GPS_NMEA_OutputGGA(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputRMC(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputGLL(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputGSA(strArray6); if (str12 != string.Empty) { writer.Write(str12); } str12 = this.GPS_NMEA_OutputVTG(strArray6); if (str12 != string.Empty) { writer.Write(str12); } } Label_0A5F: if (this._abort) { break; } } Label_0A75: if (this._abort) { break; } reader.Close(); writer.Close(); this._processesdFilesCount++; if (handler9 == null) { handler9 = delegate { this.processedFilesLabel.Text = string.Format("Files Processed: {0}", this._processesdFilesCount); }; } this.processedFilesLabel.BeginInvoke(handler9); } if (this._abort) { MessageBox.Show("Conversion Aborted", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); if (reader != null) { reader.Close(); } if (writer != null) { writer.Close(); } if (writer2 != null) { writer2.Close(); } if (handler != null) { handler.Close(); } } else { MessageBox.Show("Conversion Done", "Information", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); } this._processingStatus = false; } catch (Exception exception) { if (reader != null) { reader.Close(); } if (writer != null) { writer.Close(); } if (writer2 != null) { writer2.Close(); } if (handler != null) { handler.Close(); } this._processingStatus = false; this._abort = false; MessageBox.Show("Error: " + exception.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Hand); } try { if (handler10 == null) { handler10 = delegate { this.fileProcessedStatusLabel.Text = "Status: idle"; }; } this.fileProcessedStatusLabel.BeginInvoke(handler10); } catch { } manager.Dispose(); manager = null; }