blob: 73ba781c22d5f4ba34e9c9189d3afc95e3820c88 [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 Silverman1662a0e2013-12-19 17:50:01 -080012class 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 Petti059be422013-12-14 19:47:42 -080035
36#endif