我正在做iOS应用程序,需要生成32位crc算法。基于核心蓝牙应用程序需要与手表设备通信iPhone设备作为中央设备需要发送命令观看如下。
- (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:
(CBCharacteristic *)characteristic error:(NSError *)error
{
[SharedData sharedConstants].verifyMode = 1;
[ObjBLEConnection verifyMode:[ObjBLEConnection activePeripheral]];
[ObjBLEConnection enableButtons:[ObjBLEConnection activePeripheral]];
NSString *characteristicUUIDstring = TRANSFER_CHARACTERISTIC_UUID;
CBUUID *characteristicUUID = [CBUUID
UUIDWithString:characteristicUUIDstring];
int comm[6];
comm[0]=0x01;
comm[1]=6;
comm[2]=0x70;
comm[3]=0x00;
comm[4]=0xFFFF;
comm[5]=0xFFFF;
NSMutableArray *arr=[[NSMutableArray alloc]initWithCapacity:6];
for (int i = 0; i < 6; i++) {
NSNumber *number = [NSNumber numberWithFloat:comm[i]];
[arr addObject:number];
}
NSLog(@"mutable arr is %@",arr);
NSString *error1;
NSData *dataarr = [NSPropertyListSerialization dataFromPropertyList:arr
format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error1];
CBMutableCharacteristic *testCharacteristic = [[CBMutableCharacteristic alloc] initWithType:characteristicUUID properties:CBCharacteristicPropertyRead|CBCharacteristicPropertyWrite value:dataarr permissions:CBAttributePermissionsReadable|CBAttributePermissionsWriteable];
NSLog(@"Read or Write %@ ",testCharacteristic);
[peripheral writeValue:dataarr forCharacteristic:testCharacteristic type:CBCharacteristicWriteWithResponse];
NSString *error2;
NSData *dataarr2 = [NSPropertyListSerialization dataFromPropertyList:testCharacteristic.value format:NSPropertyListBinaryFormat_v1_0 errorDescription:&error2];
NSLog(@"data is %@",dataarr2);
}
这里命令comm [4]和comm [5]需要通过使用crc算法生成一个值,方法是使用上面用于发送到监视设备的comm命令。响应那个手表提供一些数据。我需要获取该数据并在我的应用中显示。是否有任何与生成crc算法和发送到硬件设备相关的代码片段。请帮忙