2 * Copyright Droids Corporation (2009)
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.7 2009-04-24 19:30:41 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
26 #include <aversive/pgmspace.h>
27 #include <aversive/wait.h>
28 #include <aversive/error.h>
34 #include <parse_string.h>
35 #include <vect_base.h>
42 /**********************************************************/
45 /* this structure is filled when cmd_reset is parsed successfully */
46 struct cmd_reset_result {
50 /* function called when cmd_reset is parsed successfully */
51 static void cmd_reset_parsed(__attribute__((unused)) void *parsed_result,
52 __attribute__((unused)) void *data)
57 prog_char str_reset_arg0[] = "reset";
58 parse_pgm_token_string_t cmd_reset_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_reset_result, arg0, str_reset_arg0);
60 prog_char help_reset[] = "Reset the board";
61 parse_pgm_inst_t cmd_reset = {
62 .f = cmd_reset_parsed, /* function to call */
63 .data = NULL, /* 2nd arg of func */
64 .help_str = help_reset,
65 .tokens = { /* token list, NULL terminated */
66 (prog_void *)&cmd_reset_arg0,
71 /**********************************************************/
74 /* this structure is filled when cmd_debug_frame is parsed successfully */
75 struct cmd_debug_frame_result {
80 /* function called when cmd_debug_frame is parsed successfully */
81 static void cmd_debug_frame_parsed(void *parsed_result,
82 __attribute__((unused)) void *data)
84 struct cmd_debug_frame_result *res = parsed_result;
85 if (!strcmp_P(res->arg1, PSTR("on")))
86 beacon_tsop.debug_frame = 1;
88 beacon_tsop.debug_frame = 0;
91 prog_char str_debug_frame_arg0[] = "debug_frame";
92 parse_pgm_token_string_t cmd_debug_frame_arg0 =
93 TOKEN_STRING_INITIALIZER(struct cmd_debug_frame_result,
94 arg0, str_debug_frame_arg0);
95 prog_char str_debug_frame_arg1[] = "on#off";
96 parse_pgm_token_string_t cmd_debug_frame_arg1 =
97 TOKEN_STRING_INITIALIZER(struct cmd_debug_frame_result,
98 arg1, str_debug_frame_arg1);
100 prog_char help_debug_frame[] = "Enable frame debug [debug_frame on|off]";
101 parse_pgm_inst_t cmd_debug_frame = {
102 .f = cmd_debug_frame_parsed, /* function to call */
103 .data = NULL, /* 2nd arg of func */
104 .help_str = help_debug_frame,
105 .tokens = { /* token list, NULL terminated */
106 (prog_void *)&cmd_debug_frame_arg0,
107 (prog_void *)&cmd_debug_frame_arg1,
112 /**********************************************************/
115 /* this structure is filled when cmd_debug_speed is parsed successfully */
116 struct cmd_debug_speed_result {
121 /* function called when cmd_debug_speed is parsed successfully */
122 static void cmd_debug_speed_parsed(void *parsed_result,
123 __attribute__((unused)) void *data)
125 struct cmd_debug_speed_result *res = parsed_result;
126 if (!strcmp_P(res->arg1, PSTR("on")))
127 beacon_tsop.debug_speed = 1;
129 beacon_tsop.debug_speed = 0;
132 prog_char str_debug_speed_arg0[] = "debug_speed";
133 parse_pgm_token_string_t cmd_debug_speed_arg0 =
134 TOKEN_STRING_INITIALIZER(struct cmd_debug_speed_result,
135 arg0, str_debug_speed_arg0);
136 prog_char str_debug_speed_arg1[] = "on#off";
137 parse_pgm_token_string_t cmd_debug_speed_arg1 =
138 TOKEN_STRING_INITIALIZER(struct cmd_debug_speed_result,
139 arg1, str_debug_speed_arg1);
141 prog_char help_debug_speed[] = "Enable speed debug [debug_speed on|off]";
142 parse_pgm_inst_t cmd_debug_speed = {
143 .f = cmd_debug_speed_parsed, /* function to call */
144 .data = NULL, /* 2nd arg of func */
145 .help_str = help_debug_speed,
146 .tokens = { /* token list, NULL terminated */
147 (prog_void *)&cmd_debug_speed_arg0,
148 (prog_void *)&cmd_debug_speed_arg1,
153 /**********************************************************/
156 /* this structure is filled when cmd_test is parsed successfully */
157 struct cmd_test_result {
161 /* function called when cmd_test is parsed successfully */
162 static void cmd_test_parsed(__attribute__((unused)) void *parsed_result,
163 __attribute__((unused)) void *data)
169 uint16_t time1, time2;
175 if (angles_to_posxy(&pos, a01, a12, a20) < 0)
176 printf_P(PSTR("error\n"));
182 printf_P(PSTR("%2.2f %2.2f (t=%d)\n"), pos.x, pos.y, time2-time1);
185 prog_char str_test_arg0[] = "test";
186 parse_pgm_token_string_t cmd_test_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_test_result, arg0, str_test_arg0);
188 prog_char help_test[] = "Test the board";
189 parse_pgm_inst_t cmd_test = {
190 .f = cmd_test_parsed, /* function to call */
191 .data = NULL, /* 2nd arg of func */
192 .help_str = help_test,
193 .tokens = { /* token list, NULL terminated */
194 (prog_void *)&cmd_test_arg0,
199 /**********************************************************/
201 extern parse_pgm_inst_t cmd_gain;
202 extern parse_pgm_inst_t cmd_gain_show;
203 extern parse_pgm_inst_t cmd_derivate_filter;
204 extern parse_pgm_inst_t cmd_derivate_filter_show;
205 extern parse_pgm_inst_t cmd_maximum;
206 extern parse_pgm_inst_t cmd_maximum_show;
207 extern parse_pgm_inst_t cmd_consign;
208 extern parse_pgm_inst_t cmd_consign_show;
211 parse_pgm_ctx_t main_ctx[] = {
214 (parse_pgm_inst_t *)&cmd_reset,
215 (parse_pgm_inst_t *)&cmd_debug_frame,
216 (parse_pgm_inst_t *)&cmd_debug_speed,
217 (parse_pgm_inst_t *)&cmd_test,
219 (parse_pgm_inst_t *)&cmd_gain,
220 (parse_pgm_inst_t *)&cmd_gain_show,
221 (parse_pgm_inst_t *)&cmd_derivate_filter,
222 (parse_pgm_inst_t *)&cmd_derivate_filter_show,
223 (parse_pgm_inst_t *)&cmd_maximum,
224 (parse_pgm_inst_t *)&cmd_maximum_show,
225 (parse_pgm_inst_t *)&cmd_consign,
226 (parse_pgm_inst_t *)&cmd_consign_show,