X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fsensorboard%2Fcommands_gen.c;fp=projects%2Fmicrob2010%2Fsensorboard%2Fcommands_gen.c;h=0000000000000000000000000000000000000000;hp=9f7cdd6faa9d7d2a9a0c176fe6ce45759818539d;hb=8d6a47e9e21a9a31f4bc12d32fb3d11091a4b305;hpb=821f753c0f88aff895d9feae59c442a6c446f96b diff --git a/projects/microb2010/sensorboard/commands_gen.c b/projects/microb2010/sensorboard/commands_gen.c deleted file mode 100644 index 9f7cdd6..0000000 --- a/projects/microb2010/sensorboard/commands_gen.c +++ /dev/null @@ -1,573 +0,0 @@ -/* - * Copyright Droids Corporation (2008) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - * - * Revision : $Id: commands_gen.c,v 1.4 2009-05-27 20:04:07 zer0 Exp $ - * - * Olivier MATZ - */ - -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include - -#include "main.h" -#include "cmdline.h" -#include "sensor.h" - -/**********************************************************/ -/* Reset */ - -/* this structure is filled when cmd_reset is parsed successfully */ -struct cmd_reset_result { - fixed_string_t arg0; -}; - -/* function called when cmd_reset is parsed successfully */ -static void cmd_reset_parsed(void * parsed_result, void * data) -{ - reset(); -} - -prog_char str_reset_arg0[] = "reset"; -parse_pgm_token_string_t cmd_reset_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_reset_result, arg0, str_reset_arg0); - -prog_char help_reset[] = "Reset the board"; -parse_pgm_inst_t cmd_reset = { - .f = cmd_reset_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_reset, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_reset_arg0, - NULL, - }, -}; - -/**********************************************************/ -/* Bootloader */ - -/* this structure is filled when cmd_bootloader is parsed successfully */ -struct cmd_bootloader_result { - fixed_string_t arg0; -}; - -/* function called when cmd_bootloader is parsed successfully */ -static void cmd_bootloader_parsed(void *parsed_result, void *data) -{ - bootloader(); -} - -prog_char str_bootloader_arg0[] = "bootloader"; -parse_pgm_token_string_t cmd_bootloader_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_bootloader_result, arg0, str_bootloader_arg0); - -prog_char help_bootloader[] = "Launch the bootloader"; -parse_pgm_inst_t cmd_bootloader = { - .f = cmd_bootloader_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_bootloader, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_bootloader_arg0, - NULL, - }, -}; - -/**********************************************************/ -/* Encoders tests */ - -/* this structure is filled when cmd_encoders is parsed successfully */ -struct cmd_encoders_result { - fixed_string_t arg0; - fixed_string_t arg1; -}; - -/* function called when cmd_encoders is parsed successfully */ -static void cmd_encoders_parsed(void *parsed_result, void *data) -{ - struct cmd_encoders_result *res = parsed_result; - - if (!strcmp_P(res->arg1, PSTR("reset"))) { - encoders_spi_set_value((void *)0, 0); - encoders_spi_set_value((void *)1, 0); - encoders_spi_set_value((void *)2, 0); - encoders_spi_set_value((void *)3, 0); - return; - } - - /* show */ - while(!cmdline_keypressed()) { - printf_P(PSTR("% .8ld % .8ld % .8ld % .8ld\r\n"), - encoders_spi_get_value((void *)0), - encoders_spi_get_value((void *)1), - encoders_spi_get_value((void *)2), - encoders_spi_get_value((void *)3)); - wait_ms(100); - } -} - -prog_char str_encoders_arg0[] = "encoders"; -parse_pgm_token_string_t cmd_encoders_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_encoders_result, arg0, str_encoders_arg0); -prog_char str_encoders_arg1[] = "show#reset"; -parse_pgm_token_string_t cmd_encoders_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_encoders_result, arg1, str_encoders_arg1); - -prog_char help_encoders[] = "Show encoders values"; -parse_pgm_inst_t cmd_encoders = { - .f = cmd_encoders_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_encoders, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_encoders_arg0, - (prog_void *)&cmd_encoders_arg1, - NULL, - }, -}; - -/**********************************************************/ -/* Scheduler show */ - -/* this structure is filled when cmd_scheduler is parsed successfully */ -struct cmd_scheduler_result { - fixed_string_t arg0; - fixed_string_t arg1; -}; - -/* function called when cmd_scheduler is parsed successfully */ -static void cmd_scheduler_parsed(void *parsed_result, void *data) -{ - scheduler_dump_events(); -} - -prog_char str_scheduler_arg0[] = "scheduler"; -parse_pgm_token_string_t cmd_scheduler_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_scheduler_result, arg0, str_scheduler_arg0); -prog_char str_scheduler_arg1[] = "show"; -parse_pgm_token_string_t cmd_scheduler_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_scheduler_result, arg1, str_scheduler_arg1); - -prog_char help_scheduler[] = "Show scheduler events"; -parse_pgm_inst_t cmd_scheduler = { - .f = cmd_scheduler_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_scheduler, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_scheduler_arg0, - (prog_void *)&cmd_scheduler_arg1, - NULL, - }, -}; - -/**********************************************************/ -/* Pwms tests */ - -/* this structure is filled when cmd_pwm is parsed successfully */ -struct cmd_pwm_result { - fixed_string_t arg0; - fixed_string_t arg1; - int16_t arg2; -}; - -/* function called when cmd_pwm is parsed successfully */ -static void cmd_pwm_parsed(void * parsed_result, void * data) -{ - void * pwm_ptr = NULL; - struct cmd_pwm_result * res = parsed_result; - - if (!strcmp_P(res->arg1, PSTR("1(4A)"))) - pwm_ptr = &gen.pwm1_4A; - else if (!strcmp_P(res->arg1, PSTR("2(4B)"))) - pwm_ptr = &gen.pwm2_4B; - else if (!strcmp_P(res->arg1, PSTR("3(1A)"))) - pwm_ptr = &gen.pwm3_1A; - else if (!strcmp_P(res->arg1, PSTR("4(1B)"))) - pwm_ptr = &gen.pwm4_1B; - - else if (!strcmp_P(res->arg1, PSTR("s1(3C)"))) - pwm_ptr = &gen.servo1; - else if (!strcmp_P(res->arg1, PSTR("s2(5A)"))) - pwm_ptr = &gen.servo2; - else if (!strcmp_P(res->arg1, PSTR("s3(5B)"))) - pwm_ptr = &gen.servo3; - else if (!strcmp_P(res->arg1, PSTR("s3(5C)"))) - pwm_ptr = &gen.servo4; - - if (pwm_ptr) - pwm_ng_set(pwm_ptr, res->arg2); - - printf_P(PSTR("done\r\n")); -} - -prog_char str_pwm_arg0[] = "pwm"; -parse_pgm_token_string_t cmd_pwm_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_pwm_result, arg0, str_pwm_arg0); -prog_char str_pwm_arg1[] = "1(4A)#2(4B)#3(1A)#4(1B)#s1(3C)#s2(5A)#s3(5B)#s4(5C)"; -parse_pgm_token_string_t cmd_pwm_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_pwm_result, arg1, str_pwm_arg1); -parse_pgm_token_num_t cmd_pwm_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_pwm_result, arg2, INT16); - -prog_char help_pwm[] = "Set pwm values [-4096 ; 4095]"; -parse_pgm_inst_t cmd_pwm = { - .f = cmd_pwm_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_pwm, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_pwm_arg0, - (prog_void *)&cmd_pwm_arg1, - (prog_void *)&cmd_pwm_arg2, - NULL, - }, -}; - -/**********************************************************/ -/* Adcs tests */ - -/* this structure is filled when cmd_adc is parsed successfully */ -struct cmd_adc_result { - fixed_string_t arg0; - fixed_string_t arg1; -}; - -/* function called when cmd_adc is parsed successfully */ -static void cmd_adc_parsed(void *parsed_result, void *data) -{ - struct cmd_adc_result *res = parsed_result; - uint8_t i, loop = 0; - - if (!strcmp_P(res->arg1, PSTR("loop_show"))) - loop = 1; - - do { - printf_P(PSTR("ADC values: ")); - for (i=0; iarg1, PSTR("loop_show"))) - loop = 1; - - do { - printf_P(PSTR("SENSOR values: ")); - for (i=0; iarg1, PSTR("level"))) { - gen.log_level = res->arg2; - } - - /* else it is a show */ - cmd_log_do_show(); -} - -prog_char str_log_arg0[] = "log"; -parse_pgm_token_string_t cmd_log_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg0, str_log_arg0); -prog_char str_log_arg1[] = "level"; -parse_pgm_token_string_t cmd_log_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg1, str_log_arg1); -parse_pgm_token_num_t cmd_log_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_log_result, arg2, INT32); - -prog_char help_log[] = "Set log options: level (0 -> 5)"; -parse_pgm_inst_t cmd_log = { - .f = cmd_log_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_log, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_log_arg0, - (prog_void *)&cmd_log_arg1, - (prog_void *)&cmd_log_arg2, - NULL, - }, -}; - -prog_char str_log_arg1_show[] = "show"; -parse_pgm_token_string_t cmd_log_arg1_show = TOKEN_STRING_INITIALIZER(struct cmd_log_result, arg1, str_log_arg1_show); - -prog_char help_log_show[] = "Show configured logs"; -parse_pgm_inst_t cmd_log_show = { - .f = cmd_log_parsed, /* function to call */ - .data = NULL, /* 2nd arg of func */ - .help_str = help_log_show, - .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_log_arg0, - (prog_void *)&cmd_log_arg1_show, - NULL, - }, -}; - -/* this structure is filled when cmd_log is parsed successfully */ -struct cmd_log_type_result { - fixed_string_t arg0; - fixed_string_t arg1; - fixed_string_t arg2; - fixed_string_t arg3; -}; - -/* function called when cmd_log is parsed successfully */ -static void cmd_log_type_parsed(void * parsed_result, void * data) -{ - struct cmd_log_type_result *res = (struct cmd_log_type_result *) parsed_result; - uint8_t lognum; - uint8_t i; - - lognum = log_name2num(res->arg2); - if (lognum == 0) { - printf_P(PSTR("Cannot find log num\r\n")); - return; - } - - if (!strcmp_P(res->arg3, PSTR("on"))) { - for (i=0; iarg3, PSTR("off"))) { - for (i=0; i