All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
vexshell.h
Go to the documentation of this file.
1 /*-----------------------------------------------------------------------------*/
2 /* */
3 /* Copyright (c) James Pearman */
4 /* 2013 */
5 /* All Rights Reserved */
6 /* */
7 /*-----------------------------------------------------------------------------*/
8 /* */
9 /* Module: vexshell.h */
10 /* Author: James Pearman */
11 /* Created: 15 May 2013 */
12 /* */
13 /* Revisions: */
14 /* V1.00 4 July 2013 - Initial release */
15 /* */
16 /*-----------------------------------------------------------------------------*/
17 /* */
18 /* This file is part of ConVEX. */
19 /* */
20 /* The author is supplying this software for use with the VEX cortex */
21 /* control system. ConVEX is free software; you can redistribute it */
22 /* and/or modify it under the terms of the GNU General Public License */
23 /* as published by the Free Software Foundation; either version 3 of */
24 /* the License, or (at your option) any later version. */
25 /* */
26 /* ConVEX is distributed in the hope that it will be useful, */
27 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
28 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
29 /* GNU General Public License for more details. */
30 /* */
31 /* You should have received a copy of the GNU General Public License */
32 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
33 /* */
34 /* A special exception to the GPL can be applied should you wish to */
35 /* distribute a combined work that includes ConVEX, without being obliged */
36 /* to provide the source code for any proprietary components. */
37 /* See the file exception.txt for full details of how and when the */
38 /* exception can be applied. */
39 /* */
40 /* The author can be contacted on the vex forums as jpearman */
41 /* or electronic mail using jbpearman_at_mac_dot_com */
42 /* Mentor for team 8888 RoboLancers, Pasadena CA. */
43 /* */
44 /*-----------------------------------------------------------------------------*/
45 /* */
46 /* Customized version of the ChibiOS/RT shell using the same names */
47 /* Banner message is different */
48 /* One level of history implemented using up arrow key */
49 /* Detection of (127) as backspace from the screen program running on OSX */
50 /* My weird and rather old fashioned formatting */
51 /*-----------------------------------------------------------------------------*/
52 /* */
53 /* ChibiOS/RT - Copyright (C) 2006-2013 Giovanni Di Sirio */
54 /* */
55 /* Licensed under the Apache License, Version 2.0 (the "License"); */
56 /* you may not use this file except in compliance with the License. */
57 /* You may obtain a copy of the License at */
58 /* */
59 /* http://www.apache.org/licenses/LICENSE-2.0 */
60 /* */
61 /* Unless required by applicable law or agreed to in writing, software */
62 /* distributed under the License is distributed on an "AS IS" BASIS, */
63 /* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
64 /* See the License for the specific language governing permissions and */
65 /* limitations under the License. */
66 /*-----------------------------------------------------------------------------*/
67 
68 /*-----------------------------------------------------------------------------*/
69 /** @file vexshell.h
70  * @brief Simple CLI shell header.
71 *//*---------------------------------------------------------------------------*/
72 
73 #ifndef _VEXSHELL_
74 #define _VEXSHELL_
75 
76 /*-----------------------------------------------------------------------------*/
77 /** @brief Shell maximum input line length. */
78 /*-----------------------------------------------------------------------------*/
79 
80 #if !defined(SHELL_MAX_LINE_LENGTH) || defined(__DOXYGEN__)
81 #define SHELL_MAX_LINE_LENGTH 64
82 #endif
83 
84 /*-----------------------------------------------------------------------------*/
85 /** @brief Shell maximum arguments per command. */
86 /*-----------------------------------------------------------------------------*/
87 #if !defined(SHELL_MAX_ARGUMENTS) || defined(__DOXYGEN__)
88 #define SHELL_MAX_ARGUMENTS 4
89 #endif
90 
91 /*-----------------------------------------------------------------------------*/
92 /** @brief Command handler function type. */
93 /*-----------------------------------------------------------------------------*/
94 typedef void (*shellcmd_t)(vexStream *chp, int argc, char *argv[]);
95 
96 /*-----------------------------------------------------------------------------*/
97 /** @brief Custom command entry type. */
98 /*-----------------------------------------------------------------------------*/
99 typedef struct {
100  const char *sc_name; /**< @brief Command name. */
101  shellcmd_t sc_function; /**< @brief Command function. */
102 } ShellCommand;
103 
104 /*-----------------------------------------------------------------------------*/
105 /** @brief Shell descriptor type. */
106 /*-----------------------------------------------------------------------------*/
107 typedef struct {
108  vexStream *sc_channel; /**< @brief I/O channel associated
109  to the shell. */
110  const ShellCommand *sc_commands; /**< @brief Shell extra commands
111  table. */
112 } ShellConfig;
113 
114 #if !defined(__DOXYGEN__)
115 extern EventSource shell_terminated;
116 #endif
117 
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121 
122 void shellInit(void);
123 Thread *shellCreate(const ShellConfig *scp, size_t size, tprio_t prio);
124 Thread *shellCreateStatic(const ShellConfig *scp, void *wsp, size_t size, tprio_t prio);
125 bool_t shellGetLine(vexStream *chp, char *line, unsigned size);
126 
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif /* _VEXSHELL_ */
132