1 /**
2  * @file
3  * @brief Shell APIs for Bluetooth IAS
4  *
5  * Copyright (c) 2022 Codecoup
6  *
7  * SPDX-License-Identifier: Apache-2.0
8  */
9 
10 #include <stdlib.h>
11 #include <zephyr/types.h>
12 #include <zephyr/bluetooth/conn.h>
13 
14 #include <zephyr/types.h>
15 #include <zephyr/shell/shell.h>
16 #include <zephyr/bluetooth/gatt.h>
17 #include <zephyr/bluetooth/bluetooth.h>
18 #include <zephyr/bluetooth/services/ias.h>
19 
20 #include "host/shell/bt.h"
21 
22 extern const struct shell *ctx_shell;
23 
alert_stop(void)24 static void alert_stop(void)
25 {
26 	shell_print(ctx_shell, "Alert stopped\n");
27 }
28 
alert_start(void)29 static void alert_start(void)
30 {
31 	shell_print(ctx_shell, "Mild alert started\n");
32 }
33 
alert_high_start(void)34 static void alert_high_start(void)
35 {
36 	shell_print(ctx_shell, "High alert started\n");
37 }
38 
39 BT_IAS_CB_DEFINE(ias_callbacks) = {
40 	.no_alert = alert_stop,
41 	.mild_alert = alert_start,
42 	.high_alert = alert_high_start,
43 };
44 
cmd_ias_local_alert_stop(const struct shell * sh,size_t argc,char ** argv)45 static int cmd_ias_local_alert_stop(const struct shell *sh, size_t argc, char **argv)
46 {
47 	const int result = bt_ias_local_alert_stop();
48 
49 	if (result) {
50 		shell_print(sh, "Local alert stop failed: %d", result);
51 	} else {
52 		shell_print(sh, "Local alert stopped");
53 	}
54 
55 	return result;
56 }
57 
cmd_ias(const struct shell * sh,size_t argc,char ** argv)58 static int cmd_ias(const struct shell *sh, size_t argc, char **argv)
59 {
60 	shell_error(sh, "%s unknown parameter: %s", argv[0], argv[1]);
61 
62 	return -ENOEXEC;
63 }
64 
65 SHELL_STATIC_SUBCMD_SET_CREATE(ias_cmds,
66 	SHELL_CMD_ARG(local_alert_stop, NULL,
67 		      "Stop alert locally",
68 		      cmd_ias_local_alert_stop, 1, 0),
69 	SHELL_SUBCMD_SET_END
70 );
71 
72 SHELL_CMD_ARG_REGISTER(ias, &ias_cmds, "Bluetooth IAS shell commands",
73 		       cmd_ias, 1, 1);
74