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.c,v 1.9 2009-11-08 17:24:33 zer0 Exp $
20 * Olivier MATZ <zer0@droids-corp.org>
28 #include <aversive/pgmspace.h>
29 #include <aversive/queue.h>
30 #include <aversive/endian.h>
31 #include <aversive/error.h>
32 #include <aversive/wait.h>
35 #include <parse_string.h>
36 #include <parse_num.h>
41 #include "parse_atcmd.h"
42 #include "parse_neighbor.h"
43 #include "parse_monitor.h"
45 #include "spi_servo.h"
50 #include "eeprom_config.h"
53 extern const parse_inst_t PROGMEM cmd_reset;
54 extern const parse_inst_t PROGMEM cmd_bootloader;
55 extern const parse_inst_t PROGMEM cmd_log;
56 extern const parse_inst_t PROGMEM cmd_log_show;
57 extern const parse_inst_t PROGMEM cmd_log_type;
58 extern const parse_inst_t PROGMEM cmd_stack_space;
59 extern const parse_inst_t PROGMEM cmd_scheduler;
61 static int monitor_period_ms = 1000;
62 static int monitor_running = 0;
63 static int monitor_count = 0;
64 static struct callout monitor_event;
65 struct monitor_reg *monitor_current;
67 static int range_period_ms = 1000;
68 static int range_powermask = 0x1F;
69 //static uint8_t range_power = 0;
70 static int range_running = 0;
71 static uint64_t range_dstaddr = 0xFFFF; /* broadcast by default */
72 static struct callout range_event;
73 static int range_count = 100;
74 static int range_cur_count = 0;
76 static void monitor_cb(struct callout_manager *cm,
77 struct callout *clt, void *dummy)
82 if (monitor_current == NULL)
83 monitor_current = LIST_FIRST(&xbee_monitor_list);
85 xbeeapp_send_atcmd(monitor_current->atcmd, NULL, 0, 0, NULL, NULL);
86 monitor_current = LIST_NEXT(monitor_current, next);
87 callout_reset(cm, &monitor_event,
88 monitor_period_ms / monitor_count,
89 SINGLE, monitor_cb, NULL);
92 static void range_cb(struct callout_manager *cm,
93 struct callout *clt, void *dummy)
100 struct rc_proto_range rangepkt;
107 /* get new xmit power */
108 for (i = 1; i <= 8; i++) {
109 mask = 1 << ((range_power + i) & 0x7);
110 if (mask & range_powermask)
113 range_power = ((range_power + i) & 0x7);
115 xbeeapp_send_atcmd("PL", &range_power, sizeof(range_power), 0, NULL, NULL);
117 rangepkt.type = RC_PROTO_TYPE_RANGE;
118 rangepkt.power_level = range_power;
120 xbeeapp_send_msg(range_dstaddr, &rangepkt, sizeof(rangepkt), 0);
122 if (range_cur_count == 0) {
127 callout_reset(cm, &range_event,
129 SINGLE, range_cb, NULL);
133 /* this structure is filled when cmd_help is parsed successfully */
134 struct cmd_help_result {
136 struct xbee_atcmd *cmd;
139 /* function called when cmd_help is parsed successfully */
140 static void cmd_help_parsed(void *parsed_result, void *data)
142 struct cmd_help_result *res = parsed_result;
143 struct xbee_atcmd cmdcopy;
148 memcpy_P(&cmdcopy, res->cmd, sizeof(cmdcopy));
149 type = (cmdcopy.flags & (XBEE_ATCMD_F_READ | XBEE_ATCMD_F_WRITE));
151 case XBEE_ATCMD_F_READ:
152 printf_P(PSTR("Read-only\r\n"));
154 case XBEE_ATCMD_F_WRITE:
155 printf_P(PSTR("Write-only\r\n"));
158 printf_P(PSTR("Read-write\r\n"));
161 if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_NONE)
162 printf_P(PSTR("No argument\r\n"));
163 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U8)
164 printf_P(PSTR("Register is unsigned 8 bits\r\n"));
165 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U16)
166 printf_P(PSTR("Register is unsigned 16 bits\r\n"));
167 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U32)
168 printf_P(PSTR("Register is unsigned 32 bits\r\n"));
169 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_S16)
170 printf_P(PSTR("Register is signed 16 bits\r\n"));
171 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_STRING_20B)
172 printf_P(PSTR("Register is a 20 bytes string\r\n"));
174 printf_P(PSTR("Unknown argument\r\n"));
176 printf_P(PSTR("%S\r\n"), cmdcopy.help);
178 const char PROGMEM str_help_help[] = "help";
180 const parse_token_string_t PROGMEM cmd_help_help =
181 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, str_help_help);
183 const parse_token_atcmd_t PROGMEM cmd_help_atcmd =
184 TOKEN_ATCMD_INITIALIZER(struct cmd_help_result, cmd, &xbee_dev,
187 const char PROGMEM help_help[] = "Help a register using an AT command";
188 const parse_inst_t PROGMEM cmd_help = {
189 .f = cmd_help_parsed, /* function to call */
190 .data = NULL, /* 2nd arg of func */
191 .help_str = help_help,
192 .tokens = { /* token list, NULL terminated */
193 (PGM_P)&cmd_help_help,
194 (PGM_P)&cmd_help_atcmd,
201 struct cmd_neigh_del_result {
203 fixed_string_t action;
204 struct xbee_neigh *neigh;
207 static void cmd_neigh_del_parsed(void *parsed_result,
210 struct cmd_neigh_del_result *res = parsed_result;
213 xbee_neigh_del(xbee_dev, res->neigh);
216 const char PROGMEM str_neigh_del_neigh[] = "neigh";
217 const parse_token_string_t PROGMEM cmd_neigh_del_cmd =
218 TOKEN_STRING_INITIALIZER(struct cmd_neigh_del_result, cmd,
219 str_neigh_del_neigh);
220 const char PROGMEM str_neigh_del_del[] = "del";
221 const parse_token_string_t PROGMEM cmd_neigh_del_action =
222 TOKEN_STRING_INITIALIZER(struct cmd_neigh_del_result, action,
224 const parse_token_neighbor_t PROGMEM cmd_neigh_del_neigh =
225 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_neigh_del_result, neigh,
228 const char PROGMEM help_neigh_del[] = "delete a neighbor";
229 const parse_inst_t PROGMEM cmd_neigh_del = {
230 .f = cmd_neigh_del_parsed, /* function to call */
231 .data = NULL, /* 2nd arg of func */
232 .help_str = help_neigh_del,
233 .tokens = { /* token list, NULL terminated */
234 (PGM_P)&cmd_neigh_del_cmd,
235 (PGM_P)&cmd_neigh_del_action,
236 (PGM_P)&cmd_neigh_del_neigh,
243 struct cmd_neigh_add_result {
245 fixed_string_t action;
250 static void cmd_neigh_add_parsed(void *parsed_result,
253 struct cmd_neigh_add_result *res = parsed_result;
256 if (xbee_neigh_add(xbee_dev, res->name, res->addr) == NULL)
257 printf_P(PSTR("name or addr already exist\r\n"));
260 const char PROGMEM str_neigh_add_neigh[] = "neigh";
261 const parse_token_string_t PROGMEM cmd_neigh_add_cmd =
262 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, cmd,
263 str_neigh_add_neigh);
264 const char PROGMEM str_neigh_add_add[] = "add";
265 const parse_token_string_t PROGMEM cmd_neigh_add_action =
266 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, action,
268 const parse_token_string_t PROGMEM cmd_neigh_add_name =
269 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, name, NULL);
270 const parse_token_num_t PROGMEM cmd_neigh_add_addr =
271 TOKEN_NUM_INITIALIZER(struct cmd_neigh_add_result, addr, UINT64);
273 const char PROGMEM help_neigh_add[] = "add a neighbor";
274 const parse_inst_t PROGMEM cmd_neigh_add = {
275 .f = cmd_neigh_add_parsed, /* function to call */
276 .data = NULL, /* 2nd arg of func */
277 .help_str = help_neigh_add,
278 .tokens = { /* token list, NULL terminated */
279 (PGM_P)&cmd_neigh_add_cmd,
280 (PGM_P)&cmd_neigh_add_action,
281 (PGM_P)&cmd_neigh_add_name,
282 (PGM_P)&cmd_neigh_add_addr,
289 struct cmd_neigh_list_result {
291 fixed_string_t action;
294 static void cmd_neigh_list_parsed(void *parsed_result,
297 struct xbee_neigh *neigh;
301 LIST_FOREACH(neigh, &xbee_dev->neigh_list, next) {
302 printf_P(PSTR(" %s: 0x%.8"PRIx32"%.8"PRIx32"\r\n"),
304 (uint32_t)(neigh->addr >> 32ULL),
305 (uint32_t)(neigh->addr & 0xFFFFFFFF));
309 const char PROGMEM str_neigh_list_neigh[] = "neigh";
310 const parse_token_string_t PROGMEM cmd_neigh_list_cmd =
311 TOKEN_STRING_INITIALIZER(struct cmd_neigh_list_result, cmd,
312 str_neigh_list_neigh);
313 const char PROGMEM str_neigh_list_list[] = "list";
314 const parse_token_string_t PROGMEM cmd_neigh_list_action =
315 TOKEN_STRING_INITIALIZER(struct cmd_neigh_list_result, action,
316 str_neigh_list_list);
318 const char PROGMEM help_neigh_list[] = "list all knwon neighbors";
319 const parse_inst_t PROGMEM cmd_neigh_list = {
320 .f = cmd_neigh_list_parsed, /* function to call */
321 .data = NULL, /* 2nd arg of func */
322 .help_str = help_neigh_list,
323 .tokens = { /* token list, NULL terminated */
324 (PGM_P)&cmd_neigh_list_cmd,
325 (PGM_P)&cmd_neigh_list_action,
335 /* this structure is filled when cmd_read is parsed successfully */
336 struct cmd_read_result {
338 struct xbee_atcmd *cmd;
341 /* function called when cmd_read is parsed successfully */
342 static void cmd_read_parsed(void *parsed_result,
345 struct cmd_read_result *res = parsed_result;
346 struct xbee_atcmd copy;
350 memcpy_P(©, res->cmd, sizeof(copy));
351 memcpy_P(&cmd, copy.name, 2);
353 xbeeapp_send_atcmd(cmd, NULL, 0, 1, NULL, NULL);
356 const char PROGMEM str_read_read[] = "read";
358 const parse_token_string_t PROGMEM cmd_read_read =
359 TOKEN_STRING_INITIALIZER(struct cmd_read_result, read,
362 const parse_token_atcmd_t PROGMEM cmd_read_atcmd =
363 TOKEN_ATCMD_INITIALIZER(struct cmd_read_result, cmd, &xbee_dev,
364 XBEE_ATCMD_F_READ, XBEE_ATCMD_F_READ);
366 const char PROGMEM help_read[] = "Read a register using an AT command";
367 const parse_inst_t PROGMEM cmd_read = {
368 .f = cmd_read_parsed, /* function to call */
369 .data = NULL, /* 2nd arg of func */
370 .help_str = help_read,
371 .tokens = { /* token list, NULL terminated */
372 (PGM_P)&cmd_read_read,
373 (PGM_P)&cmd_read_atcmd,
381 /* this structure is filled when cmd_write is parsed successfully */
382 struct cmd_write_result {
383 fixed_string_t write;
384 struct xbee_atcmd *cmd;
392 /* function called when cmd_write is parsed successfully */
393 static void cmd_write_parsed(void *parsed_result, void *data)
395 struct cmd_write_result *res = parsed_result;
396 struct xbee_atcmd copy;
402 memcpy_P(©, res->cmd, sizeof(copy));
404 if (copy.flags & XBEE_ATCMD_F_PARAM_NONE) {
408 else if (copy.flags & XBEE_ATCMD_F_PARAM_U8) {
409 len = sizeof(res->u8);
412 else if (copy.flags & XBEE_ATCMD_F_PARAM_U16) {
413 len = sizeof(res->u16);
414 res->u16 = htons(res->u16);
417 else if (copy.flags & XBEE_ATCMD_F_PARAM_U32) {
418 len = sizeof(res->u32);
419 res->u32 = htonl(res->u32);
423 printf_P(PSTR("Unknown argument type\r\n"));
426 memcpy_P(&cmd, copy.name, 2);
428 xbeeapp_send_atcmd(cmd, param, len, 1, NULL, NULL);
431 const char PROGMEM str_write_none[] = "write";
433 const parse_token_string_t PROGMEM cmd_write_write =
434 TOKEN_STRING_INITIALIZER(struct cmd_write_result, write,
437 const parse_token_atcmd_t PROGMEM cmd_write_none_atcmd =
438 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
440 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_NONE,
441 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_NONE);
443 const char PROGMEM help_write_none[] = "Send an AT command (no argument)";
445 const parse_inst_t PROGMEM cmd_write_none = {
446 .f = cmd_write_parsed, /* function to call */
447 .data = NULL, /* 2nd arg of func */
448 .help_str = help_write_none,
449 .tokens = { /* token list, NULL terminated */
450 (PGM_P)&cmd_write_write,
451 (PGM_P)&cmd_write_none_atcmd,
456 const parse_token_atcmd_t PROGMEM cmd_write_u8_atcmd =
457 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
459 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U8,
460 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U8);
462 const parse_token_num_t PROGMEM cmd_write_u8_u8 =
463 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u8, UINT8);
465 const char PROGMEM help_write_u8[] = "Write a 8 bits register using an AT command";
467 const parse_inst_t PROGMEM cmd_write_u8 = {
468 .f = cmd_write_parsed, /* function to call */
469 .data = NULL, /* 2nd arg of func */
470 .help_str = help_write_u8,
471 .tokens = { /* token list, NULL terminated */
472 (PGM_P)&cmd_write_write,
473 (PGM_P)&cmd_write_u8_atcmd,
474 (PGM_P)&cmd_write_u8_u8,
479 const parse_token_atcmd_t PROGMEM cmd_write_u16_atcmd =
480 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
482 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U16,
483 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U16);
485 const parse_token_num_t PROGMEM cmd_write_u16_u16 =
486 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u16, UINT16);
488 const char PROGMEM help_write_u16[] = "Write a 16 bits register using an AT command";
490 const parse_inst_t PROGMEM cmd_write_u16 = {
491 .f = cmd_write_parsed, /* function to call */
492 .data = NULL, /* 2nd arg of func */
493 .help_str = help_write_u16,
494 .tokens = { /* token list, NULL terminated */
495 (PGM_P)&cmd_write_write,
496 (PGM_P)&cmd_write_u16_atcmd,
497 (PGM_P)&cmd_write_u16_u16,
502 const parse_token_atcmd_t PROGMEM cmd_write_u32_atcmd =
503 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
505 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U32,
506 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U32);
508 const parse_token_num_t PROGMEM cmd_write_u32_u32 =
509 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u32, UINT32);
511 const char PROGMEM help_write_u32[] = "Write a 32 bits register using an AT command";
513 const parse_inst_t PROGMEM cmd_write_u32 = {
514 .f = cmd_write_parsed, /* function to call */
515 .data = NULL, /* 2nd arg of func */
516 .help_str = help_write_u32,
517 .tokens = { /* token list, NULL terminated */
518 (PGM_P)&cmd_write_write,
519 (PGM_P)&cmd_write_u32_atcmd,
520 (PGM_P)&cmd_write_u32_u32,
528 /* this structure is filled when cmd_sendmsg is parsed successfully */
529 struct cmd_sendmsg_result {
530 fixed_string_t sendmsg;
535 /* function called when cmd_sendmsg is parsed successfully */
536 static void cmd_sendmsg_parsed(void *parsed_result, void *data)
538 struct cmd_sendmsg_result *res = parsed_result;
541 xbeeapp_send_msg(res->addr, res->data, strlen(res->data), 1);
544 const char PROGMEM str_sendmsg[] = "sendmsg";
546 const parse_token_string_t PROGMEM cmd_sendmsg_sendmsg =
547 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_result, sendmsg,
550 const parse_token_num_t PROGMEM cmd_sendmsg_addr =
551 TOKEN_NUM_INITIALIZER(struct cmd_sendmsg_result, addr, UINT64);
553 const parse_token_string_t PROGMEM cmd_sendmsg_data =
554 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_result, data, NULL);
556 const char PROGMEM help_sendmsg[] = "Send data to a node using its address";
558 const parse_inst_t PROGMEM cmd_sendmsg = {
559 .f = cmd_sendmsg_parsed, /* function to call */
560 .data = NULL, /* 2nd arg of func */
561 .help_str = help_sendmsg,
562 .tokens = { /* token list, NULL terminated */
563 (PGM_P)&cmd_sendmsg_sendmsg,
564 (PGM_P)&cmd_sendmsg_addr,
565 (PGM_P)&cmd_sendmsg_data,
572 /* this structure is filled when cmd_send_hello is parsed successfully */
573 struct cmd_send_hello_result {
574 fixed_string_t send_hello;
581 /* function called when cmd_send_hello is parsed successfully */
582 static void cmd_send_hello_parsed(void *parsed_result, void *data)
584 struct cmd_send_hello_result *res = parsed_result;
585 uint16_t now, next, diff;
596 while (!cmdline_keypressed() || res->count == 0) {
602 if (diff < res->period)
605 rc_proto_send_hello(res->addr, res->data, strlen(res->data));
610 const char PROGMEM str_send_hello[] = "send_hello";
612 const parse_token_string_t PROGMEM cmd_send_hello_send_hello =
613 TOKEN_STRING_INITIALIZER(struct cmd_send_hello_result, send_hello,
616 const parse_token_num_t PROGMEM cmd_send_hello_addr =
617 TOKEN_NUM_INITIALIZER(struct cmd_send_hello_result, addr, UINT64);
619 const parse_token_num_t PROGMEM cmd_send_hello_period =
620 TOKEN_NUM_INITIALIZER(struct cmd_send_hello_result, period, UINT16);
622 const parse_token_num_t PROGMEM cmd_send_hello_count =
623 TOKEN_NUM_INITIALIZER(struct cmd_send_hello_result, count, UINT16);
625 const parse_token_string_t PROGMEM cmd_send_hello_data =
626 TOKEN_STRING_INITIALIZER(struct cmd_send_hello_result, data, NULL);
628 const char PROGMEM help_send_hello[] =
629 "Send hello msg to a node: addr, period_ms, count, str";
631 const parse_inst_t PROGMEM cmd_send_hello = {
632 .f = cmd_send_hello_parsed, /* function to call */
633 .data = NULL, /* 2nd arg of func */
634 .help_str = help_send_hello,
635 .tokens = { /* token list, NULL terminated */
636 (PGM_P)&cmd_send_hello_send_hello,
637 (PGM_P)&cmd_send_hello_addr,
638 (PGM_P)&cmd_send_hello_period,
639 (PGM_P)&cmd_send_hello_count,
640 (PGM_P)&cmd_send_hello_data,
647 /* this structure is filled when cmd_sendmsg_name is parsed successfully */
648 struct cmd_sendmsg_name_result {
649 fixed_string_t sendmsg_name;
650 struct xbee_neigh *neigh;
654 /* function called when cmd_sendmsg_name is parsed successfully */
655 static void cmd_sendmsg_name_parsed(void *parsed_result, void *data)
657 struct cmd_sendmsg_name_result *res = parsed_result;
660 xbeeapp_send_msg(res->neigh->addr, res->data, strlen(res->data), 1);
663 const parse_token_string_t PROGMEM cmd_sendmsg_name_sendmsg_name =
664 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_name_result, sendmsg_name,
667 const parse_token_neighbor_t PROGMEM cmd_sendmsg_name_neigh =
668 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_sendmsg_name_result, neigh,
671 const parse_token_string_t PROGMEM cmd_sendmsg_name_data =
672 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_name_result, data, NULL);
674 const char PROGMEM help_sendmsg_name[] = "Send data to a node using its name";
676 const parse_inst_t PROGMEM cmd_sendmsg_name = {
677 .f = cmd_sendmsg_name_parsed, /* function to call */
678 .data = NULL, /* 2nd arg of func */
679 .help_str = help_sendmsg_name,
680 .tokens = { /* token list, NULL terminated */
681 (PGM_P)&cmd_sendmsg_name_sendmsg_name,
682 (PGM_P)&cmd_sendmsg_name_neigh,
683 (PGM_P)&cmd_sendmsg_name_data,
691 /* this structure is filled when cmd_range is parsed successfully */
692 struct cmd_range_result {
693 fixed_string_t range;
694 fixed_string_t action;
697 /* function called when cmd_range is parsed successfully */
698 static void cmd_range_parsed(void *parsed_result, void *data)
700 struct cmd_range_result *res = parsed_result;
703 if (!strcmp_P(res->action, PSTR("show"))) {
704 printf_P(PSTR("range infos:\r\n"));
705 printf_P(PSTR(" range period %d\r\n"), range_period_ms);
706 printf_P(PSTR(" range count %d\r\n"), range_count);
707 printf_P(PSTR(" range powermask 0x%x\r\n"), range_powermask);
708 printf_P(PSTR(" range dstaddr 0x%.8"PRIx32"%.8"PRIx32"\r\n"),
709 (uint32_t)(range_dstaddr >> 32ULL),
710 (uint32_t)(range_dstaddr & 0xFFFFFFFF));
713 printf_P(PSTR(" range test is running\r\n"));
715 printf_P(PSTR(" range test is not running\r\n"));
717 else if (!strcmp(res->action, "start")) {
719 printf_P(PSTR("already running\r\n"));
722 range_cur_count = range_count;
723 callout_init(&range_event);
724 callout_reset(&cm, &range_event, 0,
725 SINGLE, range_cb, NULL);
728 else if (!strcmp(res->action, "end")) {
729 if (range_running == 0) {
730 printf_P(PSTR("not running\r\n"));
734 callout_stop(&cm, &range_event);
738 const char PROGMEM str_range[] = "range";
739 const char PROGMEM str_range_tokens[] = "show#start#end";
741 const parse_token_string_t PROGMEM cmd_range_range =
742 TOKEN_STRING_INITIALIZER(struct cmd_range_result, range,
744 const parse_token_string_t PROGMEM cmd_range_action =
745 TOKEN_STRING_INITIALIZER(struct cmd_range_result, action,
748 const char PROGMEM help_range[] = "start/stop/show current rangeing";
750 const parse_inst_t PROGMEM cmd_range = {
751 .f = cmd_range_parsed, /* function to call */
752 .data = NULL, /* 2nd arg of func */
753 .help_str = help_range,
754 .tokens = { /* token list, NULL terminated */
755 (PGM_P)&cmd_range_range,
756 (PGM_P)&cmd_range_action,
763 /* this structure is filled when cmd_range_period is parsed successfully */
764 struct cmd_range_period_result {
765 fixed_string_t range;
766 fixed_string_t action;
770 /* function called when cmd_range_period is parsed successfully */
771 static void cmd_range_period_parsed(void *parsed_result, void *data)
773 struct cmd_range_period_result *res = parsed_result;
776 if (res->period < 10) {
777 printf_P(PSTR("error, minimum period is 10 ms\r\n"));
781 range_period_ms = res->period;
784 const char PROGMEM str_period[] = "period";
786 const parse_token_string_t PROGMEM cmd_range_period_range_period =
787 TOKEN_STRING_INITIALIZER(struct cmd_range_period_result, range,
789 const parse_token_string_t PROGMEM cmd_range_period_action =
790 TOKEN_STRING_INITIALIZER(struct cmd_range_period_result, action,
792 const parse_token_num_t PROGMEM cmd_range_period_period =
793 TOKEN_NUM_INITIALIZER(struct cmd_range_period_result, period, UINT32);
795 const char PROGMEM help_range_period[] = "set range test period";
797 const parse_inst_t PROGMEM cmd_range_period = {
798 .f = cmd_range_period_parsed, /* function to call */
799 .data = NULL, /* 2nd arg of func */
800 .help_str = help_range_period,
801 .tokens = { /* token list, NULL terminated */
802 (PGM_P)&cmd_range_period_range_period,
803 (PGM_P)&cmd_range_period_action,
804 (PGM_P)&cmd_range_period_period,
811 /* this structure is filled when cmd_range_count is parsed successfully */
812 struct cmd_range_count_result {
813 fixed_string_t range;
814 fixed_string_t action;
818 /* function called when cmd_range_count is parsed successfully */
819 static void cmd_range_count_parsed(void *parsed_result, void *data)
821 struct cmd_range_count_result *res = parsed_result;
824 range_count = res->count;
827 const char PROGMEM str_count[] = "count";
829 const parse_token_string_t PROGMEM cmd_range_count_range_count =
830 TOKEN_STRING_INITIALIZER(struct cmd_range_count_result, range,
832 const parse_token_string_t PROGMEM cmd_range_count_action =
833 TOKEN_STRING_INITIALIZER(struct cmd_range_count_result, action,
835 const parse_token_num_t PROGMEM cmd_range_count_count =
836 TOKEN_NUM_INITIALIZER(struct cmd_range_count_result, count, UINT32);
839 const char PROGMEM help_range_count[] = "set range test count";
841 const parse_inst_t PROGMEM cmd_range_count = {
842 .f = cmd_range_count_parsed, /* function to call */
843 .data = NULL, /* 2nd arg of func */
844 .help_str = help_range_count,
845 .tokens = { /* token list, NULL terminated */
846 (PGM_P)&cmd_range_count_range_count,
847 (PGM_P)&cmd_range_count_action,
848 (PGM_P)&cmd_range_count_count,
855 /* this structure is filled when cmd_range_powermask is parsed successfully */
856 struct cmd_range_powermask_result {
857 fixed_string_t range;
858 fixed_string_t action;
862 /* function called when cmd_range_powermask is parsed successfully */
863 static void cmd_range_powermask_parsed(void *parsed_result, void *data)
865 struct cmd_range_powermask_result *res = parsed_result;
868 range_powermask = res->powermask;
871 const char PROGMEM str_powermask[] = "powermask";
873 const parse_token_string_t PROGMEM cmd_range_powermask_range_powermask =
874 TOKEN_STRING_INITIALIZER(struct cmd_range_powermask_result, range,
876 const parse_token_string_t PROGMEM cmd_range_powermask_action =
877 TOKEN_STRING_INITIALIZER(struct cmd_range_powermask_result, action,
879 const parse_token_num_t PROGMEM cmd_range_powermask_powermask =
880 TOKEN_NUM_INITIALIZER(struct cmd_range_powermask_result, powermask,
884 const char PROGMEM help_range_powermask[] = "set range test powermask";
886 const parse_inst_t PROGMEM cmd_range_powermask = {
887 .f = cmd_range_powermask_parsed, /* function to call */
888 .data = NULL, /* 2nd arg of func */
889 .help_str = help_range_powermask,
890 .tokens = { /* token list, NULL terminated */
891 (PGM_P)&cmd_range_powermask_range_powermask,
892 (PGM_P)&cmd_range_powermask_action,
893 (PGM_P)&cmd_range_powermask_powermask,
900 /* this structure is filled when cmd_range_dstaddr is parsed successfully */
901 struct cmd_range_dstaddr_result {
902 fixed_string_t range;
903 fixed_string_t action;
907 /* function called when cmd_range_dstaddr is parsed successfully */
908 static void cmd_range_dstaddr_parsed(void *parsed_result, void *data)
910 struct cmd_range_dstaddr_result *res = parsed_result;
913 range_dstaddr = res->dstaddr;
916 const char PROGMEM str_dstaddr[] = "dstaddr";
918 const parse_token_string_t PROGMEM cmd_range_dstaddr_range_dstaddr =
919 TOKEN_STRING_INITIALIZER(struct cmd_range_dstaddr_result, range,
921 const parse_token_string_t PROGMEM cmd_range_dstaddr_action =
922 TOKEN_STRING_INITIALIZER(struct cmd_range_dstaddr_result, action,
924 const parse_token_num_t PROGMEM cmd_range_dstaddr_dstaddr =
925 TOKEN_NUM_INITIALIZER(struct cmd_range_dstaddr_result, dstaddr, UINT64);
928 const char PROGMEM help_range_dstaddr[] = "set register rangeing dstaddr";
930 const parse_inst_t PROGMEM cmd_range_dstaddr = {
931 .f = cmd_range_dstaddr_parsed, /* function to call */
932 .data = NULL, /* 2nd arg of func */
933 .help_str = help_range_dstaddr,
934 .tokens = { /* token list, NULL terminated */
935 (PGM_P)&cmd_range_dstaddr_range_dstaddr,
936 (PGM_P)&cmd_range_dstaddr_action,
937 (PGM_P)&cmd_range_dstaddr_dstaddr,
945 /* this structure is filled when cmd_monitor is parsed successfully */
946 struct cmd_monitor_result {
947 fixed_string_t monitor;
948 fixed_string_t action;
951 /* function called when cmd_monitor is parsed successfully */
952 static void cmd_monitor_parsed(void *parsed_result, void *data)
954 struct cmd_monitor_result *res = parsed_result;
955 struct monitor_reg *m;
958 if (!strcmp_P(res->action, PSTR("show"))) {
959 printf_P(PSTR("monitor period is %d ms, %d regs in list\r\n"),
960 monitor_period_ms, monitor_count);
961 LIST_FOREACH(m, &xbee_monitor_list, next)
962 printf_P(PSTR(" %S\r\n"), m->desc);
964 else if (!strcmp_P(res->action, PSTR("start"))) {
965 if (monitor_running) {
966 printf_P(PSTR("already running\r\n"));
969 if (monitor_count == 0) {
970 printf_P(PSTR("no regs to be monitored\r\n"));
973 callout_init(&monitor_event);
974 callout_reset(&cm, &monitor_event, 0, SINGLE, monitor_cb, NULL);
976 monitor_current = LIST_FIRST(&xbee_monitor_list);
977 printf_P(PSTR("monitor cb: %S %s\r\n"),
978 monitor_current->desc,
979 monitor_current->atcmd);
982 else if (!strcmp_P(res->action, PSTR("end"))) {
983 if (monitor_running == 0) {
984 printf_P(PSTR("not running\r\n"));
988 callout_stop(&cm, &monitor_event);
992 const char PROGMEM str_monitor[] = "monitor";
993 const char PROGMEM str_monitor_tokens[] = "show#start#end";
995 const parse_token_string_t PROGMEM cmd_monitor_monitor =
996 TOKEN_STRING_INITIALIZER(struct cmd_monitor_result, monitor,
998 const parse_token_string_t PROGMEM cmd_monitor_action =
999 TOKEN_STRING_INITIALIZER(struct cmd_monitor_result, action,
1000 str_monitor_tokens);
1002 const char PROGMEM help_monitor[] = "start/stop/show current monitoring";
1004 const parse_inst_t PROGMEM cmd_monitor = {
1005 .f = cmd_monitor_parsed, /* function to call */
1006 .data = NULL, /* 2nd arg of func */
1007 .help_str = help_monitor,
1008 .tokens = { /* token list, NULL terminated */
1009 (PGM_P)&cmd_monitor_monitor,
1010 (PGM_P)&cmd_monitor_action,
1017 /* this structure is filled when cmd_monitor_add is parsed successfully */
1018 struct cmd_monitor_add_result {
1019 fixed_string_t monitor;
1020 fixed_string_t action;
1021 struct xbee_atcmd *cmd;
1024 /* function called when cmd_monitor_add is parsed successfully */
1025 static void cmd_monitor_add_parsed(void *parsed_result, void *data)
1027 struct cmd_monitor_add_result *res = parsed_result;
1028 struct monitor_reg *m;
1029 struct xbee_atcmd copy;
1032 memcpy_P(©, res->cmd, sizeof(copy));
1033 LIST_FOREACH(m, &xbee_monitor_list, next) {
1034 if (!strcmp_P(m->atcmd, copy.name))
1039 printf_P(PSTR("already exist\r\n"));
1043 m = malloc(sizeof(*m));
1045 printf_P(PSTR("no mem\r\n"));
1048 m->desc = copy.desc;
1049 strcpy_P(m->atcmd, copy.name);
1050 LIST_INSERT_HEAD(&xbee_monitor_list, m, next);
1054 const char PROGMEM str_monitor_add[] = "add";
1056 const parse_token_string_t PROGMEM cmd_monitor_add_monitor_add =
1057 TOKEN_STRING_INITIALIZER(struct cmd_monitor_add_result, monitor,
1059 const parse_token_string_t PROGMEM cmd_monitor_add_action =
1060 TOKEN_STRING_INITIALIZER(struct cmd_monitor_add_result, action,
1062 const parse_token_atcmd_t PROGMEM cmd_monitor_add_atcmd =
1063 TOKEN_ATCMD_INITIALIZER(struct cmd_monitor_add_result, cmd, &xbee_dev,
1064 XBEE_ATCMD_F_READ, XBEE_ATCMD_F_READ);
1067 const char PROGMEM help_monitor_add[] = "add a register in monitor list";
1069 const parse_inst_t PROGMEM cmd_monitor_add = {
1070 .f = cmd_monitor_add_parsed, /* function to call */
1071 .data = NULL, /* 2nd arg of func */
1072 .help_str = help_monitor_add,
1073 .tokens = { /* token list, NULL terminated */
1074 (PGM_P)&cmd_monitor_add_monitor_add,
1075 (PGM_P)&cmd_monitor_add_action,
1076 (PGM_P)&cmd_monitor_add_atcmd,
1083 /* this structure is filled when cmd_monitor_period is parsed successfully */
1084 struct cmd_monitor_period_result {
1085 fixed_string_t monitor;
1086 fixed_string_t action;
1090 /* function called when cmd_monitor_period is parsed successfully */
1091 static void cmd_monitor_period_parsed(void *parsed_result, void *data)
1093 struct cmd_monitor_period_result *res = parsed_result;
1096 if (res->period < 100) {
1097 printf_P(PSTR("error, minimum period is 100 ms\r\n"));
1101 monitor_period_ms = res->period;
1104 const char PROGMEM str_monitor_period[] = "period";
1106 const parse_token_string_t PROGMEM cmd_monitor_period_monitor_period =
1107 TOKEN_STRING_INITIALIZER(struct cmd_monitor_period_result, monitor,
1109 const parse_token_string_t PROGMEM cmd_monitor_period_action =
1110 TOKEN_STRING_INITIALIZER(struct cmd_monitor_period_result, action,
1111 str_monitor_period);
1112 const parse_token_num_t PROGMEM cmd_monitor_period_period =
1113 TOKEN_NUM_INITIALIZER(struct cmd_monitor_period_result, period, UINT32);
1116 const char PROGMEM help_monitor_period[] = "set register monitoring period";
1118 const parse_inst_t PROGMEM cmd_monitor_period = {
1119 .f = cmd_monitor_period_parsed, /* function to call */
1120 .data = NULL, /* 2nd arg of func */
1121 .help_str = help_monitor_period,
1122 .tokens = { /* token list, NULL terminated */
1123 (PGM_P)&cmd_monitor_period_monitor_period,
1124 (PGM_P)&cmd_monitor_period_action,
1125 (PGM_P)&cmd_monitor_period_period,
1132 /* this structure is filled when cmd_monitor_del is parsed successfully */
1133 struct cmd_monitor_del_result {
1134 fixed_string_t monitor;
1135 fixed_string_t action;
1136 struct monitor_reg *m;
1139 /* function called when cmd_monitor_del is parsed successfully */
1140 static void cmd_monitor_del_parsed(void *parsed_result, void *data)
1142 struct cmd_monitor_del_result *res = parsed_result;
1145 monitor_current = LIST_NEXT(res->m, next);
1146 LIST_REMOVE(res->m, next);
1149 if (monitor_count == 0) {
1150 printf_P(PSTR("Disable monitoring, no more event\r\n"));
1151 callout_stop(&cm, &monitor_event);
1152 monitor_running = 0;
1157 const char PROGMEM str_monitor_del[] = "del";
1159 const parse_token_string_t PROGMEM cmd_monitor_del_monitor_del =
1160 TOKEN_STRING_INITIALIZER(struct cmd_monitor_del_result, monitor,
1162 const parse_token_string_t PROGMEM cmd_monitor_del_action =
1163 TOKEN_STRING_INITIALIZER(struct cmd_monitor_del_result, action,
1165 const parse_token_monitor_t PROGMEM cmd_monitor_del_atcmd =
1166 TOKEN_MONITOR_INITIALIZER(struct cmd_monitor_del_result, m);
1169 const char PROGMEM help_monitor_del[] = "del a register in monitor list";
1171 const parse_inst_t PROGMEM cmd_monitor_del = {
1172 .f = cmd_monitor_del_parsed, /* function to call */
1173 .data = NULL, /* 2nd arg of func */
1174 .help_str = help_monitor_del,
1175 .tokens = { /* token list, NULL terminated */
1176 (PGM_P)&cmd_monitor_del_monitor_del,
1177 (PGM_P)&cmd_monitor_del_action,
1178 (PGM_P)&cmd_monitor_del_atcmd,
1186 /* this structure is filled when cmd_ping is parsed successfully */
1187 struct cmd_ping_result {
1188 fixed_string_t ping;
1191 /* function called when cmd_ping is parsed successfully */
1192 static void cmd_ping_parsed(void *parsed_result, void *data)
1194 (void)parsed_result;
1196 xbeeapp_send_atcmd("VL", NULL, 0, 1, NULL, NULL);
1199 const char PROGMEM str_ping[] = "ping";
1201 const parse_token_string_t PROGMEM cmd_ping_ping =
1202 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping,
1205 const char PROGMEM help_ping[] = "Send a ping to the xbee device";
1207 const parse_inst_t PROGMEM cmd_ping = {
1208 .f = cmd_ping_parsed, /* function to call */
1209 .data = NULL, /* 2nd arg of func */
1210 .help_str = help_ping,
1211 .tokens = { /* token list, NULL terminated */
1212 (PGM_P)&cmd_ping_ping,
1219 /* this structure is filled when cmd_raw is parsed successfully */
1220 struct cmd_raw_result {
1224 /* function called when cmd_raw is parsed successfully */
1225 static void cmd_raw_parsed(void *parsed_result, void *data)
1227 (void)parsed_result;
1229 printf_P(PSTR("switched to raw mode, CTRL-D to exit\r\n"));
1230 rdline_stop(&xbeeboard.rdl); /* don't display prompt when return */
1234 const char PROGMEM str_raw[] = "raw";
1236 const parse_token_string_t PROGMEM cmd_raw_raw =
1237 TOKEN_STRING_INITIALIZER(struct cmd_raw_result, raw,
1240 const char PROGMEM help_raw[] = "Switch to raw mode";
1242 const parse_inst_t PROGMEM cmd_raw = {
1243 .f = cmd_raw_parsed, /* function to call */
1244 .data = NULL, /* 2nd arg of func */
1245 .help_str = help_raw,
1246 .tokens = { /* token list, NULL terminated */
1247 (PGM_P)&cmd_raw_raw,
1254 /* this structure is filled when cmd_dump is parsed successfully */
1255 struct cmd_dump_result {
1256 fixed_string_t dump;
1257 fixed_string_t onoff;
1260 /* function called when cmd_dump is parsed successfully */
1261 static void cmd_dump_parsed(void *parsed_result, void *data)
1263 struct cmd_dump_result *res = parsed_result;
1266 if (!strcmp(res->onoff, "on"))
1272 const char PROGMEM str_dump[] = "dump";
1273 const char PROGMEM str_dump_onoff[] = "on#off";
1275 const parse_token_string_t PROGMEM cmd_dump_dump =
1276 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
1279 const parse_token_string_t PROGMEM cmd_dump_onoff =
1280 TOKEN_STRING_INITIALIZER(struct cmd_dump_result, onoff,
1283 const char PROGMEM help_dump[] = "enable/disable hexdump of received packets";
1285 const parse_inst_t PROGMEM cmd_dump = {
1286 .f = cmd_dump_parsed, /* function to call */
1287 .data = NULL, /* 2nd arg of func */
1288 .help_str = help_dump,
1289 .tokens = { /* token list, NULL terminated */
1290 (PGM_P)&cmd_dump_dump,
1291 (PGM_P)&cmd_dump_onoff,
1298 /* this structure is filled when cmd_debug is parsed successfully */
1299 struct cmd_debug_result {
1300 fixed_string_t debug;
1301 fixed_string_t onoff;
1304 /* function called when cmd_debug is parsed successfully */
1305 static void cmd_debug_parsed(void *parsed_result, void *data)
1307 struct cmd_debug_result *res = parsed_result;
1310 if (!strcmp(res->onoff, "on"))
1316 const char PROGMEM str_debug[] = "debug";
1317 const char PROGMEM str_debug_onoff[] = "on#off";
1319 const parse_token_string_t PROGMEM cmd_debug_debug =
1320 TOKEN_STRING_INITIALIZER(struct cmd_debug_result, debug,
1323 const parse_token_string_t PROGMEM cmd_debug_onoff =
1324 TOKEN_STRING_INITIALIZER(struct cmd_debug_result, onoff,
1327 const char PROGMEM help_debug[] = "enable/disable additionnal debug";
1329 const parse_inst_t PROGMEM cmd_debug = {
1330 .f = cmd_debug_parsed, /* function to call */
1331 .data = NULL, /* 2nd arg of func */
1332 .help_str = help_debug,
1333 .tokens = { /* token list, NULL terminated */
1334 (PGM_P)&cmd_debug_debug,
1335 (PGM_P)&cmd_debug_onoff,
1340 /**********************************************************/
1342 /* this structure is filled when cmd_baudrate is parsed successfully */
1343 struct cmd_baudrate_result {
1344 fixed_string_t arg0;
1348 /* function called when cmd_baudrate is parsed successfully */
1349 static void cmd_baudrate_parsed(void * parsed_result, __attribute__((unused)) void *data)
1351 struct cmd_baudrate_result *res = parsed_result;
1352 struct uart_config c;
1354 uart_getconf(XBEE_UART, &c);
1355 c.baudrate = res->arg1;
1356 uart_setconf(XBEE_UART, &c);
1359 const char PROGMEM str_baudrate_arg0[] = "baudrate";
1360 const parse_token_string_t PROGMEM cmd_baudrate_arg0 =
1361 TOKEN_STRING_INITIALIZER(struct cmd_baudrate_result, arg0,
1363 const parse_token_num_t PROGMEM cmd_baudrate_arg1 =
1364 TOKEN_NUM_INITIALIZER(struct cmd_baudrate_result, arg1,
1367 const char PROGMEM help_baudrate[] = "Change xbee baudrate";
1368 const parse_inst_t PROGMEM cmd_baudrate = {
1369 .f = cmd_baudrate_parsed, /* function to call */
1370 .data = NULL, /* 2nd arg of func */
1371 .help_str = help_baudrate,
1372 .tokens = { /* token list, NULL terminated */
1373 (PGM_P)&cmd_baudrate_arg0,
1374 (PGM_P)&cmd_baudrate_arg1,
1380 /**********************************************************/
1382 /* this structure is filled when cmd_beep is parsed successfully */
1383 struct cmd_beep_result {
1384 fixed_string_t beep;
1387 /* function called when cmd_beep is parsed successfully */
1388 static void cmd_beep_parsed(void *parsed_result, void *data)
1390 (void)parsed_result;
1401 const char PROGMEM str_beep[] = "beep";
1402 const parse_token_string_t PROGMEM cmd_beep_beep =
1403 TOKEN_STRING_INITIALIZER(struct cmd_beep_result, beep,
1406 const char PROGMEM help_beep[] = "Send a beep";
1408 const parse_inst_t PROGMEM cmd_beep = {
1409 .f = cmd_beep_parsed, /* function to call */
1410 .data = NULL, /* 2nd arg of func */
1411 .help_str = help_beep,
1412 .tokens = { /* token list, NULL terminated */
1413 (PGM_P)&cmd_beep_beep,
1418 /**********************************************************/
1420 /* this structure is filled when cmd_servo is parsed successfully */
1421 struct cmd_servo_result {
1422 fixed_string_t arg0;
1423 fixed_string_t arg1;
1428 /* function called when cmd_servo is parsed successfully */
1429 static void cmd_servo_parsed(void * parsed_result, void *data)
1431 struct cmd_servo_result *res = parsed_result;
1435 if (!strcmp_P(res->arg1, PSTR("set"))) {
1436 if (res->num >= N_SERVO) {
1437 printf_P(PSTR("bad servo num\n"));
1440 if (res->val >= 1024) {
1441 printf_P(PSTR("bad servo val\n"));
1444 spi_servo_set(res->num, res->val);
1446 else if (!strcmp_P(res->arg1, PSTR("bypass"))) {
1447 spi_servo_set_bypass(!!res->val);
1449 else if (!strcmp_P(res->arg1, PSTR("ppm"))) {
1450 spi_servo_set_ppm(!!res->val);
1452 else if (!strcmp_P(res->arg1, PSTR("show"))) {
1457 const char PROGMEM str_servo_arg0[] = "servo";
1458 const parse_token_string_t PROGMEM cmd_servo_arg0 =
1459 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg0,
1461 const char PROGMEM str_servo_arg1_set[] = "set";
1462 const parse_token_string_t PROGMEM cmd_servo_arg1_set =
1463 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1464 str_servo_arg1_set);
1465 const parse_token_num_t PROGMEM cmd_servo_num =
1466 TOKEN_NUM_INITIALIZER(struct cmd_servo_result, num,
1468 const parse_token_num_t PROGMEM cmd_servo_val =
1469 TOKEN_NUM_INITIALIZER(struct cmd_servo_result, val,
1472 const char PROGMEM help_servo_set[] = "set servo value";
1473 const parse_inst_t PROGMEM cmd_servo_set = {
1474 .f = cmd_servo_parsed, /* function to call */
1475 .data = NULL, /* 2nd arg of func */
1476 .help_str = help_servo_set,
1477 .tokens = { /* token list, NULL terminated */
1478 (PGM_P)&cmd_servo_arg0,
1479 (PGM_P)&cmd_servo_arg1_set,
1480 (PGM_P)&cmd_servo_num,
1481 (PGM_P)&cmd_servo_val,
1486 const char PROGMEM str_servo_arg1_show[] = "show";
1487 const parse_token_string_t PROGMEM cmd_servo_arg1_show =
1488 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1489 str_servo_arg1_show);
1491 const char PROGMEM help_servo_show[] = "read servo and config";
1492 const parse_inst_t PROGMEM cmd_servo_show = {
1493 .f = cmd_servo_parsed, /* function to call */
1494 .data = NULL, /* 2nd arg of func */
1495 .help_str = help_servo_show,
1496 .tokens = { /* token list, NULL terminated */
1497 (PGM_P)&cmd_servo_arg0,
1498 (PGM_P)&cmd_servo_arg1_show,
1503 const char PROGMEM str_servo_arg1_bypassppm[] = "bypass#ppm";
1504 const parse_token_string_t PROGMEM cmd_servo_arg1_bypassppm =
1505 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1506 str_servo_arg1_bypassppm);
1508 const char PROGMEM help_servo_bypassppm[] = "change bypass/ppm";
1509 const parse_inst_t PROGMEM cmd_servo_bypassppm = {
1510 .f = cmd_servo_parsed, /* function to call */
1511 .data = NULL, /* 2nd arg of func */
1512 .help_str = help_servo_bypassppm,
1513 .tokens = { /* token list, NULL terminated */
1514 (PGM_P)&cmd_servo_arg0,
1515 (PGM_P)&cmd_servo_arg1_bypassppm,
1516 (PGM_P)&cmd_servo_val,
1521 /**********************************************************/
1523 /* this structure is filled when cmd_test_spi is parsed successfully */
1524 struct cmd_test_spi_result {
1525 fixed_string_t arg0;
1528 static void cmd_test_spi_parsed(void * parsed_result, void *data)
1530 uint8_t i, flags, wait_time = 0;
1533 (void)parsed_result;
1536 spi_servo_set_bypass(0);
1537 spi_servo_set_ppm(0);
1539 /* stress test: send many commands, no wait between each servo
1540 * of a series, and a variable delay between series */
1541 printf_P(PSTR("stress test\r\n"));
1542 while (!cmdline_keypressed()) {
1554 for (i = 0; i < 6; i++)
1555 spi_servo_set(i, val);
1558 printf_P(PSTR("%4.4d %4.4d %4.4d %4.4d %4.4d %4.4d\r\n"),
1559 spi_servo_get(0), spi_servo_get(1), spi_servo_get(2),
1560 spi_servo_get(3), spi_servo_get(4), spi_servo_get(5));
1563 printf_P(PSTR("bypass mode, with spi commands in background\r\n"));
1564 spi_servo_set_bypass(1);
1566 /* test bypass mode */
1567 while (!cmdline_keypressed()) {
1579 for (i = 0; i < 6; i++)
1580 spi_servo_set(i, val);
1583 printf_P(PSTR("%4.4d %4.4d %4.4d %4.4d %4.4d %4.4d\r\n"),
1584 spi_servo_get(0), spi_servo_get(1), spi_servo_get(2),
1585 spi_servo_get(3), spi_servo_get(4), spi_servo_get(5));
1588 printf_P(PSTR("PPM to servo\r\n"));
1589 spi_servo_set_bypass(0);
1590 spi_servo_set_ppm(0);
1592 /* test PPM to servo (bypass) mode */
1593 while (!cmdline_keypressed()) {
1594 for (i = 0; i < 6; i++) {
1595 val = spi_servo_get(i);
1596 spi_servo_set(i, val);
1600 printf_P(PSTR("PPM to (servo + PPM)\r\n"));
1601 spi_servo_set_bypass(0);
1602 spi_servo_set_ppm(1);
1604 /* test PPM to servo (bypass) mode */
1605 while (!cmdline_keypressed()) {
1606 for (i = 0; i < 6; i++) {
1607 val = spi_servo_get(i);
1608 spi_servo_set(i, val);
1613 const char PROGMEM str_test_spi_arg0[] = "test_spi";
1614 const parse_token_string_t PROGMEM cmd_test_spi_arg0 =
1615 TOKEN_STRING_INITIALIZER(struct cmd_test_spi_result, arg0,
1618 const char PROGMEM help_test_spi[] = "Test the spi";
1619 const parse_inst_t PROGMEM cmd_test_spi = {
1620 .f = cmd_test_spi_parsed, /* function to call */
1621 .data = NULL, /* 2nd arg of func */
1622 .help_str = help_test_spi,
1623 .tokens = { /* token list, NULL terminated */
1624 (PGM_P)&cmd_test_spi_arg0,
1629 /**********************************************************/
1631 /* this structure is filled when cmd_dump_xbee_stats is parsed successfully */
1632 struct cmd_dump_xbee_stats_result {
1633 fixed_string_t arg0;
1636 static void cmd_dump_xbee_stats_parsed(void *parsed_result, void *data)
1638 (void)parsed_result;
1641 xbee_dump_stats(xbee_dev);
1644 const char PROGMEM str_dump_xbee_stats_arg0[] = "dump_xbee_stats";
1645 const parse_token_string_t PROGMEM cmd_dump_xbee_stats_arg0 =
1646 TOKEN_STRING_INITIALIZER(struct cmd_dump_xbee_stats_result, arg0,
1647 str_dump_xbee_stats_arg0);
1649 const char PROGMEM help_dump_xbee_stats[] = "Test the spi";
1650 const parse_inst_t PROGMEM cmd_dump_xbee_stats = {
1651 .f = cmd_dump_xbee_stats_parsed, /* function to call */
1652 .data = NULL, /* 2nd arg of func */
1653 .help_str = help_dump_xbee_stats,
1654 .tokens = { /* token list, NULL terminated */
1655 (PGM_P)&cmd_dump_xbee_stats_arg0,
1660 /**********************************************************/
1662 /* this structure is filled when cmd_test_eeprom_config is parsed successfully */
1663 struct cmd_test_eeprom_config_result {
1664 fixed_string_t arg0;
1667 static void cmd_test_eeprom_config_parsed(void *parsed_result, void *data)
1669 (void)parsed_result;
1673 eeprom_append_cmd("salut1\n");
1675 eeprom_append_cmd("salut2\n");
1676 eeprom_append_cmd("salut3\n");
1677 eeprom_append_cmd("salut4\n");
1679 eeprom_insert_cmd_before("coin\n", 0);
1680 eeprom_insert_cmd_before("coin2\n", 2);
1682 eeprom_delete_cmd(2);
1683 eeprom_delete_cmd(0);
1687 const char PROGMEM str_test_eeprom_config_arg0[] = "test_eeprom_config";
1688 const parse_token_string_t PROGMEM cmd_test_eeprom_config_arg0 =
1689 TOKEN_STRING_INITIALIZER(struct cmd_test_eeprom_config_result, arg0,
1690 str_test_eeprom_config_arg0);
1692 const char PROGMEM help_test_eeprom_config[] = "Test the eeprom configuration";
1693 const parse_inst_t PROGMEM cmd_test_eeprom_config = {
1694 .f = cmd_test_eeprom_config_parsed, /* function to call */
1695 .data = NULL, /* 2nd arg of func */
1696 .help_str = help_test_eeprom_config,
1697 .tokens = { /* token list, NULL terminated */
1698 (PGM_P)&cmd_test_eeprom_config_arg0,
1705 struct cmd_eeprom_del_result {
1707 fixed_string_t action;
1711 static void cmd_eeprom_del_parsed(void *parsed_result,
1714 struct cmd_eeprom_del_result *res = parsed_result;
1717 if (eeprom_delete_cmd(res->n) < 0)
1718 printf_P(PSTR("cannot delete command\n"));
1722 const char PROGMEM str_eeprom_del_eeprom[] = "eeprom";
1723 const parse_token_string_t PROGMEM cmd_eeprom_del_cmd =
1724 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, cmd,
1725 str_eeprom_del_eeprom);
1726 const char PROGMEM str_eeprom_del_del[] = "del";
1727 const parse_token_string_t PROGMEM cmd_eeprom_del_action =
1728 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, action,
1729 str_eeprom_del_del);
1730 const parse_token_num_t PROGMEM cmd_eeprom_del_num =
1731 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_del_result, n,
1734 const char PROGMEM help_eeprom_del[] = "delete an eeprom init command";
1735 const parse_inst_t PROGMEM cmd_eeprom_del = {
1736 .f = cmd_eeprom_del_parsed, /* function to call */
1737 .data = NULL, /* 2nd arg of func */
1738 .help_str = help_eeprom_del,
1739 .tokens = { /* token list, NULL terminated */
1740 (PGM_P)&cmd_eeprom_del_cmd,
1741 (PGM_P)&cmd_eeprom_del_action,
1742 (PGM_P)&cmd_eeprom_del_num,
1749 struct cmd_eeprom_add_result {
1751 fixed_string_t action;
1755 static void cmd_eeprom_add_parsed(void *parsed_result,
1758 struct cmd_eeprom_add_result *res = parsed_result;
1764 rdline_init(&rdl, cmdline_write_char, NULL, NULL);
1765 rdline_newline(&rdl, "> ");
1767 /* XXX bad: we should not block as we do not serve callout */
1769 c = cmdline_dev_recv(NULL);
1773 ret = rdline_char_in(&rdl, c);
1775 printf_P(PSTR("abort\n"));
1782 buffer = rdline_get_buffer(&rdl);
1784 eeprom_insert_cmd_before(buffer, res->n);
1786 eeprom_append_cmd(buffer);
1790 const char PROGMEM str_eeprom_add_eeprom[] = "eeprom";
1791 const parse_token_string_t PROGMEM cmd_eeprom_add_cmd =
1792 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, cmd,
1793 str_eeprom_add_eeprom);
1794 const char PROGMEM str_eeprom_add_add[] = "add";
1795 const parse_token_string_t PROGMEM cmd_eeprom_add_action =
1796 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, action,
1797 str_eeprom_add_add);
1798 const parse_token_num_t PROGMEM cmd_eeprom_add_num =
1799 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_add_result, n,
1802 const char PROGMEM help_eeprom_add[] = "insert an eeprom init command";
1803 const parse_inst_t PROGMEM cmd_eeprom_add = {
1804 .f = cmd_eeprom_add_parsed, /* function to call */
1805 .data = NULL, /* 2nd arg of func */
1806 .help_str = help_eeprom_add,
1807 .tokens = { /* token list, NULL terminated */
1808 (PGM_P)&cmd_eeprom_add_cmd,
1809 (PGM_P)&cmd_eeprom_add_action,
1810 (PGM_P)&cmd_eeprom_add_num,
1815 const char PROGMEM help_eeprom_add2[] = "append an eeprom init command";
1816 const parse_inst_t PROGMEM cmd_eeprom_add2 = {
1817 .f = cmd_eeprom_add_parsed, /* function to call */
1818 .data = (void *)1, /* 2nd arg of func */
1819 .help_str = help_eeprom_add2,
1820 .tokens = { /* token list, NULL terminated */
1821 (PGM_P)&cmd_eeprom_add_cmd,
1822 (PGM_P)&cmd_eeprom_add_action,
1829 struct cmd_eeprom_list_result {
1831 fixed_string_t action;
1834 static void cmd_eeprom_list_parsed(void *parsed_result,
1837 (void)parsed_result;
1842 const char PROGMEM str_eeprom_list_eeprom[] = "eeprom";
1843 const parse_token_string_t PROGMEM cmd_eeprom_list_cmd =
1844 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, cmd,
1845 str_eeprom_list_eeprom);
1846 const char PROGMEM str_eeprom_list_list[] = "list";
1847 const parse_token_string_t PROGMEM cmd_eeprom_list_action =
1848 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, action,
1849 str_eeprom_list_list);
1851 const char PROGMEM help_eeprom_list[] = "list all eeprom init commands";
1852 const parse_inst_t PROGMEM cmd_eeprom_list = {
1853 .f = cmd_eeprom_list_parsed, /* function to call */
1854 .data = NULL, /* 2nd arg of func */
1855 .help_str = help_eeprom_list,
1856 .tokens = { /* token list, NULL terminated */
1857 (PGM_P)&cmd_eeprom_list_cmd,
1858 (PGM_P)&cmd_eeprom_list_action,
1867 const parse_ctx_t PROGMEM main_ctx[] = {
1869 /* commands_gen.c */
1892 &cmd_range_powermask,
1895 &cmd_monitor_period,
1905 &cmd_servo_bypassppm,
1908 &cmd_dump_xbee_stats,
1909 &cmd_test_eeprom_config,