* list specific blocks
* key comparison operator * imc::object: fix timestamp, fix analog vs. digital index * imc_raw: convert datatype
This commit is contained in:
parent
eb13088257
commit
9bac0f1063
@ -82,12 +82,16 @@ namespace imc
|
|||||||
void parse_parameters()
|
void parse_parameters()
|
||||||
{
|
{
|
||||||
// parse entire block and check for separator tokens
|
// parse entire block and check for separator tokens
|
||||||
for ( unsigned long int b = begin_; b < end_; b++ )
|
// (consider only first four of any CS block)
|
||||||
|
int count = 0;
|
||||||
|
for ( unsigned long int b = begin_;
|
||||||
|
b < end_ && (!(thekey_==imc::keys.at("CS")) || count < 4 ); b++ )
|
||||||
{
|
{
|
||||||
if ( buffer_->at(b) == imc::ch_sep_ )
|
if ( buffer_->at(b) == imc::ch_sep_ )
|
||||||
{
|
{
|
||||||
// define range of parameter with first byte = ch_sep_
|
// define range of parameter with first byte = ch_sep_
|
||||||
parameters_.push_back(imc::parameter(b,b));
|
parameters_.push_back(imc::parameter(b,b));
|
||||||
|
count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,6 +39,15 @@ namespace imc
|
|||||||
version_ = version;
|
version_ = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// comparison operator
|
||||||
|
bool operator==(const key& akey)
|
||||||
|
{
|
||||||
|
return ( this->critical_ == akey.critical_
|
||||||
|
&& this->name_ == akey.name_
|
||||||
|
&& this->description_ == akey.description_
|
||||||
|
&& this->version_ == akey.version_ );
|
||||||
|
}
|
||||||
|
|
||||||
// get info string
|
// get info string
|
||||||
std::string get_info(int width = 20)
|
std::string get_info(int width = 20)
|
||||||
{
|
{
|
||||||
@ -52,7 +61,7 @@ namespace imc
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// define (non)critial markers/keys
|
// define (non)critical markers/keys
|
||||||
std::map<std::string,key> keys = {
|
std::map<std::string,key> keys = {
|
||||||
|
|
||||||
// critical keys
|
// critical keys
|
||||||
|
@ -240,14 +240,14 @@ namespace imc
|
|||||||
struct component
|
struct component
|
||||||
{
|
{
|
||||||
int component_index_;
|
int component_index_;
|
||||||
bool analog_digital_;
|
bool analog_digital_; // 1 => false (analog), 2 => true (digital)
|
||||||
|
|
||||||
// construct members by parsing particular parameters from buffer
|
// construct members by parsing particular parameters from buffer
|
||||||
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter>& parameters)
|
void parse(const std::vector<unsigned char>* buffer, const std::vector<parameter>& parameters)
|
||||||
{
|
{
|
||||||
if ( parameters.size() < 4 ) throw std::runtime_error("invalid number of parameters in CD2");
|
if ( parameters.size() < 4 ) throw std::runtime_error("invalid number of parameters in CD2");
|
||||||
component_index_ = std::stoi(get_parameter(buffer,¶meters[2]));
|
component_index_ = std::stoi(get_parameter(buffer,¶meters[2]));
|
||||||
analog_digital_ = std::stoi(get_parameter(buffer,¶meters[3]));
|
analog_digital_ = ( std::stoi(get_parameter(buffer,¶meters[3])) == 2 );
|
||||||
}
|
}
|
||||||
|
|
||||||
// get info string
|
// get info string
|
||||||
@ -505,12 +505,17 @@ namespace imc
|
|||||||
time(&rawtime);
|
time(&rawtime);
|
||||||
ts = localtime(&rawtime);
|
ts = localtime(&rawtime);
|
||||||
ts->tm_mday = day_;
|
ts->tm_mday = day_;
|
||||||
ts->tm_mon = month_;
|
ts->tm_mon = month_-1;
|
||||||
ts->tm_year = year_-1900;
|
ts->tm_year = year_-1900;
|
||||||
ts->tm_hour = hour_;
|
ts->tm_hour = hour_;
|
||||||
ts->tm_min = minute_;
|
ts->tm_min = minute_;
|
||||||
ts->tm_sec = (int)second_;
|
ts->tm_sec = (int)second_;
|
||||||
timestamp_ = asctime(ts);
|
timestamp_ = asctime(ts);
|
||||||
|
// timestamp_ = std::to_string(year_) + std::string("-") + std::to_string(month_)
|
||||||
|
// + std::string("-") + std::to_string(day_)
|
||||||
|
// + std::string("T") + std::to_string(hour_)
|
||||||
|
// + std::string(":") + std::to_string(minute_)
|
||||||
|
// + std::string(":") + std::to_string(second_);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get info string
|
// get info string
|
||||||
|
@ -166,6 +166,34 @@ namespace imc
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse channel's raw data
|
// parse channel's raw data
|
||||||
|
template<typename datatype>
|
||||||
|
void convert_data_to_type(std::vector<unsigned char>& subbuffer,
|
||||||
|
std::vector<imc::datatype>& channel)
|
||||||
|
{
|
||||||
|
// check number of elements of type "datatype" in buffer
|
||||||
|
if ( subbuffer.size() != channel.size()*sizeof(datatype) )
|
||||||
|
{
|
||||||
|
throw std::runtime_error("size mismatch between subbuffer and datatype");
|
||||||
|
}
|
||||||
|
|
||||||
|
// extract every single number of type "datatype" from buffer
|
||||||
|
for ( unsigned long int i = 0; i < channel.size(); i++ )
|
||||||
|
{
|
||||||
|
// declare number of required type and point it to first byte in buffer
|
||||||
|
// representing the number
|
||||||
|
datatype df;
|
||||||
|
uint8_t* dfcast = reinterpret_cast<uint8_t*>(&df);
|
||||||
|
|
||||||
|
for ( unsigned long int j = 0; j < sizeof(datatype); j++ )
|
||||||
|
{
|
||||||
|
dfcast[j] = (int)subbuffer[i*sizeof(datatype)+j];
|
||||||
|
}
|
||||||
|
|
||||||
|
// save number in channel
|
||||||
|
channel[i] = df;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
@ -187,6 +215,29 @@ namespace imc
|
|||||||
return cplxcnt_;
|
return cplxcnt_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// list a particular type of block
|
||||||
|
std::vector<imc::block> list_blocks(imc::key mykey)
|
||||||
|
{
|
||||||
|
std::vector<imc::block> myblocks;
|
||||||
|
for ( imc::block blk: this->rawblocks_ )
|
||||||
|
{
|
||||||
|
if ( blk.get_key() == mykey ) myblocks.push_back(blk);
|
||||||
|
}
|
||||||
|
return myblocks;
|
||||||
|
}
|
||||||
|
|
||||||
|
// list all groups (associated to blocks "CB")
|
||||||
|
std::vector<imc::block> list_groups()
|
||||||
|
{
|
||||||
|
return this->list_blocks(imc::keys.at("CB"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// list all channels
|
||||||
|
std::vector<imc::block> list_channels()
|
||||||
|
{
|
||||||
|
return this->list_blocks(imc::keys.at("CN"));
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
18
src/main.cpp
18
src/main.cpp
@ -178,7 +178,23 @@ int main(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
std::cout<<"number of blocks: "<<imcraw.blocks().size()<<"\n";
|
std::cout<<"number of blocks: "<<imcraw.blocks().size()<<"\n";
|
||||||
std::cout<<"computational complexity: "<<imcraw.computational_complexity()
|
std::cout<<"computational complexity: "<<imcraw.computational_complexity()
|
||||||
<<"/"<<imcraw.buffer_size()<<"\n";
|
<<"/"<<imcraw.buffer_size()<<"\n\n";
|
||||||
|
|
||||||
|
// list specific blocks
|
||||||
|
// std::vector<imc::block> CBblocks = imcraw.list_blocks(imc::keys.at("CB"));
|
||||||
|
// for ( auto blk: CBblocks ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> CGblocks = imcraw.list_blocks(imc::keys.at("CG"));
|
||||||
|
// for ( auto blk: CGblocks ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> CCblocks = imcraw.list_blocks(imc::keys.at("CC"));
|
||||||
|
// for ( auto blk: CCblocks ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> CNblocks = imcraw.list_blocks(imc::keys.at("CN"));
|
||||||
|
// for ( auto blk: CNblocks ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> CSblocks = imcraw.list_blocks(imc::keys.at("CS"));
|
||||||
|
// for ( auto blk: CSblocks ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> groups = imcraw.list_groups();
|
||||||
|
// for ( auto blk: groups ) std::cout<<blk.get_info()<<"\n";
|
||||||
|
// std::vector<imc::block> channels = imcraw.list_channels();
|
||||||
|
// for ( auto blk: channels ) std::cout<<blk.get_info()<<"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user