driver_obs_obsdaq.hpp 4.69 KB
Newer Older
Achim Morschhauser's avatar
Achim Morschhauser committed
1
2
3
4
5
6
7
8
9
10
11
12
13
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, April 2016			*
* mors//gfz-potsdam.de								*
*										*
* This class provides the driver for an OBSDAQ ADC.				*
* 										*
* It is based on the abstract observatory driver class driver_obs.		*
*										*
********************************************************************************/
#ifndef _DRIVER_OBS_OBSDAQ_H
#define _DRIVER_OBS_OBSDAQ_H

#include <string>
Achim Morschhauser's avatar
Achim Morschhauser committed
14
#include <unordered_map>
Achim Morschhauser's avatar
Achim Morschhauser committed
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

#include <Driver_Obs_Serial.hpp>
#include <data_obs_vector.hpp>
#include <data_obs.hpp>
#include <buffer_obs.hpp>
#include <Obs_Calibration_Vector.hpp>

//#include <Cal_Const.hpp>

/****************************************************************************
 ****************************************************************************
 *																			*
 * This class provides the driver for an OBSDAQ ADC.			        	*
 * 																			*
 * It is based on the abstract observatory driver class driver_obs.			*											*
 *																			*
 ****************************************************************************
 ***************************************************************************/

class driver_obs_obsdaq : protected Driver_Obs_Serial
{

//
// Private class variables
//

private:

/** The address to use (RS-485) */
Achim Morschhauser's avatar
Achim Morschhauser committed
44
45
int RS485_addr;                 // Used as function parameter
std::string RS485_addrstr;      // Used for commands to ObsDAQ
Achim Morschhauser's avatar
Achim Morschhauser committed
46
47
48
49

/** The quartz crystal frequency */
int quartz_freq;

50
51
52
/** The serial number */
std::string sn;

Achim Morschhauser's avatar
Achim Morschhauser committed
53
54
55
56
57
58
59
60
61
62
63
64
/** The conversion constant */
//TODO Should be an array of three!
double M;

/** Digital filter output rates */
double  valid_filter_rates[11];
static const int valid_filter_rates_num=11;
const char*  filter_cmds[11];

/** Counting variable for binary data supplemental channels */
int supp_count;

Achim Morschhauser's avatar
Achim Morschhauser committed
65
66
/** Baud rate codes */
const static std::unordered_map<int,std::string> map_baud;
67
68
std::unordered_map<int,std::string>::const_iterator it_map_baud;

Achim Morschhauser's avatar
Achim Morschhauser committed
69
70


Achim Morschhauser's avatar
Achim Morschhauser committed
71
72
73
74
75
76
77
78
79
//
// Constructors
//

/** Standard constructor (Automatic baud rate) */
public: driver_obs_obsdaq(std::string port, buffer_obs* buffer,
		Obs_Calibration_Vector* cal, int addr=0x0F);

/** Standard constructor (Pre-defined baud rate) */
Achim Morschhauser's avatar
Achim Morschhauser committed
80
81
public: driver_obs_obsdaq(std::string port, int baud, buffer_obs* buffer,
		Obs_Calibration_Vector* cal, int addr=0x0F);
Achim Morschhauser's avatar
Achim Morschhauser committed
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115

//
// Public Methods
//

public:

/** 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 */
int get(data_obs* data);
/** Take a single measurement and return all data */
int get(data_obs_vector* data);

/** Take continuous measurement in triggered mode */
int run(double freq);
/** Take continuous measurement in freerun mode */
int freerun(double freq);
/** Stop continuous measurements */
int stop();

/** Manually calibrate the ObsDAQ */
//int get_manual_calibrate(FILE* file_cal);
/** Manually calibrate the ObsDAQ */
//int get_manual_calibrate(float scale, float offset);
/** Use the manually determined calibration constants */
//int set_manual_calibrate(FILE* file_cal);
/** Use the manually determined calibration constants */
//int set_manual_calibrate(float scale, float offset);

/** Automatically calibrate the ObsDAQ */
int auto_calibrate(int channel, int repeat);

116
117
118
/** Manually calibrate the ObsDAQ */
int full_calibrate(int channel, int repeat);

Achim Morschhauser's avatar
Achim Morschhauser committed
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
//
// Protected Methods
//

protected:

/** Set the termination characters for serial comm. */
int set_term();

//
// Private Methods
//

private:

Achim Morschhauser's avatar
Achim Morschhauser committed
134
135
136
137
138
139
140
141
/** Initialize the instrument with given baud rate */
int set_baud(int baud);
/** Find the correct baud rate */
int find_baud();
/** Check if we are listening on correct baud rate */
int check_baud(int baud);

    
Achim Morschhauser's avatar
Achim Morschhauser committed
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/** Send an OBSDAQ-type command to address of RS-485 serial port */
int send(const char* cmd);
/** Send an OBSDAQ-type command to address of RS-485 serial port */
int send(char* cmd);
/** Send an OBSDAQ-type command to address of RS-485 serial port,
 *  check and get response */
int checked_send(const char* cmd, const char* reply, int digits,
		double timeout,	std::string* recv, int verbose=0);
/** Send an OBSDAQ-type command to address of RS-485 serial port
 *  and check response */
int checked_send(const char* cmd, const char* reply, int digits,
		double timeout, int verbose=0);

/** Parse the input data from ASCII format */
int parse_data_ascii(data_obs_vector* data, char* buf);
/** Parse the input data from binary format */
int parse_data_bin(data_obs_vector* data, char* buf);

/** Initialize the instrument */
int init();

/** Prepare continuous data acquisition **/
int init_run(double freq);

};

#endif /* _DRIVER_OBS_OBSDAQ_H */