diff --git a/HDFwear/OTA/LETransceiver.h b/HDFwear/OTA/LETransceiver.h index c797480..fb2580d 100644 --- a/HDFwear/OTA/LETransceiver.h +++ b/HDFwear/OTA/LETransceiver.h @@ -17,42 +17,15 @@ NS_ASSUME_NONNULL_BEGIN #define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" @protocol LEConnctionDelegate -// -//@required -//- (void)onFoundPeripheral:(CBPeripheral *) peripheral advertisementData:(NSDictionary *) advertisementData; -// -//@optional - (void)onConnectedPeripheral:(CBPeripheral *) peripheral; -//- (void)onDisconnectedPeripheral:(CBPeripheral *) peripheral; -// -@end - -@protocol LEDataDelegate - -@optional - -- (void)onDataReceive:(NSData *) data; - @end @interface LETransceiver : NSObject - @property (weak, nonatomic) id connectionDelegate; -@property (weak, nonatomic) id dataDelegate; - -//- (void)setUUIDs:(NSDictionary *) uuids; - -//- (void)scanStart; -//- (void)scanStop; - -//- (void)connect:(CBPeripheral *)peripheral; -//- (void)disconnect:(CBPeripheral *)peripheral; - - (void)write:(NSData *) data; - (void)write:(NSData *) data index:(int) i; // for BluetoothManager to call -@property (weak, nonatomic) CBCentralManager *centralManager; - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error; - (void)closeOTA; @end diff --git a/HDFwear/OTA/LETransceiver.m b/HDFwear/OTA/LETransceiver.m index 1cb3891..ca3086d 100644 --- a/HDFwear/OTA/LETransceiver.m +++ b/HDFwear/OTA/LETransceiver.m @@ -62,49 +62,6 @@ } } -//- (void)scanStart { -// NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil]; -// /* -// NSMutableArray *servicesUUID = [[NSMutableArray alloc] init]; -// if (writeServiceUUID) -// [servicesUUID addObject:writeServiceUUID]; -// if (indicateServiceUUID) -// [servicesUUID addObject:indicateServiceUUID]; -// */ -// [self.centralManager scanForPeripheralsWithServices:nil options:options]; -//} - -//- (void)scanStop { -// [self.centralManager stopScan]; -//} - -//- (void)connect:(CBPeripheral *)peripheral { -// [self scanStop]; -// -// [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}]; -// -// if (connectTimer) { -// [connectTimer invalidate]; -// } -// connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(connectTimeout:) userInfo:peripheral repeats:NO]; -//} - -//- (void)disconnect:(CBPeripheral *)peripheral { -// if (![self isPeripheralConnected:peripheral]) { -// return; -// } -// -// NSLog(@"disconnect %@", peripheral.name); -// [self.centralManager cancelPeripheralConnection:peripheral]; -//} - -//- (BOOL) isPeripheralConnected:(CBPeripheral *) peripheral { -// if (peripheral.state == CBPeripheralStateConnected) { -// return YES; -// } -// return NO; -//} - - (NSUInteger) getMtuForType:(CBCharacteristicWriteType) type { return [connectedPeripheral maximumWriteValueLengthForType:type]; } @@ -143,99 +100,6 @@ } } -//- (void)connectTimeout:(NSTimer *)timer { -// CBPeripheral *peripheral = (CBPeripheral *)[timer userInfo]; -// [self disconnect:peripheral]; -//} - -//#pragma mark -- CBCentralManagerDelegate -//- (void)centralManagerDidUpdateState:(CBCentralManager *)central { -// NSString *messtoshow; -// switch (central.state) { -// case CBManagerStatePoweredOn:{ -// messtoshow=[NSString stringWithFormat:@"CBCentralManagerStatePoweredOn"]; -// [self scanStart]; -// break; -// } -// case CBManagerStateUnknown: -// { -// messtoshow=[NSString stringWithFormat:@"State unknown, update imminent"]; -// break; -// } -// case CBManagerStateResetting: -// { -// messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."]; -// break; -// } -// case CBManagerStateUnsupported: -// { -// messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"]; -// break; -// } -// case CBManagerStateUnauthorized: -// { -// messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"]; -// break; -// } -// case CBManagerStatePoweredOff: -// { -// [self disconnect:connectedPeripheral]; -// -// messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off"]; -// break; -// } -// default: -// break; -// } -// NSLog(@"%@",messtoshow); -//} - -//- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{ -//// NSLog(@"didDiscoverPeripheral: %@", peripheral); -// -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onFoundPeripheral:advertisementData:)]) { -// [_connectionDelegate onFoundPeripheral:peripheral advertisementData:advertisementData]; -// } -//} - -//- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{ -// NSLog(@"didConnectPeripheral: %@", peripheral.name); -// -// peripheral.delegate = self; -// [peripheral discoverServices:nil]; -//} - -//- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ -// NSLog(@"Fail to connect: %@", peripheral.name); -//} - -//- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{ -// NSLog(@"didDisconnectPeripheral %@, error: %@",peripheral, error); -// -// connectedPeripheral = nil; -// characteristicWrite = nil; -// characteristicIndicate = nil; -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onDisconnectedPeripheral:)]) { -// [_connectionDelegate onDisconnectedPeripheral:peripheral]; -// } -//} - -//#pragma mark -- CBPeripheralDelegate -//- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{ -// NSLog(@"didDiscoverServices: %@", peripheral.name); -// if (error) { -// NSLog(@"Error discovering service:%@", [error localizedDescription]); -// return; -// } -// -// for (CBService *service in peripheral.services) { -// -// NSLog(@"service: %@", service); -// [peripheral discoverCharacteristics:nil forService:service]; -// } -// -//} - - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{ NSLog(@"didDiscoverCharacteristicsForService: %@, %@", peripheral.name, service.UUID.UUIDString); if (error) { @@ -275,29 +139,4 @@ } } -//- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error { -// -//} - -//- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { -// -// if (error) { -// NSLog(@"%@,%@,Error didWriteValueForCharacteristic:%@",characteristic.UUID,[characteristic value], [error localizedDescription]); -// return; -// } -// -//} - -//- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { -// if (error) { -// NSLog(@"Error didUpdateValueForCharacteristic:%@", [error localizedDescription]); -// return; -// } -// NSLog(@"didUpdateValueForCharacteristic: %@ %@", characteristic.UUID, characteristic.value); -// -// if (_dataDelegate && [_dataDelegate respondsToSelector:@selector(onDataReceive:)]) { -// [_dataDelegate onDataReceive:[characteristic value]]; -// } -//} - @end