2012-09-20 13:07:14 +08:00
|
|
|
/*
|
2021-03-08 18:19:04 +08:00
|
|
|
* Copyright (c) 2006-2021, RT-Thread Development Team
|
2012-09-20 13:07:14 +08:00
|
|
|
*
|
2018-10-14 19:28:18 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2012-09-20 13:07:14 +08:00
|
|
|
*
|
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2011-06-02 Bernard Add finsh_get_prompt function declaration
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SHELL_H__
|
|
|
|
#define __SHELL_H__
|
|
|
|
|
|
|
|
#include <rtthread.h>
|
2013-01-08 22:40:58 +08:00
|
|
|
#include "finsh.h"
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
#ifndef FINSH_THREAD_PRIORITY
|
|
|
|
#define FINSH_THREAD_PRIORITY 20
|
|
|
|
#endif
|
|
|
|
#ifndef FINSH_THREAD_STACK_SIZE
|
|
|
|
#define FINSH_THREAD_STACK_SIZE 2048
|
|
|
|
#endif
|
2015-05-18 18:12:17 +08:00
|
|
|
#ifndef FINSH_CMD_SIZE
|
2017-10-17 22:28:05 +08:00
|
|
|
#define FINSH_CMD_SIZE 80
|
2015-05-18 18:12:17 +08:00
|
|
|
#endif
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2017-10-17 22:28:05 +08:00
|
|
|
#define FINSH_OPTION_ECHO 0x01
|
2018-07-02 16:23:00 +08:00
|
|
|
|
2017-10-17 22:28:05 +08:00
|
|
|
#define FINSH_PROMPT finsh_get_prompt()
|
2012-09-20 13:07:14 +08:00
|
|
|
const char* finsh_get_prompt(void);
|
2018-07-02 16:23:00 +08:00
|
|
|
int finsh_set_prompt(const char * prompt);
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
2017-10-17 22:28:05 +08:00
|
|
|
#ifndef FINSH_HISTORY_LINES
|
|
|
|
#define FINSH_HISTORY_LINES 5
|
|
|
|
#endif
|
2013-10-16 14:54:13 +08:00
|
|
|
#endif
|
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
#ifdef FINSH_USING_AUTH
|
|
|
|
#ifndef FINSH_PASSWORD_MAX
|
|
|
|
#define FINSH_PASSWORD_MAX RT_NAME_MAX
|
|
|
|
#endif
|
|
|
|
#ifndef FINSH_PASSWORD_MIN
|
|
|
|
#define FINSH_PASSWORD_MIN 6
|
|
|
|
#endif
|
|
|
|
#ifndef FINSH_DEFAULT_PASSWORD
|
|
|
|
#define FINSH_DEFAULT_PASSWORD "rtthread"
|
|
|
|
#endif
|
|
|
|
#endif /* FINSH_USING_AUTH */
|
|
|
|
|
2018-01-12 17:19:57 +08:00
|
|
|
#ifndef FINSH_THREAD_NAME
|
|
|
|
#define FINSH_THREAD_NAME "tshell"
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 13:07:14 +08:00
|
|
|
enum input_stat
|
|
|
|
{
|
2017-10-17 22:28:05 +08:00
|
|
|
WAIT_NORMAL,
|
|
|
|
WAIT_SPEC_KEY,
|
|
|
|
WAIT_FUNC_KEY,
|
2012-09-20 13:07:14 +08:00
|
|
|
};
|
|
|
|
struct finsh_shell
|
|
|
|
{
|
2017-10-17 22:28:05 +08:00
|
|
|
struct rt_semaphore rx_sem;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2017-10-17 22:28:05 +08:00
|
|
|
enum input_stat stat;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2017-10-17 22:28:05 +08:00
|
|
|
rt_uint8_t echo_mode:1;
|
2018-07-02 15:10:11 +08:00
|
|
|
rt_uint8_t prompt_mode: 1;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_HISTORY
|
2017-10-17 22:28:05 +08:00
|
|
|
rt_uint16_t current_history;
|
|
|
|
rt_uint16_t history_count;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2017-10-17 22:28:05 +08:00
|
|
|
char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
|
2012-09-20 13:07:14 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-01 23:14:45 +08:00
|
|
|
#ifndef FINSH_USING_MSH_ONLY
|
2017-10-17 22:28:05 +08:00
|
|
|
struct finsh_parser parser;
|
2014-01-01 23:14:45 +08:00
|
|
|
#endif
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2020-10-14 09:27:40 +08:00
|
|
|
char line[FINSH_CMD_SIZE + 1];
|
2019-09-20 14:48:01 +08:00
|
|
|
rt_uint16_t line_position;
|
|
|
|
rt_uint16_t line_curpos;
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2019-09-25 20:08:53 +08:00
|
|
|
#if !defined(RT_USING_POSIX) && defined(RT_USING_DEVICE)
|
2017-10-17 22:28:05 +08:00
|
|
|
rt_device_t device;
|
2017-10-10 14:27:34 +08:00
|
|
|
#endif
|
2016-11-26 15:23:12 +08:00
|
|
|
|
|
|
|
#ifdef FINSH_USING_AUTH
|
2017-10-17 22:28:05 +08:00
|
|
|
char password[FINSH_PASSWORD_MAX];
|
2016-11-26 15:23:12 +08:00
|
|
|
#endif
|
2012-09-20 13:07:14 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void finsh_set_echo(rt_uint32_t echo);
|
|
|
|
rt_uint32_t finsh_get_echo(void);
|
|
|
|
|
2013-06-23 07:48:42 +08:00
|
|
|
int finsh_system_init(void);
|
2012-09-20 13:07:14 +08:00
|
|
|
void finsh_set_device(const char* device_name);
|
|
|
|
const char* finsh_get_device(void);
|
2021-08-21 06:14:37 +08:00
|
|
|
char finsh_getchar(void);
|
2012-09-20 13:07:14 +08:00
|
|
|
|
2018-07-02 15:10:11 +08:00
|
|
|
rt_uint32_t finsh_get_prompt_mode(void);
|
|
|
|
void finsh_set_prompt_mode(rt_uint32_t prompt_mode);
|
|
|
|
|
2016-11-26 15:23:12 +08:00
|
|
|
#ifdef FINSH_USING_AUTH
|
|
|
|
rt_err_t finsh_set_password(const char *password);
|
|
|
|
const char *finsh_get_password(void);
|
|
|
|
#endif
|
|
|
|
|
2012-09-20 13:07:14 +08:00
|
|
|
#endif
|