},
};
-/* ************* */
-
-/* this structure is filled when cmd_dump is parsed successfully */
-struct cmd_dump_result {
- fixed_string_t dump;
- fixed_string_t onoff;
-};
-
-/* function called when cmd_dump is parsed successfully */
-static void cmd_dump_parsed(void *parsed_result, void *data)
-{
- struct cmd_dump_result *res = parsed_result;
-
- (void)data;
- if (!strcmp(res->onoff, "on"))
- xbee_hexdump = 1;
- else
- xbee_hexdump = 0;
-}
-
-const char PROGMEM str_dump[] = "dump";
-const char PROGMEM str_dump_onoff[] = "on#off";
-
-const parse_token_string_t PROGMEM cmd_dump_dump =
- TOKEN_STRING_INITIALIZER(struct cmd_dump_result, dump,
- str_dump);
-
-const parse_token_string_t PROGMEM cmd_dump_onoff =
- TOKEN_STRING_INITIALIZER(struct cmd_dump_result, onoff,
- str_dump_onoff);
-
-const char PROGMEM help_dump[] = "enable/disable hexdump of received packets";
-
-const parse_inst_t PROGMEM cmd_dump = {
- .f = cmd_dump_parsed, /* function to call */
- .data = NULL, /* 2nd arg of func */
- .help_str = help_dump,
- .tokens = { /* token list, NULL terminated */
- (PGM_P)&cmd_dump_dump,
- (PGM_P)&cmd_dump_onoff,
- NULL,
- },
-};
-
-/* ************* */
-
-/* this structure is filled when cmd_debug is parsed successfully */
-struct cmd_debug_result {
- fixed_string_t debug;
- fixed_string_t onoff;
-};
-
-/* function called when cmd_debug is parsed successfully */
-static void cmd_debug_parsed(void *parsed_result, void *data)
-{
- struct cmd_debug_result *res = parsed_result;
-
- (void)data;
- if (!strcmp(res->onoff, "on"))
- xbee_debug = 1;
- else
- xbee_debug = 0;
-}
-
-const char PROGMEM str_debug[] = "debug";
-const char PROGMEM str_debug_onoff[] = "on#off";
-
-const parse_token_string_t PROGMEM cmd_debug_debug =
- TOKEN_STRING_INITIALIZER(struct cmd_debug_result, debug,
- str_debug);
-
-const parse_token_string_t PROGMEM cmd_debug_onoff =
- TOKEN_STRING_INITIALIZER(struct cmd_debug_result, onoff,
- str_debug_onoff);
-
-const char PROGMEM help_debug[] = "enable/disable additionnal debug";
-
-const parse_inst_t PROGMEM cmd_debug = {
- .f = cmd_debug_parsed, /* function to call */
- .data = NULL, /* 2nd arg of func */
- .help_str = help_debug,
- .tokens = { /* token list, NULL terminated */
- (PGM_P)&cmd_debug_debug,
- (PGM_P)&cmd_debug_onoff,
- NULL,
- },
-};
-
/**********************************************************/
/* this structure is filled when cmd_baudrate is parsed successfully */
&cmd_monitor_del,
&cmd_ping,
&cmd_raw,
- &cmd_dump,
- &cmd_debug,
&cmd_baudrate,
&cmd_beep,
&cmd_servo_set,
#include <aversive.h>
#include <aversive/endian.h>
+#include <aversive/wait.h>
#include <aversive/pgmspace.h>
#include <callout.h>
/* parameters */
int xbee_raw = 0;
-int xbee_hexdump = 0;
-int xbee_debug = 0;
static void __hexdump(const void *buf, unsigned int len)
{
LINE_LEN - out,
PSTR("%c"), c);
}
- printf_P(PSTR("%s\r\n"), line);
+ DEBUG(E_USER_XBEE, "%s");
}
}
{
unsigned i;
- printf_P(PSTR("dump %s\r\n"), title);
+ DEBUG(E_USER_XBEE, "dump %s", title);
for (i = 0; i < msg->iovlen; i++) {
- printf_P(PSTR("iovec %d at %p, len=%d\r\n"), i,
+ DEBUG(E_USER_XBEE, "iovec %d at %p, len=%d", i,
msg->iov[i].buf, msg->iov[i].len);
__hexdump(msg->iov[i].buf, msg->iov[i].len);
}
static void hexdump(const char *title, const void *buf, unsigned int len)
{
- printf_P(PSTR("dump %s at [%p], len=%d\r\n"), title, buf, len);
+ DEBUG(E_USER_XBEE, "dump %s at [%p], len=%d", title, buf, len);
__hexdump(buf, len);
}
(void)len;
if (ctx == NULL) {
- printf_P(PSTR("no context\r\n"));
+ ERROR(E_USER_XBEE, "no context");
return -1;
}
/* see if it matches a xmit query (atcmd_query must be NULL) */
if (ctx->atcmd_query[0] != '\0') {
- printf_P(PSTR("invalid response 2\r\n"));
+ ERROR(E_USER_XBEE, "invalid response 2");
return -1;
}
/* XXX use defines for these values */
if (frame->delivery_status == 0x00)
- printf_P(PSTR("Success\r\n"));
+ NOTICE(E_USER_XBEE, "Success");
else if (frame->delivery_status == 0x01)
- printf_P(PSTR("MAC ACK Failure\r\n"));
+ WARNING(E_USER_XBEE, "MAC ACK Failure");
else if (frame->delivery_status == 0x15)
- printf_P(PSTR("Invalid destination endpoint\r\n"));
+ WARNING(E_USER_XBEE, "Invalid destination endpoint");
else if (frame->delivery_status == 0x21)
- printf_P(PSTR("Network ACK Failure\r\n"));
+ WARNING(E_USER_XBEE, "Network ACK Failure");
else if (frame->delivery_status == 0x25)
- printf_P(PSTR("Route Not Found\r\n"));
+ WARNING(E_USER_XBEE, "Route Not Found");
return 0;
}
} __attribute__((packed)) *result;
if (ctx == NULL) {
- printf_P(PSTR("no context\r\n"));
+ ERROR(E_USER_XBEE, "no context");
return -1;
}
/* see if it matches query */
if (memcmp(atcmd_str, ctx->atcmd_query, 2)) {
- printf_P(PSTR("invalid response <%c%c><%s><%s>\r\n"),
+ ERROR(E_USER_XBEE, "invalid response <%c%c><%s><%s>",
frame->cmd & 0xFF,
(frame->cmd >> 8) & 0xFF,
atcmd_str, ctx->atcmd_query);
/* see if it exists */
cmd_pgm = xbee_atcmd_lookup_name(atcmd_str);
if (cmd_pgm == NULL) {
- printf_P(PSTR("unknown response\r\n"));
+ ERROR(E_USER_XBEE, "unknown response");
return -1;
}
memcpy_P(&cmd, cmd_pgm, sizeof(cmd));
/* bad status */
if (frame->status == 1) {
- printf_P(PSTR("Status is error\r\n"));
+ WARNING(E_USER_XBEE, "Status is error");
return -1;
}
else if (frame->status == 2) {
- printf_P(PSTR("Invalid command\r\n"));
+ WARNING(E_USER_XBEE, "Invalid command");
return -1;
}
else if (frame->status == 3) {
- printf_P(PSTR("Invalid parameter\r\n"));
+ WARNING(E_USER_XBEE, "Invalid parameter");
return -1;
}
else if (frame->status != 0) {
- printf_P(PSTR("Unknown status error %d\r\n"), frame->status);
+ WARNING(E_USER_XBEE, "Unknown status error %d",
+ frame->status);
return -1;
}
result = (void *)frame->data;
len -= offsetof(struct xbee_atresp_hdr, data);
if (cmd.flags & XBEE_ATCMD_F_PARAM_U8 && len == sizeof(uint8_t))
- printf_P(PSTR("<%s> is 0x%x (%d)\r\n"), atcmd_str, result->u8,
- result->u8);
+ NOTICE(E_USER_XBEE, "<%s> is 0x%x (%d)", atcmd_str,
+ result->u8, result->u8);
else if (cmd.flags & XBEE_ATCMD_F_PARAM_U16 && len == sizeof(uint16_t))
- printf_P(PSTR("<%s> is 0x%x (%d)\r\n"),
- atcmd_str,
- ntohs(result->u16), ntohs(result->u16));
+ NOTICE(E_USER_XBEE, "<%s> is 0x%x (%d)", atcmd_str,
+ ntohs(result->u16), ntohs(result->u16));
else if (cmd.flags & XBEE_ATCMD_F_PARAM_U32 && len == sizeof(uint32_t))
- printf_P(PSTR("<%s> is 0x%"PRIx32" (%"PRIu32")\r\n"),
- atcmd_str,
- ntohl(result->u32), ntohs(result->u32));
+ NOTICE(E_USER_XBEE, "<%s> is 0x%"PRIx32" (%"PRIu32")",
+ atcmd_str, ntohl(result->u32), ntohs(result->u32));
else if (cmd.flags & XBEE_ATCMD_F_PARAM_S16 && len == sizeof(int16_t))
- printf_P(PSTR("<%s> is %d\r\n"), atcmd_str, ntohs(result->s16));
+ NOTICE(E_USER_XBEE, "<%s> is %d",
+ atcmd_str, ntohs(result->s16));
else if (len == 0)
- printf_P(PSTR("no data, status ok\r\n"));
+ NOTICE(E_USER_XBEE, "no data, status ok");
else
hexdump("atcmd answer", frame->data, len);
-
return 0;
}
struct rc_proto_hello *rch =
(struct rc_proto_hello *) recvframe->data;
- if (xbee_debug)
- printf_P(PSTR("recv hello len=%d\r\n"),
- rch->datalen);
-
+ NOTICE(E_USER_XBEE, "recv hello len=%d",
+ rch->datalen);
+ /* XXX stats */
break;
}
default:
struct xbee_ctx *ctx = opaque;
int8_t ret = 0;
- if (xbee_debug)
- printf_P(PSTR("type=0x%x, channel=%d, ctx=%p\r\n"),
- type, channel, ctx);
+ NOTICE(E_USER_XBEE, "type=0x%x, channel=%d, ctx=%p",
+ type, channel, ctx);
/* if ctx is !NULL, it is an answer to a query */
if (ctx != NULL) {
/* XXX only delete timeout if answer matched */
xbee_unload_timeout(ctx);
- if (xbee_debug && ctx->atcmd_query)
- printf_P(PSTR("Received answer to query <%c%c>\r\n"),
- ctx->atcmd_query[0], ctx->atcmd_query[1]);
+ if (ctx->atcmd_query)
+ NOTICE(E_USER_XBEE, "Received answer to query <%c%c>",
+ ctx->atcmd_query[0], ctx->atcmd_query[1]);
}
/* some additional checks before sending */
switch (type) {
case XBEE_TYPE_MODEM_STATUS: {
- printf_P(PSTR("Received Modem Status frame\r\n"));
+ NOTICE(E_USER_XBEE, "Received Modem Status frame");
break;
}
} addr;
memcpy(&addr, frame, sizeof(addr));
addr.u64 = ntohll(addr.u64);
- printf_P(PSTR("from remote address %"PRIx32"%"PRIx32"\r\n"),
+ NOTICE(E_USER_XBEE, "from remote address %"PRIx32"%"PRIx32"",
addr.u32.high, addr.u32.low);
/* this answer contains an atcmd answer at offset 10 */
case XBEE_TYPE_EXPL_RECV:
case XBEE_TYPE_NODE_ID:
default:
- printf_P(PSTR("Invalid frame\r\n"));
+ ERROR(E_USER_XBEE, "Invalid frame");
ret = -1;
break;
}
- if (ret < 0)
- hexdump("undecoded rx frame", frame, len);
- else if (xbee_hexdump)
- hexdump("undecoded rx frame", frame, len);
+ WARNING(E_USER_XBEE, "undecoded rx frame");
+ hexdump("undecoded rx frame", frame, len);
/* restart command line if it was a blocking query */
if (ctx != NULL) {
channel = xbee_register_channel(xbee_dev, XBEE_CHANNEL_ANY,
xbeeapp_rx, NULL);
if (channel < 0) {
- printf_P(PSTR("cannot send: no free channel\r\n"));
+ ERROR(E_USER_XBEE, "cannot send: no free channel");
return -1;
}
ctx = &xbee_ctx[channel];
xbee_set_opaque(xbee_dev, channel, ctx);
- if (xbee_debug)
- printf_P(PSTR("send frame channel=%d type=0x%x\r\n"),
- channel, type);
- if (xbee_hexdump)
- hexdump_msg("xmit frame", msg);
+ NOTICE(E_USER_XBEE, "send frame channel=%d type=0x%x",
+ channel, type);
+ hexdump_msg("xmit frame", msg);
/* transmit the frame on this channel */
ret = xbee_tx_iovec(xbee_dev, channel, type, msg);
if (ret < 0) {
- printf_P(PSTR("cannot send\r\n"));
+ ERROR(E_USER_XBEE, "cannot send");
xbee_unregister_channel(xbee_dev, channel);
return -1;
}
int ret;
if (msg->iovlen + 2 > XBEE_MSG_MAXIOV) {
- printf_P(PSTR("too many iovecs\r\n"));
+ ERROR(E_USER_XBEE, "too many iovecs");
return -1;
}
(void)cm;
(void)clt;
- printf_P(PSTR("Timeout\r\n"));
+ WARNING(E_USER_XBEE, "Timeout");
/* restart command line */
xbee_stdin_enable();