<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    隨筆-348  評論-598  文章-0  trackbacks-0

    在Windows Mobile的手機(jī)上面, RIL提供了訪問Radio模塊的接口, 下面以一個簡單的示例說明如何在C#中通過RIL獲得基站信息。
    需要注意的是,下面的代碼可能無法在模擬器上面運(yùn)行,因為缺少必要的類庫,在真機(jī)上沒啥問題。
    第一步. 定義必要的數(shù)據(jù)結(jié)構(gòu)和回調(diào)函數(shù)
    1. 包含基站信息的RILCELLTOWERINFO類
            public class RILCELLTOWERINFO
            {
                public uint cbSize;
                public uint dwParams;
                public uint dwMobileCountryCode;//中國的MCC為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 dwGPRSCellID;
                public uint dwGPRSBaseStationID;
                public uint dwNumBCCH;
            }
     
    2.用于異步返回RIL調(diào)用結(jié)果的回調(diào)函數(shù)RILRESULTCALLBACK
            public delegate void RILRESULTCALLBACK(uint dwCode,
                                                   IntPtr hrCmdID,
                                                   IntPtr lpData,
                                                   uint cbData,
                                                   uint dwParam);
     
    3.在RIL主動發(fā)出notify的時候回調(diào)的提醒函數(shù)RILNOTIFYCALLBACK
     
            public delegate void RILNOTIFYCALLBACK(uint dwCode,
                                                   IntPtr lpData,
                                                   uint cbData,
                                                   uint dwParam);
    注意:這個提醒函數(shù)后面不會用到,但它是作為必要的Native函數(shù)的參數(shù),在pinvoke的時候是不可缺少的 
     
    第二步. 通過pinvoke引用必要的RIL Native函數(shù) 
    RIL_Initialize   , RIL_GetCellTowerInfo,RIL_Deinitialize
            [DllImport("ril.dll")]
            private static extern IntPtr RIL_Initialize(uint dwIndex,
                                                        RILRESULTCALLBACK pfnResult,
                                                        RILNOTIFYCALLBACK 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);
     
    第三步. 通過RIL_GetCellTowerInfo獲取基站信息
    1.初始化一個RIL的實例并返回它的Handle
                hRes = RIL_Initialize(1,                                        // RIL port 1
                                      new RILRESULTCALLBACK(rilResultCallback), // 返回調(diào)用結(jié)果的回調(diào)函數(shù)
                                      null,  0, 0,                                      
                                      out hRil);                                //返回RIL實例的handle
     
    2.定義回調(diào)函數(shù)
            private static AutoResetEvent waithandle = new AutoResetEvent(false);
            public static void rilResultCallback(uint dwCode,
                                                 IntPtr hrCmdID,
                                                 IntPtr lpData,
                                                 uint cbData,
                                                 uint dwParam)
            {
                //構(gòu)造一個RILCELLTOWERINFO類用于存放數(shù)據(jù)
                 rilCellTowerInfo = new RILCELLTOWERINFO();
                Marshal.PtrToStructure(lpData, rilCellTowerInfo);
                //回調(diào)通知
                waithandle.Set();}
     
    3.調(diào)用RIL_GetCellTowerInfo并釋放當(dāng)前RIL實例的handle
    RIL_GetCellTowerInfo(hRil);
                //等待回調(diào)函數(shù)返回
                waithandle.WaitOne();
                //釋放RIL handle
                RIL_Deinitialize(hRil);
     
    結(jié)果與分析:
    以下是在samsungi718+上的測試結(jié)果:
    -rilCellTowerInfo :
      cbSize 2164262660 uint
      dwBaseStationID 706412084 uint
      dwBroadcastControlChannel 0 uint
      dwCellID 0 uint //其實這里的cellid在我機(jī)器上獲取不到,確實非常遺憾
      dwGPRSBaseStationID 706412084 uint
      dwGPRSCellID 158440 uint
      dwIdleTimeSlot 33993204 uint
      dwLocationAreaCode 706412076 uint
      dwMobileCountryCode 0 uint //這個MCC中國應(yīng)該是460,我這里也沒有獲取到
      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
    需要注意的是這里的CellTowerInfo在各個機(jī)型上面的實現(xiàn)程度不一樣,文中提到的RIL相關(guān)函數(shù)嚴(yán)格來說在Windows Mobile 上面都不是必須被實現(xiàn)的,使用時需考慮到這一點(diǎn)。

    實現(xiàn)代碼:
        public partial class Form1 : Form
        {
            
    public Form1()
            {
                InitializeComponent();
            }

            
    public delegate void RILRESULTCALLBACK(uint dwCode,
                                                IntPtr hrCmdID,
                                                IntPtr lpData,
                                                
    uint cbData,
                                                
    uint dwParam);


            
    public delegate void RILNOTIFYCALLBACK(uint dwCode,
                                                   IntPtr lpData,
                                                   
    uint cbData,
                                                   
    uint dwParam);

            [DllImport(
    "ril.dll")]
            
    private static extern IntPtr RIL_Initialize(uint dwIndex,
                                                        RILRESULTCALLBACK pfnResult,
                                                        RILNOTIFYCALLBACK 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);

            
    private static AutoResetEvent waithandle = new AutoResetEvent(false);
            
    private static RILCELLTOWERINFO rilCellTowerInfo;
            
    private IntPtr hRes;
            
    private IntPtr hRil;
            
    public static void rilResultCallback(uint dwCode,
                                                 IntPtr hrCmdID,
                                                 IntPtr lpData,
                                                 
    uint cbData,
                                                 
    uint dwParam)
            {
                
    //構(gòu)造一個RILCELLTOWERINFO類用于存放數(shù)據(jù)
                rilCellTowerInfo = new RILCELLTOWERINFO();
                Marshal.PtrToStructure(lpData, rilCellTowerInfo);
                
    //回調(diào)通知
                waithandle.Set();
            }
     
     

            
    private void button1_Click(object sender, EventArgs e)
            {
                hRes 
    = RIL_Initialize(1,                                        // RIL port 1
                                     new RILRESULTCALLBACK(rilResultCallback), // 返回調(diào)用結(jié)果的回調(diào)函數(shù)
                                     null00,
                                     
    out hRil);    
                
    //返回RIL實例的handle
                RIL_GetCellTowerInfo(hRil);
                
    //等待回調(diào)函數(shù)返回
                waithandle.WaitOne();
                
    //釋放RIL handle
                RIL_Deinitialize(hRil);

            }
        }

        
    public class RILCELLTOWERINFO
        {
            
    public uint cbSize;
            
    public uint dwParams;
            
    public uint dwMobileCountryCode;//中國的MCC為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 dwGPRSCellID;
            
    public uint dwGPRSBaseStationID;
            
    public uint dwNumBCCH;
        }


    ---------------------------------------------------------
    專注移動開發(fā)

    Android, Windows Mobile, iPhone, J2ME, BlackBerry, Symbian
    posted on 2011-06-19 18:22 TiGERTiAN 閱讀(2306) 評論(0)  編輯  收藏 所屬分類: Windows Mobile
    主站蜘蛛池模板: 日韩亚洲变态另类中文| 国产精品免费看香蕉| 亚洲日本一区二区三区在线| 特黄特色大片免费| 又粗又大又长又爽免费视频| 亚洲高清乱码午夜电影网| 免费看美女被靠到爽| 无人视频在线观看免费播放影院| 国产青草视频在线观看免费影院| 亚洲国产成人久久精品软件| 国产福利免费观看| 一区二区三区视频免费观看| 亚洲中文字幕无码日韩| 91精品全国免费观看青青| 亚洲AV人人澡人人爽人人夜夜| 精品四虎免费观看国产高清午夜| 亚洲国产精品第一区二区| 每天更新的免费av片在线观看| 亚洲av无码一区二区三区观看| 成人免费a级毛片无码网站入口| 亚洲精品无码日韩国产不卡av| 四虎影视精品永久免费网站| 二级毛片免费观看全程| 国产亚洲人成无码网在线观看| 野花香高清视频在线观看免费 | 亚洲综合亚洲综合网成人| 两个人看的www免费视频| 91亚洲精品视频| 免费观看的a级毛片的网站| 男女交性无遮挡免费视频| 亚洲va中文字幕无码久久| 无人在线直播免费观看| 免费人成动漫在线播放r18| 亚洲国产精品成人精品无码区 | 国产亚洲美女精品久久久久| 丝袜熟女国偷自产中文字幕亚洲| 88xx成人永久免费观看| 国产偷国产偷亚洲清高APP| 亚洲欧洲自拍拍偷午夜色无码| 日韩欧毛片免费视频| 青青草国产免费国产是公开|