7 } __attribute__((packed));
10 /* send a hello message, no answer is expected from the peer */
11 #define RC_PROTO_HELLO 0x00
12 struct rc_proto_hello {
14 uint8_t datalen; /* len of data excluding header */
16 } __attribute__((packed));
18 /* send an echo request, expect an echo reply from the peer */
19 #define RC_PROTO_ECHO_REQ 0x01
20 struct rc_proto_echo_req {
23 uint16_t timestamp; /* copied as-is in answer */
24 uint8_t datalen; /* len of data excluding header */
26 } __attribute__((packed));
28 /* reply to an echo request */
29 #define RC_PROTO_ECHO_ANS 0x02
30 struct rc_proto_echo_ans {
33 uint8_t datalen; /* len of data excluding header */
35 } __attribute__((packed));
37 /* send a power level probe to the peer: no answer is expected, but the peer
38 * will know that a packet with this power-level is received. It can also ask
39 * the RSSI of this packet. */
40 #define RC_PROTO_POWER_PROBE 0x03
41 struct rc_proto_power_probe {
44 } __attribute__((packed));
46 /* acknowledge a servo command */
47 #define RC_PROTO_ACK 0x04
51 } __attribute__((packed));
54 * If type < 0x3f, it's a servo command. The size of the message is critical
55 * because it's send very often. The "type" field contains the bitfield of
56 * servos present in the body of the message. A sequence number (5bits) and the
57 * power level (3 bits) are also sent. The servos are listed as 10bits fields,
60 * Example: we send servo 0 (=0x123) and servo 3 (=0x234). Power = 2.
61 * command type (RC_PROTO_SERVO)
62 * power_level = 0 (3 bits, LSB) \
63 * bypass = 0 (1 bit) > one byte
64 * seq = 1 (4 bits, MSB) /
72 * -> 0x05 0x10 0x48 0xe3 0x4c 0x85 0x23 0x8d 0x32 0x10
73 * type psb |ser0 ser1 ser2 ser3 |ser4 ser5
75 #define RC_PROTO_SERVO 0x05
76 #define RC_PROTO_SERVO_LEN 10 /* len of frame */
77 struct rc_proto_servo {
83 #define RC_PROTO_STATS 0x06
84 struct rc_proto_stats {
86 uint8_t stats[]; /* format is struct rc_proto_stats_data */
87 } __attribute__((packed));
89 /* rc_proto timers configuration */
90 struct rc_proto_timers {
91 uint16_t send_servo_min_ms;
92 uint16_t send_servo_max_ms;
93 uint16_t send_power_probe_ms;
94 uint16_t autobypass_ms;
96 extern struct rc_proto_timers rc_proto_timers;
98 /* send a Hello message to a peer */
99 int8_t rc_proto_send_hello(uint64_t addr, void *data, uint8_t data_len,
102 int8_t rc_proto_send_echo_req(uint64_t addr, void *data, uint8_t data_len,
105 /* reception of a xbee message */
106 int rc_proto_rx(struct xbee_recv_hdr *recvframe, unsigned len);
108 /* dump statistics related to rc_proto */
109 void rc_proto_dump_stats(void);
111 /* reset statistics related to rc_proto */
112 void rc_proto_reset_stats(void);
114 /* set the peer xbee address */
115 void rc_proto_set_dstaddr(uint64_t addr);
117 /* get the peer xbee address */
118 uint64_t rc_proto_get_dstaddr(void);
120 void rc_proto_dump_servos(void);
123 #define RC_PROTO_FLAGS_TX_OFF 0x00
124 #define RC_PROTO_FLAGS_TX_BYPASS 0x01
125 #define RC_PROTO_FLAGS_TX_COPY_SPI 0x02
126 #define RC_PROTO_FLAGS_TX_RESERVED 0x03
127 #define RC_PROTO_FLAGS_TX_MASK 0x03
129 /* if set, copy received servo values to SPI */
130 #define RC_PROTO_FLAGS_RX_COPY_SPI 0x04
132 /* if set, switch to bypass when no servo is received during some time */
133 #define RC_PROTO_FLAGS_RX_AUTOBYPASS 0x08
135 /* if set, send stats periodically to the peer (1 sec) */
136 #define RC_PROTO_FLAGS_TX_STATS 0x10
138 /* if set, send power probe periodically to the peer (500 ms) */
139 #define RC_PROTO_FLAGS_TX_POW_PROBE 0x20
141 void rc_proto_set_mode(uint8_t flags);
143 uint8_t rc_proto_get_mode(void);
145 /* initialize rc_proto module */
146 void rc_proto_init(void);