rework xbee_user: remove the foreground param
[protos/xbee-avr.git] / rc_proto.c
index fe5c928..442eb90 100644 (file)
@@ -25,6 +25,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <string.h>
+
 #include <aversive.h>
 #include <aversive/queue.h>
 
@@ -32,8 +34,6 @@
 
 #include <uart.h>
 
-#include <scheduler.h>
-#include <clock_time.h>
 #include <parse.h>
 #include <rdline.h>
 #include <timer.h>
@@ -41,6 +41,7 @@
 
 #include "callout.h"
 #include "rc_proto.h"
+#include "xbee_user.h"
 #include "main.h"
 
 /* */
@@ -51,12 +52,17 @@ struct rc_proto_power_levels {
 static struct rc_proto_power_levels power_levels[MAX_POWER_LEVEL];
 
 /* update power level when we receive the answer from DB */
-static int update_power_level(void *frame, unsigned len, void *arg)
+static int8_t update_power_level(int8_t retcode, void *frame, unsigned len,
+       void *arg)
 {
        struct xbee_atresp_hdr *atresp = (struct xbee_atresp_hdr *)frame;
        int level = (intptr_t)arg;
        uint8_t db;
 
+       /* nothing more to do, error is already logged by xbee_user */
+       if (retcode < 0)
+               return retcode;
+
        /* XXX check if this test is correct */
        if (len < sizeof(struct xbee_atresp_hdr) + sizeof(uint8_t)) {
                /* XXX stats */
@@ -73,9 +79,28 @@ static int update_power_level(void *frame, unsigned len, void *arg)
 void rc_proto_rx_power_probe(int power_level)
 {
        (void)power_level;
-       xbeeapp_send_atcmd("DB", NULL, 0, 0, update_power_level, NULL);
+       xbeeapp_send_atcmd("DB", NULL, 0, update_power_level, NULL);
 }
 
+/* send a hello message */
+int8_t rc_proto_send_hello(uint64_t addr, void *data, uint8_t data_len)
+{
+       struct rc_proto_echo_req hdr;
+       struct xbee_msg msg;
+
+       hdr.type = RC_PROTO_HELLO;
+       hdr.datalen = data_len;
+
+       msg.iovlen = 2;
+       msg.iov[0].buf = &hdr;
+       msg.iov[0].len = sizeof(hdr);
+       msg.iov[1].buf = data;
+       msg.iov[1].len = data_len;
+
+       return xbeeapp_send_msg(addr, &msg, NULL, NULL);
+}
+
+
 #if 0
 #define N_SERVO 6
 #define SERVO_NBITS 10