I'm dying here! Spent so many hours trying to understand how to get this bluetooth characteristic data to parse. My device is a cycling power meter which has the first two bits as the flags for the device. This is where my issue is. I can connect just fine to devices with one bit as the flag but two is killing me.
Characteristic: <CBCharacteristic: 0x282298f00, UUID = 2A63, properties = 0x10, value = {length = 12, bytes = 0x2c080000235134005e4348f0}, notifying = YES>
I believe based on the data I think the flags should be "844" Which is swapping the first and second bit and concatenating them.
Then I'm not sure if I am getting the bit from the flags correctly either, I'm a mess.
Thank you greatly in advance.
Characteristic: <CBCharacteristic: 0x282298f00, UUID = 2A63, properties = 0x10, value = {length = 12, bytes = 0x2c080000235134005e4348f0}, notifying = YES>
Code Block NSData *data = [characteristic value]; const uint8_t *byteData = [data bytes]; uint16_t flags = byteData[0]; NSLog(@"measurement flag byte %lu", (unsigned long)flags); NSLog(@"flag bit 0: %d", (bool)(flags & 0x00)); NSLog(@"flag bit 1: %d", (bool)(flags & 0x01)); NSLog(@"flag bit 2: %u", (bool)(flags & 0x02)); NSLog(@"flag bit 3: %d", (bool)(flags & 0x03)); NSLog(@"flag bit 4: %d", (bool)(flags & 0x04)); NSLog(@"flag bit 5: %d", (bool)(flags & 0x05)); NSLog(@"flag bit 6: %d", (bool)(flags & 0x06)); NSLog(@"flag bit 7: %d", (bool)(flags & 0x07)); NSLog(@"flag bit 8: %d", (bool)(flags & 0x08)); NSLog(@"flag bit 9: %d", (bool)(flags & 0x09)); NSLog(@"flag bit 10: %d", (bool)(flags & 0x10)); NSLog(@"flag bit 11: %d", (bool)(flags & 0x11)); NSLog(@"flag bit 12: %d", (bool)(flags & 0x12)); offset = offset + 2; uint16_t powerMeasurment = CFSwapInt16LittleToHost(*(uint16_t *)(&[[characteristic value] bytes][offset])); NSLog(@"Power: %u", powerMeasurment); offset = offset + 2;
I believe based on the data I think the flags should be "844" Which is swapping the first and second bit and concatenating them.
Then I'm not sure if I am getting the bit from the flags correctly either, I'm a mess.
Thank you greatly in advance.