git.droids-corp.org
/
protos
/
xbee-avr.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
add i2c support
[protos/xbee-avr.git]
/
xbee_user.c
diff --git
a/xbee_user.c
b/xbee_user.c
index
a4cb84f
..
17a92af
100644
(file)
--- a/
xbee_user.c
+++ b/
xbee_user.c
@@
-56,6
+56,8
@@
int xbee_cmdline_input_enabled = 1;
/* parameters */
int xbee_raw = 0;
/* parameters */
int xbee_raw = 0;
+static struct callout xbee_rx_poll_timer;
+
static void __hexdump(const void *buf, unsigned int len)
{
unsigned int i, out, ofs;
static void __hexdump(const void *buf, unsigned int len)
{
unsigned int i, out, ofs;
@@
-137,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 .*/
/* 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;
{
union {
uint8_t u8;
@@
-153,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';
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) {
/* 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,
buf
len, "<%s> (unknown cmd)", atcmd_str);
return;
}
memcpy_P(&cmd, cmd_pgm, sizeof(cmd));
return;
}
memcpy_P(&cmd, cmd_pgm, sizeof(cmd));
+ len -= sizeof(*frame);
/* dump frame */
result = (void *)frame->data;
/* 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))
if (cmd.flags & XBEE_ATCMD_F_PARAM_U8 && len == sizeof(uint8_t))
- snprintf(buf, len, "<%s> is 0x%x (%d)", atcmd_str,
+ snprintf(buf,
buf
len, "<%s> is 0x%x (%d)", atcmd_str,
result->u8, result->u8);
else if (cmd.flags & XBEE_ATCMD_F_PARAM_U16 && len == sizeof(uint16_t))
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,
buf
len, "<%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))
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,
buf
len, "<%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))
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,
buf
len, "<%s> is %d",
atcmd_str, ntohs(result->s16));
else if (len == 0)
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,
}
static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame,
@@
-223,10
+230,10
@@
static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame,
return -1;
}
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,
data
len=%d, %s", len, buf);
if (len != 0)
hexdump("atcmd answer", frame->data, len);
if (len != 0)
hexdump("atcmd answer", frame->data, len);
@@
-235,7
+242,9
@@
static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame,
}
}
-/* main rx entry point for application */
+/* Main xbee rx entry point for application. It decodes the xbee frame type and
+ * dispatch to the application layer. Then "len" argument does not include the
+ * xbee_hdr structure (delimiter, len, type, id) and checksum. */
int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
void *frame, unsigned len, void *opaque)
{
int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
void *frame, unsigned len, void *opaque)
{
@@
-244,11
+253,12
@@
int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
NOTICE(E_USER_XBEE, "type=0x%x, channel=%d, ctx=%p",
type, channel, ctx);
NOTICE(E_USER_XBEE, "type=0x%x, channel=%d, ctx=%p",
type, channel, ctx);
+ __hexdump(frame, len);
/* if ctx is !NULL, it is an answer to a query */
if (ctx != NULL) {
xbee_unload_timeout(ctx);
/* 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]);
}
NOTICE(E_USER_XBEE, "Received answer to query <%c%c>",
ctx->atcmd_query[0], ctx->atcmd_query[1]);
}
@@
-319,8
+329,9
@@
int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
break;
}
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");
+ }
if (ctx != NULL) {
/* callback */
if (ctx != NULL) {
/* callback */
@@
-387,11
+398,18
@@
int xbeeapp_send_atcmd(char *atcmd_str, void *param, unsigned param_len,
ctx.rx_cb = rx_cb;
ctx.arg = arg;
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)
prio = callout_mgr_set_prio(&xbeeboard.intr_cm, XBEE_PRIO);
if (prio > XBEE_PRIO)
@@
-544,8
+562,8
@@
void xbee_stdin_disable(void)
void xbeeapp_init(void)
{
void xbeeapp_init(void)
{
- callout_init(&xbee
board.xbee
_rx_poll_timer, xbee_rx_poll_timer_cb,
+ callout_init(&xbee_rx_poll_timer, xbee_rx_poll_timer_cb,
NULL, XBEE_PRIO);
NULL, XBEE_PRIO);
- callout_schedule(&xbeeboard.intr_cm,
-
&xbeeboard.xbee_rx_poll_timer,
XBEE_POLL_TIMER_MS);
+ callout_schedule(&xbeeboard.intr_cm,
&xbee_rx_poll_timer,
+ XBEE_POLL_TIMER_MS);
}
}