diff --git a/lib/tdm_datamodel.hpp b/lib/tdm_datamodel.hpp index fd28b31..0ef9bb1 100644 --- a/lib/tdm_datamodel.hpp +++ b/lib/tdm_datamodel.hpp @@ -119,23 +119,172 @@ static std::string join_strings(std::vector &thestring, const char* // https://zone.ni.com/reference/de-XX/help/370858P-0113/tdmdatamodel/tdmdatamodel/tdm_header_tdx_data/ -// define mapping of locally supported datatypes to tdm datatypes -typedef short int eInt16Usi; -typedef int eInt32Usi; -typedef unsigned char eUInt8Usi; -typedef unsigned short int eUInt16Usi; -typedef unsigned int eUInt32Usi; -typedef float eFloat32Usi; -typedef double eFloat64Usi; +// define mapping of C++ supported datatypes to tdm datatypes -enum class tdmdatatype { - eInt16Usi, - eInt32Usi, - eUInt8Usi, - eUInt16Usi, - eUInt32Usi, - eFloat32Usi, - eFloat64Usi +// define mapping of locally supported datatypes to tdm datatypes +// typedef short int eInt16Usi; +// typedef int eInt32Usi; +// typedef unsigned char eUInt8Usi; +// typedef unsigned short int eUInt16Usi; +// typedef unsigned int eUInt32Usi; +// typedef float eFloat32Usi; +// typedef double eFloat64Usi; + +// enum class tdmdatatype { +// eInt16Usi, +// eInt32Usi, +// eUInt8Usi, +// eUInt16Usi, +// eUInt32Usi, +// eFloat32Usi, +// eFloat64Usi +// }; + +// base class for all tdm datatypes +class tdmdatatype +{ +protected: + short int sint16_; + int sint32_; + unsigned char uint8_; + unsigned short int uint16_; + unsigned int uint32_; + float float32_; + double float64_; +public: + tdmdatatype(): sint16_(0), sint32_(0), + uint8_(0), uint16_(0), uint32_(0), + float32_(0.0), float64_(0.0) {}; + friend std::ostream& operator<<(std::ostream& out, const tdmdatatype& num) + { + return num.print(out); + } + virtual std::ostream& print(std::ostream& out) const + { + out<<"tdmdatatype"; + return out; + } +}; + +class eInt16Usi: public tdmdatatype +{ +public: + eInt16Usi() { } + eInt16Usi(short int num) { sint16_ = num; } + // eInt16Usi& operator=(const eInt16Usi &num) + // { + // // self-assignment check + // if ( this != &num) + // { + // this->sint16_ = num.sint16_; + // } + // return *this; + // } + friend std::ostream& operator<<(std::ostream& out, const eInt16Usi& num) + { + return num.print(out); + } + std::ostream& print(std::ostream& out) const override + { + out< tdm_reaper::get_channel(std::string &id) +// extract channel by id +template +std::vector tdm_reaper::get_channel(std::string& id) { // check for existence of required channel id (=key) if ( tdmchannels_.count(id) == 1 ) @@ -576,39 +578,108 @@ std::vector tdm_reaper::get_channel(std::string &id) tdm_channel chn = tdmchannels_.at(id); // extract (first) "localcolumn" for channel + if ( chn.local_columns_.size() != 1 ) + { + throw std::runtime_error(std::string("invalid local_columns_ of channel: ") + id); + } localcolumn loccol = localcolumns_.at(chn.local_columns_[0]); + if ( loccol.sequence_representation_ != "explicit" ) + { + throw std::runtime_error(std::string("unsupported sequence_representation: ") + + loccol.sequence_representation_); + } + // use "values" id to map to external block block blk = tdx_blocks_.at(loccol.external_id_); - - // declare buffer covering the required range of "tdxbuffer_" - std::vector blkbuff( tdxbuffer_.begin()+blk.byte_offset_, - tdxbuffer_.begin()+blk.byte_offset_ - + blk.length_*sizeof(double) ); - - std::vector datvec(blk.length_); - this->convert_data_to_type(blkbuff,datvec); - - return datvec; + + // // distinguish numeric datatypes + // switch ( blk.value_type_ ) + // { + // case "eInt16Usi" : + // break; + // case "eInt32Usi" : + // break; + // case "eUInt8Usi" : + // break; + // case "eUInt16Usi" : + // break; + // case "eUInt32Usi" : + // break; + // case "eFloat32Usi" : + // // declare buffer covering the required range of "tdxbuffer_" + // std::vector blkF32( tdxbuffer_.begin()+blk.byte_offset_, + // tdxbuffer_.begin()+blk.byte_offset_ + // + blk.length_*sizeof(eFloat32Usi) ); + // std::vector datvecF32(blk.length_); + // this->convert_data_to_type(blkF32,datvecF32); + // return datvecF32; + // break; + // case "eFloat64Usi" : + // // declare buffer covering the required range of "tdxbuffer_" + // std::vector blkF64( tdxbuffer_.begin()+blk.byte_offset_, + // tdxbuffer_.begin()+blk.byte_offset_ + // + blk.length_*sizeof(eFloat64Usi) ); + // std::vector datvecF64(blk.length_); + // this->convert_data_to_type(blkF64,datvecF64); + // return datvecF64; + // break; + // case "eStringUsi" : + // throw std::runtime_error("datatype 'eStringUsi' is not supported"); + // break; + // } } else { throw std::invalid_argument(std::string("channel id does not exist: ") + id); } + + return std::vector(); } +template std::vector tdm_reaper::get_channel(std::string& id); + +// std::vector tdm_reaper::get_channel(std::string &id) +// { +// // check for existence of required channel id (=key) +// if ( tdmchannels_.count(id) == 1 ) +// { +// // retrieve full channel info +// tdm_channel chn = tdmchannels_.at(id); +// +// // extract (first) "localcolumn" for channel +// localcolumn loccol = localcolumns_.at(chn.local_columns_[0]); +// +// // use "values" id to map to external block +// block blk = tdx_blocks_.at(loccol.external_id_); +// +// // declare buffer covering the required range of "tdxbuffer_" +// std::vector blkbuff( tdxbuffer_.begin()+blk.byte_offset_, +// tdxbuffer_.begin()+blk.byte_offset_ +// + blk.length_*sizeof(double) ); +// +// std::vector datvec(blk.length_); +// this->convert_data_to_type(blkbuff,datvec); +// +// return datvec; +// } +// else +// { +// throw std::invalid_argument(std::string("channel id does not exist: ") + id); +// } +// } + void tdm_reaper::print_channel(std::string &id, const char* filename) { std::ofstream fou(filename); - std::vector chn = this->get_channel(id); + std::vector chn; // = this->get_channel(id); for ( auto el: chn ) fou< diff --git a/lib/tdm_reaper.hpp b/lib/tdm_reaper.hpp index 1f3788e..43a574c 100644 --- a/lib/tdm_reaper.hpp +++ b/lib/tdm_reaper.hpp @@ -180,76 +180,10 @@ public: // extract channel by id template - std::vector get_channel(std::string& id) - { - // check for existence of required channel id (=key) - if ( tdmchannels_.count(id) == 1 ) - { - // // retrieve full channel info - // tdm_channel chn = tdmchannels_.at(id); - // - // // extract (first) "localcolumn" for channel - // if ( chn.local_columns_.size() != 1 ) - // { - // throw std::runtime_error(std::string("invalid local_columns_ of channel: ") + id); - // } - // localcolumn loccol = localcolumns_.at(chn.local_columns_[0]); - // - // if ( loccol.sequence_representation_ != "explicit" ) - // { - // throw std::runtime_error(std::string("unsupported sequence_representation: ") - // + loccol.sequence_representation_); - // } - // - // // use "values" id to map to external block - // block blk = tdx_blocks_.at(loccol.external_id_); - // - // // distinguish numeric datatypes - // switch ( blk.value_type_ ) - // { - // case "eInt16Usi" : - // break; - // case "eInt32Usi" : - // break; - // case "eUInt8Usi" : - // break; - // case "eUInt16Usi" : - // break; - // case "eUInt32Usi" : - // break; - // case "eFloat32Usi" : - // // declare buffer covering the required range of "tdxbuffer_" - // std::vector blkF32( tdxbuffer_.begin()+blk.byte_offset_, - // tdxbuffer_.begin()+blk.byte_offset_ - // + blk.length_*sizeof(eFloat32Usi) ); - // std::vector datvecF32(blk.length_); - // this->convert_data_to_type(blkF32,datvecF32); - // return datvecF32; - // break; - // case "eFloat64Usi" : - // // declare buffer covering the required range of "tdxbuffer_" - // std::vector blkF64( tdxbuffer_.begin()+blk.byte_offset_, - // tdxbuffer_.begin()+blk.byte_offset_ - // + blk.length_*sizeof(eFloat64Usi) ); - // std::vector datvecF64(blk.length_); - // this->convert_data_to_type(blkF64,datvecF64); - // return datvecF64; - // break; - // case "eStringUsi" : - // throw std::runtime_error("datatype 'eStringUsi' is not supported"); - // break; - // } - } - else - { - throw std::invalid_argument(std::string("channel id does not exist: ") + id); - } - - return std::vector(); - } + std::vector get_channel(std::string& id); // (TODO introduce template T to reference specific datatype instead of double in general) - std::vector get_channel(std::string &id); + // std::vector get_channel(std::string &id); void print_channel(std::string &id, const char* filename); diff --git a/src/main.cpp b/src/main.cpp index 5b3225d..e4cc961 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -204,6 +204,9 @@ int main(int argc, char* argv[]) std::string chid("usi14"); std::vector chdata = jack.get_channel(chid); + std::cout<<"channel size: "< chgrids = jack.get_channelgroup_ids(); // for ( auto el: chgrids ) std::cout<