diff --git a/eatit b/eatit index 9abd411..636f108 100755 Binary files a/eatit and b/eatit differ diff --git a/raw/VehicleSpeed_HS.asc b/sample/VehicleSpeed_HS.asc similarity index 100% rename from raw/VehicleSpeed_HS.asc rename to sample/VehicleSpeed_HS.asc diff --git a/raw/VehicleSpeed_HS.raw b/sample/VehicleSpeed_HS.raw similarity index 100% rename from raw/VehicleSpeed_HS.raw rename to sample/VehicleSpeed_HS.raw diff --git a/raw/pressure_Vacuum.asc b/sample/pressure_Vacuum.asc similarity index 100% rename from raw/pressure_Vacuum.asc rename to sample/pressure_Vacuum.asc diff --git a/raw/pressure_Vacuum.raw b/sample/pressure_Vacuum.raw similarity index 100% rename from raw/pressure_Vacuum.raw rename to sample/pressure_Vacuum.raw diff --git a/src/main.cpp b/src/main.cpp index 8a471ba..ac07bfc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -43,7 +43,8 @@ int main(int argc, char* argv[]) } // convert unsigned char data in buffer to desired data type - eatraw.convert_data_16_bit_float(); + eatraw.convert_data_16_bit_decimal(); + //eatraw.convert_data_16_bit_float(); //eatraw.convert_data_32_bit_float(); // get array of encoded data diff --git a/src/raweat.hpp b/src/raweat.hpp index cc34873..58f9f87 100644 --- a/src/raweat.hpp +++ b/src/raweat.hpp @@ -57,6 +57,8 @@ private: unsigned long int datsize_; // TODO preliminary: for now, we assume 32/64 bit ? floats in all data + // index in buffer of datasec_["datas marker"] where actual data starts + unsigned long int datstartidx_; std::vector datmes_; public: @@ -159,7 +161,24 @@ public: // obtain length of data segment datsize_ = markseq.size(); + + // find starting index (supposed to be after fourth comma = 0x2c) + int countcomma = 0; + for ( unsigned long int buidx = 0; buidx < datsize_; buidx++ ) + { + // count number of comma chars in head of data segment + if ( markseq[buidx] == 0x2c ) countcomma++; + + // save position following fourth comma + if ( countcomma == 4 ) + { + datstartidx_ = buidx + 1; + break; + } + } } + + // save segment corresponding to marker datasec_.insert(std::pair>(mrk.first,markseq)); } } @@ -268,16 +287,22 @@ public: // convert 16bit "decimal-encoding" floating point numbers void convert_data_16_bit_decimal() { - //assert ( (datsize_-29)%2 == 0 && "length of buffer is not a multiple of 2" ); + assert ( (datsize_-datstartidx_)%2 == 0 && "length of data is not a multiple of 2" ); - unsigned long int totnumby = (datsize_-30)/2; + double flstp = 0.04395; + + // parse bytes in data buffer + unsigned long int totnumby = (datsize_-datstartidx_)/2; for ( unsigned long int by = 0; by < totnumby; by++ ) { + // retrieve set of two subsequent bytes std::vector pnum; - for ( int i = 0; i < 2; i++ ) pnum.push_back(datasec_["datas marker"][(unsigned long int)(29+by*2+i)]); + for ( int i = 0; i < 2; i++ ) pnum.push_back(datasec_["datas marker"][(unsigned long int)(datstartidx_+by*2+i)]); - datmes_.push_back((double)( (((int)pnum[0]-128)*256 + (int)pnum[1])/100.0 )); - + // convert to double + //datmes_.push_back((double)( (((int)pnum[0]-128)*256 + (int)pnum[1])/100.0 )); + datmes_.push_back((double)( (((int)pnum[1]-128)*256. + (int)pnum[0])/100.0 )); + //datmes_.push_back( (double) ( ( (int)pnum[0] + (int)pnum[1]*256 )*flstp ) ); } }