-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCBConnector.m
More file actions
65 lines (51 loc) · 2.15 KB
/
CBConnector.m
File metadata and controls
65 lines (51 loc) · 2.15 KB
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
//
// CBConnector.m
// UART_UDP_PROXY
//
// Created by Doug Anson on 2/21/15.
// Copyright (c) 2015 Nordic Semiconductor. All rights reserved.
//
#import "CBConnector.h"
@implementation CBConnector
@synthesize m_delegate;
@synthesize m_cm;
@synthesize m_queue;
@synthesize m_queue_name;
- (id) init:(id<CBCentralManagerDelegate>)delegate queueName:(NSString *)queue_name {
self = [super init];
self.m_delegate = delegate;
self.m_queue_name = queue_name;
[self initCM];
return self;
}
- (void) initCM {
// We want the scanner to scan with dupliate keys (to refresh RRSI every second) so it has to be done using non-main queue
self.m_queue = dispatch_queue_create([self.m_queue_name cStringUsingEncoding:NSASCIIStringEncoding], DISPATCH_QUEUE_SERIAL);
self.m_cm = [[CBCentralManager alloc]initWithDelegate:self queue:self.m_queue];
}
- (void) startScan {
[self.m_cm scanForPeripheralsWithServices:nil options:nil];
}
- (void) stopScan {
[self.m_cm stopScan];
}
- (BOOL) poweredOn {
if (self.m_cm.state == CBCentralManagerStatePoweredOn) return YES;
return NO;
}
- (void) centralManagerDidUpdateState:(CBCentralManager *)central {
[self.m_delegate centralManagerDidUpdateState:central];
}
- (void) centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
[self.m_delegate centralManager:central didDiscoverPeripheral:peripheral advertisementData:advertisementData RSSI:RSSI];
}
- (void) centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
[self.m_delegate centralManager:central didFailToConnectPeripheral:peripheral error:error];
}
- (void) centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
[self.m_delegate centralManager:central didConnectPeripheral:peripheral];
}
- (void) centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
[self.m_delegate centralManager:central didDisconnectPeripheral:peripheral error:error];
}
@end