printf -> logs in xbee_user
[protos/xbee-avr.git] / commands.c
index 54e56d7..3448ded 100644 (file)
 #include <parse_num.h>
 #include <uart.h>
 #include <xbee.h>
+#include <callout.h>
 
-#include "callout.h"
 #include "parse_atcmd.h"
 #include "parse_neighbor.h"
 #include "parse_monitor.h"
 
 #include "spi_servo.h"
 #include "rc_proto.h"
+#include "xbee_user.h"
 #include "main.h"
 #include "cmdline.h"
 #include "beep.h"
@@ -532,9 +533,15 @@ struct cmd_sendmsg_result {
 static void cmd_sendmsg_parsed(void *parsed_result, void *data)
 {
        struct cmd_sendmsg_result *res = parsed_result;
+       struct xbee_msg msg;
 
        (void)data;
-       xbeeapp_send_msg(res->addr, res->data, strlen(res->data), 1);
+
+       msg.iovlen = 1;
+       msg.iov[0].buf = res->data;
+       msg.iov[0].len = strlen(res->data);
+
+       xbeeapp_send_msg(res->addr, &msg, 1);
 }
 
 const char PROGMEM str_sendmsg[] = "sendmsg";
@@ -675,9 +682,15 @@ struct cmd_sendmsg_name_result {
 static void cmd_sendmsg_name_parsed(void *parsed_result, void *data)
 {
        struct cmd_sendmsg_name_result *res = parsed_result;
+       struct xbee_msg msg;
 
        (void)data;
-       xbeeapp_send_msg(res->neigh->addr, res->data, strlen(res->data), 1);
+
+       msg.iovlen = 1;
+       msg.iov[0].buf = res->data;
+       msg.iov[0].len = strlen(res->data);
+
+       xbeeapp_send_msg(res->neigh->addr, &msg, 1);
 }
 
 const parse_token_string_t PROGMEM cmd_sendmsg_name_sendmsg_name =
@@ -740,18 +753,18 @@ static void cmd_range_parsed(void *parsed_result, void *data)
                        return;
                }
                range_cur_count = range_count;
-               callout_init(&range_event, range_cb, NULL, 0);
-               callout_schedule(&xbeeboard.mainloop_cm,
-                       &range_event, 0); /* immediate */
+               callout_init(&range_event, range_cb, NULL, LOW_PRIO);
                range_running = 1;
+               callout_schedule(&xbeeboard.intr_cm,
+                       &range_event, 0); /* immediate */
        }
        else if (!strcmp(res->action, "end")) {
                if (range_running == 0) {
                        printf_P(PSTR("not running\r\n"));
                        return;
                }
+               callout_stop(&xbeeboard.intr_cm, &range_event);
                range_running = 0;
-               callout_stop(&xbeeboard.mainloop_cm, &range_event);
        }
 }
 
@@ -990,11 +1003,11 @@ static void cmd_monitor_parsed(void *parsed_result, void *data)
                        printf_P(PSTR("no regs to be monitored\r\n"));
                        return;
                }
-               callout_init(&monitor_event, monitor_cb, NULL, 0);
-               callout_schedule(&xbeeboard.mainloop_cm,
-                       &monitor_event, 0); /* immediate */
+               callout_init(&monitor_event, monitor_cb, NULL, 1);
                monitor_running = 1;
                monitor_current = LIST_FIRST(&xbee_monitor_list);
+               callout_schedule(&xbeeboard.intr_cm,
+                       &monitor_event, 0); /* immediate */
                printf_P(PSTR("monitor cb: %S %s\r\n"),
                         monitor_current->desc,
                         monitor_current->atcmd);
@@ -1005,8 +1018,8 @@ static void cmd_monitor_parsed(void *parsed_result, void *data)
                        printf_P(PSTR("not running\r\n"));
                        return;
                }
+               callout_stop(&xbeeboard.intr_cm, &monitor_event);
                monitor_running = 0;
-               callout_stop(&xbeeboard.mainloop_cm, &monitor_event);
        }
 }
 
