Skip to content

Commit 6899b19

Browse files
committed
[finsh][cmd] add 'console' command to config console
Signed-off-by: GuEe-GUI <[email protected]>
1 parent 2fb53c8 commit 6899b19

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

components/finsh/cmd.c

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
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>
@@ -40,6 +41,7 @@
4041

4142
#ifdef RT_USING_FINSH
4243
#include <finsh.h>
44+
#include <posix/stdio.h>
4345

4446
#define LIST_DFS_OPT_ID 0x100
4547
#define LIST_FIND_OBJ_NR 8
@@ -60,6 +62,48 @@ static long version(void)
6062
}
6163
MSH_CMD_EXPORT(version, show RT-Thread version information);
6264

65+
static int console(int argc, char **argv)
66+
{
67+
rt_err_t result = RT_EOK;
68+
69+
if (argc > 1)
70+
{
71+
if (!rt_strcmp(argv[1], "set"))
72+
{
73+
rt_kprintf("console change to %s\n", argv[2]);
74+
rt_console_set_device(argv[2]);
75+
76+
#ifdef RT_USING_POSIX
77+
{
78+
rt_device_t dev = rt_device_find(argv[2]);
79+
80+
if (dev != RT_NULL)
81+
{
82+
console_set_iodev(dev);
83+
}
84+
}
85+
#elif !defined(RT_USING_POSIX_STDIO)
86+
finsh_set_device(argv[2]);
87+
#else
88+
rt_posix_stdio_init();
89+
#endif /* RT_USING_POSIX */
90+
}
91+
else
92+
{
93+
rt_kprintf("Unknown command. Please enter 'console' for help\n");
94+
result = -RT_ERROR;
95+
}
96+
}
97+
else
98+
{
99+
rt_kprintf("Usage: \n");
100+
rt_kprintf("console set <name> - change console by name\n");
101+
result = -RT_ERROR;
102+
}
103+
return result;
104+
}
105+
MSH_CMD_EXPORT(console, console setting);
106+
63107
rt_inline void object_split(int len)
64108
{
65109
while (len--) rt_kprintf("-");

0 commit comments

Comments
 (0)