Skip to content

Commit 57ce743

Browse files
eriksandgrenhermabe
authored andcommitted
samples: bluetooth: Add logging of CS config
The CS config that is being used is important information and can be useful for debugging. The configuration will be logged once, when it is created. Signed-off-by: Erik Sandgren <[email protected]>
1 parent 18a61da commit 57ce743

File tree

2 files changed

+113
-8
lines changed
  • samples/bluetooth
    • channel_sounding_ras_initiator/src
    • channel_sounding_ras_reflector/src

2 files changed

+113
-8
lines changed

samples/bluetooth/channel_sounding_ras_initiator/src/main.c

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <stdlib.h>
1313
#include <zephyr/kernel.h>
1414
#include <zephyr/types.h>
15+
#include <zephyr/sys/byteorder.h>
1516
#include <zephyr/sys/reboot.h>
1617
#include <zephyr/bluetooth/cs.h>
1718
#include <zephyr/bluetooth/gatt.h>
@@ -396,15 +397,67 @@ static void remote_capabilities_cb(struct bt_conn *conn,
396397
}
397398
}
398399

399-
static void config_create_cb(struct bt_conn *conn,
400-
uint8_t status,
400+
static void config_create_cb(struct bt_conn *conn, uint8_t status,
401401
struct bt_conn_le_cs_config *config)
402402
{
403403
ARG_UNUSED(conn);
404404

405405
if (status == BT_HCI_ERR_SUCCESS) {
406406
cs_config = *config;
407-
LOG_INF("CS config creation complete. ID: %d", config->id);
407+
408+
const char *mode_str[5] = {"Unused", "1 (RTT)", "2 (PBR)", "3 (RTT + PBR)",
409+
"Invalid"};
410+
const char *role_str[3] = {"Initiator", "Reflector", "Invalid"};
411+
const char *rtt_type_str[8] = {
412+
"AA only", "32-bit sounding", "96-bit sounding", "32-bit random",
413+
"64-bit random", "96-bit random", "128-bit random", "Invalid"};
414+
const char *phy_str[4] = {"Invalid", "LE 1M PHY", "LE 2M PHY", "LE 2M 2BT PHY"};
415+
const char *chsel_type_str[3] = {"Algorithm #3b", "Algorithm #3c", "Invalid"};
416+
const char *ch3c_shape_str[3] = {"Hat shape", "X shape", "Invalid"};
417+
418+
uint8_t main_mode_idx = config->main_mode_type > 0 && config->main_mode_type < 4
419+
? config->main_mode_type
420+
: 4;
421+
uint8_t sub_mode_idx = config->sub_mode_type < 4 ? config->sub_mode_type : 0;
422+
uint8_t role_idx = MIN(config->role, 2);
423+
uint8_t rtt_type_idx = MIN(config->rtt_type, 7);
424+
uint8_t phy_idx = config->cs_sync_phy > 0 && config->cs_sync_phy < 4
425+
? config->cs_sync_phy
426+
: 0;
427+
uint8_t chsel_type_idx = MIN(config->channel_selection_type, 2);
428+
uint8_t ch3c_shape_idx = MIN(config->ch3c_shape, 2);
429+
430+
LOG_INF("CS config creation complete.\n"
431+
" - id: %u\n"
432+
" - main_mode_type: %s\n"
433+
" - sub_mode_type: %s\n"
434+
" - min_main_mode_steps: %u\n"
435+
" - max_main_mode_steps: %u\n"
436+
" - main_mode_repetition: %u\n"
437+
" - mode_0_steps: %u\n"
438+
" - role: %s\n"
439+
" - rtt_type: %s\n"
440+
" - cs_sync_phy: %s\n"
441+
" - channel_map_repetition: %u\n"
442+
" - channel_selection_type: %s\n"
443+
" - ch3c_shape: %s\n"
444+
" - ch3c_jump: %u\n"
445+
" - t_ip1_time_us: %u\n"
446+
" - t_ip2_time_us: %u\n"
447+
" - t_fcs_time_us: %u\n"
448+
" - t_pm_time_us: %u\n"
449+
" - channel_map: 0x%08X%08X%04X\n",
450+
config->id, mode_str[main_mode_idx], mode_str[sub_mode_idx],
451+
config->min_main_mode_steps, config->max_main_mode_steps,
452+
config->main_mode_repetition, config->mode_0_steps, role_str[role_idx],
453+
rtt_type_str[rtt_type_idx], phy_str[phy_idx],
454+
config->channel_map_repetition, chsel_type_str[chsel_type_idx],
455+
ch3c_shape_str[ch3c_shape_idx], config->ch3c_jump, config->t_ip1_time_us,
456+
config->t_ip2_time_us, config->t_fcs_time_us, config->t_pm_time_us,
457+
sys_get_le32(&config->channel_map[6]),
458+
sys_get_le32(&config->channel_map[2]),
459+
sys_get_le16(&config->channel_map[0]));
460+
408461
k_sem_give(&sem_config_created);
409462
} else {
410463
LOG_WRN("CS config creation failed. (HCI status 0x%02x)", status);
@@ -731,8 +784,8 @@ int main(void)
731784
ap, (double)distance_on_ap.ifft,
732785
(double)distance_on_ap.phase_slope,
733786
(double)distance_on_ap.rtt);
734-
}
735787
}
788+
}
736789
}
737790

