-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve central_uart sample application #12537
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,36 @@ | ||||||
# | ||||||
# Copyright (c) 2023 Nordic Semiconductor | ||||||
# | ||||||
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause | ||||||
# | ||||||
|
||||||
source "Kconfig.zephyr" | ||||||
|
||||||
menu "Nordic UART Service Client sample" | ||||||
|
||||||
config BT_NUS_UART_BUFFER_SIZE | ||||||
int "UART payload buffer element size" | ||||||
default 20 | ||||||
help | ||||||
Size of the payload buffer in each RX and TX FIFO element | ||||||
|
||||||
config BT_NUS_SECURITY_ENABLED | ||||||
bool "Enable security" | ||||||
default y | ||||||
select BT_SMP | ||||||
help | ||||||
"Enable BLE security for the UART service client" | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add dot an every help line end
Suggested change
|
||||||
|
||||||
config BT_NUS_UART_RX_WAIT_TIME | ||||||
int "Timeout for UART RX complete event" | ||||||
default 50000 | ||||||
help | ||||||
Wait for RX complete event time in microseconds | ||||||
|
||||||
config BT_NUS_WRITE_TIMEOUT | ||||||
int "Timeout for NUS write complete event" | ||||||
default 150 | ||||||
help | ||||||
Wait for NUS write complete event time in milliseconds | ||||||
|
||||||
endmenu |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -36,14 +36,14 @@ | |||||
LOG_MODULE_REGISTER(LOG_MODULE_NAME); | ||||||
|
||||||
/* UART payload buffer element size. */ | ||||||
#define UART_BUF_SIZE 20 | ||||||
#define UART_BUF_SIZE CONFIG_BT_NUS_UART_BUFFER_SIZE | ||||||
|
||||||
#define KEY_PASSKEY_ACCEPT DK_BTN1_MSK | ||||||
#define KEY_PASSKEY_REJECT DK_BTN2_MSK | ||||||
|
||||||
#define NUS_WRITE_TIMEOUT K_MSEC(150) | ||||||
#define NUS_WRITE_TIMEOUT K_MSEC(CONFIG_BT_NUS_WRITE_TIMEOUT) | ||||||
#define UART_WAIT_FOR_BUF_DELAY K_MSEC(50) | ||||||
#define UART_RX_TIMEOUT 50 | ||||||
#define UART_RX_TIMEOUT CONFIG_BT_NUS_UART_RX_WAIT_TIME | ||||||
|
||||||
static const struct device *uart = DEVICE_DT_GET(DT_NODELABEL(uart0)); | ||||||
static struct k_work_delayable uart_work; | ||||||
|
@@ -384,12 +384,16 @@ static void connected(struct bt_conn *conn, uint8_t conn_err) | |||||
LOG_WRN("MTU exchange failed (err %d)", err); | ||||||
} | ||||||
|
||||||
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use here IS_ENABLED macro instead of conditional compilation
Suggested change
|
||||||
err = bt_conn_set_security(conn, BT_SECURITY_L2); | ||||||
if (err) { | ||||||
LOG_WRN("Failed to set security: %d", err); | ||||||
|
||||||
gatt_discover(conn); | ||||||
} | ||||||
#else | ||||||
gatt_discover(conn); | ||||||
#endif | ||||||
|
||||||
err = bt_scan_stop(); | ||||||
if ((!err) && (err != -EALREADY)) { | ||||||
|
@@ -420,6 +424,7 @@ static void disconnected(struct bt_conn *conn, uint8_t reason) | |||||
} | ||||||
} | ||||||
|
||||||
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED | ||||||
static void security_changed(struct bt_conn *conn, bt_security_t level, | ||||||
enum bt_security_err err) | ||||||
{ | ||||||
|
@@ -436,11 +441,14 @@ static void security_changed(struct bt_conn *conn, bt_security_t level, | |||||
|
||||||
gatt_discover(conn); | ||||||
} | ||||||
#endif | ||||||
|
||||||
BT_CONN_CB_DEFINE(conn_callbacks) = { | ||||||
.connected = connected, | ||||||
.disconnected = disconnected, | ||||||
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED | ||||||
.security_changed = security_changed | ||||||
#endif | ||||||
}; | ||||||
|
||||||
static void scan_filter_match(struct bt_scan_device_info *device_info, | ||||||
|
@@ -515,7 +523,7 @@ static int scan_init(void) | |||||
return err; | ||||||
} | ||||||
|
||||||
|
||||||
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED | ||||||
static void auth_cancel(struct bt_conn *conn) | ||||||
{ | ||||||
char addr[BT_ADDR_LE_STR_LEN]; | ||||||
|
@@ -553,11 +561,13 @@ static struct bt_conn_auth_info_cb conn_auth_info_callbacks = { | |||||
.pairing_complete = pairing_complete, | ||||||
.pairing_failed = pairing_failed | ||||||
}; | ||||||
#endif | ||||||
|
||||||
int main(void) | ||||||
{ | ||||||
int err; | ||||||
|
||||||
#ifdef CONFIG_BT_NUS_SECURITY_ENABLED | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please try to use IS_ENABLED macro like it is done in the peripheral_uart sample |
||||||
err = bt_conn_auth_cb_register(&conn_auth_callbacks); | ||||||
if (err) { | ||||||
LOG_ERR("Failed to register authorization callbacks."); | ||||||
|
@@ -569,6 +579,7 @@ int main(void) | |||||
printk("Failed to register authorization info callbacks.\n"); | ||||||
return 0; | ||||||
} | ||||||
#endif | ||||||
|
||||||
err = bt_enable(NULL); | ||||||
if (err) { | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe BT_NUS_C_.... since this is about client side