Question regarding GATT Characteristics

⚠️
Hi there.. thanks for coming to the forums. Exciting news! we’re now in the process of moving to our new forum platform that will offer better functionality and is contained within the main Dialog website. All posts and accounts have been migrated. We’re now accepting traffic on the new forum only - please POST any new threads at计画ps://www.wsdof.com/support. We’ll be fixing bugs / optimising the searching and tagging over the coming days.
5个帖子/ 0新
Last post
dsandbue
Offline
Last seen:1年9个月前
加入:2017-02-15 14:09
Question regarding GATT Characteristics

Hello there,

I'd like to implement a GATT characteristic, where the Smartphone sends a Read-query and the DA14680 answers with the value of a variable (changing on runtime). So I've looked at the Battery Service to get an idea how to implement it.

The Battery Service behaves exactly as I'd like my own Service - you can query it and get a changing variable as return. However, what is bugging me (in file sdk/ble-services/src/bas.c):
As far as I understand, when you send a Read-query, it gets handled by the function "handle_read_req()". However, when I debug the program and set a breakpoint in this function, send a Read-query from a Smartphone to this characteristic, the breakpoint is never reached/activated, BUT the Smartphone receives the battery value anyway. So, it would be great if you could explain how/where the answer to the query gets generated/sent. :-)

Background to my question: In my application, once a Read-query is received, the DA14680 needs to perform some arithmetics before it sends out the variable as a response, and I'd like to put these operations in a handle or callback-function, but I'm uncertain which function I can use for that...
我理解,可以通过BLE_GATTS_SET_VALUE() - 函数来更改响应值 - 但我想仅在读取查询的情况下调用/使用该功能,从而避免轮询该功能并浪费计算力量。

Thanks in advance
Philipp

Device:
MT_dialog
Offline
Last seen:2 months 3 weeks ago
工作人员
加入:2015-06-08 11:34
Hi dsandbue,

Hi dsandbue,

The reply to the phone device from the peripheral device is send directly from the stack in the case of the 580, the stack will read the databases value and feedback the phone with the proper value. Now in the 5.0.4 SDK there is a way to catch the reading indication, please check the following link for more details计画ps://support.dialog-semiconductor.com/gattcreadcmdind-da14580.

Regarding your second question, in order to have handlers that will handle the interactions with your custom profile you will have to follow the examples of the allready implemented profiles, lets take for example the bas_init() function of the bas profile. You will see that there is a structure that it will house all the info regarding the profile including the handlers for each event (connected, read, write etc). So you will have to implement something similar for your custom profile and have a similar callback function for your read_req member of the structure, after doing that you will have to add the service using the ble_service_add() in order for the manager to trigger you for events, you will also be able to find some documentation in the UM-B-044 DA1468x Software Platform Reference.pdf in paragraph 7.2.2. By doing the above each time there will be a read/write etc request the corresponding handler will be triggered.

Thanks MT_dialog

dsandbue
Offline
Last seen:1年9个月前
加入:2017-02-15 14:09
谢谢您的回答,

谢谢您的回答,unfortunately I chose the wrong "category", I'm solely using the DA14680 and not 580, so I'm wondering if the first part of your answer is true for the DA14680 also? Because this is what I'm experiencing - so I can't halt the program in the handle_read_req(), because the read-query gets processed by the stack?

MT_dialog
Offline
Last seen:2 months 3 weeks ago
工作人员
加入:2015-06-08 11:34
Hi dsandbue,

Hi dsandbue,

No, this doesn't stand for the 68x family, with the 68x you should be able to halt the read request as soon as a central tries to read from your characteristic but still you need to implement the handle_read_req() function for that specific characteristic and also you need to enable that feature while creating the characteristic. So when creating the characteristic using the ble_gatts_add_characteristic() the parameter gatts_flag_t flags if set to GATTS_FLAG_CHAR_READ_REQ will re-route the request to application level and you will be able to catch the request in the application level, and then you will have to send the confirmation value manually using the ble_gatts_read_cfm().

Thanks MT_dialog

dsandbue
Offline
Last seen:1年9个月前
加入:2017-02-15 14:09
Thank you very much!! It

Thank you very much!! It works like a charm now. :-)