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>
42 #include "eeprom_config.h"
47 extern const parse_inst_t PROGMEM cmd_reset;
48 extern const parse_inst_t PROGMEM cmd_bootloader;
49 extern const parse_inst_t PROGMEM cmd_log;
50 extern const parse_inst_t PROGMEM cmd_log_show;
51 extern const parse_inst_t PROGMEM cmd_log_type;
52 extern const parse_inst_t PROGMEM cmd_stack_space;
53 extern const parse_inst_t PROGMEM cmd_callout;
55 /**********************************************************/
57 /* this structure is filled when cmd_test_eeprom_config is parsed successfully */
58 struct cmd_test_eeprom_config_result {
62 static void cmd_test_eeprom_config_parsed(void *parsed_result, void *data)
68 eeprom_append_cmd("salut1\n");
70 eeprom_append_cmd("salut2\n");
71 eeprom_append_cmd("salut3\n");
72 eeprom_append_cmd("salut4\n");
74 eeprom_insert_cmd_before("coin\n", 0);
75 eeprom_insert_cmd_before("coin2\n", 2);
82 const char PROGMEM str_test_eeprom_config_arg0[] = "test_eeprom_config";
83 const parse_token_string_t PROGMEM cmd_test_eeprom_config_arg0 =
84 TOKEN_STRING_INITIALIZER(struct cmd_test_eeprom_config_result, arg0,
85 str_test_eeprom_config_arg0);
87 const char PROGMEM help_test_eeprom_config[] = "Test the eeprom configuration";
88 const parse_inst_t PROGMEM cmd_test_eeprom_config = {
89 .f = cmd_test_eeprom_config_parsed, /* function to call */
90 .data = NULL, /* 2nd arg of func */
91 .help_str = help_test_eeprom_config,
92 .tokens = { /* token list, NULL terminated */
93 (PGM_P)&cmd_test_eeprom_config_arg0,
100 struct cmd_eeprom_del_result {
102 fixed_string_t action;
106 static void cmd_eeprom_del_parsed(void *parsed_result,
109 struct cmd_eeprom_del_result *res = parsed_result;
112 if (eeprom_delete_cmd(res->n) < 0)
113 printf_P(PSTR("cannot delete command\n"));
117 const char PROGMEM str_eeprom_del_eeprom[] = "eeprom";
118 const parse_token_string_t PROGMEM cmd_eeprom_del_cmd =
119 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, cmd,
120 str_eeprom_del_eeprom);
121 const char PROGMEM str_eeprom_del_del[] = "del";
122 const parse_token_string_t PROGMEM cmd_eeprom_del_action =
123 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, action,
125 const parse_token_num_t PROGMEM cmd_eeprom_del_num =
126 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_del_result, n,
129 const char PROGMEM help_eeprom_del[] = "delete an eeprom init command";
130 const parse_inst_t PROGMEM cmd_eeprom_del = {
131 .f = cmd_eeprom_del_parsed, /* function to call */
132 .data = NULL, /* 2nd arg of func */
133 .help_str = help_eeprom_del,
134 .tokens = { /* token list, NULL terminated */
135 (PGM_P)&cmd_eeprom_del_cmd,
136 (PGM_P)&cmd_eeprom_del_action,
137 (PGM_P)&cmd_eeprom_del_num,
144 struct cmd_eeprom_add_result {
146 fixed_string_t action;
150 static void cmd_eeprom_add_parsed(void *parsed_result,
153 struct cmd_eeprom_add_result *res = parsed_result;
159 rdline_init(&rdl, cmdline_write_char, NULL, NULL);
160 rdline_newline(&rdl, "> ");
163 c = cmdline_dev_recv(NULL);
167 ret = rdline_char_in(&rdl, c);
169 printf_P(PSTR("abort\n"));
176 buffer = rdline_get_buffer(&rdl);
178 eeprom_insert_cmd_before(buffer, res->n);
180 eeprom_append_cmd(buffer);
184 const char PROGMEM str_eeprom_add_eeprom[] = "eeprom";
185 const parse_token_string_t PROGMEM cmd_eeprom_add_cmd =
186 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, cmd,
187 str_eeprom_add_eeprom);
188 const char PROGMEM str_eeprom_add_add[] = "add";
189 const parse_token_string_t PROGMEM cmd_eeprom_add_action =
190 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, action,
192 const parse_token_num_t PROGMEM cmd_eeprom_add_num =
193 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_add_result, n,
196 const char PROGMEM help_eeprom_add[] = "insert an eeprom init command";
197 const parse_inst_t PROGMEM cmd_eeprom_add = {
198 .f = cmd_eeprom_add_parsed, /* function to call */
199 .data = NULL, /* 2nd arg of func */
200 .help_str = help_eeprom_add,
201 .tokens = { /* token list, NULL terminated */
202 (PGM_P)&cmd_eeprom_add_cmd,
203 (PGM_P)&cmd_eeprom_add_action,
204 (PGM_P)&cmd_eeprom_add_num,
209 const char PROGMEM help_eeprom_add2[] = "append an eeprom init command";
210 const parse_inst_t PROGMEM cmd_eeprom_add2 = {
211 .f = cmd_eeprom_add_parsed, /* function to call */
212 .data = (void *)1, /* 2nd arg of func */
213 .help_str = help_eeprom_add2,
214 .tokens = { /* token list, NULL terminated */
215 (PGM_P)&cmd_eeprom_add_cmd,
216 (PGM_P)&cmd_eeprom_add_action,
223 struct cmd_eeprom_list_result {
225 fixed_string_t action;
228 static void cmd_eeprom_list_parsed(void *parsed_result,
231 struct cmd_eeprom_list_result *res = parsed_result;
234 if (!strcmp_P(PSTR("list"), res->cmd))
240 const char PROGMEM str_eeprom_list_eeprom[] = "eeprom";
241 const parse_token_string_t PROGMEM cmd_eeprom_list_cmd =
242 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, cmd,
243 str_eeprom_list_eeprom);
244 const char PROGMEM str_eeprom_list_list[] = "list#reset";
245 const parse_token_string_t PROGMEM cmd_eeprom_list_action =
246 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, action,
247 str_eeprom_list_list);
249 const char PROGMEM help_eeprom_list[] = "list all eeprom init commands";
250 const parse_inst_t PROGMEM cmd_eeprom_list = {
251 .f = cmd_eeprom_list_parsed, /* function to call */
252 .data = NULL, /* 2nd arg of func */
253 .help_str = help_eeprom_list,
254 .tokens = { /* token list, NULL terminated */
255 (PGM_P)&cmd_eeprom_list_cmd,
256 (PGM_P)&cmd_eeprom_list_action,
263 struct cmd_gps_show_result {
265 fixed_string_t action;
268 static void cmd_gps_show_parsed(void *parsed_result,
274 while (!cmdline_keypressed()) {
279 const char PROGMEM str_gps_show_gps[] = "gps";
280 const parse_token_string_t PROGMEM cmd_gps_show_cmd =
281 TOKEN_STRING_INITIALIZER(struct cmd_gps_show_result, cmd,
283 const char PROGMEM str_gps_show_show[] = "show";
284 const parse_token_string_t PROGMEM cmd_gps_show_action =
285 TOKEN_STRING_INITIALIZER(struct cmd_gps_show_result, action,
288 const char PROGMEM help_gps_show[] = "show gps position";
289 const parse_inst_t PROGMEM cmd_gps_show = {
290 .f = cmd_gps_show_parsed, /* function to call */
291 .data = NULL, /* 2nd arg of func */
292 .help_str = help_gps_show,
293 .tokens = { /* token show, NULL terminated */
294 (PGM_P)&cmd_gps_show_cmd,
295 (PGM_P)&cmd_gps_show_action,
302 struct cmd_imu_show_result {
304 fixed_string_t action;
307 static void cmd_imu_show_parsed(void *parsed_result,
313 while (!cmdline_keypressed()) {
318 const char PROGMEM str_imu_show_imu[] = "imu";
319 const parse_token_string_t PROGMEM cmd_imu_show_cmd =
320 TOKEN_STRING_INITIALIZER(struct cmd_imu_show_result, cmd,
322 const char PROGMEM str_imu_show_show[] = "show";
323 const parse_token_string_t PROGMEM cmd_imu_show_action =
324 TOKEN_STRING_INITIALIZER(struct cmd_imu_show_result, action,
327 const char PROGMEM help_imu_show[] = "show imu position";
328 const parse_inst_t PROGMEM cmd_imu_show = {
329 .f = cmd_imu_show_parsed, /* function to call */
330 .data = NULL, /* 2nd arg of func */
331 .help_str = help_imu_show,
332 .tokens = { /* token show, NULL terminated */
333 (PGM_P)&cmd_imu_show_cmd,
334 (PGM_P)&cmd_imu_show_action,
343 const parse_ctx_t PROGMEM main_ctx[] = {
353 &cmd_test_eeprom_config,