@@ -478,19 +478,65 @@ static int cmd_unsubscribe(const struct shell *shell,
478478}
479479#endif /* CONFIG_BT_GATT_CLIENT */
480480
481+ static struct db_stats {
482+ u16_t svc_count ;
483+ u16_t attr_count ;
484+ u16_t chrc_count ;
485+ u16_t ccc_count ;
486+ size_t ccc_cfg ;
487+ } stats ;
488+
481489static u8_t print_attr (const struct bt_gatt_attr * attr , void * user_data )
482490{
483491 const struct shell * shell = user_data ;
484492
493+ stats .attr_count ++ ;
494+
495+ if (!bt_uuid_cmp (attr -> uuid , BT_UUID_GATT_PRIMARY ) ||
496+ !bt_uuid_cmp (attr -> uuid , BT_UUID_GATT_SECONDARY )) {
497+ stats .svc_count ++ ;
498+ }
499+
500+ if (!bt_uuid_cmp (attr -> uuid , BT_UUID_GATT_CHRC )) {
501+ stats .chrc_count ++ ;
502+ }
503+
504+ if (!bt_uuid_cmp (attr -> uuid , BT_UUID_GATT_CCC ) &&
505+ attr -> write == bt_gatt_attr_write_ccc ) {
506+ struct _bt_gatt_ccc * cfg = attr -> user_data ;
507+
508+ stats .ccc_count ++ ;
509+ stats .ccc_cfg += cfg -> cfg_len ;
510+ }
511+
485512 shell_print (shell , "attr %p handle 0x%04x uuid %s perm 0x%02x" ,
486- attr , attr -> handle , bt_uuid_str (attr -> uuid ), attr -> perm );
513+ attr , attr -> handle , bt_uuid_str (attr -> uuid ), attr -> perm );
487514
488515 return BT_GATT_ITER_CONTINUE ;
489516}
490517
491518static int cmd_show_db (const struct shell * shell , size_t argc , char * argv [])
492519{
520+ size_t total_len ;
521+
522+ memset (& stats , 0 , sizeof (stats ));
523+
493524 bt_gatt_foreach_attr (0x0001 , 0xffff , print_attr , (void * )shell );
525+
526+ if (!stats .attr_count ) {
527+ return 0 ;
528+ }
529+
530+ total_len = stats .svc_count * sizeof (struct bt_gatt_service );
531+ total_len += stats .chrc_count * sizeof (struct bt_gatt_chrc );
532+ total_len += stats .attr_count * sizeof (struct bt_gatt_attr );
533+ total_len += stats .ccc_count * sizeof (struct _bt_gatt_ccc );
534+ total_len += stats .ccc_cfg * sizeof (struct bt_gatt_ccc_cfg );
535+
536+ shell_print (shell , "=================================================" );
537+ shell_print (shell , "Total: %u services %u attributes (%u bytes)" ,
538+ stats .svc_count , stats .attr_count , total_len );
539+
494540 return 0 ;
495541}
496542
0 commit comments