Daniel Petti | cf2abd3 | 2013-12-12 03:02:34 +0000 | [diff] [blame] | 1 | #include <fcntl.h> |
| 2 | #include <termios.h> |
| 3 | #include <unistd.h> |
| 4 | |
| 5 | #include "bbb_cape/src/cape/cows.h" |
| 6 | #include "uart_receiver.h" |
| 7 | |
| 8 | // This is the code for receiving data from the cape via UART. |
| 9 | // NOTE: In order for this to work, you MUST HAVE "capemgr.enable_partno=BB_UART1" |
| 10 | // in your BBB's /media/BEAGLEBONE/uEnv.txt file! |
| 11 | |
| 12 | int UartReceiver::ReadUart(size_t packet_size) { |
| 13 | termios cape; |
| 14 | char byte_in[packet_size]; |
| 15 | int fd, bread; |
| 16 | |
| 17 | if ((fd = open("/dev/ttyO1", O_RDWR | O_NOCTTY)) < 0) { |
| 18 | LOG(FATAL, "Open() failed with error %d. |
| 19 | (Did you read my note in uart_receiver.cc?)\n", fd); |
| 20 | } |
| 21 | |
| 22 | if ((ret = tcgetattr(fd, &cape)) != 0) { |
| 23 | LOG(ERROR, "Tcgetattr() failed with error %d.\n", ret); |
| 24 | return -1; |
| 25 | } |
| 26 | } |