-
Notifications
You must be signed in to change notification settings - Fork 1
/
SerialSensor.hpp
59 lines (46 loc) · 1.44 KB
/
SerialSensor.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#ifndef SENSOR_HPP
#define SENSOR_HPP
#include <string.h>
#include <vector>
#include <iostream>
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include "ISensor.hpp"
#include "ISensorListener.hpp"
using namespace std;
class SerialSensor : public ISensor{
private:
unsigned int sensorID;
string name;
string lineEnd;
string delimeter;
vector<FieldDescriptor> fields;
string startChars;
string endChars;
vector<ISensorListener *> listeners;
boost::mutex runMutex;
boost::mutex listenersMutex;
bool running;
// Socket Variables
string port_string;
int baud;
boost::asio::serial_port* serial;
boost::asio::io_service ios;
boost::asio::streambuf buf;
boost::thread* readThread;
void setRunning(bool);
void parseLine(const boost::system::error_code& ec, size_t bytes_transferred);
public:
SerialSensor(const unsigned int _sensorID, const string _port, const int _baud, const string _name, const string _lineEnd, const string _delimeter, const vector<FieldDescriptor> _fields, const string _startChars, const string _endChars);
~SerialSensor();
virtual bool Connect();
virtual bool Disconnect();
virtual void addListener(ISensorListener *l);
virtual void clearListeners();
virtual bool isRunning();
void operator() ();
virtual unsigned int getID();
virtual string getName();
virtual vector<FieldDescriptor> getFieldDescriptors();
};
#endif