2 * Copyright Droids Corporation (2011)
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: commands.c,v 1.9 2009-11-08 17:24:33 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
28 #include <aversive/pgmspace.h>
29 #include <aversive/queue.h>
30 #include <aversive/endian.h>
31 #include <aversive/error.h>
32 #include <aversive/wait.h>
35 #include <parse_string.h>
36 #include <parse_num.h>
43 #include "eeprom_config.h"
46 extern const parse_inst_t PROGMEM cmd_reset;
47 extern const parse_inst_t PROGMEM cmd_bootloader;
48 extern const parse_inst_t PROGMEM cmd_log;
49 extern const parse_inst_t PROGMEM cmd_log_show;
50 extern const parse_inst_t PROGMEM cmd_log_type;
51 extern const parse_inst_t PROGMEM cmd_stack_space;
52 extern const parse_inst_t PROGMEM cmd_callout;
54 /**********************************************************/
56 /* this structure is filled when cmd_test_eeprom_config is parsed successfully */
57 struct cmd_test_eeprom_config_result {
61 static void cmd_test_eeprom_config_parsed(void *parsed_result, void *data)
67 eeprom_append_cmd("salut1\n");
69 eeprom_append_cmd("salut2\n");
70 eeprom_append_cmd("salut3\n");
71 eeprom_append_cmd("salut4\n");
73 eeprom_insert_cmd_before("coin\n", 0);
74 eeprom_insert_cmd_before("coin2\n", 2);
81 const char PROGMEM str_test_eeprom_config_arg0[] = "test_eeprom_config";
82 const parse_token_string_t PROGMEM cmd_test_eeprom_config_arg0 =
83 TOKEN_STRING_INITIALIZER(struct cmd_test_eeprom_config_result, arg0,
84 str_test_eeprom_config_arg0);
86 const char PROGMEM help_test_eeprom_config[] = "Test the eeprom configuration";
87 const parse_inst_t PROGMEM cmd_test_eeprom_config = {
88 .f = cmd_test_eeprom_config_parsed, /* function to call */
89 .data = NULL, /* 2nd arg of func */
90 .help_str = help_test_eeprom_config,
91 .tokens = { /* token list, NULL terminated */
92 (PGM_P)&cmd_test_eeprom_config_arg0,
99 struct cmd_eeprom_del_result {
101 fixed_string_t action;
105 static void cmd_eeprom_del_parsed(void *parsed_result,
108 struct cmd_eeprom_del_result *res = parsed_result;
111 if (eeprom_delete_cmd(res->n) < 0)
112 printf_P(PSTR("cannot delete command\n"));
116 const char PROGMEM str_eeprom_del_eeprom[] = "eeprom";
117 const parse_token_string_t PROGMEM cmd_eeprom_del_cmd =
118 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, cmd,
119 str_eeprom_del_eeprom);
120 const char PROGMEM str_eeprom_del_del[] = "del";
121 const parse_token_string_t PROGMEM cmd_eeprom_del_action =
122 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, action,
124 const parse_token_num_t PROGMEM cmd_eeprom_del_num =
125 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_del_result, n,
128 const char PROGMEM help_eeprom_del[] = "delete an eeprom init command";
129 const parse_inst_t PROGMEM cmd_eeprom_del = {
130 .f = cmd_eeprom_del_parsed, /* function to call */
131 .data = NULL, /* 2nd arg of func */
132 .help_str = help_eeprom_del,
133 .tokens = { /* token list, NULL terminated */
134 (PGM_P)&cmd_eeprom_del_cmd,
135 (PGM_P)&cmd_eeprom_del_action,
136 (PGM_P)&cmd_eeprom_del_num,
143 struct cmd_eeprom_add_result {
145 fixed_string_t action;
149 static void cmd_eeprom_add_parsed(void *parsed_result,
152 struct cmd_eeprom_add_result *res = parsed_result;
158 rdline_init(&rdl, cmdline_write_char, NULL, NULL);
159 rdline_newline(&rdl, "> ");
162 c = cmdline_dev_recv(NULL);
166 ret = rdline_char_in(&rdl, c);
168 printf_P(PSTR("abort\n"));
175 buffer = rdline_get_buffer(&rdl);
177 eeprom_insert_cmd_before(buffer, res->n);
179 eeprom_append_cmd(buffer);
183 const char PROGMEM str_eeprom_add_eeprom[] = "eeprom";
184 const parse_token_string_t PROGMEM cmd_eeprom_add_cmd =
185 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, cmd,
186 str_eeprom_add_eeprom);
187 const char PROGMEM str_eeprom_add_add[] = "add";
188 const parse_token_string_t PROGMEM cmd_eeprom_add_action =
189 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, action,
191 const parse_token_num_t PROGMEM cmd_eeprom_add_num =
192 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_add_result, n,
195 const char PROGMEM help_eeprom_add[] = "insert an eeprom init command";
196 const parse_inst_t PROGMEM cmd_eeprom_add = {
197 .f = cmd_eeprom_add_parsed, /* function to call */
198 .data = NULL, /* 2nd arg of func */
199 .help_str = help_eeprom_add,
200 .tokens = { /* token list, NULL terminated */
201 (PGM_P)&cmd_eeprom_add_cmd,
202 (PGM_P)&cmd_eeprom_add_action,
203 (PGM_P)&cmd_eeprom_add_num,
208 const char PROGMEM help_eeprom_add2[] = "append an eeprom init command";
209 const parse_inst_t PROGMEM cmd_eeprom_add2 = {
210 .f = cmd_eeprom_add_parsed, /* function to call */
211 .data = (void *)1, /* 2nd arg of func */
212 .help_str = help_eeprom_add2,
213 .tokens = { /* token list, NULL terminated */
214 (PGM_P)&cmd_eeprom_add_cmd,
215 (PGM_P)&cmd_eeprom_add_action,
222 struct cmd_eeprom_list_result {
224 fixed_string_t action;
227 static void cmd_eeprom_list_parsed(void *parsed_result,
235 const char PROGMEM str_eeprom_list_eeprom[] = "eeprom";
236 const parse_token_string_t PROGMEM cmd_eeprom_list_cmd =
237 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, cmd,
238 str_eeprom_list_eeprom);
239 const char PROGMEM str_eeprom_list_list[] = "list";
240 const parse_token_string_t PROGMEM cmd_eeprom_list_action =
241 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, action,
242 str_eeprom_list_list);
244 const char PROGMEM help_eeprom_list[] = "list all eeprom init commands";
245 const parse_inst_t PROGMEM cmd_eeprom_list = {
246 .f = cmd_eeprom_list_parsed, /* function to call */
247 .data = NULL, /* 2nd arg of func */
248 .help_str = help_eeprom_list,
249 .tokens = { /* token list, NULL terminated */
250 (PGM_P)&cmd_eeprom_list_cmd,
251 (PGM_P)&cmd_eeprom_list_action,
260 const parse_ctx_t PROGMEM main_ctx[] = {
270 &cmd_test_eeprom_config,