Пример #1
0
// Sentence
bool CATParser::receive(int iFd)
{
    // Make sure there's room for reading
    if (_uiCurrentBufferIndex >= sizeof(_acReceptionBuffer)) {

        // Ignore whatever we received already
        clear();
    }

    // Read all available bytes
    uint32_t uiPreviousBufferIndex = _uiCurrentBufferIndex;

    while (_uiCurrentBufferIndex < sizeof(_acReceptionBuffer)) {

        int iNbReadChars = read(iFd, &_acReceptionBuffer[_uiCurrentBufferIndex], sizeof(_acReceptionBuffer) - _uiCurrentBufferIndex);

        if (iNbReadChars < 0) {

            break;
        }

        _uiCurrentBufferIndex += iNbReadChars;
    }
    // We should have read something
    if (uiPreviousBufferIndex == _uiCurrentBufferIndex) {

        // Caught a signal or io error?
        return false;
    }

    // Process data
    return processReceivedData(uiPreviousBufferIndex);
}
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    resetPortList();

    //////////////////////////////////////////////////// for .svg display
    scene = new QGraphicsScene(this);
    ui->graphicsView->setScene(scene);
    ////////////////////////////////////////////////////

    this->bot = new spherebot();
    Receiver = new rxThread(this->bot);

    penDownAngle = DEFAULTPENDOWN;
    penUpAngle = DEFAULTPENUP;

    layerIndex = 0;

    connect(bot->port,  SIGNAL(readyRead()), Receiver,      SLOT(receiveData()));
    connect(bot,        SIGNAL(dataSent(QString)),this,     SLOT(sendDataUI(QString)));
    connect(bot,        SIGNAL(progressChanged(int)),this,  SLOT(refreshSendProgress(int)));
    //connect(bot,        SIGNAL(fileTransmitted()),this,     SLOT(finishedTransmission()));
    connect(Receiver,   SIGNAL(lineReceived(QString)),this, SLOT(processReceivedData(QString)));
    connect(Receiver,   SIGNAL(lineReceived(QString)),this->bot,  SLOT(processAnswer(QString)));

    initUI();
    initSateMachine();

    if(LoadSettings())
    {
        FitInTimer.setInterval(10);
        FitInTimer.setSingleShot(true);
        connect(&FitInTimer,SIGNAL(timeout()),this,SLOT(fitgraphicsView()));
        FitInTimer.start();
    }

    setWindowTitle("Spherebot Controll");

    qDebug()<<"mainwindow initialised: ";
    connect(restartLayerMsgBox,SIGNAL(accepted()),this,SLOT(hey()));
}