📄 ril.cs
字号:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace RilWrapper
{
public class RIL
{
public static RIL_EVENTS EVENTS=new RIL_EVENTS();
private const int MAXLENGTH_OPERATOR_LONG = 32;
private const int MAXLENGTH_OPERATOR_SHORT = 16;
private const int MAXLENGTH_OPERATOR_NUMERIC = 16;
private const int MAXLENGTH_OPERATOR_COUNTRY_CODE = 8;
private const int MAXLENGTH_BCCH = 48;
private const int MAXLENGTH_NMR = 16;
private const int MAXLENGTH_EQUIPINFO = 128;
private const int MAXLENGTH_DESCRIPTION = 256;
private const int MAXLENGTH_ADDRESS = 256;
private const int RIL_NCLASS_MISC = 0x00400000;
private const int RIL_NOTIFY_SIGNALQUALITY = (0x00000005 | RIL_NCLASS_MISC);
private const string RIL_PARAM_NOT_AVAILABLE = "NA/REQ";
private const string RIL_CMD_TIMEOUT = "Timeout";
//OPERATOR PARAM
private const int RIL_PARAM_ON_LONGNAME = 0x00000001;
private const int RIL_PARAM_ON_SHORTNAME = 0x00000002;
private const int RIL_PARAM_ON_NUMNAME = 0x00000004;
private const int RIL_PARAM_ON_COUNTRY_CODE = 0x00000008;
private const int RIL_PARAM_ON_GSM_ACT = 0x00000010;
private const int RIL_PARAM_ON_GSMCOMPACT_ACT = 0x00000020;
private const int RIL_PARAM_ON_UMTS_ACT = 0x00000040;
private const int RIL_PARAM_ON_ALL = 0x0000007f;
//SIGNAL QUALITY PARAMS
private const int RIL_PARAM_SQ_SIGNALSTRENGTH=0x00000001;
private const int RIL_PARAM_SQ_MINSIGNALSTRENGTH=0x00000002;
private const int RIL_PARAM_SQ_MAXSIGNALSTRENGTH=0x00000004;
private const int RIL_PARAM_SQ_BITERRORRATE=0x00000008;
private const int RIL_PARAM_SQ_LOWSIGNALSTRENGTH=0x00000010;
private const int RIL_PARAM_SQ_HIGHSIGNALSTRENGTH=0x00000020;
private const int RIL_PARAM_SQ_ALL=0x0000003f;
//CELLINFO PARAM
private const int RIL_PARAM_CTI_MOBILECOUNTRYCODE=0x00000001;
private const int RIL_PARAM_CTI_MOBILENETWORKCODE=0x00000002;
private const int RIL_PARAM_CTI_LOCATIONAREACODE=0x00000004;
private const int RIL_PARAM_CTI_CELLID=0x00000008;
private const int RIL_PARAM_CTI_BASESTATIONID=0x00000010;
private const int RIL_PARAM_CTI_BROADCASTCONTROLCHANNEL=0x00000020;
private const int RIL_PARAM_CTI_RXLEVEL=0x00000040;
private const int RIL_PARAM_CTI_RXLEVELFULL=0x00000080;
private const int RIL_PARAM_CTI_RXLEVELSUB=0x00000100;
private const int RIL_PARAM_CTI_RXQUALITY=0x00000200;
private const int RIL_PARAM_CTI_RXQUALITYFULL=0x00000400;
private const int RIL_PARAM_CTI_RXQUALITYSUB=0x00000800;
private const int RIL_PARAM_CTI_IDLETIMESLOT=0x00001000;
private const int RIL_PARAM_CTI_TIMINGADVANCE=0x00002000;
private const int RIL_PARAM_CTI_GPRSCELLID=0x00004000;
private const int RIL_PARAM_CTI_GPRSBASESTATIONID=0x00008000;
private const int RIL_PARAM_CTI_NUMBCCH=0x00010000;
private const int RIL_PARAM_CTI_NMR=0x00020000;
private const int RIL_PARAM_CTI_BCCH=0x00040000;
private const int RIL_PARAM_CTI_ALL=0x0007ffff;
//Equipment Information Param
private const int RIL_PARAM_EI_MANUFACTURER=0x00000001;
private const int RIL_PARAM_EI_MODEL=0x00000002;
private const int RIL_PARAM_EI_REVISION=0x00000004;
private const int RIL_PARAM_EI_SERIALNUMBER=0x00000008;
private const int RIL_PARAM_EI_ALL=0x0000000f;
//Subscriber Information Param
private const int RIL_PARAM_SI_ADDRESS=0x00000001;
private const int RIL_PARAM_SI_DESCRIPTION=0x00000002;
private const int RIL_PARAM_SI_SPEED=0x00000004;
private const int RIL_PARAM_SI_SERVICE=0x00000008;
private const int RIL_PARAM_SI_ITC=0x00000010;
private const int RIL_PARAM_SI_ADDRESSID=0x00000020;
private const int RIL_PARAM_SI_ALL=0x0000003f;
//Address Parm - RILADDRESS
private const int RIL_PARAM_A_TYPE=0x00000001;
private const int RIL_PARAM_A_NUMPLAN=0x00000002;
private const int RIL_PARAM_A_ADDRESS=0x00000004;
private const int RIL_PARAM_A_ALL=0x00000007;
private delegate void RILRESULTCALLBACK(IntPtr dwCode, IntPtr hrCmdID, System.IntPtr lpData, IntPtr cbData, IntPtr dwParam);
private delegate void RILNOTIFYCALLBACK(IntPtr dwCode, System.IntPtr lpData, IntPtr cbData, IntPtr dwParam);
private static bool _vInitialized = false;
private static RILOPERATORNAMES _vOperatore;
private static RILCELLTOWERINFO _cellTowerInfo;
private static RILSIGNALQUALITY _signalQuality;
private static RILEQUIPMENTINFO _equipmentInfo;
private static RILSUBSCRIBERINFO _subscriberInfo;
private static RILADDRESS _address;
private static int _vTimeOut=4;
private static RILNOTIFYCALLBACK NotifyCallback;
private static RILRESULTCALLBACK ResultCallback;
private static System.IntPtr NotifyCallbackPointer;
private static System.IntPtr ResultCallbackPointer;
private static IntPtr hRil;
private static RIL_CMD rilCmd = new RIL_CMD(0, RIL_CMD_TYPE.NONE);
private static RIL_RESULT ril_result;
public static bool isInitialized
{
get { return _vInitialized; }
}
#region Initialize RIL
public static bool Initialize()
{
if (_vInitialized)
return false;
IntPtr res = IntPtr.Zero;
IntPtr port = new IntPtr((int)1);
hRil = IntPtr.Zero;
NotifyCallback = new RIL.RILNOTIFYCALLBACK(RIL._NotifyCallback);
NotifyCallbackPointer = Marshal.GetFunctionPointerForDelegate(NotifyCallback);
ResultCallback = new RIL.RILRESULTCALLBACK(RIL._ResultCallback);
ResultCallbackPointer = Marshal.GetFunctionPointerForDelegate(ResultCallback);
IntPtr dwNotif = new IntPtr((int)0x00FF0000);
//IntPtr dwParam = new IntPtr(0x33FF33FF);
IntPtr dwParam = new IntPtr(0x55AA55AA);
res = RIL_Initialize(port, ResultCallbackPointer, NotifyCallbackPointer, dwNotif, dwParam, out hRil);
if (res != IntPtr.Zero)
return false;
_vInitialized = true;
return true;
}
#endregion
#region Deinitialize RIL
public static void Deinitialize()
{
if (!_vInitialized)
return;
IntPtr res = IntPtr.Zero;
res = RIL_Deinitialize(hRil);
if ((System.Int32)res>=0)
{
_vInitialized = false;
return;
}
return;
}
#endregion
#region GetSignalQuality
public static SIGNALQUALITY GetSignalQuality()
{
IntPtr res = IntPtr.Zero;
res = RIL_GetSignalQuality(hRil);
if ((System.Int32)res > 0)
{
rilCmd.CmdId = (System.Int32)res;
rilCmd.CmdType = RIL_CMD_TYPE.SIGNALQUALITY;
int mult = 0;
while ((mult < (_vTimeOut * 1000)) && (rilCmd.CmdType != RIL_CMD_TYPE.NONE))
{
System.Threading.Thread.Sleep(100);
mult += 100;
}
if (rilCmd.CmdType != RIL_CMD_TYPE.NONE)
return new SIGNALQUALITY(RIL_CMD_TIMEOUT,RIL_CMD_TIMEOUT,RIL_CMD_TIMEOUT,RIL_CMD_TIMEOUT,RIL_CMD_TIMEOUT,RIL_CMD_TIMEOUT);
if (ril_result != RIL_RESULT.OK)
return new SIGNALQUALITY(ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString());
else
return new SIGNALQUALITY( ((_signalQuality.dwParams & RIL_PARAM_SQ_SIGNALSTRENGTH)==0)?RIL_PARAM_NOT_AVAILABLE:_signalQuality.nSignalStrength.ToString(),
((_signalQuality.dwParams & RIL_PARAM_SQ_MINSIGNALSTRENGTH) == 0) ? RIL_PARAM_NOT_AVAILABLE : _signalQuality.nMinSignalStrength.ToString(),
((_signalQuality.dwParams & RIL_PARAM_SQ_MAXSIGNALSTRENGTH) == 0) ? RIL_PARAM_NOT_AVAILABLE : _signalQuality.nMaxSignalStrength.ToString(),
((_signalQuality.dwParams & RIL_PARAM_SQ_BITERRORRATE) == 0) ? RIL_PARAM_NOT_AVAILABLE : _signalQuality.dwBitErrorRate.ToString(),
((_signalQuality.dwParams & RIL_PARAM_SQ_LOWSIGNALSTRENGTH) == 0) ? RIL_PARAM_NOT_AVAILABLE : _signalQuality.nLowSignalStrength.ToString(),
((_signalQuality.dwParams & RIL_PARAM_SQ_HIGHSIGNALSTRENGTH) == 0) ? RIL_PARAM_NOT_AVAILABLE : _signalQuality.nHighSignalStrength.ToString());
}
return null;
}
#endregion
#region GetCellTowerInfo
public static CELLINFO GetCellTowerInfo()
{
IntPtr res = IntPtr.Zero;
res = RIL_GetCellTowerInfo(hRil);
if ((System.Int32)res > 0)
{
rilCmd.CmdId = (System.Int32)res;
rilCmd.CmdType = RIL_CMD_TYPE.CELLTOWERINFO;
int mult = 0;
while ((mult < (_vTimeOut * 1000)) && (rilCmd.CmdType != RIL_CMD_TYPE.NONE))
{
System.Threading.Thread.Sleep(100);
mult += 100;
}
if (rilCmd.CmdType != RIL_CMD_TYPE.NONE)
return new CELLINFO(RIL_CMD_TIMEOUT, RIL_CMD_TIMEOUT, RIL_CMD_TIMEOUT, RIL_CMD_TIMEOUT, RIL_CMD_TIMEOUT, RIL_CMD_TIMEOUT);
if (ril_result != RIL_RESULT.OK)
return new CELLINFO(ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString(), ril_result.ToString());
else
{
string a = _cellTowerInfo.dwBaseStationID.ToString();
string b = _cellTowerInfo.dwCellID.ToString();
string c = _cellTowerInfo.dwGPRSBaseStationID.ToString();
string d = _cellTowerInfo.dwGPRSCellID.ToString();
string e = _cellTowerInfo.dwLocationAreaCode.ToString();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -