Commit 60ae8b1c authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

stdout --> stderr, and START-script

parent a96c0a42
......@@ -91,7 +91,7 @@ int Driver_Obs_Serial::receive(char *buf, int buflen, double timeout,
********************************************************************************/
int Driver_Obs_Serial::send(const char* cmd) {
//printf("Send: %s\n",cmd);
//fprintf(stderr,"Send: %s\n",cmd);
return(serial.send(cmd));
......@@ -214,13 +214,13 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
// Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]);
//fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
serial.set_baud(valid_baudrates[i]);
usleep(100000);
for (int j = 0; j<init_chars_num-1; j++){
//printf("BAUD: %s\n",init_chars[j]);
//fprintf(stderr,"BAUD: %s\n",init_chars[j]);
send(init_chars[j]);
usleep(10000);
flush();
......@@ -232,14 +232,14 @@ int Driver_Obs_Serial::find_baud(char* init_chars[], int init_chars_num) {
break;
}
//printf("VB: %d",valid_baudrates_size);
//fprintf(stderr,"VB: %d",valid_baudrates_size);
// 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
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size);
//fprintf(stderr," %d\n",valid_baudrates_size);
}
......@@ -280,7 +280,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
// Try different baudrates
for (int i = 0; i < valid_baudrates_size; i++) {
//printf("---- Test baud rate: %7d ----\n", valid_baudrates[i]);
//fprintf(stderr,"---- Test baud rate: %7d ----\n", valid_baudrates[i]);
if (context->check_baud(valid_baudrates[i]) == 1) {
baud = valid_baudrates[i];
break;
......@@ -289,7 +289,7 @@ int Driver_Obs_Serial::find_baud(Driver_Obs_Serial* context,
somehow can corrupt the value in valid_baudrates_size (Buffer overrun
in driver_serial::receive */
serial.get_baudrates(&valid_baudrates, &valid_baudrates_size);
//printf(" %d\n",valid_baudrates_size);
//fprintf(stderr," %d\n",valid_baudrates_size);
}
// Check if baud rate could be determined
......
......@@ -83,9 +83,9 @@ int Obs_Calibration_Vector::calibrate(data_obs_vector* vdata){
vdata->get_data(data);
for (int i=0;i<3;i++){
//printf("SCALE: %f ",data[i]);
//fprintf(stderr,"SCALE: %f ",data[i]);
data[i]=data[i]*scale[i]+offset[i];
//printf("%f %f\n",data[i],scale[i]);
//fprintf(stderr,"%f %f\n",data[i],scale[i]);
}
vdata->set_data(data);
......@@ -305,7 +305,7 @@ int Obs_Calibration_Vector::add_adc_calibrate(std::string config,
}
file.close();
} else {
std::cout << "Unable to open file: " << filename << std::endl;
std::cerr << "Unable to open file: " << filename << std::endl;
}
......
......@@ -64,21 +64,33 @@ Parameters_Reader::Parameters_Reader(std::string filename) {
*******************************************************************************/
std::string Parameters_Reader::get_str(std::string key){
return parMap.at(key);
if (parMap.find(key) == parMap.end()){
return("");
} else {
return parMap.at(key);
}
}
int Parameters_Reader::get_int(std::string key){
return std::stoi(parMap.at(key));
if (parMap.find(key) == parMap.end()){
return(-1);
} else {
return std::stoi(parMap.at(key));
}
}
double Parameters_Reader::get_dbl(std::string key){
return std::stod(parMap.at(key));
if (parMap.find(key) == parMap.end()){
return(-1.0);
} else {
return std::stod(parMap.at(key));
}
}
......@@ -112,7 +124,7 @@ int Parameters_Reader::read(std::string filename){
}
file.close();
} else {
std::cout << "Unable to open file \n";
std::cerr << "Unable to open file \n";
}
return 0;
......
......@@ -40,7 +40,6 @@ buffer_obs_file::buffer_obs_file(int precision, std::string path,
// Set path
this->path = path;
std::cout << "PATH: " << path << std::endl;
// Set format
this->format = format;
......@@ -100,18 +99,7 @@ int buffer_obs_file::put(data_obs* data) {
********************************************************************************/
int buffer_obs_file::pop(data_obs* data) {
std::string input;
std::getline (std::cin,input);
/*std::cout << "STDIN: "
<< input
<< std::endl;
*/
data->parse(&input);
return(0);
return(-1);
}
......@@ -170,7 +158,6 @@ int buffer_obs_file::open(std::string filename) {
// Open new file
file.open(filename_full,std::ios::out | std::ios::app);
std::cout << "OPENING FILE FIRST TIME" << std::endl;
// Set filename
this->filename = filename;
......
......@@ -58,7 +58,7 @@ int buffer_obs_queue::put(data_obs* data) {
data->string(&string,5);
std::cout << "PUT_QUEUE: " << string << std::endl;
std::cerr << "PUT_QUEUE: " << string << std::endl;
return(0);
......@@ -72,7 +72,7 @@ int buffer_obs_queue::put(data_obs* data) {
********************************************************************************/
int buffer_obs_queue::pop(data_obs* data) {
std::cout << "POP1: " << data << " " << queue.size() << std::endl;
std::cerr << "POP1: " << data << " " << queue.size() << std::endl;
//data_obs* get;
......@@ -84,7 +84,7 @@ int buffer_obs_queue::pop(data_obs* data) {
//*data=*get;
std::cout << "POP2: " << data << std::endl;
std::cerr << "POP2: " << data << std::endl;
queue.pop();
......@@ -92,7 +92,7 @@ int buffer_obs_queue::pop(data_obs* data) {
data->string(&string,5);
std::cout << "POP_QUEUE: " << string << std::endl;
std::cerr << "POP_QUEUE: " << string << std::endl;
return(0);
......
......@@ -348,7 +348,7 @@ int driver_obs_obsdaq::freerun(double freq) {
// Receive data
if (receive(buf, sizeof(buf), 0, &recv_time) >= 0) {
//printf("Received: %s\n",buf);
//fprintf(stderr,"Received: %s\n",buf);
// Set the time
data.set_time(&recv_time);
......@@ -902,21 +902,21 @@ int driver_obs_obsdaq::parse_data_bin(data_obs_vector* data, char* buf) {
+ ( ( (buf[3 ]&127) + ((buf[0]&16)<<3) ) <<8 )
+ ( ( (buf[4 ]&127) + ((buf[0]&8 )<<4) ) );
n[0] = ((double) ((int32_t) ((n32 ^ num) - num))) * M;
//printf("XYZ: %u %u %f\n",buf[2]&127,n32,n[1]);
//fprintf(stderr,"XYZ: %u %u %f\n",buf[2]&127,n32,n[1]);
// Channel 2
n32 = ( ( (buf[5 ]&127) + ((buf[0]&4 )<<5) ) <<16 )
+ ( ( (buf[6 ]&127) + ((buf[0]&2 )<<6) ) <<8 )
+ ( ( (buf[7 ]&127) + ((buf[0]&1 )<<7) ) );
n[1] = ((double) ((int32_t) ((n32 ^ num) - num))) * M;
//printf("XYZ: %u %f\n",n32,n[2]);
//fprintf(stderr,"XYZ: %u %f\n",n32,n[2]);
// Channel 3
n32 = ( ( (buf[8 ]&127) + ((buf[1]&32)<<2) ) <<16 )
+ ( ( (buf[9 ]&127) + ((buf[1]&16)<<3)) <<8 )
+ ( ( (buf[10]&127) + ((buf[1]&8 )<<4)) );
n[2] = ((double) ((int32_t) ((n32 ^ num) - num))) * M;
//printf("XYZ: %u %f\n",n32,n[3]);
//fprintf(stderr,"XYZ: %u %f\n",n32,n[3]);
//
// Extract data from supplementary channels
......@@ -1160,7 +1160,7 @@ int driver_obs_obsdaq::init_run(double freq){
checked_send(cmd,adc_offset.c_str(),6,4);
}
//printf("============ GOT: %06X %06X\n",adc_offset,adc_scale);
//fprintf(stderr,"============ GOT: %06X %06X\n",adc_offset,adc_scale);
}
......@@ -1187,7 +1187,7 @@ int driver_obs_obsdaq::init_run(double freq){
M = 40.0 / 4.0 / (double) 0x800000;
//printf("M: %f\n",M);
//fprintf(stderr,"M: %f\n",M);
return(0);
......
......@@ -684,7 +684,7 @@ int driver_serial::init() {
// transmit raw data- REMOVED as it overwrites VMIN and VTIME
if ((fd = open((char *) port.c_str(), O_RDWR | O_NOCTTY)) < 0) {
std::cout << "Couldn't open serial port " << port << std::endl;
std::cerr << "Couldn't open serial port " << port << std::endl;
return (-1);
}
......@@ -703,7 +703,7 @@ int driver_serial::init() {
//
if (tcgetattr(fd, &tio) < 0) {
std::cout << "Could not get confiuration of serial port " << port
std::cerr << "Could not get confiuration of serial port " << port
<< std::endl;
return (-1);
}
......
......@@ -119,14 +119,14 @@ driver_serial::driver_serial(std::string port, int baud){
driver_serial::driver_serial(std::string port, const char* term, int termlen){
printf("SERIAL CONSTRUCT\n");
fprintf(stderr,"SERIAL CONSTRUCT\n");
this->port = port;
init();
set_term(term, termlen);
printf("T: %s \n",this->term);
fprintf(stderr,"T: %s \n",this->term);
}
......@@ -174,7 +174,7 @@ int driver_serial::receive(char *buf, int buflen,
* GEMSystems GSM
*/
//printf("TEST: %s\n",sent);
//fprintf(stderr,"TEST: %s\n",sent);
// Date
if ((strcmp(sent, "D")==0) || (strcmp(sent, "d")==0)) {
......@@ -236,16 +236,16 @@ int driver_serial::receive(char *buf, int buflen,
// Continuous run
} else if (strncmp(sent, "#01CS",4)==0) {
strcpy(buf,">FF4AF1010B9500414736810DE05C1D5BF5000A");
usleep(300e3);
usleep(3e3);
// Channel values
} else if (strncmp(sent, "#01A",4)==0) {
printf("RECEIVED!\n");
fprintf(stderr,"RECEIVED!\n");
strcpy(buf,">FF4AF1010B9500414736810DE05C1D5BF5000A");
// No Response
} else {
printf("Warning: Timeout. No response received\n");
fprintf(stderr,"Warning: Timeout. No response received\n");
return(-1);
}
......@@ -296,7 +296,7 @@ int driver_serial::send(char *cmd){
strcpy(sent,cmd);
printf("SEND: %s\n",sent);
fprintf(stderr,"SEND: %s\n",sent);
return(0);
......@@ -394,7 +394,7 @@ int driver_serial::set_baud(int baud){
/* Check if set_serial was already called */
if (valid_baudrates_size == 0){
printf("Set serial must be called first\n");
fprintf(stderr,"Set serial must be called first\n");
return(-1);
}
......@@ -404,17 +404,17 @@ int driver_serial::set_baud(int baud){
i++;
}
if (i==valid_baudrates_size) {
printf("Invalid baudrate specified: %d\n",baud);
printf("Valid baudrates are: %d",valid_baudrates[0]);
fprintf(stderr,"Invalid baudrate specified: %d\n",baud);
fprintf(stderr,"Valid baudrates are: %d",valid_baudrates[0]);
for (int i=1;i<valid_baudrates_size;i++){
printf(", %d",valid_baudrates[i]);
fprintf(stderr,", %d",valid_baudrates[i]);
}
printf("\n");
fprintf(stderr,"\n");
return(-1);
}
printf("Baud rate set to: %d\n",baud);
fprintf(stderr,"Baud rate set to: %d\n",baud);
return(0);
......
#!/bin/bash
BIN_DIR=./bin/
USR_DIR=/home/odaq/Data_FTP
# Paramters file
PAR_FILE=./usr/par/parameters.par
# Directory with executables
DIR_BIN=./bin/
PATH=$PATH:$DIR_BIN
LOG_DIR=$USR_DIR/log/
DAT_DIR=$USR_DIR/data/
PAR_DIR=./usr/par/parameters_
# Read parameters file
source $PAR_FILE
mounted=$(cat /etc/mtab | grep $USR_DIR)
# Check if remote directoy is mounted,
# and mount if necessry
mounted=$(cat /etc/mtab | grep $DIR_VAR)
if [ -z "$mounted" ]; then
mount $USR_DIR
mount $DIR_VAR
fi
mkdir -p $LOG_DIR
mkdir -p $DAT_DIR
# Create logging directory
mkdir -p $DIR_LOG
$BIN_DIR/OBSDAQ_Logger $PAR_DIR$1\.par 2> $LOG_DIR/OBSDAQ_$1.log | tee $DAT_DIR/OBSDAQ_$1.dat | $BIN_DIR/Stream_Reader > $DAT_DIR/OBSDAQ_FILTER_$1.dat
# Start data acquisition
OBSDAQ_Logger $PAR_FILE 2> $DIR_LOG/OBSDAQ.log | Stream_Reader $PAR_FILE
......@@ -2,6 +2,12 @@
BAUD=115200 #19200
# PORT for ObsDAQ
PORT=/dev/ttyUSB0
# Send to address, (RS-485 uses 01), ObsDAQ FTDI)
ADDRESS=01
#ADDRESS=255
# Resistance of variometer
R=1.0
# Scale values of variometer
......
......@@ -23,7 +23,7 @@ int main() {
driver_obs_gsm90 gsm90 = driver_obs_gsm90("/dev/ttyUSB0", &pipe);
// Take continuous measurements every 5s
printf("Run\n");
fprintf(stderr,"Run\n");
gsm90.run(5);
}
......@@ -19,20 +19,20 @@
int main(int argc, char* argv[]) {
/*
std::string parfile;
/*
std::string parfile;
switch (argc) {
case 1: parfile="/usr/par/parameters.par"; break;
case 2: parfile=argv[1]; break;
default: fprintf(stderr,"Please specify one parameter file to use !\n"); return(-1);
}
*/
switch (argc) {
case 1: parfile="/usr/par/parameters.par"; break;
case 2: parfile=argv[1]; break;
default: fprintf(stderr,"Please specify one parameter file to use !\n"); return(-1);
}
*/
if (argc != 2){
fprintf(stderr,"Please specify one parameter file to use !\n");
return(-1);
}
if (argc != 2){
fprintf(stderr,"Please specify one parameter file to use !\n");
return(-1);
}
// Read from parameters file
Parameters_Reader par = Parameters_Reader(argv[1]);
......@@ -45,10 +45,14 @@ int main(int argc, char* argv[]) {
double Y_s = par.get_dbl("Y_s");
double Z_s = par.get_dbl("Z_s");
// Initialize output buffers
// Add standard pipe buffer to multi buffer
buffer_obs_mult mult = new buffer_obs_mult(new buffer_obs_pipe(5));
mult.add(new buffer_obs_file(5,par.get_str("PATH"),
par.get_str("FORMAT_1Hz")));
// 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_VAR"),
par.get_str("FILE_RAW")));
}
// Initialize the calibration constants for FGE
Obs_Calibration_Vector cal = Obs_Calibration_Vector(X_s/R,Y_s/R,Z_s/R);
......@@ -65,11 +69,11 @@ int main(int argc, char* argv[]) {
data_obs_vector data=data_obs_vector();
printf("First try\n");
fprintf(stderr,"First try\n");
obsdaq.get(&data);
pipe.put(&data);
printf("Second try\n");
fprintf(stderr,"Second try\n");
obsdaq.get(&data);
pipe.put(&data);
......
......@@ -18,14 +18,14 @@ int main(){
char buf[500];
std::cout << "BAUD: ";
std::cerr << "BAUD: ";
std::cin >> baud;
driver_serial serial = driver_serial("/dev/ttyUSB0",term,1,baud);
while (1){
std::cout << "CMD: ";
std::cerr << "CMD: ";
std::cin >> cmd;
//if (cmd.compare("QUIT")){
......@@ -38,7 +38,7 @@ int main(){
serial.receive(buf,sizeof(buf),5);
std::cout << buf << std::endl;
std::cerr << buf << std::endl;
/*
// Extract data from channels 1-3
......@@ -52,21 +52,21 @@ int main(){
+ ( (uint32_t) ( (buf[3 ]&127) + ((buf[0]&16)<<3)) )<<8
+ ( (uint32_t) ( (buf[4 ]&127) + ((buf[0]&8 )<<4)) );
n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
printf("XYZ: %u %f\n",n32,n);
fprintf(stderr,"XYZ: %u %f\n",n32,n);
// Channel 2
n32 = ( (uint32_t) ( (buf[5 ]&127) + ((buf[0]&4 )<<5)) )<<16
+ ( (uint32_t) ( (buf[6 ]&127) + ((buf[0]&2 )<<6)) )<<8
+ ( (uint32_t) ( (buf[7 ]&127) + ((buf[0]&1 )<<7)) );
n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
printf("XYZ: %u %f\n",n32,n);
fprintf(stderr,"XYZ: %u %f\n",n32,n);
// Channel 3
n32 = ((buf[8 ]&127) + ((buf[1]&32)<<2))<<16
+ ((buf[9 ]&127) + ((buf[1]&16)<<3))<<8
+ ((buf[10]&127) + ((buf[1]&8 )<<4));
n = (double) ((int32_t) ((n32 ^ num) - num)) * M;
printf("XYZ: %u %f\n",n32,n);
fprintf(stderr,"XYZ: %u %f\n",n32,n);
*/
}
......
......@@ -6,18 +6,29 @@
#include <Filter_Obs.hpp>
#include <driver_obs_obsdaq.hpp>
#include <buffer_obs_pipe.hpp>
#include <buffer_obs_file.hpp>
#include <Parameters_Reader.hpp>
int main() {
int main(int argc, char* argv[]) {
// Initialize new buffer
buffer_obs_pipe pipe_in = buffer_obs_pipe();
buffer_obs_pipe pipe_out = buffer_obs_pipe(5);
if (argc != 2){
fprintf(stderr,"Please specify one parameter file to use !\n");
return(-1);
}
// Initialize new filter
Filter_Obs filter = Filter_Obs();
// Read from parameters file
Parameters_Reader par = Parameters_Reader(argv[1]);
// Initialize new buffer
buffer_obs_pipe buf_in = buffer_obs_pipe();
buffer_obs_file buf_out = buffer_obs_file(5,
par.get_str("DIR_VAR"),par.get_str("FILE_1Hz"));
// Apply PLASMON filter
filter.lowpass_PLASMON_1Hz(&pipe_in,&pipe_out,128);
// Initialize new filter
Filter_Obs filter = Filter_Obs();
// Apply PLASMON filter
filter.lowpass_PLASMON_1Hz(&buf_in,&buf_out,128);
}
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