738791
return 0;

samples/bluetooth/channel_sounding_ras_reflector/src/main.c

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <zephyr/types.h>
1212
#include <zephyr/kernel.h>
1313
#include <zephyr/bluetooth/bluetooth.h>
14+
#include <zephyr/sys/byteorder.h>
1415
#include <zephyr/sys/reboot.h>
1516
#include <zephyr/bluetooth/conn.h>
1617
#include <zephyr/bluetooth/uuid.h>
@@ -80,14 +81,65 @@ static void remote_capabilities_cb(struct bt_conn *conn,
8081
}
8182
}
8283

83-
static void config_create_cb(struct bt_conn *conn,
84-
uint8_t status,
85-
struct bt_conn_le_cs_config *config)
84+
static void config_create_cb(struct bt_conn *conn, uint8_t status,
85+
struct bt_conn_le_cs_config *config)
8686
{
8787
ARG_UNUSED(conn);
8888

8989
if (status == BT_HCI_ERR_SUCCESS) {
90-
LOG_INF("CS config creation complete. ID: %d", config->id);
90+
const char *mode_str[5] = {"Unused", "1 (RTT)", "2 (PBR)", "3 (RTT + PBR)",
91+
"Invalid"};
92+
const char *role_str[3] = {"Initiator", "Reflector", "Invalid"};
93+
const char *rtt_type_str[8] = {
94+
"AA only", "32-bit sounding", "96-bit sounding", "32-bit random",
95+
"64-bit random", "96-bit random", "128-bit random", "Invalid"};
96+
const char *phy_str[4] = {"Invalid", "LE 1M PHY", "LE 2M PHY", "LE 2M 2BT PHY"};
97+
const char *chsel_type_str[3] = {"Algorithm #3b", "Algorithm #3c", "Invalid"};
98+
const char *ch3c_shape_str[3] = {"Hat shape", "X shape", "Invalid"};
99+
100+
uint8_t main_mode_idx = config->main_mode_type > 0 && config->main_mode_type < 4
101+
? config->main_mode_type
102+
: 4;
103+
uint8_t sub_mode_idx = config->sub_mode_type < 4 ? config->sub_mode_type : 0;
104+
uint8_t role_idx = MIN(config->role, 2);
105+
uint8_t rtt_type_idx = MIN(config->rtt_type, 7);
106+
uint8_t phy_idx = config->cs_sync_phy > 0 && config->cs_sync_phy < 4
107+
? config->cs_sync_phy
108+
: 0;
109+
uint8_t chsel_type_idx = MIN(config->channel_selection_type, 2);
110+
uint8_t ch3c_shape_idx = MIN(config->ch3c_shape, 2);
111+
112+
LOG_INF("CS config creation complete.\n"
113+
" - id: %u\n"
114+
" - main_mode_type: %s\n"
115+
" - sub_mode_type: %s\n"
116+
" - min_main_mode_steps: %u\n"
117+
" - max_main_mode_steps: %u\n"
118+
" - main_mode_repetition: %u\n"
119+
" - mode_0_steps: %u\n"
120+
" - role: %s\n"
121+
" - rtt_type: %s\n"
122+
" - cs_sync_phy: %s\n"
123+
" - channel_map_repetition: %u\n"
124+
" - channel_selection_type: %s\n"
125+
" - ch3c_shape: %s\n"
126+
" - ch3c_jump: %u\n"
127+
" - t_ip1_time_us: %u\n"
128+
" - t_ip2_time_us: %u\n"
129+
" - t_fcs_time_us: %u\n"
130+
" - t_pm_time_us: %u\n"
131+
" - channel_map: 0x%08X%08X%04X\n",
132+
config->id, mode_str[main_mode_idx], mode_str[sub_mode_idx],
133+
config->min_main_mode_steps, config->max_main_mode_steps,
134+
config->main_mode_repetition, config->mode_0_steps, role_str[role_idx],
135+
rtt_type_str[rtt_type_idx], phy_str[phy_idx],
136+
config->channel_map_repetition, chsel_type_str[chsel_type_idx],
137+
ch3c_shape_str[ch3c_shape_idx], config->ch3c_jump, config->t_ip1_time_us,
138+
config->t_ip2_time_us, config->t_fcs_time_us, config->t_pm_time_us,
139+
sys_get_le32(&config->channel_map[6]),
140+
sys_get_le32(&config->channel_map[2]),
141+
sys_get_le16(&config->channel_map[0]));
142+
91143
k_sem_give(&sem_config);
92144
} else {
93145
LOG_WRN("CS config creation failed. (HCI status 0x%02x)", status);

0 commit comments

Comments
 (0)