EE445M RTOS
Taken at the University of Texas Spring 2015
shell Class Reference

#include <shellpp.hpp>

Collaboration diagram for shell:
Collaboration graph

Public Member Functions

 shell ()
 
 shell (uart *u)
 
 shell (uart *u, semaphore *m_start, semaphore *m_stop)
 
void clear_buffer ()
 
void set_ps1 (char *new_ps1)
 
void print_ps1 ()
 
bool type (char ch)
 
void backspace (void)
 
void accept (char ch)
 
exit_status_t execute_command ()
 

Private Member Functions

int32_t ustrncmp (const char *, const char *, uint32_t)
 
void * memset (void *b, int c, int len)
 
uint32_t strlen (const char *)
 
void init_ps1 (void)
 
void init (void)
 

Static Private Member Functions

static exit_status_t help_info (const char *args)
 
static exit_status_t doctor (const char *args)
 
static exit_status_t witch (const char *args)
 
static exit_status_t jester (const char *args)
 
static exit_status_t motor_start (const char *args)
 
static exit_status_t motor_stop (const char *args)
 
static void ustrcpy (char *dest, const char *source)
 

Private Attributes

uartuart0
 
buffer< char, 32 > buf
 
char ps1 [4+1]
 

Static Private Attributes

static char system_command_names [2][10]
 
static sys_cmd system_command_funcs [2]
 
static semaphorem_start
 
static semaphorem_stop
 

Detailed Description

Definition at line 31 of file shellpp.hpp.

Constructor & Destructor Documentation

shell::shell ( )

Definition at line 81 of file shellpp.cpp.

References init().

81  {
82 
83  init();
84 }
void init(void)
Definition: shellpp.cpp:75

Here is the call graph for this function:

shell::shell ( uart u)

Definition at line 86 of file shellpp.cpp.

References init(), and uart0.

86  {
87 
88  uart0 = u;
89  init();
90 }
void init(void)
Definition: shellpp.cpp:75
uart * uart0
Definition: shellpp.hpp:33

Here is the call graph for this function:

shell::shell ( uart u,
semaphore m_start,
semaphore m_stop 
)

Definition at line 92 of file shellpp.cpp.

References init(), m_start, m_stop, and uart0.

92  {
93 
94  uart0 = u;
95 
96  m_start = m_start;
97  m_stop = m_stop;
98 
99  init();
100 }
void init(void)
Definition: shellpp.cpp:75
static semaphore * m_stop
Definition: shellpp.hpp:61
uart * uart0
Definition: shellpp.hpp:33
static semaphore * m_start
Definition: shellpp.hpp:60

Here is the call graph for this function:

Member Function Documentation

void shell::accept ( char  ch)

Accept a char, shell will call or appropriately.

Definition at line 174 of file shellpp.cpp.

References backspace(), execute_command(), and type().

Referenced by shell_handler().

174  {
175 
176  switch(ch) {
177  case SC_CR:
178  execute_command();
179  break;
180 
181  case 127:
182  case SC_BACKSPACE:
183  backspace();
184  break;
185 
186  default:
187  type(ch);
188  break;
189  }
190 }
bool type(char ch)
Definition: shellpp.cpp:159
exit_status_t execute_command()
Definition: shellpp.cpp:228
void backspace(void)
Definition: shellpp.cpp:192

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::backspace ( void  )

Remove a char from the shell buffer.

Definition at line 192 of file shellpp.cpp.

References uart::atomic_printf(), buf, buffer< T, N >::get(), and uart0.

Referenced by accept().

192  {
193 
194  bool ok;
195  buf.get(ok);
196  if (ok) {
197  uart0->atomic_printf("\b \b");
198  }
199 }
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
T get(bool &ok)
Definition: bufferpp.hpp:76
buffer< char, 32 > buf
Definition: shellpp.hpp:34
uart * uart0
Definition: shellpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::clear_buffer ( )

Clear the shell buffer.

Definition at line 142 of file shellpp.cpp.

