Commit 397c0a76 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Merge branch 'rasp3_BEL'

parents f678c170 602643d1
...@@ -12,6 +12,7 @@ PRIVATE/ ...@@ -12,6 +12,7 @@ PRIVATE/
CHANGELOG CHANGELOG
DataLogger DataLogger
TMP/*
usr/* usr/*
!usr/GNUPLOT !usr/GNUPLOT
!usr/START !usr/START
......
...@@ -17,7 +17,7 @@ USR_TARGET = $(patsubst $(USE_SRC_DIR)%.cpp,%,$(USR_FILES)) ...@@ -17,7 +17,7 @@ USR_TARGET = $(patsubst $(USE_SRC_DIR)%.cpp,%,$(USR_FILES))
#-------------------------------------- #--------------------------------------
CC=g++ CC=g++
CCFLAGS=-g -lrt -std=c++11 -lpthread CCFLAGS=-g -lrt -std=c++11
EXCL=driver_serial_emulate.o EXCL=driver_serial_emulate.o
# Uncomment to use virtual serial port. Run 'make clean all' afterwards # Uncomment to use virtual serial port. Run 'make clean all' afterwards
......
/********************************************************************************
* 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_H
#define _BUFFER_OBS_file_H
#include <buffer_obs.hpp>
#include <data_obs.hpp>
#include <fstream>
class buffer_obs_file : public buffer_obs
{
//
// Private class variables
//
private:
// Precision
int precision;
// Path to output files
std::string path;
// Format of output file (strftime)
std::string format;
// Currently opened filename (no path)
std::string filename="";
// File stream
std::fstream file;
//
// Constructors
//
public:
//buffer_obs_file(int precision=2);
//buffer_obs_file(int precision,std::string path);
buffer_obs_file(int precision=2,std::string path="", std::string format="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
//
/** Initialize the buffer */
private: int init();
/** Open file and create folder */
private: int open(std::string filename);
};
#endif /* _BUFFER_OBS_file_H */
/********************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, July 2019 *
* mors//gfz-potsdam.de *
* *
* This class allows to combine different types of buffers and split output.
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
#ifndef _BUFFER_OBS_mult_H
#define _BUFFER_OBS_mult_H
// Package headers
#include <buffer_obs.hpp>
#include <data_obs.hpp>
// C++ headers
#include <vector>
class buffer_obs_mult : public buffer_obs
{
//
// Private class variables
//
private:
// Vector of buffers
std::vector <buffer_obs*> buffers;
//
// Constructors
//
public:
buffer_obs_mult(buffer_obs* buffer);
// Don't allow to avoid checking for empty buffer
//buffer_obs_mult();
//
// 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();
/** Add a buffer */
public: int add(buffer_obs* buffer);
//
// Private Methods
//
/** Initialize the buffer */
private: int init();
};
#endif /* _BUFFER_OBS_mult_H */
...@@ -69,6 +69,8 @@ public: int set_time(data_obs* data); ...@@ -69,6 +69,8 @@ public: int set_time(data_obs* data);
/** Get the time of the data */ /** Get the time of the data */
public: int get_time(int* year, int* mon, int* day, int* hour, int* min, int* sec, public: int get_time(int* year, int* mon, int* day, int* hour, int* min, int* sec,
long* msec); long* msec);
/** Get time as tm */
public: int get_time(struct tm* time) const;
/** Get time as timespec */ /** Get time as timespec */
public: int get_time(struct timespec* time) const; public: int get_time(struct timespec* time) const;
......
...@@ -91,7 +91,7 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout, ...@@ -91,7 +91,7 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout,
********************************************************************************/ ********************************************************************************/
int Driver_Obs_Serial::send(const char* cmd) { int Driver_Obs_Serial::send(const char* cmd) {
//printf("Send: %s\n",cmd); //fprintf(stderr,"Send: %s\n",cmd);
return(serial.send(cmd)); return(serial.send(cmd));
...@@ -214,13 +214,13 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) { ...@@ -214,13 +214,13 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
// Try different baudrates // Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) { for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]); //fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
serial.set_baud(valid_baudrates[i]); serial.set_baud(valid_baudrates[i]);
usleep(100000); usleep(100000);
for (int j = 0; j<init_chars_num-1; j++){ for (int j = 0; j<init_chars_num-1; j++){
//printf("BAUD: %s\n",init_chars[j]); //fprintf(stderr,"BAUD: %s\n",init_chars[j]);
send(init_chars[j]); send(init_chars[j]);
usleep(10000); usleep(10000);
flush(); flush();
...@@ -232,14 +232,14 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) { ...@@ -232,14 +232,14 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
break; break;
} }
//printf("VB: %d",valid_baudrates_size); //fprintf(stderr,"VB: %d",valid_baudrates_size);
// This has to be in loop as characters received at false baud rate // This has to be in loop as characters received at false baud rate
// somehow can corrupt the value in valid_baudrates_size (Buffer overrun // somehow can corrupt the value in valid_baudrates_size (Buffer overrun
// in driver_serial::receive // in driver_serial::receive)
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size); serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size); //fprintf(stderr," %d\n",valid_baudrates_size);
} }
...@@ -280,7 +280,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context, ...@@ -280,7 +280,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
// Try different baudrates // Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) { for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]); //fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
if (context->check_baud(valid_baudrates[i]) == 1) { if (context->check_baud(valid_baudrates[i]) == 1) {
baud = valid_baudrates[i]; baud = valid_baudrates[i];
break; break;
...@@ -289,7 +289,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context, ...@@ -289,7 +289,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
somehow can corrupt the value in valid_baudrates_size (Buffer overrun somehow can corrupt the value in valid_baudrates_size (Buffer overrun
in driver_serial::receive */ in driver_serial::receive */
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size); serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size); //fprintf(stderr," %d\n",valid_baudrates_size);
} }
// Check if baud rate could be determined // Check if baud rate could be determined
......
This diff is collapsed.
...@@ -83,9 +83,9 @@ int Obs_Calibration_Vector::calibrate(data_obs_vector* vdata){ ...@@ -83,9 +83,9 @@ int Obs_Calibration_Vector::calibrate(data_obs_vector* vdata){
vdata->get_data(data); vdata->get_data(data);
for (int i=0;i<3;i++){ for (int i=0;i<3;i++){
//printf("SCALE: %f ",data[i]); //fprintf(stderr,"SCALE: %f ",data[i]);
data[i]=data[i]*scale[i]+offset[i]; data[i]=data[i]*scale[i]+offset[i];
//printf("%f %f\n",data[i],scale[i]); //fprintf(stderr,"%f %f\n",data[i],scale[i]);
} }
vdata->set_data(data); vdata->set_data(data);
...@@ -305,7 +305,7 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config, ...@@ -305,7 +305,7 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
} }
file.close(); file.close();
} else { } else {
std::cout << "Unable to open file: " << filename << std::endl; std::cerr << "Unable to open file: " << filename << std::endl;
} }
......
...@@ -64,21 +64,33 @@ Parameters_Reader::Parameters_Reader(std::string filename) { ...@@ -64,21 +64,33 @@ Parameters_Reader::Parameters_Reader(std::string filename) {
*******************************************************************************/ *******************************************************************************/
std::string Parameters_Reader::get_str(std::string key){ std::string Parameters_Reader::get_str(std::string key){
return parMap.at(key); if (parMap.find(key) == parMap.end()){
return("");
} else {
return parMap.at(key);
}
} }
int Parameters_Reader::get_int(std::string key){ int Parameters_Reader::get_int(std::string key){
return std::stoi(parMap.at(key)); if (parMap.find(key) == parMap.end()){
return(-1);
} else {
return std::stoi(parMap.at(key));
}
} }
double Parameters_Reader::get_dbl(std::string key){ double Parameters_Reader::get_dbl(std::string key){
return std::stod(parMap.at(key)); if (parMap.find(key) == parMap.end()){
return(-1.0);
} else {
return std::stod(parMap.at(key));
}
} }
...@@ -112,7 +124,7 @@ int Parameters_Reader::read(std::string filename){ ...@@ -112,7 +124,7 @@ int Parameters_Reader::read(std::string filename){
} }
file.close(); file.close();
} else { } else {
std::cout << "Unable to open file \n"; std::cerr << "Unable to open file \n";
} }
return 0; return 0;
......
/*******************************************************************************
* 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. *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
// C++ Headers
#include <iostream> // Standard I/O
#include <fstream>
#include <sys/stat.h>
#include <libgen.h>
#include <unistd.h> // for close
// C headers
#include <time.h>
// Custom C++ Headers
#include <buffer_obs_file.hpp> // Buffer using File I/O
/********************************************************************************
*********************************************************************************
* *
* Constructors. *
* *
*********************************************************************************
********************************************************************************/
buffer_obs_file::buffer_obs_file(int precision, std::string path,
std::string format) {
// Set precision
this->precision = precision;
// Set path
this->path = path;
// Set format
this->format = format;
}
/********************************************************************************
*********************************************************************************
* *
* Public Methods. *
* *
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *
* Add data of type data_obs to the buffer. This is done by converting the *
* data to its string representation and writing to File Output. *
* Take care to name files according to date *
* *
********************************************************************************/
int buffer_obs_file::put(data_obs* data) {
std::string datastr;
struct tm time;
size_t smax=40;
char filename[smax];
std::string filename_full;
// Create filename
data->get_time(&time);
strftime(filename,smax,format.c_str(),&time);
// Check if file is already opened
if (this->filename.compare(filename)){
open(filename);
}
// Write data to file
data->string(&datastr,precision);
file << datastr << std::endl;
if (file.bad()) {
std::cerr << "Opening or writing to file " << filename_full
<< " failed!" << std::endl;
}
return(0);
}
/********************************************************************************
* *
* Read data from the buffer. This is done by reading from Standard Input and *
* parsing the string. *
* *
********************************************************************************/
int buffer_obs_file::pop(data_obs* data) {
return(-1);
}
data_obs buffer_obs_file::pop(){
data_obs data;
pop(&data);
return(data);
}
/********************************************************************************
*********************************************************************************
* *
* Private Methods. *
* *
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *
* Method dummy for initialization: No initialization is needed. *
* *
********************************************************************************/
int buffer_obs_file::init() {
return(0);
}
/********************************************************************************
* *
* Create directories and open file *
* *
********************************************************************************/
int buffer_obs_file::open(std::string filename) {
std::string filename_full;
// Create full path
filename_full = path+'/'+filename;
// Create directory
int pos = filename_full.find('/',1);
while (pos != std::string::npos){
mkdir(filename_full.substr(0,pos).c_str(),0777);
pos = filename_full.find('/',pos+1);
}
// Close old file, if necessary
if (file.is_open()) {
file.close();
}
// Open new file
file.open(filename_full,std::ios::out | std::ios::app);
// Set filename
this->filename = filename;
return(0);
}
\ No newline at end of file
/*******************************************************************************
* WRITTEN BY ACHIM MORSCHHAUSER, GFZ POTSDAM, April 2016 *
* mors//gfz-potsdam.de *
* *
* This class provides a buffer of observatory data that uses standard input *
* and output. It can be used in combination with the SHELL pipe operator (|). *
* *
* This class implements the abstract class buffer_obs. *
* *
********************************************************************************/
// C++ Headers
#include <iostream> // Standard I/O
// Custom C++ Headers
#include <buffer_obs_mult.hpp>
#include <buffer_obs.hpp>
/********************************************************************************
*********************************************************************************
* *
* Constructors. *
* *
*********************************************************************************
********************************************************************************/
buffer_obs_mult::buffer_obs_mult(buffer_obs* buffer) {
buffers.push_back(buffer);
}
/********************************************************************************
*********************************************************************************
* *
* Public Methods. *
* *
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *
* Add data of type data_obs to the buffer. This is done by converting the *
* data to its string representation and writing to Standard Output. *
* *
********************************************************************************/
int buffer_obs_mult::put(data_obs* data) {
for (int i=0; i<buffers.size(); i++){
buffers.at(i)->put(data);
}
return(0);
}
/********************************************************************************
* *
* Read data from the buffer. This is done by reading from Standard Input and *
* parsing the string. *
* *
********************************************************************************/
int buffer_obs_mult::pop(data_obs* data) {
buffers.at(0)->pop(data);
return(0);
}
data_obs buffer_obs_mult::pop(){
data_obs data;
return(data);
}
int buffer_obs_mult::add(buffer_obs* buffer) {
buffers.push_back(buffer);
return(0);
}
/********************************************************************************
*********************************************************************************
* *
* Private Methods. *
* *
*********************************************************************************
********************************************************************************/
/********************************************************************************
* *