cleaned up issues with Daniel's code
There were a lot of style things and a misunderstanding of the protocol
between the cape and the BBB.
diff --git a/bbb_cape/src/bbb/uart_receiver.h b/bbb_cape/src/bbb/uart_receiver.h
index 36bb170..73ba781 100644
--- a/bbb_cape/src/bbb/uart_receiver.h
+++ b/bbb_cape/src/bbb/uart_receiver.h
@@ -1,30 +1,36 @@
#ifndef FCR971_INPUT_UART_RECEIVER_H_
#define FRC971_INPUT_UART_RECEIVER_H_
-#include <cstdint>
+#include <stdint.h>
#define DATA_STRUCT_NAME DataStruct
-#include <bbb_cape/src/cape/data_struct.h>
+#include "cape/data_struct.h"
#undef DATA_STRUCT_NAME
namespace bbb {
-
- class UartReceiver {
- uint32_t baud_rate_;
- size_t packet_size_, stuffed_size_;
- int fd_;
- uint32_t buf_used_;
- char *buf_;
-
- public:
- UartReceiver(uint32_t baud_rate);
- ~UartReceiver();
- // Opens file descriptor, etc.
- int SetUp();
- int GetPacket(DataStruct *packet);
-
- };
-} //bbb
+class UartReceiver {
+ public:
+ UartReceiver(int32_t baud_rate);
+ ~UartReceiver();
+
+ // Returns true if it finds one or false if it gets an I/O error first.
+ // packet must be aligned to 4 bytes.
+ bool GetPacket(DataStruct *packet);
+
+ private:
+ // Reads bytes until there are 4 zeros and then fills up buf_.
+ // Returns true if it finds one or false if it gets an I/O error first or the
+ // packet is invalid in some way.
+ bool FindPacket();
+
+ typedef char __attribute__((aligned(8))) AlignedChar;
+
+ const int32_t baud_rate_;
+ AlignedChar *const buf_;
+ const int fd_;
+};
+
+} // namespace bbb
#endif