Add option to not use adacallback when invoking callback
This commit is contained in:
1 parent
b1336100cc
commit
ecf9df2fae
6 files changed
+59
-32
No files matched your search
@@ -79,18 +79,27 @@ void loop()
|
||||
void ancs_notification_callback(ancsNotification_t* notif)
|
||||
{
|
||||
int n;
|
||||
Serial.printf("| %-13s | ", EVENT_STR[notif->eventID]);
|
||||
Serial.printf("| %-8s | ", EVENT_STR[notif->eventID]);
|
||||
|
||||
// Print Category with padding
|
||||
n = Serial.printf("%s (%d)", CAT_STR[notif->categoryID], notif->categoryCount);
|
||||
for (int i=n; i<20; i++) Serial.print(' ');
|
||||
Serial.print(" | ");
|
||||
|
||||
// Get notification title
|
||||
//memset(buffer, 0, sizeof(buffer));
|
||||
//n = bleancs.getAttribute(notif->uid, ANCS_NOTIF_ATTR_TITLE, buffer, sizeof(buffer));
|
||||
//PRINT_INT(n);
|
||||
//Serial.print(buffer);
|
||||
// Get notification Title
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
bleancs.getAttribute(notif->uid, ANCS_ATTR_TITLE, buffer, sizeof(buffer));
|
||||
Serial.printf("%-14s | ", buffer);
|
||||
|
||||
// Get notification Message
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
bleancs.getAttribute(notif->uid, ANCS_ATTR_MESSAGE, buffer, sizeof(buffer));
|
||||
Serial.printf("%-15s | ", buffer);
|
||||
|
||||
// Get App ID
|
||||
memset(buffer, 0, sizeof(buffer));
|
||||
bleancs.getAttribute(notif->uid, ANCS_ATTR_APP_IDENTIFIER, buffer, sizeof(buffer));
|
||||
Serial.printf("%-20s | ", buffer);
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
@@ -111,7 +120,7 @@ void connect_callback(void)
|
||||
Serial.println("Enable Notification");
|
||||
bleancs.enableNotification();
|
||||
|
||||
Serial.println("| Notification | Category (count) | Title | Message | App ID | App Name |");
|
||||
Serial.println("| Event | Category (count) | Title | Message | App ID | App Name |");
|
||||
Serial.println("-------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,14 +47,13 @@ void adafruit_callback_task(void* arg)
|
||||
ada_callback_t* cb_data;
|
||||
if ( xQueueReceive(_cb_queue, (void*) &cb_data, portMAX_DELAY) )
|
||||
{
|
||||
PRINT_HEX(cb_data);
|
||||
PRINT_INT(cb_data->callback_type);
|
||||
PRINT_HEX(cb_data->malloced_data);
|
||||
// PRINT_HEX(cb_data);
|
||||
// PRINT_INT(cb_data->callback_type);
|
||||
// PRINT_HEX(cb_data->malloced_data);
|
||||
|
||||
void* func = cb_data->callback_func;
|
||||
uint32_t* args = cb_data->arguments;
|
||||
|
||||
|
||||
switch(cb_data->callback_type)
|
||||
{
|
||||
case AdafruitBluefruit_connect_callback_t:
|
||||
|
||||
@@ -45,6 +45,7 @@ void BLECentralCharacteristic::_init(void)
|
||||
_cccd_handle = 0;
|
||||
|
||||
_notify_cb = NULL;
|
||||
_use_AdaCallback = true;
|
||||
_sem = NULL;
|
||||
}
|
||||
|
||||
@@ -65,6 +66,11 @@ void BLECentralCharacteristic::assign(ble_gattc_char_t* gattc_chr)
|
||||
_chr = *gattc_chr;
|
||||
}
|
||||
|
||||
void BLECentralCharacteristic::useAdaCallback(bool enabled)
|
||||
{
|
||||
_use_AdaCallback = enabled;
|
||||
}
|
||||
|
||||
uint16_t BLECentralCharacteristic::valueHandle()
|
||||
{
|
||||
return _chr.handle_value;
|
||||
@@ -265,12 +271,18 @@ void BLECentralCharacteristic::_eventHandler(ble_evt_t* evt)
|
||||
{
|
||||
if (_notify_cb)
|
||||
{
|
||||
uint8_t* data = (uint8_t*) rtos_malloc(hvx->len);
|
||||
if (!data) return;
|
||||
// use AdaCallback or invoke directly
|
||||
if (_use_AdaCallback)
|
||||
{
|
||||
uint8_t* data = (uint8_t*) rtos_malloc(hvx->len);
|
||||
if (!data) return;
|
||||
memcpy(data, hvx->data, hvx->len);
|
||||
|
||||
memcpy(data, hvx->data, hvx->len);
|
||||
|
||||
ada_callback(data, _notify_cb, this, data, hvx->len);
|
||||
ada_callback(data, _notify_cb, this, data, hvx->len);
|
||||
}else
|
||||
{
|
||||
_notify_cb(*this, hvx->data, hvx->len);
|
||||
}
|
||||
}
|
||||
}else
|
||||
{
|
||||
|
||||
@@ -54,6 +54,7 @@ class BLECentralCharacteristic
|
||||
BLECentralCharacteristic(void);
|
||||
BLECentralCharacteristic(BLEUuid bleuuid);
|
||||
|
||||
void assign(ble_gattc_char_t* gattc_chr);
|
||||
bool discoverDescriptor(uint16_t conn_handle);
|
||||
void begin(void);
|
||||
|
||||
@@ -80,7 +81,8 @@ class BLECentralCharacteristic
|
||||
/*------------- Callbacks -------------*/
|
||||
void setNotifyCallback(notify_cb_t fp);
|
||||
|
||||
void assign(ble_gattc_char_t* gattc_chr);
|
||||
void useAdaCallback(bool enabled);
|
||||
|
||||
|
||||
private:
|
||||
ble_gattc_char_t _chr;
|
||||
@@ -88,6 +90,7 @@ class BLECentralCharacteristic
|
||||
|
||||
BLECentralService* _service;
|
||||
notify_cb_t _notify_cb;
|
||||
bool _use_AdaCallback; // whether callback is invoked in seperated task with AdaCallback
|
||||
|
||||
SemaphoreHandle_t _sem;
|
||||
|
||||
|
||||
@@ -95,6 +95,10 @@ bool BLEAncs::begin(void)
|
||||
_data.begin();
|
||||
|
||||
_notification.setNotifyCallback(bleancs_notification_cb);
|
||||
|
||||
// Data Attribute is likely requested in notification callback
|
||||
// let's call data's callback in the ble task
|
||||
_data.useAdaCallback(false);
|
||||
_data.setNotifyCallback(bleancs_data_cb);
|
||||
|
||||
return true;
|
||||
@@ -176,7 +180,7 @@ uint16_t BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_
|
||||
uint8_t cmdlen = 6;
|
||||
|
||||
// Title, Subtitle, Message must require 2-byte length
|
||||
if (attr == ANCS_NOTIF_ATTR_TITLE || attr == ANCS_NOTIF_ATTR_SUBTITLE || attr == ANCS_NOTIF_ATTR_MESSAGE)
|
||||
if (attr == ANCS_ATTR_TITLE || attr == ANCS_ATTR_SUBTITLE || attr == ANCS_ATTR_MESSAGE)
|
||||
{
|
||||
cmdlen = 8;
|
||||
}
|
||||
@@ -202,7 +206,7 @@ void BLEAncs::_handleNotification(uint8_t* data, uint16_t len)
|
||||
{
|
||||
if ( len != 8 ) return;
|
||||
|
||||
PRINT_BUFFER(data, len);
|
||||
// PRINT_BUFFER(data, len);
|
||||
|
||||
if ( _notif_cb ) _notif_cb((ancsNotification_t*) data);
|
||||
}
|
||||
@@ -211,7 +215,7 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
{
|
||||
static uint16_t attr_len = 0;
|
||||
|
||||
PRINT_BUFFER(data, len);
|
||||
// PRINT_BUFFER(data, len);
|
||||
|
||||
// Parse Attribute Length
|
||||
if ( attr_len == 0 )
|
||||
@@ -229,7 +233,7 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
}
|
||||
}
|
||||
|
||||
PRINT_INT(attr_len);
|
||||
// PRINT_INT(attr_len);
|
||||
|
||||
if ( _evt_bufsize && _evt_buf )
|
||||
{
|
||||
@@ -240,13 +244,13 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
_evt_buf += cplen;
|
||||
_evt_bufsize -= cplen;
|
||||
|
||||
PRINT_INT(cplen);
|
||||
// PRINT_INT(cplen);
|
||||
}
|
||||
|
||||
attr_len -= len;
|
||||
|
||||
PRINT_INT(attr_len);
|
||||
PRINT_INT(_evt_bufsize);
|
||||
// PRINT_INT(attr_len);
|
||||
// PRINT_INT(_evt_bufsize);
|
||||
|
||||
// all data arrived, signal semaphore
|
||||
if (attr_len == 0) xSemaphoreGive(_sem);
|
||||
|
||||
@@ -82,14 +82,14 @@ enum
|
||||
// Notification Attribute ID
|
||||
enum
|
||||
{
|
||||
ANCS_NOTIF_ATTR_APP_IDENTIFIER ,
|
||||
ANCS_NOTIF_ATTR_TITLE , // followed bye 2-byte length
|
||||
ANCS_NOTIF_ATTR_SUBTITLE , // followed bye 2-byte length
|
||||
ANCS_NOTIF_ATTR_MESSAGE , // followed bye 2-byte length
|
||||
ANCS_NOTIF_ATTR_MESSAGE_SIZE ,
|
||||
ANCS_NOTIF_ATTR_DATE , // UTC#35 yyyyMMdd'T'HHmmSS
|
||||
ANCS_NOTIF_ATTR_POSITIVE_ACTION_LABEL ,
|
||||
ANCS_NOTIF_ATTR_NEGATIVE_ACTION_LABEL
|
||||
ANCS_ATTR_APP_IDENTIFIER ,
|
||||
ANCS_ATTR_TITLE , // followed bye 2-byte length
|
||||
ANCS_ATTR_SUBTITLE , // followed bye 2-byte length
|
||||
ANCS_ATTR_MESSAGE , // followed bye 2-byte length
|
||||
ANCS_ATTR_MESSAGE_SIZE ,
|
||||
ANCS_ATTR_DATE , // UTC#35 yyyyMMdd'T'HHmmSS
|
||||
ANCS_ATTR_POSITIVE_ACTION_LABEL ,
|
||||
ANCS_ATTR_NEGATIVE_ACTION_LABEL
|
||||
};
|
||||
|
||||
// Action ID
|
||||
|
||||
Reference in new issue
Block a user