⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 celltrack.cs

📁 用C#实现的取得CellID和LAC的程序源代码!
💻 CS
字号:
using System;

namespace NiceTracker
{
	/// <summary>
	/// Summary description for CellTrack.
	/// </summary>
	public class CellTrack
	{
		// TODO Custom event handler
		public event EventHandler CellChanged;

		// TODO Custom event handler
		public event EventHandler SignalChanged;

		public CellTrack()
		{}
		
		public GSMCell CurrentCell = new GSMCell();
		public GSMCell LastCell = new GSMCell();

		public string Signal = "0";
		public string CellIDResponse = "";
		public string SignalResponse = "";

		public void Update()
		{			
			updateCellID();			
			updateSignal();
		}

		private void updateSignal()
		{
			string csqString = GSMLib.PerformCSQ();			
			bool updatedSignal = false;

			if ( csqString.IndexOf( "CSQ: " ) != -1 )
			{
				string[] items = csqString.Split( ' ' );
				
				if ( items.Length >= 2 )
				{
					string[] data = items[ 1 ].Split( ',' );

					if ( data.Length >= 1 )
					{
						string new_Signal = stripNoise( data[0] );

						if ( new_Signal != Signal )
						{
							updatedSignal = true;
						}
				
						Signal = new_Signal;													
					}
					else
					{
						Signal = "0";
					}
				}
				else
				{
					Signal = "0";
				}
			}

			if ( updatedSignal )
			{
				if ( SignalChanged != null )
					SignalChanged( this, null );
			}

			SignalResponse = csqString;

		}

		
		private void updateCellID()
		{
			// +CREG: <n>,<stat>[,<lac>,<ci>].
			string cregString = GSMLib.PerformCREG();
			bool updatedCellID = false;
			
			if ( cregString.IndexOf( " " ) != -1 )
			{
				string[] items = cregString.Split( ' ' );
				
				if ( items.Length >= 5 )
				{
					GSMCell newCell = new GSMCell( stripNoise( items[1] ), stripNoise( items[2] ), stripNoise( items[3] ), stripNoise( items[4] ) );

					if ( newCell.LAC != CurrentCell.LAC || newCell.CI != CurrentCell.CI )
					{
						updatedCellID = true;
					}
				
					LastCell = CurrentCell;
					CurrentCell = newCell;
				}
			}

			if ( updatedCellID )
			{
				if ( CellChanged != null )
					CellChanged( this, null );
			}

			CellIDResponse = cregString;
		}

		private string stripNoise( string inStr )
		{
			string outStr = inStr.Replace( ",", "" );
			outStr = outStr.Replace( "\n", "" );
			outStr = outStr.Replace( "\r", "" );

			return outStr;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -