Revision 1604
wireless: software retransmit done. serial functions moved to xbee.c
xbee_computer.c | ||
---|---|---|
13 | 13 |
|
14 | 14 |
#endif |
15 | 15 |
|
16 |
#ifdef USE_STDIO |
|
16 | 17 |
|
18 |
#include <stdio.h> |
|
19 |
|
|
20 |
/** |
|
21 |
* For use with fprintf() and related stdio functions |
|
22 |
**/ |
|
23 |
FILE *xbee_fd; |
|
24 |
|
|
25 |
#endif |
|
26 |
|
|
27 |
uint8_t xbee_initd=0; |
|
28 |
|
|
29 |
/** |
|
30 |
* Initializes communication over the XBee. |
|
31 |
* This must be called before any other xbee function |
|
32 |
* may be used. |
|
33 |
**/ |
|
34 |
int xbee_init() { |
|
35 |
|
|
36 |
if(xbee_initd) { |
|
37 |
return ERROR_INIT_ALREADY_INITD; |
|
38 |
} |
|
39 |
|
|
40 |
//Set baud rate |
|
41 |
// - 115200 (both wired and wireless) is UBRR=8, U2X=1 |
|
42 |
// - 9600 is U2X =1, UBRR = 107. |
|
43 |
#if (XBEE_BAUD == 115200) |
|
44 |
UBRR1H = 0x00; |
|
45 |
UBRR1L = 8; |
|
46 |
UCSR1A |= _BV(U2X1); |
|
47 |
#elif (XBEE_BAUD == 9600) |
|
48 |
UBRR1H = 0x00; |
|
49 |
UBRR1L = 103; |
|
50 |
UCSR1A |= _BV(U2X1); |
|
51 |
#else //Baud rate is defined in the header file, we should not get here |
|
52 |
return 0; |
|
53 |
#endif |
|
54 |
|
|
55 |
//Enable receiver and transmitter |
|
56 |
UCSR1B |= (1<<RXEN1)|(1<<TXEN1); |
|
57 |
|
|
58 |
// Set frame format: 8data, 1stop bit, asynchronous normal mode |
|
59 |
UCSR1C |= (1<<UCSZ10) | (1<<UCSZ11); |
|
60 |
|
|
61 |
// if we have enabled the stdio stuff, then we init it here |
|
62 |
#ifdef USE_STDIO |
|
63 |
/* Open the stdio stream corresponding to this port */ |
|
64 |
xbee_fd = fdevopen(xbee_putc, xbee_getc); |
|
65 |
#endif |
|
66 |
|
|
67 |
xbee_initd = 1; |
|
68 |
return 0; |
|
69 |
|
|
70 |
} |
|
71 |
|
|
72 |
|
|
73 |
/**@brief The port to use the XBee from on the computer. **/ |
|
74 |
#ifndef ROBOT |
|
75 |
#define XBEE_PORT_DEFAULT "/dev/ttyUSB1" |
|
76 |
#endif |
|
77 |
|
|
78 |
|
|
79 |
/**@brief Set the com port on a computer, undefined on the robot**/ |
|
80 |
void xbee_set_com_port(char* port); |
|
81 |
|
|
17 | 82 |
#define XBEE_GET_PACKET_TIMEOUT 1000 |
18 | 83 |
|
19 | 84 |
#ifndef ROBOT |
Also available in: Unified diff