move xbee rx in rc proto
[protos/xbee-avr.git] / rc_proto.h
1 #ifndef RC_PROTO_H
2 #define RC_PROTO_H
3
4 /* generic header */
5 struct rc_proto_hdr {
6         uint8_t type;
7 } __attribute__((packed));
8
9 /* send a hello message, no answer is expected from the peer */
10 #define RC_PROTO_HELLO 0
11 struct rc_proto_hello {
12         uint8_t type;
13         uint8_t datalen; /* len of data excluding header */
14         uint8_t data[];
15 } __attribute__((packed));
16
17 /* send an echo request, expect an echo reply from the peer */
18 #define RC_PROTO_ECHO_REQ 1
19 struct rc_proto_echo_req {
20         uint8_t type;
21         uint8_t datalen; /* len of data excluding header */
22         uint8_t data[];
23 } __attribute__((packed));
24
25 /* reply to an echo request */
26 #define RC_PROTO_ECHO_ANS 2
27 struct rc_proto_echo_ans {
28         uint8_t type;
29         uint8_t datalen; /* len of data excluding header */
30         uint8_t data[];
31 } __attribute__((packed));
32
33 /* send a power level probe to the peer */
34 #define RC_PROTO_POWER_PROBE 3
35 struct rc_proto_power_probe {
36         uint8_t type;
37         uint8_t power_level;
38 } __attribute__((packed));
39
40 /* send a servo command */
41 #define RC_PROTO_SERVO 4
42 struct rc_proto_servo {
43         uint8_t type;
44         uint8_t mask;
45         uint8_t seq_and_pow; /* bitfield: pow are the 3 lsb, seq the 5 msb */
46 };
47
48 /* acknowledge a servo command */
49 #define RC_PROTO_ACK 5
50 struct rc_proto_ack {
51         uint8_t type;
52         uint8_t seq;
53 } __attribute__((packed));
54
55
56 /* send a Hello message to a peer */
57 int8_t rc_proto_send_hello(uint64_t addr, void *data, uint8_t data_len);
58
59 /* reception of a xbee message */
60 int rc_proto_rx(struct xbee_recv_hdr *recvframe, unsigned len);
61
62 #endif