]> git.droids-corp.org - protos/xbee-avr.git/commitdiff
move xbee rx in rc proto
authorOlivier Matz <zer0@droids-corp.org>
Mon, 10 Mar 2014 18:56:17 +0000 (19:56 +0100)
committerOlivier Matz <zer0@droids-corp.org>
Mon, 10 Mar 2014 18:56:17 +0000 (19:56 +0100)
rc_proto.c
rc_proto.h
xbee_user.c

index 442eb909347be1c7666cfafb22a14ef6afde03e1..4ced1232883f73e565f5aea04b8b25e8f2eb6799 100644 (file)
@@ -243,3 +243,61 @@ int8_t buf2servo(uint8_t *buf, uint8_t len)
        return 0;
 }
 #endif
+
+int rc_proto_rx(struct xbee_recv_hdr *recvframe, unsigned len)
+{
+       unsigned int datalen;
+       struct rc_proto_hdr *rch = (struct rc_proto_hdr *) &recvframe->data;
+
+       if (len <  sizeof(*recvframe))
+               return -1;
+
+       datalen = len - sizeof(*recvframe);
+       if (datalen < sizeof(struct rc_proto_hdr))
+               return -1;
+
+       switch (rch->type) {
+#if 0
+               case RC_PROTO_TYPE_CHANNEL: {
+                       struct rc_proto_channel *rcc =
+                               (struct rc_proto_channel *) recvframe->data;
+                       int16_t val;
+                       if (datalen != sizeof(struct rc_proto_channel))
+                               return -1;
+                       val = ntohs(rcc->axis[0]);
+                       val >>= 6;
+                       val += 512;
+                       spi_servo_set(0, val);
+                       break;
+               }
+#endif
+               case RC_PROTO_POWER_PROBE: {
+                       struct rc_proto_power_probe *rcpb =
+                               (struct rc_proto_power_probe *) recvframe->data;
+
+                       if (datalen != sizeof(*rcpb))
+                               return -1;
+
+                       if (rcpb->power_level >= MAX_POWER_LEVEL)
+                               return -1;
+
+                       //rc_proto_rx_range(rcpb->power_level);
+
+                       break;
+               }
+
+               case RC_PROTO_HELLO: {
+                       struct rc_proto_hello *rch =
+                               (struct rc_proto_hello *) recvframe->data;
+
+                       NOTICE(E_USER_XBEE, "recv hello len=%d",
+                               rch->datalen);
+                       /* XXX stats */
+                       break;
+               }
+               default:
+                       return -1;
+       }
+
+       return 0;
+}
index a12de344a53d3fa46060469e6666d9c4721453ab..868f921aeb991f3b1627c525abe3fa8e803ee96c 100644 (file)
@@ -56,6 +56,7 @@ struct rc_proto_ack {
 /* send a Hello message to a peer */
 int8_t rc_proto_send_hello(uint64_t addr, void *data, uint8_t data_len);
 
-void rc_proto_rx_range(int power_level);
+/* reception of a xbee message */
+int rc_proto_rx(struct xbee_recv_hdr *recvframe, unsigned len);
 
 #endif
index fca39b65cd96c406b3a4c71daa40bd46a946f848..a4cb84f54499d859567f758b681c492f58f39892 100644 (file)
@@ -235,64 +235,6 @@ static int parse_atcmd(struct xbee_ctx *ctx, struct xbee_atresp_hdr *frame,
 }
 
 
-int xbee_recv_data(struct xbee_recv_hdr *recvframe, unsigned len)
-{
-       unsigned int datalen;
-       struct rc_proto_hdr *rch = (struct rc_proto_hdr *) &recvframe->data;
-
-       if (len <  sizeof(*recvframe))
-               return -1;
-
-       datalen = len - sizeof(*recvframe);
-       if (datalen < sizeof(struct rc_proto_hdr))
-               return -1;
-
-       switch (rch->type) {
-#if 0
-               case RC_PROTO_TYPE_CHANNEL: {
-                       struct rc_proto_channel *rcc =
-                               (struct rc_proto_channel *) recvframe->data;
-                       int16_t val;
-                       if (datalen != sizeof(struct rc_proto_channel))
-                               return -1;
-                       val = ntohs(rcc->axis[0]);
-                       val >>= 6;
-                       val += 512;
-                       spi_servo_set(0, val);
-                       break;
-               }
-#endif
-               case RC_PROTO_POWER_PROBE: {
-                       struct rc_proto_power_probe *rcpb =
-                               (struct rc_proto_power_probe *) recvframe->data;
-
-                       if (datalen != sizeof(*rcpb))
-                               return -1;
-
-                       if (rcpb->power_level >= MAX_POWER_LEVEL)
-                               return -1;
-
-                       //rc_proto_rx_range(rcpb->power_level);
-
-                       break;
-               }
-
-               case RC_PROTO_HELLO: {
-                       struct rc_proto_hello *rch =
-                               (struct rc_proto_hello *) recvframe->data;
-
-                       NOTICE(E_USER_XBEE, "recv hello len=%d",
-                               rch->datalen);
-                       /* XXX stats */
-                       break;
-               }
-               default:
-                       return -1;
-       }
-
-       return 0;
-}
-
 /* main rx entry point for application */
 int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
             void *frame, unsigned len, void *opaque)
@@ -358,7 +300,7 @@ int8_t xbeeapp_rx(struct xbee_dev *dev, int channel, int type,
                }
 
                case XBEE_TYPE_RECV: {
-                       if (xbee_recv_data(frame, len) < 0)
+                       if (rc_proto_rx(frame, len) < 0)
                                ret = XBEE_USER_RETCODE_BAD_FRAME;
 
                        break;