Commit 7bcce616 authored by Achim Morschhauser's avatar Achim Morschhauser
Browse files

Formatting and suppl. data

parent db2237db
......@@ -765,110 +765,111 @@ int driver_obs_obsdaq::parse_data_ascii(data_obs_vector* data, char* buf) {
int driver_obs_obsdaq::parse_data_bin(data_obs_vector* data, char* buf) {
/////////////////////////////////////////////////////////////////////////
//
// Some variables.
//
/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//
// Some variables.
//
/////////////////////////////////////////////////////////////////////////
double n[5];
uint32_t n32, num;
double n[5];
uint32_t n32, num;
// Record length (is updated below)
unsigned char reclen=12;
// Record length (is updated below)
unsigned char reclen=12;
// Temporary variable
int tmp_d;
// Temporary variable
int tmp_d;
// Set data to missing
data->set_data_MD();
// Set data to missing
data->set_data_MD();
////////////////////////////////////////////////////////////////////////
// TODO Use for sampling rates higher than 10 Hz (else, suppl. data is
// not returned).
// OBSDAQ uses LittleEndian
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
// TODO Use for sampling rates higher than 10 Hz (else, suppl. data is
// not returned).
// OBSDAQ uses LittleEndian
////////////////////////////////////////////////////////////////////////
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;
return(-1);
}
////////////////////////////////////////////////////////////////////////
//
// Parse the binary data (Manual 12.5.2).
//
/////////////////////////////////////////////////////////////////////////
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 "
<< driver_obs::freq
<< " Hz." << std::endl;
return(-1);
}
//
// Some checks on data consistency are performed
//
////////////////////////////////////////////////////////////////////////
//
// Parse the binary data (Manual 12.5.2).
//
/////////////////////////////////////////////////////////////////////////
// Check for supplementary channels
if (buf[1] & (unsigned char) 64){
reclen = 14;
}
//
// Some checks on data consistency are performed
//
// Check 7th bits
for (int i=0; i<strlen(buf);i++){
if ((unsigned char) buf[i]<32 || (unsigned char) buf[i]>159){
fprintf(stderr,"Faulty data: 7th bit check failed for byte %d: %d.\n",
i,(unsigned char) buf[i]);
//fprintf(stderr,"%d %d %d %d %d %d %d %d\n",buf[i]&1,(buf[i]&2)/2,
// (buf[i]&4)/4,(buf[i]&8)/8,(buf[i]&16)/16,(buf[i]&32)/32,
// (buf[i]&64)/64,(buf[i]&128)/128);
// Check for supplementary channels
if (buf[1] & (unsigned char) 64){
reclen = 14;
}
return(-1);
}
}
// Check 7th bits
for (int i=0; i<strlen(buf);i++){
if ((unsigned char) buf[i]<32 || (unsigned char) buf[i]>159){
fprintf(stderr,"Faulty data: 7th bit check failed for byte %d: %d.\n",
i,(unsigned char) buf[i]);
//fprintf(stderr,"%d %d %d %d %d %d %d %d\n",buf[i]&1,(buf[i]&2)/2,
// (buf[i]&4)/4,(buf[i]&8)/8,(buf[i]&16)/16,(buf[i]&32)/32,
// (buf[i]&64)/64,(buf[i]&128)/128);
// Check checksum byte
tmp_d=0;
// Sum over N-1 data bytes
for (int i=0; i<reclen-1; i++){
tmp_d += buf[i];
}
// Last byte must contain sum of last (N-1) bytes in bits 0-6
if ( (tmp_d&127) != (buf[reclen-1]&127) ){
fprintf(stderr,"Faulty data: Control sum check failed for ");
for (int i=0; i<reclen-1;i++){
fprintf(stderr,"%d ",buf[i]);
}
fprintf(stderr,"and values %d %d %d.\n",
tmp_d,tmp_d&127,buf[reclen-1]);
return(-2);
}
return(-1);
}
}
// Check supplementary data
if (buf[1]&64){
if (buf[1]&1){
supp_count=1;
} else if (supp_count) {
supp_count+=1;
}
}
// Check checksum byte
tmp_d=0;
// Sum over N-1 data bytes
for (int i=0; i<reclen-1; i++){
tmp_d += buf[i];
}
// Last byte must contain sum of last (N-1) bytes in bits 0-6
if ( (tmp_d&127) != (buf[reclen-1]&127) ){
fprintf(stderr,"Faulty data: Control sum check failed for ");
for (int i=0; i<reclen-1;i++){
fprintf(stderr,"%d ",buf[i]);
}
fprintf(stderr,"and values %d %d %d.\n",
tmp_d,tmp_d&127,buf[reclen-1]);
return(-2);
}
//
// Extract data from channels 1-3
//
// Check supplementary data
if (buf[1]&64){
if (buf[1]&1){
supp_count=1;
} else if (supp_count) {
supp_count+=1;
}
}
num = (uint32_t) 0x800000L;
//
// Extract data from channels 1-3
//
num = (uint32_t) 0x800000L;
// Channel 1
n32 = ( ( (buf[2 ]&127) + ((buf[0]&32)<<2) ) <<16 )
+ ( ( (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]);
// Channel 1
n32 = ( ( (buf[2 ]&127) + ((buf[0]&32)<<2) ) <<16 )
+ ( ( (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]);
// 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]);
// 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]);
// Channel 3
n32 = ( ( (buf[8 ]&127) + ((buf[1]&32)<<2) ) <<16 )
......@@ -878,21 +879,23 @@ int driver_obs_obsdaq::parse_data_bin(data_obs_vector* data, char* buf) {
//printf("XYZ: %u %f\n",n32,n[3]);
//
// Extract data from supplementary channels
// Extract data from supplementary channels
//
num = (uint32_t) 0x8000;
num = (uint32_t) 0x8000;
if ((buf[1]&64) && supp_count >= 3 && supp_count <=4){
n32 = ( ( (buf[11 ]&127) + ((buf[0]&4 )<<5) ) <<8 )
+ ( ( (buf[12 ]&127) + ((buf[0]&2 )<<6) ) );
n[supp_count] = ((double) ((int32_t) ((n32 ^ num) - num))) / 8000.0;
}
/*
if ((buf[1]&64) && supp_count >= 3 && supp_count <=4){
n32 = ( ( (buf[11 ]&127) + ((buf[0]&4 )<<5) ) <<8 )
+ ( ( (buf[12 ]&127) + ((buf[0]&2 )<<6) ) );
n[supp_count] = ((double) ((int32_t) ((n32 ^ num) - num))) / 8000.0;
}
*/
// Save the data
data->set_data(n);
// Save the data
data->set_data(n);
return(0);
return(0);
}
......
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