- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I want the ble module to execute some functions upon one of it's characteristics being read. Here is my callback function code:
void BleCallBack( uint32 event, void* eventParam )
{
CYBLE_GATTS_READ_RSP_PARAM_T *rdRspParam;
switch( event )
{
case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ:
rdRspParam = ( CYBLE_GATTS_READ_RSP_PARAM_T * ) eventParam;
if( rdRspParam->?????.attrHandle == CYBLE_DIAPER_BUCKLE_STOREDDIAPERCOUNT_CHAR_HANDLE; )
{
//code to run upon characteristic being read
}
break;
default:
break;
}
What should I use in place of the ?????s? Or should I be doing something completely different.
Thanks!
Solved! Go to Solution.
- Labels:
-
BLE
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/** 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. */
Thus, unless you only want it to run for certain characteristic responses, you don't really need to check what handle/value is being read/sent.
void BleCallBack( uint32 event, void* eventParam )
{
CYBLE_GATTS_READ_RSP_PARAM_T *rdRspParam;
switch( event )
{
case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ:
rdRspParam = ( CYBLE_GATTS_READ_RSP_PARAM_T * ) eventParam;
if( rdRspParam->attrHandle == CYBLE_DIAPER_BUCKLE_STOREDDIAPERCOUNT_CHAR_HANDLE; )
{
//code to run upon specific characteristic being read
}
//code that runs upon any characteristic being read
break;
default:
break;
}
Please note: As mady stated, if you are doing any long/involved calculations or functions that take up time, you will want to run them in main instead, and to only set the trigger/flag in the event here.
This also allows for more event-based programming too; With main loop being run continuously, and functions being called only when triggered by events or changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
This is fine, as long as the function you are calling does not do complex tasks (such as reading from the flash, accessing bonding data, accessing I2C, SPI interfaces etc.,)
If the function is complex, I recommend you to simply set a flag in the BLE Event Callback. In the for loop of the main function, this flag is constantly polled to see if it has been set, upon which the function to be executed is called.
This is done because, it is not recommended to call complex functions in BLE Callback.
Regards,
- Madhu Sudhan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes, I should have thought of that. Thanks much!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
/** 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. */
Thus, unless you only want it to run for certain characteristic responses, you don't really need to check what handle/value is being read/sent.
void BleCallBack( uint32 event, void* eventParam )
{
CYBLE_GATTS_READ_RSP_PARAM_T *rdRspParam;
switch( event )
{
case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ:
rdRspParam = ( CYBLE_GATTS_READ_RSP_PARAM_T * ) eventParam;
if( rdRspParam->attrHandle == CYBLE_DIAPER_BUCKLE_STOREDDIAPERCOUNT_CHAR_HANDLE; )
{
//code to run upon specific characteristic being read
}
//code that runs upon any characteristic being read
break;
default:
break;
}
Please note: As mady stated, if you are doing any long/involved calculations or functions that take up time, you will want to run them in main instead, and to only set the trigger/flag in the event here.
This also allows for more event-based programming too; With main loop being run continuously, and functions being called only when triggered by events or changes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you!