autoformatting
This commit is contained in:
@ -25,11 +25,13 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
.pref_tx_phy = BT_GAP_LE_PHY_1M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
@ -40,11 +42,13 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_NONE,
|
.options = BT_CONN_LE_PHY_OPT_NONE,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
.pref_tx_phy = BT_GAP_LE_PHY_2M,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
@ -55,11 +59,13 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S8,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
@ -70,11 +76,13 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
.pref_rx_phy = BT_GAP_LE_PHY_1M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
.pref_rx_phy = BT_GAP_LE_PHY_2M,
|
||||||
}, {
|
},
|
||||||
|
{
|
||||||
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
.options = BT_CONN_LE_PHY_OPT_CODED_S2,
|
||||||
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_tx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
.pref_rx_phy = BT_GAP_LE_PHY_CODED,
|
||||||
@ -89,14 +97,16 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
};
|
};
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
if (phy_update_countdown--) {
|
if (phy_update_countdown--)
|
||||||
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
phy_update_countdown = PHY_UPDATE_COUNTDOWN;
|
phy_update_countdown = PHY_UPDATE_COUNTDOWN;
|
||||||
|
|
||||||
phy_param_idx++;
|
phy_param_idx++;
|
||||||
if (phy_param_idx >= ARRAY_SIZE(phy_param)) {
|
if (phy_param_idx >= ARRAY_SIZE(phy_param))
|
||||||
|
{
|
||||||
/* No more PHY updates, stay at the last index */
|
/* No more PHY updates, stay at the last index */
|
||||||
phy_param_idx = ARRAY_SIZE(phy_param);
|
phy_param_idx = ARRAY_SIZE(phy_param);
|
||||||
return;
|
return;
|
||||||
@ -105,18 +115,22 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
struct bt_conn_info conn_info;
|
struct bt_conn_info conn_info;
|
||||||
|
|
||||||
err = bt_conn_get_info(conn, &conn_info);
|
err = bt_conn_get_info(conn, &conn_info);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("Failed to get connection info (%d).\n", err);
|
printk("Failed to get connection info (%d).\n", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct bt_conn_le_phy_param conn_phy_param;
|
struct bt_conn_le_phy_param conn_phy_param;
|
||||||
|
|
||||||
if (conn_info.role == BT_CONN_ROLE_CENTRAL) {
|
if (conn_info.role == BT_CONN_ROLE_CENTRAL)
|
||||||
|
{
|
||||||
conn_phy_param.options = phy_param[phy_param_idx].options;
|
conn_phy_param.options = phy_param[phy_param_idx].options;
|
||||||
conn_phy_param.pref_tx_phy = phy_param[phy_param_idx].pref_tx_phy;
|
conn_phy_param.pref_tx_phy = phy_param[phy_param_idx].pref_tx_phy;
|
||||||
conn_phy_param.pref_rx_phy = phy_param[phy_param_idx].pref_rx_phy;
|
conn_phy_param.pref_rx_phy = phy_param[phy_param_idx].pref_rx_phy;
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
conn_phy_param.options = phy_param[phy_param_idx].options;
|
conn_phy_param.options = phy_param[phy_param_idx].options;
|
||||||
conn_phy_param.pref_tx_phy = phy_param[phy_param_idx].pref_rx_phy;
|
conn_phy_param.pref_tx_phy = phy_param[phy_param_idx].pref_rx_phy;
|
||||||
conn_phy_param.pref_rx_phy = phy_param[phy_param_idx].pref_tx_phy;
|
conn_phy_param.pref_rx_phy = phy_param[phy_param_idx].pref_tx_phy;
|
||||||
@ -128,7 +142,8 @@ static void phy_update_iterate(struct bt_conn *conn)
|
|||||||
conn_phy_param.options);
|
conn_phy_param.options);
|
||||||
|
|
||||||
err = bt_conn_le_phy_update(conn, &conn_phy_param);
|
err = bt_conn_le_phy_update(conn, &conn_phy_param);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("Failed to update PHY (%d).\n", err);
|
printk("Failed to update PHY (%d).\n", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -155,7 +170,8 @@ static void write_cmd_cb(struct bt_conn *conn, void *user_data)
|
|||||||
delta = k_cycle_get_32() - cycle_stamp;
|
delta = k_cycle_get_32() - cycle_stamp;
|
||||||
delta = k_cyc_to_ns_floor64(delta);
|
delta = k_cyc_to_ns_floor64(delta);
|
||||||
|
|
||||||
if (delta == 0) {
|
if (delta == 0)
|
||||||
|
{
|
||||||
/* Skip division by zero */
|
/* Skip division by zero */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -163,7 +179,8 @@ static void write_cmd_cb(struct bt_conn *conn, void *user_data)
|
|||||||
/* if last data rx-ed was greater than 1 second in the past,
|
/* if last data rx-ed was greater than 1 second in the past,
|
||||||
* reset the metrics.
|
* reset the metrics.
|
||||||
*/
|
*/
|
||||||
if (delta > (METRICS_INTERVAL * NSEC_PER_SEC)) {
|
if (delta > (METRICS_INTERVAL * NSEC_PER_SEC))
|
||||||
|
{
|
||||||
printk("%s: count= %u, len= %u, rate= %u bps.\n", __func__,
|
printk("%s: count= %u, len= %u, rate= %u bps.\n", __func__,
|
||||||
write_count, write_len, write_rate);
|
write_count, write_len, write_rate);
|
||||||
|
|
||||||
@ -174,11 +191,13 @@ static void write_cmd_cb(struct bt_conn *conn, void *user_data)
|
|||||||
write_rate = 0U;
|
write_rate = 0U;
|
||||||
cycle_stamp = k_cycle_get_32();
|
cycle_stamp = k_cycle_get_32();
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BT_USER_PHY_UPDATE)) {
|
if (IS_ENABLED(CONFIG_BT_USER_PHY_UPDATE))
|
||||||
|
{
|
||||||
phy_update_iterate(conn);
|
phy_update_iterate(conn);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
uint16_t len;
|
uint16_t len;
|
||||||
|
|
||||||
write_count++;
|
write_count++;
|
||||||
@ -210,7 +229,8 @@ static int mtu_exchange(struct bt_conn *conn)
|
|||||||
|
|
||||||
printk("%s: Exchange MTU...\n", __func__);
|
printk("%s: Exchange MTU...\n", __func__);
|
||||||
err = bt_gatt_exchange_mtu(conn, &mtu_exchange_params);
|
err = bt_gatt_exchange_mtu(conn, &mtu_exchange_params);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("%s: MTU exchange failed (err %d)", __func__, err);
|
printk("%s: MTU exchange failed (err %d)", __func__, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -225,14 +245,16 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
|
|||||||
|
|
||||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||||
|
|
||||||
if (conn_err) {
|
if (conn_err)
|
||||||
|
{
|
||||||
printk("%s: Failed to connect to %s (%u)\n", __func__, addr,
|
printk("%s: Failed to connect to %s (%u)\n", __func__, addr,
|
||||||
conn_err);
|
conn_err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
err = bt_conn_get_info(conn, &conn_info);
|
err = bt_conn_get_info(conn, &conn_info);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("Failed to get connection info (%d).\n", err);
|
printk("Failed to get connection info (%d).\n", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -244,15 +266,18 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
|
|||||||
(void)mtu_exchange(conn);
|
(void)mtu_exchange(conn);
|
||||||
|
|
||||||
#if defined(CONFIG_BT_SMP)
|
#if defined(CONFIG_BT_SMP)
|
||||||
if (conn_info.role == BT_CONN_ROLE_CENTRAL) {
|
if (conn_info.role == BT_CONN_ROLE_CENTRAL)
|
||||||
|
{
|
||||||
err = bt_conn_set_security(conn, BT_SECURITY_L2);
|
err = bt_conn_set_security(conn, BT_SECURITY_L2);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("Failed to set security (%d).\n", err);
|
printk("Failed to set security (%d).\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (IS_ENABLED(CONFIG_BT_USER_PHY_UPDATE)) {
|
if (IS_ENABLED(CONFIG_BT_USER_PHY_UPDATE))
|
||||||
|
{
|
||||||
phy_update_countdown = PHY_UPDATE_COUNTDOWN;
|
phy_update_countdown = PHY_UPDATE_COUNTDOWN;
|
||||||
phy_param_idx = 0U;
|
phy_param_idx = 0U;
|
||||||
}
|
}
|
||||||
@ -267,7 +292,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||||||
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
bt_addr_le_to_str(bt_conn_get_dst(conn), addr, sizeof(addr));
|
||||||
|
|
||||||
err = bt_conn_get_info(conn, &conn_info);
|
err = bt_conn_get_info(conn, &conn_info);
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("Failed to get connection info (%d).\n", err);
|
printk("Failed to get connection info (%d).\n", err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -279,7 +305,8 @@ static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|||||||
|
|
||||||
bt_conn_unref(conn);
|
bt_conn_unref(conn);
|
||||||
|
|
||||||
if (conn_info.role == BT_CONN_ROLE_CENTRAL) {
|
if (conn_info.role == BT_CONN_ROLE_CENTRAL)
|
||||||
|
{
|
||||||
start_scan_func();
|
start_scan_func();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -356,13 +383,16 @@ BT_CONN_CB_DEFINE(conn_callbacks) = {
|
|||||||
|
|
||||||
int write_cmd(struct bt_conn *conn)
|
int write_cmd(struct bt_conn *conn)
|
||||||
{
|
{
|
||||||
static uint8_t data[BT_ATT_MAX_ATTRIBUTE_LEN] = {0, };
|
static uint8_t data[BT_ATT_MAX_ATTRIBUTE_LEN] = {
|
||||||
|
0,
|
||||||
|
};
|
||||||
static uint16_t data_len;
|
static uint16_t data_len;
|
||||||
uint16_t data_len_max;
|
uint16_t data_len_max;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
data_len_max = bt_gatt_get_mtu(conn) - 3;
|
data_len_max = bt_gatt_get_mtu(conn) - 3;
|
||||||
if (data_len_max > BT_ATT_MAX_ATTRIBUTE_LEN) {
|
if (data_len_max > BT_ATT_MAX_ATTRIBUTE_LEN)
|
||||||
|
{
|
||||||
data_len_max = BT_ATT_MAX_ATTRIBUTE_LEN;
|
data_len_max = BT_ATT_MAX_ATTRIBUTE_LEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -371,15 +401,20 @@ int write_cmd(struct bt_conn *conn)
|
|||||||
/* TODO: Include test case in BabbleSim tests */
|
/* TODO: Include test case in BabbleSim tests */
|
||||||
static bool decrement;
|
static bool decrement;
|
||||||
|
|
||||||
if (decrement) {
|
if (decrement)
|
||||||
|
{
|
||||||
data_len--;
|
data_len--;
|
||||||
if (data_len <= 1) {
|
if (data_len <= 1)
|
||||||
|
{
|
||||||
data_len = 1;
|
data_len = 1;
|
||||||
decrement = false;
|
decrement = false;
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
data_len++;
|
data_len++;
|
||||||
if (data_len >= data_len_max) {
|
if (data_len >= data_len_max)
|
||||||
|
{
|
||||||
data_len = data_len_max;
|
data_len = data_len_max;
|
||||||
decrement = true;
|
decrement = true;
|
||||||
}
|
}
|
||||||
@ -397,7 +432,8 @@ int write_cmd(struct bt_conn *conn)
|
|||||||
err = bt_gatt_write_without_response_cb(conn, 0x0001, data, data_len,
|
err = bt_gatt_write_without_response_cb(conn, 0x0001, data, data_len,
|
||||||
false, write_cmd_cb,
|
false, write_cmd_cb,
|
||||||
(void *)((uint32_t)data_len));
|
(void *)((uint32_t)data_len));
|
||||||
if (err) {
|
if (err)
|
||||||
|
{
|
||||||
printk("%s: Write cmd failed (%d).\n", __func__, err);
|
printk("%s: Write cmd failed (%d).\n", __func__, err);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user