2 * Copyright Droids Corporation (2007)
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 * Revision : $Id: main.c,v 1.1.2.6 2007-11-24 22:57:54 zer0 Exp $
27 #include <aversive/pgmspace.h>
28 #include <aversive/error.h>
29 #include <aversive/wait.h>
35 char prompt[RDLINE_PROMPT_SIZE];
36 extern parse_pgm_ctx_t main_ctx[];
37 extern void cmd_event_parsed(void * parsed_result, void * data);
64 valid_buffer(const char * buf, uint8_t size)
67 ret = parse(main_ctx, buf);
68 if (ret == PARSE_AMBIGUOUS)
69 printf_P(PSTR("Ambiguous command\n"));
70 else if (ret == PARSE_NOMATCH)
71 printf_P(PSTR("Command not found\n"));
72 else if (ret == PARSE_BAD_ARGS)
73 printf_P(PSTR("Bad arguments\n"));
77 complete_buffer(const char * buf, char * dstbuf, uint8_t dstsize,
80 return complete(main_ctx, buf, state, dstbuf, dstsize);
89 struct termios oldterm, term;
96 tcgetattr(0, &oldterm);
97 memcpy(&term, &oldterm, sizeof(term));
98 term.c_lflag &= ~(ICANON | ECHO | ISIG);
99 tcsetattr(0, TCSANOW, &term);
102 fdevopen(uart0_dev_send, uart0_dev_recv);
107 printf_P(PSTR("Start\n"));
110 rdline_init(&rdl, write_char, valid_buffer, complete_buffer);
111 snprintf(prompt, sizeof(prompt), "main > ");
113 rdline_newline(&rdl, prompt);
125 ret = rdline_char_in(&rdl, c);
129 if (ret != 2 && ret != 0) {
130 rdline_add_history(&rdl, rdline_get_buffer(&rdl));
131 rdline_newline(&rdl, prompt);
136 tcsetattr(0, TCSANOW, &oldterm);