public GPSGeoFenceMsgBox(bool bIn, GPSGeoFenceData geoFence, GPSSource gpsSource) { m_bIn = bIn; m_GeoFence = geoFence; m_GpsSource = gpsSource; InitializeComponent(); pictureBoxGeoFence.ImageLocation = m_GpsSource.sIconPath; labelMessage.Text = m_GpsSource.sDescription + " is "; if (bIn) labelMessage.Text += "inside "; else labelMessage.Text += "outside "; labelMessage.Text += "GeoFence Zone " + geoFence.sName; labelLatitude.Text = ""; labelLongitude.Text = ""; string sLocation = ""; string sNS; if (m_GpsSource.GpsPos.m_fLat >= (float)0) sNS = "N"; else sNS = "S"; double dLat = Math.Abs(m_GpsSource.GpsPos.m_fLat); double dWhole = Math.Floor(dLat); double dFraction = dLat - dWhole; double dMin = dFraction * (double)60; double dMinWhole = Math.Floor(dMin); double dSeconds = (dMin - dMinWhole) * (double)60; int iDegrees = Convert.ToInt32(dWhole); int iMinutes = Convert.ToInt32(dMinWhole); float fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "°" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sNS; labelLatitude.Text = sLocation; string sEW; if (m_GpsSource.GpsPos.m_fLon >= (float)0) sEW = "E"; else sEW = "W"; double dLon = Math.Abs(m_GpsSource.GpsPos.m_fLon); dWhole = Math.Floor(dLon); dFraction = dLon - dWhole; dMin = dFraction * (double)60; dMinWhole = Math.Floor(dMin); dSeconds = (dMin - dMinWhole) * (double)60; iDegrees = Convert.ToInt32(dWhole); iMinutes = Convert.ToInt32(dMinWhole); fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "°" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sEW; labelLongitude.Text = sLocation; labelTime.Text = DateTime.Now.ToString(); Thread threadMsg = new Thread(new ThreadStart(this.threadShowMsg)); threadMsg.IsBackground = true; threadMsg.Priority = System.Threading.ThreadPriority.Normal; threadMsg.Start(); }
public void threadStartUSB() { int iIndex = Int32.Parse(Thread.CurrentThread.Name); GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; while (m_GpsTracker.m_fCloseThreads == false) { lock ("threadStartUSB") { //Use GpsBabel string sBabelCommandLine = "-T;-i;" + gpsSource.sUSBDevice + ";-f;usb:;-o;kml;-F;" + GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml;"; if (File.Exists(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml")) { File.Delete(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml"); } m_GpsBabel.Execute(sBabelCommandLine); if (File.Exists(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml")) { FileInfo fInfo = new FileInfo(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml"); if (fInfo.Length > 0) { sBabelCommandLine = "-w;-i;kml;-f;" + GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".kml;"; sBabelCommandLine += "-o;nmea;-F;" + GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea;"; if (File.Exists(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea")) { File.Delete(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea"); } m_GpsBabel.Execute(sBabelCommandLine); if (File.Exists(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea")) { fInfo = new FileInfo(GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea"); if (fInfo.Length > 0) { gpsSource.sFileNameSession = GpsTrackerPlugin.m_sPluginDirectory + "\\USB" + Convert.ToString(iIndex) + ".nmea"; gpsSource.iFilePlaySpeed = 0; gpsSource.iReload = 1; gpsSource.bBabelNMEA = true; gpsSource.datePosition = fInfo.LastWriteTimeUtc; threadFile(); } } } } } Thread.Sleep(500); } gpsSource.eventThreadSync.Set(); }
public GeoFenceSetup(GPSGeoFence gpsGeoFence, GpsTrackerPlugin Plugin) { m_GpsGeoFence = gpsGeoFence; m_Plugin = Plugin; InitializeComponent(); textBoxSoundFile.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFence.wav"; textBoxSoundFileOut.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFenceOut.wav"; comboBoxGeoFenceSource.Items.Add("All Gps Sources"); for (int i = 0; i < m_Plugin.gpsTracker.m_gpsSourceList.Count; i++) { GPSSource gpsSource = (GPSSource)m_Plugin.gpsTracker.m_gpsSourceList[i]; if (gpsSource.sType != "POI" && gpsSource.sType != "GeoFence" && gpsSource.bWaypoints == false && gpsSource.bSetup) { comboBoxGeoFenceSource.Items.Add(gpsSource.sDescription); } } comboBoxGeoFenceSource.Text = "All Gps Sources"; }
public GPSGeoFenceMsgBox(bool bIn, GPSGeoFenceData geoFence, GPSSource gpsSource) { m_bIn = bIn; m_GeoFence = geoFence; m_GpsSource = gpsSource; InitializeComponent(); pictureBoxGeoFence.ImageLocation = m_GpsSource.sIconPath; labelMessage.Text = m_GpsSource.sDescription + " is "; if (bIn) { labelMessage.Text += "inside "; } else { labelMessage.Text += "outside "; } labelMessage.Text += "GeoFence Zone " + geoFence.sName; labelLatitude.Text = ""; labelLongitude.Text = ""; string sLocation = ""; string sNS; if (m_GpsSource.GpsPos.m_fLat >= (float)0) { sNS = "N"; } else { sNS = "S"; } double dLat = Math.Abs(m_GpsSource.GpsPos.m_fLat); double dWhole = Math.Floor(dLat); double dFraction = dLat - dWhole; double dMin = dFraction * (double)60; double dMinWhole = Math.Floor(dMin); double dSeconds = (dMin - dMinWhole) * (double)60; int iDegrees = Convert.ToInt32(dWhole); int iMinutes = Convert.ToInt32(dMinWhole); float fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "?" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sNS; labelLatitude.Text = sLocation; string sEW; if (m_GpsSource.GpsPos.m_fLon >= (float)0) { sEW = "E"; } else { sEW = "W"; } double dLon = Math.Abs(m_GpsSource.GpsPos.m_fLon); dWhole = Math.Floor(dLon); dFraction = dLon - dWhole; dMin = dFraction * (double)60; dMinWhole = Math.Floor(dMin); dSeconds = (dMin - dMinWhole) * (double)60; iDegrees = Convert.ToInt32(dWhole); iMinutes = Convert.ToInt32(dMinWhole); fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "?" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sEW; labelLongitude.Text = sLocation; labelTime.Text = DateTime.Now.ToString(); Thread threadMsg = new Thread(new ThreadStart(this.threadShowMsg)); threadMsg.IsBackground = true; threadMsg.Priority = System.Threading.ThreadPriority.Normal; threadMsg.Start(); }
public void threadFile() { int iIndex = Int32.Parse(Thread.CurrentThread.Name); GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; int iIndexFile; int iIndexNext; StreamReader fsGpsFile = null; System.Text.ASCIIEncoding asciiEncoder = new System.Text.ASCIIEncoding(); String sGpsLine = null; String sIndex; byte [] byNMEA; char [] cNMEA = null; char [] cNMEAMsg = new char[512]; DateTime dtCurrent; DateTime dtNext = new DateTime(0); int iEnd = 0; bool bRestartTrack = false; try { if (File.Exists(gpsSource.sFileNameSession)) { while (m_GpsTracker.m_fCloseThreads == false) { bRestartTrack = true; fsGpsFile = File.OpenText(gpsSource.sFileNameSession); { if (m_GpsTracker.m_fPlayback == true) { m_GpsTracker.LoadSettings(fsGpsFile, false); iIndexFile = iIndex + 1; do { sIndex = fsGpsFile.ReadLine(); if (sIndex != null) { iEnd = sIndex.IndexOf(","); } if (sIndex != null && iEnd > 0) { iIndexFile = Convert.ToInt32(sIndex.Substring(0, iEnd)); if (iIndexFile == iIndex && sIndex.Length > iEnd + 1) { sGpsLine = sIndex.Substring(iEnd + 1); break; } } else { break; } } while(m_GpsTracker.m_fCloseThreads == false); } else { sIndex = "dummyindex"; iIndexFile = iIndex; sGpsLine = fsGpsFile.ReadLine(); } if (sGpsLine != null) { byNMEA = asciiEncoder.GetBytes(sGpsLine); cNMEA = asciiEncoder.GetChars(byNMEA); cNMEA.CopyTo(cNMEAMsg, 0); if (m_GpsTracker.m_iPlaybackSpeed > 0) { dtNext = m_GpsTracker.m_NMEA.GetNMEATime(-1, sGpsLine); } } while (sIndex != null && sGpsLine != null && m_GpsTracker.m_fCloseThreads == false && iIndexFile == iIndex) { if (sGpsLine != "" && sIndex != "") { try { if (m_GpsTracker.m_MessageMonitor != null) { m_GpsTracker.m_MessageMonitor.AddMessageFileRaw(sGpsLine); } } catch (Exception) { m_GpsTracker.m_MessageMonitor = null; } if (m_GpsTracker.ShowGPSIcon(cNMEAMsg, cNMEA.Length, false, iIndex, bRestartTrack, true) == true) { if (bRestartTrack) { bRestartTrack = false; } //Get current NMEA msg time dtCurrent = dtNext; while (m_GpsTracker.m_fCloseThreads == false) { //Get next line from file if (m_GpsTracker.m_fPlayback == true) { sIndex = fsGpsFile.ReadLine(); if (sIndex != null) { iEnd = sIndex.IndexOf(","); if (iEnd > 0 && sIndex.Length > iEnd + 1) { sGpsLine = sIndex.Substring(iEnd + 1); sIndex = sIndex.Substring(0, iEnd); } else { sIndex = ""; } } } else { sIndex = Convert.ToString(iIndex); sGpsLine = fsGpsFile.ReadLine(); } if (sGpsLine == null || sIndex == null) { break; } else if (sGpsLine != "" && sIndex != "") { iIndexNext = Convert.ToInt32(sIndex); byNMEA = asciiEncoder.GetBytes(sGpsLine); cNMEA = asciiEncoder.GetChars(byNMEA); cNMEA.CopyTo(cNMEAMsg, 0); //Check is a valid NMEA message if (iIndexNext == iIndex && m_GpsTracker.m_NMEA.ParseGPSMessage(cNMEAMsg, cNMEA.Length, true, iIndex) == true) { if (m_GpsTracker.m_iPlaybackSpeed > 0 && gpsSource.iFilePlaySpeed > 0) { //Get time difference from current msg to next message... dtNext = m_GpsTracker.m_NMEA.GetNMEATime(-1, sGpsLine); //Check valid times if (dtCurrent.Year != 1771 && dtNext.Year != 1771) { if (dtNext < dtCurrent) { dtNext = dtNext.AddDays(1); } TimeSpan tsDelay = dtNext.Subtract(dtCurrent); double dDelay = tsDelay.TotalMilliseconds; //apply selected speed double dSpeed = Convert.ToDouble(gpsSource.iFilePlaySpeed); dDelay /= dSpeed; dDelay /= m_GpsTracker.m_iPlaybackSpeed; Thread.Sleep(Convert.ToInt32(dDelay)); break; } else { Thread.Sleep(1); break; } } else { Thread.Sleep(1); break; } } else { Thread.Sleep(1); } } else { Thread.Sleep(1); //break; } } //while } //show else { sIndex = "dummyindex"; iIndexFile = iIndex; sGpsLine = fsGpsFile.ReadLine(); if (sGpsLine != null) { byNMEA = asciiEncoder.GetBytes(sGpsLine); cNMEA = asciiEncoder.GetChars(byNMEA); cNMEA.CopyTo(cNMEAMsg, 0); if (m_GpsTracker.m_iPlaybackSpeed > 0) { dtNext = m_GpsTracker.m_NMEA.GetNMEATime(-1, sGpsLine); } } Thread.Sleep(1); } } // if gpsline else { if (sGpsLine == "") { sGpsLine = fsGpsFile.ReadLine(); } Thread.Sleep(1); //break; } } //while if (fsGpsFile != null) { fsGpsFile.Close(); fsGpsFile = null; } if (gpsSource.iReload == 0 && m_GpsTracker.m_fCloseThreads == false) { Thread.Sleep(3000); } else { break; } } //using } } //exists } catch (Exception) { } if (fsGpsFile != null) { fsGpsFile.Close(); fsGpsFile = null; } }
// // File functions // public void PreprocessFile(int iIndex, String sFileName, string sRealName, bool bCheckPre, bool bForePreprocessing) { GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; #if !DEBUG try #endif { //check if preprocess exists if ((File.Exists(sFileName + ".TrackAtOnce") || IsTrackAtOnce(sFileName)) && (bForePreprocessing == false || bCheckPre)) { string sTAOFileName; if (IsTrackAtOnce(sFileName)) { sTAOFileName = sFileName; } else { sTAOFileName = sFileName + ".TrackAtOnce"; } gpsSource.GpsPos.m_gpsTrack = null; BinaryReader binReader = new BinaryReader(File.Open(sTAOFileName, FileMode.Open)); // If the file is not empty, // read it if (binReader.PeekChar() != -1) { gpsSource.GpsPos.m_gpsTrack = new GPSTrack(); string sSign = "GPSTracker.TrackAtOnce"; char [] sSignature = binReader.ReadChars(sSign.Length); string sSignCompare = new string(sSignature); if (sSignCompare == sSign) { gpsSource.GpsPos.m_gpsTrack.m_uPointCount = binReader.ReadUInt32(); gpsSource.GpsPos.m_gpsTrack.SetSize(gpsSource.GpsPos.m_gpsTrack.m_uPointCount); byte[] byData = new byte[gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8]; byData = binReader.ReadBytes((int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); System.Buffer.BlockCopy(byData, 0, gpsSource.GpsPos.m_gpsTrack.m_fLat, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); byData = binReader.ReadBytes((int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); System.Buffer.BlockCopy(byData, 0, gpsSource.GpsPos.m_gpsTrack.m_fLon, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); byData = binReader.ReadBytes((int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 4); System.Buffer.BlockCopy(byData, 0, gpsSource.GpsPos.m_gpsTrack.m_fAlt, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 4); } } binReader.Close(); } else { uint uProgress; uint uMaxProgress; StreamReader fsGpsFile = null; String sGpsLine; byte [] byNMEA; char [] cNMEA = null; char [] cNMEAMsg = new char[512]; System.Text.ASCIIEncoding asciiEncoder = new System.Text.ASCIIEncoding(); if (File.Exists(sFileName) && !IsTrackAtOnce(sFileName)) { FileInfo fInfo = new FileInfo(sFileName); uProgress = 0; uMaxProgress = (uint)fInfo.Length; m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Processing " + sRealName + ": " + Convert.ToString(uProgress) + " of " + Convert.ToString(uMaxProgress) + " bytes."); fsGpsFile = File.OpenText(sFileName); gpsSource.GpsPos.m_gpsTrack = new GPSTrack(); gpsSource.GpsPos.m_gpsTrack.SetSize(500); //set an initial array size for the track uint uResizeArraySize = 500; while (true) { sGpsLine = fsGpsFile.ReadLine(); if (sGpsLine == null) { break; } uProgress += (uint)sGpsLine.Length; m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Processing " + sRealName + ": " + Convert.ToString(uProgress) + " of " + Convert.ToString(uMaxProgress) + " bytes."); byNMEA = asciiEncoder.GetBytes(sGpsLine); cNMEA = asciiEncoder.GetChars(byNMEA); cNMEA.CopyTo(cNMEAMsg, 0); if (m_GpsTracker.m_NMEA.ParseGPSMessage(cNMEAMsg, cNMEA.Length, false, iIndex) == true) { gpsSource.GpsPos.m_gpsTrack.AddPoint(gpsSource.GpsPos.m_fLat, gpsSource.GpsPos.m_fLon, gpsSource.GpsPos.m_fAlt); } //Keep resizing the track array as necessary if (gpsSource.GpsPos.m_gpsTrack.m_uPointCount >= uResizeArraySize) { uResizeArraySize += 100; gpsSource.GpsPos.m_gpsTrack.Resize(uResizeArraySize); } } uProgress = (uint)fInfo.Length; m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Processing " + sRealName + ": " + Convert.ToString(uProgress) + " of " + Convert.ToString(uMaxProgress) + " bytes."); fsGpsFile.Close(); //Resize track array to minimum size; gpsSource.GpsPos.m_gpsTrack.Resize(gpsSource.GpsPos.m_gpsTrack.m_uPointCount); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Creating " + sRealName + ".TrackAtOnce"); using (BinaryWriter binWriter = new BinaryWriter(File.Open(sFileName + ".TrackAtOnce", FileMode.Create))) { string sSign = "GPSTracker.TrackAtOnce"; char [] sSignature = new char[sSign.Length]; sSignature = sSign.ToCharArray(); binWriter.Write(sSignature); binWriter.Write(gpsSource.GpsPos.m_gpsTrack.m_uPointCount); byte[] byData = new byte[gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8]; System.Buffer.BlockCopy(gpsSource.GpsPos.m_gpsTrack.m_fLat, 0, byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); binWriter.Write(byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); System.Buffer.BlockCopy(gpsSource.GpsPos.m_gpsTrack.m_fLon, 0, byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); binWriter.Write(byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 8); System.Buffer.BlockCopy(gpsSource.GpsPos.m_gpsTrack.m_fAlt, 0, byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 4); binWriter.Write(byData, 0, (int)gpsSource.GpsPos.m_gpsTrack.m_uPointCount * 4); binWriter.Close(); } } } } #if !DEBUG catch (Exception) { m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); } #endif m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); }
public void threadStartFile() { int iIndex = Int32.Parse(Thread.CurrentThread.Name); GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; bool bShowError = true; while (m_GpsTracker.m_fCloseThreads == false) { gpsSource.GpsPos.m_gpsTrack = null; try { string sFileName = ""; lock ("threadStartFile") { m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Downloading " + gpsSource.sFileName); WebClient myWebClient = new WebClient(); sFileName = GpsTrackerPlugin.m_sPluginDirectory + "\\DownloadedFile" + Convert.ToString(iIndex) + ".gpsTracker"; if (File.Exists(sFileName)) { File.Delete(sFileName); } string sWebReload = ""; if (!File.Exists(gpsSource.sFileName)) { sWebReload = "?r=" + System.Guid.NewGuid().ToString(); } myWebClient.DownloadFile(gpsSource.sFileName + sWebReload, sFileName); } if (File.Exists(sFileName)) { gpsSource.bBabelNMEA = false; lock ("threadStartFile") { //Convert files to a known format switch (gpsSource.saGpsBabelFormat[0]) { case "nasabaloon": if (m_GpsTracker.m_NMEA.CheckConvertNasaBaloon(sFileName, gpsSource.sFileName)) { sFileName = sFileName + ".NMEAText"; } break; case "aprs": case "nmea": case "GpsTracker": case "Unknown": //Nothing to convert break; default: //Use GpsBabel string sBabelCommandLine; if (gpsSource.bWaypoints) { sBabelCommandLine = "-w;"; } else { sBabelCommandLine = "-t;-r;"; } sBabelCommandLine += "-i;" + gpsSource.saGpsBabelFormat[0] + ";"; sBabelCommandLine += "-f;" + sFileName + ";"; if (gpsSource.bWaypoints) { sBabelCommandLine += "-o;csv;-F;" + sFileName + ".WaypointsCSV;"; if (File.Exists(sFileName + ".WaypointsCSV")) { File.Delete(sFileName + ".WaypointsCSV"); } } else { sBabelCommandLine += "-o;nmea;-F;" + sFileName + ".NMEAText;"; if (File.Exists(sFileName + ".NMEAText")) { File.Delete(sFileName + ".NMEAText"); } } m_GpsBabel.Execute(sBabelCommandLine); if (gpsSource.bWaypoints && File.Exists(sFileName + ".WaypointsCSV")) { FileInfo fInfo = new FileInfo(sFileName + ".WaypointsCSV"); if (fInfo.Length > 0) { sFileName += ".WaypointsCSV"; } } else if (gpsSource.bWaypoints == false && File.Exists(sFileName + ".NMEAText")) { FileInfo fInfo = new FileInfo(sFileName + ".NMEAText"); if (fInfo.Length > 0) { sFileName += ".NMEAText"; gpsSource.bBabelNMEA = true; } } break; } } if (gpsSource.bTrackAtOnce != true && !m_GpsTracker.m_File.IsTrackAtOnce(sFileName)) { if (!gpsSource.bWaypoints) { m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); gpsSource.sFileNameSession = sFileName; gpsSource.iFilePlaySpeed = gpsSource.iPlaySpeed; threadFile(); } else { m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); ArrayList listWaypoints = new ArrayList(); StreamReader sReader = null; try { sReader = File.OpenText(sFileName); string sLine; do { sLine = sReader.ReadLine(); if (sLine != null) { listWaypoints.Add(sLine); } } while(sLine != null); } catch (Exception) { } if (sReader != null) { sReader.Close(); } if (listWaypoints.Count > 0) { char [] cSep = { ',' }; bool bTrack = gpsSource.bTrack; for (int i = 0; i < listWaypoints.Count; i++) { string sFormat = (string)listWaypoints[i]; string [] sWaypointData; sWaypointData = sFormat.Split(cSep); if (sWaypointData.Length == 3) { try { m_GpsTracker.AddPOI(sWaypointData[2], Convert.ToDouble(sWaypointData[0]), Convert.ToDouble(sWaypointData[1]), false, gpsSource); if (gpsSource.bTrack) { gpsSource.bTrack = false; } } catch (Exception) { Thread.Sleep(200); } } } gpsSource.bTrack = bTrack; } } } else { if (gpsSource.iReload > 0 && File.Exists(sFileName + ".TrackAtOnce")) { File.Delete(sFileName + ".TrackAtOnce"); } lock ("threadStartFile") { //track at once m_GpsTracker.m_File.PreprocessFile(iIndex, sFileName, gpsSource.sFileName, false, gpsSource.bForcePreprocessing); } GPSRenderInformation renderInfo = new GPSRenderInformation(); renderInfo.bPOI = false; renderInfo.iIndex = iIndex; renderInfo.sDescription = gpsSource.sDescription; renderInfo.fFix = false; renderInfo.bShowInfo = m_GpsTracker.m_bInfoText; renderInfo.bTrackLine = false; renderInfo.gpsTrack = gpsSource.GpsPos.m_gpsTrack; renderInfo.bRestartTrack = false; renderInfo.iDay = gpsSource.GpsPos.m_iDay; renderInfo.iMonth = gpsSource.GpsPos.m_iMonth; renderInfo.iYear = gpsSource.GpsPos.m_iYear; renderInfo.colorTrack = gpsSource.colorTrack; renderInfo.sIcon = gpsSource.sIconPath; // while (m_GpsTracker.m_fCloseThreads == false) // { m_GpsTracker.m_gpsTrackerPlugin.pluginShowOverlay(renderInfo); if (gpsSource.bTrack == true) { m_GpsTracker.m_gpsTrackerPlugin.pluginWorldWindowGotoLatLonHeading(gpsSource.GpsPos.m_gpsTrack.m_fLat[0], gpsSource.GpsPos.m_gpsTrack.m_fLon[0], -1F, gpsSource.iStartAltitud); } if (gpsSource.iStartAltitud > 0) { gpsSource.iStartAltitud = 0; } // Thread.Sleep(3000); // } } } if (gpsSource.iReload == 0 || m_GpsTracker.m_fCloseThreads == true) { break; } else { for (int i = 0; i < gpsSource.iReload && m_GpsTracker.m_fCloseThreads == false; i++) { Thread.Sleep(1000); } } } catch (Exception) { if (bShowError) { lock ("threadStartFile") { bShowError = false; m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Unable to Download " + gpsSource.sFileName + ". Retrying in the background."); for (int i = 0; i < 5 && m_GpsTracker.m_fCloseThreads == false; i++) { Thread.Sleep(1000); } m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); } for (int i = 0; i < 60 && m_GpsTracker.m_fCloseThreads == false; i++) { Thread.Sleep(1000); } } else { m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo(""); m_GpsTracker.m_gpsTrackerPlugin.pluginShowFixInfo("GPSTracker: Active"); for (int i = 0; i < 60 && m_GpsTracker.m_fCloseThreads == false; i++) { Thread.Sleep(1000); } } } } gpsSource.eventThreadSync.Set(); }
// //sCallSign is the call sign get data from //use * as wild card (only at the end of the call sign): //eg: sCallSign=N9UMJ-15 //eg: sCallSign=N9UMJ* //eg: sCallSign=* - get data from all available call signs public void threadAPRSIS() { int iIndex = Int32.Parse(Thread.CurrentThread.Name); GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; string sCallSign = gpsSource.sCallSign; int iRefresh = gpsSource.iRefreshRate; while (sCallSign != null && sCallSign.Length > 0 && m_GpsTracker.m_fCloseThreads == false) { try { HttpWebRequest request = null; request = (HttpWebRequest)WebRequest.Create(gpsSource.sAPRSServerURL.Trim() + sCallSign); HttpWebResponse response = null; // execute the request response = (HttpWebResponse)request.GetResponse(); // we will read data via the response stream Stream resStream = response.GetResponseStream(); resStream.ReadTimeout = 60000; int iRead; byte[] byChar = new byte[1]; StringBuilder sbMsg = new StringBuilder(""); do { iRead = resStream.ReadByte(); if (iRead >= 0) { byChar[0] = Convert.ToByte(iRead); if (byChar[0] != '\r' && byChar[0] != '\n') { sbMsg.Append(Encoding.ASCII.GetString(byChar)); } else { string sMsg = sbMsg.ToString(); try { if (m_GpsTracker.m_MessageMonitor != null) { m_GpsTracker.m_MessageMonitor.AddMessageUnfilteredAPRS(sMsg); } } catch (Exception) { m_GpsTracker.m_MessageMonitor = null; } char [] cMessage = sMsg.ToCharArray(); if (!m_GpsTracker.ShowGPSIcon(cMessage, sMsg.Length, false, iIndex, false, true)) { if (sMsg.StartsWith("\"packet_id\"") == false) { CSVReader csvReader = new CSVReader(); string [] sMsgField = csvReader.GetCSVLine(sMsg); if (sMsgField != null && sMsgField.Length == 14) { //Display icon gpsSource.GpsPos.m_sName = sMsgField[1]; if (sMsgField[2] != "") { gpsSource.GpsPos.m_fLat = Convert.ToSingle(sMsgField[2]); } if (sMsgField[3] != "") { gpsSource.GpsPos.m_fLon = Convert.ToSingle(sMsgField[3]); } if (sMsgField[4] != "") { gpsSource.GpsPos.m_fHeading = Convert.ToSingle(sMsgField[4]); } if (sMsgField[5] != "") { gpsSource.GpsPos.m_fSpeed = Convert.ToSingle(sMsgField[5]); } if (sMsgField[6] != "") { gpsSource.GpsPos.m_fAlt = Convert.ToSingle(sMsgField[6]); } if (sMsgField[7] != "") { gpsSource.GpsPos.m_iAPRSIconTable = Convert.ToInt32(Convert.ToChar(sMsgField[7])); } if (sMsgField[8] != "") { gpsSource.GpsPos.m_iAPRSIconCode = Convert.ToInt32(Convert.ToChar(sMsgField[8])); } gpsSource.GpsPos.m_sComment = sMsgField[9]; if (sMsgField[13] != "") { DateTime dateAPRS = new DateTime(0); dateAPRS = DateTime.Parse(sMsgField[13]); gpsSource.GpsPos.m_iYear = dateAPRS.Year; gpsSource.GpsPos.m_iMonth = dateAPRS.Month; gpsSource.GpsPos.m_iDay = dateAPRS.Day; gpsSource.GpsPos.m_iHour = dateAPRS.Hour; gpsSource.GpsPos.m_iMin = dateAPRS.Minute; gpsSource.GpsPos.m_iSec = Convert.ToSingle(dateAPRS.Second); } gpsSource.GpsPos.m_fRoll = -1000F; gpsSource.GpsPos.m_fPitch = -1000F; gpsSource.GpsPos.m_fESpeed = -1000000; gpsSource.GpsPos.m_fNSpeed = -1000000; gpsSource.GpsPos.m_fVSpeed = -1000000; gpsSource.GpsPos.m_fDepth = -1000000; gpsSource.GpsPos.m_sAltUnit = "m"; gpsSource.GpsPos.m_sSpeedUnit = "km\\h"; sMsg = "APRS:" + sMsg; cMessage = sMsg.ToCharArray(); m_GpsTracker.ShowGPSIcon(cMessage, sMsg.Length, false, iIndex, false, false); } } } sbMsg = new StringBuilder(""); } } } while (iRead >= 0 && m_GpsTracker.m_fCloseThreads == false); } catch (Exception) { } for (int iDelay = 0; iDelay < (iRefresh * 2); iDelay++) { if (m_GpsTracker.m_fCloseThreads == true) { break; } Thread.Sleep(500); } } gpsSource.eventThreadSync.Set(); }
public bool Parse(string sMsg, int iIndex) { bool bRet = false; //Init APRS structures APRSPOSITION aprsPosition = new APRSPOSITION(); APRSSTATUS aprsStatus = new APRSSTATUS(); aprsPosition.source = new string(' ', 10); aprsPosition.sentence = new string(' ', 6); aprsPosition.name = new string(' ', 10); aprsStatus.source = new string(' ', 10); aprsStatus.comment = new string(' ', 256); if (APRSParse(sMsg, ref aprsPosition, ref aprsStatus) >= 0) { bRet = false; GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex]; for (int i = 0; i < gpsSource.sCallSignFilterLines.Length - 1; i++) { string source = aprsPosition.source; string sourceFilter = gpsSource.sCallSignFilterLines[i]; int iWildIndex = sourceFilter.LastIndexOf('*'); if (iWildIndex == 0) { bRet = true; break; } else if (iWildIndex >= 1) { sourceFilter = sourceFilter.Substring(0, iWildIndex); if (source.ToUpper().StartsWith(sourceFilter.ToUpper())) { bRet = true; break; } } else if (iWildIndex == -1 && source.ToUpper() == sourceFilter.ToUpper()) { bRet = true; break; } } if (gpsSource.sCallSignFilterLines.Length <= 1) { bRet = true; } if (bRet) { gpsSource.GpsPos.m_fLat = Convert.ToSingle(aprsPosition.latitude); gpsSource.GpsPos.m_fLon = Convert.ToSingle(aprsPosition.longitude); gpsSource.GpsPos.m_fAlt = aprsPosition.altitude; gpsSource.GpsPos.m_fSpeed = aprsPosition.speed_over_ground; gpsSource.GpsPos.m_sName = aprsPosition.source; gpsSource.GpsPos.m_sComment = aprsStatus.comment; gpsSource.GpsPos.m_iAPRSIconCode = Convert.ToInt32(aprsStatus.symbol_code); gpsSource.GpsPos.m_iAPRSIconTable = Convert.ToInt32(aprsStatus.symbol_table); } } return(bRet); }
private bool ApplySettings(GPSSource gpsS, bool bNoSet, bool bCheck, bool bAddedPOI) { gpsS.bSetup=true; gpsS.bSave=true; if (bNoSet && bCheck) { labelTrackCode.Text=""; int i; for (i=0; i<m_gpsSourceList.Count; i++) { GPSSource gpsSource=(GPSSource)m_gpsSourceList[i]; GPSSource gpsSourceSelected=(GPSSource)treeViewSources.SelectedNode.Tag; if ( tabControlGPS.SelectedTab.Name == "tabPageCOM" && gpsSourceSelected!=gpsSource && gpsSource.bSetup==true && (gpsSource.sType=="COM" && gpsSource.iCOMPort==Convert.ToInt32(comboBoxCOMPort.Text))) { labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="COM Port " + comboBoxCOMPort.Text + " is already in use."; gpsS.bSetup=false; break; } if ( tabControlGPS.SelectedTab.Name == "tabPageUDP" && gpsSourceSelected!=gpsSource && gpsSource.bSetup==true && ( (gpsSource.sType=="UDP" && gpsSource.iUDPPort==(int)numericUpDownUDPPort.Value) || (gpsSource.sType=="TCP" && gpsSource.iTCPPort==(int)numericUpDownUDPPort.Value) ) ) { labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="Port " + numericUpDownUDPPort.Value.ToString().Trim() + " is already in use."; gpsS.bSetup=false; break; } if ( tabControlGPS.SelectedTab.Name == "tabPageTCP" && gpsSourceSelected!=gpsSource && gpsSource.bSetup==true && ( (gpsSource.sType=="UDP" && gpsSource.iUDPPort==(int)numericUpDownTCPPort.Value) || (gpsSource.sType=="TCP" && gpsSource.iTCPPort==(int)numericUpDownTCPPort.Value) ) ) { labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="Port " + numericUpDownTCPPort.Value.ToString().Trim() + " is already in use."; gpsS.bSetup=false; break; } } #if !DEBUG try #endif { float fLat; float fLon; if (tabControlGPS.SelectedTab.Name == "tabPagePOI") { fLat=Convert.ToSingle(textBoxLatitud.Text); fLon=Convert.ToSingle(textBoxLongitud.Text); if (fLat>=(float)-90 && fLat<=(float)90 && fLon>=(float)-180 && fLon<=(float)180) gpsS.bSetup=true; else { gpsS.bSetup=false; labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="Please enter a valid Latitud and Longitud."; } } } #if !DEBUG catch (Exception) { gpsS.bSetup=false; labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="Please enter a valid Latitud and Longitud."; } #endif } if (gpsS.bSetup==true) { bool bExport = false; gpsS.bNMEAExport = false; gpsS.sComment = ""; gpsS.swExport = null; switch(gpsS.sType) { case "COM": gpsS.iCOMPort=Convert.ToInt32(comboBoxCOMPort.Text); gpsS.iBaudRate=Convert.ToInt32(comboBoxBaudRate.Text); gpsS.iByteSize=Convert.ToInt32(comboBoxByteSize.Text); gpsS.iParity=comboParity.SelectedIndex; gpsS.iStopBits=comboBoxStopBits.SelectedIndex; gpsS.iFlowControl=comboBoxFlowControl.SelectedIndex; gpsS.colorTrack=buttonTrackColorCOM.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); bExport = checkBoxCOMExport.Checked; gpsS.bSetup=true; break; case "USB": gpsS.sUSBDevice=comboBoxUSBDevice.Text; gpsS.colorTrack=buttonTrackColorUSB.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); bExport = checkBoxUSBExport.Checked; gpsS.bSetup=true; break; case "GeoFence": int iVertices; if (bCheck) { gpsS.bSetup = false; if ((checkBoxGeoFenceEmailIn.Checked || checkBoxGeoFenceEmailOut.Checked) && textBoxEmailAddress.Text == "") { MessageBox.Show("Please, enter a valid email address.", "GpsTracker::Error", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } for (iVertices = 0; iVertices < listViewGeoFence.Items.Count; iVertices++) { if (listViewGeoFence.Items[iVertices].SubItems[1].Text == "" || listViewGeoFence.Items[iVertices].SubItems[2].Text == "") break; } if (iVertices <= 2) { MessageBox.Show("Please, enter at least 3 vertices to create a Geo Fence.", "GpsTracker::Error", MessageBoxButtons.OK, MessageBoxIcon.Information); break; } } labelGeoFenceSelectedSource.Text = comboBoxGeoFenceSource.Text; gpsS.GeoFence.sSource = comboBoxGeoFenceSource.Text; gpsS.GeoFence.sEmail = textBoxEmailAddress.Text; //gpsS.GeoFence.sName = if (textBoxSoundFile.Text=="") textBoxSoundFile.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFence.wav"; if (textBoxSoundFileOut.Text == "") textBoxSoundFileOut.Text = GpsTrackerPlugin.m_sPluginDirectory + "\\GeoFenceOut.wav"; gpsS.GeoFence.sSound = textBoxSoundFile.Text; gpsS.GeoFence.sSoundOut = textBoxSoundFileOut.Text; gpsS.GeoFence.bMsgBoxIn = checkBoxGeoFenceMsgBoxIn.Checked; gpsS.GeoFence.bMsgBoxOut = checkBoxGeoFenceMsgBoxOut.Checked; gpsS.GeoFence.bEmailIn = checkBoxGeoFenceEmailIn.Checked; gpsS.GeoFence.bEmailOut = checkBoxGeoFenceEmailOut.Checked; gpsS.GeoFence.bSoundIn = checkBoxGeoFenceSoundIn.Checked; gpsS.GeoFence.bSoundOut = checkBoxGeoFenceSoundOut.Checked; gpsS.GeoFence.arrayLat.Clear(); gpsS.GeoFence.arrayLon.Clear(); for (iVertices = 0; iVertices < listViewGeoFence.Items.Count; iVertices++) { if (listViewGeoFence.Items[iVertices].SubItems[1].Text == "" || listViewGeoFence.Items[iVertices].SubItems[2].Text == "") break; gpsS.GeoFence.arrayLat.Add((float)Convert.ToDouble(listViewGeoFence.Items[iVertices].SubItems[1].Text)); gpsS.GeoFence.arrayLon.Add((float)Convert.ToDouble(listViewGeoFence.Items[iVertices].SubItems[2].Text)); } gpsS.bSetup = true; break; case "UDP": gpsS.iUDPPort=(int)numericUpDownUDPPort.Value; gpsS.colorTrack=buttonTrackColorUDP.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); bExport = checkBoxUDPExport.Checked; gpsS.bSetup=true; break; case "TCP": gpsS.iTCPPort=(int)numericUpDownTCPPort.Value; gpsS.sTCPAddress=comboBoxTcpIP.Text.Trim(); gpsS.colorTrack=buttonTrackColorTCP.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); gpsS.bSecureSocket=checkBoxSecureSocket.Checked; if (bNoSet==true && gpsS.sTCPAddress!="") { int i; for (i=0; i<comboBoxTcpIP.Items.Count; i++) if ((String)comboBoxTcpIP.Items[i] == gpsS.sTCPAddress) break; if (i==comboBoxTcpIP.Items.Count) { if (comboBoxTcpIP.Items.Count==10) { for (i=1; i<=9; i++) comboBoxTcpIP.Items[i-1]=comboBoxTcpIP.Items[i]; comboBoxTcpIP.Items.RemoveAt(9); } comboBoxTcpIP.Items.Add(gpsS.sTCPAddress); } } if (gpsS.sTCPAddress == "") gpsS.bSetup = false; else { bExport = checkBoxTCPExport.Checked; gpsS.bSetup = true; } break; case "File": gpsS.iReload=Convert.ToInt32(numericUpDownReload.Value); gpsS.bSession=false; string sFileName; if (tabControlGPS.SelectedTab.Text=="Waypoints") { gpsS.bWaypoints=true; gpsS.iReload=0; sFileName=comboBoxWaypointsFile.Text.Trim(); } else { gpsS.bWaypoints=false; sFileName=comboBoxFile.Text.Trim(); } #if !DEBUG try #endif { if(File.Exists(sFileName) && bCheck && gpsS.bWaypoints==false) { StreamReader srReader = File.OpenText(comboBoxFile.Text.Trim()); if (LoadSettings(srReader,false)) gpsS.bSession=true; srReader.Close(); } } #if !DEBUG catch(Exception) { gpsS.bSetup=false; } #endif gpsS.bSetup=true; if (!gpsS.bSetup) { labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="Unable to open the selected file."; } else { string sDescription=gpsS.sDescription; if (!gpsS.bWaypoints && sDescription.StartsWith("Waypoints #")) sDescription="File #" + gpsS.sDescription.Substring(11); if (gpsS.bWaypoints && sDescription.StartsWith("File #")) sDescription="Waypoints #" + gpsS.sDescription.Substring(6); if (gpsS.bSession && sDescription.StartsWith("File #")) sDescription="Session #" + gpsS.sDescription.Substring(6); else if (checkBoxTrackAtOnce.Checked==true && gpsS.bSession==false && sDescription.StartsWith("File #")) sDescription="Track #" + gpsS.sDescription.Substring(6); gpsS.treeNode.Text=sDescription; gpsS.sDescription=sDescription; if (gpsS.bWaypoints==true) gpsS.sFileName=comboBoxWaypointsFile.Text.Trim(); else gpsS.sFileName=comboBoxFile.Text.Trim(); gpsS.bNoDelay=checkBoxNoDelay.Checked; gpsS.bTrackAtOnce=checkBoxTrackAtOnce.Checked; if (gpsS.bNoDelay) gpsS.iPlaySpeed=0; else gpsS.iPlaySpeed=trackBarFileSpeed.Value; gpsS.colorTrack=buttonTrackColor.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); gpsS.bForcePreprocessing=checkBoxForcePreprocessing.Checked; int iSelectedIndex=-1; try { if (gpsS.bWaypoints==true) iSelectedIndex=comboBoxWaypointsFileType.SelectedIndex; else iSelectedIndex=comboBoxTrackFileType.SelectedIndex; } catch(Exception) { } if (iSelectedIndex>=0 && iSelectedIndex<m_arrayGpsBabelFormats.Count) gpsS.saGpsBabelFormat = (string[])m_arrayGpsBabelFormats[iSelectedIndex]; else { gpsS.saGpsBabelFormat = new string[3]; gpsS.saGpsBabelFormat[0]="Unknown"; } string sFormat=""; if (gpsS.bWaypoints==true) sFormat = comboBoxWaypointsFileType.Text; else sFormat = comboBoxTrackFileType.Text; //Auto detect format from file extension, if possible if (sFormat=="Autodetect format from file name extension" && bCheck) { gpsS.saGpsBabelFormat[0]=""; int iIndex=sFileName.LastIndexOf("."); if (iIndex>0 && iIndex<sFileName.Length) { string sExtension=sFileName.Substring(iIndex).ToLower(); switch(sExtension) { case ".gpstrackersession": gpsS.saGpsBabelFormat[0]="GpsTracker"; gpsS.saGpsBabelFormat[1]="GPSTrackerSession"; gpsS.saGpsBabelFormat[2]="GpsTracker Session File"; break; case ".trackatonce": gpsS.saGpsBabelFormat[0]="GpsTracker"; gpsS.saGpsBabelFormat[1]="TrackAtOnce"; gpsS.saGpsBabelFormat[2]="GpsTracker TrackAtOnce File"; break; case ".nmea": case ".nmeatext": case ".nmeatxt": gpsS.saGpsBabelFormat[0]="nmea"; gpsS.saGpsBabelFormat[1]="txt"; gpsS.saGpsBabelFormat[2]="NMEA GPRMC and GPGGA sentences"; break; case ".aprs": case ".aprstext": case ".aprstxt": gpsS.saGpsBabelFormat[0]="aprs"; gpsS.saGpsBabelFormat[1]="txt"; gpsS.saGpsBabelFormat[2]="APRS sentences"; break; case ".gpx": gpsS.saGpsBabelFormat[0]="gpx"; gpsS.saGpsBabelFormat[1]="gpx"; gpsS.saGpsBabelFormat[2]="GPX XML format"; break; case ".kml": gpsS.saGpsBabelFormat[0]="kml"; gpsS.saGpsBabelFormat[1]="kml"; gpsS.saGpsBabelFormat[2]="Google Earth Markup Language"; break; case ".pcx": gpsS.saGpsBabelFormat[0]="pcx"; gpsS.saGpsBabelFormat[1]="pcx"; gpsS.saGpsBabelFormat[2]="Garmin PCX5"; break; case ".gpl": gpsS.saGpsBabelFormat[0]="gpl"; gpsS.saGpsBabelFormat[1]="gpl"; gpsS.saGpsBabelFormat[2]="DeLorme GPL"; break; case ".upt": gpsS.saGpsBabelFormat[0]="magellanx"; gpsS.saGpsBabelFormat[1]="upt"; gpsS.saGpsBabelFormat[2]="Magellan SD files (as for eXplorist)"; break; case ".gs": gpsS.saGpsBabelFormat[0]="maggeo"; gpsS.saGpsBabelFormat[1]="gs"; gpsS.saGpsBabelFormat[2]="Magellan Explorist Geocaching)"; break; case ".usr": gpsS.saGpsBabelFormat[0]="lowranceusr"; gpsS.saGpsBabelFormat[1]="usr"; gpsS.saGpsBabelFormat[2]="Lowrance USR"; break; } } if (gpsS.saGpsBabelFormat[0]=="") { MessageBox.Show("Could not auto detect the format of the file " + sFileName + "\r\nPlease try to manually select the correct format.","GpsTracker :: File Format Error", MessageBoxButtons.OK, MessageBoxIcon.Warning); gpsS.bSetup=false; break; } else { if (gpsS.bWaypoints==true) comboBoxWaypointsFileType.Text = gpsS.saGpsBabelFormat[2]; else comboBoxTrackFileType.Text = gpsS.saGpsBabelFormat[2]; } } if (bNoSet==true && comboBoxFile.Text!="" && gpsS.bWaypoints==false) { int i; for (i=0; i<comboBoxFile.Items.Count; i++) if ((String)comboBoxFile.Items[i] == comboBoxFile.Text) break; if (i==comboBoxFile.Items.Count) { if (comboBoxFile.Items.Count==10) { for (i=2; i<=9; i++) comboBoxFile.Items[i-1]=comboBoxFile.Items[i]; comboBoxFile.Items.RemoveAt(9); } comboBoxFile.Items.Add(comboBoxFile.Text); } } else if (bNoSet==true && comboBoxWaypointsFile.Text!="" && gpsS.bWaypoints==true) { int i; for (i=0; i<comboBoxWaypointsFile.Items.Count; i++) if ((String)comboBoxWaypointsFile.Items[i] == comboBoxWaypointsFile.Text) break; if (i==comboBoxWaypointsFile.Items.Count) { if (comboBoxWaypointsFile.Items.Count==10) { for (i=2; i<=9; i++) comboBoxWaypointsFile.Items[i-1]=comboBoxWaypointsFile.Items[i]; comboBoxWaypointsFile.Items.RemoveAt(9); } comboBoxWaypointsFile.Items.Add(comboBoxWaypointsFile.Text); } } if (gpsS.bSetup) { if (gpsS.bWaypoints == true) { bExport = checkBoxWaypointsExport.Checked; } else { bExport = checkBoxTrackExport.Checked; } } } break; case "APRS Internet": gpsS.sAPRSServerURL=comboBoxAPRSInternetServer.Text; gpsS.sCallSign=textBoxAPRSISCallSign.Text.Trim(); gpsS.iRefreshRate=(int)numericUpDownAPRSIS.Value; gpsS.colorTrack=buttonTrackColorAPRS.BackColor; gpsS.sCallSignFilter = textBoxCallSignFilter.Text; gpsS.sCallSignFilterLines = (string[])textBoxCallSignFilter.Lines.Clone(); if (bNoSet==true && gpsS.sAPRSServerURL!="") { int i; for (i=0; i<comboBoxAPRSInternetServer.Items.Count; i++) if ((String)comboBoxAPRSInternetServer.Items[i] == gpsS.sAPRSServerURL) break; if (i==comboBoxAPRSInternetServer.Items.Count) { if (comboBoxAPRSInternetServer.Items.Count==10) { for (i=3; i<=9; i++) comboBoxAPRSInternetServer.Items[i-1]=comboBoxAPRSInternetServer.Items[i]; comboBoxAPRSInternetServer.Items.RemoveAt(9); } comboBoxAPRSInternetServer.Items.Add(gpsS.sAPRSServerURL); } } if (gpsS.sAPRSServerURL == "") gpsS.bSetup = false; else { bExport = checkBoxAPRSInternetExport.Checked; gpsS.bSetup = true; } break; case "POI": if (bNoSet==false) { gpsS.fLat=(float)0; gpsS.fLon=(float)0; } else { if (!bAddedPOI) { gpsS.bSetup = true; bExport = checkBoxPOIExport.Checked; gpsS.fLat=Convert.ToSingle(textBoxLatitud.Text); gpsS.fLon=Convert.ToSingle(textBoxLongitud.Text); } } gpsS.bPOISet=false; break; } if (bNoSet == false) { gpsS.bSetup = false; gpsS.bNMEAExport = false; } if (gpsS.bSetup) { string sIconName; int iIconLimit; if (gpsS.sType=="POI") { sIconName="poi"; iIconLimit=10; } else { sIconName="gps"; iIconLimit=20; } if (gpsS.iNameIndex<=iIconLimit) { gpsS.sIconPath = GpsTrackerPlugin.m_sPluginDirectory + "\\" + sIconName + Convert.ToString(gpsS.iNameIndex) + ".png"; Bitmap image = new Bitmap(gpsS.sIconPath); imageListGpsIcons.Images.Add(image); gpsS.treeNode.ImageIndex=imageListGpsIcons.Images.Count-1; gpsS.treeNode.SelectedImageIndex=gpsS.treeNode.ImageIndex; } else { gpsS.sIconPath = GpsTrackerPlugin.m_sPluginDirectory + "\\" + sIconName + "x.png"; Bitmap image = new Bitmap(gpsS.sIconPath); imageListGpsIcons.Images.Add(image); gpsS.treeNode.ImageIndex=imageListGpsIcons.Images.Count-1; gpsS.treeNode.SelectedImageIndex=gpsS.treeNode.ImageIndex; } gpsS.bNMEAExport = bExport; } } SaveSettings(null); return gpsS.bSetup; }
public void AddGeoFence(GPSGeoFenceData geoFence) { lock ("GeoFenceAccess") { m_bHandleControlValueChangeEvent = false; GPSSource gpsSource = new GPSSource(); TreeNode treeNode; gpsSource.sType = "GeoFence"; gpsSource.sDescription = geoFence.sName; gpsSource.GeoFence = geoFence; gpsSource.iNameIndex = GetAvailableIndex(); gpsSource.bSave = true; gpsSource.bTrack = false; gpsSource.bSetup = true; gpsSource.bNeedApply = false; treeNode = new TreeNode(gpsSource.sDescription); treeNode.ImageIndex = 1; treeNode.SelectedImageIndex = 1; treeNode.Tag = gpsSource; gpsSource.treeNode = treeNode; m_gpsSourceList.Add(gpsSource); m_treeNodeGeoFence.Nodes.Add(treeNode); m_treeNodeGeoFence.ExpandAll(); listViewGeoFence.Items.Clear(); for (int i = 0; i < 100; i++) { ListViewItem lvItem = new ListViewItem(); lvItem.Text = Convert.ToString(i); lvItem.SubItems.Add(""); lvItem.SubItems.Add(""); listViewGeoFence.Items.Add(lvItem); } for (int i = 0; i < gpsSource.GeoFence.arrayLat.Count; i++) { listViewGeoFence.Items[i].SubItems[1].Text = Convert.ToString(gpsSource.GeoFence.arrayLat[i]); listViewGeoFence.Items[i].SubItems[2].Text = Convert.ToString(gpsSource.GeoFence.arrayLon[i]); } //textBoxGeoFenceName.Text = geoFence.sName; textBoxEmailAddress.Text = geoFence.sEmail; textBoxSoundFile.Text = geoFence.sSound; textBoxSoundFileOut.Text = geoFence.sSoundOut; checkBoxGeoFenceEmailIn.Checked = geoFence.bEmailIn; checkBoxGeoFenceEmailOut.Checked = geoFence.bEmailOut; checkBoxGeoFenceMsgBoxIn.Checked = geoFence.bMsgBoxIn; checkBoxGeoFenceMsgBoxOut.Checked = geoFence.bMsgBoxOut; checkBoxGeoFenceSoundIn.Checked = geoFence.bSoundIn; checkBoxGeoFenceSoundOut.Checked = geoFence.bSoundOut; comboBoxGeoFenceSource.Items.Clear(); comboBoxGeoFenceSource.Items.Add("All Gps Sources"); for (int i = 0; i < m_gpsSourceList.Count; i++) { GPSSource gpsSourceFence = (GPSSource)m_gpsSourceList[i]; if (gpsSourceFence.sType != "POI" && gpsSourceFence.sType != "GeoFence" && gpsSourceFence.bWaypoints == false && gpsSourceFence.bSetup) comboBoxGeoFenceSource.Items.Add(gpsSourceFence.sDescription); } comboBoxGeoFenceSource.Text = "All Gps Sources"; comboBoxGeoFenceSource.Text = geoFence.sSource; labelGeoFenceSelectedSource.Text = geoFence.sSource; ApplySettings(gpsSource, true, false, true); m_iSourceNameCount++; m_bHandleControlValueChangeEvent = true; } }
private void menuItemAdd_Click(object sender, System.EventArgs e) { GPSSource gpsSource = new GPSSource(); TreeNode treeNode; labelTrackCode.Text=""; if (m_gpsSourceList.Count==m_iMaxDevices) { labelTrackCode.ForeColor = System.Drawing.Color.Red; labelTrackCode.Text="The max. number of GPS devices is " + m_iMaxDevices.ToString(); } else { gpsSource.sType=treeViewSources.SelectedNode.Text; gpsSource.iNameIndex=GetAvailableIndex(); gpsSource.sDescription=gpsSource.sType + " #" + gpsSource.iNameIndex; gpsSource.bTrack=false; gpsSource.bSetup=false; treeNode = new TreeNode(gpsSource.sDescription); treeNode.ImageIndex=1; treeNode.SelectedImageIndex=1; treeNode.Tag=gpsSource; gpsSource.treeNode=treeNode; gpsSource.bNeedApply=true; if (gpsSource.sType=="GeoFence") listViewGeoFence.Items.Clear(); m_gpsSourceList.Add(gpsSource); ApplySettings(gpsSource,false,false,false); treeViewSources.SelectedNode.Nodes.Add(treeNode); treeViewSources.SelectedNode.ExpandAll(); treeViewSources.SelectedNode=treeNode; SetupTabs(); m_iSourceNameCount++; StartStop.Enabled=true; } }
//Load user selected settings public bool LoadSettings(StreamReader srReader, bool bSet) { bool bRet=false; Bitmap image; StreamReader sr; m_bHandleControlValueChangeEvent=false; if (bSet) { SetupTree(); m_bHandleControlValueChangeEvent=false; m_gpsSourceList.Clear(); progressBarPreprocessing.Value=0; progressBarSetup.Value=0; comboBoxFile.Items.Clear(); comboBoxWaypointsFile.Items.Clear(); comboBoxTcpIP.Items.Clear(); comboBoxAPRSInternetServer.Items.Clear(); checkBoxNoDelay.Checked=false; checkBoxSecureSocket.Checked=false; progressBarSetup.Visible=false; labelSettingup.Visible=false; labelPreprocessing.Visible=false; progressBarPreprocessing.Visible=false; image = new Bitmap(GpsTrackerPlugin.m_sPluginDirectory + "\\satellite.png"); imageListGpsIcons.Images.Add(image); image = new Bitmap(GpsTrackerPlugin.m_sPluginDirectory + "\\gpsnotset.png"); imageListGpsIcons.Images.Add(image); } #if !DEBUG try #endif { if (srReader==null) { if (!File.Exists(GpsTrackerPlugin.m_sPluginDirectory + "\\GpsTracker.cfg")) { SetDefaultSettings(bSet); return false; } sr = File.OpenText(GpsTrackerPlugin.m_sPluginDirectory + "\\GpsTracker.cfg"); } else sr=srReader; { string line=sr.ReadLine(); if (line!=null && line.StartsWith("GPSTracker Version") ) { if (bSet) { while(true) { line = sr.ReadLine(); if (line==null || line.StartsWith("END UI CONTROLS")) break; if (line.StartsWith("checkBoxVExaggeration=")) checkBoxVExaggeration.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxVExaggeration=".Length)); else if (line.StartsWith("checkBoxGeoFenceEmailIn=")) checkBoxGeoFenceEmailIn.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceEmailIn=".Length)); else if (line.StartsWith("checkBoxGeoFenceEmailOut=")) checkBoxGeoFenceEmailOut.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceEmailOut=".Length)); else if (line.StartsWith("checkBoxGeoFenceMsgBoxIn=")) checkBoxGeoFenceMsgBoxIn.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceMsgBoxIn=".Length)); else if (line.StartsWith("checkBoxGeoFenceMsgBoxOut=")) checkBoxGeoFenceMsgBoxOut.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceMsgBoxOut=".Length)); else if (line.StartsWith("checkBoxGeoFenceSoundIn=")) checkBoxGeoFenceSoundIn.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceSoundIn=".Length)); else if (line.StartsWith("checkBoxGeoFenceSoundOut=")) checkBoxGeoFenceSoundOut.Checked = Convert.ToBoolean(line.Remove(0, "checkBoxGeoFenceSoundOut=".Length)); else if (line.StartsWith("textBoxEmailFrom=")) textBoxEmailFrom.Text = line.Remove(0, "textBoxEmailFrom=".Length); else if (line.StartsWith("textBoxEmailServer=")) textBoxEmailServer.Text = line.Remove(0, "textBoxEmailServer=".Length); else if (line.StartsWith("textBoxEmailAddress=")) textBoxEmailAddress.Text = line.Remove(0, "textBoxEmailAddress=".Length); else if (line.StartsWith("textBoxSoundFileIn=")) textBoxSoundFile.Text = line.Remove(0, "textBoxSoundFileIn=".Length); else if (line.StartsWith("textBoxSoundFileOut=")) textBoxSoundFileOut.Text = line.Remove(0, "textBoxSoundFileOut=".Length); else if (line.StartsWith("textBoxNMEAExportPath=")) textBoxNMEAExportPath.Text = line.Remove(0, "textBoxNMEAExportPath=".Length); else if (line.StartsWith("comboBoxTrackFileType=")) comboBoxTrackFileType.Text=line.Remove(0,"comboBoxTrackFileType=".Length); else if (line.StartsWith("comboBoxWaypointsFileType=")) comboBoxWaypointsFileType.Text=line.Remove(0,"comboBoxWaypointsFileType=".Length); else if (line.StartsWith("checkBoxSecureSocket=")) checkBoxSecureSocket.Checked=Convert.ToBoolean(line.Remove(0,"checkBoxSecureSocket=".Length)); else if (line.StartsWith("comboBoxCOMPort=")) comboBoxCOMPort.Text=line.Remove(0,"comboBoxCOMPort=".Length); else if (line.StartsWith("comboBoxBaudRate=")) comboBoxBaudRate.Text=line.Remove(0,"comboBoxBaudRate=".Length); else if (line.StartsWith("comboBoxByteSize=")) comboBoxByteSize.Text=line.Remove(0,"comboBoxByteSize=".Length); else if (line.StartsWith("comboParity=")) comboParity.SelectedIndex=Convert.ToInt32(line.Remove(0,"comboParity=".Length)); else if (line.StartsWith("comboBoxStopBits=")) comboBoxStopBits.SelectedIndex=Convert.ToInt32(line.Remove(0,"comboBoxStopBits=".Length)); else if (line.StartsWith("numericUpDownUDPPort=")) numericUpDownUDPPort.Value=Convert.ToDecimal(line.Remove(0,"numericUpDownUDPPort=".Length)); else if (line.StartsWith("numericUpDownTCPPort=")) numericUpDownTCPPort.Value=Convert.ToDecimal(line.Remove(0,"numericUpDownTCPPort=".Length)); else if (line.StartsWith("numericUpDownReload=")) numericUpDownReload.Value=Convert.ToDecimal(line.Remove(0,"numericUpDownReload=".Length)); else if (line.StartsWith("comboBoxTcpIP=")) comboBoxTcpIP.Text=line.Remove(0,"comboBoxTcpIP=".Length); else if (line.StartsWith("comboBoxAPRSInternetServer=")) comboBoxAPRSInternetServer.Text=line.Remove(0,"comboBoxAPRSInternetServer=".Length); else if (line.StartsWith("comboBoxFile=")) comboBoxFile.Text=line.Remove(0,"comboBoxFile=".Length); else if (line.StartsWith("comboBoxWaypointsFile=")) comboBoxWaypointsFile.Text=line.Remove(0,"comboBoxWaypointsFile=".Length); else if (line.StartsWith("trackBarFileSpeed=")) trackBarFileSpeed.Value=Convert.ToInt32(line.Remove(0,"trackBarFileSpeed=".Length)); else if (line.StartsWith("m_bTrackHeading=")) m_bTrackHeading=Convert.ToBoolean(line.Remove(0,"m_bTrackHeading=".Length)); else if (line.StartsWith("m_bTrackLine=")) m_bTrackLine=Convert.ToBoolean(line.Remove(0,"m_bTrackLine=".Length)); // else // if (line.StartsWith("m_bRecordSession=")) // m_bRecordSession=Convert.ToBoolean(line.Remove(0,"m_bRecordSession=".Length)); else if (line.StartsWith("m_bInfoText=")) m_bInfoText=Convert.ToBoolean(line.Remove(0,"m_bInfoText=".Length)); else if (line.StartsWith("checkBoxNoDelay=")) checkBoxNoDelay.Checked=Convert.ToBoolean(line.Remove(0,"checkBoxNoDelay=".Length)); else if (line.StartsWith("checkBoxNoDelay=")) checkBoxNoDelay.Checked=Convert.ToBoolean(line.Remove(0,"checkBoxNoDelay=".Length)); else if (line.StartsWith("comboBoxFlowControl=")) comboBoxFlowControl.SelectedIndex=Convert.ToInt32(line.Remove(0,"comboBoxFlowControl=".Length)); else if (line.StartsWith("buttonTrackColorCOM=")) buttonTrackColorCOM.BackColor=Color.FromArgb(Convert.ToInt32(line.Remove(0,"buttonTrackColorCOM=".Length))); else if (line.StartsWith("buttonTrackColorTCP=")) buttonTrackColorTCP.BackColor=Color.FromArgb(Convert.ToInt32(line.Remove(0,"buttonTrackColorTCP=".Length))); else if (line.StartsWith("buttonTrackColorUDP=")) buttonTrackColorUDP.BackColor=Color.FromArgb(Convert.ToInt32(line.Remove(0,"buttonTrackColorUDP=".Length))); else if (line.StartsWith("buttonTrackColor=")) buttonTrackColor.BackColor=Color.FromArgb(Convert.ToInt32(line.Remove(0,"buttonTrackColor=".Length))); else if (line.StartsWith("textBoxCallSignFilter=")) { CSVReader csvReader=new CSVReader(); string [] sLines=csvReader.GetCSVLine(line.Remove(0,"textBoxCallSignFilter=".Length)); if (sLines!=null && sLines.Length>0) textBoxCallSignFilter.Lines=(string[])sLines.Clone(); else textBoxCallSignFilter.Text=""; } else if (line.StartsWith("FILE COMBOBOX COUNT")) { int iCount=Convert.ToInt32(line.Remove(0,"FILE COMBOBOX COUNT=".Length)); for (int i=0; i<iCount; i++) comboBoxFile.Items.Add(sr.ReadLine()); } else if (line.StartsWith("WAYPOINTSFILE COMBOBOX COUNT")) { int iCount=Convert.ToInt32(line.Remove(0,"WAYPOINTSFILE COMBOBOX COUNT=".Length)); for (int i=0; i<iCount; i++) comboBoxWaypointsFile.Items.Add(sr.ReadLine()); } else if (line.StartsWith("TCPIP COMBOBOX COUNT")) { int iCount=Convert.ToInt32(line.Remove(0,"TCPIP COMBOBOX COUNT=".Length)); for (int i=0; i<iCount; i++) comboBoxTcpIP.Items.Add(sr.ReadLine()); } else if (line.StartsWith("APRSINTERNET COMBOBOX COUNT")) { int iCount=Convert.ToInt32(line.Remove(0,"APRSINTERNET COMBOBOX COUNT=".Length)); for (int i=0; i<iCount; i++) comboBoxAPRSInternetServer.Items.Add(sr.ReadLine()); } else if (line.StartsWith("textBoxAPRSISCallSign=")) textBoxAPRSISCallSign.Text=line.Remove(0,"textBoxAPRSISCallSign=".Length); else if (line.StartsWith("buttonTrackColorAPRS=")) buttonTrackColorAPRS.BackColor=Color.FromArgb(Convert.ToInt32(line.Remove(0,"buttonTrackColorAPRS=".Length))); else if (line.StartsWith("numericUpDownAPRSIS=")) numericUpDownAPRSIS.Value=Convert.ToDecimal(line.Remove(0,"numericUpDownAPRSIS=".Length)); else if (line.StartsWith("textBoxLongitud=")) textBoxLongitud.Text=line.Remove(0,"textBoxLongitud=".Length); else if (line.StartsWith("textBoxLatitud=")) textBoxLatitud.Text=line.Remove(0,"textBoxLatitud=".Length); else if (line.StartsWith("numericUpDownAltitud=")) numericUpDownAltitud.Value=Convert.ToDecimal(line.Remove(0,"numericUpDownAltitud=".Length)); else if (line.StartsWith("checkBoxSetAltitud=")) checkBoxSetAltitud.Checked=Convert.ToBoolean(line.Remove(0,"checkBoxSetAltitud=".Length)); else if (line.StartsWith("comboBoxAPRSInternetServer=")) comboBoxAPRSInternetServer.SelectedIndex=Convert.ToInt32(line.Remove(0,"comboBoxAPRSInternetServer=".Length)); } } int iSourceCount=0; line = sr.ReadLine(); if (line!=null && line.StartsWith("SOURCE COUNT")) iSourceCount=Convert.ToInt32(line.Remove(0,"SOURCE COUNT=".Length)); for (int i=0; i<iSourceCount; i++) { GPSSource gpsS=new GPSSource(); gpsS.bNeedApply=true; gpsS.saGpsBabelFormat = new string[3]; m_gpsSourceList.Add(gpsS); } int iItem=0; while(true) { line = sr.ReadLine(); if (line!=null && line.StartsWith("END SOURCE INDEX")) { iItem++; if (iItem == iSourceCount) break; m_iSourceNameCount++; line = sr.ReadLine(); } if (line==null || (srReader!=null && line=="--------------------------------------------------")) { bRet=true; break; } if (bSet) { GPSSource gpsSource = (GPSSource)m_gpsSourceList[iItem]; if (line.StartsWith("iNameIndex=")) gpsSource.iNameIndex=Convert.ToInt32(line.Remove(0,"iNameIndex=".Length)); else if (line.StartsWith("bSecureSocket=")) gpsSource.bSecureSocket=Convert.ToBoolean(line.Remove(0,"bSecureSocket=".Length)); else if (line.StartsWith("bNeedApply=")) gpsSource.bNeedApply=Convert.ToBoolean(line.Remove(0,"bNeedApply=".Length)); else if (line.StartsWith("bSetup=")) gpsSource.bSetup=Convert.ToBoolean(line.Remove(0,"bSetup=".Length)); else if (line.StartsWith("sType=")) gpsSource.sType=line.Remove(0,"sType=".Length); else if (line.StartsWith("sDescription=")) gpsSource.sDescription=line.Remove(0,"sDescription=".Length); else if (line.StartsWith("sComment=")) gpsSource.sComment=line.Remove(0,"sComment=".Length); else if (line.StartsWith("sIconPath=")) gpsSource.sIconPath=line.Remove(0,"sIconPath=".Length); else if (line.StartsWith("colorTrack=")) gpsSource.colorTrack=Color.FromArgb(Convert.ToInt32(line.Remove(0,"colorTrack=".Length))); else if (line.StartsWith("fLat=")) gpsSource.fLat=Convert.ToDouble(line.Remove(0,"fLat=".Length)); else if (line.StartsWith("fLon=")) gpsSource.fLon=Convert.ToDouble(line.Remove(0,"fLon=".Length)); else if (line.StartsWith("bTrack=")) gpsSource.bTrack=Convert.ToBoolean(line.Remove(0,"bTrack=".Length)); else if (line.StartsWith("sUSBDevice=")) gpsSource.sUSBDevice=line.Remove(0,"sUSBDevice=".Length); else if (line.StartsWith("iCOMPort=")) gpsSource.iCOMPort=Convert.ToInt32(line.Remove(0,"iCOMPort=".Length)); else if (line.StartsWith("iBaudRate=")) gpsSource.iBaudRate=Convert.ToInt32(line.Remove(0,"iBaudRate=".Length)); else if (line.StartsWith("iByteSize=")) gpsSource.iByteSize=Convert.ToInt32(line.Remove(0,"iByteSize=".Length)); else if (line.StartsWith("iSelectedItem=")) gpsSource.iSelectedItem=Convert.ToInt32(line.Remove(0,"iSelectedItem=".Length)); else if (line.StartsWith("iParity=")) gpsSource.iParity=Convert.ToInt32(line.Remove(0,"iParity=".Length)); else if (line.StartsWith("iStopBits=")) gpsSource.iStopBits=Convert.ToInt32(line.Remove(0,"iStopBits=".Length)); else if (line.StartsWith("iFlowControl=")) gpsSource.iFlowControl=Convert.ToInt32(line.Remove(0,"iFlowControl=".Length)); else if (line.StartsWith("iUDPPort=")) gpsSource.iUDPPort=Convert.ToInt32(line.Remove(0,"iUDPPort=".Length)); else if (line.StartsWith("iTCPPort=")) gpsSource.iTCPPort=Convert.ToInt32(line.Remove(0,"iTCPPort=".Length)); else if (line.StartsWith("sTCPAddress=")) gpsSource.sTCPAddress=line.Remove(0,"sTCPAddress=".Length); else if (line.StartsWith("sFileName=")) gpsSource.sFileName=line.Remove(0,"sFileName=".Length); else if (line.StartsWith("sFileNameSession=")) gpsSource.sFileNameSession=line.Remove(0,"sFileNameSession=".Length); else if (line.StartsWith("bNoDelay=")) gpsSource.bNoDelay=Convert.ToBoolean(line.Remove(0,"bNoDelay=".Length)); else if (line.StartsWith("bTrackAtOnce=")) gpsSource.bTrackAtOnce=Convert.ToBoolean(line.Remove(0,"bTrackAtOnce=".Length)); else if (line.StartsWith("iPlaySpeed=")) gpsSource.iPlaySpeed=Convert.ToInt32(line.Remove(0,"iPlaySpeed=".Length)); else if (line.StartsWith("iFilePlaySpeed=")) gpsSource.iFilePlaySpeed=Convert.ToInt32(line.Remove(0,"iFilePlaySpeed=".Length)); else if (line.StartsWith("sCallSign=")) gpsSource.sCallSign=line.Remove(0,"sCallSign=".Length); else if (line.StartsWith("iRefreshRate=")) gpsSource.iRefreshRate=Convert.ToInt32(line.Remove(0,"iRefreshRate=".Length)); else if (line.StartsWith("iReload=")) gpsSource.iReload=Convert.ToInt32(line.Remove(0,"iReload=".Length)); else if (line.StartsWith("bForcePreprocessing=")) gpsSource.bForcePreprocessing=Convert.ToBoolean(line.Remove(0,"bForcePreprocessing=".Length)); else if (line.StartsWith("bWaypoints=")) gpsSource.bWaypoints=Convert.ToBoolean(line.Remove(0,"bWaypoints=".Length)); else if (line.StartsWith("bSave=")) gpsSource.bSave=Convert.ToBoolean(line.Remove(0,"bSave=".Length)); else if (line.StartsWith("bSession=")) gpsSource.bSession=Convert.ToBoolean(line.Remove(0,"bSession=".Length)); else if (line.StartsWith("babelType=")) gpsSource.saGpsBabelFormat[0]=line.Remove(0,"babelType=".Length); else if (line.StartsWith("babelExtension=")) gpsSource.saGpsBabelFormat[1]=line.Remove(0,"babelExtension=".Length); else if (line.StartsWith("babelDescription=")) gpsSource.saGpsBabelFormat[2]=line.Remove(0,"babelDescription=".Length); else if (line.StartsWith("sCallSignFilter=")) { CSVReader csvReader=new CSVReader(); string [] sLines=csvReader.GetCSVLine(line.Remove(0,"sCallSignFilter=".Length)); if (sLines!=null && sLines.Length>0) gpsSource.sCallSignFilterLines=(string[])sLines.Clone(); } else if (line.StartsWith("sAPRSServerURL=")) gpsSource.sAPRSServerURL=line.Remove(0,"sAPRSServerURL=".Length); else if (line.StartsWith("bNMEAExport=")) gpsSource.bNMEAExport=Convert.ToBoolean(line.Remove(0,"bNMEAExport=".Length)); else if (line.StartsWith("GeoFence.sSource=")) gpsSource.GeoFence.sSource = line.Remove(0, "GeoFence.sSource=".Length); else if (line.StartsWith("GeoFence.sName=")) gpsSource.GeoFence.sName=line.Remove(0,"GeoFence.sName=".Length); else if (line.StartsWith("GeoFence.sEmail=")) gpsSource.GeoFence.sEmail=line.Remove(0,"GeoFence.sEmail=".Length); else if (line.StartsWith("GeoFence.sSound=")) gpsSource.GeoFence.sSound=line.Remove(0,"GeoFence.sSound=".Length); else if (line.StartsWith("GeoFence.sSoundOut=")) gpsSource.GeoFence.sSoundOut = line.Remove(0, "GeoFence.sSoundOut=".Length); else if (line.StartsWith("GeoFence.bEmailIn=")) gpsSource.GeoFence.bEmailIn=Convert.ToBoolean(line.Remove(0,"GeoFence.bEmailIn=".Length)); else if (line.StartsWith("GeoFence.bEmailOut=")) gpsSource.GeoFence.bEmailOut = Convert.ToBoolean(line.Remove(0, "GeoFence.bEmailOut=".Length)); else if (line.StartsWith("GeoFence.bMsgBoxIn=")) gpsSource.GeoFence.bMsgBoxIn=Convert.ToBoolean(line.Remove(0,"GeoFence.bMsgBoxIn=".Length)); else if (line.StartsWith("GeoFence.bMsgBoxOut=")) gpsSource.GeoFence.bMsgBoxOut = Convert.ToBoolean(line.Remove(0, "GeoFence.bMsgBoxOut=".Length)); else if (line.StartsWith("GeoFence.bSoundIn=")) gpsSource.GeoFence.bSoundIn=Convert.ToBoolean(line.Remove(0,"GeoFence.bSoundIn=".Length)); else if (line.StartsWith("GeoFence.bSoundOut=")) gpsSource.GeoFence.bSoundOut = Convert.ToBoolean(line.Remove(0, "GeoFence.bSoundOut=".Length)); else if (line.StartsWith("GeoFence.arrayLat=")) { do { gpsSource.GeoFence.arrayLat.Add((float)Convert.ToDouble(line.Remove(0, "GeoFence.arrayLat=".Length))); line = sr.ReadLine(); if (line != null && line.StartsWith("GeoFence.arrayLon=")) gpsSource.GeoFence.arrayLon.Add((float)Convert.ToDouble(line.Remove(0, "GeoFence.arrayLon=".Length))); line = sr.ReadLine(); } while (line != null && line.StartsWith("GeoFence.Array DONE") == false); } } } } else { SetDefaultSettings(bSet); m_bHandleControlValueChangeEvent=false; } } if (srReader==null) sr.Close(); } #if !DEBUG catch(Exception) { SetDefaultSettings(bSet); m_bHandleControlValueChangeEvent=false; if (m_gpsSourceList.Count>=1 && bSet) StartStop.Enabled=true; bRet=false; } #endif if (bSet) { int i; //set up tree view in different function for (i=0; i<m_gpsSourceList.Count; i++) { GPSSource gpsSource = (GPSSource)m_gpsSourceList[i]; TreeNode treeNode; TreeNode treeNodeParent; treeNode = new TreeNode(gpsSource.sDescription); gpsSource.treeNode=treeNode; treeNode.Tag=gpsSource; switch (gpsSource.sType) { case "COM": treeNodeParent=m_treeNodeCOM; break; case "USB": treeNodeParent=m_treeNodeUSB; break; case "UDP": treeNodeParent=m_treeNodeUDP; break; case "TCP": treeNodeParent=m_treeNodeTCP; break; case "File": treeNodeParent=m_treeNodeFile; break; case "APRS Internet": treeNodeParent=m_treeNodeAPRS; break; case "POI": treeNodeParent=m_treeNodePOI; break; case "GeoFence": treeNodeParent = m_treeNodeGeoFence; break; default: treeNodeParent=null; break; } if (treeNodeParent != null) { treeNodeParent.Nodes.Add(treeNode); if (gpsSource.sIconPath == "") gpsSource.sIconPath = GpsTrackerPlugin.m_sPluginDirectory + "\\Gpsnotset.png"; if (!File.Exists(gpsSource.sIconPath)) gpsSource.sIconPath = GpsTrackerPlugin.m_sPluginDirectory + "\\Gpsx.png"; image = new Bitmap(gpsSource.sIconPath); imageListGpsIcons.Images.Add(image); treeNode.ImageIndex = imageListGpsIcons.Images.Count - 1; treeNode.SelectedImageIndex = treeNode.ImageIndex; if (gpsSource.bTrack) { treeNode.NodeFont = new System.Drawing.Font(treeViewSources.Font, FontStyle.Bold); treeNode.Text = treeNode.Text + " "; } treeNodeParent.ExpandAll(); } } checkBoxTrackHeading.Checked=m_bTrackHeading; checkBoxTrackLine.Checked=m_bTrackLine; checkBoxRecordSession.Checked=m_bRecordSession; checkBoxInformationText.Checked=m_bInfoText; for (i=0; i<comboBoxFile.Items.Count; i++) if ((String)comboBoxFile.Items[i] == GpsTrackerPlugin.m_sPluginDirectory + "\\SampleSession.GPSTrackerSession") break; if (i==comboBoxFile.Items.Count) comboBoxFile.Items.Add(GpsTrackerPlugin.m_sPluginDirectory + "\\SampleSession.GPSTrackerSession"); } if (m_gpsSourceList.Count>=1 && bSet) StartStop.Enabled=true; m_bHandleControlValueChangeEvent=true; return bRet; }
// //POI functions // public void AddPOI(string sName, double fLat, double fLon, bool bAdd, GPSSource gpsSourceWaypointsFile) { lock (LockPOI) { GPSSource gpsSource = new GPSSource(); gpsSource.sType="POI"; if (sName=="") gpsSource.sDescription=gpsSource.sType + " #" + Convert.ToString(gpsSource.iNameIndex); else gpsSource.sDescription=sName; gpsSource.bSave=bAdd; gpsSource.bTrack=false; gpsSource.bSetup=true; gpsSource.bPOISet=false; TreeNode treeNode=null; gpsSource.iNameIndex=GetAvailableIndex(); gpsSource.treeNode=null; if (bAdd) { treeNode = new TreeNode(gpsSource.sDescription); treeNode.ImageIndex=1; treeNode.SelectedImageIndex=1; treeNode.Tag=gpsSource; gpsSource.treeNode=treeNode; } gpsSource.bNeedApply=false; gpsSource.fLat=fLat; gpsSource.fLon=fLon; m_gpsSourceList.Add(gpsSource); if (bAdd) { ApplySettings(gpsSource,true,false,true); m_treeNodePOI.Nodes.Add(treeNode); m_treeNodePOI.ExpandAll(); } m_iSourceNameCount++; if (gpsSourceWaypointsFile!=null) { gpsSource.bTrack=gpsSourceWaypointsFile.bTrack; gpsSource.sIconPath = gpsSourceWaypointsFile.sIconPath; gpsSource.GpsPos.m_gpsTrack = gpsSourceWaypointsFile.GpsPos.m_gpsTrack; gpsSource.GpsPos.m_iDay=gpsSourceWaypointsFile.GpsPos.m_iDay; gpsSource.GpsPos.m_iMonth=gpsSourceWaypointsFile.GpsPos.m_iMonth; gpsSource.GpsPos.m_iYear=gpsSourceWaypointsFile.GpsPos.m_iYear; gpsSource.colorTrack=gpsSourceWaypointsFile.colorTrack; gpsSource.iStartAltitud=gpsSourceWaypointsFile.iStartAltitud; } if (m_hPOIThread==null) { m_eventPOIThreadSync = new AutoResetEvent(false); m_hPOIThread = new Thread(new ThreadStart(this.threadPOI)); m_hPOIThread.IsBackground = true; m_hPOIThread.Priority = System.Threading.ThreadPriority.Normal; m_hPOIThread.Start(); } } }
void SignalGeoFence(bool bIn, GPSGeoFenceData geoFence, GPSSource gpsSource) { string sBody = ""; string sSubject = ""; try { if (bIn) //Signal In { //Audio if (geoFence.bSoundIn && geoFence.sSound != "") { System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(); soundPlayer.SoundLocation = geoFence.sSound; soundPlayer.Play(); } //MessageBox if (geoFence.bMsgBoxIn) { GPSGeoFenceMsgBox geoFenceMsgBox = new GPSGeoFenceMsgBox(bIn, geoFence, gpsSource); } } else //Signal Out { //Audio if (geoFence.bSoundOut && geoFence.sSoundOut != "") { System.Media.SoundPlayer soundPlayer = new System.Media.SoundPlayer(); soundPlayer.SoundLocation = geoFence.sSoundOut; soundPlayer.Play(); } //MessageBox if (geoFence.bMsgBoxOut) { GPSGeoFenceMsgBox geoFenceMsgBox = new GPSGeoFenceMsgBox(bIn, geoFence, gpsSource); } } if (((geoFence.bEmailIn && bIn) || (geoFence.bEmailOut && !bIn)) && geoFence.sEmail != "" && textBoxEmailServer.Text!="" && textBoxEmailFrom.Text!="") { sSubject = "GpsTracker :: GeoFence detected message"; sBody = gpsSource.sDescription + " is "; if (bIn) sBody += "inside "; else sBody += "outside "; sBody += "GeoFence Zone " + geoFence.sName; sBody += "\r\n\r\n"; sBody += "Location:\r\n"; string sLocation = ""; string sNS; if (gpsSource.GpsPos.m_fLat >= (float)0) sNS = "N"; else sNS = "S"; double dLat = Math.Abs(gpsSource.GpsPos.m_fLat); double dWhole = Math.Floor(dLat); double dFraction = dLat - dWhole; double dMin = dFraction * (double)60; double dMinWhole = Math.Floor(dMin); double dSeconds = (dMin - dMinWhole) * (double)60; int iDegrees = Convert.ToInt32(dWhole); int iMinutes = Convert.ToInt32(dMinWhole); float fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "°" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sNS; sBody+= "Latitude: " + sLocation + "\r\n"; string sEW; if (gpsSource.GpsPos.m_fLon >= (float)0) sEW = "E"; else sEW = "W"; double dLon = Math.Abs(gpsSource.GpsPos.m_fLon); dWhole = Math.Floor(dLon); dFraction = dLon - dWhole; dMin = dFraction * (double)60; dMinWhole = Math.Floor(dMin); dSeconds = (dMin - dMinWhole) * (double)60; iDegrees = Convert.ToInt32(dWhole); iMinutes = Convert.ToInt32(dMinWhole); fSeconds = Convert.ToSingle(dSeconds); sLocation = Convert.ToString(iDegrees) + "°" + Convert.ToString(iMinutes) + "'" + Convert.ToString(fSeconds) + "\" " + sEW; sBody+= "Longitude: " + sLocation + "\r\n\r\n"; sBody+= "Date and Time: " + DateTime.Now.ToString() + "\r\n"; // Command line argument must the the SMTP host. SmtpClient client = new SmtpClient(textBoxEmailServer.Text.Trim()); // Specify the e-mail sender. // Create a mailing address that includes a UTF8 character // in the display name. MailAddress from = new MailAddress(textBoxEmailFrom.Text.Trim(), textBoxEmailFrom.Text.Trim(), System.Text.Encoding.UTF8); // Set destinations for the e-mail message. MailAddress to = new MailAddress(geoFence.sEmail.Trim()); // Specify the message content. MailMessage message = new MailMessage(from, to); message.Body = sBody; message.BodyEncoding = System.Text.Encoding.UTF8; message.Subject = sSubject; message.SubjectEncoding = System.Text.Encoding.UTF8; client.UseDefaultCredentials = true; client.Send(message); // Clean up. message.Dispose(); client = null; } } catch (Exception) { } }
public void UdpReceiveData(IAsyncResult iar) { try { String sGPS; // Create temporary remote end Point IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); EndPoint tempRemoteEP = (EndPoint)sender; // Get the Socket TCPSockets tcpSockets = (TCPSockets)iar.AsyncState; Socket remote = tcpSockets.socketUDP; // Call EndReceiveFrom to get the received Data int nBytesRec = remote.EndReceiveFrom(iar, ref tempRemoteEP); if (nBytesRec > 0) { sGPS = System.Text.Encoding.ASCII.GetString(tcpSockets.byTcpBuffer, 0, nBytesRec); try { if (m_GpsTracker.m_MessageMonitor != null) { m_GpsTracker.m_MessageMonitor.AddMessageTCPUDPRaw(sGPS); } } catch (Exception) { m_GpsTracker.m_MessageMonitor = null; } tcpSockets.sStream += sGPS; int iIndex = -1; char [] cEOL = { '\n', '\r' }; string sData = ""; do { iIndex = tcpSockets.sStream.IndexOfAny(cEOL); if (iIndex >= 0) { sData = tcpSockets.sStream.Substring(0, iIndex); sData = sData.Trim(cEOL); tcpSockets.sStream = tcpSockets.sStream.Remove(0, iIndex + 1); if (sData != "") { m_GpsTracker.ShowGPSIcon(sData.ToCharArray(), sData.Length, false, tcpSockets.iDeviceIndex, false, true); } } }while(iIndex >= 0); } GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[tcpSockets.iDeviceIndex]; EndPoint endPoint = new IPEndPoint(IPAddress.Any, Convert.ToInt32(gpsSource.iUDPPort)); remote.BeginReceiveFrom(tcpSockets.byTcpBuffer, 0, 1024, SocketFlags.None, ref endPoint, new AsyncCallback(UdpReceiveData), tcpSockets); } catch (Exception) { } }