get channel for any datatype
This commit is contained in:
parent
fe19f723b3
commit
1d70e7b58e
@ -119,6 +119,15 @@ static std::string join_strings(std::vector<std::string> &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;
|
||||
|
||||
enum class tdmdatatype {
|
||||
eInt16Usi,
|
||||
eInt32Usi,
|
||||
|
@ -491,6 +491,80 @@ std::string tdm_reaper::get_localcolumn_overview(format formatter)
|
||||
return summary;
|
||||
}
|
||||
|
||||
std::string tdm_reaper::get_block_overview(format formatter)
|
||||
{
|
||||
// summarize all output in single string
|
||||
std::string summary;
|
||||
|
||||
// set tabular mode of formatter
|
||||
formatter.set_tabular(true);
|
||||
|
||||
// compose header
|
||||
formatter.set_header(true);
|
||||
block blk;
|
||||
summary += blk.get_info(formatter);
|
||||
std::string rule;
|
||||
for ( unsigned long int i = 0; i < summary.size(); i++ )
|
||||
{
|
||||
rule += std::string("-");
|
||||
}
|
||||
summary += std::string("\n") + rule + std::string("\n");
|
||||
|
||||
formatter.set_header(false);
|
||||
for (std::map<std::string,block>::iterator it=tdx_blocks_.begin();
|
||||
it!=tdx_blocks_.end(); ++it)
|
||||
{
|
||||
summary += it->second.get_info(formatter);
|
||||
summary += std::string("\n");
|
||||
}
|
||||
|
||||
return summary;
|
||||
}
|
||||
|
||||
// template<typename tdmelement>
|
||||
// std::string tdm_reaper::get_overview(format formatter)
|
||||
// {
|
||||
// // summarize all output in single string
|
||||
// std::string summary;
|
||||
//
|
||||
// // set tabular mode of formatter
|
||||
// formatter.set_tabular(true);
|
||||
//
|
||||
// // compose header
|
||||
// formatter.set_header(true);
|
||||
// tdmelement tdmel;
|
||||
// summary += tdmel.get_info(formatter);
|
||||
// std::string rule;
|
||||
// for ( unsigned long int i = 0; i < summary.size(); i++ )
|
||||
// {
|
||||
// rule += std::string("-");
|
||||
// }
|
||||
// summary += std::string("\n") + rule + std::string("\n");
|
||||
//
|
||||
// formatter.set_header(false);
|
||||
// std::map<std::string,tdmelement> thedat = this->get_tdm_member<tdmelement>(tdmel);
|
||||
// for ( std::map<std::string,tdmelement> el: thedat )
|
||||
// {
|
||||
// summary += el->second.get_info(formatter) + std::string("\n");
|
||||
// }
|
||||
// // for (std::map<std::string,tdmelement>::iterator it=thedat.begin();
|
||||
// // it!=thedat.end(); ++it)
|
||||
// // {
|
||||
// // summary += it->second.get_info(formatter);
|
||||
// // summary += std::string("\n");
|
||||
// // }
|
||||
//
|
||||
// return summary;
|
||||
// }
|
||||
//
|
||||
// template<typename tdmelement>
|
||||
// std::map<std::string,tdmelement> tdm_reaper::get_tdm_member(block blk)
|
||||
// {
|
||||
// return this->tdx_blocks_;
|
||||
// }
|
||||
//
|
||||
// template std::string tdm_reaper::get_overview<block>(format formatter);
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
|
||||
std::vector<double> tdm_reaper::get_channel(std::string &id)
|
||||
|
@ -149,9 +149,14 @@ public:
|
||||
// get full channel(group) overview
|
||||
std::string get_channel_overview(format chformatter);
|
||||
|
||||
// get submatrix/localcolumn overview
|
||||
// get block/submatrix/localcolumn overview
|
||||
// template<typename tdmelement>
|
||||
// std::string get_overview(format formatter);
|
||||
// template<typename tdmelement>
|
||||
// std::map<std::string,tdmelement> get_tdm_member(block blk);
|
||||
std::string get_submatrix_overview(format formatter);
|
||||
std::string get_localcolumn_overview(format formatter);
|
||||
std::string get_block_overview(format formatter);
|
||||
|
||||
// get list of channelgroup ids
|
||||
std::vector<std::string> get_channelgroup_ids()
|
||||
@ -174,6 +179,75 @@ public:
|
||||
}
|
||||
|
||||
// extract channel by id
|
||||
template<typename tdmtype>
|
||||
std::vector<tdmtype> 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<unsigned char> blkF32( tdxbuffer_.begin()+blk.byte_offset_,
|
||||
// tdxbuffer_.begin()+blk.byte_offset_
|
||||
// + blk.length_*sizeof(eFloat32Usi) );
|
||||
// std::vector<eFloat32Usi> datvecF32(blk.length_);
|
||||
// this->convert_data_to_type<eFloat32Usi>(blkF32,datvecF32);
|
||||
// return datvecF32;
|
||||
// break;
|
||||
// case "eFloat64Usi" :
|
||||
// // declare buffer covering the required range of "tdxbuffer_"
|
||||
// std::vector<unsigned char> blkF64( tdxbuffer_.begin()+blk.byte_offset_,
|
||||
// tdxbuffer_.begin()+blk.byte_offset_
|
||||
// + blk.length_*sizeof(eFloat64Usi) );
|
||||
// std::vector<eFloat64Usi> datvecF64(blk.length_);
|
||||
// this->convert_data_to_type<eFloat64Usi>(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<tdmtype>();
|
||||
}
|
||||
|
||||
// (TODO introduce template T to reference specific datatype instead of double in general)
|
||||
std::vector<double> get_channel(std::string &id);
|
||||
|
||||
|
@ -199,6 +199,10 @@ int main(int argc, char* argv[])
|
||||
format formatter(18,false,false,' ');
|
||||
std::cout<<jack.get_submatrix_overview(formatter)<<"\n";
|
||||
std::cout<<jack.get_localcolumn_overview(formatter)<<"\n";
|
||||
std::cout<<jack.get_block_overview(formatter)<<"\n";
|
||||
|
||||
std::string chid("usi14");
|
||||
std::vector<tdmdatatype> chdata = jack.get_channel<tdmdatatype>(chid);
|
||||
|
||||
// std::vector<std::string> chgrids = jack.get_channelgroup_ids();
|
||||
// for ( auto el: chgrids ) std::cout<<el<<",";
|
||||
|
Loading…
x
Reference in New Issue
Block a user