Commit 562ddd93 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Merge branch 'fix_segfault_r' into testrasp

parents 12da76b5 ba053dae
......@@ -118,16 +118,19 @@ int data_obs::set_time(int year, int mon, int day, int hour, int min, int sec,
********************************************************************************/
int data_obs::set_time(struct timespec* time) {
struct tm* tm;
gmtime_r(&time->tv_sec,tm);
year = tm->tm_year + 1900;
mon = tm->tm_mon + 1;
day = tm->tm_mday;
hour = tm->tm_hour;
min = tm->tm_min;
sec = tm->tm_sec;
// Initialize tm
//TODO Make t a class-variable to avoid repeated allocation
struct tm t = {0};
// Use gmtime_r for thread-safety
gmtime_r(&time->tv_sec,&t);
year = t.tm_year + 1900;
mon = t.tm_mon + 1;
day = t.tm_mday;
hour = t.tm_hour;
min = t.tm_min;
sec = t.tm_sec;
msec = (int) (time->tv_nsec / 1e6);
return (0);
......
......@@ -101,7 +101,7 @@ driver_obs_obsdaq::driver_obs_obsdaq(std::string port, int baud,
RS485_addrstr = std::string(addr_str);
/* In development
// Check if requested baud rate is already set
if ( check_baud(baud) != 1){
......@@ -112,6 +112,10 @@ driver_obs_obsdaq::driver_obs_obsdaq(std::string port, int baud,
// Set baud rate
set_baud(baud);
// Set the ObsDAQ baud rate
// Stop the measurement
stop();
}
*/
......@@ -323,7 +327,7 @@ int driver_obs_obsdaq::freerun(double freq) {
usleep(1e6);
flush();
if (freq < 10.0){
if (driver_obs::freq < 10.0){
// Use ASCII mode
checked_send("#CS","",0,1);
parse_data = &driver_obs_obsdaq::parse_data_ascii;
......@@ -450,7 +454,7 @@ int driver_obs_obsdaq::auto_calibrate(int channel, int repeat){
// Check if calibration is finished
sprintf(cmd,"$%1dRR",channel);
usleep(4.0/freq*1e6);
usleep(4.0/driver_obs::freq*1e6);
while (checked_send(cmd,"R0",2,5)<0){
}
......@@ -789,7 +793,7 @@ int driver_obs_obsdaq::parse_data_bin(data_obs_vector* data, char* buf) {
// OBSDAQ uses LittleEndian
////////////////////////////////////////////////////////////////////////
if (freq < 10.0){
if (driver_obs::freq < 10.0){
std::cerr << "ERROR: Binary mode not available for sampling rate "
<< "of lower than 10 Hz. Current sampling rate is " << freq
<< " Hz." << std::endl;
......@@ -1028,7 +1032,13 @@ int driver_obs_obsdaq::init_run(double freq){
//
/////////////////////////////////////////////////////////////////////
// Find the closest possible valid frequency.
// Set triggering off
//TODO Check if necessary here
send("#PP00000000");
usleep(1e6);
// Find the closest possible valid frequency larger or equal to
// the one requested.
for (int i=0; i<valid_filter_rates_num; i++){
if (valid_filter_rates[i]>=freq){
freq_sel = i;
......@@ -1048,7 +1058,7 @@ int driver_obs_obsdaq::init_run(double freq){
// Print used and requested frequency
fprintf(stderr,"Frequency set to: %6.2f Hz. "
"Requested frequency: %6.2f Hz.\n",
valid_filter_rates[freq_sel],freq);
driver_obs::freq,freq);
/////////////////////////////////////////////////////////////////////////
//
......@@ -1056,7 +1066,6 @@ int driver_obs_obsdaq::init_run(double freq){
//
/////////////////////////////////////////////////////////////////////////
// Iterate over all three channels
for (int i=0; i<3; i++){
......@@ -1106,7 +1115,6 @@ int driver_obs_obsdaq::init_run(double freq){
// Set the conversion parameters
//FULLSCALE=42.5; // Self-Gain calibration
//FULLSCALE=40.0; // System-Gain calibration
//GAIN=4.0; // +/- 10V range
//GAIN=8.0; // +/- 5V range
......
......@@ -32,7 +32,6 @@ int main() {
// Initialize the calibration constants
Obs_Calibration_Vector cal = Obs_Calibration_Vector(X_s/R,Y_s/R,Z_s/R);
// Initialize new OBSDAQ device
driver_obs_obsdaq obsdaq = driver_obs_obsdaq(par.get_str("PORT"),
par.get_int("BAUD"), &pipe, &cal, 1);
......@@ -55,7 +54,7 @@ int main() {
// Take continuous measurements
fprintf(stderr,"Run\n");
obsdaq.freerun(100);
obsdaq.freerun(par.get_dbl("Freq"));
}
......
# Baudrate for ObsDAQ
BAUD=38400 #19200 (Default)
# PORT for ObsDAQ
PORT=/dev/ttyUSB1
PORT=/dev/ttyUSB0
# 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=100
Supports Markdown
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