beep when GPS ready
[protos/xbee-avr.git] / xbee_user.h
index ced5363..bba7885 100644 (file)
 #define _XBEE_USER_H_
 
 #include <callout.h>
+#include <xbee_rxtx.h>
+
+#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;
 };
@@ -43,17 +51,33 @@ struct xbee_ctx {
 //extern cmdline_parse_ctx_t main_ctx;
 extern struct xbee_dev *xbee_dev;
 extern int xbee_raw;
-extern int xbee_hexdump;
-extern int xbee_debug;
 
+/* we use a specific structure to send packets. It allows to prepend some
+ * data in the frame without doing a copy. */
+struct xbeeapp_pkt {
+       char *buf;
+       unsigned len;
+       unsigned headroom;
+       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 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,
-                 void *frame, unsigned len, void *opaque);
-int xbeeapp_send_atcmd(const char *atcmd_str,
-                      void *param, unsigned param_len, int foreground,
-                      int (*func)(void *frame, unsigned len, void *arg),
-                      void *arg);
-int xbeeapp_send_msg(uint64_t addr, void *data,
-                    unsigned data_len, int foreground);
+       void *frame, unsigned len, void *opaque);
+
+/* 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, 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,
+       xbee_user_rx_cb_t *rx_cb, void *arg);
 
 void xbee_stdin_enable(void);
 void xbee_stdin_disable(void);
@@ -63,4 +87,6 @@ void xbee_unload_timeout(struct xbee_ctx *ctx);
 
 void xbee_mainloop(void);
 
+void xbeeapp_init(void);
+
 #endif /* _XBEE_USER_H_ */