Skip to content
GitLab
Menu
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
9e85b0be
Commit
9e85b0be
authored
Feb 03, 2020
by
Achim Morschhauser
Browse files
Merge branch 'master' into TEST
parents
e2d1475f
93daa06e
Changes
110
Hide whitespace changes
Inline
Side-by-side
include/driver_obs_gsm90.hpp
View file @
9e85b0be
...
...
@@ -55,6 +55,8 @@ public: driver_obs_gsm90(std::string port, buffer_obs* buffer, int baud);
/** Freerun mode */
public:
int
freerun
(
double
freq
);
/** Triggered run mode **/
public:
int
run
(
double
freq
);
//
// Private Methods
...
...
@@ -65,6 +67,9 @@ private:
/** Initialize the GSM-90 */
int
init
();
/** Set the cycle time */
int
set_cycle
(
double
freq
);
};
#endif
/* _DRIVER_OBS_GSM90_H */
src/Driver_Obs_Serial.cpp
View file @
9e85b0be
...
...
@@ -236,7 +236,7 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
// This has to be in loop as characters received at false baud rate
// 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
);
//fprintf(stderr," %d\n",valid_baudrates_size);
...
...
src/driver_obs_gsm.cpp
View file @
9e85b0be
...
...
@@ -169,10 +169,17 @@ int driver_obs_gsm::run(double freq_in) {
data
.
get_time
(
&
time_recv
);
// Calculate the delay
start_sec
=
freq
-
(
data
.
get_sec
()
%
freq
);
start_msec
=
1000
-
data
.
get_msec
();
if
(
start_msec
<
1000
)
{
start_sec
=
start_sec
-
1
;
if
(
freq
>
1
)
{
start_sec
=
freq
-
(
data
.
get_sec
()
%
freq
);
if
(
start_msec
<
1000
)
{
start_sec
=
start_sec
-
1
;
}
}
else
{
start_sec
=
0
;
}
if
(
start_msec
==
1000
)
{
start_msec
=
0
;
}
// Measurement time
...
...
src/driver_obs_gsm90.cpp
View file @
9e85b0be
...
...
@@ -64,70 +64,50 @@ driver_obs_gsm90::driver_obs_gsm90(std::string port, buffer_obs* buffer,
/****************************************************************************
*
* Take measurements in
freerun mod
e.
* Take measurements in
triggered mode. Trigger command is send by softwar
e.
*
***************************************************************************/
int
driver_obs_gsm90
::
freerun
(
double
freq
)
{
int
driver_obs_gsm90
::
run
(
double
freq
)
{
char
buf
[
1000
];
/////////////////////////////////////////////////////////////////////////
//
// Initialize
some variables.
// Initialize
: Set cycle period and external trigger
//
/////////////////////////////////////////////////////////////////////////
char
buf
[
100
];
char
*
cycle_s
;
double
cycle_f
;
// Set the cycle period
set_cycle
(
freq
);
// Set external trigger (software-based)
send
(
"g"
);
/////////////////////////////////////////////////////////////////////////
//
//
Try to set cycle time to requested frequency
//
Start freerun mode and freerun data acquisition.
//
/////////////////////////////////////////////////////////////////////////
// Decrease frequency
send
(
"D"
);
// Receive new frequency
receive
(
buf
,
sizeof
(
buf
),
0.2
);
int
pos
=
strcspn
(
buf
,
"s"
);
cycle_s
=
(
char
*
)
malloc
(
pos
+
1
);
strncpy
(
cycle_s
,
buf
,
pos
);
cycle_f
=
atof
(
cycle_s
);
// Start freerun mode
send
(
"R"
);
usleep
(
4e6
);
flush
();
// Check if we are above, below, or at the requested frequency
int
lowup
=
0
;
if
(
cycle_f
>
freq
)
{
lowup
=
1
;
}
else
if
(
cycle_f
<
freq
)
{
lowup
=
-
1
;
}
else
{
return
(
0
);
}
driver_obs_gsm
::
run
(
freq
);
// Increase/Decrease until just above/below the requested frequency
while
(
1
)
{
return
(
0
);
if
(
cycle_f
>
freq
)
{
if
(
lowup
<
0
)
break
;
send
(
"D"
);
}
else
if
(
cycle_f
<
freq
)
{
if
(
lowup
>
0
)
break
;
send
(
"U"
);
}
else
{
break
;
}
}
receive
(
buf
,
sizeof
(
buf
),
0.2
);
strncpy
(
cycle_s
,
buf
,
pos
);
cycle_f
=
atof
(
cycle_s
);
/****************************************************************************
*
* Take measurements in freerun mode.
*
***************************************************************************/
int
driver_obs_gsm90
::
freerun
(
double
freq
)
{
}
set_cycle
(
freq
);
/////////////////////////////////////////////////////////////////////////
//
...
...
@@ -162,6 +142,16 @@ int driver_obs_gsm90::init() {
char
buf
[
1000
];
/////////////////////////////////////////////////////////////////////////
//
// Stop any running measurement, also return to main menu in debug mode
//
/////////////////////////////////////////////////////////////////////////
send
(
"S"
);
usleep
(
5e6
);
flush
();
/////////////////////////////////////////////////////////////////////////
//
// Restore default settings
...
...
@@ -169,7 +159,7 @@ int driver_obs_gsm90::init() {
/////////////////////////////////////////////////////////////////////////
send
(
"&"
);
usleep
(
2e6
);
while
(
!
receive
(
buf
,
sizeof
(
buf
),
1
))
{}
flush
();
/////////////////////////////////////////////////////////////////////////
...
...
@@ -185,6 +175,7 @@ int driver_obs_gsm90::init() {
send
(
"Q"
);
receive
(
buf
,
sizeof
(
buf
),
1
);
fprintf
(
stderr
,
"Q: %s
\n
"
,
buf
);
}
...
...
@@ -215,3 +206,75 @@ int driver_obs_gsm90::init() {
}
/****************************************************************************
*
* Set the cycle time of the GSM-90.
*
***************************************************************************/
int
driver_obs_gsm90
::
set_cycle
(
double
freq
)
{
/////////////////////////////////////////////////////////////////////////
//
// Initialize some variables.
//
/////////////////////////////////////////////////////////////////////////
char
buf
[
100
];
char
*
cycle_s
;
double
cycle_f
;
/////////////////////////////////////////////////////////////////////////
//
// Try to set cycle time to requested frequency
//
/////////////////////////////////////////////////////////////////////////
// Decrease frequency
send
(
"D"
);
// Receive new frequency
receive
(
buf
,
sizeof
(
buf
),
0.2
);
int
pos
=
strcspn
(
buf
,
"s"
);
cycle_s
=
(
char
*
)
malloc
(
pos
+
1
);
strncpy
(
cycle_s
,
buf
,
pos
);
cycle_f
=
atof
(
cycle_s
);
// Check if we are above, below, or at the requested frequency
int
lowup
=
0
;
if
(
cycle_f
>
freq
)
{
lowup
=
1
;
}
else
if
(
cycle_f
<
freq
)
{
lowup
=
-
1
;
}
else
{
return
(
0
);
}
// Increase/Decrease until just above/below the requested frequency
while
(
1
)
{
if
(
cycle_f
>
freq
)
{
if
(
lowup
<
0
)
{
break
;
}
send
(
"D"
);
}
else
if
(
cycle_f
<
freq
)
{
if
(
lowup
>
0
)
{
break
;
}
send
(
"U"
);
}
else
{
break
;
}
receive
(
buf
,
sizeof
(
buf
),
0.2
);
strncpy
(
cycle_s
,
buf
,
pos
);
cycle_f
=
atof
(
cycle_s
);
}
return
(
0
);
}
src/driver_obs_obsdaq.cpp
View file @
9e85b0be
...
...
@@ -1061,6 +1061,15 @@ int driver_obs_obsdaq::init() {
filter_cmds
[
9
]
=
"92"
;
filter_cmds
[
10
]
=
"A1"
;
/////////////////////////////////////////////////////////////////////////
//
// Logging.
//
/////////////////////////////////////////////////////////////////////////
std
::
cerr
<<
"==== Initialized ObsDAQ with S/N "
<<
sn
<<
std
::
endl
;
return
(
0
);
}
...
...
usr/START
View file @
9e85b0be
...
...
@@ -9,20 +9,6 @@ PAR_FILE=/home/odaq/parameters.par
DIR_BIN
=
$DIR_BASE
\b
in
/
PATH
=
$PATH
:
$DIR_BIN
#MYPID=$$
#echo $MYPID > /home/odaq/pidfile
# Kill all subprocesses when parent dies
#trap 'echo "HELLO: TEST" > /home/odaq/TEST; killall Stream_Reader; killall OBSDAQ_Logger' SIGHUP SIGINT SIGQUIT SIGTERM SIGPIPE TERM EXIT SIGCHLD SIGTSTP SIGBUS SIGABRT SIGTAP SIGILL
function
killit
{
PIDs
=
$(
pgrep
-P
$MYPID
)
for
p
in
$PIDs
;
do
pkill
-P
$p
;
done
}
# Read parameters file
source
$PAR_FILE
...
...
@@ -30,17 +16,4 @@ source $PAR_FILE
mkdir
-p
$DIR_LOG
# Start data acquisition
{
trap
'kill 0'
EXIT
;
OBSDAQ_Logger
$PAR_FILE
2>
$DIR_LOG
/OBSDAQ.log
;
pkill
-g
0
;
}
|
{
trap
'kill 0'
EXIT
;
Stream_Reader
$PAR_FILE
;
pkill
-g
0
;
}
#(OBSDAQ_Logger $PAR_FILE 2> $DIR_LOG/OBSDAQ.log && pkill -g 0) | { Stream_Reader $PAR_FILE; pkill -g 0; }
#{ (OBSDAQ_Logger $PAR_FILE $DIR_LOG/OBSDAQ.log | Stream_Reader $PAR_FILE); pkill -P $MYPID; }
# Some attempts to kill all from child process
#PID=$!
#PIDs=$(pgrep -P $PID)
#PID_O=$(pidof OBSDAQ_Logger)
#PID_S=$(pidof Stream_Reader)
#echo "TEST: " $PIDs > /home/odaq/TEST
#wait $!
{
trap
'kill 0'
EXIT
;
OBSDAQ_Logger
$PAR_FILE
2>
$DIR_LOG
/OBSDAQ.log
;
pkill
-g
0
;
}
|
{
trap
'kill 0'
EXIT
;
Stream_Reader
$PAR_FILE
2>
$DIR_LOG
/Stream_Reader.log
;
pkill
-g
0
;
}
usr/par/parameters_default.par
View file @
9e85b0be
#########################
# Filenames and paths
#########################
# Path to logfiles
DIR_LOG=/home/odaq/log/
#------------------------
# Variometer
#------------------------
# Path to variometer recordings
DIR_VEC=/home/odaq/DATA/VAR/
# File format of 1Hz variometer data (see 'man strftime')
FILE_1Hz=MAG1_%Y%m%d.txt
# File format of variometer raw data, uncomment
# if raw data should not be written
#FILE_RAW=TEST_%Y%m%d.txt
#
#------------------------
# Scalar instrument
#------------------------
# Path to scalar recordings
DIR_SCA=/home/odaq/DATA/SCA/
# File format for scalar recordings
FILE_SCA=MAG1_%Y%m%d.txt
#########################
# ADC
#########################
# Baudrate for ObsDAQ
BAUD
=115
200 #19200
BAUD
_VEC=19
200 #19200
# PORT for ObsDAQ
PORT=/dev/ttyUSB
0
PORT
_VEC
=/dev/ttyUSB
1
# Send to address, (RS-485 uses 01), ObsDAQ FTDI)
ADDRESS=01
#ADDRESS=255
FILE_ADC_CONFIG=/home/mors/TMP/ADC.par
#########################
# Recording variometer
#########################
# Resistance of variometer
R=1.0
# Scale values of variometer
X_s=1.0
Y_s=1.0
Z_s=1.0
# Recording frequency
Freq=120
# Recording frequency [Hz]
FREQ_VEC=3
#########################
# Recording scalar
#########################
# Desired frequency of scalar recordings [s]
FREQ_SCA=1
usr/src/GSM_Logger.cpp
View file @
9e85b0be
...
...
@@ -8,22 +8,31 @@
// Custom C++ Headers
//
// Driver for GSM19
#include
<Parameters_Reader.hpp>
#include
<driver_obs_gsm90.hpp>
// Data buffer implemented as pipe on stdout/stdin
#include
<buffer_obs_pipe.hpp>
#include
<buffer_obs_file.hpp>
int
main
()
{
int
main
(
int
argc
,
char
*
argv
[]
)
{
// Read from parameters file
if
(
argc
!=
2
){
fprintf
(
stderr
,
"Please specify one parameter file to use !
\n
"
);
return
(
-
1
);
}
Parameters_Reader
par
=
Parameters_Reader
(
argv
[
1
]);
// Initialize new data buffer
buffer_obs_pipe
pipe
=
buffer_obs_pipe
();
//buffer_obs_pipe pipe = buffer_obs_pipe();
buffer_obs_file
pipe
=
buffer_obs_file
(
5
,
par
.
get_str
(
"DIR_SCA"
),
par
.
get_str
(
"FILE_SCA"
));
// Initialize new GSM90 device
// Initialize new GSM90 device
// Provide serial port and buffer as arguments
driver_obs_gsm90
gsm90
=
driver_obs_gsm90
(
"/dev/ttyUSB0"
,
&
pipe
);
driver_obs_gsm90
gsm90
=
driver_obs_gsm90
(
par
.
get_str
(
"PORT_SCA"
)
,
&
pipe
);
// Take continuous measurements
every 5s
// Take continuous measurements
fprintf
(
stderr
,
"Run
\n
"
);
gsm90
.
run
(
5
);
gsm90
.
run
(
par
.
get_int
(
"FREQ_SCA"
)
);
}
usr/src/OBSDAQ_Logger.cpp
View file @
9e85b0be
...
...
@@ -4,6 +4,11 @@
#include
<sched.h>
#include
<sys/resource.h>
#include
<sys/time.h>
<<<<<<<
HEAD
=======
#include
<ctime>
#include
<iomanip>
// put_time
>>>>>>>
master
//#include <thread>
//#include <vector>
...
...
@@ -22,15 +27,21 @@
int
main
(
int
argc
,
char
*
argv
[])
{
/*
// Write logging message
std
::
time_t
time
=
std
::
time
(
nullptr
);
fprintf
(
stderr
,
"=========================================
\n
"
);
fprintf
(
stderr
,
"# Logger restarted #
\n
"
);
std
::
cerr
<<
"#"
<<
std
::
put_time
(
std
::
gmtime
(
&
time
),
"%c %Z"
)
<<
"#"
<<
std
::
endl
;
fprintf
(
stderr
,
"=========================================
\n
"
);
// Try to schedule with realtime scheduler
struct
sched_param
sp
=
{
.
sched_priority
=
10
};
if
(
!
sched_setscheduler
(
0
,
SCHED_FIFO
,
&
sp
))
{
std
::
cerr
<<
"High priority FIFO scheduler FAILED for OBSDAQ_Logger."
<<
std
::
endl
;
sched_setscheduler(0,SCHED_BATCH,&sp)
sched_setscheduler
(
0
,
SCHED_BATCH
,
&
sp
)
;
setpriority
(
PRIO_PROCESS
,
0
,
-
20
);
}
*/
/*
std::string parfile;
...
...
@@ -62,7 +73,7 @@ int main(int argc, char* argv[]) {
// Add file buffer, if file_format is given
if
(
par
.
get_str
(
"FILE_RAW"
)
!=
""
)
{
mult
.
add
(
new
buffer_obs_file
(
5
,
par
.
get_str
(
"DIR_V
AR
"
),
mult
.
add
(
new
buffer_obs_file
(
5
,
par
.
get_str
(
"DIR_V
EC
"
),
par
.
get_str
(
"FILE_RAW"
)));
}
...
...
@@ -72,8 +83,8 @@ int main(int argc, char* argv[]) {
cal
.
set_adc_calibrate
(
par
.
get_str
(
"FILE_ADC_CONFIG"
));
// Initialize new OBSDAQ device
driver_obs_obsdaq
obsdaq
=
driver_obs_obsdaq
(
par
.
get_str
(
"PORT"
),
par
.
get_int
(
"BAUD"
),
&
mult
,
&
cal
,
par
.
get_int
(
"ADDRESS"
));
driver_obs_obsdaq
obsdaq
=
driver_obs_obsdaq
(
par
.
get_str
(
"PORT
_VEC
"
),
par
.
get_int
(
"BAUD
_VEC
"
),
&
mult
,
&
cal
,
par
.
get_int
(
"ADDRESS"
));
// Get some data
...
...
@@ -93,7 +104,7 @@ int main(int argc, char* argv[]) {
// Take continuous measurements
fprintf
(
stderr
,
"Run
\n
"
);
obsdaq
.
freerun
(
par
.
get_dbl
(
"F
req
"
));
obsdaq
.
freerun
(
par
.
get_dbl
(
"F
REQ_VEC
"
));
}
...
...
usr/src/Stream_Reader.cpp
View file @
9e85b0be
...
...
@@ -23,7 +23,7 @@ int main(int argc, char* argv[]) {
// Initialize new buffer
buffer_obs_pipe
buf_in
=
buffer_obs_pipe
();
buffer_obs_file
buf_out
=
buffer_obs_file
(
5
,
par
.
get_str
(
"DIR_V
AR
"
),
par
.
get_str
(
"FILE_
1Hz
"
));
par
.
get_str
(
"DIR_V
EC
"
),
par
.
get_str
(
"FILE_
VEC
"
));
// Initialize new filter
Filter_Obs
filter
=
Filter_Obs
();
...
...
Prev
1
2
3
4
5
6
Next
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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