So, I had asked about this method previously, but I have some other questions that I am trying to figure out. I am working on a Core Bluetooth Application in which I programmed a peripheral device to transmit a heart rate value of 90 beats per minute. On iOS, I have discovered my service and my heart rate characteristic and am now working on processing that data, from the console output, the raw NSData characteristic.value data is 5a000000 which translates to a unsigned 32 bit integer value of 90 beats per minute. What I want to do now is to take that NSData data and turn store it as an unsigned 32 bit value and turn it into an NSNumber type and NSString for displaying on the screen. Thanks to some smart folks in the previous thread, I got my questions answered, but a few remain. Firstly, here is the code, specifically focusing on STEP 2:
// STEP 1: Make rawData and initialize 32-bit integer value:
NSData *rawData = characteristic.value;
uint32_t rawInt = 0;
// STEP 2: Copy data from rawData into address of rawInt
[rawData getBytes:&rawInt length:sizeof(rawInt)];
// STEP 3: Turn to NSNumber and then String
self.heartRateValue = [[NSNumber alloc]initWithUnsignedInt:rawInt];
[self.heartRateLabel setText:[self.heartRateValue stringValue]];
Questions:
1 - So as I understand it is that we are send a message to NSData *rawData variable to give the data it has inside so we can copy that data into our rawInt variable's address?
2 - For the length parameter, I chose sizeof rawInt, but should I be doing sizeof rawData instead? Would I lose data as a result? Why would i choose sizeOf rawInt vs. rawData and vice versa?