This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Reading BLE Characteristics in iOS

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!

Related