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