On a Windows Mobile Phone, rIL provides an interface to access the radio module. The following is a simple example of how to obtain the base station information through RIL in C.
Step 1. Define necessary data structures and callback Functions
1. rilcelltowerinfo class containing the base station information
Public class rilcelltowerinfo
{
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 46_818_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 46_818_closed_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 46_818_closed_text '). style. display = 'inline ';
} "Id =" codehighlighter1_46_818_open_image "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 46_818_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 46_818_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 46_818_open_text '). style. display = 'inline ';
} "Id =" codehighlighter%46_818_closed_image "style =" display: none "> {
Public uint cbsize;
Public uint dwparams;
Public uint dwmobilecountrycode; // MCC in China is 460
Public uint dwmobilenetworkcode;
Public uint dwlocationareacode;
Public uint dwcellid;
Public uint dwbasestationid;
Public uint dwbroadcastcontrolchannel;
Public uint dwrxlevel;
Public uint dwrxlevelfull;
Public uint dwrxlevelsub;
Public uint dwrxquality;
Public uint dwrxqualityfull;
Public uint dwrxqualitysub;
Public uint dwidletimeslot;
Public uint dwtimingadvance;
Public uint dwgprs scellid;
Public uint dwgprs sbasestationid;
Public uint dwnumbcch;
}
2. rilresultcallback, a callback function used to asynchronously return RIL call results
Public Delegate void rilresultcallback (uint dwcode,
Intptr hrcmdid,
Intptr lpdata,
Uint cbdata,
Uint dwparam );
3. Callback reminder function rilpolicycallback when RIL actively sends callback y
Public Delegate void rilpolicycallback (uint dwcode,
Intptr lpdata,
Uint cbdata,
Uint dwparam );
Note: This reminder function will not be used later, but it is a required native function parameter and is indispensable in pinvoke.
Step 2. Use pinvoke to reference necessary RIL native functions
Ril_initialize, ril_getcelltowerinfo, ril_deinitialize
[Dllimport ("RIL. dll")]
Private Static extern intptr ril_initialize (uint dwindex,
Rilresultcallback pfnresult,
Rilpolicycallback pfnnotify,
Uint dwnotificationclasses,
Uint dwparam,
Out intptr lphril );
[Dllimport ("RIL. dll")]
Private Static extern intptr ril_getcelltowerinfo (intptr hril );
[Dllimport ("RIL. dll")]
Private Static extern intptr ril_deinitialize (intptr hril );
Step 3. Obtain the base station information through ril_getcelltowerinfo
1. initialize a RIL instance and return its handle
Hres = ril_initialize (1, // RIL Port 1
New rilresultcallback (rilresultcallback), // return the callback function of the call result
Null, 0, 0,
Out hril); // returns the handle of the RIL instance.
2. Define the callback function
Private Static autoresetevent waithandle = new autoresetevent (false );
Public static void rilresultcallback (uint dwcode,
Intptr hrcmdid,
Intptr lpdata,
Uint cbdata,
Uint dwparam)
{
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 383_871_open_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 383_871_closed_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 383_871_closed_text '). style. display = 'inline ';
} "Id =" codehighlighter0000383_871_open_image "> {
This. style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 383_871_closed_text '). style. display = 'none'; document. getelementbyid ('codehighlighter1 _ 383_871_open_image '). style. display = 'inline'; document. getelementbyid ('codehighlighter1 _ 383_871_open_text '). style. display = 'inline ';
} "Id =" codehighlighter0000383_871_closed_image "style =" display: none "> {
// Construct an rilcelltowerinfo class to store data
Rilcelltowerinfo = new rilcelltowerinfo ();
Marshal. ptrtostructure (lpdata, rilcelltowerinfo );
// Callback notification
Waithandle. Set ();}
3. Call ril_getcelltowerinfo and release the handle of the current RIL instance.
Ril_getcelltowerinfo (hril );
// Wait for the callback function to return
Waithandle. waitone ();
// Release RIL handle
Ril_deinitialize (hril );
Results and Analysis:
The following are the test results on samsungi718 +:
-Rilcelltowerinfo:
Cbsize 2164262660 uint
Dwbasestationid 706412084 uint
Dwbroadcastcontrolchannel 0 uint
Dwcellid 0 uint // actually, the cellid here cannot be obtained on my machine. It is really a pity
Dwgprs sbasestationid 706412084 uint
Dwuplscellid 158440 uint
Dwidletimeslot 33993204 uint
Dwlocationareacode706412076 uint
Dwmobilecountrycode 0 uint // This MCC China should be 460, and I have not obtained it here
Dwmobilenetworkcode 33993204 uint
Dwnumbcch 706411928 uint
Dwparams 0 uint
Dwrxlevel 4 uint
Dwrxlevelfull 0 uint
Dwrxlevelsub 706412004 uint
Dwrxquality 706411908 uint
Dwrxqualityfull 158172 uint
Dwrxqualitysub 67853664 uint
Dwtimingadvance 0 uint
Note that celltowerinfo has different implementation degrees on different models. The RIL-related functions mentioned in this article are strictly mentioned on Windows Mobile.NoMust be implemented. This must be taken into account during use.
You are welcome to add more model testing results in the comments.
Enjoy & Merry Xmas!
Yellow winter
UpdateComplete code: http://files.cnblogs.com/fox23/CellIDSample.rar