Daniel Petti | 059be42 | 2013-12-14 19:47:42 -0800 | [diff] [blame] | 1 | #ifndef FCR971_INPUT_UART_RECEIVER_H_ |
| 2 | #define FRC971_INPUT_UART_RECEIVER_H_ |
| 3 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame^] | 4 | #include <stdint.h> |
Daniel Petti | 059be42 | 2013-12-14 19:47:42 -0800 | [diff] [blame] | 5 | |
| 6 | #define DATA_STRUCT_NAME DataStruct |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame^] | 7 | #include "cape/data_struct.h" |
Daniel Petti | 059be42 | 2013-12-14 19:47:42 -0800 | [diff] [blame] | 8 | #undef DATA_STRUCT_NAME |
| 9 | |
| 10 | namespace bbb { |
Daniel Petti | 059be42 | 2013-12-14 19:47:42 -0800 | [diff] [blame] | 11 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame^] | 12 | class UartReceiver { |
| 13 | public: |
| 14 | UartReceiver(int32_t baud_rate); |
| 15 | ~UartReceiver(); |
| 16 | |
| 17 | // Returns true if it finds one or false if it gets an I/O error first. |
| 18 | // packet must be aligned to 4 bytes. |
| 19 | bool GetPacket(DataStruct *packet); |
| 20 | |
| 21 | private: |
| 22 | // Reads bytes until there are 4 zeros and then fills up buf_. |
| 23 | // Returns true if it finds one or false if it gets an I/O error first or the |
| 24 | // packet is invalid in some way. |
| 25 | bool FindPacket(); |
| 26 | |
| 27 | typedef char __attribute__((aligned(8))) AlignedChar; |
| 28 | |
| 29 | const int32_t baud_rate_; |
| 30 | AlignedChar *const buf_; |
| 31 | const int fd_; |
| 32 | }; |
| 33 | |
| 34 | } // namespace bbb |
Daniel Petti | 059be42 | 2013-12-14 19:47:42 -0800 | [diff] [blame] | 35 | |
| 36 | #endif |