Commit 1188d60c authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Merge remote

parents a13875a2 af67ce1d
......@@ -75,6 +75,7 @@ public:
int get_adc_calibrate(std::string config, std::string &offset,
std::string &scale);
/** Add a calibration constant for the ADC */
int add_adc_calibrate(std::string config, std::string offset,
std::string scale);
......
......@@ -47,6 +47,9 @@ std::string RS485_addrstr; // Used for commands to ObsDAQ
/** The quartz crystal frequency */
int quartz_freq;
/** The serial number */
std::string sn;
/** The conversion constant */
//TODO Should be an array of three!
double M;
......@@ -110,6 +113,9 @@ int stop();
/** Automatically calibrate the ObsDAQ */
int auto_calibrate(int channel, int repeat);
/** Manually calibrate the ObsDAQ */
int full_calibrate(int channel, int repeat);
//
// Protected Methods
//
......
......@@ -403,17 +403,16 @@ int driver_obs_obsdaq::stop() {
}
/****************************************************************************
* *
* Auto-calibrate. *
* *
* Channels are auto-calibrated based on actual channel settings. *
* Calibration is not stored. *
* *
* IN: *
* - repeat int Number of calibration steps. *
* Individual calibration steps are *
* averaged. *
* *
*
* Auto-calibrate.
*
* Channels are auto-calibrated based on actual channel settings.
* Calibration is not stored.
*
* IN:
* - repeat int Number of calibration steps.
* Individual calibration steps are averaged.
*
***************************************************************************/
int driver_obs_obsdaq::auto_calibrate(int channel, int repeat){
......@@ -423,7 +422,7 @@ int driver_obs_obsdaq::auto_calibrate(int channel, int repeat){
//
/////////////////////////////////////////////////////////////////////////
char cmd[50], recv[50];
char cmd[50], recv[50]="";
uint32_t n32, num;
......@@ -520,6 +519,24 @@ int driver_obs_obsdaq::auto_calibrate(int channel, int repeat){
}
/***************************************************************************
*
* Auto-calibrate.
*
* Channels are auto-calibrated based on actual channel settings.
* Calibration is not stored.
*
* IN:
* - repeat int Number of calibration steps.
* Individual calibration steps are averaged.
*
***************************************************************************/
int driver_obs_obsdaq::full_calibrate(int channel, int repeat){
return(0);
}
/****************************************************************************
****************************************************************************
* *
......@@ -629,71 +646,63 @@ int driver_obs_obsdaq::checked_send(const char* cmd, const char* reply,
flush();
/////////////////////////////////////////////////////////////////////////
//
// Initialize some variables.
//
/////////////////////////////////////////////////////////////////////////
char buf[1000]="";
std::string strbuf;
std::string expected;
/////////////////////////////////////////////////////////////////////////
//
// Send command and check answer.
//
/////////////////////////////////////////////////////////////////////////
// Send the command
send(cmd);
// Wait for an answer
if (receive(buf, sizeof(buf), timeout) < 0) {
if (verbose) {
fprintf(stderr,"Reply not received for cmd: %s\n",cmd);
}
return (-1);
}
strbuf=std::string(buf);
// Construct expected answer
expected = "!" + RS485_addrstr + reply;
// Check address part of answer
if ((expected.compare(1, 2, &buf[1], 2) != 0)
&& (RS485_addr != 0x0F)){
if (verbose) {
std::cerr << "Wrong address received." << " Expected: "
<< expected.substr(1, 2) << " Received: " << &buf[1]
<< std::endl;
}
return (-2);
}
/////////////////////////////////////////////////////////////////////////
//
// Initialize some variables.
//
/////////////////////////////////////////////////////////////////////////
// Check response part of answer
if ((expected.compare(3, digits, &buf[3], digits) != 0)) {
if (verbose) {
char buf[1000]="";
std::string strbuf;
std::string expected;
std::cerr << "Wrong answer received." << " Expected: "
<< expected.substr(3, digits) << " Received: "
<< strbuf.substr(3, digits) << std::endl;
/////////////////////////////////////////////////////////////////////////
//
// Send command and check answer.
//
/////////////////////////////////////////////////////////////////////////
}
// Send the command
send(cmd);
return (-3);
// Wait for an answer
if (receive(buf, sizeof(buf), timeout) < 0) {
if (verbose) {
fprintf(stderr,"Reply not received for cmd: %s\n",cmd);
}
return (-1);
}
strbuf=std::string(buf);
// Construct expected answer
expected = "!" + RS485_addrstr + reply;
// Check address part of answer
if ((expected.compare(1, 2, &buf[1], 2) != 0)
&& (RS485_addr != 0x0F)){
if (verbose) {
std::cerr << "Wrong address received." << " Expected: "
<< expected.substr(1, 2) << " Received: " << &buf[1]
<< std::endl;
}
return (-2);
}
}
// Check response part of answer
if ((expected.compare(3, digits, &buf[3], digits) != 0)) {
if (verbose) {
std::cerr << "Wrong answer received." << " Expected: "
<< expected.substr(3, digits) << " Received: "
<< strbuf.substr(3, digits) << std::endl;
}
return (-3);
}
// Return response
*recv = &buf[3 + digits];
// Return response
*recv = &buf[3 + digits];
return (0);
return (0);
}
......@@ -920,6 +929,8 @@ int driver_obs_obsdaq::parse_data_bin(data_obs_vector* data, char* buf) {
***************************************************************************/
int driver_obs_obsdaq::init() {
std::string recv;
/////////////////////////////////////////////////////////////////////////
//
// Stop running data acquisition.
......@@ -938,14 +949,21 @@ int driver_obs_obsdaq::init() {
send("#PP00000000");
usleep(2e6);
/////////////////////////////////////////////////////////////////////////
//
// Get the serial number
//
/////////////////////////////////////////////////////////////////////////
checked_send("$SN", "SN", 2, 1, &recv);
sn = recv;
/////////////////////////////////////////////////////////////////////////
//
// Get the quartz crystal frequency.
//
/////////////////////////////////////////////////////////////////////////
std::string recv;
checked_send("$QF", "R", 1, 1, &recv);
std::cerr << "Received: " << recv << std::endl;
......@@ -1029,7 +1047,7 @@ int driver_obs_obsdaq::init() {
int driver_obs_obsdaq::init_run(double freq){
// The receive buffer
char buf[200]="";
std::string recv="";
// A command to send
char cmd[20];
// Index of the selected frequency
......@@ -1081,30 +1099,28 @@ int driver_obs_obsdaq::init_run(double freq){
// Iterate over all three channels
for (int i=0; i<3; i++){
// Get current 24-bit configuration (Manual 12.4.9)
sprintf(cmd,"$%1dRS",i);
send(cmd);
receive(buf,sizeof(buf),1);
fprintf(stderr,"REC_CONFIG: %s\n",buf);
checked_send(cmd,"02",2,1,&recv);
std::cout << "REC CONFIG: " << recv << std::endl;
// Get the last four bytes ("ccdd") and add channel number
config= (i<<16) + strtoul(&buf[7],NULL,16);
config= sn + "/" + recv.substr(2,4) + "/" + std::to_string(i);
fprintf(stderr,"----- CONFIG: %s\n",config.c_str());
// Check if calibration for the given config
// was pre-determined
if (driver_obs::cal->get_adc_calibrate
(config, adc_offset, adc_scale)<0){
// Automatic Calibration
auto_calibrate(i,1);
} else {
// Set the pre-determined calibration constant
sprintf(cmd,"$%1dWO%06X",i,adc_offset);
sprintf(cmd,"$%1dWO%s",i,adc_offset.c_str());
send(cmd); waitanswer(5);
sprintf(cmd,"$%1dWF%06X",i,adc_scale);
sprintf(cmd,"$%1dWF%s",i,adc_scale.c_str());
send(cmd); waitanswer(5);
}
......
# S/N, config (ccdd), channel, scale, offset
# config (serialnumber/ccdd/channel),scale,offset
# Tatuoca
OD-550C0001/0203/1,3AEC9C,00028E
......
#include <iostream>
#include <string.h>
#include <inttypes.h>
#include <stdio.h>
#include <driver_obs_obsdaq.hpp>
#include <Obs_Calibration_Vector.hpp>
#include <Parameters_Reader.hpp>
#include <buffer_obs_pipe.hpp>
int main(){
// Create calibration vector
Obs_Calibration_Vector cal = Obs_Calibration_Vector();
// Read from parameters file
Parameters_Reader par = Parameters_Reader("usr/parameters.par");
// Initialize new buffer for STDOUT
//TODO Replace by null buffer (discard everything)
buffer_obs_pipe pipe = buffer_obs_pipe(5);
// Initialize new OBSDAQ device
driver_obs_obsdaq obsdaq = driver_obs_obsdaq(par.get_str("PORT"),
par.get_int("BAUD"), &pipe, &cal, 1);
std::string cmd;
int baud;
char term[1];
term[0]=13;
char buf[500];
std::cout << "BAUD: ";
std::cin >> baud;
driver_serial serial = driver_serial("/dev/ttyUSB0",term,1,baud);
while (1){
std::cout << "CMD: ";
std::cin >> cmd;
//if (cmd.compare("QUIT")){
// break;
//}
cmd=cmd+(char) 13;
serial.send((const char*) cmd.c_str());
serial.receive(buf,sizeof(buf),5);
std::cout << buf << std::endl;
/*
// Extract data from channels 1-3
uint32_t num = (uint32_t) 0x800000L;
uint32_t n32;
double n;
double M = 42.5 / 4 / (double) 0x800000;
// Channel 1
n32 = ( (uint32_t) ( (buf[2 ]&127) + ((buf[0]&32)<<2)) )<<16
+ ( (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);
// 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);
// 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);
*/
}
}
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