blob: 53f9288a95334c1ef23824007bd94634479ce7ad (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
#ifndef XBEE_H
#define XBEE_H
void xbee_send(uint16_t type, int len, const uint8_t* buf) {
// Start and length.
usart_send(0x7e);
usart_send(((len + 16) >> 8) & 0xff);
usart_send((len + 16) & 0xff);
// Frame type and ID.
usart_send(0x10);
usart_send(0x01);
// Destination address.
usart_send(0x00);
usart_send(0x13);
usart_send(0xa2);
usart_send(0x00);
usart_send(0x40);
usart_send(0x6f);
usart_send(0x19);
usart_send(0xf1);
usart_send(0xff);
usart_send(0xfe);
usart_send(0x00);
usart_send(0x00);
uint8_t chsum = 0x83;
usart_send(type & 0xff);
chsum -= type & 0xff;
usart_send(type >> 8);
chsum -= type >> 8;
// Payload
for(int i = 0; i < len; i++) {
usart_send(buf[i]);
chsum -= buf[i];
}
usart_send(chsum);
}
#endif
|