From: Olivier Matz Date: Mon, 10 Mar 2014 18:56:17 +0000 (+0100) Subject: move xbee rx in rc proto X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=0373c0e13f4a81426ee5084c0c1ee148bc6b935a;p=protos%2Fxbee-avr.git move xbee rx in rc proto --- diff --git a/rc_proto.c b/rc_proto.c index 442eb90..4ced123 100644 --- a/rc_proto.c +++ b/rc_proto.c @@ -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; +} diff --git a/rc_proto.h b/rc_proto.h index a12de34..868f921 100644 --- a/rc_proto.h +++ b/rc_proto.h @@ -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 diff --git a/xbee_user.c b/xbee_user.c index fca39b6..a4cb84f 100644 --- a/xbee_user.c +++ b/xbee_user.c @@ -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;