Driver_Obs_Serial.hpp 2.58 KB
Newer Older
Achim Morschhauser's avatar
Achim Morschhauser committed
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * Driver_Obs_Serial.h
 *
 *  Created on: May 12, 2016
 *      Author: mors
 */

#ifndef INCLUDE_DRIVER_OBS_SERIAL_HPP_
#define INCLUDE_DRIVER_OBS_SERIAL_HPP_

//#include <driver_serial_emulate.hpp>
#include <driver_serial.hpp>
#include <driver_obs.hpp>
#include "Obs_Calibration.hpp"

class Driver_Obs_Serial: protected driver_obs {

//
// Private class variables
//

private:

/** The serial driver to use */
driver_serial serial;

//
// Constructors
//

public:

/** Constructor */
Driver_Obs_Serial(std::string port, buffer_obs* buffer);

/** Constructor with calibration */
Driver_Obs_Serial(std::string port, buffer_obs* buffer,
		Obs_Calibration* cal);

/**
 * Constructors of derived classes must call [set_term(term,termlen)]
 * and [set_baud(const char* init_char) or set_baud(int baud)].
 */

//
// Public Methods
//

/** Take a single measurement. An object data_obs with the timestamp is returned.
    This method must be implemented as specified in the abstract class driver_obs */
public: virtual int get(data_obs* data)=0;

/** Take continuous measurement in triggered mode */
public: virtual int run(double freq)=0;
/** Take continuous measurement in freerun mode */
public: virtual int freerun(double freq)=0;
/** Stop continuous measurements */
public: virtual int stop()=0;

//
// Private Methods
//

protected:

/** Receive raw from serial port without time information. */
virtual int receive_raw(char *buf, int buflen, double timeout);
/** Receive from serial port without time information. */
virtual int receive(char *buf, int buflen, double timeout);
/** Receive from serial port with time information. */
virtual int receive(char *buf, int buflen, double timeout,
		struct timespec *recv_time);

/** Send a command to the serial port. */
virtual int send(const char* cmd);
/** Send a command to the serial port. */
virtual int send(char* cmd);

/** Wait for a correctly terminated answer */
int waitanswer(double timeout);


/** Flush the buffer of the serial port. */
virtual int flush();

86
87
88
89
90
91
92
/** Automatic determination of the baud rate */
virtual int find_baud(char* init_chars[], int init_chars_num);
/** Automatic determination of the baud rate */
virtual int find_baud(const char* init_chars);
/** Automatic determination of the baud rate */
virtual int find_baud(Driver_Obs_Serial* context,int(Driver_Obs_Serial::*check_baud)(int));
/** Set given baud rate */
Achim Morschhauser's avatar
Achim Morschhauser committed
93
virtual int set_baud(int baud);
94
95
/** Check if baud rate is correct */
virtual int check_baud(int baud);
Achim Morschhauser's avatar
Achim Morschhauser committed
96
97
98
99
100
101
102
103
104

/** Set the termination characters. */
virtual int set_term(const char* term,int termlen);

};



#endif /* INCLUDE_DRIVER_OBS_SERIAL_HPP_ */