From: Olivier Matz Date: Tue, 8 Apr 2014 20:39:09 +0000 (+0200) Subject: fix xbee_user after rework (e39c5d5) X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=bdfd2cee44033c3fd22d3091de815f235271e765;p=protos%2Fxbee-avr.git fix xbee_user after rework (e39c5d5) --- diff --git a/commands.c b/commands.c index f525e5f..68c0c6b 100644 --- a/commands.c +++ b/commands.c @@ -175,9 +175,9 @@ static int8_t dump_xbee_atresp_cb(int8_t retcode, void *frame, unsigned len, memcpy(atcmd_str, &recvframe->cmd, 2); atcmd_str[2] = '\0'; + atresp_to_str(buf, sizeof(buf), frame, len); len -= sizeof(*recvframe); - atresp_to_str(buf, sizeof(buf), frame); - NOTICE(E_USER_XBEE, "status ok, len=%d, %s", len, buf); + printf_P(PSTR("status ok, len=%d, %s\n"), len, buf); return XBEE_USER_RETCODE_OK; } diff --git a/xbee_user.c b/xbee_user.c index 9d3da99..ff57b8e 100644 --- a/xbee_user.c +++ b/xbee_user.c @@ -139,7 +139,8 @@ static int parse_xmit_status(struct xbee_ctx *ctx, /* Write in a human readable format the content of an atcmd response frame. It * assumes the frame is valid .*/ -void atresp_to_str(char *buf, unsigned len, const struct xbee_atresp_hdr *frame) +void atresp_to_str(char *buf, unsigned buflen, const struct xbee_atresp_hdr *frame, + unsigned len) { union { uint8_t u8; @@ -155,31 +156,35 @@ void atresp_to_str(char *buf, unsigned len, const struct xbee_atresp_hdr *frame) memcpy(atcmd_str, &frame->cmd, 2); atcmd_str[2] = '\0'; + /* see if it exists */ cmd_pgm = xbee_atcmd_lookup_name(atcmd_str); if (cmd_pgm == NULL) { - snprintf(buf, len, "<%s> (unknown cmd)", atcmd_str); + snprintf(buf, buflen, "<%s> (unknown cmd)", atcmd_str); return; } memcpy_P(&cmd, cmd_pgm, sizeof(cmd)); + len -= sizeof(*frame); /* dump frame */ result = (void *)frame->data; - len -= offsetof(struct xbee_atresp_hdr, data); + if (cmd.flags & XBEE_ATCMD_F_PARAM_U8 && len == sizeof(uint8_t)) - snprintf(buf, len, "<%s> is 0x%x (%d)", atcmd_str, + snprintf(buf, buflen, "<%s> is 0x%x (%d)", atcmd_str, result->u8, result->u8); else if (cmd.flags & XBEE_ATCMD_F_PARAM_U16 && len == sizeof(uint16_t)) - snprintf(buf, len, "<%s> is 0x%x (%d)", atcmd_str, + snprintf(buf, buflen, "<%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)) - snprintf(buf, len, "<%s> is 0x%"PRIx32" (%"PRIu32")", + snprintf(buf, buflen, "<%s> is 0x%"PRIx32" (%"PRIu32")", atcmd_str, ntohl(result->u32), ntohl(result->u32)); else if (cmd.flags & XBEE_ATCMD_F_PARAM_S16 && len == sizeof(int16_t)) - snprintf(buf, len, "<%s> is %d", + snprintf(buf, buflen, "<%s> is %d", atcmd_str, ntohs(result->s16)); else if (len == 0) - snprintf(buf, len, "<%s> no data", atcmd_str); + snprintf(buf, buflen, "<%s> no data", atcmd_str); + else + snprintf(buf, buflen, "invalid atresp"); } static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame, @@ -225,10 +230,10 @@ static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame, return -1; } - len -= offsetof(struct xbee_atresp_hdr, data); + atresp_to_str(buf, sizeof(buf), frame, len); - atresp_to_str(buf, sizeof(buf), frame); - NOTICE(E_USER_XBEE, "status ok, len=%d, %s", len, buf); + len -= sizeof(*frame); + NOTICE(E_USER_XBEE, "status ok, datalen=%d, %s", len, buf); if (len != 0) hexdump("atcmd answer", frame->data, len); @@ -252,7 +257,7 @@ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type, /* if ctx is !NULL, it is an answer to a query */ if (ctx != NULL) { xbee_unload_timeout(ctx); - if (ctx->atcmd_query) + if (ctx->atcmd_query[0]) NOTICE(E_USER_XBEE, "Received answer to query <%c%c>", ctx->atcmd_query[0], ctx->atcmd_query[1]); } @@ -323,8 +328,10 @@ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type, break; } - WARNING(E_USER_XBEE, "undecoded rx frame"); - hexdump("undecoded rx frame", frame, len); + if (ret != XBEE_USER_RETCODE_OK) { + WARNING(E_USER_XBEE, "undecoded rx frame"); + hexdump("undecoded rx frame", frame, len); + } if (ctx != NULL) { /* callback */ @@ -391,11 +398,18 @@ int xbeeapp_send_atcmd(char *atcmd_str, void *param, unsigned param_len, ctx.rx_cb = rx_cb; ctx.arg = arg; - msg.iovlen = 2; - msg.iov[0].buf = atcmd_str; - msg.iov[0].len = 2; - msg.iov[1].buf = param; - msg.iov[1].len = param_len; + if (param_len == 0) { + msg.iovlen = 1; + msg.iov[0].buf = atcmd_str; + msg.iov[0].len = 2; + } + else { + msg.iovlen = 2; + msg.iov[0].buf = atcmd_str; + msg.iov[0].len = 2; + msg.iov[1].buf = param; + msg.iov[1].len = param_len; + } prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO); if (prio > XBEE_PRIO) diff --git a/xbee_user.h b/xbee_user.h index e2bc926..bba7885 100644 --- a/xbee_user.h +++ b/xbee_user.h @@ -63,7 +63,8 @@ struct xbeeapp_pkt { /* Write in a human readable format the content of an atcmd response frame. It * assumes the frame is valid .*/ -void atresp_to_str(char *buf, unsigned len, const struct xbee_atresp_hdr *frame); +void atresp_to_str(char *buf, unsigned buflen, const struct xbee_atresp_hdr *frame, + unsigned len); /* callback registered to xbee module, called when a xbee frame is received */ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,