From c0f5346f5805b8ff7632be0363a28ffcf3e80238 Mon Sep 17 00:00:00 2001 From: Mario Fink Date: Tue, 19 Jan 2021 18:52:44 +0100 Subject: [PATCH] processing of blocks complete --- lib/tdm_datamodel.hpp | 33 +++++++++++++++ lib/tdm_reaper.cpp | 95 +++++++++++++++++++++++++++++++++++++++---- lib/tdm_reaper.hpp | 24 +++++++---- makefile | 2 +- src/main.cpp | 10 ++--- 5 files changed, 142 insertions(+), 22 deletions(-) diff --git a/lib/tdm_datamodel.hpp b/lib/tdm_datamodel.hpp index 8cd6d2d..8f26d05 100644 --- a/lib/tdm_datamodel.hpp +++ b/lib/tdm_datamodel.hpp @@ -15,6 +15,39 @@ #include #include +// -------------------------------------------------------------------------- // +// block of data + +struct block { + + std::string id_; + unsigned long int byte_offset_; + unsigned long int length_; + unsigned long int block_offset_, block_size_; + std::string value_type_; + + block () { + id_ = std::string(""); + byte_offset_ = 0; + length_ = 0; + block_offset_ = 0; + block_size_ = 0; + value_type_ = std::string(""); + } + + const std::string get_info(int width = 20) + { + std::stringstream ss; + ss<process_include(showlog); + +} + +void tdm_reaper::process_include(bool showlog) +{ + // get XML node + pugi::xml_node tdmincl = xml_doc_.child("usi:tdm").child("usi:include"); + + // check endianess + std::string endianness(tdmincl.child("file").attribute("byteOrder").value()); + endianness_ = endianness.compare("littleEndian") == 0 ? true : false; + + // obtain machine's endianess + int num = 1; + machine_endianness_ = ( *(char*)&num == 1 ); + if ( machine_endianness_ != endianness_ ) throw std::runtime_error("endianess mismatch"); + + if ( showlog ) + { + std::cout<<"\n"; + std::cout<<"endianess: "<<(endianness_?"little":"big")<<"\n" + <<"machine endianness: "<<(machine_endianness_?"little":"big")<<"\n\n"; + } + + // check for existence of attributes before using + // pugi::xml_attribute attr; + + // list block of massdata + for (pugi::xml_node anode: tdmincl.child("file").children()) + { + // declare new block + block tdxblock; + + if ( anode.attribute("id") ) + { + tdxblock.id_ = anode.attribute("id").value(); + } + if ( anode.attribute("byteOffset") ) + { + tdxblock.byte_offset_ = std::stoul(anode.attribute("byteOffset").value()); + } + if ( anode.attribute("length") ) + { + tdxblock.length_ = std::stoul(anode.attribute("length").value()); + } + if ( anode.attribute("blockOffset") ) + { + tdxblock.block_offset_ = std::stoul(anode.attribute("blockOffset").value()); + } + if ( anode.attribute("blockSize") ) + { + tdxblock.block_size_ = std::stoul(anode.attribute("blockSize").value()); + } + if ( anode.attribute("valueType") ) + { + tdxblock.value_type_ = anode.attribute("valueType").value(); + } + + // add block to map + tdx_blocks_.insert(std::pair(tdxblock.id_,tdxblock)); + + if ( showlog ) std::cout< csvfile_; + // XML parser + pugi::xml_document xml_doc_; + pugi::xml_parse_result xml_result_; + // endianness (true = little, false = big) bool endianness_, machine_endianness_; + // blocks of data in .tdx file + std::map tdx_blocks_; + // tdm root tdm_root tdmroot_; @@ -65,10 +72,6 @@ class tdm_ripper // NI datatypes ( ) std::map datatypes_; - // xml parser - pugi::xml_document xml_doc_; - pugi::xml_parse_result xml_result_; - // .tdm-file eventually contains some meta information (about measurement) std::map root_info_; std::map meta_info_; @@ -78,7 +81,14 @@ class tdm_ripper public: - tdm_ripper(std::string tdmfile, std::string tdxfile = std::string(""), bool showlog = false); + // decoding + tdm_reaper(std::string tdmfile, std::string tdxfile = std::string(""), bool showlog = false); + + // encoding + tdm_reaper(std::vector csvfile); + + // process element + void process_include(bool showlog); void parse_structure(); diff --git a/makefile b/makefile index 68a78c1..e306fdf 100644 --- a/makefile +++ b/makefile @@ -42,7 +42,7 @@ main.o : src/main.cpp $(CC) -c $(OPT) -I $(LIB) -I lib/ $<.cpp -o $@ @rm $<.cpp -$(SRC).o : lib/$(SRC).cpp lib/$(SRC).hpp +$(SRC).o : lib/$(SRC).cpp lib/$(SRC).hpp lib/tdm_datamodel.hpp $(CC) -c $(OPT) -I $(LIB) $< -o $@ clean : diff --git a/src/main.cpp b/src/main.cpp index 7622e6a..eb1d0f3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -171,15 +171,15 @@ int main(int argc, char* argv[]) : std::string(","); std::string files = cfgopts.count("filenames") == 1 ? cfgopts.at("filenames") : std::string("channel_%G_%C.csv"); - bool listgroups = cfgopts.count("listgroups") == 1 ? true : false; - bool listchannels = cfgopts.count("listchannels") == 1 ? true : false; + // bool listgroups = cfgopts.count("listgroups") == 1 ? true : false; + // bool listchannels = cfgopts.count("listchannels") == 1 ? true : false; // declare and initialize tdm_ripper instance - tdm_ripper jack(cfgopts.at("tdm"),cfgopts.at("tdx")); + tdm_reaper jack(cfgopts.at("tdm"),cfgopts.at("tdx"),true); // print list of groups or channels to stdout - if ( listgroups ) jack.list_groups(); - if ( listchannels ) jack.list_channels(); + // if ( listgroups ) jack.list_groups(); + // if ( listchannels ) jack.list_channels(); // // write data to filesystem // if ( !listgroups && !listchannels )