shell.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. /* For historical reasons, users don't define FINSH_USING_HISTORY in rtconfig.h
  34. * but expect the history feature. So you sould define FINSH_USING_HISTORY to 0
  35. * to disable it from the rtconfig.h. */
  36. #ifdef FINSH_USING_HISTORY
  37. # if FINSH_USING_HISTORY == 0
  38. # undef FINSH_USING_HISTORY
  39. # endif
  40. #else
  41. # define FINSH_USING_HISTORY
  42. #endif
  43. #ifndef FINSH_THREAD_PRIORITY
  44. #define FINSH_THREAD_PRIORITY 20
  45. #endif
  46. #ifndef FINSH_THREAD_STACK_SIZE
  47. #define FINSH_THREAD_STACK_SIZE 2048
  48. #endif
  49. #ifndef FINSH_CMD_SIZE
  50. #define FINSH_CMD_SIZE 80
  51. #endif
  52. #define FINSH_OPTION_ECHO 0x01
  53. #if defined(FINSH_USING_MSH) || (defined(RT_USING_DFS) && defined(DFS_USING_WORKDIR))
  54. #define FINSH_PROMPT finsh_get_prompt()
  55. const char* finsh_get_prompt(void);
  56. #else
  57. #define FINSH_PROMPT "finsh>>"
  58. #endif
  59. #ifdef FINSH_USING_HISTORY
  60. #ifndef FINSH_HISTORY_LINES
  61. #define FINSH_HISTORY_LINES 5
  62. #endif
  63. #endif
  64. #ifdef FINSH_USING_AUTH
  65. #ifndef FINSH_PASSWORD_MAX
  66. #define FINSH_PASSWORD_MAX RT_NAME_MAX
  67. #endif
  68. #ifndef FINSH_PASSWORD_MIN
  69. #define FINSH_PASSWORD_MIN 6
  70. #endif
  71. #ifndef FINSH_DEFAULT_PASSWORD
  72. #define FINSH_DEFAULT_PASSWORD "rtthread"
  73. #endif
  74. #endif /* FINSH_USING_AUTH */
  75. enum input_stat
  76. {
  77. WAIT_NORMAL,
  78. WAIT_SPEC_KEY,
  79. WAIT_FUNC_KEY,
  80. };
  81. struct finsh_shell
  82. {
  83. struct rt_semaphore rx_sem;
  84. enum input_stat stat;
  85. rt_uint8_t echo_mode:1;
  86. #ifdef FINSH_USING_HISTORY
  87. rt_uint16_t current_history;
  88. rt_uint16_t history_count;
  89. char cmd_history[FINSH_HISTORY_LINES][FINSH_CMD_SIZE];
  90. #endif
  91. #ifndef FINSH_USING_MSH_ONLY
  92. struct finsh_parser parser;
  93. #endif
  94. char line[FINSH_CMD_SIZE];
  95. rt_uint8_t line_position;
  96. rt_uint8_t line_curpos;
  97. rt_device_t device;
  98. #ifdef FINSH_USING_AUTH
  99. char password[FINSH_PASSWORD_MAX];
  100. #endif
  101. };
  102. void finsh_set_echo(rt_uint32_t echo);
  103. rt_uint32_t finsh_get_echo(void);
  104. int finsh_system_init(void);
  105. void finsh_set_device(const char* device_name);
  106. const char* finsh_get_device(void);
  107. #ifdef FINSH_USING_AUTH
  108. rt_err_t finsh_set_password(const char *password);
  109. const char *finsh_get_password(void);
  110. #endif
  111. #endif