Reedyuk / blue-falcon

A Bluetooth kotlin multiplatform "Cross-Platform" library for iOS and Android
https://bluefalcon.dev
Apache License 2.0
321 stars 43 forks source link

Byte array values are not properly converted on iOS #79

Closed beniamin-cazacu closed 2 years ago

beniamin-cazacu commented 2 years ago

Describe the bug I want to use the blue-falcon library in a Kotlin Multiplatform app. I face the following situation: I need to convert a value to a byte array, in the order of Little Endian, and send it to a sensor. In Android, I can do this using the following method: ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putFloat(value).array()

The issue with this is that on Android we can send the value as a byte array (which has a range of values between [-128, 127]). But on iOS, the byte equivalent is UInt8 (which has a range of values between [0, 255]).

Expected behavior The value should be converted as in the native apps. To send the value 500 to the sensor, on Android I have the following array: [0, 0, -6, 67]. On iOS, I should have it like this: [0, 0, 250, 67].

Additional context

The problem is that I can only send arrays of bytes and strings in the writeCharacteristic() method. On the Android application, it works accordingly. On iOS, I think that the array is not converted properly and it breaks the functionality.

Have you perhaps faced this situation or do you have any idea how to solve this issue? Maybe if we convert byte array to unsigned byte array but I think for that, we should add new functionality in the library

beniamin-cazacu commented 2 years ago

I may found a solution to this issue. I opened #80 PR and I added the option to send the array without the need to decode and encode again the array.