#include "tdm_ripper.hpp" tdm_ripper::tdm_ripper(std::string tdmfile, std::string tdxfile): tdmfile_(tdmfile), tdxfile_(tdxfile), num_channels_(0), num_groups_(0), channel_id_(0), group_id_(0), channel_name_(0), group_name_(0), num_channels_group_(0), channels_group_(0), byteoffset_(0), length_(0), type_(0) { datatypes_ = { {"eInt8Usi",8}, {"eInt16Usi",16}, {"eInt32Usi",32}, {"eInt64Usi",64}, {"eUInt8Usi",8}, {"eUInt16Usi",16}, {"eUInt32Usi",32}, {"eUInt64Usi",64}, {"eFloat32Usi",32}, {"eFloat64Usi",64} }; // make sure the provided file is a .tdm file assert( tdmfile_.compare("") != 0 && "please provide a valid .tdm file" ); std::string::size_type idx; idx = tdmfile_.find_last_of("."); assert( idx != std::string::npos && "there's no file extension at all - .tdm is required" ); assert( tdmfile_.substr(tdmfile_.find_last_of(".")+1).compare("tdm") == 0 && "it's not a .tdm file" ); // setup of xml-parser xml_result_ = xml_doc_.load_file(tdmfile_.c_str()); std::cout<<"\nloading and parsing file: "< tdxbuf((std::istreambuf_iterator(fin)), (std::istreambuf_iterator())); tdxbuf_ = tdxbuf; std::cout<<"number of bytes in binary file: "< maxshow ) { for ( int i = num_channels_-maxshow; i < num_channels_; i++ ) { gout< bych) { assert( bych.size() == sizeof(int) ); assert( endianness_ ); int df = 0.0; uint8_t *dfcast = reinterpret_cast(&df); for ( int i = 0; i < (int)sizeof(int); i++ ) { dfcast[i] = (int)bych[i]; } return df; } // convert array of chars to floating point double double tdm_ripper::convert_double(std::vector bych) { assert( bych.size() == sizeof(double) ); assert( endianness_ ); // check for IEEE754 floating point standard assert( std::numeric_limits::is_iec559 ); double df = 0.0; uint8_t *dfcast = reinterpret_cast(&df); for ( int i = 0; i < (int)sizeof(double); i++ ) { dfcast[i] = (int)bych[i]; } return df; } std::vector tdm_ripper::convert_channel(int byteoffset, int length, std::string type) { std::vector chann(length); int typesize = datatypes_[type]/CHAR_BIT; for ( int i = 0; i < length; i++ ) { std::vector cseg(tdxbuf_.begin()+byteoffset+i*typesize, tdxbuf_.begin()+byteoffset+(i+1)*typesize); if ( type.compare("eInt32Usi") == 0 ) chann[i] = convert_int(cseg); if ( type.compare("eFloat64Usi") == 0 ) chann[i] = convert_double(cseg); } return chann; } std::vector tdm_ripper::get_channel(int channelid) { assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" ); return convert_channel(byteoffset_[channelid-1],length_[channelid-1],type_[channelid-1]); // return convert_channel(byteoffset_[channelid-1],length_[channelid-1], // datatypes_[type_[channelid-1]]/CHAR_BIT); } void tdm_ripper::print_channel(int channelid, const char* filename, int width) { assert( channelid > 0 && channelid <= num_channels_ && "please provide valid channel id" ); std::ofstream fout(filename); std::vector channdat = get_channel(channelid); for ( auto el: channdat ) fout<