diff --git a/lib/imc_block.hpp b/lib/imc_block.hpp index 1f8adb2..967f083 100644 --- a/lib/imc_block.hpp +++ b/lib/imc_block.hpp @@ -82,12 +82,16 @@ namespace imc void parse_parameters() { // 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_ ) { // define range of parameter with first byte = ch_sep_ parameters_.push_back(imc::parameter(b,b)); + count++; } } diff --git a/lib/imc_key.hpp b/lib/imc_key.hpp index df19962..2d738f2 100644 --- a/lib/imc_key.hpp +++ b/lib/imc_key.hpp @@ -39,6 +39,15 @@ namespace imc 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 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 keys = { // critical keys diff --git a/lib/imc_object.hpp b/lib/imc_object.hpp index 705ff58..17f4e66 100644 --- a/lib/imc_object.hpp +++ b/lib/imc_object.hpp @@ -240,14 +240,14 @@ namespace imc struct component { int component_index_; - bool analog_digital_; + bool analog_digital_; // 1 => false (analog), 2 => true (digital) // construct members by parsing particular parameters from buffer void parse(const std::vector* buffer, const std::vector& parameters) { if ( parameters.size() < 4 ) throw std::runtime_error("invalid number of parameters in CD2"); 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 @@ -505,12 +505,17 @@ namespace imc time(&rawtime); ts = localtime(&rawtime); ts->tm_mday = day_; - ts->tm_mon = month_; + ts->tm_mon = month_-1; ts->tm_year = year_-1900; ts->tm_hour = hour_; ts->tm_min = minute_; ts->tm_sec = (int)second_; 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 diff --git a/lib/imc_raw.hpp b/lib/imc_raw.hpp index 14eb990..26f0b05 100644 --- a/lib/imc_raw.hpp +++ b/lib/imc_raw.hpp @@ -166,6 +166,34 @@ namespace imc } // parse channel's raw data + template + void convert_data_to_type(std::vector& subbuffer, + std::vector& 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(&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: @@ -187,6 +215,29 @@ namespace imc return cplxcnt_; } + // list a particular type of block + std::vector list_blocks(imc::key mykey) + { + std::vector 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 list_groups() + { + return this->list_blocks(imc::keys.at("CB")); + } + + // list all channels + std::vector list_channels() + { + return this->list_blocks(imc::keys.at("CN")); + } + }; } diff --git a/src/main.cpp b/src/main.cpp index 238ef30..565da34 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -178,7 +178,23 @@ int main(int argc, char* argv[]) } std::cout<<"number of blocks: "< CBblocks = imcraw.list_blocks(imc::keys.at("CB")); + // for ( auto blk: CBblocks ) std::cout< CGblocks = imcraw.list_blocks(imc::keys.at("CG")); + // for ( auto blk: CGblocks ) std::cout< CCblocks = imcraw.list_blocks(imc::keys.at("CC")); + // for ( auto blk: CCblocks ) std::cout< CNblocks = imcraw.list_blocks(imc::keys.at("CN")); + // for ( auto blk: CNblocks ) std::cout< CSblocks = imcraw.list_blocks(imc::keys.at("CS")); + // for ( auto blk: CSblocks ) std::cout< groups = imcraw.list_groups(); + // for ( auto blk: groups ) std::cout< channels = imcraw.list_channels(); + // for ( auto blk: channels ) std::cout<