Ejemplo n.º 1
0
int main(int argc, char** argv) {
    if(argc != 3) {
        fprintf(stderr, "usage: %s port speed\n", argv[0]);
        return 1;
    }

    char *portname = argv[1];
    int fd = open (portname, O_RDWR | O_NOCTTY | O_SYNC);
    if (fd < 0)
    {
        error_message ("error %d opening %s: %s", errno, portname, strerror (errno));
        return 1;
    }

    set_interface_attribs (fd, B19200, 0);  // set speed to 115,200 bps, 8n1 (no parity)
    set_blocking (fd, 0);                // set no blocking

    sendMessage(fd, COMMAND_SYNC_STREAM, COMMAND_SYNC_STREAM);
    sendMessage(fd, COMMAND_SET_SPEED, 500);

    Message msg;
    while(!hasMessage(&msg, fd));

    printf("message type = %d: high = %d low = %d\n", msg.type, msg.payload_high, msg.payload_low);
}
Ejemplo n.º 2
0
    void work(void)
    {
        auto inPort = this->input(0);
        auto outPort = this->output(0);
        inPort->setReserve(_mod);

        //handle packet conversion if applicable
        if (inPort->hasMessage())
        {
            auto msg = inPort->popMessage();
            if (msg.type() == typeid(Pothos::Packet))
                this->msgWork(msg.extract<Pothos::Packet>());
            else outPort->postMessage(msg);
            return; //output buffer used, return now
        }

        //calculate work size
        const size_t numSyms = std::min(inPort->elements() / _mod, outPort->elements());
        if (numSyms == 0) return;

        //perform conversion
        auto in = inPort->buffer().as<const unsigned char *>();
        auto out = outPort->buffer().as<unsigned char *>();
        switch (_order)
        {
        case MSBit: ::bitsToSymbolsMSBit(_mod, in, out, numSyms); break;
        case LSBit: ::bitsToSymbolsLSBit(_mod, in, out, numSyms); break;
        }

        //produce/consume
        inPort->consume(numSyms * _mod);
        outPort->produce(numSyms);
    }
Ejemplo n.º 3
0
    void work(void)
    {
        auto inputPort = this->input(0);
        auto outputPort = this->output(0);

        while (inputPort->hasMessage())
        {
            auto m = inputPort->popMessage();
            outputPort->postMessage(m);
        }

        const auto &buffer = inputPort->buffer();
        if (buffer.length != 0)
        {
            outputPort->postBuffer(buffer);
            inputPort->consume(inputPort->elements());

            for (size_t i = 0; i < inputPort->elements(); i++)
            {
                if (std::generate_canonical<double, 10>(_gen) <= _probability)
                {
                    Pothos::Label label;
                    label.index = i;
                    label.width = buffer.dtype.size();
                    if (not _ids.empty()) label.id = _ids.at(_randomId(_gen));
                    outputPort->postLabel(label);
                }
            }
        }
    }
Ejemplo n.º 4
0
int FuzzyCom::update() {
  if (Serial.available() > 0) {
    read();
    return hasMessage();
  } else {
    return false;
  }
}
Ejemplo n.º 5
0
void Exception::formatEntry(std::ostream &stream, size_t depth) const {
	LocaleUtils::CLocaleScope localeScope(stream);

	if (depth > maxDepth_) {
		return;
	}

	if (hasTypeName(depth)) {
		formatTypeName(stream, depth);
	}
	else {
		stream << "(Unknown exception)";
	}

	if (hasFileName(depth)) {
		stream << " ";
		formatFileName(stream, depth);
	}

	if (hasFunctionName(depth)) {
		stream << " ";
		formatFunctionName(stream, depth);
	}

	if (hasLineNumber(depth)) {
		stream << " line=" << getLineNumber(depth);
	}

	if (hasErrorCode(depth)) {
		stream << " [";

		if (!hasErrorCodeName(depth)) {
			stream << "Code:";
		}

		stream << getErrorCode(depth);

		if (hasErrorCodeName(depth)) {
			stream << ":";
			formatErrorCodeName(stream, depth);
		}

		stream << "]";
	}

	if (hasMessage(depth)) {
		stream << " " ;
		formatMessage(stream, depth);
	}
#ifdef UTIL_STACK_TRACE_ENABLED

	if (hasStackTrace(depth)) {
		stream << " : " ;
		formatStackTrace(stream, depth);
	}
#endif
}
Ejemplo n.º 6
0
 void work(void)
 {
     auto in0 = this->input("in0");
     if (in0->hasMessage())
     {
         in0->popMessage();
         triggered++;
     }
 }
