]> granicus.if.org Git - esp-idf/commitdiff
component/bt: Added the queue event when the gattc command is full.
authorYulong <huangyulong@espressif.com>
Tue, 14 Nov 2017 03:44:27 +0000 (22:44 -0500)
committerYulong <huangyulong@espressif.com>
Tue, 14 Nov 2017 03:44:27 +0000 (22:44 -0500)
components/bt/bluedroid/api/include/esp_gattc_api.h
components/bt/bluedroid/bta/gatt/bta_gattc_act.c
components/bt/bluedroid/bta/gatt/bta_gattc_utils.c
components/bt/bluedroid/bta/include/bta_gatt_api.h
components/bt/bluedroid/bta/include/bta_gattc_int.h
components/bt/bluedroid/btc/profile/std/gatt/btc_gattc.c

index 6a6aa579cfcd255820cca4f515448617ca5258d6..1bf9d3b9f4f5e8b84382b6002834ab645774d29f 100644 (file)
@@ -64,6 +64,7 @@ typedef enum {
     ESP_GATTC_CONNECT_EVT             = 40,       /*!< When the ble physical connection is set up, the event comes */
     ESP_GATTC_DISCONNECT_EVT          = 41,       /*!< When the ble physical connection disconnected, the event comes */
     ESP_GATTC_READ_MUTIPLE_EVT        = 42,       /*!< When the ble characteristic or descriptor mutiple complete, the event comes */
+    ESP_GATTC_QUEUE_FULL_EVT          = 43,       /*!< When the gattc command queue full, the event comes */
 } esp_gattc_cb_event_t;
 
 
@@ -214,6 +215,15 @@ typedef union {
         esp_bd_addr_t remote_bda;       /*!< Remote bluetooth device address */
     } disconnect;                       /*!< Gatt client callback param of ESP_GATTC_DISCONNECT_EVT */
 
+    /**
+     * @brief ESP_GATTC_QUEUE_FULL_EVT
+     */
+    struct gattc_queue_full_evt_param {
+        esp_gatt_status_t status;      /*!< Operation status */
+        uint16_t conn_id;              /*!< Connection id */
+        bool     is_full;              /*!< The gattc command queue is full or not */
+    } queue_full;                      /*!< Gatt client callback param of ESP_GATTC_QUEUE_FULL_EVT */
+
 } esp_ble_gattc_cb_param_t;             /*!< GATT client callback parameter union type */
 
 /**
index c5a2990d9ddbdc1b91b358f1a2efd87daa994ed3..e93f451a039beaac6a13a6170e8831eb0e74206f 100644 (file)
@@ -1478,13 +1478,21 @@ static void bta_gattc_pop_command_to_send(tBTA_GATTC_CLCB *p_clcb)
         if (p_data != NULL) {
             /* execute pending operation of link block still present */
             if (l2cu_find_lcb_by_bd_addr(p_clcb->p_srcb->server_bda, BT_TRANSPORT_LE) != NULL) {
-                if (p_data->hdr.event == BTA_GATTC_API_WRITE_EVT) {
-                    APPL_TRACE_ERROR("%s(), p_data = %d", __func__, p_data->api_write.p_value[0]);
-                }
                 // The data to be sent to the gattc state machine for processing
                 if(bta_gattc_sm_execute(p_clcb, p_data->hdr.event, p_data)) {
                     list_remove(p_clcb->p_cmd_list, (void *)p_data);
                 }
+
+                if (p_clcb->is_full) {
+                    tBTA_GATTC cb_data = {0};
+                    p_clcb->is_full = FALSE;
+                    cb_data.status = GATT_SUCCESS;
+                    cb_data.queue_full.conn_id = p_clcb->bta_conn_id;
+                    cb_data.queue_full.is_full = FALSE;
+                    if (p_clcb->p_rcb->p_cback != NULL) {
+                        ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_QUEUE_FULL_EVT, (tBTA_GATTC *)&cb_data);
+                    }
+                }
             }
         }
     }
index c5423a1a8250f5bbda2855041526d6c8efc6e00d..620d08e83075a05383a76a1eb7423ee749460465 100644 (file)
@@ -427,7 +427,7 @@ tBTA_GATTC_SERV *bta_gattc_srcb_alloc(BD_ADDR bda)
     return p_tcb;
 }
 
-static void bta_gattc_remove_prepare_write_in_queue(tBTA_GATTC_CLCB *p_clcb)
+static BOOLEAN bta_gattc_has_prepare_command_in_queue(tBTA_GATTC_CLCB *p_clcb)
 {
     assert(p_clcb != NULL);
 
@@ -438,12 +438,11 @@ static void bta_gattc_remove_prepare_write_in_queue(tBTA_GATTC_CLCB *p_clcb)
         if (cmd_data != NULL && ((cmd_data->hdr.event == BTA_GATTC_API_WRITE_EVT &&
             cmd_data->api_write.write_type == BTA_GATTC_WRITE_PREPARE) ||
             cmd_data->hdr.event == BTA_GATTC_API_EXEC_EVT)) {
-            // remove the prepare write command in the command queue
-            list_remove(p_clcb->p_cmd_list, (void *)cmd_data);
+            return TRUE;
         }
     }
 
