X-Git-Url: http://git.droids-corp.org/?p=protos%2Fxbee-avr.git;a=blobdiff_plain;f=xbee_user.h;h=e2bc926ae400d7da742796ea11652f0192804b82;hp=cfb2ea8d58605072254e958e40fd5afae50f0214;hb=e39c5d534eaa4d29fea56d7851343612fdab9a23;hpb=852fd37145aaaee0ce2117f5c8173f5b86020fd0 diff --git a/xbee_user.h b/xbee_user.h index cfb2ea8..e2bc926 100644 --- a/xbee_user.h +++ b/xbee_user.h @@ -31,12 +31,19 @@ #include #include +#define XBEE_USER_RETCODE_OK 0 +#define XBEE_USER_RETCODE_BAD_FRAME 1 +#define XBEE_USER_RETCODE_TIMEOUT 2 + +/* called when we receive an answer to a query */ +typedef int8_t (xbee_user_rx_cb_t)(int8_t code, void *frame, + unsigned len, void *arg); + /* used for timeouts and xbee rx callback */ struct xbee_ctx { - int foreground; int channel; - char atcmd_query[2]; - int (*func)(void *frame, unsigned len, void *arg); + char atcmd_query[2]; /* 00 is it's data */ + xbee_user_rx_cb_t *rx_cb; void *arg; struct callout timeout; }; @@ -54,6 +61,10 @@ struct xbeeapp_pkt { unsigned tailroom; }; +/* 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); + /* callback registered to xbee module, called when a xbee frame is received */ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type, void *frame, unsigned len, void *opaque); @@ -61,12 +72,11 @@ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type, /* Send an AT command to the xbee device. The callback function for the answer * is given as a parameter */ int xbeeapp_send_atcmd(char *atcmd_str, void *param, - unsigned param_len, int foreground, - int (*func)(void *frame, unsigned len, void *arg), - void *arg); + unsigned param_len, xbee_user_rx_cb_t *rx_cb, void *arg); /* send a message to a peer */ -int xbeeapp_send_msg(uint64_t addr, struct xbee_msg *msg, int foreground); +int xbeeapp_send_msg(uint64_t addr, struct xbee_msg *msg, + xbee_user_rx_cb_t *rx_cb, void *arg); void xbee_stdin_enable(void); void xbee_stdin_disable(void);