Ejemplo n.º 1
0
static void btc_gattc_fill_gatt_db_conversion(uint16_t count, uint16_t num, esp_gatt_db_attr_type_t type,
                                                                  uint16_t offset, void *result, btgatt_db_element_t *db)
{
    tBT_UUID bta_uuid = {0};
    uint16_t db_size = (count + offset > num) ? (num - offset) : count;
    switch(type) {
        case ESP_GATT_DB_PRIMARY_SERVICE:
        case ESP_GATT_DB_SECONDARY_SERVICE: {
            esp_gattc_service_elem_t *svc_result = (esp_gattc_service_elem_t *)result;
            for (int i = 0; i < db_size; i++) {
                svc_result->is_primary = (db[offset + i].type == BTGATT_DB_PRIMARY_SERVICE) ? true : false;
                svc_result->start_handle = db[offset + i].start_handle;
                svc_result->end_handle = db[offset + i].end_handle;
                btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
                bta_to_btc_uuid(&svc_result->uuid, &bta_uuid);
                svc_result++;
            }
            break;
        }
        case ESP_GATT_DB_CHARACTERISTIC: {
            esp_gattc_char_elem_t *char_result = (esp_gattc_char_elem_t *)result;
            for (int i = 0; i < db_size; i++) {
                char_result->char_handle = db[offset + i].attribute_handle;
                char_result->properties = db[offset + i].properties;
                btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
                bta_to_btc_uuid(&char_result->uuid, &bta_uuid);
                char_result++;
            }
            break;
        }
        case ESP_GATT_DB_DESCRIPTOR: {
            esp_gattc_descr_elem_t *descr_result = (esp_gattc_descr_elem_t *)result;
            for (int i = 0; i < db_size; i++) {
                descr_result->handle = db[offset + i].attribute_handle;
                btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
                bta_to_btc_uuid(&descr_result->uuid, &bta_uuid);
                descr_result++;
            }
            break;
        }
        case ESP_GATT_DB_INCLUDED_SERVICE: {
            esp_gattc_incl_svc_elem_t *incl_result = (esp_gattc_incl_svc_elem_t *)result;
            for (int i = 0; i < db_size; i++) {
                incl_result->handle = db[offset + i].attribute_handle;
                incl_result->incl_srvc_s_handle = db[offset + i].start_handle;
                incl_result->incl_srvc_e_handle = db[offset + i].end_handle;
                btc128_to_bta_uuid(&bta_uuid, db[offset + i].uuid.uu);
                bta_to_btc_uuid(&incl_result->uuid, &bta_uuid);
                incl_result++;
            }
            break;
        }
        default:
            BTC_TRACE_WARNING("%s(), Not support type(%d)", __func__, type);
            break;
    }
}
Ejemplo n.º 2
0
esp_gatt_status_t btc_ble_gattc_get_db(uint16_t conn_id, uint16_t start_handle, uint16_t end_handle,
                                       esp_gattc_db_elem_t *db, uint16_t *count)
{
    btgatt_db_element_t *get_db = NULL;
    int num = 0;
    tBT_UUID bta_uuid;
    uint16_t db_size = 0;
    BTA_GATTC_GetGattDb(conn_id, start_handle, end_handle, &get_db, &num);

    if (num == 0) {
        if (get_db) {
            osi_free(get_db);
        }
        *count = 0;
        return ESP_GATT_NOT_FOUND;
    }

    db_size = (*count > num) ? num : (*count);
    for (int i = 0; i < db_size; i++) {
        db[i].type = get_db[i].type;
        db[i].attribute_handle = get_db[i].id;
        db[i].start_handle = get_db[i].start_handle;
        db[i].end_handle = get_db[i].end_handle;
        db[i].properties = get_db[i].properties;
        btc128_to_bta_uuid(&bta_uuid, get_db[i].uuid.uu);
        bta_to_btc_uuid(&db[i].uuid, &bta_uuid);
    }
    *count = db_size;
    //don't forget to free the db buffer after used.
    if (get_db) {
        osi_free(get_db);
    }
    return ESP_GATT_OK;
}
Ejemplo n.º 3
0
void bta_to_btc_gatt_id(esp_gatt_id_t *p_dest, tBTA_GATT_ID *p_src)
{
    p_dest->inst_id = p_src->inst_id;
    bta_to_btc_uuid(&p_dest->uuid, &p_src->uuid);
}