Commit 2663d479 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Merge branch 'WNG' into DEVELOP

parents 5077c6d9 7142056a
*.o
*.tmp
*.cbp
*~
.settings/
......@@ -12,6 +13,7 @@ PRIVATE/
CHANGELOG
DataLogger
parameters*
RSYNC
DATA
DATA/*
......@@ -23,6 +25,8 @@ usr/*
usr/src/*
!usr/src/GSM_Logger.cpp
!usr/src/OBSDAQ_Logger.cpp
!usr/src/OBSDAQ_Calibrate.cpp
!usr/src/OBSDAQ_Logger.cpp
!usr/src/Serial_Talk.cpp
!usr/src/Stream_Reader.cpp
!usr/par/
......
......@@ -29,11 +29,13 @@ public:
/** Get the calibration constants for the ADC with the given
* configuration (config) */
virtual int get_adc_calibrate(int* offset, int* scale, int config)=0;
virtual int get_adc_calibrate(int* offset, int* scale, double temperature,
int config)=0;
/** Add the calibration constants for the ADC with the given
* configuration (config) */
virtual int add_adc_calibrate(int offset, int scale, int config)=0;
virtual int add_adc_calibrate(int offset, int scale, double temperature,
int config)=0;
};
......
......@@ -15,42 +15,36 @@ class Obs_Calibration_Vector {
private:
/** File for ADC calibration constants */
std::string file_ADC="";
/** File for ADC calibration constants */
std::string file_ADC = "";
/** The offset */
std::vector<double> offset;
/** The scale value */
std::vector<double> scale;
int N=0;
int N = 0;
/** Non-zero calibration constants */
char do_cal=0;
/** ADC calibration constant */
struct adc_cal {
std::string scale="";
std::string offset="";
std::string comment="";
bool operator==(const adc_cal& a) const {
return (scale == a.scale && offset == a.offset);
}
};
/** Map containing the ADC calibration key-value pairs */
std::unordered_map<std::string, struct adc_cal> map_ADC;
/** ADC Offsets */
std::vector<int> adc_offset;
/** ADC scale values */
std::vector<int> adc_scale;
/** ADC configuration */
std::vector<int> adc_config;
char do_cal = 0;
/** ADC calibration constant */
struct adc_cal {
std::string scale = "";
std::string offset = "";
double temperature = 999; //TODO Insert MD value here
std::string mode = "MANU";
std::string comment = "";
bool operator==(const adc_cal &a) const {
return (scale == a.scale && offset == a.offset);
}
};
/** Map containing the ADC calibration key-value pairs */
std::unordered_map<std::string, struct adc_cal> map_ADC;
//
// Constructors
......@@ -59,11 +53,11 @@ private:
public:
/** Constructor with single values */
Obs_Calibration_Vector(int N, double offset=0, double scale=1);
Obs_Calibration_Vector(int N, double offset = 0, double scale = 1);
/** Constructor with vector values */
Obs_Calibration_Vector(std::vector<double>& offset,
std::vector<double>& scale);
Obs_Calibration_Vector(std::vector<double> &offset,
std::vector<double> &scale);
//
// Public Methods
......@@ -72,35 +66,45 @@ public:
public:
/** Calibrate data */
int calibrate(data_obs* sdata);
int calibrate(data_obs *sdata);
/** Multiply the calibration scale values for data **/
int multiply_scale(std::vector<double> &scale, int pos=0);
/** Get the calibration constants for data **/
int get_calibration(std::vector<double> &offset,
std::vector<double> &scale);
/** Get the calibration constants for the ADC */
int get_adc_calibrate(std::string config, std::string &offset,
std::string &scale);
std::string &scale, std::string &mode);
/** Get the calibration constants for the ADC (with temperature) */
int get_adc_calibrate(std::string config, std::string &offset,
std::string &scale, std::string &mode, double &temperature);
/** Add a calibration constant for the ADC */
int add_adc_calibrate(std::string config, std::string offset,
std::string scale, std::string comment);
/** Save the calibration constants to file */
int save_adc_calibrate(std::string filename);
int save_adc_calibrate();
/** Read the calibration constants from file */
int read_adc_calibrate(std::string filename);
int read_adc_calibrate();
/** Parse an ADC calibration line */
int parse_adc_calibration(std::string line,
std::string& config, struct adc_cal& cal);
int parse_adc_calibration(std::string line,
std::string& config, struct adc_cal& cal, std::string& comment);
/** Set the internal ADC calibration file */
int set_adc_calibrate(std::string filename);
/** Get the internal ADC calibration file */
std::string get_adc_calibrate();
std::string scale, double temperature, std::string mode,
std::string comment);
/** Save the calibration constants to file */
int save_adc_calibrate(std::string filename);
int save_adc_calibrate();
/** Read the calibration constants from file */
int read_adc_calibrate(std::string filename);
int read_adc_calibrate();
/** Parse an ADC calibration line */
int parse_adc_calibration(std::string line, std::string &config,
struct adc_cal &cal);
int parse_adc_calibration(std::string line, std::string &config,
struct adc_cal &cal, std::string &comment);
/** Set the internal ADC calibration file */
int set_adc_calibrate(std::string filename);
/** Get the internal ADC calibration file */
std::string get_adc_calibrate();
};
......
......@@ -8,8 +8,8 @@
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_file_H
#define _BUFFER_OBS_file_H
#ifndef _BUFFER_OBS_FILE_H
#define _BUFFER_OBS_FILE_H
#include <buffer_obs.hpp>
#include <data_obs.hpp>
......@@ -27,7 +27,7 @@ class buffer_obs_file : public buffer_obs
// Private class variables
//
private:
protected:
// Path to output files
std::string path;
......@@ -37,8 +37,9 @@ std::string format;
std::string filename="";
// File stream
std::fstream file;
// String Parser for data format in file
String_Parser parser;
// Read and writing position
std::streampos readpos;
std::streampos writepos;
//
......@@ -47,45 +48,36 @@ String_Parser parser;
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
//buffer_obs_file_ascii(int precision=2);
//buffer_obs_file_ascii(int precision,std::string path);
buffer_obs_file(std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(int precision,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(std::string& formatstr,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file(const String_Parser& parser,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
public: virtual int put(data_obs* data)=0;
/** Get last element and delete */
public: int pop(data_obs* data);
public: virtual int pop(data_obs* data)=0;
/** Get last element and delete */
public: data_obs pop();
public: virtual data_obs pop()=0;
/** Read from file **/
public: std::istream& read(char* s, std::streamsize n);
/** Write to file **/
public: std::ostream& write(const char* s, std::streamsize n);
//
// Private Methods
//
/** Initialize the buffer */
private: int init();
protected: int init();
/** Open file and create folder */
private: int open(std::string filename);
protected: int open(std::string filename);
/** Write string to file buffer */
private: int check(data_obs* data);
protected: int check(data_obs* data);
};
#endif /* _BUFFER_OBS_file_H */
#endif /* _BUFFER_OBS_FILE_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input and *
* output. It can be used in combination with the SHELL file operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_FILE_ASCII_H
#define _BUFFER_OBS_FILE_ASCII_H
#include <buffer_obs_file.hpp>
#include <data_obs.hpp>
#include <data_obs_vector.hpp>
#include <data_obs_scalar.hpp>
#include <fstream>
#include <String_Parser.hpp>
class buffer_obs_file_ascii : public buffer_obs_file
{
//
// Private class variables
//
private:
// String Parser for data format in file
String_Parser parser;
//
// Constructors
//
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
buffer_obs_file_ascii(std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(int precision,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(std::string& formatstr,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
buffer_obs_file_ascii(const String_Parser& parser,
std::string path="",
std::string file="TEST_%Y%m%d.txt");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
//
// Private Methods
//
};
#endif /* _BUFFER_OBS_FILE_ASCII_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses file input and *
* output. It can be used in combination with the SHELL file operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_FILE_BINARY_H
#define _BUFFER_OBS_FILE_BINARY_H
#include <buffer_obs_file.hpp>
#include <data_obs.hpp>
#include <data_obs_vector.hpp>
#include <data_obs_scalar.hpp>
#include <fstream>
class buffer_obs_file_binary : public buffer_obs_file
{
//
// Private class variables
//
private:
bool info_written=false;
//
// Constructors
//
public:
//buffer_obs_file_binary(int precision=2);
//buffer_obs_file_binary(int precision,std::string path);
buffer_obs_file_binary(std::string path="",
std::string file="TEST_%Y%m%d.bin");
//
// Public Methods
//
/** Add to buffer */
public: int put(data_obs* data);
/** Get last element and delete */
public: int pop(data_obs* data);
/** Get last element and delete */
public: data_obs pop();
//
// Private Methods
//
private:
int info(data_obs* data);
};
#endif /* _BUFFER_OBS_FILE_BINARY_H */
......@@ -78,6 +78,8 @@ double get_MD();
/** Set msec to zero if below given scatter. */
public: int smooth_msec(int prec);
/** Set msec */
public: int set_msec(long msec);
/** Set the time of the data */
public: int set_time(int year, int mon, int day, int hour, int min, int sec,
long msec);
......@@ -88,9 +90,14 @@ public: int set_timing_err(double error);
/** Set the time of the data */
public: int set_time(data_obs* data);
/** Add specified time **/
public: int add_time(time_t sec, long nsec);
/** Get the time of the data */
public: int get_time(int* year, int* mon, int* day, int* hour, int* min, int* sec,
long* msec);
/** Get the time as std::vector */
public: int get_time(std::vector<int> &time);
/** Get time as tm */
public: int get_time(struct tm* time) const;
/** Get time as timespec */
......@@ -155,7 +162,7 @@ public: double timediff(data_obs* data) const;
/** Calculate median for odd number of data */
virtual int median_odd(std::vector <data_obs*>* data);
private: virtual int median_odd_time(std::vector <data_obs*>* data);
public: virtual int median_time(std::vector <data_obs*>* data);
private: virtual int median_odd_data(std::vector <data_obs*>* data);
/** Symmetric FIR filter */
......@@ -165,8 +172,6 @@ private: virtual int filter_fir_sym_data(std::vector <data_obs*>* data,
std::vector <double>* win);
private: virtual int filter_fir_sym_supp(std::vector <data_obs*>* data,
std::vector <double>* win);
private: virtual int filter_fir_sym_time(std::vector <data_obs*>* data,
std::vector <double>* win);
/** Calculate median of even number of data */
//public: virtual int median_even(std::vector <data_obs> data);
......
......@@ -30,7 +30,9 @@ class data_obs_vector : public data_obs
/** Standard Construtor */
public:
data_obs_vector(double MD=-99999, int Nsupp=2);
//TODO Maybe there is a better way to initialize MD with the
// standard value in data_obs
data_obs_vector(double MD=99999, int Nsupp=2);
data_obs_vector(int Nsupp);
data_obs_vector(data_obs_vector* data);
......@@ -68,7 +70,6 @@ class data_obs_vector : public data_obs
where mil: milliseconds*/
virtual int parse(std::string* string);
};
#endif /* _DATA_OBS_VECTOR_H */
......@@ -50,10 +50,6 @@ int quartz_freq;
/** The serial number */
std::string sn;
/** 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;
......@@ -115,10 +111,10 @@ int stop();
//int set_manual_calibrate(float scale, float offset);
/** Automatically calibrate the ObsDAQ */
int auto_calibrate(int channel, int repeat);
int auto_calibrate(int repeat, double freq);
/** Manually calibrate the ObsDAQ */
int full_calibrate(int channel, int repeat);
int manual_calibrate(int repeat, double freq);
//
// Protected Methods
......@@ -180,8 +176,21 @@ int init();
/** Prepare continuous data acquisition **/
int init_run(double freq);
/** Automatically calibrate the ObsDAQ with given config*/
int auto_calibrate(int channel, int repeat, std::string config);
/** General calibration routine for all three channels*/
int calibrate(int repeat, std::string mode);
int calibrate_channel(int channel, int repeat, std::string mode, std::string config);
/** Set calibration on the ObsDAQ*/
int set_calibration(int channel, std::string &adc_offset,
std::string &adc_scale);
double read_cal(int channel, char mode, int N, double val);
/** Choose the sampling frequency **/
int set_freq(double freq);
int write_message(std::string msg);
std::string ask_message(std::string msg);
std::string ask_message(std::string msg, std::vector<std::string>);
};
......
......@@ -17,7 +17,7 @@
* *
****************************************************************************
***************************************************************************/
Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs* buffer) :
Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs *buffer) :
serial(port) {
this->buffer = buffer;
......@@ -28,8 +28,8 @@ Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs* buffer) :
}
Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs* buffer,
Obs_Calibration_Vector* cal) :
Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs *buffer,
Obs_Calibration_Vector *cal) :
serial(port) {
this->buffer = buffer;
......@@ -57,7 +57,7 @@ Driver_Obs_Serial::Driver_Obs_Serial(std::string port, buffer_obs* buffer,
***************************************************************************/
int Driver_Obs_Serial::receive_raw(char *buf, int buflen, double timeout) {
return(serial.receive_raw(buf,buflen,timeout));
return (serial.receive_raw(buf, buflen, timeout));
}
......@@ -68,7 +68,7 @@ int Driver_Obs_Serial::receive_raw(char *buf, int buflen, double timeout) {
***************************************************************************/
int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout) {
return(serial.receive(buf,buflen,timeout));
return (serial.receive(buf, buflen, timeout));
}
......@@ -80,7 +80,7 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout) {
int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout,
struct timespec *recv_time) {
return(serial.receive(buf,buflen,timeout,recv_time));
return (serial.receive(buf, buflen, timeout, recv_time));
}
......@@ -89,11 +89,11 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout,
* Send a command to the serial port. CMD is given as constant char. *
* *
********************************************************************************/
int Driver_Obs_Serial::send(const char* cmd) {
int Driver_Obs_Serial::send(const char *cmd) {
//fprintf(stderr,"Send: %s\n",cmd);
//fprintf(stderr,"Send: %s\n",cmd);
return(serial.send(cmd));
return (serial.send(cmd));
}
......@@ -104,7 +104,7 @@ int Driver_Obs_Serial::send(const char* cmd) {
********************************************************************************/
int Driver_Obs_Serial::send(char *cmd) {
return(serial.send(cmd));
return (serial.send(cmd));
}
......@@ -115,7 +115,7 @@ int Driver_Obs_Serial::send(char *cmd) {
********************************************************************************/
int Driver_Obs_Serial::waitanswer(double timeout) {
return(serial.waitanswer(timeout));
return (serial.waitanswer(timeout));
}
......@@ -126,7 +126,7 @@ int Driver_Obs_Serial::waitanswer(double timeout) {
********************************************************************************/
int Driver_Obs_Serial::flush() {
return(serial.flush());
return (serial.flush());
}
......@@ -135,9 +135,9 @@ int Driver_Obs_Serial::flush() {
* Set the termination characters. *
* *
********************************************************************************/
int Driver_Obs_Serial::set_term(const char* term, int termlen) {
int Driver_Obs_Serial::set_term(const char *term, int termlen) {
return(serial.set_term(term,termlen));
return (serial.set_term(term, termlen));