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

Parents
  • Hi,

    Also want to update you that if I did not defined CPFD, master by default measure the value as int32 (Client not only reads my device also reads another sensor data with different datatype). So I have to define the CPFD. is there any template/project/sample syntax on how to define the CPFD on characteristic.

    Thanks and Regards,

    Sreejith 

  • Hi Sreejith

    Since you are using a proprietary service I assume you are also developing the client code? 

    If the client is provided by a third party, do they have some specification describing how you should set up the service, and how the data should be formatted?

    Do you know that the client is set up to read the CPFD descriptor, and which CPF values it will support?

    Are you planning to combine the value, timestamp and alert fields into a single characteristic?

    Sreejith Sundh said:
    Is there any example project/ code available? 

    Can you first tell me if you are planning to use the nRF5 SDK, or the nRF Connect SDK?
    Then I will see if I can find a relevant example. 

    Sreejith Sundh said:
    is it possible for me to go with int32 datatype for acceleration by converting the float measured data to int32 (using IEEE 754 float point standard) and by mentioning the CPFD by myself. If so how should I define the CPFD (what is the syntax in defining CPFD)

    When doing something proprietary anything is possible ;)

    You could include a separate field in the characteristic data for switching between different data formats even. You just need to make sure that the peripheral (server) and central (client) is on the same page, and interpret the characteristics in the same way. 

    Best regards
    Torbjørn

Reply
  • Hi Sreejith

    Since you are using a proprietary service I assume you are also developing the client code? 

    If the client is provided by a third party, do they have some specification describing how you should set up the service, and how the data should be formatted?

    Do you know that the client is set up to read the CPFD descriptor, and which CPF values it will support?

    Are you planning to combine the value, timestamp and alert fields into a single characteristic?

    Sreejith Sundh said:
    Is there any example project/ code available? 

    Can you first tell me if you are planning to use the nRF5 SDK, or the nRF Connect SDK?
    Then I will see if I can find a relevant example. 

    Sreejith Sundh said:
    is it possible for me to go with int32 datatype for acceleration by converting the float measured data to int32 (using IEEE 754 float point standard) and by mentioning the CPFD by myself. If so how should I define the CPFD (what is the syntax in defining CPFD)

    When doing something proprietary anything is possible ;)

    You could include a separate field in the characteristic data for switching between different data formats even. You just need to make sure that the peripheral (server) and central (client) is on the same page, and interpret the characteristics in the same way. 

    Best regards
    Torbjørn

Children
  • HI,

    I am using nRF5 SDK, I am interested to learn how to define, update Presentation Format Descriptor with an example project / example syntax.

    regarding seconds explanation. I can explain my target. I would like to develop a slave acceleration service device which communicates with a master which also communicates with many other peripherals. so, Accelaration characteristic, I have to use floating point datatype, but the master programmed in such a way that if I did not describe the Presentation Format descriptor the master device by default consider it as int32 (but in my case I am defining the value of the characteristic as float). For this purpose I am requesting for the CPFD implementation.

    Thanks Torbjørn.

    Best Regards,

    Sreejith

  • Hi Sreejith

    If you look at any of the existing service implementations (such as ble_nus.c) you will find an init function that sets up the different characteristics. 

    For each characteristic there will be an init structure of type ble_add_char_params_t, typically called something like add_char_params in the code. 

    This struct has a field of type p_presentation_format, and if you point this to a struct of type ble_gatts_char_pf_t you can set up the presentation format descriptor as needed for this particular characteristic. 

    The code should look something like this:

    ble_gatts_char_pf_t cpfd = {.exponent = 1,
                                .format = BLE_GATT_CPF_FORMAT_FLOAT32,
                                .unit = 0x2715,
                                .name_space = BLE_GATT_CPF_NAMESPACE_BTSIG,
                                .desc = BLE_GATT_CPF_NAMESPACE_BTSIG};
    add_char_params.p_presentation_format = &cpfd;

    In order to figure out what to put in the unit field you can get an overview of the various BT Sig defined units here

    Best regards
    Torbjørn

  • Hi Torbjørn,

    Many thanks for the updates. It really helping me....

    As part of this ticket I would like to ask one more question, is it possible for sending float value (with fractional value) over ble? Ultimately my requirement to send the original data of acceleration measured from the sensor. is it possible?

    Thanks and Regards,

    Sreejith

  • Hi Sreejith

    When creating your own proprietary service there is no limit to the types of data that you can send. In the end you are just sending a byte array, and whatever data you want to put into that array is up to you. 

    The important aspect is that you are interpreting the data in the same way on both sides of the link. Normally you would need some code to handle the conversion from a byte array to whatever data fields you want. 

    The easiest way to do this is to create a union between a byte array, and a custom struct containing the actual data fields that you want to use. 

    Best regards
    Torbjørn

  • Hi Torbjørn,

    Yes I am planning to combine the value, timestamp and alert. would it be fine? If I am using 32 bit for value, 32 bit for timestamp and 8 bit for alerts, then client can seperate it accordingly on the client side.( I hope the CGMS example in nRF5 SDK works exactly same like this?)

    Thank you for your response on this ticket, I have included the CPFD, once I included CPFD with FLOAT32 (IEEE754) it shows a value in the characteristics (is that indicates the representation for the IEEE754, can we verify that  "it is the right representation" just for cross checking? ( Yes the client will checks for CPFD in order to decode the data). 

    even though I am combining all three fields together in the characteristics, Is it possible to control the characteristic notify property only depends on the alert flag field? because sometimes I just want to notify only if there is any alert flag obtained. If so what changes should I implement in the notification property of the characteristic?

    Thanks and Regards,

    Sreejith

Related