/* 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;
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,
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);
/* 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]);
}
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 */
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)