basically done for doubles/float, still to fix starting byte
This commit is contained in:
parent
20566df9ca
commit
5b1868daf0
85322
csv/myfile.csv
Normal file
85322
csv/myfile.csv
Normal file
File diff suppressed because it is too large
Load Diff
74
src/main.cpp
74
src/main.cpp
@ -1,5 +1,7 @@
|
||||
//---------------------------------------------------------------------------//
|
||||
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "../src/raweat.hpp"
|
||||
|
||||
//---------------------------------------------------------------------------//
|
||||
@ -24,60 +26,26 @@ int main(int argc, char* argv[])
|
||||
eatraw.show_markers();
|
||||
eatraw.find_markers();
|
||||
|
||||
std::map<std::string,std::vector<unsigned char>> marks = eatraw.get_markers();
|
||||
for ( auto mrk: marks )
|
||||
{
|
||||
// get data
|
||||
std::vector<unsigned char> dat = eatraw.get_marker_data(mrk.first);
|
||||
|
||||
// tdm_ripper ripper(argv[1],argv[2],false); //,"samples/SineData.tdx",false);
|
||||
//
|
||||
// // ripper.list_datatypes();
|
||||
// // ripper.show_structure();
|
||||
//
|
||||
// ripper.print_hash_local("data/hash_table_xml_local.dat");
|
||||
// ripper.print_hash_values("data/hash_table_xml_value.dat");
|
||||
// ripper.print_hash_double("data/hash_table_xml_double.dat");
|
||||
// ripper.print_extid("data/channel_ext_id.dat");
|
||||
//
|
||||
// ripper.list_groups();
|
||||
// std::ofstream gout("data/list_of_groups.dat");
|
||||
// ripper.list_groups(gout);
|
||||
// gout.close();
|
||||
//
|
||||
// ripper.list_channels();
|
||||
// std::ofstream fout("data/list_of_channels.dat");
|
||||
// ripper.list_channels(fout);
|
||||
// fout.close();
|
||||
//
|
||||
// // long int nsa = 6.3636349745e10; // expected result: 22.07.2016, 19:49:05
|
||||
// // long int nsb = 6.3636350456e10;
|
||||
// // std::string ts = std::to_string(nsa);
|
||||
// // std::cout<<ripper.unix_timestamp(ts)<<"\n";
|
||||
//
|
||||
// std::cout<<"number of channels "<<ripper.num_channels()<<"\n";
|
||||
// std::cout<<"number of groups "<<ripper.num_groups()<<"\n\n";
|
||||
//
|
||||
// // obtain some specific meta information tags
|
||||
// std::cout<<"\n"<<ripper.get_meta("SMP_Name")<<"\n";
|
||||
// std::cout<<ripper.get_meta("SMP_Aufbau_Nr")<<"\n";
|
||||
// std::cout<<ripper.get_meta("SMP_Type")<<"\n";
|
||||
// std::cout<<ripper.get_meta("Location")<<"\n\n";
|
||||
//
|
||||
// // print all meta information
|
||||
// ripper.print_meta("data/meta_info.csv");
|
||||
//
|
||||
// // for ( int i = 0; i < ripper.num_groups(); i++ )
|
||||
// // {
|
||||
// // std::cout<<std::setw(10)<<i+1<<std::setw(10)<<ripper.no_channels(i+1)<<"\n";
|
||||
// // for ( int j = 0; j < ripper.no_channels(i+1); j++ )
|
||||
// // {
|
||||
// // std::cout<<std::setw(10)<<i+1<<std::setw(10)<<j+1<<std::setw(30)<<ripper.channel_name(i+1,j+1)<<"\n";
|
||||
// // }
|
||||
// // }
|
||||
//
|
||||
// // for ( int i = 3; i < 10; i++ )
|
||||
// for ( int i = 0; i < ripper.num_channels(); i++ )
|
||||
// // for ( int i = 11880; i < ripper.num_channels(); i++ )
|
||||
// {
|
||||
// ripper.print_channel(i,("data/channel_"+std::to_string(i+1)+"_"
|
||||
// +ripper.channel_name(i)+".dat").c_str());
|
||||
// }
|
||||
// print marker name, length and data
|
||||
std::cout<<mrk.first<<" : "<<dat.size()<<'\n';
|
||||
std::cout<<std::setfill('-')<<std::setw(96)<<'\n'<<std::setfill(' ');
|
||||
eatraw.show_hex(dat,32,512);
|
||||
std::cout<<"\n";
|
||||
}
|
||||
|
||||
eatraw.convert_data();
|
||||
|
||||
std::vector<double> mydata = eatraw.get_data();
|
||||
std::cout<<"\n"<<mydata.size()<<"\n\n";
|
||||
//for ( unsigned long int i = 0; i < 10; i++ ) std::cout<<mydata[i]<<"\n";
|
||||
|
||||
eatraw.write_data(std::string("csv/myfile.csv"));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
103
src/raweat.hpp
103
src/raweat.hpp
@ -40,6 +40,9 @@ private:
|
||||
// data sections corresponding to markers
|
||||
std::map<std::string,std::vector<unsigned char>> datasec_;
|
||||
|
||||
// TODO preliminary: for now, we assume 32/64 bit ? floats in all data
|
||||
std::vector<double> datmes_;
|
||||
|
||||
public:
|
||||
|
||||
// constructor
|
||||
@ -85,8 +88,9 @@ public:
|
||||
{
|
||||
std::cout<<el.first<<" ";
|
||||
for ( unsigned char c: el.second) std::cout<<std::hex<<int(c);
|
||||
std::cout<<"\n";
|
||||
std::cout<<"\n\n";
|
||||
}
|
||||
std::cout<<std::dec;
|
||||
}
|
||||
|
||||
// find predefined markers in data buffer
|
||||
@ -132,15 +136,108 @@ public:
|
||||
markseq.push_back(rawdata_[didx]);
|
||||
}
|
||||
}
|
||||
datasec_.insert(std::pair<std::string,std::vector<unsigned char>>(mrk.first,markseq));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (std::pair<std::string,std::vector<unsigned char>> mrk : markers_ )
|
||||
}
|
||||
|
||||
// get all predefined markers
|
||||
std::map<std::string,std::vector<unsigned char>> get_markers()
|
||||
{
|
||||
return markers_;
|
||||
}
|
||||
|
||||
// get data associated to specific marker
|
||||
std::vector<unsigned char> get_marker_data(std::string marker)
|
||||
{
|
||||
return datasec_[marker];
|
||||
}
|
||||
|
||||
// show hex dump
|
||||
void show_hex(std::vector<unsigned char> &datavec, int width = 32, unsigned long int maxchars = 512)
|
||||
{
|
||||
// compose hex string and encoded string
|
||||
std::stringstream hex, enc;
|
||||
|
||||
for ( unsigned long int i = 0; i < datavec.size() && i < maxchars; i++ )
|
||||
{
|
||||
std::cout<<mrk.first<<" "<<mrk.second.size()<<"\n";
|
||||
if ( (int)(i+1)%width == 0 )
|
||||
{
|
||||
// print both strings
|
||||
std::cout<<std::setw(3*width)<<std::left<<hex.str()<<" "<<enc.str()<<"\n";
|
||||
std::cout<<std::right;
|
||||
|
||||
// clear stringstreams
|
||||
hex.str(std::string());
|
||||
enc.str(std::string());
|
||||
}
|
||||
else
|
||||
{
|
||||
// accumulate in stringstreams
|
||||
hex<<std::nouppercase<<std::setfill('0')<<std::setw(2)<<std::hex<<(int)datavec[i]<<" ";
|
||||
// check if byte corresponds to some control character and if it's printable
|
||||
int ic = (int)datavec[i];
|
||||
if ( ic > 0x20 && ic < 0x7f )
|
||||
{
|
||||
enc<<(char)(datavec[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
enc<<".";
|
||||
}
|
||||
}
|
||||
}
|
||||
// print final remaining part
|
||||
std::cout<<std::setw(3*width)<<std::left<<hex.str()<<" "<<enc.str()<<"\n";
|
||||
std::cout<<std::right;
|
||||
std::cout<<std::dec;
|
||||
}
|
||||
|
||||
// convert actual measurement data
|
||||
void convert_data()
|
||||
{
|
||||
// length of data array
|
||||
unsigned long int datsize = datasec_["datas marker"].size();
|
||||
|
||||
assert ( (datsize-28)%4 == 0 && "length of buffer is not a multiple of 4" );
|
||||
|
||||
unsigned long int totnumfl = (datsize-28)/4;
|
||||
for ( unsigned long int numfl = 0; numfl < totnumfl; numfl++ )
|
||||
{
|
||||
// assuming 4 byte float
|
||||
float num = 0.0;
|
||||
uint8_t* pnum = reinterpret_cast<uint8_t*>(&num);
|
||||
for ( int byi = 0; byi < (int)sizeof(float); byi++ )
|
||||
{
|
||||
pnum[byi] = (int)datasec_["datas marker"][(unsigned long int)(28+numfl*sizeof(float)+byi)];
|
||||
}
|
||||
|
||||
// add number of array
|
||||
datmes_.push_back((double)num);
|
||||
}
|
||||
}
|
||||
|
||||
// get data array encoded as floats/doubles
|
||||
std::vector<double>& get_data()
|
||||
{
|
||||
return datmes_;
|
||||
}
|
||||
|
||||
// write data to csv-like file
|
||||
void write_data(std::string filename)
|
||||
{
|
||||
// open file
|
||||
std::ofstream fout(filename.c_str());
|
||||
|
||||
for ( auto el : datmes_ )
|
||||
{
|
||||
fout<<std::dec<<el<<"\n";
|
||||
}
|
||||
|
||||
// close file
|
||||
fout.close();
|
||||
}
|
||||
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user