@@ -1169,7 +1182,7 @@ static void cmd_monitor_del_parsed(void *parsed_result, void *data)
        monitor_count --;
        if (monitor_count == 0) {
                printf_P(PSTR("Disable monitoring, no more event\r\n"));
-               callout_stop(&xbeeboard.mainloop_cm, &monitor_event);
+               callout_stop(&xbeeboard.intr_cm, &monitor_event);
                monitor_running = 0;
                return;
        }
@@ -1247,6 +1260,11 @@ static void cmd_raw_parsed(void *parsed_result, void *data)
 {
        (void)parsed_result;
        (void)data;
+
+       if (range_running || monitor_running) {
+               printf_P(PSTR("stop running range or monitor first\r\n"));
+               return;
+       }
        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;
@@ -1270,94 +1288,6 @@ const parse_inst_t PROGMEM cmd_raw = {
        },
 };
 
-/* ************* */
-
-/* this structure is filled when cmd_dump is parsed successfully */
-struct cmd_dump_result {
-       fixed_string_t dump;
-       fixed_string_t onoff;
-};
-
-/* function called when cmd_dump is parsed successfully */
-static void cmd_dump_parsed(void *parsed_result, void *data)
-{
-       struct cmd_dump_result *res = parsed_result;
-
-       (void)data;
-       if (!strcmp(res->onoff, "on"))
-               xbee_hexdump = 1;
-       else
-               xbee_hexdump = 0;
-}
-
-const char PROGMEM str_dump[] = "dump";
-const char PROGMEM str_dump_onoff[] = "on#off";
-
-const parse_token_string_t PROGMEM cmd_dump_dump =
-       TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
-                                str_dump);
-
-const parse_token_string_t PROGMEM cmd_dump_onoff =
-       TOKEN_STRING_INITIALIZER(struct cmd_dump_result, onoff,
-                                str_dump_onoff);
-
-const char PROGMEM help_dump[] = "enable/disable hexdump of received packets";
-
-const parse_inst_t PROGMEM cmd_dump = {
-       .f = cmd_dump_parsed,  /* function to call */
-       .data = NULL,      /* 2nd arg of func */
-       .help_str = help_dump,
-       .tokens = {        /* token list, NULL terminated */
-               (PGM_P)&cmd_dump_dump,
-               (PGM_P)&cmd_dump_onoff,
-               NULL,
-       },
-};
-
-/* ************* */
-
-/* this structure is filled when cmd_debug is parsed successfully */
-struct cmd_debug_result {
-       fixed_string_t debug;
-       fixed_string_t onoff;
-};
-
-/* function called when cmd_debug is parsed successfully */
-static void cmd_debug_parsed(void *parsed_result, void *data)
-{
-       struct cmd_debug_result *res = parsed_result;
-
-       (void)data;
-       if (!strcmp(res->onoff, "on"))
-               xbee_debug = 1;
-       else
-               xbee_debug = 0;
-}
-
-const char PROGMEM str_debug[] = "debug";
-const char PROGMEM str_debug_onoff[] = "on#off";
-
-const parse_token_string_t PROGMEM cmd_debug_debug =
-       TOKEN_STRING_INITIALIZER(struct cmd_debug_result, debug,
-                                str_debug);
-
-const parse_token_string_t PROGMEM cmd_debug_onoff =
-       TOKEN_STRING_INITIALIZER(struct cmd_debug_result, onoff,
-                                str_debug_onoff);
-
-const char PROGMEM help_debug[] = "enable/disable additionnal debug";
-
-const parse_inst_t PROGMEM cmd_debug = {
-       .f = cmd_debug_parsed,  /* function to call */
-       .data = NULL,      /* 2nd arg of func */
-       .help_str = help_debug,
-       .tokens = {        /* token list, NULL terminated */
-               (PGM_P)&cmd_debug_debug,
-               (PGM_P)&cmd_debug_onoff,
-               NULL,
-       },
-};
-
 /**********************************************************/
 
 /* this structure is filled when cmd_baudrate is parsed successfully */
@@ -1919,8 +1849,6 @@ const parse_ctx_t PROGMEM main_ctx[] = {
        &cmd_monitor_del,
        &cmd_ping,
        &cmd_raw,
-       &cmd_dump,
-       &cmd_debug,
        &cmd_baudrate,
        &cmd_beep,
        &cmd_servo_set,