RIL PROBLEMS |
| Giuliano Peretti posted at 08-May-08 06:36 |
With this code:
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices;
namespace TEST1 { public partial class Form1 : Form { public delegate void RILRESULTCALLBACK(int dwCode, IntPtr hrCmdID, IntPtr lpData, int cbData, int dwParam); public delegate void RILNOTIFYCALLBACK(int dwCode, IntPtr lpData, int cbData, int dwParam); public static IntPtr hRil;
[StructLayout(LayoutKind.Explicit)] class RILADDRESS { [FieldOffset(0)] public uint dwSize; [FieldOffset(4)] public uint dwParams; [FieldOffset(8)] public uint dwType; [FieldOffset(12)] public uint dwNumPlan; [FieldOffset(16)] public byte[] sAddress = new byte[256 * 2]; //[FieldOffset(528)] }
[StructLayout(LayoutKind.Explicit)] class RILSUBADDRESS { [FieldOffset(0)] public uint dwSize; [FieldOffset(4)] public uint dwParams; [FieldOffset(8)] public uint dwType; [FieldOffset(12)] public byte[] sSubAddress = new byte[256 * 2]; //[FieldOffset(524)] }
[StructLayout(LayoutKind.Explicit)] class RILREMOTEPARTYINFO { [FieldOffset(0)] public uint dwSize; [FieldOffset(4)] public uint dwParams; /*[FieldOffset(8)] public RILADDRESS rilAddress = new RILADDRESS(); [FieldOffset(536)] public RILSUBADDRESS rilSubAddress = new RILSUBADDRESS(); [FieldOffset(1060)] public char[] sDescription = new char[256 * 2]; [FieldOffset(1572)] public uint dwValidity;*/ }
[StructLayout(LayoutKind.Explicit)] class RILCELLTOWERINFO { [FieldOffset(0)] uint dwSize; [FieldOffset(4)] uint dwParams; [FieldOffset(8)] public uint dwMobileCountryCode; [FieldOffset(12)] public uint dwMobileNetworkCode; [FieldOffset(16)] public uint dwLocationAreaCode; [FieldOffset(20)] public uint dwCellID; [FieldOffset(24)] uint dwBaseStationID; [FieldOffset(28)] uint dwBroadcastControlChannel; [FieldOffset(32)] uint dwRxLevel; [FieldOffset(36)] uint dwRxLevelFull; [FieldOffset(40)] uint dwRxLevelSub; [FieldOffset(44)] uint dwRxQuality; [FieldOffset(48)] uint dwRxQualityFull; [FieldOffset(52)] uint dwRxQualitySub; /* More minor interesting fields below */ }
[StructLayout(LayoutKind.Explicit)] class RILRINGINFO { [FieldOffset(0)] public uint dwSize; [FieldOffset(4)] public uint dwParams; [FieldOffset(8)] public uint dwCallType; [FieldOffset(12)] public uint dwAddressID; }
//private static bool done = false; private static string result = "";
[DllImport("ril.dll")] private static extern IntPtr RIL_Initialize(int dwIndex, RILRESULTCALLBACK pfnResult, RILNOTIFYCALLBACK pfnNotify, int dwNotificationClasses, int dwParam, out IntPtr lphRil); [DllImport("ril.dll", EntryPoint = "RIL_GetCellTowerInfo")] private static extern IntPtr RIL_GetCellTowerInfo(IntPtr hRil); [DllImport("ril.dll", EntryPoint = "RIL_Hangup")] private static extern IntPtr RIL_Hangup(IntPtr hRil); [DllImport("ril.dll")] private static extern IntPtr RIL_Deinitialize(IntPtr hRil);
public static void f_notify(int dwCode, IntPtr lpData, int cbData, int dwParam) { string strMsg = "";
switch (dwCode & 0x00ff0000) //RIL_NCLASS_ALL { case 0x00080000: //RIL_NCLASS_SUPSERVICE switch (dwCode & 0xff) { case 0x00000001: // RIL_NOTIFY_CALLERID RILREMOTEPARTYINFO rilRemotePartyInfo = new RILREMOTEPARTYINFO(); Marshal.PtrToStructure(lpData, rilRemotePartyInfo); break; case 0x00000002: // RIL_NOTIFY_DIALEDRID break; case 0x00000003: // RIL_NOTIFY_CALLWAITING break; case 0x00000004: // RIL_NOTIFY_SUPSERVICEDATA break; } strMsg += "SUPSERVICE"; break; case 0x00010000: //RIL_NCLASS_CALLCTRL switch (dwCode & 0xff) { case 0x00000001: // RIL_NOTIFY_RING RILRINGINFO rilRingInfo = new RILRINGINFO(); Marshal.PtrToStructure(lpData, rilRingInfo); switch (rilRingInfo.dwCallType) { case 0x00000000: strMsg += "UNKNOWN "; break; case 0x00000001: strMsg += "VOICE "; //RIL_Hangup(hRil); break; case 0x00000002: strMsg += "DATA "; break; case 0x00000003: strMsg += "FAX "; break; default: strMsg += "UNHANDLED "; break; } break; case 0x00000002: // RIL_NOTIFY_CONNECT strMsg += "CONNECT "; break; case 0x00000003: // RIL_NOTIFY_DISCONNECT strMsg += "DISCONNECT "; break; case 0x0000000B: // RIL_NOTIFY_CALLPROGRESSINFO strMsg += "CPI "; break; default: strMsg += "SOME "; break; } strMsg += "CALL"; break; case 0x00020000: // RIL_NCLASS_MESSAGE switch (dwCode & 0xff) { case 0x00000001: // RIL_NOTIFY_MESSAGE strMsg += "NEW "; break; default: strMsg += "SOME "; break; } strMsg += "SMS"; break; } //MessageBox.Show(strMsg); }
public static void f_result(int dwCode, IntPtr hrCmdID, IntPtr lpData, int cbData, int dwParam) { /*RILCELLTOWERINFO rci = new RILCELLTOWERINFO(); Marshal.PtrToStructure(lpData, rci);
result = String.Format("MCC: {0}, MNC: {1}, LAC: {2}, CID: {3}", rci.dwMobileCountryCode, rci.dwMobileNetworkCode, rci.dwLocationAreaCode, rci.dwCellID); done = true;*/ }
public static string GetCellTowerInfo() { IntPtr res;
RILRESULTCALLBACK result = new RILRESULTCALLBACK(f_result); RILNOTIFYCALLBACK notify = new RILNOTIFYCALLBACK(f_notify);
res = RIL_Initialize(1, result, notify, (0x00010000 | 0x00020000 | 0x00080000), 0, out Form1.hRil); if (res != IntPtr.Zero) return ("Could not initialize Ril"); /*Form1.done = false; Form1.result = ""; res = RIL_GetCellTowerInfo(hRil); int i = 10; while (i-- > 0 && !Form1.done) { System.Threading.Thread.Sleep(1000); }
RIL_Deinitialize(hRil);*/ return Form1.result; } public Form1() { InitializeComponent(); string s = Form1.GetCellTowerInfo(); //MessageBox.Show(s); }
private void button1_Click(object sender, EventArgs e) { RIL_Deinitialize(hRil); Application.Exit(); } } }
at line 136 (Marshal.PtrToStructure(lpData, rilRemotePartyInfo);) there is an exception (NotSupportedException) and i don't understand why!!! Need some help please...........
|
|