|
17 | 17 | static uint32_t phy_update_countdown;
|
18 | 18 | static uint8_t phy_param_idx;
|
19 | 19 |
|
| 20 | +/* Count down number of metrics intervals before performing a param update */ |
| 21 | +#define PARAM_UPDATE_COUNTDOWN PHY_UPDATE_COUNTDOWN |
| 22 | +static uint32_t param_update_countdown; |
| 23 | + |
20 | 24 | static void phy_update_iterate(struct bt_conn *conn)
|
21 | 25 | {
|
22 | 26 | const struct bt_conn_le_phy_param phy_param[] = {
|
@@ -178,6 +182,34 @@ static void write_cmd_cb(struct bt_conn *conn, void *user_data)
|
178 | 182 | phy_update_iterate(conn);
|
179 | 183 | }
|
180 | 184 |
|
| 185 | + const struct bt_le_conn_param update_params[2] = {{ |
| 186 | + .interval_min = 0x0029, |
| 187 | + .interval_max = 0x0029, |
| 188 | + .latency = 0, |
| 189 | + .timeout = 31, |
| 190 | + }, { |
| 191 | + .interval_min = 0x0028, |
| 192 | + .interval_max = 0x0028, |
| 193 | + .latency = 0, |
| 194 | + .timeout = 30, |
| 195 | + }, |
| 196 | + }; |
| 197 | + static uint8_t param_update_count; |
| 198 | + int err; |
| 199 | + |
| 200 | + if ((param_update_countdown--) != 0U) { |
| 201 | + return; |
| 202 | + } |
| 203 | + |
| 204 | + param_update_countdown = PARAM_UPDATE_COUNTDOWN; |
| 205 | + |
| 206 | + err = bt_conn_le_param_update(conn, &update_params[param_update_count & 0x1]); |
| 207 | + if (err != 0) { |
| 208 | + printk("Parameter update failed (err %d)\n", err); |
| 209 | + } |
| 210 | + |
| 211 | + param_update_count++; |
| 212 | + |
181 | 213 | } else {
|
182 | 214 | uint16_t len;
|
183 | 215 |
|
@@ -256,6 +288,14 @@ static void connected(struct bt_conn *conn, uint8_t conn_err)
|
256 | 288 | phy_update_countdown = PHY_UPDATE_COUNTDOWN;
|
257 | 289 | phy_param_idx = 0U;
|
258 | 290 | }
|
| 291 | + |
| 292 | + /* Every 1 second the acknowledged total GATT Write without Response data size is used for |
| 293 | + * the throughput calculation. |
| 294 | + * PHY update is performed in reference to this calculation interval, and connection update |
| 295 | + * is offset by 1 of this interval so that connection update is initiated one such interval |
| 296 | + * after PHY update was requested. |
| 297 | + */ |
| 298 | + param_update_countdown = PARAM_UPDATE_COUNTDOWN + 1U; |
259 | 299 | }
|
260 | 300 |
|
261 | 301 | static void disconnected(struct bt_conn *conn, uint8_t reason)
|
|
0 commit comments