start to add callback task
This commit is contained in:
1 parent
13571bfb7a
commit
1d9d23ddce
3 files changed
+51
-10
No files matched your search
@@ -16,6 +16,8 @@
|
||||
// BLE Service
|
||||
BLEAncs bleancs;
|
||||
|
||||
char buffer[128];
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@@ -71,7 +73,10 @@ void loop()
|
||||
if ( Bluefruit.requestPairing() )
|
||||
{
|
||||
Serial.println("Enable Notification Source's CCCD");
|
||||
bleancs.enableNotification();
|
||||
bleancs.enableNotification();
|
||||
|
||||
Serial.println("| Notification | Category (count) | Title | Message | App ID | App Name |");
|
||||
Serial.println("-------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -79,6 +84,8 @@ void loop()
|
||||
|
||||
void ancs_notification_callback(ancsNotification_t* notif)
|
||||
{
|
||||
int n;
|
||||
|
||||
// Check BLEAncs.h for ancsNotification_t
|
||||
const char* event_str[] = { "Added", "Modified", "Removed" };
|
||||
const char* cat_str [] =
|
||||
@@ -88,8 +95,18 @@ void ancs_notification_callback(ancsNotification_t* notif)
|
||||
"Health and Fitness", "Business and Finance", "Location" , "Entertainment"
|
||||
};
|
||||
|
||||
Serial.printf("[Notification %s] ", event_str[notif->eventID]);
|
||||
Serial.printf("%s (%d) ", cat_str[notif->categoryID], notif->categoryCount);
|
||||
Serial.printf("| %-13s | ", 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);
|
||||
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
#define CFG_ADV_BLINKY_INTERVAL 500
|
||||
|
||||
#define CFG_BLE_TASK_STACKSIZE (512*3)
|
||||
#define CFG_WORKER_TASK_STACKSIZE (512*1)
|
||||
#define CFG_CALLBACK_TASK_STACKSIZE (512*1)
|
||||
#define CFG_SOC_TASK_STACKSIZE (200)
|
||||
|
||||
#define CFG_BOND_NFFS_DIR "/adafruit/bond"
|
||||
@@ -63,8 +63,7 @@ extern "C"
|
||||
|
||||
void adafruit_ble_task(void* arg);
|
||||
void adafruit_soc_task(void* arg);
|
||||
|
||||
COMMENT_OUT( void adafruit_worker_task(void* arg); )
|
||||
void adafruit_callback_task(void* arg);
|
||||
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
@@ -212,6 +211,9 @@ err_t AdafruitBluefruit::begin(bool prph_enable, bool central_enable)
|
||||
TaskHandle_t soc_task_hdl;
|
||||
xTaskCreate( adafruit_soc_task, "SD SOC", CFG_SOC_TASK_STACKSIZE, NULL, TASK_PRIO_HIGH, &soc_task_hdl);
|
||||
|
||||
// TaskHandle_t callback_task_hdl;
|
||||
// xTaskCreate( adafruit_callback_task, "Worker", CFG_CALLBACK_TASK_STACKSIZE, NULL, TASK_PRIO_NORMAL, &callback_task_hdl);
|
||||
|
||||
NVIC_SetPriority(SD_EVT_IRQn, 6);
|
||||
NVIC_EnableIRQ(SD_EVT_IRQn);
|
||||
|
||||
@@ -416,7 +418,15 @@ void adafruit_soc_task(void* arg)
|
||||
}
|
||||
}
|
||||
|
||||
COMMENT_OUT(void adafruit_worker_task(void* arg) { } )
|
||||
void adafruit_callback_task(void* arg)
|
||||
{
|
||||
(void) arg;
|
||||
|
||||
while(1)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------*/
|
||||
/* BLE Event handler
|
||||
|
||||
@@ -164,7 +164,7 @@ typedef struct ATTR_PACKED
|
||||
|
||||
}get_app_attr_t;
|
||||
|
||||
bool BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_t bufsize)
|
||||
uint16_t BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_t bufsize)
|
||||
{
|
||||
// command ID | uid | attr (+ len)
|
||||
get_notif_attr_t command =
|
||||
@@ -188,18 +188,23 @@ bool BLEAncs::getAttribute(uint32_t uid, uint8_t attr, void* buffer, uint16_t bu
|
||||
VERIFY( cmdlen == _control.write_resp(&command, cmdlen) );
|
||||
|
||||
// wait for data arrived (in handleData() )
|
||||
if ( !xSemaphoreTake(_sem, BLE_GENERIC_TIMEOUT) ) return false;
|
||||
if ( !xSemaphoreTake(_sem, ms2tick(BLE_GENERIC_TIMEOUT*10)) ) return 0;
|
||||
|
||||
// calculate actual byte copied
|
||||
bufsize -= _evt_bufsize;
|
||||
|
||||
_evt_buf = NULL;
|
||||
_evt_bufsize = 0;
|
||||
|
||||
return true;
|
||||
return bufsize;
|
||||
}
|
||||
|
||||
void BLEAncs::_handleNotification(uint8_t* data, uint16_t len)
|
||||
{
|
||||
if ( len != 8 ) return;
|
||||
|
||||
PRINT_BUFFER(data, len);
|
||||
|
||||
if ( _notif_cb ) _notif_cb((ancsNotification_t*) data);
|
||||
}
|
||||
|
||||
@@ -207,6 +212,8 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
{
|
||||
static uint16_t attr_len = 0;
|
||||
|
||||
PRINT_BUFFER(data, len);
|
||||
|
||||
// Parse Attribute Length
|
||||
if ( attr_len == 0 )
|
||||
{
|
||||
@@ -223,6 +230,8 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
}
|
||||
}
|
||||
|
||||
PRINT_INT(attr_len);
|
||||
|
||||
if ( _evt_bufsize && _evt_buf )
|
||||
{
|
||||
uint16_t cplen = min16(len, _evt_bufsize);
|
||||
@@ -231,10 +240,15 @@ void BLEAncs::_handleData(uint8_t* data, uint16_t len)
|
||||
|
||||
_evt_buf += cplen;
|
||||
_evt_bufsize -= cplen;
|
||||
|
||||
PRINT_INT(cplen);
|
||||
}
|
||||
|
||||
attr_len -= len;
|
||||
|
||||
PRINT_INT(attr_len);
|
||||
PRINT_INT(_evt_bufsize);
|
||||
|
||||
// all data arrived, signal semaphore
|
||||
if (attr_len == 0) xSemaphoreGive(_sem);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user