Re: Reading voltage value from BTLE device
Re: Reading voltage value from BTLE device
- Subject: Re: Reading voltage value from BTLE device
- From: Etan Kissling <email@hidden>
- Date: Fri, 09 Nov 2012 20:28:12 +0000
- Thread-topic: Reading voltage value from BTLE device
Constantijn,
The problem seems to lie in your casting operation. As you are reading a float value into an integer, you will get a wrong number. This is because floating point values have a different bit representation than integer values.
When you cast an int to a float, you won't reinterpret the same bit representation as a float. Instead you generate a new floating point value with the same value as your int, that was already wrong.
One way to fix it would be to simply read into the float directly instead of doing the workaround with the int.
Another option would be to cast like this:
float result = *((float *)(&val))
in order to ensure that the value is not changed in the casting process.
Etan
On 07.11.2012, at 22:29, "Constantijn Schepens" <email@hidden> wrote:
> Hi there,
>
> I am working with a custom bluetooth profile which is designed to store multiple voltage values in its GATT database. (BLE112 using BGScript to be specific) This all works correctly. My iPhone connects correctly as well as finds characteristics correctly. My issue arises when I try to read the values of my characteristics. I just am not managing to read the value that is in the GATT database. It always comes out with really large (but consistently so) numbers, yet I cannot understand why because I feel I am reading the correctly number of bytes. The GATT database stores these values (coming from an ADC) in 4 bytes. The code I am currently trying to use(based on the TemperatureSensor example) is:
>
> CGFloat result = NAN;
> int32_t val = 0;
>
> {sensorZeroCharacteristic.value getBytes:&val length:sizeof(val)];
> result = (CGFloat)val;
>
> Can anyone see what I might be doing wrong or just have a better(correct) way of doing this?
>
> Thanks in advance!
> Constantijn
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Bluetooth-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Bluetooth-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden