Commit 78069d6aa915683f6a047b7a8eff98e4c44bee40
1 parent
671a3d9e
feat:lettransceiver annotation
Showing
5 changed files
with
116 additions
and
56 deletions
HDFwear/OTA/LETransceiver.h
@@ -16,16 +16,16 @@ NS_ASSUME_NONNULL_BEGIN | @@ -16,16 +16,16 @@ NS_ASSUME_NONNULL_BEGIN | ||
16 | #define KeyWriteCharacteristicUUID @"kWriteCharacteristicUUID" | 16 | #define KeyWriteCharacteristicUUID @"kWriteCharacteristicUUID" |
17 | #define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" | 17 | #define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" |
18 | 18 | ||
19 | -//@protocol LEConnctionDelegate <NSObject> | 19 | +@protocol LEConnctionDelegate <NSObject> |
20 | // | 20 | // |
21 | //@required | 21 | //@required |
22 | //- (void)onFoundPeripheral:(CBPeripheral *) peripheral advertisementData:(NSDictionary *) advertisementData; | 22 | //- (void)onFoundPeripheral:(CBPeripheral *) peripheral advertisementData:(NSDictionary *) advertisementData; |
23 | // | 23 | // |
24 | //@optional | 24 | //@optional |
25 | -//- (void)onConnectedPeripheral:(CBPeripheral *) peripheral; | 25 | +- (void)onConnectedPeripheral:(CBPeripheral *) peripheral; |
26 | //- (void)onDisconnectedPeripheral:(CBPeripheral *) peripheral; | 26 | //- (void)onDisconnectedPeripheral:(CBPeripheral *) peripheral; |
27 | // | 27 | // |
28 | -//@end | 28 | +@end |
29 | 29 | ||
30 | @protocol LEDataDelegate <NSObject> | 30 | @protocol LEDataDelegate <NSObject> |
31 | 31 | ||
@@ -35,9 +35,9 @@ NS_ASSUME_NONNULL_BEGIN | @@ -35,9 +35,9 @@ NS_ASSUME_NONNULL_BEGIN | ||
35 | 35 | ||
36 | @end | 36 | @end |
37 | 37 | ||
38 | -@interface LETransceiver : NSObject<CBPeripheralDelegate, CBCentralManagerDelegate> | 38 | +@interface LETransceiver : NSObject |
39 | 39 | ||
40 | -//@property (weak, nonatomic) id<LEConnctionDelegate> connectionDelegate; | 40 | +@property (weak, nonatomic) id<LEConnctionDelegate> connectionDelegate; |
41 | @property (weak, nonatomic) id<LEDataDelegate> dataDelegate; | 41 | @property (weak, nonatomic) id<LEDataDelegate> dataDelegate; |
42 | 42 | ||
43 | //- (void)setUUIDs:(NSDictionary *) uuids; | 43 | //- (void)setUUIDs:(NSDictionary *) uuids; |
@@ -53,8 +53,8 @@ NS_ASSUME_NONNULL_BEGIN | @@ -53,8 +53,8 @@ NS_ASSUME_NONNULL_BEGIN | ||
53 | 53 | ||
54 | // for BluetoothManager to call | 54 | // for BluetoothManager to call |
55 | @property (weak, nonatomic) CBCentralManager *centralManager; | 55 | @property (weak, nonatomic) CBCentralManager *centralManager; |
56 | -- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error; | ||
57 | - | 56 | +- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error; |
57 | +- (void)closeOTA; | ||
58 | @end | 58 | @end |
59 | 59 | ||
60 | NS_ASSUME_NONNULL_END | 60 | NS_ASSUME_NONNULL_END |
HDFwear/OTA/LETransceiver.m
@@ -13,11 +13,6 @@ | @@ -13,11 +13,6 @@ | ||
13 | #define BLE_UUID_SERVICE_WRITE @"e49a25e0-f69a-11e8-8eb2-f2801f1b9fd1" | 13 | #define BLE_UUID_SERVICE_WRITE @"e49a25e0-f69a-11e8-8eb2-f2801f1b9fd1" |
14 | #define BLE_UUID_SERVICE_READ @"e49a28e1-f69a-11e8-8eb2-f2801f1b9fd1" | 14 | #define BLE_UUID_SERVICE_READ @"e49a28e1-f69a-11e8-8eb2-f2801f1b9fd1" |
15 | 15 | ||
16 | -#define KeyWriteServiceUUID @"kWriteServiceUUID" | ||
17 | -#define KeyIndicateServiceUUID @"kIndicateServiceUUID" | ||
18 | -#define KeyWriteCharacteristicUUID @"kWriteCharacteristicUUID" | ||
19 | -#define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID" | ||
20 | - | ||
21 | @implementation LETransceiver { | 16 | @implementation LETransceiver { |
22 | NSString *writeServiceUUID; | 17 | NSString *writeServiceUUID; |
23 | NSString *writeCharacteristicUUID; | 18 | NSString *writeCharacteristicUUID; |
@@ -36,6 +31,10 @@ | @@ -36,6 +31,10 @@ | ||
36 | 31 | ||
37 | } | 32 | } |
38 | 33 | ||
34 | +- (void)closeOTA { | ||
35 | + [connectedPeripheral setNotifyValue:NO forCharacteristic:characteristicIndicate]; | ||
36 | +} | ||
37 | + | ||
39 | - (id) init { | 38 | - (id) init { |
40 | self = [super init]; | 39 | self = [super init]; |
41 | if (self) { | 40 | if (self) { |
@@ -72,17 +71,17 @@ | @@ -72,17 +71,17 @@ | ||
72 | // if (indicateServiceUUID) | 71 | // if (indicateServiceUUID) |
73 | // [servicesUUID addObject:indicateServiceUUID]; | 72 | // [servicesUUID addObject:indicateServiceUUID]; |
74 | // */ | 73 | // */ |
75 | -// [centralManager scanForPeripheralsWithServices:nil options:options]; | 74 | +// [self.centralManager scanForPeripheralsWithServices:nil options:options]; |
76 | //} | 75 | //} |
77 | 76 | ||
78 | //- (void)scanStop { | 77 | //- (void)scanStop { |
79 | -// [centralManager stopScan]; | 78 | +// [self.centralManager stopScan]; |
80 | //} | 79 | //} |
81 | 80 | ||
82 | //- (void)connect:(CBPeripheral *)peripheral { | 81 | //- (void)connect:(CBPeripheral *)peripheral { |
83 | // [self scanStop]; | 82 | // [self scanStop]; |
84 | // | 83 | // |
85 | -// [centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}]; | 84 | +// [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}]; |
86 | // | 85 | // |
87 | // if (connectTimer) { | 86 | // if (connectTimer) { |
88 | // [connectTimer invalidate]; | 87 | // [connectTimer invalidate]; |
@@ -96,20 +95,12 @@ | @@ -96,20 +95,12 @@ | ||
96 | // } | 95 | // } |
97 | // | 96 | // |
98 | // NSLog(@"disconnect %@", peripheral.name); | 97 | // NSLog(@"disconnect %@", peripheral.name); |
99 | -// [centralManager cancelPeripheralConnection:peripheral]; | 98 | +// [self.centralManager cancelPeripheralConnection:peripheral]; |
100 | //} | 99 | //} |
101 | 100 | ||
102 | //- (BOOL) isPeripheralConnected:(CBPeripheral *) peripheral { | 101 | //- (BOOL) isPeripheralConnected:(CBPeripheral *) peripheral { |
103 | -// if (IOS_VERSION >= 7.0) { | ||
104 | -// if (peripheral.state == CBPeripheralStateConnected) { | ||
105 | -// return YES; | ||
106 | -// } | ||
107 | -// } else { | ||
108 | -//#ifndef __IPHONE_7_0 | ||
109 | -// if (peripheral.isConnected) { | ||
110 | -// return YES; | ||
111 | -// } | ||
112 | -//#endif | 102 | +// if (peripheral.state == CBPeripheralStateConnected) { |
103 | +// return YES; | ||
113 | // } | 104 | // } |
114 | // return NO; | 105 | // return NO; |
115 | //} | 106 | //} |
@@ -157,7 +148,7 @@ | @@ -157,7 +148,7 @@ | ||
157 | // [self disconnect:peripheral]; | 148 | // [self disconnect:peripheral]; |
158 | //} | 149 | //} |
159 | 150 | ||
160 | -#pragma mark -- CBCentralManagerDelegate | 151 | +//#pragma mark -- CBCentralManagerDelegate |
161 | //- (void)centralManagerDidUpdateState:(CBCentralManager *)central { | 152 | //- (void)centralManagerDidUpdateState:(CBCentralManager *)central { |
162 | // NSString *messtoshow; | 153 | // NSString *messtoshow; |
163 | // switch (central.state) { | 154 | // switch (central.state) { |
@@ -229,7 +220,7 @@ | @@ -229,7 +220,7 @@ | ||
229 | // } | 220 | // } |
230 | //} | 221 | //} |
231 | 222 | ||
232 | -#pragma mark -- CBPeripheralDelegate | 223 | +//#pragma mark -- CBPeripheralDelegate |
233 | //- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{ | 224 | //- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{ |
234 | // NSLog(@"didDiscoverServices: %@", peripheral.name); | 225 | // NSLog(@"didDiscoverServices: %@", peripheral.name); |
235 | // if (error) { | 226 | // if (error) { |
@@ -253,16 +244,16 @@ | @@ -253,16 +244,16 @@ | ||
253 | } | 244 | } |
254 | 245 | ||
255 | NSLog(@"UUID: %@, %@, %@", service.UUID.UUIDString, writeServiceUUID, indicateServiceUUID); | 246 | NSLog(@"UUID: %@, %@, %@", service.UUID.UUIDString, writeServiceUUID, indicateServiceUUID); |
256 | - if ([service.UUID.UUIDString isEqualToString:writeServiceUUID]) { | 247 | + if ([writeServiceUUID containsString:service.UUID.UUIDString]) { |
257 | for (CBCharacteristic *characteristic in service.characteristics) { | 248 | for (CBCharacteristic *characteristic in service.characteristics) { |
258 | NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); | 249 | NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); |
259 | - | 250 | + |
260 | if ([characteristic.UUID.UUIDString isEqualToString:writeCharacteristicUUID]) | 251 | if ([characteristic.UUID.UUIDString isEqualToString:writeCharacteristicUUID]) |
261 | characteristicWrite = characteristic; | 252 | characteristicWrite = characteristic; |
262 | } | 253 | } |
263 | } | 254 | } |
264 | 255 | ||
265 | - if ([service.UUID.UUIDString isEqualToString:indicateServiceUUID]) { | 256 | + if ([indicateServiceUUID containsString:service.UUID.UUIDString]) { |
266 | for (CBCharacteristic *characteristic in service.characteristics) { | 257 | for (CBCharacteristic *characteristic in service.characteristics) { |
267 | NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); | 258 | NSLog(@"DiscoverCharacteristics: %@", characteristic.UUID); |
268 | 259 | ||
@@ -278,35 +269,35 @@ | @@ -278,35 +269,35 @@ | ||
278 | connectedPeripheral = peripheral; | 269 | connectedPeripheral = peripheral; |
279 | [connectTimer invalidate]; | 270 | [connectTimer invalidate]; |
280 | 271 | ||
281 | -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onConnectedPeripheral:)]) { | ||
282 | -// [_connectionDelegate onConnectedPeripheral:peripheral]; | ||
283 | -// } | 272 | + if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onConnectedPeripheral:)]) { |
273 | + [_connectionDelegate onConnectedPeripheral:peripheral]; | ||
274 | + } | ||
284 | } | 275 | } |
285 | } | 276 | } |
286 | 277 | ||
287 | -- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error { | ||
288 | - | ||
289 | -} | 278 | +//- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error { |
279 | +// | ||
280 | +//} | ||
290 | 281 | ||
291 | -- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { | ||
292 | - | ||
293 | - if (error) { | ||
294 | - NSLog(@"%@,%@,Error didWriteValueForCharacteristic:%@",characteristic.UUID,[characteristic value], [error localizedDescription]); | ||
295 | - return; | ||
296 | - } | ||
297 | - | ||
298 | -} | 282 | +//- (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { |
283 | +// | ||
284 | +// if (error) { | ||
285 | +// NSLog(@"%@,%@,Error didWriteValueForCharacteristic:%@",characteristic.UUID,[characteristic value], [error localizedDescription]); | ||
286 | +// return; | ||
287 | +// } | ||
288 | +// | ||
289 | +//} | ||
299 | 290 | ||
300 | -- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { | ||
301 | - if (error) { | ||
302 | - NSLog(@"Error didUpdateValueForCharacteristic:%@", [error localizedDescription]); | ||
303 | - return; | ||
304 | - } | ||
305 | - NSLog(@"didUpdateValueForCharacteristic: %@ %@", characteristic.UUID, characteristic.value); | ||
306 | - | ||
307 | - if (_dataDelegate && [_dataDelegate respondsToSelector:@selector(onDataReceive:)]) { | ||
308 | - [_dataDelegate onDataReceive:[characteristic value]]; | ||
309 | - } | ||
310 | -} | 291 | +//- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error { |
292 | +// if (error) { | ||
293 | +// NSLog(@"Error didUpdateValueForCharacteristic:%@", [error localizedDescription]); | ||
294 | +// return; | ||
295 | +// } | ||
296 | +// NSLog(@"didUpdateValueForCharacteristic: %@ %@", characteristic.UUID, characteristic.value); | ||
297 | +// | ||
298 | +// if (_dataDelegate && [_dataDelegate respondsToSelector:@selector(onDataReceive:)]) { | ||
299 | +// [_dataDelegate onDataReceive:[characteristic value]]; | ||
300 | +// } | ||
301 | +//} | ||
311 | 302 | ||
312 | @end | 303 | @end |
HDFwear/OTA/OTAUpdateViewController.h
0 โ 100644
HDFwear/OTA/OTAUpdateViewController.m
0 โ 100644
1 | +// | ||
2 | +// OTAUpdateViewController.m | ||
3 | +// HDFwear | ||
4 | +// | ||
5 | +// Created by admin on 2024/1/24. | ||
6 | +// | ||
7 | + | ||
8 | +#import "OTAUpdateViewController.h" | ||
9 | + | ||
10 | +@interface OTAUpdateViewController () | ||
11 | + | ||
12 | +@end | ||
13 | + | ||
14 | +@implementation OTAUpdateViewController | ||
15 | + | ||
16 | +- (void)viewDidLoad { | ||
17 | + [super viewDidLoad]; | ||
18 | + // Do any additional setup after loading the view from its nib. | ||
19 | +} | ||
20 | + | ||
21 | +/* | ||
22 | +#pragma mark - Navigation | ||
23 | + | ||
24 | +// In a storyboard-based application, you will often want to do a little preparation before navigation | ||
25 | +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { | ||
26 | + // Get the new view controller using [segue destinationViewController]. | ||
27 | + // Pass the selected object to the new view controller. | ||
28 | +} | ||
29 | +*/ | ||
30 | + | ||
31 | +@end |
HDFwear/OTA/OTAUpdateViewController.xib
0 โ 100644
1 | +<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
2 | +<document type="com.apple.InterfaceBuilder3.CocoaTouch.XIB" version="3.0" toolsVersion="13142" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES"> | ||
3 | + <dependencies> | ||
4 | + <plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="12042"/> | ||
5 | + <capability name="Safe area layout guides" minToolsVersion="9.0"/> | ||
6 | + <capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
7 | + </dependencies> | ||
8 | + <objects> | ||
9 | + <placeholder placeholderIdentifier="IBFilesOwner" id="-1" userLabel="File's Owner" customClass="OTAUpdateViewController"> | ||
10 | + <connections> | ||
11 | + <outlet property="view" destination="i5M-Pr-FkT" id="sfx-zR-JGt"/> | ||
12 | + </connections> | ||
13 | + </placeholder> | ||
14 | + <placeholder placeholderIdentifier="IBFirstResponder" id="-2" customClass="UIResponder"/> | ||
15 | + <view clearsContextBeforeDrawing="NO" contentMode="scaleToFill" id="i5M-Pr-FkT"> | ||
16 | + <rect key="frame" x="0.0" y="0.0" width="375" height="667"/> | ||
17 | + <autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/> | ||
18 | + <color key="backgroundColor" systemColor="systemBackgroundColor" cocoaTouchSystemColor="whiteColor"/> | ||
19 | + <viewLayoutGuide key="safeArea" id="Q5M-cg-NOt"/> | ||
20 | + </view> | ||
21 | + </objects> | ||
22 | +</document> |