From 78069d6aa915683f6a047b7a8eff98e4c44bee40 Mon Sep 17 00:00:00 2001 From: jason Date: Thu, 25 Jan 2024 14:35:21 +0800 Subject: [PATCH] feat:lettransceiver annotation --- HDFwear/OTA/LETransceiver.h | 14 +++++++------- HDFwear/OTA/LETransceiver.m | 89 ++++++++++++++++++++++++++++++++++++++++------------------------------------------------- HDFwear/OTA/OTAUpdateViewController.h | 16 ++++++++++++++++ HDFwear/OTA/OTAUpdateViewController.m | 31 +++++++++++++++++++++++++++++++ HDFwear/OTA/OTAUpdateViewController.xib | 22 ++++++++++++++++++++++ 5 files changed, 116 insertions(+), 56 deletions(-) create mode 100644 HDFwear/OTA/OTAUpdateViewController.h create mode 100644 HDFwear/OTA/OTAUpdateViewController.m create mode 100644 HDFwear/OTA/OTAUpdateViewController.xib diff --git a/HDFwear/OTA/LETransceiver.h b/HDFwear/OTA/LETransceiver.h index 9c12044..c797480 100644 --- a/HDFwear/OTA/LETransceiver.h +++ b/HDFwear/OTA/LETransceiver.h @@ -16,16 +16,16 @@ NS_ASSUME_NONNULL_BEGIN #define KeyWriteCharacteristicUUID @"kWriteCharacteristicUUID" #define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" -//@protocol LEConnctionDelegate +@protocol LEConnctionDelegate // //@required //- (void)onFoundPeripheral:(CBPeripheral *) peripheral advertisementData:(NSDictionary *) advertisementData; // //@optional -//- (void)onConnectedPeripheral:(CBPeripheral *) peripheral; +- (void)onConnectedPeripheral:(CBPeripheral *) peripheral; //- (void)onDisconnectedPeripheral:(CBPeripheral *) peripheral; // -//@end +@end @protocol LEDataDelegate @@ -35,9 +35,9 @@ NS_ASSUME_NONNULL_BEGIN @end -@interface LETransceiver : NSObject +@interface LETransceiver : NSObject -//@property (weak, nonatomic) id connectionDelegate; +@property (weak, nonatomic) id connectionDelegate; @property (weak, nonatomic) id dataDelegate; //- (void)setUUIDs:(NSDictionary *) uuids; @@ -53,8 +53,8 @@ NS_ASSUME_NONNULL_BEGIN // for BluetoothManager to call @property (weak, nonatomic) CBCentralManager *centralManager; -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error; - +- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error; +- (void)closeOTA; @end NS_ASSUME_NONNULL_END diff --git a/HDFwear/OTA/LETransceiver.m b/HDFwear/OTA/LETransceiver.m index 4945f5d..1cb3891 100644 --- a/HDFwear/OTA/LETransceiver.m +++ b/HDFwear/OTA/LETransceiver.m @@ -13,11 +13,6 @@ #define BLE_UUID_SERVICE_WRITE @"e49a25e0-f69a-11e8-8eb2-f2801f1b9fd1" #define BLE_UUID_SERVICE_READ @"e49a28e1-f69a-11e8-8eb2-f2801f1b9fd1" -#define KeyWriteServiceUUID @"kWriteServiceUUID" -#define KeyIndicateServiceUUID @"kIndicateServiceUUID" -#define KeyWriteCharacteristicUUID @"kWriteCharacteristicUUID" -#define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" - @implementation LETransceiver { NSString *writeServiceUUID; NSString *writeCharacteristicUUID; @@ -36,6 +31,10 @@ } +- (void)closeOTA { + [connectedPeripheral setNotifyValue:NO forCharacteristic:characteristicIndicate]; +} + - (id) init { self = [super init]; if (self) { @@ -72,17 +71,17 @@ // if (indicateServiceUUID) // [servicesUUID addObject:indicateServiceUUID]; // */ -// [centralManager scanForPeripheralsWithServices:nil options:options]; +// [self.centralManager scanForPeripheralsWithServices:nil options:options]; //} //- (void)scanStop { -// [centralManager stopScan]; +// [self.centralManager stopScan]; //} //- (void)connect:(CBPeripheral *)peripheral { // [self scanStop]; // -// [centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}]; +// [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}]; // // if (connectTimer) { // [connectTimer invalidate]; @@ -96,20 +95,12 @@ // } // // NSLog(@"disconnect %@", peripheral.name); -// [centralManager cancelPeripheralConnection:peripheral]; +// [self.centralManager cancelPeripheralConnection:peripheral]; //} //- (BOOL) isPeripheralConnected:(CBPeripheral *) peripheral { -// if (IOS_VERSION >= 7.0) { -// if (peripheral.state == CBPeripheralStateConnected) { -// return YES; -// } -// } else { -//#ifndef __IPHONE_7_0 -// if (peripheral.isConnected) { -// return YES; -// } -//#endif +// if (peripheral.state == CBPeripheralStateConnected) { +// return YES; // } // return NO; //} @@ -157,7 +148,7 @@ // [self disconnect:peripheral]; //} -#pragma mark -- CBCentralManagerDelegate +//#pragma mark -- CBCentralManagerDelegate //- (void)centralManagerDidUpdateState:(CBCentralManager *)central { // NSString *messtoshow; // switch (central.state) { @@ -229,7 +220,7 @@ // } //} -#pragma mark -- CBPeripheralDelegate +//#pragma mark -- CBPeripheralDelegate //- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{ // NSLog(@"didDiscoverServices: %@", peripheral.name); // if (error) { @@ -253,16 +244,16 @@ } NSLog(@"UUID: %@, %@, %@", service.UUID.UUIDString, writeServiceUUID, indicateServiceUUID); - if ([service.UUID.UUIDString isEqualToString:writeServiceUUID]) { + if ([writeServiceUUID containsString:service.UUID.UUIDString]) { for (CBCharacteristic *characteristic in service.characteristics) { NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); - + if ([characteristic.UUID.UUIDString isEqualToString:writeCharacteristicUUID]) characteristicWrite = characteristic; } } - if ([service.UUID.UUIDString isEqualToString:indicateServiceUUID]) { + if ([indicateServiceUUID containsString:service.UUID.UUIDString]) { for (CBCharacteristic *characteristic in service.characteristics) { NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); @@ -278,35 +269,35 @@ connectedPeripheral = peripheral; [connectTimer invalidate]; -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onConnectedPeripheral:)]) { -// [_connectionDelegate onConnectedPeripheral:peripheral]; -// } + if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onConnectedPeripheral:)]) { + [_connectionDelegate onConnectedPeripheral:peripheral]; + } } } -- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error { - -} +//- (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 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]]; - } -} +//- (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 diff --git a/HDFwear/OTA/OTAUpdateViewController.h b/HDFwear/OTA/OTAUpdateViewController.h new file mode 100644 index 0000000..1920d3c --- /dev/null +++ b/HDFwear/OTA/OTAUpdateViewController.h @@ -0,0 +1,16 @@ +// +// OTAUpdateViewController.h +// HDFwear +// +// Created by admin on 2024/1/24. +// + +#import + +NS_ASSUME_NONNULL_BEGIN + +@interface OTAUpdateViewController : UIViewController + +@end + +NS_ASSUME_NONNULL_END diff --git a/HDFwear/OTA/OTAUpdateViewController.m b/HDFwear/OTA/OTAUpdateViewController.m new file mode 100644 index 0000000..9a1aae6 --- /dev/null +++ b/HDFwear/OTA/OTAUpdateViewController.m @@ -0,0 +1,31 @@ +// +// OTAUpdateViewController.m +// HDFwear +// +// Created by admin on 2024/1/24. +// + +#import "OTAUpdateViewController.h" + +@interface OTAUpdateViewController () + +@end + +@implementation OTAUpdateViewController + +- (void)viewDidLoad { + [super viewDidLoad]; + // Do any additional setup after loading the view from its nib. +} + +/* +#pragma mark - Navigation + +// In a storyboard-based application, you will often want to do a little preparation before navigation +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { + // Get the new view controller using [segue destinationViewController]. + // Pass the selected object to the new view controller. +} +*/ + +@end diff --git a/HDFwear/OTA/OTAUpdateViewController.xib b/HDFwear/OTA/OTAUpdateViewController.xib new file mode 100644 index 0000000..da8e6fe --- /dev/null +++ b/HDFwear/OTA/OTAUpdateViewController.xib @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + -- libgit2 0.21.4