* add support for datatype 11 = 2-byte-word digital

* usage.py: raise proper exception
* usage_adv.py: use different example file
This commit is contained in:
Mario Fink 2021-04-27 11:38:43 +02:00
parent 8708d2d008
commit 2b2e69f0e5
4 changed files with 39 additions and 14 deletions

View File

@ -149,7 +149,9 @@ namespace imc
// constructor takes channel's block environment // constructor takes channel's block environment
channel(channel_env chnenv, std::map<std::string,imc::block>* blocks, channel(channel_env chnenv, std::map<std::string,imc::block>* blocks,
std::vector<unsigned char>* buffer): std::vector<unsigned char>* buffer):
chnenv_(chnenv), blocks_(blocks), buffer_(buffer), group_index_(-1) chnenv_(chnenv), blocks_(blocks), buffer_(buffer),
factor_(1.), offset_(0.),
group_index_(-1)
{ {
// declare list of block parameters // declare list of block parameters
std::vector<imc::parameter> prms; std::vector<imc::parameter> prms;
@ -292,6 +294,11 @@ namespace imc
{ {
imc::convert_data_to_type<imc_double>(CSbuffer,ydata_); imc::convert_data_to_type<imc_double>(CSbuffer,ydata_);
} }
// ...
else if ( datatp_ == 11 )
{
imc::convert_data_to_type<imc_digital>(CSbuffer,ydata_);
}
else else
{ {
throw std::runtime_error(std::string("unsupported/unknown datatype") + std::to_string(datatp_)); throw std::runtime_error(std::string("unsupported/unknown datatype") + std::to_string(datatp_));

View File

@ -16,7 +16,11 @@ namespace imc
typedef signed long int imc_Slongint; typedef signed long int imc_Slongint;
typedef float imc_float; typedef float imc_float;
typedef double imc_double; typedef double imc_double;
// TODO remaining types are not yet supported // TODO not all remaining types are supported yet
// typedef <whatever that is ->... > "imc Devices Transitional Recording"
// typedf <sometimestamptype> "Timestamp Ascii"
typedef char16_t imc_digital;
// typedef < > imc_sixbyte "6byte unsigned long"
class datatype class datatype
{ {
@ -29,12 +33,14 @@ namespace imc
imc_Slongint slint_; // 5 imc_Slongint slint_; // 5
imc_float sfloat_; // 6 imc_float sfloat_; // 6
imc_double sdouble_; // 7 imc_double sdouble_; // 7
short int dtidx_; // \in \{0,...,7\} imc_digital sdigital_; // 10
short int dtidx_; // \in \{0,...,7,10\}
public: public:
datatype(): ubyte_(0), sbyte_(0), datatype(): ubyte_(0), sbyte_(0),
ushort_(0), sshort_(0), ushort_(0), sshort_(0),
ulint_(0.0), slint_(0.0), ulint_(0.0), slint_(0.0),
sfloat_(0.0), sdouble_(0.0), sfloat_(0.0), sdouble_(0.0),
sdigital_(0),
dtidx_(0) { }; dtidx_(0) { };
// every supported datatype gets its own constructor // every supported datatype gets its own constructor
datatype(imc_Ubyte num): ubyte_(num), dtidx_(0) {}; datatype(imc_Ubyte num): ubyte_(num), dtidx_(0) {};
@ -46,7 +52,10 @@ namespace imc
datatype(imc_float num): sfloat_(num), dtidx_(6) {}; datatype(imc_float num): sfloat_(num), dtidx_(6) {};
datatype(imc_double num): ubyte_(0), sbyte_(0), ushort_(0), sshort_(0), datatype(imc_double num): ubyte_(0), sbyte_(0), ushort_(0), sshort_(0),
ulint_(0.0), slint_(0.0), sfloat_(0.0), sdouble_(num), ulint_(0.0), slint_(0.0), sfloat_(0.0), sdouble_(num),
dtidx_(7) {}; sdigital_(0), dtidx_(7) {};
datatype(imc_digital num): ubyte_(0), sbyte_(0), ushort_(0), sshort_(0),
ulint_(0.0), slint_(0.0), sfloat_(0.0), sdouble_(num),
sdigital_(num), dtidx_(10) {};
// identify type // identify type
short int& dtype() { return dtidx_; } short int& dtype() { return dtidx_; }
@ -64,6 +73,7 @@ namespace imc
this->slint_ = num.slint_; this->slint_ = num.slint_;
this->sfloat_ = num.sfloat_; this->sfloat_ = num.sfloat_;
this->sdouble_ = num.sdouble_; this->sdouble_ = num.sdouble_;
this->sdigital_ = num.sdigital_;
this->dtidx_ = num.dtidx_; this->dtidx_ = num.dtidx_;
} }
@ -119,6 +129,12 @@ namespace imc
this->dtidx_ = 7; this->dtidx_ = 7;
return *this; return *this;
} }
datatype& operator=(const imc_digital &num)
{
this->sdigital_ = num;
this->dtidx_ = 10;
return *this;
}
// obtain number as double // obtain number as double
double as_double() double as_double()
@ -132,6 +148,7 @@ namespace imc
else if ( dtidx_ == 5 ) num = (double)slint_; else if ( dtidx_ == 5 ) num = (double)slint_;
else if ( dtidx_ == 6 ) num = (double)sfloat_; else if ( dtidx_ == 6 ) num = (double)sfloat_;
else if ( dtidx_ == 7 ) num = (double)sdouble_; else if ( dtidx_ == 7 ) num = (double)sdouble_;
else if ( dtidx_ == 10 ) num = static_cast<double>(sdigital_);
return num; return num;
} }
@ -146,6 +163,7 @@ namespace imc
else if ( num.dtidx_ == 5 ) out<<num.slint_; else if ( num.dtidx_ == 5 ) out<<num.slint_;
else if ( num.dtidx_ == 6 ) out<<num.sfloat_; else if ( num.dtidx_ == 6 ) out<<num.sfloat_;
else if ( num.dtidx_ == 7 ) out<<num.sdouble_; else if ( num.dtidx_ == 7 ) out<<num.sdouble_;
else if ( num.dtidx_ == 10 ) out<<static_cast<double>(num.sdigital_);
return out; return out;
} }

View File

@ -6,7 +6,7 @@ import json
try : try :
imcraw = imc_termite.imctermite(b"samples/sampleA.raw") imcraw = imc_termite.imctermite(b"samples/sampleA.raw")
except RuntimeError as e : except RuntimeError as e :
print("failed to load/parse raw-file: " + str(e)) raise Exception("failed to load/parse raw-file: " + str(e))
# obtain list of channels as list of dictionaries (without data) # obtain list of channels as list of dictionaries (without data)
channels = imcraw.get_channels(False) channels = imcraw.get_channels(False)

View File

@ -8,7 +8,7 @@ from pathlib import Path
# list files in sample directory # list files in sample directory
# fileobj1 = Path("samples/").rglob("*.raw") # fileobj1 = Path("samples/").rglob("*.raw")
# rawlist1 = [str(fl) for fl in fileobj1] # rawlist1 = [str(fl) for fl in fileobj1]
rawlist1 = ["samples/datasetB/datasetB_32.raw"] rawlist1 = ["samples/datasetB/datasetB_29.raw"]
print(rawlist1) print(rawlist1)
for fl in rawlist1: for fl in rawlist1: