如果位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);
}
}