static int cmd_gatt_mread(int argc, char *argv[]) { uint16_t h[8]; int i, err; if (!default_conn) { printk("Not connected\n"); return 0; } if (argc < 3) { return -EINVAL; } if (argc - 1 > ARRAY_SIZE(h)) { printk("Enter max %u handle items to read\n", ARRAY_SIZE(h)); return 0; } for (i = 0; i < argc - 1; i++) { h[i] = strtoul(argv[i + 1], NULL, 16); } read_params.func = read_func; read_params.handle_count = i; read_params.handles = h; /* not used in read func */ err = bt_gatt_read(default_conn, &read_params); if (err) { printk("GATT multiple read request failed (err %d)\n", err); } return 0; }
static int cmd_gatt_read(int argc, char *argv[]) { int err; if (!default_conn) { printk("Not connected\n"); return 0; } read_params.func = read_func; if (argc < 2) { return -EINVAL; } read_params.handle_count = 1; read_params.single.handle = strtoul(argv[1], NULL, 16); if (argc > 2) { read_params.single.offset = strtoul(argv[2], NULL, 16); } err = bt_gatt_read(default_conn, &read_params); if (err) { printk("Read failed (err %d)\n", err); } else { printk("Read pending\n"); } return 0; }
bool BLECharacteristicImp::read() { int retval = 0; bt_conn_t* conn = NULL; if (true == BLEUtils::isLocalBLE(_ble_device)) { // GATT server can't write return false; } if (_reading) { // Already in reading state return false; } _read_params.func = profile_read_rsp_process; _read_params.handle_count = 1; _read_params.single.handle = _value_handle; _read_params.single.offset = 0; if (0 == _read_params.single.handle) { // Discover not complete return false; } conn = bt_conn_lookup_addr_le(_ble_device.bt_le_address()); if (NULL == conn) { return false; } // Send read request retval = bt_gatt_read(conn, &_read_params); bt_conn_unref(conn); if (0 == retval) { _reading = true; } return _reading; }
static void att_read_rsp(struct bt_conn *conn, uint8_t err, const void *pdu, uint16_t length, void *user_data) { struct bt_gatt_read_params *params = user_data; BT_DBG("err 0x%02x", err); if (err) { params->func(conn, err, NULL, 0); goto done; } if (params->func(conn, 0, pdu, length) == BT_GATT_ITER_STOP) { goto done; } /* * Core Spec 4.2, Vol. 3, Part G, 4.8.1 * If the Characteristic Value is greater than (ATT_MTU – 1) octets * in length, the Read Long Characteristic Value procedure may be used * if the rest of the Characteristic Value is required. */ if (length < (bt_att_get_mtu(conn) - 1)) { goto done; } params->offset += length; /* Continue reading the attribute */ if (bt_gatt_read(conn, params) < 0) { params->func(conn, BT_ATT_ERR_UNLIKELY, NULL, 0); goto done; } return; done: if (params->destroy) { params->destroy(params); } }
bool BLECharacteristic::read(BLEPeripheralHelper &peripheral) { int retval = 0; bt_conn_t* conn = NULL; if (_reading) { // Already in reading state return false; } _read_params.func = profile_read_rsp_process; _read_params.handle_count = 1; _read_params.single.handle = peripheral.valueHandle(this); _read_params.single.offset = 0; if (0 == _read_params.single.handle) { // Discover not complete return false; } conn = bt_conn_lookup_addr_le(peripheral.bt_le_address()); if (NULL == conn) { return false; } // Send read request retval = bt_gatt_read(conn, &_read_params); bt_conn_unref(conn); if (0 == retval) { _reading = true; } return _reading; }