Goliath II
Controller Receiver
 All Classes Namespaces Files Functions Enumerations
bluetooth_controller.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <boost/asio.hpp>
5 #include <boost/asio/serial_port.hpp>
6 #include <boost/log/trivial.hpp>
7 
18 namespace goliath::btc {
19 
23  enum class Status : std::uint8_t {
24  BT_CONNECTED = 0,
25  BT_INVALID_INPUT = 1,
26  BT_BATTERY = 2,
27  BT_LOG_WARNING = 3,
28  BT_LOG_ERROR = 4,
29  BT_LOG_FATAL = 5
30  };
31 
35  enum class InputError : std::uint8_t {
36  IE_SUCCES,
37  IE_EMPTY,
38  IE_WRONG_FORMAT,
39  IE_WRONG_VALUE,
40  IE_READ_ERROR,
41  IE_CONNECTION_LOST
42  };
43 
44  struct Input {
45  public:
46  Input();
47 
48  Input(std::string type, std::string control, std::string value);
49 
50  Input(InputError error);
51 
52  std::string type;
53  std::string control;
54  std::string value;
55  InputError error;
56  };
57 
58  struct StatusMessage {
59  StatusMessage();
60 
61  StatusMessage(Status status, short value);
62 
63  void set(Status status, short value);
64 
65  Status status;
66  short value;
67  bool isSet = false;
68  };
69 
74  public:
79  BluetoothController(const std::string &devicePath, std::string &newDeviceAddress);
80 
85 
90  bool connect();
91 
96  void start();
97 
104  void start(const std::string &newDevicePath, std::string &newDeviceAddress);
105 
110  void reconnect();
111 
116  Input receive();
117 
124  void send(Status status, int value);
125 
132  void send(int severity, std::string message);
133 
138  void sendLast();
139 
144  void clear();
145 
151  bool connected();
152 
153  private:
154  const char *devicePath;
155  const int BUFFER_SIZE = 1024;
156  std::string deviceAddress;
157  boost::asio::io_service io;
158  boost::asio::serial_port serialPort = boost::asio::serial_port(io);
159  StatusMessage lastMessage = StatusMessage((Status) 0, 0);
160 
161  Input convertInput(char buffer[]);
162  };
163 }
Definition: bluetooth_controller.h:58
void start()
Start the controller.
Definition: bluetooth_controller.cpp:50
BluetoothController()
Constructor.
Definition: bluetooth_controller.cpp:224
void reconnect()
Reconnect to controller if connection was lost.
Definition: bluetooth_controller.cpp:63
Definition: bluetooth_controller.h:44
void sendLast()
Send last status message to controller.
Definition: bluetooth_controller.cpp:170
InputError
enum for input errors
Definition: bluetooth_controller.h:35
Status
enum for all status updates to controller
Definition: bluetooth_controller.h:23
bool connect()
Connect to controller.
Definition: bluetooth_controller.cpp:10
Definition: bluetooth_controller.h:73
bool connected()
Check if still connected to controller.
Definition: bluetooth_controller.cpp:79
Input receive()
Wait for input to be received.
Definition: bluetooth_controller.cpp:102
void clear()
Clear bluetooth serial buffer.
Definition: bluetooth_controller.cpp:215