@@ -68,6 +68,11 @@ static struct k_poll_event can_shell_rx_msgq_events[] = {
6868static void can_shell_tx_msgq_triggered_work_handler (struct k_work * work );
6969static void can_shell_rx_msgq_triggered_work_handler (struct k_work * work );
7070
71+ static bool can_device_check (const struct device * dev )
72+ {
73+ return DEVICE_API_IS (can , dev ) && device_is_ready (dev );
74+ }
75+
7176#ifdef CONFIG_CAN_SHELL_SCRIPTING_FRIENDLY
7277static void can_shell_dummy_bypass_cb (const struct shell * sh , uint8_t * data , size_t len )
7378{
@@ -279,7 +284,7 @@ static int cmd_can_start(const struct shell *sh, size_t argc, char **argv)
279284 const struct device * dev = device_get_binding (argv [1 ]);
280285 int err ;
281286
282- if (!device_is_ready (dev )) {
287+ if (!can_device_check (dev )) {
283288 shell_error (sh , "device %s not ready" , argv [1 ]);
284289 return - ENODEV ;
285290 }
@@ -300,7 +305,7 @@ static int cmd_can_stop(const struct shell *sh, size_t argc, char **argv)
300305 const struct device * dev = device_get_binding (argv [1 ]);
301306 int err ;
302307
303- if (!device_is_ready (dev )) {
308+ if (!can_device_check (dev )) {
304309 shell_error (sh , "device %s not ready" , argv [1 ]);
305310 return - ENODEV ;
306311 }
@@ -331,7 +336,7 @@ static int cmd_can_show(const struct shell *sh, size_t argc, char **argv)
331336 can_mode_t cap ;
332337 int err ;
333338
334- if (!device_is_ready (dev )) {
339+ if (!can_device_check (dev )) {
335340 shell_error (sh , "device %s not ready" , argv [1 ]);
336341 return - ENODEV ;
337342 }
@@ -436,7 +441,7 @@ static int cmd_can_bitrate_set(const struct shell *sh, size_t argc, char **argv)
436441 char * endptr ;
437442 int err ;
438443
439- if (!device_is_ready (dev )) {
444+ if (!can_device_check (dev )) {
440445 shell_error (sh , "device %s not ready" , argv [1 ]);
441446 return - ENODEV ;
442447 }
@@ -507,7 +512,7 @@ static int cmd_can_dbitrate_set(const struct shell *sh, size_t argc, char **argv
507512 char * endptr ;
508513 int err ;
509514
510- if (!device_is_ready (dev )) {
515+ if (!can_device_check (dev )) {
511516 shell_error (sh , "device %s not ready" , argv [1 ]);
512517 return - ENODEV ;
513518 }
@@ -613,7 +618,7 @@ static int cmd_can_timing_set(const struct shell *sh, size_t argc, char **argv)
613618 struct can_timing timing = { 0 };
614619 int err ;
615620
616- if (!device_is_ready (dev )) {
621+ if (!can_device_check (dev )) {
617622 shell_error (sh , "device %s not ready" , argv [1 ]);
618623 return - ENODEV ;
619624 }
@@ -642,7 +647,7 @@ static int cmd_can_dtiming_set(const struct shell *sh, size_t argc, char **argv)
642647 struct can_timing timing = { 0 };
643648 int err ;
644649
645- if (!device_is_ready (dev )) {
650+ if (!can_device_check (dev )) {
646651 shell_error (sh , "device %s not ready" , argv [1 ]);
647652 return - ENODEV ;
648653 }
@@ -675,7 +680,7 @@ static int cmd_can_mode_set(const struct shell *sh, size_t argc, char **argv)
675680 int i ;
676681 int j ;
677682
678- if (!device_is_ready (dev )) {
683+ if (!can_device_check (dev )) {
679684 shell_error (sh , "device %s not ready" , argv [1 ]);
680685 return - ENODEV ;
681686 }
@@ -727,7 +732,7 @@ static int cmd_can_send(const struct shell *sh, size_t argc, char **argv)
727732 int err ;
728733 int i ;
729734
730- if (!device_is_ready (dev )) {
735+ if (!can_device_check (dev )) {
731736 shell_error (sh , "device %s not ready" , argv [1 ]);
732737 return - ENODEV ;
733738 }
@@ -844,7 +849,7 @@ static int cmd_can_filter_add(const struct shell *sh, size_t argc, char **argv)
844849 char * endptr ;
845850 int err ;
846851
847- if (!device_is_ready (dev )) {
852+ if (!can_device_check (dev )) {
848853 shell_error (sh , "device %s not ready" , argv [1 ]);
849854 return - ENODEV ;
850855 }
@@ -940,7 +945,7 @@ static int cmd_can_filter_remove(const struct shell *sh, size_t argc, char **arg
940945 int filter_id ;
941946 char * endptr ;
942947
943- if (!device_is_ready (dev )) {
948+ if (!can_device_check (dev )) {
944949 shell_error (sh , "device %s not ready" , argv [1 ]);
945950 return - ENODEV ;
946951 }
@@ -966,7 +971,7 @@ static int cmd_can_recover(const struct shell *sh, size_t argc, char **argv)
966971 char * endptr ;
967972 int err ;
968973
969- if (!device_is_ready (dev )) {
974+ if (!can_device_check (dev )) {
970975 shell_error (sh , "device %s not ready" , argv [1 ]);
971976 return - ENODEV ;
972977 }
@@ -996,7 +1001,7 @@ static int cmd_can_recover(const struct shell *sh, size_t argc, char **argv)
9961001
9971002static void cmd_can_device_name (size_t idx , struct shell_static_entry * entry )
9981003{
999- const struct device * dev = shell_device_lookup (idx , NULL );
1004+ const struct device * dev = shell_device_filter (idx , can_device_check );
10001005
10011006 entry -> syntax = (dev != NULL ) ? dev -> name : NULL ;
10021007 entry -> handler = NULL ;
0 commit comments