Commit 4d9e81b4 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

ADC calibrate

parent 7af972ae
......@@ -32,8 +32,9 @@ private:
/** ADC calibration constant */
struct adc_cal {
std::string scale;
std::string offset;
std::string scale="";
std::string offset="";
std::string comment="";
bool operator==(const adc_cal& a) const {
return (scale == a.scale && offset == a.offset);
......@@ -87,7 +88,7 @@ public:
/** Add a calibration constant for the ADC */
int add_adc_calibrate(std::string config, std::string offset,
std::string scale);
std::string scale, std::string comment);
/** Save the calibration constants to file */
int save_adc_calibrate(std::string filename);
......
......@@ -7,6 +7,7 @@
#include <Obs_Calibration_Vector.hpp>
#include <stdio.h>
#include <time.h>
Obs_Calibration_Vector::Obs_Calibration_Vector(double offset, double scale){
......@@ -157,12 +158,13 @@ int Obs_Calibration_Vector::get_adc_calibrate(std::string config,
* *
***************************************************************************/
int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
std::string offset, std::string scale){
std::string offset, std::string scale, std::string comment){
struct adc_cal cal;
cal.offset = offset;
cal.scale = scale;
cal.comment = comment;
// Check if already exists
if (map_ADC.count(config)>0) {
......@@ -190,9 +192,12 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
*/
std::ifstream file_in(filename);
std::stringstream buf_in;
std::ofstream file_out;
std::string line, config, comment;
std::stringstream buf_in;
time_t t=time(0); // Current time
char time_c[20]; // Current time as c-string
size_t pos_c;
......@@ -232,6 +237,7 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
file_out << line << std::endl;
// Existing config is different
} else {
file_out << "# " << asctime(gmtime(&t)) << " UTC\n";
file_out << "#" << line << std::endl;
file_out << config << "," << cal.offset << "," <<
cal.scale << ";" << comment << std::endl;
......@@ -248,6 +254,8 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
// Write all remaining configurations
for (auto& i : map_ADC_cpy){
strftime(time_c,sizeof(time_c),"%F %T",gmtime(&t));
file_out << "\n# " << i.second.comment << " " << time_c << " UTC\n";
file_out << i.first << "," << i.second.scale << ","
<< i.second.offset << ";" << std::endl;
}
......@@ -334,7 +342,6 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
line=line.substr(0,pos_c);
}
if (line.size()==0) return(-1);
std::cerr << "PARSE: " << line << std::endl;
// Find configuration string
pos_c=line.find(',');
config=line.substr(0,pos_c);
......
......@@ -508,7 +508,7 @@ int driver_obs_obsdaq::auto_calibrate(int channel, int repeat,
^ (int32_t) 0x800000L ;
sprintf(cmd,"$%1dWF%06X",channel,n32);
send(cmd);
scale_str=offset_str.substr(4,6);
scale_str=std::string(cmd).substr(4,6);
waitanswer(1);
std::cerr << "Set scale: " << scale/repeat << " " << cmd << std::endl;
......@@ -528,7 +528,7 @@ int driver_obs_obsdaq::auto_calibrate(int channel, int repeat,
// Store the new calibration values
//
/////////////////////////////////////////////////////////////////////////
cal->add_adc_calibrate(config,offset_str,scale_str);
cal->add_adc_calibrate(config,offset_str,scale_str,"AUTO-CALIBRATE");
return(0);
......
# config (serialnumber/ccdd/channel),scale,offset
# Tatuoca
OD-56A17021/0223/0,3AEC9C,00028E;
#OD-56A17021/0223/0,3AEC9C,00028E;
OD-56A17021/0223/1,3AEC9C,00028E;
OD-56A17021/0223/2,3AEC9C,00028E;
# AUTO-CALIBRATE 2018-11-15 11:54:13 UTC
OD-56A17021/0223/0,2F2486,0003E4;
......@@ -20,23 +20,21 @@ int main() {
Parameters_Reader par = Parameters_Reader("usr/parameters.par");
// Set the calibration constants.
// Will be done in driver_obs_obsdaq constructor in future, and parameter
// file will be given as argument to constructor
double R = par.get_dbl("R");
double X_s = par.get_dbl("X_s");
double Y_s = par.get_dbl("Y_s");
double Z_s = par.get_dbl("Z_s");
// Initialize new buffer for STDOUT
buffer_obs_pipe pipe = buffer_obs_pipe(5);
// Initialize the calibration constants
// Initialize the calibration constants for FGE
Obs_Calibration_Vector cal = Obs_Calibration_Vector(X_s/R,Y_s/R,Z_s/R);
// Initialize the calibration constants for ObsDAQ
cal.set_adc_calibrate("usr/ADC.par");
std::string offset,scale,config;
config="OD-550C0001/0203/1";
cal.get_adc_calibrate(config,offset,scale);
std::cout << "READ ADC: " << offset << " " << scale << std::endl;
// Initialize new OBSDAQ device
driver_obs_obsdaq obsdaq = driver_obs_obsdaq(par.get_str("PORT"),
par.get_int("BAUD"), &pipe, &cal, 1);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment