raweat.hpp: introduce error queue, find_markers: check for/consider corrupted markers
This commit is contained in:
parent
043784d278
commit
f99c37e6dd
@ -71,6 +71,9 @@ private:
|
|||||||
// save all data, i.e. physical values of measured entities as 64bit double
|
// save all data, i.e. physical values of measured entities as 64bit double
|
||||||
std::vector<double> datmes_;
|
std::vector<double> datmes_;
|
||||||
|
|
||||||
|
// error message queue
|
||||||
|
std::string error_queue_;
|
||||||
|
|
||||||
// check format validity
|
// check format validity
|
||||||
bool valid_ = true;
|
bool valid_ = true;
|
||||||
|
|
||||||
@ -105,6 +108,9 @@ public:
|
|||||||
segments_.clear();
|
segments_.clear();
|
||||||
datmes_.clear();
|
datmes_.clear();
|
||||||
|
|
||||||
|
// reset error queue
|
||||||
|
error_queue_ = std::string("");
|
||||||
|
|
||||||
// do setup and conversion
|
// do setup and conversion
|
||||||
//setup_and_conversion(showlog);
|
//setup_and_conversion(showlog);
|
||||||
}
|
}
|
||||||
@ -152,6 +158,11 @@ public:
|
|||||||
// check result
|
// check result
|
||||||
if ( segments_.size() == 0 || datmes_.size() == 0 ) valid_ = false;
|
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
|
// display buffer/data properties
|
||||||
@ -167,6 +178,8 @@ public:
|
|||||||
std::cout<<"\n";
|
std::cout<<"\n";
|
||||||
for ( auto el: markers_ )
|
for ( auto el: markers_ )
|
||||||
{
|
{
|
||||||
|
assert( el.second.size() > 0 && "please don't define any empty markers" );
|
||||||
|
|
||||||
std::cout<<el.first<<" ";
|
std::cout<<el.first<<" ";
|
||||||
for ( unsigned char c: el.second) std::cout<<std::hex<<int(c);
|
for ( unsigned char c: el.second) std::cout<<std::hex<<int(c);
|
||||||
std::cout<<"\n";
|
std::cout<<"\n";
|
||||||
@ -185,10 +198,8 @@ public:
|
|||||||
|
|
||||||
for (std::pair<std::string,std::vector<unsigned char>> mrk : markers_ )
|
for (std::pair<std::string,std::vector<unsigned char>> mrk : markers_ )
|
||||||
{
|
{
|
||||||
assert( mrk.second.size() > 0 && "please don't define any empty markers" );
|
|
||||||
|
|
||||||
// find marker's byte sequence in buffer
|
// 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
|
// for every byte in buffer, check, if the three subsequent bytes
|
||||||
// correspond to required predefined marker
|
// correspond to required predefined marker
|
||||||
@ -203,26 +214,51 @@ public:
|
|||||||
{
|
{
|
||||||
// array of data associated to marker
|
// array of data associated to marker
|
||||||
std::vector<unsigned char> markseq;
|
std::vector<unsigned char> markseq;
|
||||||
|
int seqidx = 0;
|
||||||
|
|
||||||
|
// read any marker but the data marker
|
||||||
if ( mrk.first != "datas marker" )
|
if ( mrk.first != "datas marker" )
|
||||||
{
|
{
|
||||||
// collect bytes until we find semicolon ";", i.e. 0x3b
|
// collect bytes until we find a semicolon ";", i.e. 0x3b (or until buffer is depleted)
|
||||||
int seqidx = 0;
|
|
||||||
while ( rawdata_[idx+seqidx] != 0x3b )
|
while ( rawdata_[idx+seqidx] != 0x3b )
|
||||||
{
|
{
|
||||||
markseq.push_back(rawdata_[idx+seqidx]);
|
markseq.push_back(rawdata_[idx+seqidx]);
|
||||||
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
|
else
|
||||||
{
|
{
|
||||||
// marker 'datas' is the data marker and is supposed to be the last
|
// collect data sequence (ignoring final semicolon)
|
||||||
// and should extend until end of file
|
while ( idx+seqidx < rawdata_.size()-1 )
|
||||||
for ( unsigned long int didx = idx; didx < rawdata_.size()-1; didx++ )
|
|
||||||
{
|
{
|
||||||
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
|
// obtain length of data segment
|
||||||
datsize_ = markseq.size();
|
datsize_ = markseq.size();
|
||||||
}
|
}
|
||||||
@ -240,13 +276,17 @@ public:
|
|||||||
if ( datasec_[mrk.first].size() == 0 )
|
if ( datasec_[mrk.first].size() == 0 )
|
||||||
{
|
{
|
||||||
std::string errmess = mrk.first + std::string(" not found in buffer");
|
std::string errmess = mrk.first + std::string(" not found in buffer");
|
||||||
// std::cerr<<errmess;
|
// // std::cerr<<errmess;
|
||||||
try {
|
// try {
|
||||||
throw std::runtime_error(errmess);
|
// throw std::runtime_error(errmess);
|
||||||
} catch( const std::exception& e ) {
|
// } catch( const std::exception& e ) {
|
||||||
throw;
|
// throw;
|
||||||
//std::cout<<e.what()<<"\n";
|
// //std::cout<<e.what()<<"\n";
|
||||||
}
|
// }
|
||||||
|
error_queue_ += errmess + std::string(" - ");
|
||||||
|
|
||||||
|
// if any of the required (essential) markers are missing => invalid!
|
||||||
|
valid_ = false;
|
||||||
}
|
}
|
||||||
totalmarksize += datasec_[mrk.first].size();
|
totalmarksize += datasec_[mrk.first].size();
|
||||||
}
|
}
|
||||||
@ -254,7 +294,7 @@ public:
|
|||||||
// std::cout<<"\n";
|
// std::cout<<"\n";
|
||||||
|
|
||||||
// check validity of format
|
// check validity of format
|
||||||
valid_ = ( totalmarksize < 100 ) ? false : true;
|
// valid_ = ( totalmarksize < 100 ) ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// display content of found markers
|
// display content of found markers
|
||||||
|
@ -72,7 +72,7 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
// add channels
|
// add channels
|
||||||
eatmea.add_channel(rawfile,false);
|
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/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);
|
// eatmea.add_channel("smp/Rangerover_Evoque_F-RR534_2019-05-07/Temp_Disc_FR.raw",false);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user