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_gen.c,v 1.8 2009-11-08 17:24:33 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
26 #include <aversive/pgmspace.h>
27 #include <aversive/wait.h>
28 #include <aversive/error.h>
29 #include <aversive/queue.h>
32 #include <clock_time.h>
34 #include <scheduler.h>
35 #include <scheduler_stats.h>
39 #include <parse_string.h>
40 #include <parse_num.h>
42 #include <diagnostic.h>
48 /**********************************************************/
51 /* this structure is filled when cmd_reset is parsed successfully */
52 struct cmd_reset_result {
56 /* function called when cmd_reset is parsed successfully */
57 static void cmd_reset_parsed(void * parsed_result, void * data)
65 prog_char str_reset_arg0[] = "reset";
66 parse_pgm_token_string_t cmd_reset_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_reset_result, arg0, str_reset_arg0);
68 prog_char help_reset[] = "Reset the board";
69 parse_pgm_inst_t cmd_reset = {
70 .f = cmd_reset_parsed, /* function to call */
71 .data = NULL, /* 2nd arg of func */
72 .help_str = help_reset,
73 .tokens = { /* token list, NULL terminated */
74 (prog_void *)&cmd_reset_arg0,
79 /**********************************************************/
82 /* this structure is filled when cmd_bootloader is parsed successfully */
83 struct cmd_bootloader_result {
87 /* function called when cmd_bootloader is parsed successfully */
88 static void cmd_bootloader_parsed(void *parsed_result, void *data)
93 printf("not implemented\n");
97 prog_char str_bootloader_arg0[] = "bootloader";
98 parse_pgm_token_string_t cmd_bootloader_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_bootloader_result, arg0, str_bootloader_arg0);
100 prog_char help_bootloader[] = "Launch the bootloader";
101 parse_pgm_inst_t cmd_bootloader = {
102 .f = cmd_bootloader_parsed, /* function to call */
103 .data = NULL, /* 2nd arg of func */
104 .help_str = help_bootloader,
105 .tokens = { /* token list, NULL terminated */
106 (prog_void *)&cmd_bootloader_arg0,
111 /**********************************************************/
114 /* this structure is filled when cmd_scheduler is parsed successfully */
115 struct cmd_scheduler_result {
120 /* function called when cmd_scheduler is parsed successfully */
121 static void cmd_scheduler_parsed(void *parsed_result, void *data)
123 scheduler_dump_events();
124 scheduler_stats_dump();
127 prog_char str_scheduler_arg0[] = "scheduler";
128 parse_pgm_token_string_t cmd_scheduler_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_scheduler_result, arg0, str_scheduler_arg0);
129 prog_char str_scheduler_arg1[] = "show";
130 parse_pgm_token_string_t cmd_scheduler_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_scheduler_result, arg1, str_scheduler_arg1);
132 prog_char help_scheduler[] = "Show scheduler events";
133 parse_pgm_inst_t cmd_scheduler = {
134 .f = cmd_scheduler_parsed, /* function to call */
135 .data = NULL, /* 2nd arg of func */
136 .help_str = help_scheduler,
137 .tokens = { /* token list, NULL terminated */
138 (prog_void *)&cmd_scheduler_arg0,
139 (prog_void *)&cmd_scheduler_arg1,
144 /**********************************************************/
147 /* this structure is filled when cmd_log is parsed successfully */
148 struct cmd_log_result {
155 /* keep it sync with string choice */
156 static const prog_char uart_log[] = "uart";
157 static const prog_char i2c_log[] = "i2c";
158 static const prog_char default_log[] = "default";
160 struct log_name_and_num {
161 const prog_char * name;
165 static const struct log_name_and_num log_name_and_num[] = {
166 { uart_log, E_UART },
168 { default_log, E_USER_DEFAULT },
172 log_name2num(const char * s)
176 for (i=0; i<sizeof(log_name_and_num)/sizeof(struct log_name_and_num); i++) {
177 if (!strcmp_P(s, log_name_and_num[i].name)) {
178 return log_name_and_num[i].num;
185 log_num2name(uint8_t num)
189 for (i=0; i<sizeof(log_name_and_num)/sizeof(struct log_name_and_num); i++) {
190 if (num == log_name_and_num[i].num) {
191 return log_name_and_num[i].name;
197 /* function called when cmd_log is parsed successfully */
198 static void cmd_log_do_show(void)
201 const prog_char * name;
203 printf_P(PSTR("log level is %d\r\n"), xbeeboard.log_level);
204 for (i=0; i<NB_LOGS; i++) {
205 name = log_num2name(xbeeboard.logs[i]);
208 printf_P(PSTR("log type %s is on\r\n"), name);
210 printf_P(PSTR("log type %S is on\r\n"), name);
216 printf_P(PSTR("no log configured\r\n"));
219 /* function called when cmd_log is parsed successfully */
220 static void cmd_log_parsed(void * parsed_result, void * data)
222 struct cmd_log_result *res = (struct cmd_log_result *) parsed_result;
224 if (!strcmp_P(res->arg1, PSTR("level"))) {
225 xbeeboard.log_level = res->arg2;
228 /* else it is a show */
232 prog_char str_log_arg0[] = "log";
233 parse_pgm_token_string_t cmd_log_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg0, str_log_arg0);
234 prog_char str_log_arg1[] = "level";
235 parse_pgm_token_string_t cmd_log_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg1, str_log_arg1);
236 parse_pgm_token_num_t cmd_log_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT8);
238 prog_char help_log[] = "Set log options: level (0 -> 5)";
239 parse_pgm_inst_t cmd_log = {
240 .f = cmd_log_parsed, /* function to call */
241 .data = NULL, /* 2nd arg of func */
242 .help_str = help_log,
243 .tokens = { /* token list, NULL terminated */
244 (prog_void *)&cmd_log_arg0,
245 (prog_void *)&cmd_log_arg1,
246 (prog_void *)&cmd_log_arg2,
251 prog_char str_log_arg1_show[] = "show";
252 parse_pgm_token_string_t cmd_log_arg1_show = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg1, str_log_arg1_show);
254 prog_char help_log_show[] = "Show configured logs";
255 parse_pgm_inst_t cmd_log_show = {
256 .f = cmd_log_parsed, /* function to call */
257 .data = NULL, /* 2nd arg of func */
258 .help_str = help_log_show,
259 .tokens = { /* token list, NULL terminated */
260 (prog_void *)&cmd_log_arg0,
261 (prog_void *)&cmd_log_arg1_show,
266 /* this structure is filled when cmd_log is parsed successfully */
267 struct cmd_log_type_result {
274 /* function called when cmd_log is parsed successfully */
275 static void cmd_log_type_parsed(void * parsed_result, void * data)
277 struct cmd_log_type_result *res = (struct cmd_log_type_result *) parsed_result;
281 lognum = log_name2num(res->arg2);
283 printf_P(PSTR("Cannot find log num\r\n"));
287 if (!strcmp_P(res->arg3, PSTR("on"))) {
288 for (i=0; i<NB_LOGS; i++) {
289 if (xbeeboard.logs[i] == lognum) {
290 printf_P(PSTR("Already on\r\n"));
294 for (i=0; i<NB_LOGS; i++) {
295 if (xbeeboard.logs[i] == 0) {
296 xbeeboard.logs[i] = lognum;
301 printf_P(PSTR("no more room\r\n"));
304 else if (!strcmp_P(res->arg3, PSTR("off"))) {
305 for (i=0; i<NB_LOGS; i++) {
306 if (xbeeboard.logs[i] == lognum) {
307 xbeeboard.logs[i] = 0;
312 printf_P(PSTR("already off\r\n"));
318 prog_char str_log_arg1_type[] = "type";
319 parse_pgm_token_string_t cmd_log_arg1_type = TOKEN_STRING_INITIALIZER(struct cmd_log_type_result, arg1, str_log_arg1_type);
320 /* keep it sync with log_name_and_num above */
321 prog_char str_log_arg2_type[] = "uart#rs#servo#traj#i2c#oa#strat#i2cproto#ext#sensor#bd#cs";
322 parse_pgm_token_string_t cmd_log_arg2_type = TOKEN_STRING_INITIALIZER(struct cmd_log_type_result, arg2, str_log_arg2_type);
323 prog_char str_log_arg3[] = "on#off";
324 parse_pgm_token_string_t cmd_log_arg3 = TOKEN_STRING_INITIALIZER(struct cmd_log_type_result, arg3, str_log_arg3);
326 prog_char help_log_type[] = "Set log type";
327 parse_pgm_inst_t cmd_log_type = {
328 .f = cmd_log_type_parsed, /* function to call */
329 .data = NULL, /* 2nd arg of func */
330 .help_str = help_log_type,
331 .tokens = { /* token list, NULL terminated */
332 (prog_void *)&cmd_log_arg0,
333 (prog_void *)&cmd_log_arg1_type,
334 (prog_void *)&cmd_log_arg2_type,
335 (prog_void *)&cmd_log_arg3,
341 /**********************************************************/
344 /* this structure is filled when cmd_stack_space is parsed successfully */
345 struct cmd_stack_space_result {
349 /* function called when cmd_stack_space is parsed successfully */
350 static void cmd_stack_space_parsed(void *parsed_result, void *data)
353 printf("not implemented\n");
355 printf("res stack: %d\r\n", min_stack_space_available());
359 prog_char str_stack_space_arg0[] = "stack_space";
360 parse_pgm_token_string_t cmd_stack_space_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_stack_space_result, arg0, str_stack_space_arg0);
362 prog_char help_stack_space[] = "Display remaining stack space";
363 parse_pgm_inst_t cmd_stack_space = {
364 .f = cmd_stack_space_parsed, /* function to call */
365 .data = NULL, /* 2nd arg of func */
366 .help_str = help_stack_space,
367 .tokens = { /* token list, NULL terminated */
368 (prog_void *)&cmd_stack_space_arg0,