Ejemplo n.º 7
0
    /*******************************************************************
     * Streaming implementation
     ******************************************************************/
    void work(void)
    {
        //handle input messages in the packet work method
        auto inPort0 = this->input(0);
        if (_channels.size() <= 1 and inPort0->hasMessage()) this->packetWork();

        int flags = 0;
        long long timeNs = 0;
        size_t numElems = this->workInfo().minInElements;
        if (numElems == 0) return;

        //parse labels (from input 0)
        for (const auto &label : inPort0->labels())
        {
            //skip out of range labels
            if (label.index >= numElems) break;

            //found a time label
            if (label.id == "txTime")
            {
                if (label.index == 0) //time for this packet
                {
                    flags |= SOAPY_SDR_HAS_TIME;
                    timeNs = label.data.convert<long long>();
                }
                else //time on the next packet
                {
                    //truncate to not include this time label
                    numElems = label.index;
                    break;
                }
            }
            //found an end label
            if (label.id == "txEnd")
            {
                flags |= SOAPY_SDR_END_BURST;
                numElems = std::min<size_t>(label.index+label.width, numElems);
                break;
            }
        }

        //write the stream data
        const long timeoutUs = this->workInfo().maxTimeoutNs/1000;
        const auto &buffs = this->workInfo().inputPointers;
        const int ret = _device->writeStream(_stream, buffs.data(), numElems, flags, timeNs, timeoutUs);

        //handle result
        if (ret > 0) for (auto input : this->inputs()) input->consume(size_t(ret));
        else if (ret == SOAPY_SDR_TIMEOUT) return this->yield();
        else
        {
            for (auto input : this->inputs()) input->consume(numElems); //consume error region
            throw Pothos::Exception("SDRSink::work()", "writeStream "+std::string(SoapySDR::errToStr(ret)));
        }
    }
Ejemplo n.º 8
0
 void work(void)
 {
     workCount++;
     auto in0 = this->input("in0");
     auto out0 = this->output("out0");
     if (in0->hasMessage())
     {
         auto msg = in0->popMessage();
         out0->postMessage(msg);
     }
 }
Ejemplo n.º 9
0
FCoreApp::~FCoreApp()
{
  if(!hasMessage())   verbose(FUNC, QObject::tr("Done."));
  else if(hasFatal()) verbose(FUNC, QObject::tr("Houston, we have a problem."));
  else if(hasError()) verbose(FUNC, QObject::tr("Exit with error."));
  else verbose(FUNC, QObject::tr("Not the best."));

  if(hasConfigError()) return;

  delete mCmd;
}
Ejemplo n.º 10
0
//Sse a message that has already been made
//sets startTime of iMessage to current time
ofxMessage* ofxObject::doMessage(ofxMessage *iMessage)
{
	if (iMessage->id == OF_FUNCTION) {
		iMessage->autoDelete = false;
	} else {
    //iMessage->setStartTime(ofGetElapsedTimef());
    iMessage->setStartTime(curTime);
  }
	iMessage->enableMessage(true);
	if(!hasMessage(iMessage))	//only add it if it's not already there
		messages.push_back(iMessage);
	
	return iMessage;
}
Ejemplo n.º 11
0
/***********************************************************************
 * work function
 **********************************************************************/