References buf, and buffer< T, N >::clear().

142  {
143 
144  buf.clear();
145 }
void clear()
Definition: bufferpp.hpp:33
buffer< char, 32 > buf
Definition: shellpp.hpp:34

Here is the call graph for this function:

exit_status_t shell::doctor ( const char *  args)
staticprivate

Definition at line 21 of file shellpp.cpp.

References blink, EXIT_SUCCESS, PIN_RED, and blinker::toggle().

Referenced by execute_command().

21  {
22 
23  blinker blink = blinker(GPIO_PORTF_BASE);
24  blink.toggle(PIN_RED);
25  return EXIT_SUCCESS;
26 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
blinker blink
Definition: move-main.cpp:38
const pin_t PIN_RED
Definition: blinker.hpp:18
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34

Here is the call graph for this function:

Here is the caller graph for this function:

exit_status_t shell::execute_command ( )

Execute this command.

You know how I know this shell sucks? You can't even do this, because uart0 is a non-static context and this is a static context. eff this implementation of system

Definition at line 228 of file shellpp.cpp.

References uart::atomic_printf(), buf, buffer< T, N >::buf, doctor(), EXIT_SUCCESS, jester(), buffer< T, N >::length(), motor_start(), motor_stop(), print_ps1(), shell_command_is, uart0, and witch().

Referenced by accept().

228  {
229 
230  /* Null terminate to separate the cmd from the args */
231  uint8_t len = buf.length();
232  uint8_t idx = 0;
233  while((idx < len) && (buf.buf[idx] != ' ')) {
234  ++idx;
235  }
236  buf.buf[idx] = 0;
237 
238  /* Clear some space between the user input and this cmd output */
239  uart0->atomic_printf("\r\n");
240 
241  exit_status_t exit_code = (exit_status_t) 0xDEADBEEF;
242  const char* args = &buf.buf[idx+1];
243  /* Waldo says this line requires the extra char to be a 0 */
244  if(shell_command_is("doctor")) {
245  exit_code = doctor(args);
246  } else if(shell_command_is("witch")) {
247  exit_code = witch(args);
248  } else if(shell_command_is("jester")) {
249  exit_code = jester(args);
250  /* begin motor control commands */
251  } else if(shell_command_is("start")) {
252  exit_code = motor_start(args);
253  } else if(shell_command_is("stop")) {
254  exit_code = motor_stop(args);
255  } else {
256  uart0->atomic_printf("%s is not a recognized command.\n\r", buf.buf);
257  }
258 
259 #ifdef SHELL_VERBOSE
260  if (exit_code != EXIT_SUCCESS) {
261  uart0->atomic_printf("\n\rnonzero exit code: %d", exit_code);
262  }
263 #endif
264 
265  /* Prepare for the next command */
266  print_ps1();
267 
268  return exit_code;
269 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
uint8_t exit_status_t
Definition: shellpp.hpp:28
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
static exit_status_t motor_start(const char *args)
Definition: shellpp.cpp:201
#define shell_command_is(a)
Definition: shellpp.cpp:12
T buf[N]
Definition: bufferpp.hpp:115
static exit_status_t witch(const char *args)
Definition: shellpp.cpp:28
void print_ps1()
Definition: shellpp.cpp:153
static exit_status_t motor_stop(const char *args)
Definition: shellpp.cpp:207
static exit_status_t jester(const char *args)
Definition: shellpp.cpp:35
static exit_status_t doctor(const char *args)
Definition: shellpp.cpp:21
buffer< char, 32 > buf
Definition: shellpp.hpp:34
uart * uart0
Definition: shellpp.hpp:33
uint32_t length()
Definition: bufferpp.hpp:106

Here is the call graph for this function:

Here is the caller graph for this function:

static exit_status_t shell::help_info ( const char *  args)
staticprivate
void shell::init ( void  )
private

Common code between constructors

Definition at line 75 of file shellpp.cpp.

References buf, and init_ps1().

Referenced by shell().

75  {
76 
78  init_ps1();
79 }
void init_ps1(void)
Definition: shellpp.cpp:102
buffer< char, 32 > buf
Definition: shellpp.hpp:34

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::init_ps1 ( void  )
private

Definition at line 102 of file shellpp.cpp.

References print_ps1(), and ps1.

Referenced by init().

102  {
103 
104  /* KLUDGE: shitty way to set PS1 */
105  ps1[0] = '>';
106  ps1[1] = ' ';
107  ps1[2] = ' ';
108  ps1[3] = 0;
109 
110  print_ps1();
111 }
char ps1[4+1]
Definition: shellpp.hpp:36
void print_ps1()
Definition: shellpp.cpp:153

Here is the call graph for this function:

Here is the caller graph for this function:

exit_status_t shell::jester ( const char *  args)
staticprivate

Definition at line 35 of file shellpp.cpp.

References blink, EXIT_SUCCESS, PIN_BLUE, and blinker::toggle().

Referenced by execute_command().

35  {
36 
37  blinker blink = blinker(GPIO_PORTF_BASE);
38  blink.toggle(PIN_BLUE);
39  return EXIT_SUCCESS;
40 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
const pin_t PIN_BLUE
Definition: blinker.hpp:20
blinker blink
Definition: move-main.cpp:38
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34

Here is the call graph for this function:

Here is the caller graph for this function:

void * shell::memset ( void *  b,
int  c,
int  len 
)
private

Definition at line 113 of file shellpp.cpp.

113  {
114 
115  int i;
116  unsigned char *p = (unsigned char *) b;
117  i = 0;
118  while(len > 0) {
119  *p = c;
120  ++p;
121  --len;
122  }
123  return b;
124 }
exit_status_t shell::motor_start ( const char *  args)
staticprivate

Definition at line 201 of file shellpp.cpp.

References EXIT_SUCCESS, and semaphore::post().

Referenced by execute_command().

201  {
202 
203  shell::m_start->post();
204  return EXIT_SUCCESS;
205 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
void post(void)
Definition: semaphorepp.cpp:45
static semaphore * m_start
Definition: shellpp.hpp:60

Here is the call graph for this function:

Here is the caller graph for this function:

exit_status_t shell::motor_stop ( const char *  args)
staticprivate

Definition at line 207 of file shellpp.cpp.

References EXIT_SUCCESS, and semaphore::post().

Referenced by execute_command().

207  {
208 
209  shell::m_stop->post();
210  return EXIT_SUCCESS;
211 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
void post(void)
Definition: semaphorepp.cpp:45
static semaphore * m_stop
Definition: shellpp.hpp:61

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::print_ps1 ( )

Print the PS1.

Note
has the side effect of clearing the shell buffer

Definition at line 153 of file shellpp.cpp.

References uart::atomic_printf(), buf, buffer< T, N >::clear(), ps1, and uart0.

Referenced by execute_command(), and init_ps1().

153  {
154 
155  buf.clear();
156  uart0->atomic_printf("\n\n\r%s", ps1);
157 }
void clear()
Definition: bufferpp.hpp:33
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
char ps1[4+1]
Definition: shellpp.hpp:36
buffer< char, 32 > buf
Definition: shellpp.hpp:34
uart * uart0
Definition: shellpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::set_ps1 ( char *  new_ps1)

Set the PS1.

Definition at line 147 of file shellpp.cpp.

References ps1, strlen(), and umemcpy().

147  {
148 
149  umemcpy(ps1, new_ps1, strlen(new_ps1));
150 }
void * umemcpy(void *str1, const void *str2, long n)
Definition: shellpp.cpp:132
char ps1[4+1]
Definition: shellpp.hpp:36
uint32_t strlen(const char *)
Definition: shellpp.cpp:126

Here is the call graph for this function:

uint32_t shell::strlen ( const char *  s)
private

Return the length of a null-terminated string.

Definition at line 126 of file shellpp.cpp.

Referenced by set_ps1().

126  {
127  uint32_t len = 0;
128  while(s[len]) { ++len; }
129  return(len);
130 }

Here is the caller graph for this function:

bool shell::type ( char  ch)

Add a char to the shell buffer.

Definition at line 159 of file shellpp.cpp.

References buffer< T, N >::add(), uart::atomic_printf(), buf, buffer< T, N >::full(), and uart0.

Referenced by accept().

159  {
160 
161  bool ret;
162  if (buf.full()) {
163  ret = false;
164  } else {
165  ret = true;
166  buf.add((const char) ch);
167  }
168  if(ret) {
169  uart0->atomic_printf("%c", ch);
170  }
171  return ret;
172 }
void atomic_printf(const char *pcString,...)
Definition: uartpp.cpp:348
bool full()
Definition: bufferpp.hpp:96
bool add(const T data)
Definition: bufferpp.hpp:56
buffer< char, 32 > buf
Definition: shellpp.hpp:34
uart * uart0
Definition: shellpp.hpp:33

Here is the call graph for this function:

Here is the caller graph for this function:

void shell::ustrcpy ( char *  dest,
const char *  source 
)
staticprivate

Definition at line 66 of file shellpp.cpp.

66  {
67 
68  uint32_t i = 0;
69  while (1) {
70  dest[i] = source[i];
71  if (source[i++] == '\0') { break; }
72  }
73 }
int32_t shell::ustrncmp ( const char *  s1,
const char *  s2,
uint32_t  n 
)
private

Execute a system command.

Note
this implementation does not compare length, thus unique abbreviations are fair game (gdb style)

Definition at line 44 of file shellpp.cpp.

44  {
45 
46  /* Loop while there are more characters. */
47  while(n) {
48  /* If we reached a NULL in both strings, they must be equal so
49  * we end the comparison and return 0 */
50  if((!*s1 || (*s1 == ' ')) && (!*s2 || (*s2 == ' '))) {
51  return(0);
52  }
53 
54  if(*s2 < *s1) { return(1); }
55  if(*s1 < *s2) { return(-1); }
56 
57  s1++;
58  s2++;
59  n--;
60  }
61  /* If we fall out, the strings must be equal for at least the
62  * first n characters so return 0 to indicate this. */
63  return 0;
64 }
exit_status_t shell::witch ( const char *  args)
staticprivate

Definition at line 28 of file shellpp.cpp.

References blink, EXIT_SUCCESS, PIN_GREEN, and blinker::toggle().

Referenced by execute_command().

28  {
29 
30  blinker blink = blinker(GPIO_PORTF_BASE);
31  blink.toggle(PIN_GREEN);
32  return EXIT_SUCCESS;
33 }
#define EXIT_SUCCESS
Definition: shellpp.cpp:8
blinker blink
Definition: move-main.cpp:38
virtual void toggle(pin_t pin)
Definition: blinker.cpp:34
const pin_t PIN_GREEN
Definition: blinker.hpp:19

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

buffer<char, 32 > shell::buf
private

Definition at line 34 of file shellpp.hpp.

Referenced by backspace(), clear_buffer(), execute_command(), init(), print_ps1(), and type().

semaphore * shell::m_start
staticprivate

Definition at line 60 of file shellpp.hpp.

Referenced by shell().

semaphore * shell::m_stop
staticprivate

Definition at line 61 of file shellpp.hpp.

Referenced by shell().

char shell::ps1[4+1]
private

Definition at line 36 of file shellpp.hpp.

Referenced by init_ps1(), print_ps1(), and set_ps1().

sys_cmd shell::system_command_funcs
staticprivate

Definition at line 54 of file shellpp.hpp.

char shell::system_command_names
staticprivate

Definition at line 53 of file shellpp.hpp.

uart* shell::uart0
private

Definition at line 33 of file shellpp.hpp.

Referenced by backspace(), execute_command(), print_ps1(), shell(), and type().


The documentation for this class was generated from the following files: