MCC:460;MNC:0;simoncelli的哀悼会...

Pages: 1/6
主题 : 获取CELLID,LAC等信息方法
级别: 骑士
可可豆: 2045 CB
威望: 2045 点
在线时间: 724(时)
发自: Web Page
来源于&&分类
获取CELLID,LAC等信息方法&&&
搞了一个来月的这个东西了,还是没有完全解决问题,下面方法可以获取简单的Cell信息,方法一://CoreTelephony.h//主要就这两个结构体,其他需要的话,自己添加struct CTServerConnection{ int int b;CFMachPortRef int int int int int int int};struct CellInfo{ int int int int int int int// int c1; int c2;};//.m#import &GetGsmInfo.h&#import &CoreTelephony.h&#include &dlfcn.h&CFMachPortRstruct CTServerConnection *sc=NULL;struct CTServerCstruct CellIintint t1;@implementationGetGsmInfoint callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){printf(&Callback called\n&); return0;}- (void) getCellInfo{ intchar* sdk_path = &/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony&; int* handle =dlopen(sdk_path, RTLD_LAZY); void (*CTServerConnectionCellMonitorGetCellInfo)() = dlsym(handle, &_CTServerConnectionCellMonitorGetCellInfo&); int* (*CTServerConnectionCellMonitorGetCellCount)() = dlsym(handle, &_CTServerConnectionCellMonitorGetCellCount&); void (*CTServerConnectionCellMonitorStart)() = dlsym(handle, &_CTServerConnectionCellMonitorStart&); struct CTServerConnection * (*CTServerConnectionCreate)() = dlsym(handle, &_CTServerConnectionCreate&); int (*CTServerConnectionGetPort)() = dlsym(handle, &_CTServerConnectionGetPort&);
sc=CTServerConnectionCreate(kCFAllocatorDefault, callback, &t1); for(b=0;b&b++) { NSAutoreleasePool* pool = [[NSAutoreleasePoolalloc] init];
memset(&cellinfo, 0, sizeof(struct CellInfo)); int ts = 0;
/** 这个方法的问题出现在这里,3.0以前的版本是4个参数,运行后会崩溃,这个我花了很长时间发现是5个参数,不过获取的结果不理想,只获取了5个结果,其他4个是错误的,如果有人知道请,跟贴,或告诉我下,谢谢了*/ CTServerConnectionCellMonitorGetCellInfo(&t1, sc, b, &ts, &cellinfo); printf(&Cell Site: %d, MNC: %d, &,b,cellinfo.servingmnc);printf(&LAC: %d, Cell ID: %d, Station: %d, &,cellinfo.location, cellinfo.cellid, cellinfo.station);printf(&Freq: %d, RxLevel: %d, &, cellinfo.freq, cellinfo.rxlevel);printf(&C1: %d, C2: %d\n&, cellinfo.c1, cellinfo.c2);
[pool release]; pool = nil; }
dlclose(handle);}把上面的东西直接加,必须在真机上调试(要插上卡哦),才能看到结果哦,其中获取项有MNC,MCC,LAC,CELLID,PXLEVEL,其他四项返回-1,如果有人知道请告诉我下,谢谢了,方法2:串口通信,这个方法很实用,可以解决很多问题,这个我也是找网上的资料,只是拿来用罢了,代码如下:#include &at.h&int fd= InitConn(115200); AT(fd); char buf[100] = &&; /** 这里是发送的AT命令,如下面的命令,可以获取CELL的一些信息, 还有其他的一些信息,网上找找就有了,不过不是所有的命令都可以用哦,有些iphone没有留接口,有就用到一个命令AT+CCED=0,1,这个可以获取CELL的较详细的信息,但是IPHONE就没有留接口,没法用,悲剧*/ //下面是一些我找到的,可以用的命令//获取小区信息//SendStrCmd(fd, &AT+CREG=2;+CREG?\r\n&);//获取当前小区的信号强度//SendStrCmd(fd, &AT+CSQ\r\n&);//基带信息//SendStrCmd(fd, &At+xgendata\r\n&);//获得IMSI。这命令用来读取或者识别SIM卡的IMSI(国际移动签署者标识)。在读取IMSI之前应该先输入PIN(如果需要PIN的话)。//SendStrCmd(fd, &AT+CCID\r\n&);//获得SIM卡的标识。这个命令使模块读取SIM卡上的EF-CCID文件//SendStrCmd(fd, &AT+CCID\r\n&);//读取信息中心号码//SendStrCmd(fd, &AT+CSCA?\r\n&);//单元广播信息标识。//SendStrCmd(fd, &AT+CSCB?\r\n&);SendStrCmd(fd, &AT+XCELLINFO=1\r\n&); while (1)  { read(fd, buf, 100); printf(&%s&, buf); memset(buf, 0, 100); };使用前,下载我的附件,把它们加入工程,然后用上面的方法就可以获取信息,获取的信息为mcc,mnc,lac,cellid,rssi。还有前后两个整数,应该是标示当前CELL的,我还想获取更详细的关于CELL的信息,如果有人知道请告诉我下,谢谢,注意:在使用上面的方法时,我奉劝使用第二个方法,虽然第一个简单,易操作,但是,有内存问题,程序容易崩溃,现在我也没有解决那个问题,所有用的第二个方法,自己解析AT获取的数据。还有第二个方法,我是在iphone 3GS上试的,iphone4断口打开了,但是一直获取不到数据,运行不过去,如果有知道原因的,请告诉下,谢谢,[ 此帖被tiger723在 16:16重新编辑 ]
级别: 新手上路
可可豆: 172 CB
威望: 172 点
在线时间: 86(时)
发自: Web Page
楼主~我不大会。能不能完整工程发给我看看!
级别: 新手上路
可可豆: 172 CB
威望: 172 点
在线时间: 86(时)
发自: Web Page
signalstrength我是获取过,但是跟*#*不一样 不是负数,值也有所不同啊!求探讨,求教!
级别: 骑士
可可豆: 2045 CB
威望: 2045 点
在线时间: 724(时)
发自: Web Page
回 2楼(monikey) 的帖子
signalstrength不知道什么,呵呵 我没获取那个 找AT命令吧,应该有的
级别: 骑士
可可豆: 2045 CB
威望: 2045 点
在线时间: 724(时)
发自: Web Page
回 1楼(monikey) 的帖子
帮不了你 上面的就是所有了&&你创建个工程 把那些拷贝进去就是的
级别: 新手上路
可可豆: 123 CB
威望: 123 点
在线时间: 4(时)
发自: Web Page
你好,请问你有qq或者邮箱么有问题想请教你啊我的邮箱是
级别: 新手上路
可可豆: 283 CB
威望: 173 点
在线时间: 290(时)
发自: Web Page
回 楼主(tiger723) 的帖子
楼主的方法管用不,俺正需要查询这方面的信息。祈求能用啊
级别: 新手上路
可可豆: 187 CB
威望: 187 点
在线时间: 95(时)
发自: Web Page
楼主你好,我用iphone4,Ios5设备测了你的程序。 但我的 int fd = open(&/dev/tty.debug&, O_RDWR | O_NOCTTY); 返回结果总是-1。&& 看了这篇文章后,我试着改为&&int fd = open(&/dev/dlci.spi-baseband.extra_0&, O_RDWR | O_NOCTTY); 后,返回还是-1。请问有解决办法么?
级别: 新手上路
可可豆: 187 CB
威望: 187 点
在线时间: 95(时)
发自: Web Page
刚从网上看到机子要越狱才行?
级别: 新手上路
可可豆: 187 CB
威望: 187 点
在线时间: 95(时)
发自: Web Page
折腾了一天,终于把楼主的第一个方法调通了,在未越狱的装有ios 5.0的iPhone4上多次测试,可获得LAC和CellID,多次运行程序也不会崩溃了。改动的主要两方面:1.dlsym()方法只是获取到了所需函数的指针,需要执行相应函数才能取得所需的值;2.方法的执行顺序应该为:打开动态库、创建服务、执行服务(先取得信息数再循环取得信息)、关闭动态库。我把改动并加了点注释的代码贴到下面供大家指正和参考://CoreTelephony.m#import &CoreTelephony.h&#include &dlfcn.h&#import &UIKit/UIKit.h&#include &stdio.h&#include &stdlib.h&CFMachPortRstruct CTServerConnection *sc=NULL;//struct CTServerCstruct CellIint t1;@implementation CoreTelephonyint callback(CFNotificationCenterRef center, void *observer, CFStringRef name, const void *object, CFDictionaryRef userInfo){&&&&printf(&Callback called\n&);&&&&return 0;}- (void) getCellInfo{&&&&&&&&char* sdk_path = &/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony&;&&&&&&&&// void * dlopen( const char * pathname, int mode ); &&&&// 功能:以指定模式打开指定的动态连接库文件,并返回一个句柄给调用进程。 打开错误返回NULL,成功,返回库引用&&&&// RTLD_LAZY 暂缓决定,等有需要时再解出符号。这个参数使得未解析的symbol将在使用时去解析&&&&int* handle =dlopen(sdk_path, RTLD_LAZY);&&&&if (handle == NULL) {&&&&&&&&&&&&}&&&&&&&&// void* dlsym(void* handle,const char* symbol) 该函数在&dlfcn.h&文件中。将库中的一个函数绑定到预定义的函数地址(即获取到函数的指针)。handle是由dlopen打开动态链接库后返回的指针,symbol就是要求获取的函数的名称,函数返回值是void*,指向函数的地址,供调用使用。&&&&struct CTServerConnection * (*CTServerConnectionCreate)() = dlsym(handle, &_CTServerConnectionCreate&);&&&&sc=CTServerConnectionCreate(kCFAllocatorDefault, callback, &t1);&&&&//&&&&int (*CTServerConnectionGetPort)() = dlsym(handle, &_CTServerConnectionGetPort&);//&&&&port=CFMachPortCreateWithPort(kCFAllocatorDefault, _CTServerConnectionGetPort(sc), NULL, NULL, NULL);&&&&&&&&void (*CTServerConnectionCellMonitorStart)() = dlsym(handle, &_CTServerConnectionCellMonitorStart&);&&&&CTServerConnectionCellMonitorStart(&t1,sc);&&&&&&&&int* (*CTServerConnectionCellMonitorGetCellCount)() = dlsym(handle, &_CTServerConnectionCellMonitorGetCellCount&);&&&&CTServerConnectionCellMonitorGetCellCount(&t1,sc,&cellcount);&&&&NSLog(@&cellcount:%d&,cellcount);&&&&&&&&void (*CTServerConnectionCellMonitorGetCellInfo)() = dlsym(handle, &_CTServerConnectionCellMonitorGetCellInfo&);&&&&&&&&for(int b=0;b&b++)&&&&{ &&&&&&&&NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];&&&&&&&&&&&&&&&&memset(&cellinfo, 0, sizeof(struct CellInfo));&&&&&&&&int ts = 0;&&&&&&&&&&&&&&&&/** 这个方法的问题出现在这里,3.0以前的版本是4个参数,运行后会崩溃,后来发现新版本中是5个参数,不过获取的结果不理想,只获取了5个结果:MNC,MCC,LAC,CELLID,PXLEVEL,其他4项四项返回-1*/&&&&&&&&CTServerConnectionCellMonitorGetCellInfo(&t1, sc, b, &ts, &cellinfo);&&&&&&&&&&&&&&&&printf(&Cell Site: %d, MNC: %d, &,b,cellinfo.servingmnc);&&&&&&&&printf(&LAC: %d, Cell ID: %d, Station: %d, &,cellinfo.location, cellinfo.cellid, cellinfo.station);&&&&&&&&printf(&Freq: %d, RxLevel: %d, &, cellinfo.freq, cellinfo.rxlevel);&&&&&&&&printf(&C1: %d, C2: %d\n&, cellinfo.c1, cellinfo.c2);&&&&&&&&&&&&&&&&[pool release];&&&&&&&&pool =&&&&}&&&&&&&&// 使用dlclose()来卸载打开的库&&&&dlclose(handle);}
Pages: 1/6
关注本帖(如果有新回复会站内信通知您)
iPhone5的分辨率? 正确答案:
发帖、回帖都会得到可观的积分奖励。
按"Ctrl+Enter"直接提交
关注CocoaChina
关注微信 每日推荐
扫一扫 浏览移动版Subscriber Login
Latest Analysis
(C) 2014 Media Partners Asia, Ltd. All rights reserved.
For further information or assistance, please

我要回帖

更多关于 simoncelli的哀悼会 的文章

 

随机推荐