void SpectrogramDisplay::work(void)
{
    auto updateRate = this->height()/_timeSpan;
    if (updateRate != _lastUpdateRate) this->callVoid("updateRateChanged", updateRate);
    _lastUpdateRate = updateRate;

    auto inPort = this->input(0);
    if (not inPort->hasMessage()) return;
    const auto msg = inPort->popMessage();

    //label-based messages have in-line commands
    if (msg.type() == typeid(Pothos::Label))
    {
        const auto &label = msg.convert<Pothos::Label>();
        if (label.id == _freqLabelId and label.data.canConvert(typeid(double)))
        {
            this->setCenterFrequency(label.data.convert<double>());
        }
        if (label.id == _rateLabelId and label.data.canConvert(typeid(double)))
        {
            this->setSampleRate(label.data.convert<double>());
        }
    }

    //packet-based messages have payloads to FFT
    if (msg.type() == typeid(Pothos::Packet))
    {
        const auto &buff = msg.convert<Pothos::Packet>().payload;
        auto floatBuff = buff.convert(Pothos::DType(typeid(std::complex<float>)), buff.elements());

        //safe guard against FFT size changes, old buffers could still be in-flight
        if (floatBuff.elements() != this->numFFTBins()) return;

        //handle automatic FFT mode
        if (_fftModeAutomatic)
        {
            const bool isComplex = buff.dtype.isComplex();
            const bool changed = _fftModeComplex != isComplex;
            _fftModeComplex = isComplex;
            if (changed) QMetaObject::invokeMethod(this, "handleUpdateAxis", Qt::QueuedConnection);
        }

        //power bins to points on the curve
        CArray fftBins(floatBuff.as<const std::complex<float> *>(), this->numFFTBins());
        const auto powerBins = _fftPowerSpectrum.transform(fftBins, _fullScale);
        this->appendBins(powerBins);
    }
}
Ejemplo n.º 12
0
Archivo: main.c Proyecto: mrlambo/chat
int main(int argc, char *argv[])
{
    Peer* peer;
    SDL_Thread *input_thread;

    if(!menu(&peer))
        exit(1);

    input_thread = SDL_CreateThread(input, "Input", (void*)peer);

    if(!input_thread)
    {
        printf("\nSDL_CreateThread failed: %s\n", SDL_GetError());
        exit(1);
    }

    while(!done)
    {
        if(!checkPackets(peer))
            done = 1;

        if(hasMessage(peer))
        {
            switch(getMessageType(peer))
            {
            case 0:
                break;
            case 1:
                printf("%s\n", getMessage(peer));
                break;
            case 2:
                printf("[PM] %s\n", getMessage(peer));
                break;
            case 3:
                break;
            default:
                printf("mensagem desconhecida: %d\n", getMessageType(peer));
            }

            flushClientState(peer);
        }
    }

    SDL_WaitThread(input_thread, NULL);
    disconnect(peer);

    return 0;
}
Ejemplo n.º 13
0
void ConstellationDisplay::work(void)
{
    auto inPort = this->input(0);

    if (not inPort->hasMessage()) return;
    const auto msg = inPort->popMessage();

    //packet-based messages have payloads to plot
    if (msg.type() == typeid(Pothos::Packet))
    {
        _queueDepth++;
        const auto &buff = msg.convert<Pothos::Packet>().payload;
        auto floatBuff = buff.convert(Pothos::DType(typeid(std::complex<float>)), buff.elements());
        QMetaObject::invokeMethod(this, "handleSamples", Qt::QueuedConnection, Q_ARG(Pothos::BufferChunk, floatBuff));
    }
}
Ejemplo n.º 14
0
    void work(void)
    {
        auto inputPort = this->input(0);
        auto outputPort = this->output(0);

        //extract message
        if (not inputPort->hasMessage()) return;
        auto msg = inputPort->popMessage();

        //forward non-packet messages
        if (msg.type() != typeid(Pothos::Packet))
        {
            outputPort->postMessage(msg);
            return;
        }
        const auto &packet = msg.extract<Pothos::Packet>();

        //post output labels
        for (auto label : packet.labels)
        {
            outputPort->postLabel(label.toAdjusted(
                packet.payload.dtype.size(), 1)); //elements to bytes
        }

        //post start of frame label
        if (not _frameStartId.empty())
        {
            outputPort->postLabel(Pothos::Label(_frameStartId, Pothos::Object(), 0, packet.payload.dtype.size()));
        }

        //post end of frame label
        if (not _frameEndId.empty())
        {
            outputPort->postLabel(Pothos::Label(_frameEndId, Pothos::Object(), packet.payload.length-1, packet.payload.dtype.size()));
        }

        //post the payload
        outputPort->postBuffer(packet.payload);
    }
