From 8fec43eecb05fa667012c8a9f442243f83be51bf Mon Sep 17 00:00:00 2001 From: Isha Pardikar Date: Tue, 5 Oct 2021 16:06:20 +0530 Subject: [PATCH] Merge branch 'nimble/add_throughput_example' into 'master' NimBLE throughput example: Changed write api to write without response See merge request espressif/esp-idf!16138 --- .../bluetooth/nimble/throughput_app/README.md | 6 +- .../components/cmd_system/cmd_system.c | 11 ++-- .../components/cmd_system/cmd_system.h | 12 ++-- .../blecent_throughput/main/Kconfig.projbuild | 2 +- .../blecent_throughput/main/gattc.h | 19 +----- .../blecent_throughput/main/main.c | 59 +++++-------------- .../blecent_throughput/main/misc.c | 17 +----- .../blecent_throughput/main/peer.c | 17 +----- .../blecent_throughput/main/scli.c | 19 +----- .../bleprph_throughput/main/gatt_svr.c | 19 +----- .../bleprph_throughput/main/gatts_sens.h | 19 +----- .../bleprph_throughput/main/main.c | 19 +----- 12 files changed, 41 insertions(+), 178 deletions(-) diff --git a/examples/bluetooth/nimble/throughput_app/README.md b/examples/bluetooth/nimble/throughput_app/README.md index 0f6199a79c..0b26ba21db 100644 --- a/examples/bluetooth/nimble/throughput_app/README.md +++ b/examples/bluetooth/nimble/throughput_app/README.md @@ -9,8 +9,8 @@ sample numbers of different throughput test runs for 60 seconds (MTU = 512, conn |GATT method | Measurement time | Application Throughput| |--- | --- | ---| -|NOTIFY | 60 seconds | ~530Kbps| -|READ | 60 seconds | ~180kbps| -|WRITE | 60 seconds | ~180kbps| +|NOTIFY | 60 seconds | ~340Kbps| +|READ | 60 seconds | ~200kbps| +|WRITE | 60 seconds | ~500kbps| The notify output is seen on `bleprph_throughput` console and read/write throughput are seen on `blecent_throughput` console. diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c index d1a6876d8f..4fa3240b1c 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.c @@ -1,10 +1,7 @@ -/* Console example — various system commands - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.h b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.h index 9af96a8ae5..96bf93b71b 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.h +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/components/cmd_system/cmd_system.h @@ -1,11 +1,9 @@ -/* Console example — various system commands - - This example code is in the Public Domain (or CC0 licensed, at your option.) - - Unless required by applicable law or agreed to in writing, this - software is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR - CONDITIONS OF ANY KIND, either express or implied. +/* + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 */ + #pragma once #ifdef __cplusplus diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/Kconfig.projbuild b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/Kconfig.projbuild index 429b5b1331..f82a600bcf 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/Kconfig.projbuild +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/Kconfig.projbuild @@ -37,7 +37,7 @@ menu "Example Configuration" Set the minimum connection event length in 0.625msec units. config EXAMPLE_CONN_CE_LEN_MAX - int "Minimum connection itvl" + int "Maximum connection event length" default 12 help Set the maximum connection event length in 0.625msec units. diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/gattc.h b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/gattc.h index 5f7a9a1260..9983498123 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/gattc.h +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/gattc.h @@ -1,22 +1,7 @@ /* - * // Modifications Copyright 2020-2021 Espressif Systems (Shanghai) CO., LTD. + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #ifndef H_BLECENT_ diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c index 88ab0a5d49..b1e8f75311 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/main.c @@ -1,22 +1,7 @@ /* - * Copyright 2020 Espressif Systems (Shanghai) PTE LTD + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include "esp_log.h" @@ -117,26 +102,8 @@ err: return ble_gap_terminate(peer->conn_handle, BLE_ERR_REM_USER_CONN_TERM); } -static int -blecent_repeat_write(uint16_t conn_handle, - const struct ble_gatt_error *error, - struct ble_gatt_attr *attr, - void *arg) -{ - if (error->status == 0) { - xSemaphoreGive(xSemaphore); - ESP_LOGD(tag, " attr_handle=%d value=", attr->handle); - MODLOG_DFLT(INFO, "\n"); - } else { - failure_count++; - xSemaphoreGive(xSemaphore); - ESP_LOGE(tag, " Error writing error code = %d", error->status); - } - return error->status; -} - static int blecent_write(uint16_t conn_handle, uint16_t val_handle, - ble_gatt_attr_fn *cb, struct peer *peer, int test_time) + struct peer *peer, int test_time) { int64_t start_time, end_time, write_time = 0; int write_count = 0; @@ -150,13 +117,16 @@ static int blecent_write(uint16_t conn_handle, uint16_t val_handle, while (write_time < test_time * 1000) { /* Wait till the previous write is complete. For first time Semaphore * is already available */ - xSemaphoreTake(xSemaphore, portMAX_DELAY); - rc = ble_gattc_write_flat(conn_handle, val_handle, - &value, sizeof value, blecent_repeat_write, NULL); - if (rc != 0) { - ESP_LOGE(tag, "Error: Failed to write characteristic; rc=%d\n", - rc); - goto err; + label: + rc = ble_gattc_write_no_rsp_flat(conn_handle, val_handle, &value, sizeof value); + + if(rc == BLE_HS_ENOMEM) { + vTaskDelay(2); /* Wait for buffers to free up and try again */ + goto label; + } + else if (rc != 0) { + ESP_LOGE(tag, "Error: Failed to write characteristic; rc=%d\n",rc); + goto err; } end_time = esp_timer_get_time(); @@ -311,8 +281,7 @@ static void throughput_task(void *arg) } if (test_data[1] > 0) { - rc = blecent_write(peer->conn_handle, chr->chr.val_handle, - blecent_repeat_write, (void *) peer, test_data[1]); + rc = blecent_write(peer->conn_handle, chr->chr.val_handle, (void *) peer, test_data[1]); if (rc != 0) { ESP_LOGE(tag, "Error while writing data; rc = %d", rc); } diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/misc.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/misc.c index 943638b3db..b7d6997c73 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/misc.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/misc.c @@ -1,20 +1,7 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/peer.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/peer.c index b06435d8a2..e7e655cd1f 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/peer.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/peer.c @@ -1,20 +1,7 @@ /* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/scli.c b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/scli.c index 4cd00cea8a..3e03db1f7b 100644 --- a/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/scli.c +++ b/examples/bluetooth/nimble/throughput_app/blecent_throughput/main/scli.c @@ -1,22 +1,7 @@ /* - * Copyright 2020 Espressif Systems (Shanghai) PTE LTD + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatt_svr.c b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatt_svr.c index ce0f43f311..4a0059c5e6 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatt_svr.c +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatt_svr.c @@ -1,22 +1,7 @@ /* - * Copyright 2020-2021 Espressif Systems (Shanghai) PTE LTD + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatts_sens.h b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatts_sens.h index bc52837d39..1313c12156 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatts_sens.h +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/gatts_sens.h @@ -1,22 +1,7 @@ /* - * Copyright 2020-21 Espressif Systems (Shanghai) PTE LTD + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #ifndef H_GATTS_SENS_ diff --git a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c index f53e84d363..94a79c8526 100644 --- a/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c +++ b/examples/bluetooth/nimble/throughput_app/bleprph_throughput/main/main.c @@ -1,22 +1,7 @@ /* - * Copyright 2020 Espressif Systems (Shanghai) PTE LTD + * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. + * SPDX-License-Identifier: Apache-2.0 */ #include "esp_log.h"