X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fballboard%2Fcommands_ballboard.c;h=ba570a466b305509ec15a4ed80dffe13e118688d;hp=03dc830462e62bbc81cd8c392038adce1de25ba2;hb=aa68be2d5d596693bda1109e4ccd6489f613b4f7;hpb=8d6a47e9e21a9a31f4bc12d32fb3d11091a4b305 diff --git a/projects/microb2010/ballboard/commands_ballboard.c b/projects/microb2010/ballboard/commands_ballboard.c index 03dc830..ba570a4 100644 --- a/projects/microb2010/ballboard/commands_ballboard.c +++ b/projects/microb2010/ballboard/commands_ballboard.c @@ -1,6 +1,6 @@ /* * Copyright Droids Corporation (2009) - * + * * 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 @@ -17,7 +17,7 @@ * * Revision : $Id: commands_ballboard.c,v 1.2 2009-04-24 19:30:42 zer0 Exp $ * - * Olivier MATZ + * Olivier MATZ */ #include @@ -44,6 +44,7 @@ #include #include "main.h" +#include "state.h" #include "cmdline.h" #include "../common/i2c_commands.h" #include "i2c_protocol.h" @@ -62,22 +63,24 @@ static void cmd_event_parsed(void *parsed_result, void *data) u08 bit=0; struct cmd_event_result * res = parsed_result; - + if (!strcmp_P(res->arg1, PSTR("all"))) { - bit = DO_ENCODERS | DO_CS | DO_BD | DO_POWER; + bit = 0xFF; if (!strcmp_P(res->arg2, PSTR("on"))) ballboard.flags |= bit; else if (!strcmp_P(res->arg2, PSTR("off"))) ballboard.flags &= bit; else { /* show */ - printf_P(PSTR("encoders is %s\r\n"), + printf_P(PSTR("encoders is %s\r\n"), (DO_ENCODERS & ballboard.flags) ? "on":"off"); - printf_P(PSTR("cs is %s\r\n"), + printf_P(PSTR("cs is %s\r\n"), (DO_CS & ballboard.flags) ? "on":"off"); - printf_P(PSTR("bd is %s\r\n"), + printf_P(PSTR("bd is %s\r\n"), (DO_BD & ballboard.flags) ? "on":"off"); - printf_P(PSTR("power is %s\r\n"), + printf_P(PSTR("power is %s\r\n"), (DO_POWER & ballboard.flags) ? "on":"off"); + printf_P(PSTR("errblock is %s\r\n"), + (DO_ERRBLOCKING & ballboard.flags) ? "on":"off"); } return; } @@ -91,6 +94,8 @@ static void cmd_event_parsed(void *parsed_result, void *data) bit = DO_BD; else if (!strcmp_P(res->arg1, PSTR("power"))) bit = DO_POWER; + else if (!strcmp_P(res->arg1, PSTR("errblock"))) + bit = DO_ERRBLOCKING; if (!strcmp_P(res->arg2, PSTR("on"))) @@ -103,13 +108,13 @@ static void cmd_event_parsed(void *parsed_result, void *data) } ballboard.flags &= (~bit); } - printf_P(PSTR("%s is %s\r\n"), res->arg1, + printf_P(PSTR("%s is %s\r\n"), res->arg1, (bit & ballboard.flags) ? "on":"off"); } prog_char str_event_arg0[] = "event"; parse_pgm_token_string_t cmd_event_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg0, str_event_arg0); -prog_char str_event_arg1[] = "all#encoders#cs#bd#power"; +prog_char str_event_arg1[] = "all#encoders#cs#bd#power#errblock"; parse_pgm_token_string_t cmd_event_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg1, str_event_arg1); prog_char str_event_arg2[] = "on#off#show"; parse_pgm_token_string_t cmd_event_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_event_result, arg2, str_event_arg2); @@ -120,9 +125,9 @@ parse_pgm_inst_t cmd_event = { .data = NULL, /* 2nd arg of func */ .help_str = help_event, .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_event_arg0, - (prog_void *)&cmd_event_arg1, - (prog_void *)&cmd_event_arg2, + (prog_void *)&cmd_event_arg0, + (prog_void *)&cmd_event_arg1, + (prog_void *)&cmd_event_arg2, NULL, }, }; @@ -140,18 +145,18 @@ struct cmd_color_result { static void cmd_color_parsed(void *parsed_result, void *data) { struct cmd_color_result *res = (struct cmd_color_result *) parsed_result; - if (!strcmp_P(res->color, PSTR("red"))) { - ballboard.our_color = I2C_COLOR_RED; + if (!strcmp_P(res->color, PSTR("yellow"))) { + ballboard.our_color = I2C_COLOR_YELLOW; } - else if (!strcmp_P(res->color, PSTR("green"))) { - ballboard.our_color = I2C_COLOR_GREEN; + else if (!strcmp_P(res->color, PSTR("blue"))) { + ballboard.our_color = I2C_COLOR_BLUE; } printf_P(PSTR("Done\r\n")); } prog_char str_color_arg0[] = "color"; parse_pgm_token_string_t cmd_color_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_color_result, arg0, str_color_arg0); -prog_char str_color_color[] = "green#red"; +prog_char str_color_color[] = "blue#yellow"; parse_pgm_token_string_t cmd_color_color = TOKEN_STRING_INITIALIZER(struct cmd_color_result, color, str_color_color); prog_char help_color[] = "Set our color"; @@ -160,13 +165,296 @@ parse_pgm_inst_t cmd_color = { .data = NULL, /* 2nd arg of func */ .help_str = help_color, .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_color_arg0, - (prog_void *)&cmd_color_color, + (prog_void *)&cmd_color_arg0, + (prog_void *)&cmd_color_color, NULL, }, }; +/**********************************************************/ +/* State1 */ + +/* this structure is filled when cmd_state1 is parsed successfully */ +struct cmd_state1_result { + fixed_string_t arg0; + fixed_string_t arg1; +}; + +/* function called when cmd_state1 is parsed successfully */ +static void cmd_state1_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_state1_result *res = parsed_result; + + if (!strcmp_P(res->arg1, PSTR("init"))) + state_init(); + else if (!strcmp_P(res->arg1, PSTR("off"))) + state_set_mode(I2C_BALLBOARD_MODE_OFF); + else if (!strcmp_P(res->arg1, PSTR("eject"))) + state_set_mode(I2C_BALLBOARD_MODE_EJECT); + else if (!strcmp_P(res->arg1, PSTR("harvest"))) + state_set_mode(I2C_BALLBOARD_MODE_HARVEST); + + /* other commands */ +} + +prog_char str_state1_arg0[] = "ballboard"; +parse_pgm_token_string_t cmd_state1_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state1_result, arg0, str_state1_arg0); +prog_char str_state1_arg1[] = "init#eject#harvest#off"; +parse_pgm_token_string_t cmd_state1_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state1_result, arg1, str_state1_arg1); + +prog_char help_state1[] = "set ballboard mode"; +parse_pgm_inst_t cmd_state1 = { + .f = cmd_state1_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_state1, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_state1_arg0, + (prog_void *)&cmd_state1_arg1, + NULL, + }, +}; + +/**********************************************************/ +/* State2 */ + +/* this structure is filled when cmd_state2 is parsed successfully */ +struct cmd_state2_result { + fixed_string_t arg0; + fixed_string_t arg1; + fixed_string_t arg2; +}; + +/* function called when cmd_state2 is parsed successfully */ +static void cmd_state2_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_state2_result *res = parsed_result; + uint8_t mode; + + if (!strcmp_P(res->arg2, PSTR("left"))) { + if (!strcmp_P(res->arg1, PSTR("prepare"))) + mode = I2C_BALLBOARD_MODE_PREP_L_FORK; + else if (!strcmp_P(res->arg1, PSTR("take"))) + mode = I2C_BALLBOARD_MODE_TAKE_L_FORK; + } + else { + if (!strcmp_P(res->arg1, PSTR("prepare"))) + mode = I2C_BALLBOARD_MODE_PREP_R_FORK; + else if (!strcmp_P(res->arg1, PSTR("take"))) + mode = I2C_BALLBOARD_MODE_TAKE_R_FORK; + } + //state_set_mode(mode); +} + +prog_char str_state2_arg0[] = "ballboard"; +parse_pgm_token_string_t cmd_state2_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg0, str_state2_arg0); +prog_char str_state2_arg1[] = "prepare#take"; +parse_pgm_token_string_t cmd_state2_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg1, str_state2_arg1); +prog_char str_state2_arg2[] = "left#right"; +parse_pgm_token_string_t cmd_state2_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg2, str_state2_arg2); + +prog_char help_state2[] = "set ballboard mode"; +parse_pgm_inst_t cmd_state2 = { + .f = cmd_state2_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_state2, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_state2_arg0, + (prog_void *)&cmd_state2_arg1, + (prog_void *)&cmd_state2_arg2, + NULL, + }, +}; + +/**********************************************************/ +/* State3 */ + +/* this structure is filled when cmd_state3 is parsed successfully */ +struct cmd_state3_result { + fixed_string_t arg0; + fixed_string_t arg1; + uint8_t arg2; +}; + +/* function called when cmd_state3 is parsed successfully */ +static void cmd_state3_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_state3_result *res = parsed_result; + + if (!strcmp_P(res->arg1, PSTR("xxx"))) { + /* xxx = res->arg2 */ + } + else if (!strcmp_P(res->arg1, PSTR("yyy"))) { + } + state_set_mode(0); +} + +prog_char str_state3_arg0[] = "ballboard"; +parse_pgm_token_string_t cmd_state3_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state3_result, arg0, str_state3_arg0); +prog_char str_state3_arg1[] = "xxx"; +parse_pgm_token_string_t cmd_state3_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state3_result, arg1, str_state3_arg1); +parse_pgm_token_num_t cmd_state3_arg2 = TOKEN_NUM_INITIALIZER(struct cmd_state3_result, arg2, UINT8); + +prog_char help_state3[] = "set ballboard mode"; +parse_pgm_inst_t cmd_state3 = { + .f = cmd_state3_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_state3, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_state3_arg0, + (prog_void *)&cmd_state3_arg1, + (prog_void *)&cmd_state3_arg2, + NULL, + }, +}; + +/**********************************************************/ +/* State_Machine */ + +/* this structure is filled when cmd_state_machine is parsed successfully */ +struct cmd_state_machine_result { + fixed_string_t arg0; +}; + +/* function called when cmd_state_machine is parsed successfully */ +static void cmd_state_machine_parsed(__attribute__((unused)) void *parsed_result, + __attribute__((unused)) void *data) +{ + state_machine(); +} + +prog_char str_state_machine_arg0[] = "state_machine"; +parse_pgm_token_string_t cmd_state_machine_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state_machine_result, arg0, str_state_machine_arg0); + +prog_char help_state_machine[] = "launch state machine"; +parse_pgm_inst_t cmd_state_machine = { + .f = cmd_state_machine_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_state_machine, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_state_machine_arg0, + NULL, + }, +}; + +/**********************************************************/ +/* State_Debug */ + +/* this structure is filled when cmd_state_debug is parsed successfully */ +struct cmd_state_debug_result { + fixed_string_t arg0; + uint8_t on; +}; + +/* function called when cmd_state_debug is parsed successfully */ +static void cmd_state_debug_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_state_debug_result *res = parsed_result; + state_debug = res->on; +} + +prog_char str_state_debug_arg0[] = "state_debug"; +parse_pgm_token_string_t cmd_state_debug_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state_debug_result, arg0, str_state_debug_arg0); +parse_pgm_token_num_t cmd_state_debug_on = TOKEN_NUM_INITIALIZER(struct cmd_state_debug_result, on, UINT8); + +prog_char help_state_debug[] = "Set debug for state machine"; +parse_pgm_inst_t cmd_state_debug = { + .f = cmd_state_debug_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_state_debug, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_state_debug_arg0, + (prog_void *)&cmd_state_debug_on, + NULL, + }, +}; + +/**********************************************************/ +/* Fork */ + +/* this structure is filled when cmd_fork is parsed successfully */ +struct cmd_fork_result { + fixed_string_t arg0; + fixed_string_t arg1; +}; + +/* function called when cmd_fork is parsed successfully */ +static void cmd_fork_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_fork_result *res = parsed_result; + if (!strcmp_P(res->arg1, PSTR("deploy"))) + fork_deploy(); + else if (!strcmp_P(res->arg1, PSTR("pack"))) + fork_pack(); + else if (!strcmp_P(res->arg1, PSTR("left"))) + fork_left(); + else if (!strcmp_P(res->arg1, PSTR("right"))) + fork_right(); + else if (!strcmp_P(res->arg1, PSTR("middle"))) + fork_middle(); +} + +prog_char str_fork_arg0[] = "fork"; +parse_pgm_token_string_t cmd_fork_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_fork_result, arg0, str_fork_arg0); +prog_char str_fork_arg1[] = "deploy#pack#left#right#middle"; +parse_pgm_token_string_t cmd_fork_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_fork_result, arg1, str_fork_arg1); + +prog_char help_fork[] = "move fork"; +parse_pgm_inst_t cmd_fork = { + .f = cmd_fork_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_fork, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_fork_arg0, + (prog_void *)&cmd_fork_arg1, + NULL, + }, +}; + +/**********************************************************/ +/* Roller */ + +/* this structure is filled when cmd_roller is parsed successfully */ +struct cmd_roller_result { + fixed_string_t arg0; + fixed_string_t arg1; +}; + +/* function called when cmd_roller is parsed successfully */ +static void cmd_roller_parsed(void *parsed_result, + __attribute__((unused)) void *data) +{ + struct cmd_roller_result *res = parsed_result; + if (!strcmp_P(res->arg1, PSTR("on"))) + roller_on(); + else if (!strcmp_P(res->arg1, PSTR("off"))) + roller_off(); + else if (!strcmp_P(res->arg1, PSTR("reverse"))) + roller_reverse(); +} + +prog_char str_roller_arg0[] = "roller"; +parse_pgm_token_string_t cmd_roller_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_roller_result, arg0, str_roller_arg0); +prog_char str_roller_arg1[] = "on#off#reverse"; +parse_pgm_token_string_t cmd_roller_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_roller_result, arg1, str_roller_arg1); + +prog_char help_roller[] = "Servo door function"; +parse_pgm_inst_t cmd_roller = { + .f = cmd_roller_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_roller, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_roller_arg0, + (prog_void *)&cmd_roller_arg1, + NULL, + }, +}; + /**********************************************************/ /* Test */ @@ -179,7 +467,6 @@ struct cmd_test_result { static void cmd_test_parsed(void *parsed_result, void *data) { //struct cmd_test_result *res = parsed_result; - } prog_char str_test_arg0[] = "test"; @@ -191,7 +478,7 @@ parse_pgm_inst_t cmd_test = { .data = NULL, /* 2nd arg of func */ .help_str = help_test, .tokens = { /* token list, NULL terminated */ - (prog_void *)&cmd_test_arg0, + (prog_void *)&cmd_test_arg0, NULL, }, };