Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Functioning of Characteristic Presentation Format Descriptor (CPFD)

Hi,

I would like to know the functioning of CPFD (I would like to represent the characteristic value as IEEE754 float32) I am not aware of how can I implement this. for example, if I am measuring the acceleration (float value), but I would like to send the data as int32 type (which following method should I chose in case of CPFD?)

1. Convert the float measuured value to corresponding hexadecimal value according to IEEE754 Floating point representation and mention in the descriptor that I uses IEEE754 so that, master can convert back it in to the float point

2. or I can use float datatype for the characteristic value by mentioning CPFD as #define BLE_GATT_CPF_FORMAT_FLOAT32 (according to  Characteristic Presentation Formats (nordicsemi.com) )?

all together I just want to know what is CPFD, how to implement this and how this helps me with my project of reading acceleration value (with fractional value).

 

Thanks in advance for your time and effort.

with Regards,

Sreejith

  • Hi Torbjørn,

    Thank you for your response. 

    Yes, this should work fine. 

    The only thing to be aware of is that when you are combining fields of different sizes in the struct you should declare it packed, otherwise each field might be aligned to that of the largest field (meaning your 8 bit alert field would occupy 32 bits in the struct rather than 8). 

    Thanks for the explanation, if the master/client knows about size of each parameter and the order of the packing, I hope the client can easily understand the measurement. am I correct?

    You mean you want to verify that the raw value of the characteristic decodes to the correct floating point value according to the IEEE754 specification?

    If so you should be able to use something like this online IEEE754 converter to check if the value is correct

    No, I meant, after I added the Presentation format Descriptor and when I tested using nRF Connect for Desktop it shows the CPFD as follows in the picture. What these number indicates? How a client distinguish that it is IEEE754?

    No, the notify property only allows the client to set a single bit, in order to enable or disable notifications. You can't send any additional information through the CCCD. 

    In the end it is the server device (the peripheral normally) that decides when to send notifications. Either you can use a separate characteristic to allow the client to configure when the server should send notifications, or the server would have to expose two different characteristics of the same type, where the client can subscribe to one to get updates all the time, or subscribe to the other one to only get updates when the alert flag field is set.

    Ok, it is clear

    Thanks once again for your time and response.

    With Regards,

    Sreejith

  • Hi Sreejith

    Sreejith Sundh said:
    Thanks for the explanation, if the master/client knows about size of each parameter and the order of the packing, I hope the client can easily understand the measurement. am I correct?

    That shouldn't be a problem, as long as you are in charge of both sides in terms of the implementation, and you can ensure that they format the data the same way. 

    The main thing to be aware off is that if the client is a phone you will most likely be using a different programming language (Java or Swift for instance), and targetting a different CPU architecture, so low level data operations might not work exactly the same. 

    Sreejith Sundh said:
    No, I meant, after I added the Presentation format Descriptor and when I tested using nRF Connect for Desktop it shows the CPFD as follows in the picture. What these number indicates? How a client distinguish that it is IEEE754?

    The first byte is the Format, and 0x14 corresponds to 32-bit IEEE754 float as defined here.

    For a full description of the CPF format you should refer to Volume 3, Part G, Chapter 3.3.3.5 and 3.3.3.6 of the Bluetooth Core specification v5.3.

    Best regards
    Torbjørn 

Related