blob: 9d5a510079da77d9e095f25db5fc06c856fb3715 [file] [log] [blame]
Daniel Petti059be422013-12-14 19:47:42 -08001#ifndef FCR971_INPUT_UART_RECEIVER_H_
2#define FRC971_INPUT_UART_RECEIVER_H_
3
Brian Silverman1662a0e2013-12-19 17:50:01 -08004#include <stdint.h>
Daniel Petti059be422013-12-14 19:47:42 -08005
6#define DATA_STRUCT_NAME DataStruct
Brian Silverman1662a0e2013-12-19 17:50:01 -08007#include "cape/data_struct.h"
Daniel Petti059be422013-12-14 19:47:42 -08008#undef DATA_STRUCT_NAME
9
10namespace bbb {
Daniel Petti059be422013-12-14 19:47:42 -080011
Brian Silvermanf6b68842013-12-20 12:34:58 -080012class UartReader {
Brian Silverman1662a0e2013-12-19 17:50:01 -080013 public:
Brian Silvermanf6b68842013-12-20 12:34:58 -080014 UartReader(int32_t baud_rate);
15 ~UartReader();
Brian Silverman1662a0e2013-12-19 17:50:01 -080016
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 Petti059be422013-12-14 19:47:42 -080035
36#endif