void MainWindow::on_connectAction_triggered(bool connect)
{
    if(connect)
    {
        ConnectDialog dlg(this);
        if(dlg.exec() == QDialog::Accepted)
        {
            if(dlg.connectionType() == Serial)
            {
                QSerialPort* serialPort = new QSerialPort(this);
                _ioDevice = serialPort;
                serialPort->setPort( dlg.serialPortInfo());
                if(serialPort->open(QIODevice::ReadWrite))
                {
                    // TODO hardcoded settings
                    if(!serialPort->setBaudRate(QSerialPort::Baud115200) ||
                        !serialPort->setDataBits(QSerialPort::Data8) ||
                        !serialPort->setParity(QSerialPort::NoParity) ||
                        !serialPort->setFlowControl(QSerialPort::NoFlowControl) ||
                        !serialPort->setStopBits(QSerialPort::TwoStop))
                    {
                        serialPort->close();
                        QMessageBox::critical(this, "Logger", "Can't configure serial port, reason: " + serialErrorString());
                        return;
                    }

                }
                else
                {
                    QMessageBox::critical(this, "Logger", "Serial port connection failed, reason: " + serialErrorString(), QMessageBox::Ok);
                    return;
                }
            }
            else if(dlg.connectionType() == File)
            {
                QFile* file = new QFile(dlg.fileName(), this);
                _ioDevice = file;
            }

            _logParser = new LogParser(_ioDevice, this);
            QObject::connect(_logParser, SIGNAL(logMessageReceived(QString)), SLOT(onLogMessageReceived(QString)));
            QObject::connect(_logParser, SIGNAL(packetParsed(Packet)), SLOT(onPacketParsed(Packet)));

           _logParser->setParent(0);
           _logParser->moveToThread(_parserThread);
            _parserThread->start();
            _logParser->openDevice();
        }
    }
    else
    {
        _ioDevice->close();
    }

    updateStatus();
}
Exemplo n.º 2
0
void LTWindow::stopRecording(bool autoStop)
{
    recording = false;
    ui->actionOpen->setEnabled(true);
    ui->actionRecord->setEnabled(true);
    ui->actionLT_files_data_base->setEnabled(true);
    ui->actionStop_recording->setEnabled(false);

    if (!autoStop)
        eventRecorder->stopRecording();

//    disconnect(streamReader, SIGNAL(packetParsed(Packet)), eventRecorder, SLOT(appendPacket(Packet)));
    disconnect(streamReader, SIGNAL(packetParsed(QPair<Packet, qint64>)), eventRecorder, SLOT(appendPacket(QPair<Packet, qint64>)));
}
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow)
{    
    qRegisterMetaType<Packet>();

    ui->setupUi(this);

    _packetsReceivedCount = 0;
    _crcErrorCount = 0;
    _bytesSkippedCount = 0;

    _serialPortComboBox = new QComboBox(this);
    connect(_serialPortComboBox, SIGNAL(currentIndexChanged(int)), SLOT(onSerialPortSelected(int)));

    _serialPort = new SerialPort(this);
    _logParser = new LogParser(_serialPort);
    connect(_logParser, SIGNAL(logMessageReceived(QString)), SLOT(onLogMessageReceived(QString)));
    connect(_logParser, SIGNAL(packetParsed(Packet)), SLOT(onPacketParsed(Packet)));

    initToolbar();
    initStatusbar();

    QThread readerThread;
    _logParser->setParent(0);
    _logParser->moveToThread(&readerThread);
    readerThread.start();

    detectSerialPorts();

    ui->plotWidget->addGraph();
    ui->plotWidget->graph(0)->setScatterStyle(QCP::ssDisc);
    ui->plotWidget->graph(0)->setScatterSize(5);
    ui->plotWidget->xAxis->setLabel("timestamp");
    ui->plotWidget->yAxis->setLabel("RSS [dBm]");
    ui->plotWidget->yAxis->setRange(-120, 0);
    ui->plotWidget->xAxis->setTickLabelType(QCPAxis::ltDateTime);
    ui->plotWidget->xAxis->setDateTimeFormat("hh:mm:ss:zzz");
    ui->plotWidget->xAxis->setTickLabelFont(QFont(QFont().family(), 8));
    ui->plotWidget->yAxis->setTickLabelFont(QFont(QFont().family(), 8));
}
Exemplo n.º 4
0
void LTWindow::startRecording(bool autoRecord)
{
    //if the current session is recorded while auto record has turned on we don't do anything
    if (autoRecord == true &&
        eventRecorder->isSessionRecorded() == true)
        return;

    recording = true;
    ui->actionStop_recording->setEnabled(true);
    ui->actionRecord->setEnabled(false);
    ui->actionLT_files_data_base->setEnabled(false);
//        ui->actionRecord->setIcon(QIcon(":/ui_icons/stop.png"));
    ui->actionOpen->setEnabled(false);
    eventRecorder->startRecording(delayWidget->getDelay());
//    connect(streamReader, SIGNAL(packetParsed(Packet)), eventRecorder, SLOT(appendPacket(Packet)));
    connect(streamReader, SIGNAL(packetParsed(QPair<Packet, qint64>)), eventRecorder, SLOT(appendPacket(QPair<Packet, qint64>)));

    if (!sessionTimer->isActive())
    {
        sessionTimer->start();
        driverTrackerWidget->startTimer();
    }
}
void LogParser::parseReceivedData()
{
    if(_receivedDataQueue->size() < 3)
        return;

    unsigned char start = _receivedDataQueue->dequeue();
    while(start != 0xDD && !_receivedDataQueue->isEmpty())
    {
        if(start != 0xFF) // skip bytes received when cable disconnected
            qDebug() << "skipping unexpected data" << QString().sprintf("0x%02x", start);

        start = _receivedDataQueue->dequeue();
    }

 /*   if(_receivedDataQueue->size() >= 1)
    {
        if(_receivedDataQueue->at(0) != LOG_TYPE_STRING &&
                _receivedDataQueue->at(0) !=LOG_TYPE_PHY_RX_RES &&
                _receivedDataQueue->at(0) != LOG_TYPE_DLL_RX_RES)
        {
            qWarning(qPrintable(QString().sprintf("Unexpected type: 0x%02x, skipping ...", _receivedDataQueue->at(0))));
            return;
        }
    }
*/
    if(_receivedDataQueue->size() < 2 || _receivedDataQueue->size() < _receivedDataQueue->at(1) + 2)
    {
        //  not a full packet, reinsert header and wait for more data ...
        _receivedDataQueue->insert(0, 0xDD);
        return;
    }

    u8 type = _receivedDataQueue->dequeue();
    u8 len = _receivedDataQueue->dequeue();

    if(type == LOG_TYPE_STRING)
    {
        QString msg;
        for(int i = 0; i < len; i++)
        {
            msg += QString(_receivedDataQueue->dequeue());
        }

        emit logMessageReceived(msg);
    }
    if(type == LOG_TYPE_PHY_RX_RES)
    {
        QByteArray packetData;
        unsigned char byte;
        for(int i = 0; i < len; i++)
        {
            byte = _receivedDataQueue->dequeue();
            packetData.append(byte);
        }

        Packet p;
        p.parsePhyRx(packetData);
        _packets.append(p);
    }
    if(type == LOG_TYPE_DLL_RX_RES)
    {
        QByteArray packetData;
        unsigned char byte;
        for(int i = 0; i < len; i++)
        {
            byte = _receivedDataQueue->dequeue();
            packetData.append(byte);
        }

        if(_packets.isEmpty())
        {
            qWarning("Received a DllRx while packets empty, probably the first log message received, skipping ...");
            return;
        }

        Packet lastPacket = _packets.last();
        if(lastPacket.hasDllInformation())
        {
            QString msg = "Out of sync, got DLL data while current packet instance already has parsed DLL data";
            qCritical(msg.toLocal8Bit());
            qDebug() << msg;
        }

        lastPacket.parseDllRx(packetData);

        emit logMessageReceived(lastPacket.toString());
        emit packetParsed(lastPacket);
    }

    parseReceivedData();
}