-
Notifications
You must be signed in to change notification settings - Fork 18
/
VAFieldTestViewController.m
140 lines (110 loc) · 4.12 KB
/
VAFieldTestViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
//
// VAFieldTestViewController.m
// VAFieldTest
//
// Created by Vlad Alexa on 7/6/10.
// Copyright NextDesign 2010. All rights reserved.
//
#import "CoreTelephony.h"
#include <dlfcn.h>
CFMachPortRef mach_port;
CTServerConnectionRef conn;
CFRunLoopSourceRef source;
void ConnectionCallback(CTServerConnectionRef connection, CFStringRef string, CFDictionaryRef dictionary, void *data) {
NSLog(@"ConnectionCallback");
CFShow(dictionary);
}
void NotifCallback(){
NSLog(@"NotifCallback");
}
void Dump(void* x, int size) {
char* c = (char*)x;
int i;
for (i = 0; i < size; i++) {
printf(" %x ", c[i]);
}
NSLog(@"Dumped");
}
void start_monitor(){
conn = _CTServerConnectionCreate(kCFAllocatorDefault, ConnectionCallback,NULL);
NSLog(@"connection=%d",conn);
//Dump(conn, sizeof(struct __CTServerConnection));
mach_port_t port = _CTServerConnectionGetPort(conn);
NSLog(@"port=%d",port);
mach_port = CFMachPortCreateWithPort(kCFAllocatorDefault,port,NULL,NULL, NULL);
NSLog(@"mach_port=%x",CFMachPortGetPort(mach_port));
source = CFMachPortCreateRunLoopSource ( kCFAllocatorDefault, mach_port, 0);
CFRunLoopAddSource([[NSRunLoop currentRunLoop] getCFRunLoop], source, kCFRunLoopCommonModes);
_CTServerConnectionCellMonitorStart(mach_port,conn);
}
void register_notification(){
if (!mach_port || !conn) return;
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LOCAL | RTLD_LAZY);
void *kCTCellMonitorUpdateNotification = dlsym(libHandle, "kCTIndicatorsSignalStrengthNotification");
if( kCTCellMonitorUpdateNotification== NULL) NSLog(@"Could not find kCTCellMonitorUpdateNotification");
int x = 0; //placehoder for callback
_CTServerConnectionRegisterForNotification(conn,kCTCellMonitorUpdateNotification,&x);
}
void printInfo(){
if (!mach_port || !conn) return;
int count = 0;
_CTServerConnectionCellMonitorGetCellCount(mach_port, conn, &count);
if (count > 0) {
int i;
for (i = 0; i < count; i++) {
CellInfoRef cellinfo;
_CTServerConnectionCellMonitorGetCellInfo(mach_port, conn, i, &cellinfo);
NSLog(@"Cell site: %d, MNC: %d ", i, cellinfo->servingmnc);
NSLog(@"Location: %d, Cell ID: %d, Station: %d, ", cellinfo->location,cellinfo->cellid, cellinfo->station);
NSLog(@"Freq: %d, RxLevel: %d, ", cellinfo->freq, cellinfo->rxlevel);
NSLog(@"C1: %d, C2: %d", cellinfo->c1, cellinfo->c2);
}
}else {
NSLog(@"No Cell info");
}
}
int getSignalStrength()
{
void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
int (*CTGetSignalStrength)();
CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength");
int result = CTGetSignalStrength();
dlclose(libHandle);
return result;
}
#import "VAFieldTestViewController.h"
@implementation VAFieldTestViewController
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor viewFlipsideBackgroundColor];
voice = [[NSClassFromString(@"VSSpeechSynthesizer") alloc] init];
start_monitor();
register_notification();
//[(NSValue *)[(NSDictionary *)userInfo objectForKey:@"kCTIndicatorsSignalStrength"] getValue:&rawStrength];
//kCTIndicatorsSignalStrength
//kCTIndicatorsSignalStrengthNotification
//kCTIndicatorsGradedSignalStrength
//kCTIndicatorsRawSignalStrength
[NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(signalLoop) userInfo:nil repeats:YES];
[NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(infoLoop) userInfo:nil repeats:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)dealloc {
[voice release];
[super dealloc];
}
-(void)signalLoop{
[strength setText:[NSString stringWithFormat:@"%i",getSignalStrength()]];
if (voice && oldStrength != [strength.text intValue]) {
[voice startSpeakingString:strength.text];
}
oldStrength = [strength.text intValue];
}
-(void)infoLoop{
printInfo();
}
@end