1 /*
2  * Copyright (c) 2021 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <ctype.h>
8 
9 #include <zephyr/console/console.h>
10 #include <zephyr/bluetooth/bluetooth.h>
11 #include <zephyr/bluetooth/iso.h>
12 
13 #include "common.h"
14 
15 #include <zephyr/logging/log.h>
16 LOG_MODULE_REGISTER(iso_broadcast_main, LOG_LEVEL_DBG);
17 
18 enum benchmark_role {
19 	ROLE_RECEIVER,
20 	ROLE_BROADCASTER,
21 	ROLE_QUIT
22 };
23 
device_role_select(void)24 static enum benchmark_role device_role_select(void)
25 {
26 	char role;
27 
28 	while (true) {
29 		printk("Choose device role - type r (receiver role) or b "
30 		       "(broadcaster role), or q to quit: ");
31 
32 		role = tolower(console_getchar());
33 
34 		printk("%c\n", role);
35 
36 		if (role == 'r') {
37 			printk("Receiver role\n");
38 			return ROLE_RECEIVER;
39 		} else if (role == 'b') {
40 			printk("Broadcaster role\n");
41 			return ROLE_BROADCASTER;
42 		} else if (role == 'q') {
43 			printk("Quitting\n");
44 			return ROLE_QUIT;
45 		} else if (role == '\n') {
46 			continue;
47 		}
48 
49 		printk("Invalid role: %c\n", role);
50 	}
51 }
52 
main(void)53 int main(void)
54 {
55 	int err;
56 	enum benchmark_role role;
57 
58 	LOG_INF("Starting Bluetooth Throughput example");
59 
60 	err = bt_enable(NULL);
61 	if (err != 0) {
62 		LOG_INF("Bluetooth init failed (err %d)", err);
63 		return 0;
64 	}
65 
66 	err = console_init();
67 	if (err != 0) {
68 		LOG_INF("Console init failed (err %d)", err);
69 		return 0;
70 	}
71 
72 	LOG_INF("Bluetooth initialized");
73 
74 
75 	while (true) {
76 		role = device_role_select();
77 
78 		if (role == ROLE_RECEIVER) {
79 			err = test_run_receiver();
80 		} else if (role == ROLE_BROADCASTER) {
81 			err = test_run_broadcaster();
82 		} else {
83 			if (role != ROLE_QUIT) {
84 				LOG_INF("Invalid role %u", role);
85 				continue;
86 			} else {
87 				err = 0;
88 				break;
89 			}
90 		}
91 
92 		LOG_INF("Test complete %d", err);
93 	}
94 
95 	LOG_INF("Exiting");
96 	return 0;
97 }
98