You are here

GATT events for stanadard BLE services | Cypress Semiconductor

GATT events for stanadard BLE services

Summary: 13 Replies, Latest post by jrow on 31 Aug 2016 08:31 AM PDT
Verified Answers: 4
Last post
Log in to post new comments.
sharan.avati_1560381's picture
User
25 posts

Hi,

Is it possible to handle the GATT events in the app level for the BLE standard services such as device information service, battery service etc.

I looked at the device info example application, the db values are set during main init and the read events are handled by the stack.

Actually we want to handle all the events at the application level as we get all information from an external MCU.

Thanks & Regards,

Sharan

SmartPSoC's picture
Cypress Employee
74 posts

All the standard service events are handled in the stack. Please check the BLE_eventhandler.c for the event handlers.

 

 

sharan.avati_1560381's picture
User
25 posts

Hi,

That didn't answer my question.

I meant what do I need to do in order to receive the standard service events. As I said in my earlier post that we require these events to be handled in the application because we are interfacing with an external MCU.

Please let me know is there way to receive these events?

Thanks & Regards,

Sharan

 

 

jrow's picture
Cypress Employee
117 posts

Hello Sharan,

You may want to check out the recently released EZ-Serial firmware platform:

http://www.cypress.com/documentation/software-and-drivers/ez-serial-ez-b...

The User Guide available on that page contains all of the information you should need to tell whether it would be a good fit for what you're trying to do.

This platform or something like it will be necessary to do what you need; there is no universal protocol for exposing general host-level BLE events to an external MCU, so it has to be implemented in module application firmware by bridging the BLE Component APIs to some kind of host interface. EZ-Serial does this using a text-mode or binary-mode serial protocol over the UART interface.

Jeff

sharan.avati_1560381's picture
User
25 posts

Hi Jrow,

I understand what you're trying to say but we don't need serial like BLE module. We writing our complete application firmware on Cypress BLE chip. We have an external MCU for some other reasons.

But we want handle all the servers events(standard and custom services) at the app level(BLE event callback). For e.g Is it possible to handle the read request of the device info service characteristic at the app level and send a read response. 

This is quite possible in most of the BLE solutions in the market.

Note:

Currently we are evaluating the Cypress BLE 4.2 chip for our future products.

Thanks & Regards,

Sharan

jrow's picture
Cypress Employee
117 posts

Hi Sharan,

In this case, yes, it is possible to do this with your own custom application as well. There are two options; first is to enable all events being passed up to the application by setting the correct flag:

cyBle_eventHandlerFlag |= CYBLE_ENABLE_ALL_EVENTS;

This will retain the built-in functionality, but also allow the event to reach the application callback handler after the component callback handlers processes it.

The other option is to augment or modify the code in the Generated_Source folder that PSoC Creator builds for the application. For example, tweaking the #define macros in the BLEName_gatt.h file starting usually around line 50 or so where various profiles are enabled:

#define CYBLE_DIS
#define CYBLE_DIS_SERVER

If you comment these lines out or remove them entirely, then the component's built-in event handlers for these profiles won't be run, and only your application handler will receive them. Also, keep in mind that this approach--modifying PSoC Creator generated code--will require re-applying those modifications any time the code is regenerated. This occurs after a "clean" operation or after any change to the project schematic or design-wide resources.

The specific case you mention as an example (read request to allow the application to intercept the response) is handled via the CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event, described in the source code with the following comment:

   /** Event parameter type is CYBLE_GATTS_CHAR_VAL_READ_REQ_T. It is triggered on server side
       when client sends read request and when characteristic has CYBLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT
       property set. This event could be ignored by application unless it need to response by error response which
       needs to be set in gattErrorCode field of event parameter. */

Note that the event parameter, a pointer to data of type CYBLE_GATTS_CHAR_VAL_READ_REQ_T, does not have a structure field for the actual data which is returned. In other words, the event parameter (pointer) does not provide a way to change the value data that is sent back to the client. However, the parameter does include the attribute handle, and with this you should be able to modify the contents of the attribute with the CyBle_GattsWriteAttributeValue API method.

I am not certain whether this occurs before or after the attribute data has been loaded into the packet buffer for transmission, but I would assume for efficiency's sake (in case an error code is set) that it happens before.

sharan.avati_1560381's picture
User
25 posts

Hi Jrow,

Appreciate the detailed explanation. Thank you very much.

I hope that packet buffer is loaded after responding to the CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ. Otherwise it would be tricky for the application's logic.  If not isn't it a good idea to fix it?

Anyways I'll verify the behavior.

Thanks & Regards,

Sharan

 

 

 

 

 

 

sharan.avati_1560381's picture
User
25 posts

Hi Jrow,

Can you please tell me how to enable all the events programmatically, is there an API available?

cyBle_eventHandlerFlag |= CYBLE_ENABLE_ALL_EVENTS;

Thanks & Regards,

Sharan

 

 

jrow's picture
Cypress Employee
117 posts

Hi Sharan,

The line of code directly assigning the CYBLE_ENABLE_ALL_EVENTS bitmask to the cyBle_eventHandlerFlag variable is the only way that I know of to set that flag. I don't believe there is a separate API to set it.

All events are generated internally regardless of this setting, but the component's auto-generated CyBle_EventHandler method may consume some events before your application handler gets them unless this flag is set.

sharan.avati_1560381's picture
User
25 posts

Hi Jrow,

I tried it today, the application didn't receive the event CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ.

Enabled cyBle_eventHandlerFlag in the main entry to receive all the events.

Thanks & Regards,

Sharan

 

jrow's picture
Cypress Employee
117 posts

Hi Sharan,

In the /Generated_Source/PSoC4/BLE_gatt.c source file, there is a cyBle_gattDB[] array declaration which defines the complete GATT structure for your application. The 3rd field in each entry is the permissions value. Can you confirm that this value has the equivalent bitmask applied which matches the CYBLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT constant value, on each of the characteristic value attributes for which you want to receive the CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ event?

If you aren't totally sure how to do this, you can also simply copy and paste the cyBle_gattDB[] array definition from BLE_gatt.c into a reply here, and I can check it for you.

Log in to post new comments.