Commit f36f0ce5 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

GSM90 fast reading triggered mode

parent 36c1a7cc
......@@ -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 */
......@@ -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
......
......@@ -64,70 +64,50 @@ driver_obs_gsm90::driver_obs_gsm90(std::string port, buffer_obs* buffer,
/****************************************************************************
*
* Take measurements in freerun mode.
* Take measurements in triggered mode. Trigger command is send by software.
*
***************************************************************************/
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);
}
#######################################################
# Configuration for GSM-90
#######################################################
# PORT for ObsDAQ
GSM90_PORT=/dev/ttyUSB0
# Recording period [s]
GSM90_PERIOD=1
#######################################################
# Configuration for variometer
#######################################################
# -----------------------------------------------------
# Configuration for ObsDAQ
# -----------------------------------------------------
# Baudrate for ObsDAQ
BAUD=115200 #19200
# PORT for ObsDAQ
PORT=/dev/ttyUSB0
# Recording frequency
Freq=120
# -----------------------------------------------------
# Scale values of 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
......@@ -12,18 +12,27 @@
#include <driver_obs_gsm90.hpp>
// Data buffer implemented as pipe on stdout/stdin
#include <buffer_obs_pipe.hpp>
#include <Parameters_Reader.hpp>
int main() {
int main(int argc, char* argv[]) {
// Initialize new data buffer
buffer_obs_pipe pipe = buffer_obs_pipe();
if (argc != 2) {
fprintf(stderr, "Please specify one parameter file to use !\n");
return (-1);
}
// Initialize new GSM90 device
// Read from parameters file
Parameters_Reader par = Parameters_Reader(argv[1]);
// Initialize new data buffer
buffer_obs_pipe pipe = buffer_obs_pipe();
// 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("GSM90_PORT"), &pipe);
// Take continuous measurements every 5s
printf("Run\n");
gsm90.run(5);
// Take continuous measurements every 5s
printf("Run\n");
gsm90.run(par.get_dbl("GSM90_PERIOD"));
}
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