Witmotion IMU Library  1.3.1~dev_4684448
Open source UART communication library for sensor devices manufactured by WitMotion Shenzhen Co.,Ltd
serial.h
1 #ifndef WITMOTION_SERIAL_H
2 #define WITMOTION_SERIAL_H
3 
4 #include "witmotion/types.h"
5 #include "witmotion/util.h"
6 
7 #include <QtCore>
8 #include <QSerialPort>
9 
10 #include <list>
11 
12 namespace witmotion
13 {
14 
16 {
17  Q_OBJECT
18 private:
20  QSerialPort* witmotion_port;
21  QSerialPort::BaudRate port_rate;
22  qint64 last_avail;
23  quint16 avail_rep_count;
24  uint8_t raw_data[128];
25  bool validate;
26  bool user_defined_return_interval;
27  uint32_t return_interval;
28  bool user_defined_timeout;
29  uint32_t timeout_ms;
30  uint32_t timeout_counter;
31 protected:
32  QTextStream ttyout;
33  QTimer* poll_timer;
34  QMetaObject::Connection timer_connection;
35  QMetaObject::Connection config_connection;
36  enum read_state_t
37  {
38  rsUnknown,
39  rsClear,
40  rsRead
41  }read_state;
44  witmotion_packet_id read_cell;
45 
46  volatile bool configuring;
47  std::list<witmotion_config_packet> configuration;
48  virtual void ReadData();
49  virtual void Configure();
50  virtual void SendConfig(const witmotion_config_packet& packet);
51 public:
52  void SetBaudRate(const QSerialPort::BaudRate& rate);
53  QBaseSerialWitmotionSensorReader(const QString device, const QSerialPort::BaudRate rate);
54  virtual ~QBaseSerialWitmotionSensorReader();
55  virtual void RunPoll();
56  virtual void Suspend();
57  void ValidatePackets(const bool value);
58  void SetSensorPollInterval(const uint32_t ms);
59  void SetSensorTimeout(const uint32_t ms);
60 };
61 
63 {
64  Q_OBJECT
65 private:
67 protected:
68  QString port_name;
69  QSerialPort::BaudRate port_rate;
71  QTextStream ttyout;
72 public:
73  virtual const std::set<witmotion_packet_id>* RegisteredPacketTypes() = 0;
74  QAbstractWitmotionSensorController(const QString tty_name, const QSerialPort::BaudRate rate);
75  virtual void Start() = 0;
76  virtual ~QAbstractWitmotionSensorController();
77  virtual void Calibrate() = 0;
78  virtual void SetBaudRate(const QSerialPort::BaudRate& rate) = 0;
79  void SetValidation(const bool validate);
80 public slots:
81  virtual void Packet(const witmotion_datapacket& packet);
82  virtual void Error(const QString& description);
83 signals:
84  void RunReader();
85  void ErrorOccurred(const QString& description);
86  void Acquired(const witmotion_datapacket& packet);
87  void SendConfig(const witmotion_config_packet& packet);
88 };
89 
90 }
91 #endif