24
24
#include <shell/shell.h>
25
25
26
26
#include "bt.h"
27
- #include "gatt.h"
28
27
29
28
#define CHAR_SIZE_MAX 512
30
29
@@ -37,7 +36,8 @@ static void exchange_func(struct bt_conn *conn, u8_t err,
37
36
38
37
static struct bt_gatt_exchange_params exchange_params ;
39
38
40
- void cmd_gatt_exchange_mtu (const struct shell * shell , size_t argc , char * argv [])
39
+ static void cmd_exchange_mtu (const struct shell * shell ,
40
+ size_t argc , char * argv [])
41
41
{
42
42
int err ;
43
43
@@ -146,7 +146,7 @@ static u8_t discover_func(struct bt_conn *conn,
146
146
return BT_GATT_ITER_CONTINUE ;
147
147
}
148
148
149
- void cmd_gatt_discover (const struct shell * shell , size_t argc , char * argv [])
149
+ static void cmd_discover (const struct shell * shell , size_t argc , char * argv [])
150
150
{
151
151
int err ;
152
152
@@ -174,13 +174,13 @@ void cmd_gatt_discover(const struct shell *shell, size_t argc, char *argv[])
174
174
}
175
175
}
176
176
177
- if (!strcmp (argv [0 ], "gatt- discover-secondary" )) {
177
+ if (!strcmp (argv [0 ], "discover-secondary" )) {
178
178
discover_params .type = BT_GATT_DISCOVER_SECONDARY ;
179
- } else if (!strcmp (argv [0 ], "gatt- discover-include" )) {
179
+ } else if (!strcmp (argv [0 ], "discover-include" )) {
180
180
discover_params .type = BT_GATT_DISCOVER_INCLUDE ;
181
- } else if (!strcmp (argv [0 ], "gatt- discover-characteristic" )) {
181
+ } else if (!strcmp (argv [0 ], "discover-characteristic" )) {
182
182
discover_params .type = BT_GATT_DISCOVER_CHARACTERISTIC ;
183
- } else if (!strcmp (argv [0 ], "gatt- discover-descriptor" )) {
183
+ } else if (!strcmp (argv [0 ], "discover-descriptor" )) {
184
184
discover_params .type = BT_GATT_DISCOVER_DESCRIPTOR ;
185
185
} else {
186
186
discover_params .type = BT_GATT_DISCOVER_PRIMARY ;
@@ -210,7 +210,7 @@ static u8_t read_func(struct bt_conn *conn, u8_t err,
210
210
return BT_GATT_ITER_CONTINUE ;
211
211
}
212
212
213
- void cmd_gatt_read (const struct shell * shell , size_t argc , char * argv [])
213
+ static void cmd_read (const struct shell * shell , size_t argc , char * argv [])
214
214
{
215
215
int err ;
216
216
@@ -241,7 +241,7 @@ void cmd_gatt_read(const struct shell *shell, size_t argc, char *argv[])
241
241
}
242
242
}
243
243
244
- void cmd_gatt_mread (const struct shell * shell , size_t argc , char * argv [])
244
+ static void cmd_mread (const struct shell * shell , size_t argc , char * argv [])
245
245
{
246
246
u16_t h [8 ];
247
247
int i , err ;
@@ -287,7 +287,7 @@ static void write_func(struct bt_conn *conn, u8_t err,
287
287
(void )memset (& write_params , 0 , sizeof (write_params ));
288
288
}
289
289
290
- void cmd_gatt_write (const struct shell * shell , size_t argc , char * argv [])
290
+ static void cmd_write (const struct shell * shell , size_t argc , char * argv [])
291
291
{
292
292
int err ;
293
293
u16_t handle , offset ;
@@ -337,8 +337,8 @@ void cmd_gatt_write(const struct shell *shell, size_t argc, char *argv[])
337
337
}
338
338
}
339
339
340
- void cmd_gatt_write_without_rsp (const struct shell * shell ,
341
- size_t argc , char * argv [])
340
+ static void cmd_write_without_rsp (const struct shell * shell ,
341
+ size_t argc , char * argv [])
342
342
{
343
343
u16_t handle ;
344
344
u16_t repeat ;
@@ -355,7 +355,7 @@ void cmd_gatt_write_without_rsp(const struct shell *shell,
355
355
return ;
356
356
}
357
357
358
- sign = !strcmp (argv [0 ], "gatt -write-signed " );
358
+ sign = !strcmp (argv [0 ], "signed -write" );
359
359
handle = strtoul (argv [1 ], NULL , 16 );
360
360
gatt_write_buf [0 ] = strtoul (argv [2 ], NULL , 16 );
361
361
len = 1 ;
@@ -408,7 +408,7 @@ static u8_t notify_func(struct bt_conn *conn,
408
408
return BT_GATT_ITER_CONTINUE ;
409
409
}
410
410
411
- void cmd_gatt_subscribe (const struct shell * shell , size_t argc , char * argv [])
411
+ static void cmd_subscribe (const struct shell * shell , size_t argc , char * argv [])
412
412
{
413
413
int err ;
414
414
@@ -444,7 +444,8 @@ void cmd_gatt_subscribe(const struct shell *shell, size_t argc, char *argv[])
444
444
}
445
445
}
446
446
447
- void cmd_gatt_unsubscribe (const struct shell * shell , size_t argc , char * argv [])
447
+ static void cmd_unsubscribe (const struct shell * shell ,
448
+ size_t argc , char * argv [])
448
449
{
449
450
int err ;
450
451
@@ -477,7 +478,7 @@ static u8_t print_attr(const struct bt_gatt_attr *attr, void *user_data)
477
478
return BT_GATT_ITER_CONTINUE ;
478
479
}
479
480
480
- void cmd_gatt_show_db (const struct shell * shell , size_t argc , char * argv [])
481
+ static void cmd_show_db (const struct shell * shell , size_t argc , char * argv [])
481
482
{
482
483
bt_gatt_foreach_attr (0x0001 , 0xffff , print_attr , (void * )shell );
483
484
}
@@ -624,17 +625,17 @@ static struct bt_gatt_attr vnd1_attrs[] = {
624
625
625
626
static struct bt_gatt_service vnd1_svc = BT_GATT_SERVICE (vnd1_attrs );
626
627
627
- void cmd_gatt_register_test_svc (const struct shell * shell ,
628
- size_t argc , char * argv [])
628
+ static void cmd_register_test_svc (const struct shell * shell ,
629
+ size_t argc , char * argv [])
629
630
{
630
631
bt_gatt_service_register (& vnd_svc );
631
632
bt_gatt_service_register (& vnd1_svc );
632
633
633
634
print (shell , "Registering test vendor services\n" );
634
635
}
635
636
636
- void cmd_gatt_unregister_test_svc (const struct shell * shell ,
637
- size_t argc , char * argv [])
637
+ static void cmd_unregister_test_svc (const struct shell * shell ,
638
+ size_t argc , char * argv [])
638
639
{
639
640
bt_gatt_service_unregister (& vnd_svc );
640
641
bt_gatt_service_unregister (& vnd1_svc );
@@ -714,8 +715,7 @@ static struct bt_gatt_attr met_attrs[] = {
714
715
715
716
static struct bt_gatt_service met_svc = BT_GATT_SERVICE (met_attrs );
716
717
717
- void cmd_gatt_write_cmd_metrics (const struct shell * shell ,
718
- size_t argc , char * argv [])
718
+ static void cmd_metrics (const struct shell * shell , size_t argc , char * argv [])
719
719
{
720
720
int err = 0 ;
721
721
@@ -748,3 +748,61 @@ void cmd_gatt_write_cmd_metrics(const struct shell *shell,
748
748
print (shell , "GATT write cmd metrics %s.\n" , argv [1 ]);
749
749
}
750
750
}
751
+
752
+ #define HELP_NONE "[none]"
753
+
754
+ SHELL_CREATE_STATIC_SUBCMD_SET (gatt_cmds ) {
755
+ #if defined(CONFIG_BT_GATT_CLIENT )
756
+ SHELL_CMD (discover - characteristic , NULL ,
757
+ "[UUID] [start handle] [end handle]" , cmd_discover ),
758
+ SHELL_CMD (discover - descriptor , NULL ,
759
+ "[UUID] [start handle] [end handle]" , cmd_discover ),
760
+ SHELL_CMD (discover - include , NULL ,
761
+ "[UUID] [start handle] [end handle]" , cmd_discover ),
762
+ SHELL_CMD (discover - primary , NULL ,
763
+ "[UUID] [start handle] [end handle]" , cmd_discover ),
764
+ SHELL_CMD (discover - secondary , NULL ,
765
+ "[UUID] [start handle] [end handle]" , cmd_discover ),
766
+ SHELL_CMD (exchange - mtu , NULL , HELP_NONE , cmd_exchange_mtu ),
767
+ SHELL_CMD (read , NULL , "<handle> [offset]" , cmd_read ),
768
+ SHELL_CMD (read - multiple , NULL , "<handle 1> <handle 2> ..." ,
769
+ cmd_mread ),
770
+ SHELL_CMD (signed - write , NULL , "<handle> <data> [length] [repeat]" ,
771
+ cmd_write_without_rsp ),
772
+ SHELL_CMD (subscribe , NULL , "<CCC handle> <value handle> [ind]" ,
773
+ cmd_subscribe ),
774
+ SHELL_CMD (write , NULL , "<handle> <offset> <data> [length]" ,
775
+ cmd_write ),
776
+ SHELL_CMD (write - without - response , NULL ,
777
+ "<handle> <data> [length] [repeat]" ,
778
+ cmd_write_without_rsp ),
779
+ SHELL_CMD (unsubscribe , NULL , HELP_NONE , cmd_unsubscribe ),
780
+ #endif /* CONFIG_BT_GATT_CLIENT */
781
+ SHELL_CMD (metrics , NULL ,
782
+ "register vendr char and measure rx [value on, off]" ,
783
+ cmd_metrics ),
784
+ SHELL_CMD (register , NULL ,
785
+ "register pre-predefined test service" ,
786
+ cmd_register_test_svc ),
787
+ SHELL_CMD (show - db , NULL , HELP_NONE , cmd_show_db ),
788
+ SHELL_CMD (unregister , NULL ,
789
+ "unregister pre-predefined test service" ,
790
+ cmd_unregister_test_svc ),
791
+ SHELL_SUBCMD_SET_END
792
+ };
793
+
794
+ static void cmd_gatt (const struct shell * shell , size_t argc , char * * argv )
795
+ {
796
+ if (argc == 1 ) {
797
+ shell_help_print (shell , NULL , 0 );
798
+ return ;
799
+ }
800
+
801
+ if (!shell_cmd_precheck (shell , (argc == 2 ), NULL , 0 )) {
802
+ return ;
803
+ }
804
+
805
+ error (shell , "%s:%s%s\r\n" , argv [0 ], "unknown parameter: " , argv [1 ]);
806
+ }
807
+
808
+ SHELL_CMD_REGISTER (gatt , & gatt_cmds , "Bluetooth GATT shell commands" , cmd_gatt );
0 commit comments