//
		//NMEA Parsing
		//
		//Parse the data in cNMEAMessage looking for supported messages,
		//if found get lat and lon and return true (locked).
		public bool ParseGPSMessage(char [] cNMEAMessage, int iMsgLength, bool fCheck, int iIndex)
		{
			bool fLocked=false;
			SupportedMessages supportedMsg=SupportedMessages.msgNotSupported;
			GPSSource gpsSource = (GPSSource)m_GpsTracker.m_gpsSourceList[iIndex];

			string [] sMsgField;
			String sGpsLat="";
			String sGpsLatMin="";
			String sGpsLon="";
			String sGpsLonMin="";
			String sNS="";
			String sEW="";
			String sGpsSpeed="";
			String sGpsAlt="";
			String sGpsAltUnit="";
			String sGpsHeading="";
			String sGpsDate="";
			String sCallSign="";
			int iIndex1;

            gpsSource.GpsPos.m_sName = "";
            gpsSource.GpsPos.m_sComment = "";
            gpsSource.GpsPos.m_iAPRSIconCode = -1;
            gpsSource.GpsPos.m_iAPRSIconTable = -1;

//			#if !DEBUG
			try
//			#endif
			{
				//cNMEAMessage[iMsgLength]=(char)0; //ensure null terminated;
				char [] trimChars = { ' ', '\t', '\r', '\n' };
				String sGPRMC = new String(cNMEAMessage,0,iMsgLength);
				sGPRMC = sGPRMC.TrimStart(trimChars);
				sGPRMC = sGPRMC.TrimEnd(trimChars);
						
				//System.Diagnostics.Debug.Write(sGPRMC);
				//System.Diagnostics.Debug.Write(Environment.NewLine);

				#region Check for supported message
				//look for the GPRMC message
				if	(iMsgLength > 11)
				{
					if (sGPRMC.StartsWith("$GPRMC")==true)
						supportedMsg=SupportedMessages.msgGPRMC;
					else
						if (sGPRMC.StartsWith("$GPGGA")==true)
						supportedMsg=SupportedMessages.msgGPGGA;
					else
						if (sGPRMC.StartsWith("APRS:")==true)
						supportedMsg=SupportedMessages.mspAPRSWebSession;
					else
						if (m_Aprs.Parse(sGPRMC,iIndex)==true)
							supportedMsg=SupportedMessages.msgAPRS;
					else
					{	//special NMEA APRS MEssage
						int iIndexGPRMC=sGPRMC.IndexOf("$GPRMC");
						int iIndexGPGGA=sGPRMC.IndexOf("$GPGGA");
						int iIndexCallSign=sGPRMC.IndexOf(">");
						int iIndexNMEA=-1;
						if (iIndexGPRMC>0)
						{
							supportedMsg=SupportedMessages.msgGPRMC;
							iIndexNMEA=iIndexGPRMC;
						}
						else
						if (iIndexGPGGA>0)
						{
							supportedMsg=SupportedMessages.msgGPGGA;
							iIndexNMEA=iIndexGPGGA;
						}
						if (iIndexNMEA>0 && iIndexCallSign>0 && iIndexNMEA>iIndexCallSign)
						{
							sCallSign=sGPRMC.Substring(0,iIndexCallSign);
							sGPRMC=sGPRMC.Substring(iIndexNMEA);
						}
						else
							supportedMsg=SupportedMessages.msgNotSupported;

						//Filter call sign
						if (supportedMsg!=SupportedMessages.msgNotSupported)
						{
							bool bRet=false;
							if (gpsSource.sCallSignFilterLines.Length<=1)
								bRet=true;
							else
								for (int i=0; i<gpsSource.sCallSignFilterLines.Length-1; i++)
								{
									string source=sCallSign;
									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 (!bRet)
								supportedMsg=SupportedMessages.msgNotSupported;
							else
								gpsSource.sDescription=sCallSign;
						}
							 

					}
					
				}
				#endregion

				if (supportedMsg!=SupportedMessages.msgNotSupported)
				{
					if (fCheck) //they just want to know if this is a Supported message
						fLocked=true;
					else
					{
						switch (supportedMsg)
						{
							//if we have the correct message, parse data and get Lat and Lon.
							//TODO: rewrite this in a more efficient way.
							#region GPRMC
							case SupportedMessages.msgGPRMC:
								sMsgField  = m_CSVParser.GetCSVLine(sGPRMC);
								//Proceed with Lat and Lon only if we have an Active lock into the 
								//sattelites.
								if (sMsgField[2].ToUpper()=="A" || gpsSource.bBabelNMEA==true)
								{
									sGpsLat = sMsgField[3];
									iIndex1=sGpsLat.IndexOf('.',0);
									sGpsLatMin = sGpsLat.Substring(iIndex1-2);
									sGpsLat = sGpsLat.Substring(0,iIndex1-2);
									sNS = sMsgField[4];
												
									sGpsLon = sMsgField[5];
									iIndex1=sGpsLon.IndexOf('.',0);
									sGpsLonMin = sGpsLon.Substring(iIndex1-2);
									sGpsLon = sGpsLon.Substring(0,iIndex1-2);
									sEW = sMsgField[6];

									sGpsSpeed = sMsgField[7];
									sGpsHeading = sMsgField[8];

									sGpsDate = sMsgField[9];

									sGpsAlt="NA";

									GetNMEATime(iIndex,sGPRMC);

									fLocked=true;
								}
								break;
							#endregion
							#region GPGGA
							case SupportedMessages.msgGPGGA:
								sMsgField  = m_CSVParser.GetCSVLine(sGPRMC);
								//Proceed with Lat and Lon only if we have an Active lock into the 
								//sattelites.
								if (sMsgField[6]=="1" || sMsgField[6]=="2" || gpsSource.bBabelNMEA==true)
								{
									sGpsLat= sMsgField[2];
									iIndex1=sGpsLat.IndexOf('.',0);
									sGpsLatMin = sGpsLat.Substring(iIndex1-2);
									sGpsLat = sGpsLat.Substring(0,iIndex1-2);
									sNS= sMsgField[3];
						
									sGpsLon= sMsgField[4];
									iIndex1=sGpsLon.IndexOf('.',0);
									sGpsLonMin = sGpsLon.Substring(iIndex1-2);
									sGpsLon = sGpsLon.Substring(0,iIndex1-2);
									sEW= sMsgField[5];


									sGpsAlt = sMsgField[9];
									sGpsAltUnit = sMsgField[10];

									sGpsDate = "NA";
									sGpsSpeed = "NA";
									sGpsHeading = "NA";

									GetNMEATime(iIndex,sGPRMC);

                                    fLocked=true;
								}
								break;
							#endregion
							#region APRS
							case SupportedMessages.msgAPRS:
								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";

								if (gpsSource.GpsPos.m_fLat!=-1000000F && gpsSource.GpsPos.m_fLon!=-1000000F)
									fLocked=true;
								break;
							#endregion
							#region APRSWebSession
							case SupportedMessages.mspAPRSWebSession:
								sGPRMC=sGPRMC.Remove(0,"APRS:".Length);
								CSVReader csvReader = new CSVReader();
								sMsgField = csvReader.GetCSVLine(sGPRMC);
								//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];

								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";

								fLocked=true;
								break;
								#endregion
						}

						if (fLocked)
						{
							#region Convert to WorldWind format
							switch (supportedMsg)
							{
								#region GPRMC, GPGGA
								case SupportedMessages.msgGPRMC:
								case SupportedMessages.msgGPGGA:
									sGpsLatMin=sGpsLatMin.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
									gpsSource.GpsPos.m_fLat = System.Convert.ToDouble(sGpsLatMin)/(float)60;
									gpsSource.GpsPos.m_fLat = System.Convert.ToDouble(sGpsLat) + gpsSource.GpsPos.m_fLat;
									if (sNS.ToUpper()=="S")
										gpsSource.GpsPos.m_fLat*=(float)-1;

									sGpsLonMin=sGpsLonMin.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
									gpsSource.GpsPos.m_fLon = System.Convert.ToDouble(sGpsLonMin)/(float)60;
									gpsSource.GpsPos.m_fLon = System.Convert.ToDouble(sGpsLon) + gpsSource.GpsPos.m_fLon;
									if (sEW.ToUpper()=="W")
										gpsSource.GpsPos.m_fLon*=(float)-1;

									if (sGpsSpeed!="NA")
									{
										sGpsSpeed=sGpsSpeed.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
										gpsSource.GpsPos.m_fSpeed = System.Convert.ToSingle(sGpsSpeed);
										gpsSource.GpsPos.m_sSpeedUnit="knots";
									}
						
									if (sGpsAlt!="NA")
									{
										sGpsAlt=sGpsAlt.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
										gpsSource.GpsPos.m_fAlt = System.Convert.ToSingle(sGpsAlt);
										gpsSource.GpsPos.m_sAltUnit = sGpsAltUnit;
									}
									//						else
									//							gpsSource.GpsPos.m_fAlt=-1F;

									if (sGpsHeading!="NA")
									{
										sGpsHeading=sGpsHeading.Replace('.', Convert.ToChar(CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator));
										gpsSource.GpsPos.m_fHeading = System.Convert.ToSingle(sGpsHeading);
									}

									if (sGpsDate!="NA")
									{
										gpsSource.GpsPos.m_iDay=Convert.ToInt32(sGpsDate.Substring(0,2));
										gpsSource.GpsPos.m_iMonth=Convert.ToInt32(sGpsDate.Substring(2,2));
										gpsSource.GpsPos.m_iYear=Convert.ToInt32(sGpsDate.Substring(4,2));
									}

									//if we have a valid time in datePosition then use it instead of the one
									//in the nmea message. This is mainly used with GpsBabel USB nmea files
									if (gpsSource.datePosition.Year!=1771 && gpsSource.datePosition.Month!=6 &&
										gpsSource.datePosition.Month!=9)
									{
										gpsSource.GpsPos.m_iDay=gpsSource.datePosition.Day;
										gpsSource.GpsPos.m_iMonth=gpsSource.datePosition.Month;
										gpsSource.GpsPos.m_iYear=gpsSource.datePosition.Year;
										gpsSource.GpsPos.m_iHour=gpsSource.datePosition.Hour;
										gpsSource.GpsPos.m_iMin=gpsSource.datePosition.Minute;
										gpsSource.GpsPos.m_iSec=gpsSource.datePosition.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;
									break;
									#endregion
							}
							#endregion
						}
					}
				}
			}
//			#if !DEBUG
			catch (Exception)
			{
				fLocked=false;
			}
//			#endif


			return fLocked;
		}
		public GpsTrackerNMEA(GpsTracker gpsTracker)
		{
			m_GpsTracker=gpsTracker;
			m_Aprs = new GpsTrackerAPRS(gpsTracker);
			m_CSVParser = new CSVReader();
		}
		//
		//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();
		}
        //
        //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();
        }
示例#5
0
		//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;
		}