shell.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * shell implementation for finsh shell.
  3. *
  4. * COPYRIGHT (C) 2006 - 2013, RT-Thread Development Team
  5. *
  6. * This file is part of RT-Thread (http://www.rt-thread.org)
  7. * Maintainer: bernard.xiong <bernard.xiong at gmail.com>
  8. *
  9. * All rights reserved.
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License along
  22. * with this program; if not, write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  24. *
  25. * Change Logs:
  26. * Date Author Notes
  27. * 2011-06-02 Bernard Add finsh_get_prompt function declaration
  28. */
  29. #ifndef __SHELL_H__
  30. #define __SHELL_H__
  31. #include <rtthread.h>
  32. #include "finsh.h"
  33. #ifndef FINSH_THREAD_PRIORITY
  34. #define FINSH_THREAD_PRIORITY 20
  35. #endif
  36. #ifndef FINSH_THREAD_STACK_SIZE
  37. #define FINSH_THREAD_STACK_SIZE 2048
  38. #endif
  39. #ifndef FINSH_CMD_SIZE
  40. #define FINSH_CMD_SIZE 80
  41. #endif
  42. #define FINSH_OPTION_ECHO 0x01
  43. #define FINSH_PROMPT finsh_get_prompt()
  44. const char* finsh_get_prompt(void);
  45. int finsh_set_prompt(const char * prompt);
  46. #ifdef FINSH_USING_HISTORY
  47. #ifndef FINSH_HISTORY_LINES
  48. #define FINSH_HISTORY_LINES 5
  49. #endif
  50. #endif
  51. #ifdef FINSH_USING_AUTH
  52. #ifndef FINSH_PASSWORD_MAX
  53. #define FINSH_PASSWORD_MAX RT_NAME_MAX
  54. #endif
  55. #ifndef FINSH_PASSWORD_MIN
  56. #define FINSH_PASSWORD_MIN 6
  57. #endif
  58. #ifndef FINSH_DEFAULT_PASSWORD
  59. #define FINSH_DEFAULT_PASSWORD "rtthread"
  60. #endif
  61. #endif /* FINSH_USING_AUTH */
  62. #ifndef FINSH_THREAD_NAME
  63. #define FINSH_THREAD_NAME "tshell"
  64. #endif
  65. enum input_stat
  66. {
  67. WAIT_NORMAL,
  68. WAIT_SPEC_KEY,
  69. WAIT_FUNC_KEY,
  70. };
  71. struct finsh_shell
  72. {
  73. struct rt_semaphore rx_sem;
  74. enum input_stat stat;
  75. rt_uint8_t echo_mode:1;
  76. rt_uint8_t prompt_mode: 1;
  77. #ifdef FINSH_USING_HISTORY
  78. rt_uint16_t current_history;
  79. rt_uint16_t history_count;
  80. char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
  81. #endif
  82. #ifndef FINSH_USING_MSH_ONLY
  83. struct finsh_parser parser;
  84. #endif
  85. char line[FINSH_CMD_SIZE];
  86. rt_uint8_t line_position;
  87. rt_uint8_t line_curpos;
  88. #ifndef RT_USING_POSIX
  89. rt_device_t device;
  90. #endif
  91. #ifdef FINSH_USING_AUTH
  92. char password[FINSH_PASSWORD_MAX];
  93. #endif
  94. };
  95. void finsh_set_echo(rt_uint32_t echo);
  96. rt_uint32_t finsh_get_echo(void);
  97. int finsh_system_init(void);
  98. void finsh_set_device(const char* device_name);
  99. const char* finsh_get_device(void);
  100. rt_uint32_t finsh_get_prompt_mode(void);
  101. void finsh_set_prompt_mode(rt_uint32_t prompt_mode);
  102. #ifdef FINSH_USING_AUTH
  103. rt_err_t finsh_set_password(const char *password);
  104. const char *finsh_get_password(void);
  105. #endif
  106. #endif