I am reading data off of a hardware device through Core Bluetooth (BLE). One of the charecteristics I am reading is a struct compressed down to a single value. The struct as programmed to the board looks like this:
typedef struct
{
uint8 id;
uint32 dur;
uint16 dis;
} record;
Most of the other characteristics I am parsing are of a single type, uint8
, uint32
, so on.
How can I loop through the bytes and parse each individual characteristic either to native type or an NSString
? Is there a way to iterate over the bytes or substring the NSData
object?
NSData *data = [characteristic value]; // characteristic is of type CBCharacteristic
NSUInteger len = data.length;
Byte *bytes = (Byte *)[data bytes];
for (Byte in bytes) { // no fast enumeration here, but the general intention is to iterate byte by byte
// TODO: parse out uint8
// TODO: parse out uint32
// TODO: parse out uint16
}