BLEServiceHandler.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. //
  2. // BLEServiceHandler.m
  3. // OneCable
  4. //
  5. // Created by KaRam Kim on 2017. 5. 18..
  6. // Copyright © 2017년 ntels. All rights reserved.
  7. //
  8. #import "BLEServiceHandler.h"
  9. #import <CoreBluetooth/Corebluetooth.h>
  10. #import "Definitions.h"
  11. #import "JDJSONModel.h"
  12. #import "JDObject.h"
  13. @interface BLEServiceHandler()<CBCentralManagerDelegate, CBPeripheralDelegate>
  14. {
  15. CBCentralManager *_manager;
  16. NSMutableArray *_devices;
  17. BOOL _scanning;
  18. NSTimer *_scanTimer;
  19. BTLEDeivceModel *_connectedDevice;
  20. //service characteristic
  21. CBService *lastService;
  22. }
  23. @end
  24. @implementation BLEServiceHandler
  25. + (id)sharedManager
  26. {
  27. static BLEServiceHandler *sharedBLEServiceHandler = nil;
  28. static dispatch_once_t onceToken;
  29. dispatch_once(&onceToken, ^{
  30. sharedBLEServiceHandler = [[self alloc] init];
  31. });
  32. return sharedBLEServiceHandler;
  33. }
  34. - (id) init
  35. {
  36. self = [super init];
  37. if (self) {
  38. _manager = [[CBCentralManager alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
  39. // *peripheralManager = [[CBPeripheralManager alloc]initWithDelegate:nil queue:nil options:@{CBPeripheralManagerOptionShowPowerAlertKey:@NO}]
  40. _devices = [NSMutableArray array];
  41. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startScan) name:kBLEConnect object:nil];
  42. // [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startScan) name:kBLEDisConnect object:nil];
  43. }
  44. return self;
  45. }
  46. - (void)connect:(BTLEDeivceModel *)info
  47. {
  48. [_manager connectPeripheral:info.peripheralRef options:nil];
  49. // if (info.peripheralRef.state != CBPeripheralStateDisconnected) {
  50. // [_manager cancelPeripheralConnection:info.peripheralRef];
  51. // } else {
  52. // [_manager connectPeripheral:info.peripheralRef options:nil];
  53. // }
  54. }
  55. - (void)disConnect
  56. {
  57. _conDevice = nil;
  58. }
  59. -(void) openBluetoothSettings{
  60. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Bluetooth"]];
  61. }
  62. - (BOOL) checkBLEStatus {
  63. if (_manager.state == CBManagerStatePoweredOff) {
  64. NSLog(@"_manager.state != CBCentralManagerStatePoweredOn") ;
  65. [[JDFacade facade] confirmTitle:@"Notice"
  66. message:@"블루투스가 비활성화 되어 있습니다. 활성화 해주세요."
  67. btnOKLabel:@"OK"
  68. btnCancelLabel:@"Cancel"
  69. completion:^(CustomAlertView *alertView, NSInteger buttonIndex) {
  70. if (buttonIndex == 1) {
  71. [self openBluetoothSettings];
  72. }
  73. }];
  74. return NO;
  75. }
  76. return YES;
  77. }
  78. - (void) startScan
  79. {
  80. if (![self checkBLEStatus])
  81. return;
  82. _devices = [NSMutableArray array];
  83. if (_scanTimer) [_scanTimer invalidate];
  84. _scanning = YES;
  85. [_manager stopScan];
  86. [_manager scanForPeripheralsWithServices:nil options:nil];
  87. _scanTimer = [NSTimer scheduledTimerWithTimeInterval:10 target:self selector:@selector(stopScan:) userInfo:@"Y" repeats:NO];
  88. }
  89. - (void)stopScan:(NSString*)timeout
  90. {
  91. NSLog(@"STOP SCAN");
  92. [_manager stopScan] ;
  93. _scanning = NO ;
  94. if( _delegate && [_delegate respondsToSelector:@selector(BLEEndScan:)] ) {
  95. [_delegate BLEEndScan:_devices] ;
  96. }
  97. }
  98. -(NSMutableArray *)getDeviceList
  99. {
  100. return _devices;
  101. }
  102. -(CBCharacteristic *)getChrInfo:(NSString *)name
  103. {
  104. CBCharacteristic *result = nil;
  105. for (CBService *serviceInfo in [_conDevice getServiceList]) {
  106. for (CBCharacteristic *chrInfo in serviceInfo.characteristics) {
  107. if ([[self getStrUUID:chrInfo] isEquestToIgnoreCase:[self getServiceUUID:name]]) {
  108. //NSLog(@"\nname : %@, chrInfo : %@", name, chrInfo.UUID);
  109. result = chrInfo;
  110. break;
  111. }
  112. }
  113. }
  114. return result;
  115. }
  116. -(NSString *)getChrName:(CBCharacteristic *)info
  117. {
  118. NSString *result = nil;
  119. for (NSString *key in [[self getGatewayCharDict] allKeysForObject:[[self getStrUUID:info] lowercaseString]]) {
  120. result = key;
  121. }
  122. return result;
  123. }
  124. -(NSString *)getStrUUID:(CBCharacteristic *)info
  125. {
  126. NSString *uuid =[NSString stringWithFormat:@"%@", info.UUID];
  127. return uuid;
  128. }
  129. - (BTLEDeivceModel *)addPeripheral:(CBPeripheral*)peripheral {
  130. BTLEDeivceModel *device = [[BTLEDeivceModel alloc] init];
  131. device.peripheralRef = peripheral;
  132. device.manager = _manager;
  133. peripheral.delegate = self;
  134. if (![_devices containsObject:device]) {
  135. [_devices addObject:device];
  136. }
  137. // if( _delegate && [_delegate respondsToSelector:@selector(BLEUpldateDevice:)] ) {
  138. // [_delegate BLEUpldateDevice:device] ;
  139. // }
  140. return device;
  141. }
  142. - (NSString*)hexStringValue:(CBCharacteristic *)input {
  143. if (!input.value) return @"-";
  144. NSString *raw = [NSString stringWithFormat:@"0x%@", input.value];
  145. raw = [raw stringByReplacingOccurrencesOfString:@"<" withString:@""];
  146. raw = [raw stringByReplacingOccurrencesOfString:@">" withString:@""];
  147. return raw;
  148. }
  149. - (NSString*)asciiStringValue:(CBCharacteristic *)input {
  150. if (!input.value) return @"-";
  151. NSString *ascii = [[NSString alloc] initWithData:input.value encoding:NSASCIIStringEncoding];
  152. return ascii;
  153. }
  154. -(void)sendData:(CBCharacteristic *)chr str:(NSString *)str
  155. {
  156. NSData *data = [NSData data];
  157. if ([str isDigit]) {
  158. int dataToWrite = [str intValue];
  159. data = [NSData dataWithBytes:&dataToWrite length:1];
  160. } else {
  161. data = [str dataUsingEncoding:NSASCIIStringEncoding];
  162. }
  163. if (chr.properties & CBCharacteristicPropertyWriteWithoutResponse)
  164. [chr.service.peripheral writeValue:data forCharacteristic:chr type:CBCharacteristicWriteWithoutResponse];
  165. else if (chr.properties & CBCharacteristicPropertyWrite)
  166. [chr.service.peripheral writeValue:data forCharacteristic:chr type:CBCharacteristicWriteWithResponse];
  167. }
  168. #pragma mark - WiFi Settings
  169. //WiFi Setting관련 메뉴
  170. -(void)scanWiFiList
  171. {
  172. [self sendData:[self getChrInfo:kBLEChrStWiFiScan] str:@"1"];
  173. }
  174. -(NSString *)getWLanList:(BLEWlanListType)type
  175. {
  176. // TODO : WLanList 가져오기
  177. NSString *result = @"";
  178. switch (type) {
  179. case BLEWlanListType1:
  180. [self readAndNotifyCharacteristicUUID:kBLEChrRdWiFiList1 isNotify:NO];
  181. //result = [self asciiStringValue:[self getChrInfo:kBLEChrRdWiFiList1]];
  182. break;
  183. case BLEWlanListType2:
  184. [self readAndNotifyCharacteristicUUID:kBLEChrRdWiFiList2 isNotify:NO];
  185. //result = [self asciiStringValue:[self getChrInfo:kBLEChrRdWiFiList2]];
  186. break;
  187. case BLEWlanListType3:
  188. [self readAndNotifyCharacteristicUUID:kBLEChrRdWiFiList3 isNotify:NO];
  189. //result = [self asciiStringValue:[self getChrInfo:kBLEChrRdWiFiList3]];
  190. break;
  191. default:
  192. break;
  193. }
  194. return result;
  195. }
  196. -(void)setWiFiSSID:(NSString *)ssid
  197. {
  198. [self sendData:[self getChrInfo:kBLEChrStSSIDArg] str:ssid];
  199. }
  200. -(void)setWiFiPwd:(NSString *)pwd
  201. {
  202. [self sendData:[self getChrInfo:kBLEChrStPWDArg] str:pwd];
  203. }
  204. -(void)enableDHCP
  205. {
  206. [self sendData:[self getChrInfo:kBLEChrStDHCPArg] str:@"1"];
  207. }
  208. -(void)applyWiFiSettingInfo
  209. {
  210. [self sendData:[self getChrInfo:kBLEChrStSetApply] str:@"1"];
  211. // todo : Connection정보가 notify로 들어오면, delegate를 통해서 알리기
  212. }
  213. -(void)readAndNotifyCharacteristicUUID:(NSString *)uuid
  214. isNotify:(BOOL)isNotify
  215. {
  216. for (CBService *service in _conDevice.peripheralRef.services) {
  217. for (CBCharacteristic *characteristic in service.characteristics) {
  218. if ([characteristic.UUID.UUIDString isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:uuid]]) {
  219. if (isNotify)
  220. [_conDevice.peripheralRef setNotifyValue:YES forCharacteristic:characteristic];
  221. else
  222. [_conDevice.peripheralRef readValueForCharacteristic:characteristic];
  223. break;
  224. }
  225. }
  226. }
  227. }
  228. - (void)readConnectionWiFiInfo {
  229. [self readAndNotifyCharacteristicUUID:kBLEChrRdSSID isNotify:NO];
  230. [self readAndNotifyCharacteristicUUID:kBLEChrRdBSSID isNotify:NO];
  231. [self readAndNotifyCharacteristicUUID:kBLEChrRnIpSet isNotify:NO];
  232. [self readAndNotifyCharacteristicUUID:kBLEChrRnIpAddr isNotify:NO];
  233. }
  234. - (NSString*)getStringValueForCharacteristicWithKey:(NSString*)key {
  235. return [self asciiStringValue:[self getChrInfo:key]];
  236. }
  237. -(NSString *)getServiceName:(NSString *)uuid
  238. {
  239. NSString *result = nil;
  240. for (NSString *key in [[self getGatewayCharDict] allKeysForObject:uuid.lowercaseString]) {
  241. result = key;
  242. }
  243. return result;
  244. }
  245. -(NSString *)getServiceUUID:(NSString *)strKey
  246. {
  247. NSString *result = nil;
  248. for (NSString *key in [[self getGatewayCharDict] allKeys]) {
  249. if ([key isEquestToIgnoreCase:strKey]) {
  250. result = [[self getGatewayCharDict] objectForKey:key];
  251. break;
  252. }
  253. }
  254. return result;
  255. }
  256. - (NSString*)getGatewayDicUUIDForKey:(NSString*)key{
  257. return [[self getGatewayCharDict] objectForKey:key];
  258. }
  259. -(NSDictionary *)getGatewayCharDict
  260. {
  261. NSDictionary *db = @{@"WFNPS_UUID":@"6f819d94-dddf-11e6-bf26-cec0c932ce01",
  262. @"SCAN_CHR_UUID":@"b364676d-dd76-11e6-bf26-cec0c932ce01",
  263. @"WLAN_LIST1_CHR_UUID":@"f333f87c-0787-11e7-93ae-92361f002671",
  264. @"WLAN_LIST2_CHR_UUID":@"f333fad4-0787-11e7-93ae-92361f002671",
  265. @"WLAN_LIST3_CHR_UUID":@"f333fbec-0787-11e7-93ae-92361f002671",
  266. @"SSID_ARG_CHR_UUID":@"508e6c28-0788-11e7-93ae-92361f002671",
  267. @"PASSWORD_ARG_CHR_UUID":@"b3646c08-dd76-11e6-bf26-cec0c932ce01",
  268. @"CONNECTION_CHR_UUID":@"b3646fbe-dd76-11e6-bf26-cec0c932ce01",
  269. @"SSID_CHR_UUID":@"b3647108-dd76-11e6-bf26-cec0c932ce01",
  270. @"BSSID_CHR_UUID":@"b3647234-dd76-11e6-bf26-cec0c932ce01",
  271. @"WF_IP_SET_ARG_CHR_UUID":@"8e0b49e6-088b-11e7-93ae-92361f002671",
  272. @"WF_IP_ADDR_ARG_CHR_UUID":@"8e0b4c2a-088b-11e7-93ae-92361f002671",
  273. @"WF_NET_PRE_LEN_ARG_CHR_UUID":@"8e0b4e32-088b-11e7-93ae-92361f002671",
  274. @"WF_GATEWAY_ARG_CHR_UUID":@"8e0b4ffe-088b-11e7-93ae-92361f002671",
  275. @"WF_DNS_ARG_CHR_UUID":@"8e0b50d0-088b-11e7-93ae-92361f002671",
  276. @"APPLY_CHR_UUID":@"8e0b51a2-088b-11e7-93ae-92361f002671",
  277. @"WF_IP_SET_CHR_UUID":@"8e0b5314-088b-11e7-93ae-92361f002671",
  278. @"WF_IP_ADDR_CHR_UUID":@"8e0b54a4-088b-11e7-93ae-92361f002671",
  279. @"WF_NET_PRE_LEN_CHR_UUID":@"8e0b5576-088b-11e7-93ae-92361f002671",
  280. @"WF_GATEWAY_CHR_UUID":@"8e0b568e-088b-11e7-93ae-92361f002671",
  281. @"WF_DNS_CHR_UUID":@"8e0b5878-088b-11e7-93ae-92361f002671",
  282. @"IPNPS_UUID":@"09d38ae8-dbb9-11e6-bf26-cec0c932ce01",
  283. @"IP_SET_ARG_CHR_UUID":@"09d38d68-dbb9-11e6-bf26-cec0c932ce01",
  284. @"IP_ADDR_ARG_CHR_UUID":@"09d38e62-dbb9-11e6-bf26-cec0c932ce01",
  285. @"NET_PRE_LEN_ARG_CHR_UUID":@"09d38f48-dbb9-11e6-bf26-cec0c932ce01",
  286. @"GATEWAY_ARG_CHR_UUID":@"09d39024-dbb9-11e6-bf26-cec0c932ce01",
  287. @"DNS_ARG_CHR_UUID":@"09d3960a-dbb9-11e6-bf26-cec0c932ce01",
  288. @"APPLY_IP_CHR_UUID":@"73207ac8-dd72-11e6-bf26-cec0c932ce01",
  289. @"IP_SET_CHR_UUID":@"73208018-dd72-11e6-bf26-cec0c932ce01",
  290. @"IP_ADDR_CHR_UUID":@"73208126-dd72-11e6-bf26-cec0c932ce01",
  291. @"NET_PRE_LEN_CHR_UUID":@"73208202-dd72-11e6-bf26-cec0c932ce01",
  292. @"GATEWAY_CHR_UUID":@"732082de-dd72-11e6-bf26-cec0c932ce01",
  293. @"DNS_CHR_UUID":@"732083a6-dd72-11e6-bf26-cec0c932ce01"};
  294. return db;
  295. }
  296. #pragma mark - CBCentralManagerDelegate
  297. - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
  298. NSLog(@"Central manager changed state: %ld", central.state);
  299. if( _delegate && [_delegate respondsToSelector:@selector(BLEStateChange:)] ) {
  300. [_delegate BLEStateChange:central.state == CBCentralManagerStatePoweredOn] ;
  301. }
  302. if (central.state == CBCentralManagerStatePoweredOn) {
  303. [self startScan];
  304. }
  305. }
  306. - (void)centralManager:(CBCentralManager *)central didRetrievePeripherals:(NSArray *)peripherals {
  307. NSLog(@"%ld periphirals retrieved", [peripherals count]);
  308. }
  309. - (void)centralManager:(CBCentralManager *)central didRetrieveConnectedPeripherals:(NSArray *)peripherals {
  310. for (CBPeripheral *peripheral in peripherals)
  311. {
  312. NSLog(@"1Periphiral discovered: %@, %@", peripheral.name, peripheral.identifier);
  313. BOOL isExist = NO;
  314. for (BTLEDeivceModel *device in _devices)
  315. {
  316. if ([[device.peripheralRef.identifier UUIDString] isEqualToString:[peripheral.identifier UUIDString]])
  317. {
  318. isExist = YES;
  319. }
  320. }
  321. if (!isExist)
  322. [self addPeripheral:peripheral];
  323. }
  324. }
  325. - (void)centralManager:(CBCentralManager *)central didDiscoverPeripheral:(CBPeripheral *)peripheral advertisementData:(NSDictionary *)advertisementData RSSI:(NSNumber *)RSSI {
  326. //NSLog(@"2Periphiral discovered: %@, %@, signal strength: %d", peripheral.name, peripheral.identifier, RSSI.intValue);
  327. for (BTLEDeivceModel *device in _devices) {
  328. if ([[device.peripheralRef.identifier UUIDString] isEqualToString:[peripheral.identifier UUIDString]]) {
  329. return;
  330. }
  331. }
  332. if (peripheral.name != nil && peripheral.name != (id)[NSNull null]) {
  333. if ([peripheral.name rangeOfString:@"DKC"].location != NSNotFound || [peripheral.name rangeOfString:@"BlueZ"].location != NSNotFound) {
  334. BTLEDeivceModel *device = [self addPeripheral:peripheral];
  335. if (![_devices containsObject:device]) {
  336. [_devices addObject:device];
  337. }
  338. }
  339. }
  340. }
  341. - (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
  342. NSLog(@"Periphiral connected name : %@", peripheral.name);
  343. _isConnected = YES;
  344. [peripheral discoverServices:nil] ;
  345. }
  346. - (void)centralManager:(CBCentralManager *)central didDisconnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
  347. NSLog(@"Periphiral disconnected: %@", peripheral.name);
  348. if( _delegate && [_delegate respondsToSelector:@selector(BLEDisConnected:)] ) {
  349. [_delegate BLEDisConnected:_conDevice] ;
  350. }
  351. _isConnected = NO;
  352. _conDevice = nil;
  353. }
  354. - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
  355. NSLog(@"Periphiral failed to connect: %@", peripheral.name);
  356. }
  357. #pragma mark - CBPeripheralDelegate
  358. - (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
  359. NSLog(@"\nServices dicovered for peripheral %@:", peripheral.name);
  360. lastService = [peripheral.services lastObject];
  361. for (CBService *service in peripheral.services) {
  362. [peripheral discoverCharacteristics:nil forService:service];
  363. }
  364. }
  365. - (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error {
  366. NSLog(@"\ncharacteristics dicovered for service : %@", service.UUID);
  367. if ([lastService.UUID isEqual:service.UUID]) {
  368. _conDevice = [self addPeripheral:peripheral];
  369. lastService = nil;
  370. if( _delegate && [_delegate respondsToSelector:@selector(BLEConnected:)] ) {
  371. [_delegate BLEConnected:_conDevice] ;
  372. }
  373. }
  374. for (CBCharacteristic *characteristic in service.characteristics) {
  375. //NSLog(@"characteristic : %@", characteristic.UUID);
  376. // [self readValueSetNotifyValueForCharacteristic:characteristic peripheral:peripheral];
  377. // [peripheral setNotifyValue:YES forCharacteristic:characteristic];
  378. // [peripheral readValueForCharacteristic:characteristic];
  379. }
  380. }
  381. - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
  382. NSLog(@"Incoming: [%@], %@, %@, %@",
  383. [self getChrName:characteristic],
  384. characteristic.value,
  385. [self asciiStringValue:characteristic],
  386. [self hexStringValue:characteristic]);
  387. [self updateValueForDelegateWithCharacteristic:characteristic];
  388. }
  389. -(void)peripheral:(CBPeripheral *)peripheral didModifyServices:(NSArray<CBService *> *)invalidatedServices
  390. {
  391. // device = peripheral;
  392. NSLog(@"peripheral : %@", peripheral);
  393. NSLog(@"didModifyServices : %@", invalidatedServices);
  394. }
  395. - (void)peripheral:(CBPeripheral *)peripheral didWriteValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {
  396. //_conDevice.peripheralRef = peripheral;
  397. NSLog(@"didWriteValueForCharacteristic %@", [self getChrName:characteristic]) ;
  398. }
  399. //update characteristic 데이터 처리
  400. - (void)updateValueForDelegateWithCharacteristic:(CBCharacteristic*)characteristic {
  401. //wlan list
  402. if ([self isReadWlanForCharacteristic:characteristic]) {
  403. if( _delegate && [_delegate respondsToSelector:@selector(BLEWLanUpdateWithKey:result:)] ) {
  404. [_delegate BLEWLanUpdateWithKey:[self getChrName:characteristic]
  405. result:[self asciiStringValue:characteristic]];
  406. }
  407. }
  408. //ssid argument 읽음
  409. else if ([[self getStrUUID:characteristic] isEquestToIgnoreCase:
  410. [self getServiceUUID:kBLEChrStSSIDArg]]) {
  411. if( _delegate && [_delegate respondsToSelector:@selector(BLEWiFiSSIDUpdate:)] ) {
  412. [_delegate BLEWiFiSSIDUpdate:[self asciiStringValue:characteristic]];
  413. }
  414. }
  415. //dhcp 읽음
  416. else if ([[self getStrUUID:characteristic] isEquestToIgnoreCase:
  417. [self getServiceUUID:kBLEChrStDHCPArg]]) {
  418. if( _delegate && [_delegate respondsToSelector:@selector(BLEWiFiDHCPUpdate:)] ) {
  419. [_delegate BLEWiFiDHCPUpdate:nil];
  420. }
  421. }
  422. //wifi connection
  423. else if ([[self getStrUUID:characteristic] isEquestToIgnoreCase:
  424. [self getServiceUUID:kBLEChrRdConInfo]]) {
  425. if( _delegate && [_delegate respondsToSelector:@selector(BLEWiFiConnectionUpdate:)] ) {
  426. [_delegate BLEWiFiConnectionUpdate:characteristic];
  427. }
  428. }
  429. //ssid
  430. else if ([self isReadConInfoForCharacteristic:characteristic]) {
  431. if( _delegate && [_delegate respondsToSelector:@selector(BLEWiFiConnectionInfoUpdateWithKey:result:)] ) {
  432. [_delegate BLEWiFiConnectionInfoUpdateWithKey:[self getChrName:characteristic]
  433. result:[self asciiStringValue:characteristic]];
  434. }
  435. }
  436. }
  437. //wlan list read 인지 판단
  438. - (BOOL)isReadWlanForCharacteristic:(CBCharacteristic*)characteristic {
  439. NSString *uuid = characteristic.UUID.UUIDString;
  440. BOOL rdWiFi = [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRdWiFiList1]] ||
  441. [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRdWiFiList2]] ||
  442. [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRdWiFiList3]];
  443. return rdWiFi;
  444. }
  445. //wlan list read 인지 판단
  446. - (BOOL)isReadConInfoForCharacteristic:(CBCharacteristic*)characteristic {
  447. NSString *uuid = characteristic.UUID.UUIDString;
  448. // static NSString *kBLEChrRdSSID = @"SSID_CHR_UUID";
  449. // static NSString *kBLEChrRdBSSID = @"BSSID_CHR_UUID";
  450. // static NSString *kBLEChrRnIpSet = @"WF_IP_SET_CHR_UUID";
  451. // static NSString *kBLEChrRnIpAddr = @"WF_IP_ADDR_CHR_UUID";
  452. BOOL conInfo = [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRdSSID]] ||
  453. [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRdBSSID]] ||
  454. [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRnIpSet]] ||
  455. [uuid isEquestToIgnoreCase:[self getGatewayDicUUIDForKey:kBLEChrRnIpAddr]] ;
  456. return conInfo;
  457. }
  458. @end