SeaTalk: message 54 added.
[marnav.git] / src / marnav / io / seatalk_reader.hpp
blob4dc9189238313beb261be37a3baf333dc1f47fcf
1 #ifndef __IO__SEATALK_READER__HPP__
2 #define __IO__SEATALK_READER__HPP__
4 #include <marnav/io/device.hpp>
5 #include <marnav/seatalk/message.hpp>
7 namespace marnav
9 namespace io
12 /// This class reads SeaTalk messages from a device. Normally this would
13 /// be a serial character device (e.g. /dev/ttyS0 or /dev/ttyUSB0).
14 ///
15 /// In order to use this SeaTalk reader, it must be subclassed.
16 ///
17 /// @example read_seatalk.cpp
18 class seatalk_reader
20 public:
21 seatalk_reader(std::unique_ptr<device> && dev);
22 virtual ~seatalk_reader();
24 void close();
25 bool read();
26 uint32_t get_collisions() const { return ctx.collisions; }
28 protected:
29 virtual void process_message(const seatalk::raw &) = 0;
31 private:
32 enum class State { READ, ESCAPE, PARITY };
34 struct context {
35 State state;
36 uint8_t index;
37 uint8_t remaining;
38 uint8_t data[seatalk::MAX_MESSAGE_SIZE];
40 uint8_t raw;
41 uint32_t collisions;
44 void emit_message();
46 uint8_t parity(uint8_t a) const;
47 void write_cmd(uint8_t c);
48 void write_data(uint8_t c);
49 void process_seatalk();
50 bool read_data();
52 context ctx;
53 std::unique_ptr<device> dev; ///< Device to read data from.
58 #endif