uint16_t set_read_value(btgatt_read_params_t *p_dest, tBTA_GATTC_READ *p_src)
{
    int i = 0;
    uint16_t descr_type = 0;
    uint16_t len = 0;

    p_dest->status = p_src->status;
    bta_to_btif_srvc_id(&p_dest->srvc_id, &p_src->srvc_id);
    bta_to_btif_gatt_id(&p_dest->char_id, &p_src->char_id);
    bta_to_btif_gatt_id(&p_dest->descr_id, &p_src->descr_type);

    descr_type = get_uuid16(&p_src->descr_type.uuid);

    switch (descr_type)
    {
        case GATT_UUID_CHAR_AGG_FORMAT:
            /* not supported */
            p_dest->value_type = GATTC_READ_VALUE_TYPE_AGG_FORMAT;
            break;

        default:
            if (( p_src->status == BTA_GATT_OK ) &&(p_src->p_value != NULL))
            {
                ALOGI("%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len);
                p_dest->value.len = p_src->p_value->unformat.len;
                if ( p_src->p_value->unformat.len > 0  && p_src->p_value->unformat.p_value != NULL )
                {
                    memcpy(p_dest->value.value, p_src->p_value->unformat.p_value,
                           p_src->p_value->unformat.len);
                }
                len += p_src->p_value->unformat.len;
            }
            else
            {
                p_dest->value.len = 0;
            }

            p_dest->value_type = GATTC_READ_VALUE_TYPE_VALUE;
            break;
    }

    return len;
}
Ejemplo n.º 2
0
uint16_t set_read_value(uint8_t *gattc_if, esp_ble_gattc_cb_param_t *p_dest, tBTA_GATTC_READ *p_src)
{
    uint16_t descr_type = 0;
    uint16_t len = 0;

    p_dest->read.status = p_src->status;
    p_dest->read.conn_id = BTC_GATT_GET_CONN_ID(p_src->conn_id);
    *gattc_if = BTC_GATT_GET_GATT_IF(p_src->conn_id);
    bta_to_btc_srvc_id(&p_dest->read.srvc_id, &p_src->srvc_id);
    bta_to_btc_gatt_id(&p_dest->read.char_id, &p_src->char_id);
    bta_to_btc_gatt_id(&p_dest->read.descr_id, &p_src->descr_type);

    descr_type = get_uuid16(&p_src->descr_type.uuid);

    switch (descr_type) {
    case GATT_UUID_CHAR_AGG_FORMAT:
        /* not supported */
        p_dest->read.value_type = GATTC_READ_VALUE_TYPE_AGG_FORMAT;
        p_dest->read.value_len = 0;
        break;

    default:
        if (( p_src->status == BTA_GATT_OK ) && (p_src->p_value != NULL)) {
            LOG_INFO("%s unformat.len = %d ", __FUNCTION__, p_src->p_value->unformat.len);
            p_dest->read.value_len = p_src->p_value->unformat.len;
            if ( p_src->p_value->unformat.len > 0  && p_src->p_value->unformat.p_value != NULL ) {
                p_dest->read.value = p_src->p_value->unformat.p_value;
            }
            len += p_src->p_value->unformat.len;
        } else {
            p_dest->read.value_len = 0;
        }

        p_dest->read.value_type = GATTC_READ_VALUE_TYPE_VALUE;
        break;
    }

    return len;
}