本文介绍了得到多个小区的ID使用蜂窝塔C#Windows Mobile的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

继微软的RIL文件我已经能够实现检索小区ID,LAC,MCC,MNC和信号强度的代码。利用这些数据和我能够检索的纬度和经度该手机信号塔。问题是,我需要实现某种形式的三角测量算法,以获得更准确的位置。但是,即使在三角思维之前,我将需要超过一塔ID的工作。我怎样才能得到呢?我试图创建towerIDs的数组,并在循环填充它,而塔id不数组中存在,那么添加它,但如果它存在,那么忽略它并继续寻找另外一个。显然,没有工作,一旦它之一,保持它,如果我删除的对象,并创建一个新的它获得的同塔。我怎样才能得到一个不同?



在此先感谢

 使用系统; 
使用System.Collections.Generic;使用System.Runtime.InteropServices
;
使用System.Text;
使用的System.Threading;

命名空间GPS_Test
{
公共类CellTower的
{
公众诠释的CellID {搞定;组; }

// LAC(本地区号)
公众诠释LAC {搞定;组; }

// MCC(移动国家代码)
公众诠释MCC {搞定;组; }

// MNC(移动网络代码)
公众诠释MNC {搞定;组; }

//接收信号强度
公众诠释signalStrength {搞定;组; }

//基站ID
//公众诠释baseStationID {搞定;组; }
}


公共类RIL
{
公众委托无效RILRESULTCALLBACK(UINT dwCode,
IntPtr的hrCmdID,IntPtr的的lpData,UINT cbData ,UINT dwParam);

公众委托无效RILNOTIFYCALLBACK(UINT dwCode,
的IntPtr的lpData,UINT cbData,UINT dwParam);

函数[DllImport(ril.dll)]
公共静态外部的IntPtr RIL_Initialize(UINT dwIndex,
RILRESULTCALLBACK pfnResult,
RILNOTIFYCALLBACK pfnNotify,
UINT dwNotificationClasses,
UINT dwParam,
OUT的IntPtr lphRil);

函数[DllImport(ril.dll,入口点=RIL_GetCellTowerInfo)]
公共静态外部的IntPtr RIL_GetCellTowerInfo(IntPtr的HRIL);

函数[DllImport(ril.dll)]
公共静态外部的IntPtr RIL_Deinitialize(IntPtr的HRIL);

函数[DllImport(ril.dll,入口点=RIL_GetSignalQuality)]
公共静态外部的IntPtr RIL_GetSignalQuality(IntPtr的HRIL);

[StructLayout(LayoutKind.Explicit)
内部类RILCELLTOWERINFO
{
[FieldOffset(0)]
UINT的dwSize;
[FieldOffset(4)]
UINT dwParams;
[FieldOffset(8)]
公共UINT dwMobileCountryCode;
[FieldOffset(12)]
公共UINT dwMobileNetworkCode;
[FieldOffset(16)]
公共UINT dwLocationAreaCode;
[FieldOffset(20)]
公共UINT dwCellID;
[FieldOffset(28)]
公共UINT dwBaseStationID;
[FieldOffset(36)]
公共UINT dwRxLevel;
}

[StructLayout(LayoutKind.Explicit)
内部类RILSIGNALQUALITY
{
[FieldOffset(0)]
UINT的dwSize;
[FieldOffset(4)]
UINT dwParams;
[FieldOffset(8)]
公众诠释nSignalStrength;
[FieldOffset(12)]
公共UINT nMinSignalStrength;
[FieldOffset(16)]
公共UINT nMaxSignalStrength;
[FieldOffset(20)]
公共UINT dwBitErrorRate;
[FieldOffset(24)]
公共UINT nLowSignalStrength;
[FieldOffset(28)]
公共UINT nHighSignalStrength;
}
}

公共类CellTowerInfo
{
私有静态的AutoResetEvent dataReceived =新的AutoResetEvent(假);
私有静态的AutoResetEvent whSignalQuality =新的AutoResetEvent(假);

私有静态RIL.RILCELLTOWERINFO towerInfo;
私有静态RIL.RILSIGNALQUALITY signalQuality;

公共静态CellTower的GetCellTowerInfo()
{
IntPtr的HRIL = IntPtr.Zero;
IntPtr的HRESULT = IntPtr.Zero;

HRESULT = RIL.RIL_Initialize(1,
新RIL.RILRESULTCALLBACK(CellTowerData)
空,0,0,出HRIL);

如果(HRESULT = IntPtr.Zero!)
返回NULL;

HRESULT = RIL.RIL_GetCellTowerInfo(HRIL);

dataReceived.WaitOne();

RIL.RIL_Deinitialize(HRIL);

CellTower的克拉=新CellTower的();
ct.LAC =(INT)towerInfo.dwLocationAreaCode;
ct.MCC =(INT)towerInfo.dwMobileCountryCode;
ct.MNC =(INT)towerInfo.dwMobileNetworkCode;
ct.CellID =(INT)towerInfo.dwCellID;
ct.signalStrength = GetSignalQuality();

返回克拉;
}


公共静态INT GetSignalQuality()
{
IntPtr的HRES = IntPtr.Zero;
IntPtr的hSignalQ = IntPtr.Zero;

HRES = RIL.RIL_Initialize(1,新RIL.RILRESULTCALLBACK(SignalQualityCallback)
空,0,0,出hSignalQ);

HRES = RIL.RIL_GetSignalQuality(hSignalQ);

whSignalQuality.WaitOne();

RIL.RIL_Deinitialize(hSignalQ);

返回signalQuality.nSignalStrength;
}

私有静态无效CellTowerData(UINT dwCode,IntPtr的hrCmdID,
的IntPtr的lpData,UINT cbData,UINT dwPara)
{
towerInfo =新的RIL .RILCELLTOWERINFO();
Marshal.PtrToStructure(lpData所(对象)towerInfo);
dataReceived.Set();
}

私有静态无效SignalQualityCallback(UINT dwCode,IntPtr的hrCmdID,
的IntPtr的lpData,UINT cbData,UINT dwPara)
{
signalQuality =新的RIL .RILSIGNALQUALITY();
Marshal.PtrToStructure(lpData所(对象)signalQuality);
whSignalQuality.Set();
}
}
}


解决方案

尝试保存所有有关当前信号的信息,这样做后,重新启动寻找另一个信号服务,但首先要检查你已经存储的人,如果是相同的无视和继续寻找。
祝你好运!


Following Microsoft's documentation on RIL I've been able to implement a code that retrieves Cell ID, LAC, MCC, MNC and Signal Strength. Using these data and http://www.opencellid.org/ I'm able to retrieve latitude and longitude of that cell tower. The problem is that I need to implement some kind of triangulation algorithm to get a more accurate position. But before even thinking in triangulation, I'm going to need more than one tower ID to work with. How can I get them? I tried to create an array of towerIDs and populate it in a loop, while a tower id does not exist in the array then add it, but if it exists then ignore it and keep looking for another one. Obviously it did not work, once it gets one it keeps it and if I delete the object and create a new one it gets the same tower. How can I get a different one?

Thanks in advance.

using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading;

namespace GPS_Test
{
    public class CellTower
    {
        public int CellID { get; set; }

        // LAC (Local Area Code)
        public int LAC { get; set; }

        // MCC (Mobile Country Code)
        public int MCC { get; set; }

        // MNC (Mobile Network Code)
        public int MNC { get; set; }

        // Received signal strength
        public int signalStrength { get; set; }

        // Base Station ID
        //public int baseStationID { get; set; }
    }


    public class RIL
    {
        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")]
        public static extern IntPtr RIL_Initialize(uint dwIndex,
            RILRESULTCALLBACK pfnResult,
            RILNOTIFYCALLBACK pfnNotify,
            uint dwNotificationClasses,
            uint dwParam,
            out IntPtr lphRil);

        [DllImport("ril.dll", EntryPoint = "RIL_GetCellTowerInfo")]
        public static extern IntPtr RIL_GetCellTowerInfo(IntPtr hril);

        [DllImport("ril.dll")]
        public static extern IntPtr RIL_Deinitialize(IntPtr hril);

        [DllImport("ril.dll", EntryPoint = "RIL_GetSignalQuality")]
        public static extern IntPtr RIL_GetSignalQuality(IntPtr hRil);

        [StructLayout(LayoutKind.Explicit)]
        internal 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(28)]
            public uint dwBaseStationID;
            [FieldOffset(36)]
            public uint dwRxLevel;
        }

        [StructLayout(LayoutKind.Explicit)]
        internal class RILSIGNALQUALITY
        {
            [FieldOffset(0)]
            uint dwSize;
            [FieldOffset(4)]
            uint dwParams;
            [FieldOffset(8)]
            public int nSignalStrength;
            [FieldOffset(12)]
            public uint nMinSignalStrength;
            [FieldOffset(16)]
            public uint nMaxSignalStrength;
            [FieldOffset(20)]
            public uint dwBitErrorRate;
            [FieldOffset(24)]
            public uint nLowSignalStrength;
            [FieldOffset(28)]
            public uint nHighSignalStrength;
        }
    }

    public class CellTowerInfo
    {
        private static AutoResetEvent dataReceived = new AutoResetEvent(false);
        private static AutoResetEvent whSignalQuality = new AutoResetEvent(false);

        private static RIL.RILCELLTOWERINFO towerInfo;
        private static RIL.RILSIGNALQUALITY signalQuality;

        public static CellTower GetCellTowerInfo()
        {
            IntPtr hRil = IntPtr.Zero;
            IntPtr hResult = IntPtr.Zero;

            hResult = RIL.RIL_Initialize(1,
                new RIL.RILRESULTCALLBACK(CellTowerData),
                null, 0, 0, out hRil);

            if (hResult != IntPtr.Zero)
                return null;

            hResult = RIL.RIL_GetCellTowerInfo(hRil);

            dataReceived.WaitOne();

            RIL.RIL_Deinitialize(hRil);

            CellTower ct = new CellTower();
            ct.LAC = (int)towerInfo.dwLocationAreaCode;
            ct.MCC = (int)towerInfo.dwMobileCountryCode;
            ct.MNC = (int)towerInfo.dwMobileNetworkCode;
            ct.CellID = (int)towerInfo.dwCellID;
            ct.signalStrength = GetSignalQuality();

            return ct;
        }


        public static int GetSignalQuality()
        {
            IntPtr hRes = IntPtr.Zero;
            IntPtr hSignalQ = IntPtr.Zero;

            hRes = RIL.RIL_Initialize(1, new RIL.RILRESULTCALLBACK(SignalQualityCallback),
                null, 0, 0, out hSignalQ);

            hRes = RIL.RIL_GetSignalQuality(hSignalQ);

            whSignalQuality.WaitOne();

            RIL.RIL_Deinitialize(hSignalQ);

            return signalQuality.nSignalStrength;
        }

        private static void CellTowerData(uint dwCode, IntPtr hrCmdID,
            IntPtr lpData, uint cbData, uint dwPara)
        {
            towerInfo = new RIL.RILCELLTOWERINFO();
            Marshal.PtrToStructure(lpData, (object)towerInfo);
            dataReceived.Set();
        }

        private static void SignalQualityCallback(uint dwCode, IntPtr hrCmdID,
            IntPtr lpData, uint cbData, uint dwPara)
        {
            signalQuality = new RIL.RILSIGNALQUALITY();
            Marshal.PtrToStructure(lpData, (object)signalQuality);
            whSignalQuality.Set();
        }
    }
}
解决方案

Try to save all the info regarding the current signal, after doing so restart the service looking to another signal but first check the one you had stored, if it's the same disregard and keep looking.Good luck!

这篇关于得到多个小区的ID使用蜂窝塔C#Windows Mobile的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 02:34
查看更多