3232 * 2022-07-02 Stanley Lwin add list command
3333 * 2023-09-15 xqyjlj perf rt_hw_interrupt_disable/enable
3434 * 2024-02-09 Bernard fix the version command
35+ * 2023-02-25 GuEe-GUI add console
3536 */
3637
3738#include <rthw.h>
4041
4142#ifdef RT_USING_FINSH
4243#include <finsh.h>
44+ #if !defined(RT_USING_POSIX ) && defined(RT_USING_POSIX_STDIO )
45+ #include <posix/stdio.h>
46+ #endif
4347
4448#define LIST_DFS_OPT_ID 0x100
4549#define LIST_FIND_OBJ_NR 8
@@ -60,6 +64,48 @@ static long version(void)
6064}
6165MSH_CMD_EXPORT (version , show RT - Thread version information );
6266
67+ static int console (int argc , char * * argv )
68+ {
69+ rt_err_t result = RT_EOK ;
70+
71+ if (argc > 1 )
72+ {
73+ if (!rt_strcmp (argv [1 ], "set" ))
74+ {
75+ rt_kprintf ("console change to %s\n" , argv [2 ]);
76+ rt_console_set_device (argv [2 ]);
77+
78+ #ifdef RT_USING_POSIX
79+ {
80+ rt_device_t dev = rt_device_find (argv [2 ]);
81+
82+ if (dev != RT_NULL )
83+ {
84+ console_set_iodev (dev );
85+ }
86+ }
87+ #elif !defined(RT_USING_POSIX_STDIO )
88+ finsh_set_device (argv [2 ]);
89+ #else
90+ rt_posix_stdio_init ();
91+ #endif /* RT_USING_POSIX */
92+ }
93+ else
94+ {
95+ rt_kprintf ("Unknown command. Please enter 'console' for help\n" );
96+ result = - RT_ERROR ;
97+ }
98+ }
99+ else
100+ {
101+ rt_kprintf ("Usage: \n" );
102+ rt_kprintf ("console set <name> - change console by name\n" );
103+ result = - RT_ERROR ;
104+ }
105+ return result ;
106+ }
107+ MSH_CMD_EXPORT (console , console setting );
108+
63109rt_inline void object_split (int len )
64110{
65111 while (len -- ) rt_kprintf ("-" );
0 commit comments