ios通过计数位扫描不同的设备

时间:2015-08-31 02:21:43

标签: ios bluetooth-lowenergy scanning

如果位0x00显示10次或更多,我正在处理用于扫描设备的BLE扫描模块。扫描多个相同设备时,控制台在NSLog中显示备用0x00,0x01。由于我使用一个整数计数器来计算0x00位的存在,因此它经常被覆盖。您能告诉我实现键/值数据结构以保存UUID和存储scanningPeripheral的计数的方法吗?

以下是我的工作

  for(NSUInteger  i = 0 ; i < [ _ble.scannedPeripheral count ] ; i ++){
            DevicePeriperal *device;
            NSString *uuid = [_ble.scannedPeripheralKey objectAtIndex:i];
            if (uuid)
            {
                device = [_ble.scannedPeripheral objectForKey:uuid];
                if([self isEmptyArrayOrNil:[_dbMan getDeviceRecord:device.uuid ] ]){

                    NSLog(@"pair bit %@ ," ,  device.pairBit );
                    const unsigned char ssss[1] = {0x00};
                    NSData* pairBi =  [NSData dataWithBytes:(const void *)ssss length:(sizeof(unsigned char) * 1)];
                    const unsigned char ssLow[1] = {0x01};
                    NSData* pairX =  [NSData dataWithBytes:(const void *)ssLow length:(sizeof(unsigned char) * 1)];

                    if ([device.pairBit  isEqualToData:pairBi ]){

                        pCount++;
                        if(pCount > 9){
                            NSLog(@"pair bit paired " );
                            NSLog (@"device = %@", device.uuid);                                                           
                        }
                    }else if([device.pairBit  isEqualToData:pairX ]){                            
                        NSLog(@"pair bit not matched " );
                        pCount=0;                            
                    }
                }else{
                    // others
                    NSLog(@"pair bit paired before" );
                    NSLog (@"device = %@", device.uuid);
                }
        }

0 个答案:

没有答案