From f99c37e6ddc49f9f0464cdad14be2b350402d463 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Wed, 14 Oct 2020 15:30:46 +0200 Subject: [PATCH] raweat.hpp: introduce error queue, find_markers: check for/consider corrupted markers --- lib/raweat.hpp | 74 ++++++++++++++++++++++++++++++++++++++------------ src/main.cpp | 2 +- 2 files changed, 58 insertions(+), 18 deletions(-) diff --git a/lib/raweat.hpp b/lib/raweat.hpp index 42637d4..b444924 100644 --- a/lib/raweat.hpp +++ b/lib/raweat.hpp @@ -71,6 +71,9 @@ private: // save all data, i.e. physical values of measured entities as 64bit double std::vector datmes_; + // error message queue + std::string error_queue_; + // check format validity bool valid_ = true; @@ -105,6 +108,9 @@ public: segments_.clear(); datmes_.clear(); + // reset error queue + error_queue_ = std::string(""); + // do setup and conversion //setup_and_conversion(showlog); } @@ -152,6 +158,11 @@ public: // check result if ( segments_.size() == 0 || datmes_.size() == 0 ) valid_ = false; } + else + { + // throw error with collected error messages + throw std::runtime_error(error_queue_); + } } // display buffer/data properties @@ -167,6 +178,8 @@ public: std::cout<<"\n"; for ( auto el: markers_ ) { + assert( el.second.size() > 0 && "please don't define any empty markers" ); + std::cout<> mrk : markers_ ) { - assert( mrk.second.size() > 0 && "please don't define any empty markers" ); - // find marker's byte sequence in buffer - for ( unsigned long int idx = 0; idx < rawdata_.size(); idx++ ) + for ( unsigned long int idx = 0; idx < (rawdata_.size() - mrk.second.size()); idx++ ) { // for every byte in buffer, check, if the three subsequent bytes // correspond to required predefined marker @@ -203,26 +214,51 @@ public: { // array of data associated to marker std::vector markseq; + int seqidx = 0; + // read any marker but the data marker if ( mrk.first != "datas marker" ) { - // collect bytes until we find semicolon ";", i.e. 0x3b - int seqidx = 0; + // collect bytes until we find a semicolon ";", i.e. 0x3b (or until buffer is depleted) while ( rawdata_[idx+seqidx] != 0x3b ) { markseq.push_back(rawdata_[idx+seqidx]); seqidx++; + + // if buffer is depleted before we find the proper termination of + // the markers, the data seems to be corrupted!! + if ( idx+seqidx == rawdata_.size()-1 ) + { + std::string errmess = mrk.first + std::string(" is corrupted"); + // throw std::runtime_error(errmess); + error_queue_ += errmess + std::string(" - "); + break; + } } } + // data marker is supposed to be located at the very end of the buffer + // but still be terminated by a semicolon (but may contain any number + // of semicolons in between) else { - // marker 'datas' is the data marker and is supposed to be the last - // and should extend until end of file - for ( unsigned long int didx = idx; didx < rawdata_.size()-1; didx++ ) + // collect data sequence (ignoring final semicolon) + while ( idx+seqidx < rawdata_.size()-1 ) { - markseq.push_back(rawdata_[didx]); + markseq.push_back(rawdata_[idx+seqidx]); + seqidx++; } + // check for terminating semicolon + if ( rawdata_.back() != 0x3b ) + { + std::string errmess = mrk.first + std::string(" is corrupted"); + error_queue_ += errmess + std::string(" - "); + } + } + + // find length of data sequence + if ( mrk.first == "datas marker" ) + { // obtain length of data segment datsize_ = markseq.size(); } @@ -240,13 +276,17 @@ public: if ( datasec_[mrk.first].size() == 0 ) { std::string errmess = mrk.first + std::string(" not found in buffer"); - // std::cerr< invalid! + valid_ = false; } totalmarksize += datasec_[mrk.first].size(); } @@ -254,7 +294,7 @@ public: // std::cout<<"\n"; // check validity of format - valid_ = ( totalmarksize < 100 ) ? false : true; + // valid_ = ( totalmarksize < 100 ) ? false : true; } // display content of found markers diff --git a/src/main.cpp b/src/main.cpp index 55a37c5..13ef599 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -72,7 +72,7 @@ int main(int argc, char* argv[]) // add channels eatmea.add_channel(rawfile,false); - // eatmea.add_channel("smp/VehicleSpeed_HS.raw",true); + eatmea.add_channel("smp/VehicleSpeed_HS.raw",false); // eatmea.add_channel("smp/Mercedes_E-Klasse-2019-08-08/Flex_StWhl_AnglSpd.raw",false); // eatmea.add_channel("smp/Rangerover_Evoque_F-RR534_2019-05-07/Temp_Disc_FR.raw",false);