bool StringStream::get( uint32 &chr ) { if( popBuffer( chr ) ) return true; m_b->m_mtx.lock(); if ( m_b->m_str == 0 ) { m_b->m_mtx.unlock(); m_status = t_error; return false; } if( m_pos == m_b->m_str->size() ) { m_status = m_status | t_eof; m_b->m_mtx.unlock(); return false; } else { int32 cs = m_b->m_str->manipulator()->charSize(); chr = m_b->m_str->getCharAt( m_pos/cs ); // manipulator may have changed. m_pos += cs; } m_b->m_mtx.unlock(); return true; }
void msgWork(const Pothos::Packet &inPkt) { //calculate conversion and buffer sizes (round up) const size_t numSyms = (inPkt.payload.length + _mod - 1)/_mod; //create a new packet for output symbols Pothos::Packet outPkt; auto outPort = this->output(0); if (outPort->elements() >= numSyms) { outPkt.payload = outPort->buffer(); outPkt.payload.length = numSyms; outPort->popBuffer(numSyms); } else outPkt.payload = Pothos::BufferChunk(outPort->dtype(), numSyms); //perform conversion auto in = inPkt.payload.as<const unsigned char*>(); auto out = outPkt.payload.as<unsigned char*>(); switch (_order) { case MSBit: ::bitsToSymbolsMSBit(_mod, in, out, numSyms); break; case LSBit: ::bitsToSymbolsLSBit(_mod, in, out, numSyms); break; } //copy and adjust labels for (const auto &label : inPkt.labels) { outPkt.labels.push_back(label.toAdjusted(1, _mod)); } //post the output packet outPort->postMessage(outPkt); }
void SynChan::process( const Eref& e, ProcPtr info ) { // while ( !pendingEvents_.empty() && // pendingEvents_.top().getDelay() <= info->currTime ) { activation_ += popBuffer(info->currTime) / info->dt; // pendingEvents_.pop(); // } X_ = modulation_ * activation_ * xconst1_ + X_ * xconst2_; Y_ = X_ * yconst1_ + Y_ * yconst2_; double Gk = Y_ * norm_; setGk( Gk ); updateIk(); activation_ = 0.0; modulation_ = 1.0; SynChanBase::process( e, info ); // Sends out messages for channel. }
bool StringStream::readString( String &target, uint32 size ) { uint32 chr; target.size(0); target.manipulator( &csh::handler_buffer ); while ( size > 0 && popBuffer(chr) ) { target += chr; --size; } if( size == 0 ) { return true; } m_b->m_mtx.lock(); if ( m_b->m_str == 0 ) { m_b->m_mtx.unlock(); m_status = t_error; return false; } String* src = m_b->m_str; int csize = src->manipulator()->charSize(); int tglen = src->length(); uint32 start = (m_pos / csize); if ( start >= tglen ) { m_status = m_status | t_eof; m_b->m_mtx.unlock(); return false; } uint32 end = start + size; if ( end > tglen ) { end = tglen; } target = src->subString(start,end); m_pos = end * csize; m_b->m_mtx.unlock(); return true; }
void NetworkSource::work(void) { const auto timeout = Poco::Timespan(this->workInfo().maxTimeoutNs/1000); auto outputPort = this->output(0); //recv the header, use output buffer when possible for zero-copy Poco::UInt16 type; Poco::UInt64 index; auto buffer = outputPort->buffer(); _ep.recv(type, index, buffer, timeout); //handle the output if (type == PothosPacketTypeBuffer) { _nextExpectedIndex = index + buffer.length; outputPort->popBuffer(buffer.length); outputPort->postBuffer(buffer); } else if (type == PothosPacketTypeMessage) { std::istringstream iss(std::string(buffer.as<char *>(), buffer.length)); Pothos::Object msg; msg.deserialize(iss); outputPort->postMessage(msg); } else if (type == PothosPacketTypeLabel) { std::istringstream iss(std::string(buffer.as<char *>(), buffer.length)); Pothos::Label label; label.index = index + outputPort->totalElements() - _nextExpectedIndex; label.data.deserialize(iss); outputPort->postLabel(label); } else this->yield(); }