Commit e8cd4c098735d29afcacfc77f5e170c1f44e8116

Authored by jason
1 parent 78069d6a

feat:letransceiver lean

HDFwear/OTA/LETransceiver.h
... ... @@ -17,42 +17,15 @@ NS_ASSUME_NONNULL_BEGIN
17 17 #define KeyIndicateCharacteristicUUID @"kIndicateCharacteristicUUID"
18 18  
19 19 @protocol LEConnctionDelegate <NSObject>
20   -//
21   -//@required
22   -//- (void)onFoundPeripheral:(CBPeripheral *) peripheral advertisementData:(NSDictionary *) advertisementData;
23   -//
24   -//@optional
25 20 - (void)onConnectedPeripheral:(CBPeripheral *) peripheral;
26   -//- (void)onDisconnectedPeripheral:(CBPeripheral *) peripheral;
27   -//
28   -@end
29   -
30   -@protocol LEDataDelegate <NSObject>
31   -
32   -@optional
33   -
34   -- (void)onDataReceive:(NSData *) data;
35   -
36 21 @end
37 22  
38 23 @interface LETransceiver : NSObject
39   -
40 24 @property (weak, nonatomic) id<LEConnctionDelegate> connectionDelegate;
41   -@property (weak, nonatomic) id<LEDataDelegate> dataDelegate;
42   -
43   -//- (void)setUUIDs:(NSDictionary *) uuids;
44   -
45   -//- (void)scanStart;
46   -//- (void)scanStop;
47   -
48   -//- (void)connect:(CBPeripheral *)peripheral;
49   -//- (void)disconnect:(CBPeripheral *)peripheral;
50   -
51 25 - (void)write:(NSData *) data;
52 26 - (void)write:(NSData *) data index:(int) i;
53 27  
54 28 // for BluetoothManager to call
55   -@property (weak, nonatomic) CBCentralManager *centralManager;
56 29 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(nullable NSError *)error;
57 30 - (void)closeOTA;
58 31 @end
... ...
HDFwear/OTA/LETransceiver.m
... ... @@ -62,49 +62,6 @@
62 62 }
63 63 }
64 64  
65   -//- (void)scanStart {
66   -// NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerScanOptionAllowDuplicatesKey, nil];
67   -// /*
68   -// NSMutableArray *servicesUUID = [[NSMutableArray alloc] init];
69   -// if (writeServiceUUID)
70   -// [servicesUUID addObject:writeServiceUUID];
71   -// if (indicateServiceUUID)
72   -// [servicesUUID addObject:indicateServiceUUID];
73   -// */
74   -// [self.centralManager scanForPeripheralsWithServices:nil options:options];
75   -//}
76   -
77   -//- (void)scanStop {
78   -// [self.centralManager stopScan];
79   -//}
80   -
81   -//- (void)connect:(CBPeripheral *)peripheral {
82   -// [self scanStop];
83   -//
84   -// [self.centralManager connectPeripheral:peripheral options:@{CBConnectPeripheralOptionNotifyOnConnectionKey:@YES}];
85   -//
86   -// if (connectTimer) {
87   -// [connectTimer invalidate];
88   -// }
89   -// connectTimer = [NSTimer scheduledTimerWithTimeInterval:20.0 target:self selector:@selector(connectTimeout:) userInfo:peripheral repeats:NO];
90   -//}
91   -
92   -//- (void)disconnect:(CBPeripheral *)peripheral {
93   -// if (![self isPeripheralConnected:peripheral]) {
94   -// return;
95   -// }
96   -//
97   -// NSLog(@"disconnect %@", peripheral.name);
98   -// [self.centralManager cancelPeripheralConnection:peripheral];
99   -//}
100   -
101   -//- (BOOL) isPeripheralConnected:(CBPeripheral *) peripheral {
102   -// if (peripheral.state == CBPeripheralStateConnected) {
103   -// return YES;
104   -// }
105   -// return NO;
106   -//}
107   -
108 65 - (NSUInteger) getMtuForType:(CBCharacteristicWriteType) type {
109 66 return [connectedPeripheral maximumWriteValueLengthForType:type];
110 67 }
... ... @@ -143,99 +100,6 @@
143 100 }
144 101 }
145 102  
146   -//- (void)connectTimeout:(NSTimer *)timer {
147   -// CBPeripheral *peripheral = (CBPeripheral *)[timer userInfo];
148   -// [self disconnect:peripheral];
149   -//}
150   -
151   -//#pragma mark -- CBCentralManagerDelegate
152   -//- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
153   -// NSString *messtoshow;
154   -// switch (central.state) {
155   -// case CBManagerStatePoweredOn:{
156   -// messtoshow=[NSString stringWithFormat:@"CBCentralManagerStatePoweredOn"];
157   -// [self scanStart];
158   -// break;
159   -// }
160   -// case CBManagerStateUnknown:
161   -// {
162   -// messtoshow=[NSString stringWithFormat:@"State unknown, update imminent"];
163   -// break;
164   -// }
165   -// case CBManagerStateResetting:
166   -// {
167   -// messtoshow=[NSString stringWithFormat:@"The connection with the system service was momentarily lost, update imminent."];
168   -// break;
169   -// }
170   -// case CBManagerStateUnsupported:
171   -// {
172   -// messtoshow=[NSString stringWithFormat:@"The platform doesn't support Bluetooth Low Energy"];
173   -// break;
174   -// }
175   -// case CBManagerStateUnauthorized:
176   -// {
177   -// messtoshow=[NSString stringWithFormat:@"The app is not authorized to use Bluetooth Low Energy"];
178   -// break;
179   -// }
180   -// case CBManagerStatePoweredOff:
181   -// {
182   -// [self disconnect:connectedPeripheral];
183   -//
184   -// messtoshow=[NSString stringWithFormat:@"Bluetooth is currently powered off"];
185   -// break;
186   -// }
187   -// default:
188   -// break;
189   -// }
190   -// NSLog(@"%@",messtoshow);
191   -//}
192   -
193   -//- (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI{
194   -//// NSLog(@"didDiscoverPeripheral: %@", peripheral);
195   -//
196   -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onFoundPeripheral:advertisementData:)]) {
197   -// [_connectionDelegate onFoundPeripheral:peripheral advertisementData:advertisementData];
198   -// }
199   -//}
200   -
201   -//- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral{
202   -// NSLog(@"didConnectPeripheral: %@", peripheral.name);
203   -//
204   -// peripheral.delegate = self;
205   -// [peripheral discoverServices:nil];
206   -//}
207   -
208   -//- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
209   -// NSLog(@"Fail to connect: %@", peripheral.name);
210   -//}
211   -
212   -//- (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error{
213   -// NSLog(@"didDisconnectPeripheral %@, error: %@",peripheral, error);
214   -//
215   -// connectedPeripheral = nil;
216   -// characteristicWrite = nil;
217   -// characteristicIndicate = nil;
218   -// if(_connectionDelegate && [_connectionDelegate respondsToSelector:@selector(onDisconnectedPeripheral:)]) {
219   -// [_connectionDelegate onDisconnectedPeripheral:peripheral];
220   -// }
221   -//}
222   -
223   -//#pragma mark -- CBPeripheralDelegate
224   -//- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error{
225   -// NSLog(@"didDiscoverServices: %@", peripheral.name);
226   -// if (error) {
227   -// NSLog(@"Error discovering service:%@", [error localizedDescription]);
228   -// return;
229   -// }
230   -//
231   -// for (CBService *service in peripheral.services) {
232   -//
233   -// NSLog(@"service: %@", service);
234   -// [peripheral discoverCharacteristics:nil forService:service];
235   -// }
236   -//
237   -//}
238   -
239 103 - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error{
240 104 NSLog(@"didDiscoverCharacteristicsForService: %@, %@", peripheral.name, service.UUID.UUIDString);
241 105 if (error) {
... ... @@ -275,29 +139,4 @@
275 139 }
276 140 }
277 141  
278   -//- (void)peripheral:(CBPeripheral *)peripheral didReadRSSI:(NSNumber *)RSSI error:(nullable NSError *)error {
279   -//
280   -//}
281   -
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   -//}
290   -
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   -//}
302   -
303 142 @end
... ...