Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Achim Morschhauser
GeomagLogger
Commits
b41d5ed0
Commit
b41d5ed0
authored
Dec 07, 2021
by
Achim Morschhauser
Browse files
Save temperature and calibration mode for calibration
parent
740da9fe
Changes
4
Hide whitespace changes
Inline
Side-by-side
include/Obs_Calibration.hpp
View file @
b41d5ed0
...
...
@@ -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
;
};
...
...
include/Obs_Calibration_Vector.hpp
View file @
b41d5ed0
...
...
@@ -33,6 +33,8 @@ private:
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
{
...
...
@@ -79,7 +81,8 @@ public:
/** Add a calibration constant for the ADC */
int
add_adc_calibrate
(
std
::
string
config
,
std
::
string
offset
,
std
::
string
scale
,
std
::
string
comment
);
std
::
string
scale
,
double
temperature
,
std
::
string
mode
,
std
::
string
comment
);
/** Save the calibration constants to file */
int
save_adc_calibrate
(
std
::
string
filename
);
...
...
src/Obs_Calibration_Vector.cpp
View file @
b41d5ed0
...
...
@@ -4,6 +4,7 @@
#include
<sstream>
// String streams
#include
<fstream>
// File operations
#include
<unordered_map>
#include
<iomanip>
// Set precision in strstream
#include
<Obs_Calibration_Vector.hpp>
#include
<stdio.h>
...
...
@@ -128,22 +129,29 @@ 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
comment
)
{
std
::
string
offset
,
std
::
string
scale
,
double
temperature
,
std
::
string
mode
,
std
::
string
comment
)
{
struct
adc_cal
cal
;
cal
.
offset
=
offset
;
cal
.
scale
=
scale
;
cal
.
comment
=
comment
;
cal
.
temperature
=
temperature
;
cal
.
mode
=
mode
;
// Check if already exists
if
(
map_ADC
.
count
(
config
)
>
0
)
{
std
::
cerr
<<
"Calibration for "
<<
config
<<
" overwritten."
<<
std
::
endl
;
}
else
{
std
::
cerr
<<
"Calibration for "
<<
config
<<
" newly written."
<<
std
::
endl
;
}
std
::
cerr
<<
"WRITE: "
<<
config
<<
std
::
endl
;
map_ADC
[
config
]
=
cal
;
std
::
cerr
<<
"Calibration for "
<<
config
<<
" newly written."
<<
std
::
endl
;
return
(
0
);
...
...
@@ -215,7 +223,9 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
file_out
<<
"# "
<<
cal
.
comment
<<
" "
<<
time_c
<<
" UTC
\n
"
;
file_out
<<
config
<<
","
<<
cal
.
scale
<<
","
<<
cal
.
offset
<<
";"
<<
std
::
endl
;
<<
std
::
setprecision
(
3
)
<<
";T:"
<<
cal
.
temperature
<<
";"
<<
"M:"
<<
cal
.
mode
<<
";"
<<
std
::
endl
;
}
// Configuration only exists in file
...
...
@@ -227,11 +237,15 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
}
// Write all remaining configurations
// Write all remaining
(new)
configurations
for
(
auto
&
i
:
map_ADC_cpy
){
file_out
<<
"
\n
# "
<<
i
.
second
.
comment
<<
" "
<<
time_c
<<
" UTC
\n
"
;
file_out
<<
i
.
first
<<
","
<<
i
.
second
.
scale
<<
","
<<
i
.
second
.
offset
<<
";"
<<
std
::
endl
;
<<
i
.
second
.
offset
<<
";"
<<
std
::
setprecision
(
3
)
<<
"T:"
<<
i
.
second
.
temperature
<<
";"
<<
"M:"
<<
i
.
second
.
mode
<<
";"
<<
std
::
endl
;
}
...
...
@@ -274,7 +288,7 @@ int Obs_Calibration_Vector::read_adc_calibrate(std::string filename) {
// Save key-value pair
map_ADC
[
config
]
=
cal
;
std
::
cerr
<<
"Read ADC: "
<<
config
<<
" "
<<
cal
.
offset
<<
" "
<<
cal
.
scale
<<
std
::
endl
;
<<
cal
.
scale
<<
" "
<<
cal
.
temperature
<<
std
::
endl
;
}
}
file
.
close
();
...
...
@@ -320,13 +334,36 @@ int Obs_Calibration_Vector::parse_adc_calibration(std::string line,
// Find configuration string
pos_c
=
line
.
find
(
','
);
config
=
line
.
substr
(
0
,
pos_c
);
// Find calibration string
line
=
line
.
substr
(
pos_c
+
1
);
// Find scale string
pos_c
=
line
.
find
(
','
);
cal
.
scale
=
line
.
substr
(
0
,
pos_c
);
line
=
line
.
substr
(
pos_c
+
1
);
// Find fullscale value
pos_c
=
line
.
find
(
';'
);
cal
.
offset
=
line
.
substr
(
0
,
pos_c
);
line
=
line
.
substr
(
pos_c
+
1
);
// Find temperature string (added later)
// Here we use a tag ('T:') to add future values
while
(
!
line
.
empty
()){
pos_c
=
line
.
find
(
';'
);
if
(
pos_c
!=
std
::
string
::
npos
){
switch
(
line
.
at
(
0
))
{
case
'T'
:
cal
.
temperature
=
stof
(
line
.
substr
(
2
,
pos_c
));
break
;
case
'M'
:
cal
.
mode
=
line
.
substr
(
2
,
pos_c
);
break
;
case
';'
:
pos_c
++
;
break
;
default:
break
;
}
line
=
line
.
substr
(
pos_c
+
1
);
}
}
return
(
0
);
}
...
...
src/driver_obs_obsdaq.cpp
View file @
b41d5ed0
...
...
@@ -441,22 +441,16 @@ int driver_obs_obsdaq::auto_calibrate(int repeat, double freq) {
int
driver_obs_obsdaq
::
calibrate
(
int
repeat
,
std
::
string
mode
,
double
&
fullscale
)
{
int
cal_done
=
0
;
int
cal_done
,
cal_load
;
std
::
string
adc_scale
,
adc_offset
,
str_recv
;
char
cmd
[
20
]
=
""
;
std
::
string
config
;
data_obs_vector
data
(
5
);
// Get temperature
get
(
&
data
);
double
T
=
data
.
get_supp
(
1
);
std
::
cout
<<
"OBSDAQ temperature: "
<<
T
<<
std
::
endl
;
// Iterate over all three channels
for
(
int
i
=
0
;
i
<
3
;
i
++
)
{
str_recv
=
""
;
cal_load
=
0
;
// Get current 24-bit configuration (Manual 12.4.9)
flush
();
...
...
@@ -488,14 +482,14 @@ int driver_obs_obsdaq::calibrate(int repeat, std::string mode,
std
::
string
rsp
=
ask_message
(
msg
,
std
::
vector
<
std
::
string
>
{
"y"
,
"n"
});
if
(
rsp
==
"y"
)
{
calibrate_channel
(
i
,
5
,
mode
,
config
);
calibrate_channel
(
i
,
repeat
,
mode
,
config
);
cal_done
=
1
;
}
else
{
cal_
done
=
0
;
cal_
load
=
1
;
}
}
if
(
cal_
done
==
0
)
{
if
(
cal_
load
)
{
// Set the pre-determined calibration constant
std
::
cerr
<<
"PRE DETERMINED"
<<
std
::
endl
;
set_calibration
(
i
,
adc_offset
,
adc_scale
);
...
...
@@ -514,7 +508,7 @@ int driver_obs_obsdaq::calibrate(int repeat, std::string mode,
// Save calibration constants
if
(
cal_done
)
{
driver_obs
::
cal
->
save_adc_calibrate
();
std
::
c
err
<<
"==== New calibration constants written to "
std
::
c
out
<<
"==== New calibration constants written to "
<<
cal
->
get_adc_calibrate
()
<<
std
::
endl
;
}
...
...
@@ -730,7 +724,18 @@ int driver_obs_obsdaq::calibrate_channel(int channel, int repeat,
//
/////////////////////////////////////////////////////////////////////////
tmp
=
mode
.
substr
(
0
,
4
)
+
"-CALIBRATE"
;
cal
->
add_adc_calibrate
(
config
,
offset_str
,
scale_str
,
tmp
);
// Get temperature
data_obs_vector
data
(
5
);
get
(
&
data
);
double
T
=
data
.
get_supp
(
1
);
std
::
cout
<<
"OBSDAQ temperature: "
<<
T
<<
std
::
endl
;
cal
->
add_adc_calibrate
(
config
,
offset_str
,
scale_str
,
T
,
mode
.
substr
(
0
,
4
),
tmp
);
std
::
cout
<<
"CALIBRATION FOR CHANNEL "
<<
channel
<<
" FINISHED"
<<
std
::
endl
;
return
(
0
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment