X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee-avr.git;a=blobdiff_plain;f=commands.c;h=6eb034c59b92ade35bdb1673f7b84b3e5f836a3b;hp=1cacfedacf3fb25239b3968073cf49c561451e18;hb=f97044f0c5ecbbc665bd7ac1d454fd9479476a78;hpb=d6014994e06ebe952d51bef2e36a795f624c4b4d diff --git a/commands.c b/commands.c index 1cacfed..6eb034c 100644 --- a/commands.c +++ b/commands.c @@ -28,10 +28,13 @@ #include #include #include +#include +#include #include #include #include #include +#include #include "xbee_atcmd.h" #include "xbee_neighbor.h" @@ -44,8 +47,10 @@ #include "parse_neighbor.h" #include "parse_monitor.h" +#include "spi_servo.h" #include "rc_proto.h" #include "main.h" +#include "cmdline.h" /* commands_gen.c */ extern parse_pgm_inst_t cmd_reset; @@ -396,7 +401,7 @@ static void cmd_write_parsed(void *parsed_result, void *data) param = &res->u32; } else { - printf("Unknown argument type\n"); + printf_P(PSTR("Unknown argument type\r\n")); return; } memcpy_P(&cmd, copy.name, 2); @@ -612,7 +617,7 @@ static void cmd_range_parsed(void *parsed_result, void *data) } else if (!strcmp(res->action, "start")) { if (range_running) { - printf("already running\n"); + printf_P(PSTR("already running\r\n")); return; } range_cur_count = range_count; @@ -623,7 +628,7 @@ static void cmd_range_parsed(void *parsed_result, void *data) } else if (!strcmp(res->action, "end")) { if (range_running == 0) { - printf("not running\n"); + printf_P(PSTR("not running\r\n")); return; } range_running = 0; @@ -669,7 +674,7 @@ static void cmd_range_period_parsed(void *parsed_result, void *data) struct cmd_range_period_result *res = parsed_result; if (res->period < 10) { - printf("error, minimum period is 10 ms\n"); + printf_P(PSTR("error, minimum period is 10 ms\r\n")); return; } @@ -847,15 +852,15 @@ static void cmd_monitor_parsed(void *parsed_result, void *data) printf_P(PSTR("monitor period is %d ms, %d regs in list\r\n"), monitor_period_ms, monitor_count); LIST_FOREACH(m, &xbee_monitor_list, next) - printf_P(PSTR(" %S\n"), m->desc); + printf_P(PSTR(" %S\r\n"), m->desc); } else if (!strcmp_P(res->action, PSTR("start"))) { if (monitor_running) { - printf("already running\n"); + printf_P(PSTR("already running\r\n")); return; } if (monitor_count == 0) { - printf("no regs to be monitored\n"); + printf_P(PSTR("no regs to be monitored\r\n")); return; } callout_init(&monitor_event); @@ -869,7 +874,7 @@ static void cmd_monitor_parsed(void *parsed_result, void *data) } else if (!strcmp_P(res->action, PSTR("end"))) { if (monitor_running == 0) { - printf("not running\n"); + printf_P(PSTR("not running\r\n")); return; } monitor_running = 0; @@ -923,13 +928,13 @@ static void cmd_monitor_add_parsed(void *parsed_result, void *data) } if (m != NULL) { - printf("already exist\n"); + printf_P(PSTR("already exist\r\n")); return; } m = malloc(sizeof(*m)); if (m == NULL) { - printf("no mem\n"); + printf_P(PSTR("no mem\r\n")); return; } m->desc = copy.desc; @@ -980,7 +985,7 @@ static void cmd_monitor_period_parsed(void *parsed_result, void *data) struct cmd_monitor_period_result *res = parsed_result; if (res->period < 100) { - printf("error, minimum period is 100 ms\n"); + printf_P(PSTR("error, minimum period is 100 ms\r\n")); return; } @@ -1032,7 +1037,7 @@ static void cmd_monitor_del_parsed(void *parsed_result, void *data) free(res->m); monitor_count --; if (monitor_count == 0) { - printf("Disable monitoring, no more event\n"); + printf_P(PSTR("Disable monitoring, no more event\r\n")); callout_stop(&cm, &monitor_event); monitor_running = 0; return; @@ -1107,7 +1112,7 @@ struct cmd_raw_result { /* function called when cmd_raw is parsed successfully */ static void cmd_raw_parsed(void *parsed_result, void *data) { - printf("switched to raw mode, CTRL-D to exit\n"); + printf_P(PSTR("switched to raw mode, CTRL-D to exit\r\n")); rdline_stop(&xbeeboard.rdl); /* don't display prompt when return */ xbee_raw = 1; } @@ -1214,7 +1219,88 @@ parse_pgm_inst_t cmd_debug = { }, }; +#ifndef USE_USB +/**********************************************************/ +/* this structure is filled when cmd_baudrate is parsed successfully */ +struct cmd_baudrate_result { + fixed_string_t arg0; + uint32_t arg1; +}; + +/* function called when cmd_baudrate is parsed successfully */ +static void cmd_baudrate_parsed(void * parsed_result, __attribute__((unused)) void *data) +{ + struct cmd_baudrate_result *res = parsed_result; + struct uart_config c; + + uart_getconf(XBEE_UART, &c); + c.baudrate = res->arg1; + uart_setconf(XBEE_UART, &c); +} + +prog_char str_baudrate_arg0[] = "baudrate"; +parse_pgm_token_string_t cmd_baudrate_arg0 = + TOKEN_STRING_INITIALIZER(struct cmd_baudrate_result, arg0, + str_baudrate_arg0); +parse_pgm_token_num_t cmd_baudrate_arg1 = + TOKEN_NUM_INITIALIZER(struct cmd_baudrate_result, arg1, + UINT32); + +prog_char help_baudrate[] = "Change xbee baudrate"; +parse_pgm_inst_t cmd_baudrate = { + .f = cmd_baudrate_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_baudrate, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_baudrate_arg0, + (prog_void *)&cmd_baudrate_arg1, + NULL, + }, +}; +#endif + +/* this structure is filled when cmd_test_spi is parsed successfully */ +struct cmd_test_spi_result { + fixed_string_t arg0; +}; + +static void cmd_test_spi_parsed(void * parsed_result, + __attribute__((unused)) void *data) +{ + int i; + + + while (1) { + for (i = 0; i < 50; i++) { + spi_servo_set(0, 0); + wait_ms(100); + spi_servo_set(0, 500); + wait_ms(100); + } + + spi_servo_bypass(1); + wait_ms(10000); + spi_servo_bypass(0); + wait_ms(1); + } +} + +prog_char str_test_spi_arg0[] = "test_spi"; +parse_pgm_token_string_t cmd_test_spi_arg0 = + TOKEN_STRING_INITIALIZER(struct cmd_test_spi_result, arg0, + str_test_spi_arg0); + +prog_char help_test_spi[] = "Test the spi"; +parse_pgm_inst_t cmd_test_spi = { + .f = cmd_test_spi_parsed, /* function to call */ + .data = NULL, /* 2nd arg of func */ + .help_str = help_test_spi, + .tokens = { /* token list, NULL terminated */ + (prog_void *)&cmd_test_spi_arg0, + NULL, + }, +}; /* in progmem */ parse_pgm_ctx_t main_ctx[] = { @@ -1251,5 +1337,9 @@ parse_pgm_ctx_t main_ctx[] = { (parse_pgm_inst_t *)&cmd_raw, (parse_pgm_inst_t *)&cmd_dump, (parse_pgm_inst_t *)&cmd_debug, +#ifndef USE_USB + (parse_pgm_inst_t *)&cmd_baudrate, +#endif + (parse_pgm_inst_t *)&cmd_test_spi, NULL, };