-    return;
+    return FALSE;
 }
 /*******************************************************************************
 **
@@ -456,27 +455,38 @@ static void bta_gattc_remove_prepare_write_in_queue(tBTA_GATTC_CLCB *p_clcb)
 *******************************************************************************/
 BOOLEAN bta_gattc_enqueue(tBTA_GATTC_CLCB *p_clcb, tBTA_GATTC_DATA *p_data)
 {
+    tBTA_GATTC cb_data = {0};
 
     if (p_clcb->p_q_cmd == NULL) {
         p_clcb->p_q_cmd = p_data;
         return TRUE;
     } else if (p_data->hdr.event == BTA_GATTC_API_WRITE_EVT &&
                p_data->api_write.write_type == BTA_GATTC_WRITE_PREPARE &&
-               p_data->api_write.handle == p_clcb->p_q_cmd->api_write.handle) {
-        bta_gattc_remove_prepare_write_in_queue (p_clcb);
-        tBTA_GATTC cb_data = {0};
+               p_data->api_write.handle == p_clcb->p_q_cmd->api_write.handle &&
+               bta_gattc_has_prepare_command_in_queue(p_clcb)) {
         cb_data.write.status = BTA_GATT_CONGESTED;
         cb_data.write.handle = p_data->api_write.handle;
         cb_data.write.conn_id = p_clcb->bta_conn_id;
         /* write complete, callback */
-        ( *p_clcb->p_rcb->p_cback)(p_data->hdr.event, (tBTA_GATTC *)&cb_data);
+        if (p_clcb->p_rcb->p_cback != NULL) {
+            ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_PREP_WRITE_EVT, (tBTA_GATTC *)&cb_data);
+        }
         return FALSE;
     }
     else if (p_clcb->p_cmd_list) {
         UINT16 len = 0;
         tBTA_GATTC_DATA *cmd_data = NULL;
+
         if (list_length(p_clcb->p_cmd_list) >= GATTC_COMMAND_QUEUE_SIZE_MAX) {
+
             APPL_TRACE_ERROR("%s(), the gattc command queue is full.", __func__);
+            cb_data.status = GATT_BUSY;
+            cb_data.queue_full.conn_id = p_clcb->bta_conn_id;
+            cb_data.queue_full.is_full = TRUE;
+            p_clcb->is_full = TRUE;
+            if (p_clcb->p_rcb->p_cback != NULL) {
+                ( *p_clcb->p_rcb->p_cback)(BTA_GATTC_QUEUE_FULL_EVT, (tBTA_GATTC *)&cb_data);
+            }
             return FALSE;
         }
 
index 4d5b975e100831965578e721afaada37acf91a4d..b7dfa855a69732eb87475d34a839a3a9be176eb2 100644 (file)
@@ -182,6 +182,7 @@ typedef UINT8 tBTA_GATT_STATUS;
 #define BTA_GATTC_CONNECT_EVT           35 /* GATTC CONNECT  event */
 #define BTA_GATTC_DISCONNECT_EVT        36 /* GATTC DISCONNECT  event */
 #define BTA_GATTC_READ_MUTIPLE_EVT      37 /* GATTC Read mutiple event */
+#define BTA_GATTC_QUEUE_FULL_EVT        38 /* GATTC queue full event */
 
 typedef UINT8 tBTA_GATTC_EVT;
 
@@ -354,6 +355,12 @@ typedef struct {
     BOOLEAN congested; /* congestion indicator */
 } tBTA_GATTC_CONGEST;
 
+typedef struct {
+    tBTA_GATT_STATUS status;
+    UINT16 conn_id;
+    BOOLEAN is_full;
+} tBTA_GATTC_QUEUE_FULL;
+
 typedef struct {
     tBTA_GATT_STATUS        status;
     tBTA_GATTC_IF           client_if;
@@ -399,6 +406,7 @@ typedef union {
     BD_ADDR                 remote_bda;     /* service change event */
     tBTA_GATTC_CFG_MTU      cfg_mtu;        /* configure MTU operation */
     tBTA_GATTC_CONGEST      congest;
+    tBTA_GATTC_QUEUE_FULL   queue_full;
 } tBTA_GATTC;
 
 /* GATTC enable callback function */
index 8bb233fcc421e0ea0ae7e708fc7f926f1e2ddad6..59810b223cfee9fb5db47c00151d2a9442425dfb 100644 (file)
@@ -311,6 +311,7 @@ typedef struct {
     tBTA_GATTC_SERV     *p_srcb;    /* server cache CB */
     tBTA_GATTC_DATA     *p_q_cmd;   /* command in queue waiting for execution */
     list_t              *p_cmd_list; /* The list to store the command to be sent */
+    BOOLEAN             is_full;     /* The gattc command queue is full or not */
 #define BTA_GATTC_NO_SCHEDULE       0
 #define BTA_GATTC_DISC_WAITING      0x01
 #define BTA_GATTC_REQ_WAITING       0x10
index c13b9ff0e26822fbef2344631ffb128701dc96a3..a1a1c88541710979337ec60a153ff1bd7d00c616 100644 (file)
@@ -917,6 +917,15 @@ void btc_gattc_cb_handler(btc_msg_t *msg)
         btc_gattc_cb_to_app(ESP_GATTC_SRVC_CHG_EVT, ESP_GATT_IF_NONE, &param);
         break;
     }
+    case BTA_GATTC_QUEUE_FULL_EVT: {
+        tBTA_GATTC_QUEUE_FULL *queue_full = &arg->queue_full;
+        gattc_if = BTC_GATT_GET_GATT_IF(queue_full->conn_id);
+        param.queue_full.conn_id = BTC_GATT_GET_CONN_ID(queue_full->conn_id);
+        param.queue_full.status = arg->status;
+        param.queue_full.is_full = queue_full->is_full;
+        btc_gattc_cb_to_app(ESP_GATTC_QUEUE_FULL_EVT, gattc_if, &param);
+        break;
+    }
     default:
         LOG_DEBUG("%s: Unhandled event (%d)!", __FUNCTION__, msg->act);
         break;