Reading BLE Characteristics in iOS

dkwill gravatar image

asked 2017-01-11 17:44:46 +0100

updated 2017-01-11 17:45:56 +0100

Hi - I am trying to send a signed 16bit Integer from nRF52 to iOS. Using the following characteristic reader from Nordic in the nRF Toolbox on Github (here).

        static func readSInt16Value(ptr aPointer : inout UnsafeMutablePointer<UInt8>) -> Int16 {
    let anInt16Pointer = UnsafeMutablePointer<Int16>(OpaquePointer(aPointer))
    let val = CFSwapInt16LittleToHost(UnsafeMutablePointer<UInt16>(OpaquePointer(anInt16Pointer)).pointee)
    aPointer = aPointer.advanced(by: 2)
    return Int16(val)
   }

On the nRF52 side, packaging as follows:

'#define UINT16_TO_BSTREAM(p,n) {*(p)++ = (uint8_t)(n); *(p)++ = (uint8_t)((n)>>8);}

Any guidance on what I might be doing wrong would be greatly appreciated. Thanks!

edit retag flag offensive close delete report spam

Comments

So BLE doesn't really care about data type. Are you trying to read the characteristic or are you sending notifications? To read a characteristic from iOS use the readValueForCharacteristic method. I guess you should look at the Core Bluetooth Programming Guide.

run_ar ( 2017-01-13 14:14:07 +0100 )editconvert to answer

Thanks. I'm sending notifications. I probably could have framed the question better. Since I know the iOS side is correct since Nordic wrote it, I don't see any of the BLE examples that utilize a 16bit signed integer - they are all uint8. Simply changing the type from uint8 to int16 on the nRF side doesn't work. So I'm trying to understand how I would need to change one of the "typical" BLE examples so that it sends it in correct format. How does it need to be "packaged" on the nRF side?

dkwill ( 2017-01-13 14:54:10 +0100 )editconvert to answer