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"
48 extern const parse_inst_t PROGMEM cmd_reset;
49 extern const parse_inst_t PROGMEM cmd_bootloader;
50 extern const parse_inst_t PROGMEM cmd_log;
51 extern const parse_inst_t PROGMEM cmd_log_show;
52 extern const parse_inst_t PROGMEM cmd_log_type;
53 extern const parse_inst_t PROGMEM cmd_stack_space;
54 extern const parse_inst_t PROGMEM cmd_callout;
56 /**********************************************************/
58 /* this structure is filled when cmd_test_eeprom_config is parsed successfully */
59 struct cmd_test_eeprom_config_result {
63 static void cmd_test_eeprom_config_parsed(void *parsed_result, void *data)
69 eeprom_append_cmd("salut1\n");
71 eeprom_append_cmd("salut2\n");
72 eeprom_append_cmd("salut3\n");
73 eeprom_append_cmd("salut4\n");
75 eeprom_insert_cmd_before("coin\n", 0);
76 eeprom_insert_cmd_before("coin2\n", 2);
83 const char PROGMEM str_test_eeprom_config_arg0[] = "test_eeprom_config";
84 const parse_token_string_t PROGMEM cmd_test_eeprom_config_arg0 =
85 TOKEN_STRING_INITIALIZER(struct cmd_test_eeprom_config_result, arg0,
86 str_test_eeprom_config_arg0);
88 const char PROGMEM help_test_eeprom_config[] = "Test the eeprom configuration";
89 const parse_inst_t PROGMEM cmd_test_eeprom_config = {
90 .f = cmd_test_eeprom_config_parsed, /* function to call */
91 .data = NULL, /* 2nd arg of func */
92 .help_str = help_test_eeprom_config,
93 .tokens = { /* token list, NULL terminated */
94 (PGM_P)&cmd_test_eeprom_config_arg0,
101 struct cmd_eeprom_del_result {
103 fixed_string_t action;
107 static void cmd_eeprom_del_parsed(void *parsed_result,
110 struct cmd_eeprom_del_result *res = parsed_result;
113 if (eeprom_delete_cmd(res->n) < 0)
114 printf_P(PSTR("cannot delete command\n"));
118 const char PROGMEM str_eeprom_del_eeprom[] = "eeprom";
119 const parse_token_string_t PROGMEM cmd_eeprom_del_cmd =
120 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, cmd,
121 str_eeprom_del_eeprom);
122 const char PROGMEM str_eeprom_del_del[] = "del";
123 const parse_token_string_t PROGMEM cmd_eeprom_del_action =
124 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, action,
126 const parse_token_num_t PROGMEM cmd_eeprom_del_num =
127 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_del_result, n,
130 const char PROGMEM help_eeprom_del[] = "delete an eeprom init command";
131 const parse_inst_t PROGMEM cmd_eeprom_del = {
132 .f = cmd_eeprom_del_parsed, /* function to call */
133 .data = NULL, /* 2nd arg of func */
134 .help_str = help_eeprom_del,
135 .tokens = { /* token list, NULL terminated */
136 (PGM_P)&cmd_eeprom_del_cmd,
137 (PGM_P)&cmd_eeprom_del_action,
138 (PGM_P)&cmd_eeprom_del_num,
145 struct cmd_eeprom_add_result {
147 fixed_string_t action;
151 static void cmd_eeprom_add_parsed(void *parsed_result,
154 struct cmd_eeprom_add_result *res = parsed_result;
160 rdline_init(&rdl, cmdline_write_char, NULL, NULL);
161 rdline_newline(&rdl, "> ");
164 c = cmdline_dev_recv(NULL);
168 ret = rdline_char_in(&rdl, c);
170 printf_P(PSTR("abort\n"));
177 buffer = rdline_get_buffer(&rdl);
179 eeprom_insert_cmd_before(buffer, res->n);
181 eeprom_append_cmd(buffer);
185 const char PROGMEM str_eeprom_add_eeprom[] = "eeprom";
186 const parse_token_string_t PROGMEM cmd_eeprom_add_cmd =
187 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, cmd,
188 str_eeprom_add_eeprom);
189 const char PROGMEM str_eeprom_add_add[] = "add";
190 const parse_token_string_t PROGMEM cmd_eeprom_add_action =
191 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, action,
193 const parse_token_num_t PROGMEM cmd_eeprom_add_num =
194 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_add_result, n,
197 const char PROGMEM help_eeprom_add[] = "insert an eeprom init command";
198 const parse_inst_t PROGMEM cmd_eeprom_add = {
199 .f = cmd_eeprom_add_parsed, /* function to call */
200 .data = NULL, /* 2nd arg of func */
201 .help_str = help_eeprom_add,
202 .tokens = { /* token list, NULL terminated */
203 (PGM_P)&cmd_eeprom_add_cmd,
204 (PGM_P)&cmd_eeprom_add_action,
205 (PGM_P)&cmd_eeprom_add_num,
210 const char PROGMEM help_eeprom_add2[] = "append an eeprom init command";
211 const parse_inst_t PROGMEM cmd_eeprom_add2 = {
212 .f = cmd_eeprom_add_parsed, /* function to call */
213 .data = (void *)1, /* 2nd arg of func */
214 .help_str = help_eeprom_add2,
215 .tokens = { /* token list, NULL terminated */
216 (PGM_P)&cmd_eeprom_add_cmd,
217 (PGM_P)&cmd_eeprom_add_action,
224 struct cmd_eeprom_list_result {
226 fixed_string_t action;
229 static void cmd_eeprom_list_parsed(void *parsed_result,
237 const char PROGMEM str_eeprom_list_eeprom[] = "eeprom";
238 const parse_token_string_t PROGMEM cmd_eeprom_list_cmd =
239 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, cmd,
240 str_eeprom_list_eeprom);
241 const char PROGMEM str_eeprom_list_list[] = "list";
242 const parse_token_string_t PROGMEM cmd_eeprom_list_action =
243 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, action,
244 str_eeprom_list_list);
246 const char PROGMEM help_eeprom_list[] = "list all eeprom init commands";
247 const parse_inst_t PROGMEM cmd_eeprom_list = {
248 .f = cmd_eeprom_list_parsed, /* function to call */
249 .data = NULL, /* 2nd arg of func */
250 .help_str = help_eeprom_list,
251 .tokens = { /* token list, NULL terminated */
252 (PGM_P)&cmd_eeprom_list_cmd,
253 (PGM_P)&cmd_eeprom_list_action,
260 struct cmd_gps_show_result {
262 fixed_string_t action;
265 static void cmd_gps_show_parsed(void *parsed_result,
271 while (!cmdline_keypressed()) {
276 const char PROGMEM str_gps_show_gps[] = "gps";
277 const parse_token_string_t PROGMEM cmd_gps_show_cmd =
278 TOKEN_STRING_INITIALIZER(struct cmd_gps_show_result, cmd,
280 const char PROGMEM str_gps_show_show[] = "show";
281 const parse_token_string_t PROGMEM cmd_gps_show_action =
282 TOKEN_STRING_INITIALIZER(struct cmd_gps_show_result, action,
285 const char PROGMEM help_gps_show[] = "show gps position";
286 const parse_inst_t PROGMEM cmd_gps_show = {
287 .f = cmd_gps_show_parsed, /* function to call */
288 .data = NULL, /* 2nd arg of func */
289 .help_str = help_gps_show,
290 .tokens = { /* token show, NULL terminated */
291 (PGM_P)&cmd_gps_show_cmd,
292 (PGM_P)&cmd_gps_show_action,
299 struct cmd_imu_show_result {
301 fixed_string_t action;
304 static void cmd_imu_show_parsed(void *parsed_result,
310 while (!cmdline_keypressed()) {
315 const char PROGMEM str_imu_show_imu[] = "imu";
316 const parse_token_string_t PROGMEM cmd_imu_show_cmd =
317 TOKEN_STRING_INITIALIZER(struct cmd_imu_show_result, cmd,
319 const char PROGMEM str_imu_show_show[] = "show";
320 const parse_token_string_t PROGMEM cmd_imu_show_action =
321 TOKEN_STRING_INITIALIZER(struct cmd_imu_show_result, action,
324 const char PROGMEM help_imu_show[] = "show imu position";
325 const parse_inst_t PROGMEM cmd_imu_show = {
326 .f = cmd_imu_show_parsed, /* function to call */
327 .data = NULL, /* 2nd arg of func */
328 .help_str = help_imu_show,
329 .tokens = { /* token show, NULL terminated */
330 (PGM_P)&cmd_imu_show_cmd,
331 (PGM_P)&cmd_imu_show_action,
340 const parse_ctx_t PROGMEM main_ctx[] = {
350 &cmd_test_eeprom_config,