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"
47 #include "xbee_user.h"
51 #include "eeprom_config.h"
54 extern const parse_inst_t PROGMEM cmd_reset;
55 extern const parse_inst_t PROGMEM cmd_bootloader;
56 extern const parse_inst_t PROGMEM cmd_log;
57 extern const parse_inst_t PROGMEM cmd_log_show;
58 extern const parse_inst_t PROGMEM cmd_log_type;
59 extern const parse_inst_t PROGMEM cmd_stack_space;
60 extern const parse_inst_t PROGMEM cmd_callout;
62 static int monitor_period_ms = 1000;
63 static int monitor_running = 0;
64 static int monitor_count = 0;
65 static struct callout monitor_event;
66 struct monitor_reg *monitor_current;
68 static int range_period_ms = 1000;
69 static int range_powermask = 0x1F;
70 static uint8_t range_power = 0;
71 static int range_running = 0;
72 static uint64_t range_dstaddr = 0xFFFF; /* broadcast by default */
73 static struct callout range_event;
74 static int range_count = 100;
75 static int range_cur_count = 0;
77 static void monitor_cb(struct callout_mgr *cm,
78 struct callout *clt, void *dummy)
83 if (monitor_current == NULL)
84 monitor_current = LIST_FIRST(&xbee_monitor_list);
86 /* no rx_cb given: the user must check the monitored values in logs */
87 xbeeapp_send_atcmd(monitor_current->atcmd, NULL, 0, NULL, NULL);
88 monitor_current = LIST_NEXT(monitor_current, next);
89 callout_reschedule(cm, clt, monitor_period_ms / monitor_count);
92 static void range_cb(struct callout_mgr *cm,
93 struct callout *clt, void *dummy)
95 struct rc_proto_power_probe power_probe;
104 /* get new xmit power */
105 for (i = 1; i <= 8; i++) {
106 mask = 1 << ((range_power + i) & 0x7);
107 if (mask & range_powermask)
110 range_power = ((range_power + i) & 0x7);
112 xbeeapp_send_atcmd("PL", &range_power, sizeof(range_power), NULL, NULL);
114 power_probe.type = RC_PROTO_POWER_PROBE;
115 power_probe.power_level = range_power;
118 msg.iov[0].buf = &power_probe;
119 msg.iov[0].len = sizeof(power_probe);
121 xbeeapp_send_msg(range_dstaddr, &msg, NULL, NULL);
123 if (range_cur_count == 0) {
125 callout_stop(cm, clt);
129 callout_reschedule(cm, clt, range_period_ms);
132 /* callback invoked when a xbee_send is done */
133 static int8_t send_msg_cb(int8_t retcode, void *frame, unsigned len,
136 struct xbee_recv_hdr *recvframe = frame;
140 if (retcode == XBEE_USER_RETCODE_TIMEOUT) {
141 printf_P(PSTR("timeout\r\n"));
144 if (retcode == XBEE_USER_RETCODE_BAD_FRAME ||
145 len < sizeof(*recvframe)) {
146 printf_P(PSTR("invalid frame\r\n"));
147 return XBEE_USER_RETCODE_BAD_FRAME;
150 printf_P(PSTR("ok\r\n"));
151 return XBEE_USER_RETCODE_OK;
154 /* callback invoked to dump the response to AT command */
155 static int8_t dump_xbee_atresp_cb(int8_t retcode, void *frame, unsigned len,
158 struct xbee_atresp_hdr *recvframe = frame;
164 if (retcode == XBEE_USER_RETCODE_TIMEOUT) {
165 printf_P(PSTR("timeout\r\n"));
168 if (retcode == XBEE_USER_RETCODE_BAD_FRAME ||
169 len < sizeof(*recvframe)) {
170 printf_P(PSTR("invalid frame\r\n"));
171 return XBEE_USER_RETCODE_BAD_FRAME;
174 /* get AT command from frame */
175 memcpy(atcmd_str, &recvframe->cmd, 2);
178 atresp_to_str(buf, sizeof(buf), frame, len);
179 len -= sizeof(*recvframe);
180 printf_P(PSTR("status ok, len=%d, %s\n"), len, buf);
181 return XBEE_USER_RETCODE_OK;
184 /* this structure is filled when cmd_help is parsed successfully */
185 struct cmd_help_result {
187 struct xbee_atcmd *cmd;
190 /* function called when cmd_help is parsed successfully */
191 static void cmd_help_parsed(void *parsed_result, void *data)
193 struct cmd_help_result *res = parsed_result;
194 struct xbee_atcmd cmdcopy;
199 memcpy_P(&cmdcopy, res->cmd, sizeof(cmdcopy));
200 type = (cmdcopy.flags & (XBEE_ATCMD_F_READ | XBEE_ATCMD_F_WRITE));
202 case XBEE_ATCMD_F_READ:
203 printf_P(PSTR("Read-only\r\n"));
205 case XBEE_ATCMD_F_WRITE:
206 printf_P(PSTR("Write-only\r\n"));
209 printf_P(PSTR("Read-write\r\n"));
212 if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_NONE)
213 printf_P(PSTR("No argument\r\n"));
214 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U8)
215 printf_P(PSTR("Register is unsigned 8 bits\r\n"));
216 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U16)
217 printf_P(PSTR("Register is unsigned 16 bits\r\n"));
218 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_U32)
219 printf_P(PSTR("Register is unsigned 32 bits\r\n"));
220 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_S16)
221 printf_P(PSTR("Register is signed 16 bits\r\n"));
222 else if (cmdcopy.flags & XBEE_ATCMD_F_PARAM_STRING_20B)
223 printf_P(PSTR("Register is a 20 bytes string\r\n"));
225 printf_P(PSTR("Unknown argument\r\n"));
227 printf_P(PSTR("%S\r\n"), cmdcopy.help);
229 const char PROGMEM str_help_help[] = "help";
231 const parse_token_string_t PROGMEM cmd_help_help =
232 TOKEN_STRING_INITIALIZER(struct cmd_help_result, help, str_help_help);
234 const parse_token_atcmd_t PROGMEM cmd_help_atcmd =
235 TOKEN_ATCMD_INITIALIZER(struct cmd_help_result, cmd, &xbee_dev,
238 const char PROGMEM help_help[] = "Help a register using an AT command";
239 const parse_inst_t PROGMEM cmd_help = {
240 .f = cmd_help_parsed, /* function to call */
241 .data = NULL, /* 2nd arg of func */
242 .help_str = help_help,
243 .tokens = { /* token list, NULL terminated */
244 (PGM_P)&cmd_help_help,
245 (PGM_P)&cmd_help_atcmd,
252 struct cmd_neigh_del_result {
254 fixed_string_t action;
255 struct xbee_neigh *neigh;
258 static void cmd_neigh_del_parsed(void *parsed_result,
261 struct cmd_neigh_del_result *res = parsed_result;
264 xbee_neigh_del(xbee_dev, res->neigh);
267 const char PROGMEM str_neigh_del_neigh[] = "neigh";
268 const parse_token_string_t PROGMEM cmd_neigh_del_cmd =
269 TOKEN_STRING_INITIALIZER(struct cmd_neigh_del_result, cmd,
270 str_neigh_del_neigh);
271 const char PROGMEM str_neigh_del_del[] = "del";
272 const parse_token_string_t PROGMEM cmd_neigh_del_action =
273 TOKEN_STRING_INITIALIZER(struct cmd_neigh_del_result, action,
275 const parse_token_neighbor_t PROGMEM cmd_neigh_del_neigh =
276 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_neigh_del_result, neigh,
279 const char PROGMEM help_neigh_del[] = "delete a neighbor";
280 const parse_inst_t PROGMEM cmd_neigh_del = {
281 .f = cmd_neigh_del_parsed, /* function to call */
282 .data = NULL, /* 2nd arg of func */
283 .help_str = help_neigh_del,
284 .tokens = { /* token list, NULL terminated */
285 (PGM_P)&cmd_neigh_del_cmd,
286 (PGM_P)&cmd_neigh_del_action,
287 (PGM_P)&cmd_neigh_del_neigh,
294 struct cmd_neigh_add_result {
296 fixed_string_t action;
301 static void cmd_neigh_add_parsed(void *parsed_result,
304 struct cmd_neigh_add_result *res = parsed_result;
307 if (xbee_neigh_add(xbee_dev, res->name, res->addr) == NULL)
308 printf_P(PSTR("name or addr already exist\r\n"));
311 const char PROGMEM str_neigh_add_neigh[] = "neigh";
312 const parse_token_string_t PROGMEM cmd_neigh_add_cmd =
313 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, cmd,
314 str_neigh_add_neigh);
315 const char PROGMEM str_neigh_add_add[] = "add";
316 const parse_token_string_t PROGMEM cmd_neigh_add_action =
317 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, action,
319 const parse_token_string_t PROGMEM cmd_neigh_add_name =
320 TOKEN_STRING_INITIALIZER(struct cmd_neigh_add_result, name, NULL);
321 const parse_token_num_t PROGMEM cmd_neigh_add_addr =
322 TOKEN_NUM_INITIALIZER(struct cmd_neigh_add_result, addr, UINT64);
324 const char PROGMEM help_neigh_add[] = "add a neighbor";
325 const parse_inst_t PROGMEM cmd_neigh_add = {
326 .f = cmd_neigh_add_parsed, /* function to call */
327 .data = NULL, /* 2nd arg of func */
328 .help_str = help_neigh_add,
329 .tokens = { /* token list, NULL terminated */
330 (PGM_P)&cmd_neigh_add_cmd,
331 (PGM_P)&cmd_neigh_add_action,
332 (PGM_P)&cmd_neigh_add_name,
333 (PGM_P)&cmd_neigh_add_addr,
340 struct cmd_neigh_list_result {
342 fixed_string_t action;
345 static void cmd_neigh_list_parsed(void *parsed_result,
348 struct xbee_neigh *neigh;
352 LIST_FOREACH(neigh, &xbee_dev->neigh_list, next) {
353 printf_P(PSTR(" %s: 0x%.8"PRIx32"%.8"PRIx32"\r\n"),
355 (uint32_t)(neigh->addr >> 32ULL),
356 (uint32_t)(neigh->addr & 0xFFFFFFFF));
360 const char PROGMEM str_neigh_list_neigh[] = "neigh";
361 const parse_token_string_t PROGMEM cmd_neigh_list_cmd =
362 TOKEN_STRING_INITIALIZER(struct cmd_neigh_list_result, cmd,
363 str_neigh_list_neigh);
364 const char PROGMEM str_neigh_list_list[] = "list";
365 const parse_token_string_t PROGMEM cmd_neigh_list_action =
366 TOKEN_STRING_INITIALIZER(struct cmd_neigh_list_result, action,
367 str_neigh_list_list);
369 const char PROGMEM help_neigh_list[] = "list all knwon neighbors";
370 const parse_inst_t PROGMEM cmd_neigh_list = {
371 .f = cmd_neigh_list_parsed, /* function to call */
372 .data = NULL, /* 2nd arg of func */
373 .help_str = help_neigh_list,
374 .tokens = { /* token list, NULL terminated */
375 (PGM_P)&cmd_neigh_list_cmd,
376 (PGM_P)&cmd_neigh_list_action,
383 /* this structure is filled when cmd_read is parsed successfully */
384 struct cmd_read_result {
386 struct xbee_atcmd *cmd;
389 /* function called when cmd_read is parsed successfully */
390 static void cmd_read_parsed(void *parsed_result,
393 struct cmd_read_result *res = parsed_result;
394 struct xbee_atcmd copy;
396 volatile uint8_t done = 0;
399 memcpy_P(©, res->cmd, sizeof(copy));
400 memcpy_P(&cmd, copy.name, 2);
402 xbeeapp_send_atcmd(cmd, NULL, 0, dump_xbee_atresp_cb, (void *)&done);
406 const char PROGMEM str_read_read[] = "read";
408 const parse_token_string_t PROGMEM cmd_read_read =
409 TOKEN_STRING_INITIALIZER(struct cmd_read_result, read,
412 const parse_token_atcmd_t PROGMEM cmd_read_atcmd =
413 TOKEN_ATCMD_INITIALIZER(struct cmd_read_result, cmd, &xbee_dev,
414 XBEE_ATCMD_F_READ, XBEE_ATCMD_F_READ);
416 const char PROGMEM help_read[] = "Read a register using an AT command";
417 const parse_inst_t PROGMEM cmd_read = {
418 .f = cmd_read_parsed, /* function to call */
419 .data = NULL, /* 2nd arg of func */
420 .help_str = help_read,
421 .tokens = { /* token list, NULL terminated */
422 (PGM_P)&cmd_read_read,
423 (PGM_P)&cmd_read_atcmd,
431 /* this structure is filled when cmd_write is parsed successfully */
432 struct cmd_write_result {
433 fixed_string_t write;
434 struct xbee_atcmd *cmd;
442 /* function called when cmd_write is parsed successfully */
443 static void cmd_write_parsed(void *parsed_result, void *data)
445 struct cmd_write_result *res = parsed_result;
446 struct xbee_atcmd copy;
450 volatile uint8_t done = 0;
453 memcpy_P(©, res->cmd, sizeof(copy));
455 if (copy.flags & XBEE_ATCMD_F_PARAM_NONE) {
459 else if (copy.flags & XBEE_ATCMD_F_PARAM_U8) {
460 len = sizeof(res->u8);
463 else if (copy.flags & XBEE_ATCMD_F_PARAM_U16) {
464 len = sizeof(res->u16);
465 res->u16 = htons(res->u16);
468 else if (copy.flags & XBEE_ATCMD_F_PARAM_U32) {
469 len = sizeof(res->u32);
470 res->u32 = htonl(res->u32);
474 printf_P(PSTR("Unknown argument type\r\n"));
477 memcpy_P(&cmd, copy.name, 2);
479 xbeeapp_send_atcmd(cmd, param, len, dump_xbee_atresp_cb, (void *)&done);
483 const char PROGMEM str_write_none[] = "write";
485 const parse_token_string_t PROGMEM cmd_write_write =
486 TOKEN_STRING_INITIALIZER(struct cmd_write_result, write,
489 const parse_token_atcmd_t PROGMEM cmd_write_none_atcmd =
490 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
492 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_NONE,
493 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_NONE);
495 const char PROGMEM help_write_none[] = "Send an AT command (no argument)";
497 const parse_inst_t PROGMEM cmd_write_none = {
498 .f = cmd_write_parsed, /* function to call */
499 .data = NULL, /* 2nd arg of func */
500 .help_str = help_write_none,
501 .tokens = { /* token list, NULL terminated */
502 (PGM_P)&cmd_write_write,
503 (PGM_P)&cmd_write_none_atcmd,
508 const parse_token_atcmd_t PROGMEM cmd_write_u8_atcmd =
509 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
511 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U8,
512 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U8);
514 const parse_token_num_t PROGMEM cmd_write_u8_u8 =
515 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u8, UINT8);
517 const char PROGMEM help_write_u8[] = "Write a 8 bits register using an AT command";
519 const parse_inst_t PROGMEM cmd_write_u8 = {
520 .f = cmd_write_parsed, /* function to call */
521 .data = NULL, /* 2nd arg of func */
522 .help_str = help_write_u8,
523 .tokens = { /* token list, NULL terminated */
524 (PGM_P)&cmd_write_write,
525 (PGM_P)&cmd_write_u8_atcmd,
526 (PGM_P)&cmd_write_u8_u8,
531 const parse_token_atcmd_t PROGMEM cmd_write_u16_atcmd =
532 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
534 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U16,
535 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U16);
537 const parse_token_num_t PROGMEM cmd_write_u16_u16 =
538 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u16, UINT16);
540 const char PROGMEM help_write_u16[] = "Write a 16 bits register using an AT command";
542 const parse_inst_t PROGMEM cmd_write_u16 = {
543 .f = cmd_write_parsed, /* function to call */
544 .data = NULL, /* 2nd arg of func */
545 .help_str = help_write_u16,
546 .tokens = { /* token list, NULL terminated */
547 (PGM_P)&cmd_write_write,
548 (PGM_P)&cmd_write_u16_atcmd,
549 (PGM_P)&cmd_write_u16_u16,
554 const parse_token_atcmd_t PROGMEM cmd_write_u32_atcmd =
555 TOKEN_ATCMD_INITIALIZER(struct cmd_write_result, cmd,
557 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U32,
558 XBEE_ATCMD_F_WRITE | XBEE_ATCMD_F_PARAM_U32);
560 const parse_token_num_t PROGMEM cmd_write_u32_u32 =
561 TOKEN_NUM_INITIALIZER(struct cmd_write_result, u32, UINT32);
563 const char PROGMEM help_write_u32[] = "Write a 32 bits register using an AT command";
565 const parse_inst_t PROGMEM cmd_write_u32 = {
566 .f = cmd_write_parsed, /* function to call */
567 .data = NULL, /* 2nd arg of func */
568 .help_str = help_write_u32,
569 .tokens = { /* token list, NULL terminated */
570 (PGM_P)&cmd_write_write,
571 (PGM_P)&cmd_write_u32_atcmd,
572 (PGM_P)&cmd_write_u32_u32,
580 /* this structure is filled when cmd_sendmsg is parsed successfully */
581 struct cmd_sendmsg_result {
582 fixed_string_t sendmsg;
587 /* function called when cmd_sendmsg is parsed successfully */
588 static void cmd_sendmsg_parsed(void *parsed_result, void *data)
590 struct cmd_sendmsg_result *res = parsed_result;
592 volatile uint8_t done = 0;
597 msg.iov[0].buf = res->data;
598 msg.iov[0].len = strlen(res->data);
600 xbeeapp_send_msg(res->addr, &msg, send_msg_cb, (void *)&done);
604 const char PROGMEM str_sendmsg[] = "sendmsg";
606 const parse_token_string_t PROGMEM cmd_sendmsg_sendmsg =
607 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_result, sendmsg,
610 const parse_token_num_t PROGMEM cmd_sendmsg_addr =
611 TOKEN_NUM_INITIALIZER(struct cmd_sendmsg_result, addr, UINT64);
613 const parse_token_string_t PROGMEM cmd_sendmsg_data =
614 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_result, data, NULL);
616 const char PROGMEM help_sendmsg[] = "Send data to a node using its address";
618 const parse_inst_t PROGMEM cmd_sendmsg = {
619 .f = cmd_sendmsg_parsed, /* function to call */
620 .data = NULL, /* 2nd arg of func */
621 .help_str = help_sendmsg,
622 .tokens = { /* token list, NULL terminated */
623 (PGM_P)&cmd_sendmsg_sendmsg,
624 (PGM_P)&cmd_sendmsg_addr,
625 (PGM_P)&cmd_sendmsg_data,
632 /* this structure is filled when cmd_sendmsg_name is parsed successfully */
633 struct cmd_sendmsg_name_result {
634 fixed_string_t sendmsg_name;
635 struct xbee_neigh *neigh;
639 /* function called when cmd_sendmsg_name is parsed successfully */
640 static void cmd_sendmsg_name_parsed(void *parsed_result, void *data)
642 struct cmd_sendmsg_name_result *res = parsed_result;
644 volatile uint8_t done = 0;
649 msg.iov[0].buf = res->data;
650 msg.iov[0].len = strlen(res->data);
652 xbeeapp_send_msg(res->neigh->addr, &msg, send_msg_cb, (void *)&done);
656 const parse_token_string_t PROGMEM cmd_sendmsg_name_sendmsg_name =
657 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_name_result, sendmsg_name,
660 const parse_token_neighbor_t PROGMEM cmd_sendmsg_name_neigh =
661 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_sendmsg_name_result, neigh,
664 const parse_token_string_t PROGMEM cmd_sendmsg_name_data =
665 TOKEN_STRING_INITIALIZER(struct cmd_sendmsg_name_result, data, NULL);
667 const char PROGMEM help_sendmsg_name[] = "Send data to a node using its name";
669 const parse_inst_t PROGMEM cmd_sendmsg_name = {
670 .f = cmd_sendmsg_name_parsed, /* function to call */
671 .data = NULL, /* 2nd arg of func */
672 .help_str = help_sendmsg_name,
673 .tokens = { /* token list, NULL terminated */
674 (PGM_P)&cmd_sendmsg_name_sendmsg_name,
675 (PGM_P)&cmd_sendmsg_name_neigh,
676 (PGM_P)&cmd_sendmsg_name_data,
684 /* this structure is filled when cmd_range is parsed successfully */
685 struct cmd_range_result {
686 fixed_string_t range;
687 fixed_string_t action;
690 /* function called when cmd_range is parsed successfully */
691 static void cmd_range_parsed(void *parsed_result, void *data)
693 struct cmd_range_result *res = parsed_result;
696 if (!strcmp_P(res->action, PSTR("show"))) {
697 printf_P(PSTR("range infos:\r\n"));
698 printf_P(PSTR(" range period %d\r\n"), range_period_ms);
699 printf_P(PSTR(" range count %d\r\n"), range_count);
700 printf_P(PSTR(" range powermask 0x%x\r\n"), range_powermask);
701 printf_P(PSTR(" range dstaddr 0x%.8"PRIx32"%.8"PRIx32"\r\n"),
702 (uint32_t)(range_dstaddr >> 32ULL),
703 (uint32_t)(range_dstaddr & 0xFFFFFFFF));
706 printf_P(PSTR(" range test is running\r\n"));
708 printf_P(PSTR(" range test is not running\r\n"));
710 else if (!strcmp(res->action, "start")) {
712 printf_P(PSTR("already running\r\n"));
715 range_cur_count = range_count;
716 callout_init(&range_event, range_cb, NULL, LOW_PRIO);
718 callout_schedule(&xbeeboard.intr_cm,
719 &range_event, 0); /* immediate */
721 else if (!strcmp(res->action, "end")) {
722 if (range_running == 0) {
723 printf_P(PSTR("not running\r\n"));
726 callout_stop(&xbeeboard.intr_cm, &range_event);
731 const char PROGMEM str_range[] = "range";
732 const char PROGMEM str_range_tokens[] = "show#start#end";
734 const parse_token_string_t PROGMEM cmd_range_range =
735 TOKEN_STRING_INITIALIZER(struct cmd_range_result, range,
737 const parse_token_string_t PROGMEM cmd_range_action =
738 TOKEN_STRING_INITIALIZER(struct cmd_range_result, action,
741 const char PROGMEM help_range[] = "start/stop/show current rangeing";
743 const parse_inst_t PROGMEM cmd_range = {
744 .f = cmd_range_parsed, /* function to call */
745 .data = NULL, /* 2nd arg of func */
746 .help_str = help_range,
747 .tokens = { /* token list, NULL terminated */
748 (PGM_P)&cmd_range_range,
749 (PGM_P)&cmd_range_action,
756 /* this structure is filled when cmd_range_period is parsed successfully */
757 struct cmd_range_period_result {
758 fixed_string_t range;
759 fixed_string_t action;
763 /* function called when cmd_range_period is parsed successfully */
764 static void cmd_range_period_parsed(void *parsed_result, void *data)
766 struct cmd_range_period_result *res = parsed_result;
769 if (res->period < 10) {
770 printf_P(PSTR("error, minimum period is 10 ms\r\n"));
774 range_period_ms = res->period;
777 const char PROGMEM str_period[] = "period";
779 const parse_token_string_t PROGMEM cmd_range_period_range_period =
780 TOKEN_STRING_INITIALIZER(struct cmd_range_period_result, range,
782 const parse_token_string_t PROGMEM cmd_range_period_action =
783 TOKEN_STRING_INITIALIZER(struct cmd_range_period_result, action,
785 const parse_token_num_t PROGMEM cmd_range_period_period =
786 TOKEN_NUM_INITIALIZER(struct cmd_range_period_result, period, UINT32);
788 const char PROGMEM help_range_period[] = "set range test period";
790 const parse_inst_t PROGMEM cmd_range_period = {
791 .f = cmd_range_period_parsed, /* function to call */
792 .data = NULL, /* 2nd arg of func */
793 .help_str = help_range_period,
794 .tokens = { /* token list, NULL terminated */
795 (PGM_P)&cmd_range_period_range_period,
796 (PGM_P)&cmd_range_period_action,
797 (PGM_P)&cmd_range_period_period,
804 /* this structure is filled when cmd_range_count is parsed successfully */
805 struct cmd_range_count_result {
806 fixed_string_t range;
807 fixed_string_t action;
811 /* function called when cmd_range_count is parsed successfully */
812 static void cmd_range_count_parsed(void *parsed_result, void *data)
814 struct cmd_range_count_result *res = parsed_result;
817 range_count = res->count;
820 const char PROGMEM str_count[] = "count";
822 const parse_token_string_t PROGMEM cmd_range_count_range_count =
823 TOKEN_STRING_INITIALIZER(struct cmd_range_count_result, range,
825 const parse_token_string_t PROGMEM cmd_range_count_action =
826 TOKEN_STRING_INITIALIZER(struct cmd_range_count_result, action,
828 const parse_token_num_t PROGMEM cmd_range_count_count =
829 TOKEN_NUM_INITIALIZER(struct cmd_range_count_result, count, UINT32);
832 const char PROGMEM help_range_count[] = "set range test count";
834 const parse_inst_t PROGMEM cmd_range_count = {
835 .f = cmd_range_count_parsed, /* function to call */
836 .data = NULL, /* 2nd arg of func */
837 .help_str = help_range_count,
838 .tokens = { /* token list, NULL terminated */
839 (PGM_P)&cmd_range_count_range_count,
840 (PGM_P)&cmd_range_count_action,
841 (PGM_P)&cmd_range_count_count,
848 /* this structure is filled when cmd_range_powermask is parsed successfully */
849 struct cmd_range_powermask_result {
850 fixed_string_t range;
851 fixed_string_t action;
855 /* function called when cmd_range_powermask is parsed successfully */
856 static void cmd_range_powermask_parsed(void *parsed_result, void *data)
858 struct cmd_range_powermask_result *res = parsed_result;
861 range_powermask = res->powermask;
864 const char PROGMEM str_powermask[] = "powermask";
866 const parse_token_string_t PROGMEM cmd_range_powermask_range_powermask =
867 TOKEN_STRING_INITIALIZER(struct cmd_range_powermask_result, range,
869 const parse_token_string_t PROGMEM cmd_range_powermask_action =
870 TOKEN_STRING_INITIALIZER(struct cmd_range_powermask_result, action,
872 const parse_token_num_t PROGMEM cmd_range_powermask_powermask =
873 TOKEN_NUM_INITIALIZER(struct cmd_range_powermask_result, powermask,
877 const char PROGMEM help_range_powermask[] = "set range test powermask";
879 const parse_inst_t PROGMEM cmd_range_powermask = {
880 .f = cmd_range_powermask_parsed, /* function to call */
881 .data = NULL, /* 2nd arg of func */
882 .help_str = help_range_powermask,
883 .tokens = { /* token list, NULL terminated */
884 (PGM_P)&cmd_range_powermask_range_powermask,
885 (PGM_P)&cmd_range_powermask_action,
886 (PGM_P)&cmd_range_powermask_powermask,
893 /* this structure is filled when cmd_range_dstaddr is parsed successfully */
894 struct cmd_range_dstaddr_result {
895 fixed_string_t range;
896 fixed_string_t action;
900 /* function called when cmd_range_dstaddr is parsed successfully */
901 static void cmd_range_dstaddr_parsed(void *parsed_result, void *data)
903 struct cmd_range_dstaddr_result *res = parsed_result;
906 range_dstaddr = res->dstaddr;
909 const char PROGMEM str_dstaddr[] = "dstaddr";
911 const parse_token_string_t PROGMEM cmd_range_dstaddr_range_dstaddr =
912 TOKEN_STRING_INITIALIZER(struct cmd_range_dstaddr_result, range,
914 const parse_token_string_t PROGMEM cmd_range_dstaddr_action =
915 TOKEN_STRING_INITIALIZER(struct cmd_range_dstaddr_result, action,
917 const parse_token_num_t PROGMEM cmd_range_dstaddr_dstaddr =
918 TOKEN_NUM_INITIALIZER(struct cmd_range_dstaddr_result, dstaddr, UINT64);
921 const char PROGMEM help_range_dstaddr[] = "set register rangeing dstaddr";
923 const parse_inst_t PROGMEM cmd_range_dstaddr = {
924 .f = cmd_range_dstaddr_parsed, /* function to call */
925 .data = NULL, /* 2nd arg of func */
926 .help_str = help_range_dstaddr,
927 .tokens = { /* token list, NULL terminated */
928 (PGM_P)&cmd_range_dstaddr_range_dstaddr,
929 (PGM_P)&cmd_range_dstaddr_action,
930 (PGM_P)&cmd_range_dstaddr_dstaddr,
938 /* this structure is filled when cmd_monitor is parsed successfully */
939 struct cmd_monitor_result {
940 fixed_string_t monitor;
941 fixed_string_t action;
944 /* function called when cmd_monitor is parsed successfully */
945 static void cmd_monitor_parsed(void *parsed_result, void *data)
947 struct cmd_monitor_result *res = parsed_result;
948 struct monitor_reg *m;
951 if (!strcmp_P(res->action, PSTR("show"))) {
952 printf_P(PSTR("monitor period is %d ms, %d regs in list\r\n"),
953 monitor_period_ms, monitor_count);
954 LIST_FOREACH(m, &xbee_monitor_list, next)
955 printf_P(PSTR(" %S\r\n"), m->desc);
957 else if (!strcmp_P(res->action, PSTR("start"))) {
958 if (monitor_running) {
959 printf_P(PSTR("already running\r\n"));
962 if (monitor_count == 0) {
963 printf_P(PSTR("no regs to be monitored\r\n"));
966 callout_init(&monitor_event, monitor_cb, NULL, 1);
968 monitor_current = LIST_FIRST(&xbee_monitor_list);
969 callout_schedule(&xbeeboard.intr_cm,
970 &monitor_event, 0); /* immediate */
971 printf_P(PSTR("monitor cb: %S %s\r\n"),
972 monitor_current->desc,
973 monitor_current->atcmd);
976 else if (!strcmp_P(res->action, PSTR("end"))) {
977 if (monitor_running == 0) {
978 printf_P(PSTR("not running\r\n"));
981 callout_stop(&xbeeboard.intr_cm, &monitor_event);
986 const char PROGMEM str_monitor[] = "monitor";
987 const char PROGMEM str_monitor_tokens[] = "show#start#end";
989 const parse_token_string_t PROGMEM cmd_monitor_monitor =
990 TOKEN_STRING_INITIALIZER(struct cmd_monitor_result, monitor,
992 const parse_token_string_t PROGMEM cmd_monitor_action =
993 TOKEN_STRING_INITIALIZER(struct cmd_monitor_result, action,
996 const char PROGMEM help_monitor[] = "start/stop/show current monitoring";
998 const parse_inst_t PROGMEM cmd_monitor = {
999 .f = cmd_monitor_parsed, /* function to call */
1000 .data = NULL, /* 2nd arg of func */
1001 .help_str = help_monitor,
1002 .tokens = { /* token list, NULL terminated */
1003 (PGM_P)&cmd_monitor_monitor,
1004 (PGM_P)&cmd_monitor_action,
1011 /* this structure is filled when cmd_monitor_add is parsed successfully */
1012 struct cmd_monitor_add_result {
1013 fixed_string_t monitor;
1014 fixed_string_t action;
1015 struct xbee_atcmd *cmd;
1018 /* function called when cmd_monitor_add is parsed successfully */
1019 static void cmd_monitor_add_parsed(void *parsed_result, void *data)
1021 struct cmd_monitor_add_result *res = parsed_result;
1022 struct monitor_reg *m;
1023 struct xbee_atcmd copy;
1026 memcpy_P(©, res->cmd, sizeof(copy));
1027 LIST_FOREACH(m, &xbee_monitor_list, next) {
1028 if (!strcmp_P(m->atcmd, copy.name))
1033 printf_P(PSTR("already exist\r\n"));
1037 m = malloc(sizeof(*m));
1039 printf_P(PSTR("no mem\r\n"));
1042 m->desc = copy.desc;
1043 strcpy_P(m->atcmd, copy.name);
1044 LIST_INSERT_HEAD(&xbee_monitor_list, m, next);
1048 const char PROGMEM str_monitor_add[] = "add";
1050 const parse_token_string_t PROGMEM cmd_monitor_add_monitor_add =
1051 TOKEN_STRING_INITIALIZER(struct cmd_monitor_add_result, monitor,
1053 const parse_token_string_t PROGMEM cmd_monitor_add_action =
1054 TOKEN_STRING_INITIALIZER(struct cmd_monitor_add_result, action,
1056 const parse_token_atcmd_t PROGMEM cmd_monitor_add_atcmd =
1057 TOKEN_ATCMD_INITIALIZER(struct cmd_monitor_add_result, cmd, &xbee_dev,
1058 XBEE_ATCMD_F_READ, XBEE_ATCMD_F_READ);
1061 const char PROGMEM help_monitor_add[] = "add a register in monitor list";
1063 const parse_inst_t PROGMEM cmd_monitor_add = {
1064 .f = cmd_monitor_add_parsed, /* function to call */
1065 .data = NULL, /* 2nd arg of func */
1066 .help_str = help_monitor_add,
1067 .tokens = { /* token list, NULL terminated */
1068 (PGM_P)&cmd_monitor_add_monitor_add,
1069 (PGM_P)&cmd_monitor_add_action,
1070 (PGM_P)&cmd_monitor_add_atcmd,
1077 /* this structure is filled when cmd_monitor_period is parsed successfully */
1078 struct cmd_monitor_period_result {
1079 fixed_string_t monitor;
1080 fixed_string_t action;
1084 /* function called when cmd_monitor_period is parsed successfully */
1085 static void cmd_monitor_period_parsed(void *parsed_result, void *data)
1087 struct cmd_monitor_period_result *res = parsed_result;
1090 if (res->period < 100) {
1091 printf_P(PSTR("error, minimum period is 100 ms\r\n"));
1095 monitor_period_ms = res->period;
1098 const char PROGMEM str_monitor_period[] = "period";
1100 const parse_token_string_t PROGMEM cmd_monitor_period_monitor_period =
1101 TOKEN_STRING_INITIALIZER(struct cmd_monitor_period_result, monitor,
1103 const parse_token_string_t PROGMEM cmd_monitor_period_action =
1104 TOKEN_STRING_INITIALIZER(struct cmd_monitor_period_result, action,
1105 str_monitor_period);
1106 const parse_token_num_t PROGMEM cmd_monitor_period_period =
1107 TOKEN_NUM_INITIALIZER(struct cmd_monitor_period_result, period, UINT32);
1110 const char PROGMEM help_monitor_period[] = "set register monitoring period";
1112 const parse_inst_t PROGMEM cmd_monitor_period = {
1113 .f = cmd_monitor_period_parsed, /* function to call */
1114 .data = NULL, /* 2nd arg of func */
1115 .help_str = help_monitor_period,
1116 .tokens = { /* token list, NULL terminated */
1117 (PGM_P)&cmd_monitor_period_monitor_period,
1118 (PGM_P)&cmd_monitor_period_action,
1119 (PGM_P)&cmd_monitor_period_period,
1126 /* this structure is filled when cmd_monitor_del is parsed successfully */
1127 struct cmd_monitor_del_result {
1128 fixed_string_t monitor;
1129 fixed_string_t action;
1130 struct monitor_reg *m;
1133 /* function called when cmd_monitor_del is parsed successfully */
1134 static void cmd_monitor_del_parsed(void *parsed_result, void *data)
1136 struct cmd_monitor_del_result *res = parsed_result;
1139 monitor_current = LIST_NEXT(res->m, next);
1140 LIST_REMOVE(res->m, next);
1143 if (monitor_count == 0) {
1144 printf_P(PSTR("Disable monitoring, no more event\r\n"));
1145 callout_stop(&xbeeboard.intr_cm, &monitor_event);
1146 monitor_running = 0;
1151 const char PROGMEM str_monitor_del[] = "del";
1153 const parse_token_string_t PROGMEM cmd_monitor_del_monitor_del =
1154 TOKEN_STRING_INITIALIZER(struct cmd_monitor_del_result, monitor,
1156 const parse_token_string_t PROGMEM cmd_monitor_del_action =
1157 TOKEN_STRING_INITIALIZER(struct cmd_monitor_del_result, action,
1159 const parse_token_monitor_t PROGMEM cmd_monitor_del_atcmd =
1160 TOKEN_MONITOR_INITIALIZER(struct cmd_monitor_del_result, m);
1163 const char PROGMEM help_monitor_del[] = "del a register in monitor list";
1165 const parse_inst_t PROGMEM cmd_monitor_del = {
1166 .f = cmd_monitor_del_parsed, /* function to call */
1167 .data = NULL, /* 2nd arg of func */
1168 .help_str = help_monitor_del,
1169 .tokens = { /* token list, NULL terminated */
1170 (PGM_P)&cmd_monitor_del_monitor_del,
1171 (PGM_P)&cmd_monitor_del_action,
1172 (PGM_P)&cmd_monitor_del_atcmd,
1180 /* this structure is filled when cmd_ping is parsed successfully */
1181 struct cmd_ping_result {
1182 fixed_string_t ping;
1185 /* function called when cmd_ping is parsed successfully */
1186 static void cmd_ping_parsed(void *parsed_result, void *data)
1188 volatile uint8_t done = 0;
1190 (void)parsed_result;
1192 xbeeapp_send_atcmd("VL", NULL, 0, dump_xbee_atresp_cb, (void *)&done);
1196 const char PROGMEM str_ping[] = "ping";
1198 const parse_token_string_t PROGMEM cmd_ping_ping =
1199 TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping,
1202 const char PROGMEM help_ping[] = "Send a ping to the xbee device";
1204 const parse_inst_t PROGMEM cmd_ping = {
1205 .f = cmd_ping_parsed, /* function to call */
1206 .data = NULL, /* 2nd arg of func */
1207 .help_str = help_ping,
1208 .tokens = { /* token list, NULL terminated */
1209 (PGM_P)&cmd_ping_ping,
1216 /* this structure is filled when cmd_raw is parsed successfully */
1217 struct cmd_raw_result {
1221 /* function called when cmd_raw is parsed successfully */
1222 static void cmd_raw_parsed(void *parsed_result, void *data)
1224 (void)parsed_result;
1227 if (range_running || monitor_running) {
1228 printf_P(PSTR("stop running range or monitor first\r\n"));
1231 printf_P(PSTR("switched to raw mode, CTRL-D to exit\r\n"));
1232 rdline_stop(&xbeeboard.rdl); /* don't display prompt when return */
1236 const char PROGMEM str_raw[] = "raw";
1238 const parse_token_string_t PROGMEM cmd_raw_raw =
1239 TOKEN_STRING_INITIALIZER(struct cmd_raw_result, raw,
1242 const char PROGMEM help_raw[] = "Switch to raw mode";
1244 const parse_inst_t PROGMEM cmd_raw = {
1245 .f = cmd_raw_parsed, /* function to call */
1246 .data = NULL, /* 2nd arg of func */
1247 .help_str = help_raw,
1248 .tokens = { /* token list, NULL terminated */
1249 (PGM_P)&cmd_raw_raw,
1254 /**********************************************************/
1256 /* this structure is filled when cmd_baudrate is parsed successfully */
1257 struct cmd_baudrate_result {
1258 fixed_string_t arg0;
1262 /* function called when cmd_baudrate is parsed successfully */
1263 static void cmd_baudrate_parsed(void * parsed_result, __attribute__((unused)) void *data)
1265 struct cmd_baudrate_result *res = parsed_result;
1266 struct uart_config c;
1268 uart_getconf(XBEE_UART, &c);
1269 c.baudrate = res->arg1;
1270 uart_setconf(XBEE_UART, &c);
1273 const char PROGMEM str_baudrate_arg0[] = "baudrate";
1274 const parse_token_string_t PROGMEM cmd_baudrate_arg0 =
1275 TOKEN_STRING_INITIALIZER(struct cmd_baudrate_result, arg0,
1277 const parse_token_num_t PROGMEM cmd_baudrate_arg1 =
1278 TOKEN_NUM_INITIALIZER(struct cmd_baudrate_result, arg1,
1281 const char PROGMEM help_baudrate[] = "Change xbee baudrate";
1282 const parse_inst_t PROGMEM cmd_baudrate = {
1283 .f = cmd_baudrate_parsed, /* function to call */
1284 .data = NULL, /* 2nd arg of func */
1285 .help_str = help_baudrate,
1286 .tokens = { /* token list, NULL terminated */
1287 (PGM_P)&cmd_baudrate_arg0,
1288 (PGM_P)&cmd_baudrate_arg1,
1294 /**********************************************************/
1296 /* this structure is filled when cmd_beep is parsed successfully */
1297 struct cmd_beep_result {
1298 fixed_string_t beep;
1301 /* function called when cmd_beep is parsed successfully */
1302 static void cmd_beep_parsed(void *parsed_result, void *data)
1304 (void)parsed_result;
1315 const char PROGMEM str_beep[] = "beep";
1316 const parse_token_string_t PROGMEM cmd_beep_beep =
1317 TOKEN_STRING_INITIALIZER(struct cmd_beep_result, beep,
1320 const char PROGMEM help_beep[] = "Send a beep";
1322 const parse_inst_t PROGMEM cmd_beep = {
1323 .f = cmd_beep_parsed, /* function to call */
1324 .data = NULL, /* 2nd arg of func */
1325 .help_str = help_beep,
1326 .tokens = { /* token list, NULL terminated */
1327 (PGM_P)&cmd_beep_beep,
1332 /**********************************************************/
1334 /* this structure is filled when cmd_servo is parsed successfully */
1335 struct cmd_servo_result {
1336 fixed_string_t arg0;
1337 fixed_string_t arg1;
1342 /* function called when cmd_servo is parsed successfully */
1343 static void cmd_servo_parsed(void * parsed_result, void *data)
1345 struct cmd_servo_result *res = parsed_result;
1349 if (!strcmp_P(res->arg1, PSTR("set"))) {
1350 if (res->num >= N_SERVO) {
1351 printf_P(PSTR("bad servo num\n"));
1354 if (res->val >= 1024) {
1355 printf_P(PSTR("bad servo val\n"));
1358 spi_servo_set(res->num, res->val);
1360 else if (!strcmp_P(res->arg1, PSTR("bypass"))) {
1361 spi_servo_set_bypass(!!res->val);
1363 else if (!strcmp_P(res->arg1, PSTR("ppm"))) {
1364 spi_servo_set_ppm(!!res->val);
1366 else if (!strcmp_P(res->arg1, PSTR("show"))) {
1371 const char PROGMEM str_servo_arg0[] = "servo";
1372 const parse_token_string_t PROGMEM cmd_servo_arg0 =
1373 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg0,
1375 const char PROGMEM str_servo_arg1_set[] = "set";
1376 const parse_token_string_t PROGMEM cmd_servo_arg1_set =
1377 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1378 str_servo_arg1_set);
1379 const parse_token_num_t PROGMEM cmd_servo_num =
1380 TOKEN_NUM_INITIALIZER(struct cmd_servo_result, num,
1382 const parse_token_num_t PROGMEM cmd_servo_val =
1383 TOKEN_NUM_INITIALIZER(struct cmd_servo_result, val,
1386 const char PROGMEM help_servo_set[] = "set servo value";
1387 const parse_inst_t PROGMEM cmd_servo_set = {
1388 .f = cmd_servo_parsed, /* function to call */
1389 .data = NULL, /* 2nd arg of func */
1390 .help_str = help_servo_set,
1391 .tokens = { /* token list, NULL terminated */
1392 (PGM_P)&cmd_servo_arg0,
1393 (PGM_P)&cmd_servo_arg1_set,
1394 (PGM_P)&cmd_servo_num,
1395 (PGM_P)&cmd_servo_val,
1400 const char PROGMEM str_servo_arg1_show[] = "show";
1401 const parse_token_string_t PROGMEM cmd_servo_arg1_show =
1402 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1403 str_servo_arg1_show);
1405 const char PROGMEM help_servo_show[] = "read servo and config";
1406 const parse_inst_t PROGMEM cmd_servo_show = {
1407 .f = cmd_servo_parsed, /* function to call */
1408 .data = NULL, /* 2nd arg of func */
1409 .help_str = help_servo_show,
1410 .tokens = { /* token list, NULL terminated */
1411 (PGM_P)&cmd_servo_arg0,
1412 (PGM_P)&cmd_servo_arg1_show,
1417 const char PROGMEM str_servo_arg1_bypassppm[] = "bypass#ppm";
1418 const parse_token_string_t PROGMEM cmd_servo_arg1_bypassppm =
1419 TOKEN_STRING_INITIALIZER(struct cmd_servo_result, arg1,
1420 str_servo_arg1_bypassppm);
1422 const char PROGMEM help_servo_bypassppm[] = "change bypass/ppm";
1423 const parse_inst_t PROGMEM cmd_servo_bypassppm = {
1424 .f = cmd_servo_parsed, /* function to call */
1425 .data = NULL, /* 2nd arg of func */
1426 .help_str = help_servo_bypassppm,
1427 .tokens = { /* token list, NULL terminated */
1428 (PGM_P)&cmd_servo_arg0,
1429 (PGM_P)&cmd_servo_arg1_bypassppm,
1430 (PGM_P)&cmd_servo_val,
1435 /**********************************************************/
1437 /* this structure is filled when cmd_test_spi is parsed successfully */
1438 struct cmd_test_spi_result {
1439 fixed_string_t arg0;
1442 static void cmd_test_spi_parsed(void * parsed_result, void *data)
1444 uint8_t i, flags, wait_time = 0;
1447 (void)parsed_result;
1450 spi_servo_set_bypass(0);
1451 spi_servo_set_ppm(0);
1453 /* stress test: send many commands, no wait between each servo
1454 * of a series, and a variable delay between series */
1455 printf_P(PSTR("stress test\r\n"));
1456 while (!cmdline_keypressed()) {
1468 for (i = 0; i < 6; i++)
1469 spi_servo_set(i, val);
1472 printf_P(PSTR("%4.4d %4.4d %4.4d %4.4d %4.4d %4.4d\r\n"),
1473 spi_servo_get(0), spi_servo_get(1), spi_servo_get(2),
1474 spi_servo_get(3), spi_servo_get(4), spi_servo_get(5));
1477 printf_P(PSTR("bypass mode, with spi commands in background\r\n"));
1478 spi_servo_set_bypass(1);
1480 /* test bypass mode */
1481 while (!cmdline_keypressed()) {
1493 for (i = 0; i < 6; i++)
1494 spi_servo_set(i, val);
1497 printf_P(PSTR("%4.4d %4.4d %4.4d %4.4d %4.4d %4.4d\r\n"),
1498 spi_servo_get(0), spi_servo_get(1), spi_servo_get(2),
1499 spi_servo_get(3), spi_servo_get(4), spi_servo_get(5));
1502 printf_P(PSTR("PPM to servo\r\n"));
1503 spi_servo_set_bypass(0);
1504 spi_servo_set_ppm(0);
1506 /* test PPM to servo (bypass) mode */
1507 while (!cmdline_keypressed()) {
1508 for (i = 0; i < 6; i++) {
1509 val = spi_servo_get(i);
1510 spi_servo_set(i, val);
1514 printf_P(PSTR("PPM to (servo + PPM)\r\n"));
1515 spi_servo_set_bypass(0);
1516 spi_servo_set_ppm(1);
1518 /* test PPM to servo (bypass) mode */
1519 while (!cmdline_keypressed()) {
1520 for (i = 0; i < 6; i++) {
1521 val = spi_servo_get(i);
1522 spi_servo_set(i, val);
1527 const char PROGMEM str_test_spi_arg0[] = "test_spi";
1528 const parse_token_string_t PROGMEM cmd_test_spi_arg0 =
1529 TOKEN_STRING_INITIALIZER(struct cmd_test_spi_result, arg0,
1532 const char PROGMEM help_test_spi[] = "Test the spi";
1533 const parse_inst_t PROGMEM cmd_test_spi = {
1534 .f = cmd_test_spi_parsed, /* function to call */
1535 .data = NULL, /* 2nd arg of func */
1536 .help_str = help_test_spi,
1537 .tokens = { /* token list, NULL terminated */
1538 (PGM_P)&cmd_test_spi_arg0,
1543 /**********************************************************/
1545 /* this structure is filled when cmd_dump_xbee_stats is parsed successfully */
1546 struct cmd_dump_xbee_stats_result {
1547 fixed_string_t arg0;
1550 static void cmd_dump_xbee_stats_parsed(void *parsed_result, void *data)
1552 (void)parsed_result;
1555 xbee_dump_stats(xbee_dev);
1558 const char PROGMEM str_dump_xbee_stats_arg0[] = "dump_xbee_stats";
1559 const parse_token_string_t PROGMEM cmd_dump_xbee_stats_arg0 =
1560 TOKEN_STRING_INITIALIZER(struct cmd_dump_xbee_stats_result, arg0,
1561 str_dump_xbee_stats_arg0);
1563 const char PROGMEM help_dump_xbee_stats[] = "Test the spi";
1564 const parse_inst_t PROGMEM cmd_dump_xbee_stats = {
1565 .f = cmd_dump_xbee_stats_parsed, /* function to call */
1566 .data = NULL, /* 2nd arg of func */
1567 .help_str = help_dump_xbee_stats,
1568 .tokens = { /* token list, NULL terminated */
1569 (PGM_P)&cmd_dump_xbee_stats_arg0,
1574 /**********************************************************/
1576 /* this structure is filled when cmd_rc_proto_stats is parsed successfully */
1577 struct cmd_rc_proto_stats_result {
1578 fixed_string_t arg0;
1579 fixed_string_t arg1;
1582 static void cmd_rc_proto_stats_parsed(void *parsed_result, void *data)
1584 struct cmd_rc_proto_stats_result *res = parsed_result;
1587 if (!strcmp(res->arg1, "show"))
1588 rc_proto_dump_stats();
1590 rc_proto_reset_stats();
1593 const char PROGMEM str_rc_proto_stats_arg0[] = "rc_proto_stats";
1594 const parse_token_string_t PROGMEM cmd_rc_proto_stats_arg0 =
1595 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_stats_result, arg0,
1596 str_rc_proto_stats_arg0);
1597 const char PROGMEM str_rc_proto_stats_arg1[] = "show#reset";
1598 const parse_token_string_t PROGMEM cmd_rc_proto_stats_arg1 =
1599 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_stats_result, arg1,
1600 str_rc_proto_stats_arg1);
1602 const char PROGMEM help_rc_proto_stats[] = "dump rc_proto stats";
1603 const parse_inst_t PROGMEM cmd_rc_proto_stats = {
1604 .f = cmd_rc_proto_stats_parsed, /* function to call */
1605 .data = NULL, /* 2nd arg of func */
1606 .help_str = help_rc_proto_stats,
1607 .tokens = { /* token list, NULL terminated */
1608 (PGM_P)&cmd_rc_proto_stats_arg0,
1609 (PGM_P)&cmd_rc_proto_stats_arg1,
1614 /**********************************************************/
1616 /* this structure is filled when cmd_rc_proto_hello is parsed successfully */
1617 struct cmd_rc_proto_hello_result {
1618 fixed_string_t rc_proto_hello;
1620 struct xbee_neigh *neigh;
1623 fixed_string_t data;
1626 /* function called when cmd_rc_proto_hello is parsed successfully */
1627 static void cmd_rc_proto_hello_parsed(void *parsed_result, void *use_neigh)
1629 struct cmd_rc_proto_hello_result *res = parsed_result;
1630 uint16_t now, next, diff;
1635 addr = res->neigh->addr;
1645 while (!cmdline_keypressed() && res->count != 0) {
1651 if (diff < res->period)
1654 rc_proto_send_hello(addr, res->data, strlen(res->data), -1);
1655 next += res->period;
1660 const char PROGMEM str_rc_proto_hello[] = "rc_proto_hello";
1662 const parse_token_string_t PROGMEM cmd_rc_proto_hello_rc_proto_hello =
1663 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_hello_result, rc_proto_hello,
1664 str_rc_proto_hello);
1666 const parse_token_num_t PROGMEM cmd_rc_proto_hello_addr =
1667 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_hello_result, addr, UINT64);
1669 const parse_token_num_t PROGMEM cmd_rc_proto_hello_period =
1670 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_hello_result, period, UINT16);
1672 const parse_token_num_t PROGMEM cmd_rc_proto_hello_count =
1673 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_hello_result, count, UINT16);
1675 const parse_token_string_t PROGMEM cmd_rc_proto_hello_data =
1676 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_hello_result, data, NULL);
1678 const char PROGMEM help_rc_proto_hello[] =
1679 "Send hello msg to a node: addr, period_ms, count, str";
1681 const parse_inst_t PROGMEM cmd_rc_proto_hello = {
1682 .f = cmd_rc_proto_hello_parsed, /* function to call */
1683 .data = NULL, /* 2nd arg of func */
1684 .help_str = help_rc_proto_hello,
1685 .tokens = { /* token list, NULL terminated */
1686 (PGM_P)&cmd_rc_proto_hello_rc_proto_hello,
1687 (PGM_P)&cmd_rc_proto_hello_addr,
1688 (PGM_P)&cmd_rc_proto_hello_period,
1689 (PGM_P)&cmd_rc_proto_hello_count,
1690 (PGM_P)&cmd_rc_proto_hello_data,
1695 const parse_token_neighbor_t PROGMEM cmd_rc_proto_hello_neigh =
1696 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_rc_proto_hello_result, neigh,
1699 const parse_inst_t PROGMEM cmd_rc_proto_hello_name = {
1700 .f = cmd_rc_proto_hello_parsed, /* function to call */
1701 .data = (void *)1, /* 2nd arg of func */
1702 .help_str = help_rc_proto_hello,
1703 .tokens = { /* token list, NULL terminated */
1704 (PGM_P)&cmd_rc_proto_hello_rc_proto_hello,
1705 (PGM_P)&cmd_rc_proto_hello_neigh,
1706 (PGM_P)&cmd_rc_proto_hello_period,
1707 (PGM_P)&cmd_rc_proto_hello_count,
1708 (PGM_P)&cmd_rc_proto_hello_data,
1713 /**********************************************************/
1715 /* this structure is filled when cmd_rc_proto_echo is parsed successfully */
1716 struct cmd_rc_proto_echo_result {
1717 fixed_string_t rc_proto_echo;
1719 struct xbee_neigh *neigh;
1722 fixed_string_t data;
1725 /* function called when cmd_rc_proto_echo is parsed successfully */
1726 static void cmd_rc_proto_echo_parsed(void *parsed_result, void *use_neigh)
1728 struct cmd_rc_proto_echo_result *res = parsed_result;
1729 uint16_t now, next, diff;
1734 addr = res->neigh->addr;
1744 while (!cmdline_keypressed() && res->count != 0) {
1750 if (diff < res->period)
1753 rc_proto_send_echo_req(addr, res->data, strlen(res->data), -1);
1754 next += res->period;
1759 const char PROGMEM str_rc_proto_echo[] = "rc_proto_echo";
1761 const parse_token_string_t PROGMEM cmd_rc_proto_echo_rc_proto_echo =
1762 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_echo_result, rc_proto_echo,
1765 const parse_token_num_t PROGMEM cmd_rc_proto_echo_addr =
1766 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_echo_result, addr, UINT64);
1768 const parse_token_num_t PROGMEM cmd_rc_proto_echo_period =
1769 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_echo_result, period, UINT16);
1771 const parse_token_num_t PROGMEM cmd_rc_proto_echo_count =
1772 TOKEN_NUM_INITIALIZER(struct cmd_rc_proto_echo_result, count, UINT16);
1774 const parse_token_string_t PROGMEM cmd_rc_proto_echo_data =
1775 TOKEN_STRING_INITIALIZER(struct cmd_rc_proto_echo_result, data, NULL);
1777 const char PROGMEM help_rc_proto_echo[] =
1778 "Send echo msg to a node: addr, period_ms, count, str";
1780 const parse_inst_t PROGMEM cmd_rc_proto_echo = {
1781 .f = cmd_rc_proto_echo_parsed, /* function to call */
1782 .data = NULL, /* 2nd arg of func */
1783 .help_str = help_rc_proto_echo,
1784 .tokens = { /* token list, NULL terminated */
1785 (PGM_P)&cmd_rc_proto_echo_rc_proto_echo,
1786 (PGM_P)&cmd_rc_proto_echo_addr,
1787 (PGM_P)&cmd_rc_proto_echo_period,
1788 (PGM_P)&cmd_rc_proto_echo_count,
1789 (PGM_P)&cmd_rc_proto_echo_data,
1794 const parse_token_neighbor_t PROGMEM cmd_rc_proto_echo_neigh =
1795 TOKEN_NEIGHBOR_INITIALIZER(struct cmd_rc_proto_echo_result, neigh,
1798 const parse_inst_t PROGMEM cmd_rc_proto_echo_name = {
1799 .f = cmd_rc_proto_echo_parsed, /* function to call */
1800 .data = (void *)1, /* 2nd arg of func */
1801 .help_str = help_rc_proto_echo,
1802 .tokens = { /* token list, NULL terminated */
1803 (PGM_P)&cmd_rc_proto_echo_rc_proto_echo,
1804 (PGM_P)&cmd_rc_proto_echo_neigh,
1805 (PGM_P)&cmd_rc_proto_echo_period,
1806 (PGM_P)&cmd_rc_proto_echo_count,
1807 (PGM_P)&cmd_rc_proto_echo_data,
1812 /**********************************************************/
1814 /* this structure is filled when cmd_test_eeprom_config is parsed successfully */
1815 struct cmd_test_eeprom_config_result {
1816 fixed_string_t arg0;
1819 static void cmd_test_eeprom_config_parsed(void *parsed_result, void *data)
1821 (void)parsed_result;
1825 eeprom_append_cmd("salut1\n");
1827 eeprom_append_cmd("salut2\n");
1828 eeprom_append_cmd("salut3\n");
1829 eeprom_append_cmd("salut4\n");
1831 eeprom_insert_cmd_before("coin\n", 0);
1832 eeprom_insert_cmd_before("coin2\n", 2);
1834 eeprom_delete_cmd(2);
1835 eeprom_delete_cmd(0);
1839 const char PROGMEM str_test_eeprom_config_arg0[] = "test_eeprom_config";
1840 const parse_token_string_t PROGMEM cmd_test_eeprom_config_arg0 =
1841 TOKEN_STRING_INITIALIZER(struct cmd_test_eeprom_config_result, arg0,
1842 str_test_eeprom_config_arg0);
1844 const char PROGMEM help_test_eeprom_config[] = "Test the eeprom configuration";
1845 const parse_inst_t PROGMEM cmd_test_eeprom_config = {
1846 .f = cmd_test_eeprom_config_parsed, /* function to call */
1847 .data = NULL, /* 2nd arg of func */
1848 .help_str = help_test_eeprom_config,
1849 .tokens = { /* token list, NULL terminated */
1850 (PGM_P)&cmd_test_eeprom_config_arg0,
1857 struct cmd_eeprom_del_result {
1859 fixed_string_t action;
1863 static void cmd_eeprom_del_parsed(void *parsed_result,
1866 struct cmd_eeprom_del_result *res = parsed_result;
1869 if (eeprom_delete_cmd(res->n) < 0)
1870 printf_P(PSTR("cannot delete command\n"));
1874 const char PROGMEM str_eeprom_del_eeprom[] = "eeprom";
1875 const parse_token_string_t PROGMEM cmd_eeprom_del_cmd =
1876 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, cmd,
1877 str_eeprom_del_eeprom);
1878 const char PROGMEM str_eeprom_del_del[] = "del";
1879 const parse_token_string_t PROGMEM cmd_eeprom_del_action =
1880 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_del_result, action,
1881 str_eeprom_del_del);
1882 const parse_token_num_t PROGMEM cmd_eeprom_del_num =
1883 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_del_result, n,
1886 const char PROGMEM help_eeprom_del[] = "delete an eeprom init command";
1887 const parse_inst_t PROGMEM cmd_eeprom_del = {
1888 .f = cmd_eeprom_del_parsed, /* function to call */
1889 .data = NULL, /* 2nd arg of func */
1890 .help_str = help_eeprom_del,
1891 .tokens = { /* token list, NULL terminated */
1892 (PGM_P)&cmd_eeprom_del_cmd,
1893 (PGM_P)&cmd_eeprom_del_action,
1894 (PGM_P)&cmd_eeprom_del_num,
1901 struct cmd_eeprom_add_result {
1903 fixed_string_t action;
1907 static void cmd_eeprom_add_parsed(void *parsed_result,
1910 struct cmd_eeprom_add_result *res = parsed_result;
1916 rdline_init(&rdl, cmdline_write_char, NULL, NULL);
1917 rdline_newline(&rdl, "> ");
1919 /* XXX bad: we should not block as we do not serve callout */
1921 c = cmdline_dev_recv(NULL);
1925 ret = rdline_char_in(&rdl, c);
1927 printf_P(PSTR("abort\n"));
1934 buffer = rdline_get_buffer(&rdl);
1936 eeprom_insert_cmd_before(buffer, res->n);
1938 eeprom_append_cmd(buffer);
1942 const char PROGMEM str_eeprom_add_eeprom[] = "eeprom";
1943 const parse_token_string_t PROGMEM cmd_eeprom_add_cmd =
1944 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, cmd,
1945 str_eeprom_add_eeprom);
1946 const char PROGMEM str_eeprom_add_add[] = "add";
1947 const parse_token_string_t PROGMEM cmd_eeprom_add_action =
1948 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_add_result, action,
1949 str_eeprom_add_add);
1950 const parse_token_num_t PROGMEM cmd_eeprom_add_num =
1951 TOKEN_NUM_INITIALIZER(struct cmd_eeprom_add_result, n,
1954 const char PROGMEM help_eeprom_add[] = "insert an eeprom init command";
1955 const parse_inst_t PROGMEM cmd_eeprom_add = {
1956 .f = cmd_eeprom_add_parsed, /* function to call */
1957 .data = NULL, /* 2nd arg of func */
1958 .help_str = help_eeprom_add,
1959 .tokens = { /* token list, NULL terminated */
1960 (PGM_P)&cmd_eeprom_add_cmd,
1961 (PGM_P)&cmd_eeprom_add_action,
1962 (PGM_P)&cmd_eeprom_add_num,
1967 const char PROGMEM help_eeprom_add2[] = "append an eeprom init command";
1968 const parse_inst_t PROGMEM cmd_eeprom_add2 = {
1969 .f = cmd_eeprom_add_parsed, /* function to call */
1970 .data = (void *)1, /* 2nd arg of func */
1971 .help_str = help_eeprom_add2,
1972 .tokens = { /* token list, NULL terminated */
1973 (PGM_P)&cmd_eeprom_add_cmd,
1974 (PGM_P)&cmd_eeprom_add_action,
1981 struct cmd_eeprom_list_result {
1983 fixed_string_t action;
1986 static void cmd_eeprom_list_parsed(void *parsed_result,
1989 (void)parsed_result;
1994 const char PROGMEM str_eeprom_list_eeprom[] = "eeprom";
1995 const parse_token_string_t PROGMEM cmd_eeprom_list_cmd =
1996 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, cmd,
1997 str_eeprom_list_eeprom);
1998 const char PROGMEM str_eeprom_list_list[] = "list";
1999 const parse_token_string_t PROGMEM cmd_eeprom_list_action =
2000 TOKEN_STRING_INITIALIZER(struct cmd_eeprom_list_result, action,
2001 str_eeprom_list_list);
2003 const char PROGMEM help_eeprom_list[] = "list all eeprom init commands";
2004 const parse_inst_t PROGMEM cmd_eeprom_list = {
2005 .f = cmd_eeprom_list_parsed, /* function to call */
2006 .data = NULL, /* 2nd arg of func */
2007 .help_str = help_eeprom_list,
2008 .tokens = { /* token list, NULL terminated */
2009 (PGM_P)&cmd_eeprom_list_cmd,
2010 (PGM_P)&cmd_eeprom_list_action,
2019 const parse_ctx_t PROGMEM main_ctx[] = {
2021 /* commands_gen.c */
2043 &cmd_range_powermask,
2046 &cmd_monitor_period,
2054 &cmd_servo_bypassppm,
2057 &cmd_dump_xbee_stats,
2058 &cmd_rc_proto_stats,
2059 &cmd_rc_proto_hello,
2060 &cmd_rc_proto_hello_name,
2062 &cmd_rc_proto_echo_name,
2063 &cmd_test_eeprom_config,