Ejemplo n.º 15
0
    void work(void)
    {
        auto inputPort = this->input(0);
        auto outputPort = this->output(0);

        while (inputPort->hasMessage() and _elementsLeft != 0)
        {
            auto m = inputPort->popMessage();
            outputPort->postMessage(m);
            _elementsLeft -= 1;
        }

        auto buffer = inputPort->buffer();
        //input port type unspecified, inspect buffer for actual element count
        const size_t elems = std::min(_elementsLeft, buffer.elements());
        if (elems != 0)
        {
            buffer.length = elems*buffer.dtype.size();
            outputPort->postBuffer(buffer);
            inputPort->consume(buffer.length);
            _elementsLeft -= elems;
        }
    }
Ejemplo n.º 16
0
    void work(void)
    {
        auto inputPort = this->input(0);
        auto outputPort = this->output(0);

        //forward messages
        while (inputPort->hasMessage())
        {
            auto msg = inputPort->popMessage();
            outputPort->postMessage(msg);
        }

        //is there any input buffer available?
        if (inputPort->elements() == 0) return;

        //start frame mode has its own work implementation
        if (_startFrameMode) return this->startFrameModeWork();

        //drop until start of frame label
        if (_fullFrameMode and not _inFrame)
        {
            for (const auto &label : inputPort->labels())
            {
                //end of input buffer labels, exit loop
                if (label.index >= inputPort->elements()) break;

                //ignore labels that are not start of frame
                if (label.id != _frameStartId) continue;

                //in position 0, set in frame, done loop
                if (label.index == 0)
                {
                    _inFrame = true;
                    break;
                }

                //otherwise consume up to but not including
                //done work, will be in-frame for next work
                else
                {
                    inputPort->consume(label.index);
                    _inFrame = true;
                    return;
                }
            }

            //start of frame not found, consume everything, exit this work
            if (not _inFrame)
            {
                inputPort->consume(inputPort->elements());
                return;
            }
        }

        //grab the input buffer
        Pothos::Packet packet;
        packet.payload = inputPort->buffer();
        if (_mtu != 0)
        {
            const auto elemSize = packet.payload.dtype.size();
            const auto mtuElems = (_mtu/elemSize)*elemSize;
            packet.payload.length = std::min(mtuElems, packet.payload.length);
        }

        //grab the input labels
        for (const auto &label : inputPort->labels())
        {
            const auto pktLabel = label.toAdjusted(
                1, packet.payload.dtype.size()); //bytes to elements
            if (pktLabel.index >= packet.payload.elements()) break;
            packet.labels.push_back(pktLabel);

            //end of frame found, truncate payload and leave loop
            if (_fullFrameMode and label.id == _frameEndId)
            {
                packet.payload.length = label.index+label.width;
                _inFrame = false;
                break;
            }
        }

        //consume the input and produce the packet
        inputPort->consume(packet.payload.length);
        outputPort->postMessage(packet);
    }