• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Reading voltage value from BTLE device
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >Reading voltage value from BTLE device (From: Constantijn Schepens <email@hidden>)

  • Prev by Date: Re: Resetting CentralManager to re-detect previously detected devices
  • Next by Date: Bluetooth 2.0+EDR MFi Question
  • Previous by thread: Re: Reading voltage value from BTLE device
  • Next by thread: Bluetooth 2.0+EDR MFi Question
  • Index(es):
    • Date
    • Thread