555 vector< adc16_t > chdata;
556 deque< bitset<1> > bitqueue;
559 short lastdelta = -999;
569 while( adc.size() != nch*seqlen )
571 if(byteidx<bufsize)
ReadNextByte(byteidx, buf, bitqueue);
576 msg_err<<
"There seems to be a problem with decoding"<<
endl 577 <<
"Bytes read "<<byteidx<<
" out of "<<bufsize<<
endl 578 <<
"Samples accumulated in this channel "<<chdata.size()<<
endl 579 <<
"Remaining bits are "<<bitqueue.size()<<
" "<<bitqueue.empty()<<
endl;
584 if( bitqueue.size() <
m_PacketSize && byteidx != bufsize)
587 bool iscomp = bitqueue.front().test(0);
589 bitqueue.pop_front();
597 msg_err<<
"Fatal decoding error has been encountered : "<<
endl 598 <<
" Number of bits in the uncompressed stream should be at least " 599 <<
m_NbitsHC<<
" the current value is "<<bitqueue.size()<<
endl;
603 size_t bitcounter = 0;
606 ss << bitqueue.front();
607 bitqueue.pop_front();
610 bitsread += bitcounter;
612 adc16_t val = ( strtoul(ss.str().c_str(), 0, 2) & 0x7FFF );
613 chdata.push_back( val );
618 size_t bitcounter = 0;
621 bitstoread = bitqueue.size();
623 while( bitcounter < bitstoread )
625 ss << bitqueue.front();
626 bitqueue.pop_front();
630 size_t strsize = ss.str().size();
633 bool ok = (
m_UCmMap[strsize-1].first == ss.str());
635 short val =
m_UCmMap[strsize-1].second;
644 chdata.push_back( newval );
651 adc16_t newval = chdata.back() + lastdelta;
652 chdata.push_back( newval );
658 if(chdata.size() == seqlen)
break;
664 if(chdata.size() == seqlen)
674 <<
"Bits read : "<<bitsread<<
endl 675 <<
"Bits to boundary : "<<padbits<<
endl 676 <<
"Last value : "<<chdata.back()<<
" ADC "<<
endl;
680 if( bitqueue.size() < padbits )
682 msg_err<<
"Fatal decoding error has been encountered : "<<
endl 683 <<
"Byte boundary does not appear to be valid"<<
endl 684 <<
"Check that the codes are padded with 0 to the next byte boundary"<<
endl;
691 bitqueue.pop_front();
696 if(!bitqueue.empty())
698 if(bitqueue.front().test(0) && chread <= (nch-1) )
700 msg_err<<
"Fatal decoding error had been encounter : "<<
endl 701 <<
"The first bit of the next ch sequence should always be 0 and not " 702 <<bitqueue.front()<<
endl;
711 adc.insert(adc.end(), chdata.begin(), chdata.end() );
716 cout<<
"Decoded "<<adc.size()<<
" samples"<<
endl<<
endl;
723 if(bitqueue.size() > 0)
725 msg_info<<
"Bits remaning in the queue "<<bitqueue.size()<<
endl;
733 msg_info<<
"Bits remaning in the queue "<<bitqueue.size()<<
endl;
std::vector< std::pair< std::string, short > > m_UCmMap
bool SetNbitsAdc(short nbadc)
static LogStream msg_info(std::cout, _strinfo)
void ReadNextByte(size_t &byteidx, const char *buf, std::deque< std::bitset< 1 > > &bits)
static LogStream msg_err(std::cerr, _strerror)
QTextStream & endl(QTextStream &s)