shell.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
  44. #define FINSH_PROMPT finsh_get_prompt()
  45. const char* finsh_get_prompt(void);
  46. #else
  47. #define FINSH_PROMPT "finsh>>"
  48. #endif
  49. #ifdef FINSH_USING_HISTORY
  50. #ifndef FINSH_HISTORY_LINES
  51. #define FINSH_HISTORY_LINES 5
  52. #endif
  53. #endif
  54. #ifdef FINSH_USING_AUTH
  55. #ifndef FINSH_PASSWORD_MAX
  56. #define FINSH_PASSWORD_MAX RT_NAME_MAX
  57. #endif
  58. #ifndef FINSH_PASSWORD_MIN
  59. #define FINSH_PASSWORD_MIN 6
  60. #endif
  61. #ifndef FINSH_DEFAULT_PASSWORD
  62. #define FINSH_DEFAULT_PASSWORD "rtthread"
  63. #endif
  64. #endif /* FINSH_USING_AUTH */
  65. #ifndef FINSH_THREAD_NAME
  66. #define FINSH_THREAD_NAME "tshell"
  67. #endif
  68. enum input_stat
  69. {
  70. WAIT_NORMAL,
  71. WAIT_SPEC_KEY,
  72. WAIT_FUNC_KEY,
  73. };
  74. struct finsh_shell
  75. {
  76. struct rt_semaphore rx_sem;
  77. enum input_stat stat;
  78. rt_uint8_t echo_mode:1;
  79. #ifdef FINSH_USING_HISTORY
  80. rt_uint16_t current_history;
  81. rt_uint16_t history_count;
  82. char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
  83. #endif
  84. #ifndef FINSH_USING_MSH_ONLY
  85. struct finsh_parser parser;
  86. #endif
  87. char line[FINSH_CMD_SIZE];
  88. rt_uint8_t line_position;
  89. rt_uint8_t line_curpos;
  90. #ifndef RT_USING_POSIX
  91. rt_device_t device;
  92. #endif
  93. #ifdef FINSH_USING_AUTH
  94. char password[FINSH_PASSWORD_MAX];
  95. #endif
  96. };
  97. void finsh_set_echo(rt_uint32_t echo);
  98. rt_uint32_t finsh_get_echo(void);
  99. int finsh_system_init(void);
  100. void finsh_set_device(const char* device_name);
  101. const char* finsh_get_device(void);
  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