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!

Parents
  • 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?

Reply
  • 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?

Children
No Data
Related