Moved all the parsing to other thread (MAJOR boost in speed)
This commit is contained in:
parent
e904d4499e
commit
7dd5da143e
@ -21,7 +21,8 @@ SOURCES += main.cpp\
|
|||||||
errorwindow.cpp \
|
errorwindow.cpp \
|
||||||
erroricon.cpp \
|
erroricon.cpp \
|
||||||
sdwindow.cpp \
|
sdwindow.cpp \
|
||||||
eepromwindow.cpp
|
eepromwindow.cpp \
|
||||||
|
parser.cpp
|
||||||
|
|
||||||
HEADERS += mainwindow.h \
|
HEADERS += mainwindow.h \
|
||||||
settingswindow.h \
|
settingswindow.h \
|
||||||
@ -30,7 +31,8 @@ HEADERS += mainwindow.h \
|
|||||||
erroricon.h \
|
erroricon.h \
|
||||||
sdwindow.h \
|
sdwindow.h \
|
||||||
repraptor.h \
|
repraptor.h \
|
||||||
eepromwindow.h
|
eepromwindow.h \
|
||||||
|
parser.h
|
||||||
|
|
||||||
FORMS += mainwindow.ui \
|
FORMS += mainwindow.ui \
|
||||||
settingswindow.ui \
|
settingswindow.ui \
|
||||||
|
|||||||
@ -37,7 +37,7 @@ EEPROMWindow::EEPROMWindow(QStringList eepromLines, QWidget *parent) :
|
|||||||
hline->setFrameShadow(QFrame::Sunken);
|
hline->setFrameShadow(QFrame::Sunken);
|
||||||
line->addWidget(hline);
|
line->addWidget(hline);
|
||||||
|
|
||||||
edit->setObjectName("e"+QString::number(j));
|
edit->setObjectName("e"+QString::number(j)); //Name the LineEdit, so when it emits signal we know where it came from
|
||||||
|
|
||||||
QRegExpValidator *doublevalidator = new QRegExpValidator(
|
QRegExpValidator *doublevalidator = new QRegExpValidator(
|
||||||
QRegExp("^\\-?\\d+\\.?\\d+(e\\-?\\d+)?$",
|
QRegExp("^\\-?\\d+\\.?\\d+(e\\-?\\d+)?$",
|
||||||
|
|||||||
@ -59,6 +59,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
userCommand = "";
|
userCommand = "";
|
||||||
currentLine = 0;
|
currentLine = 0;
|
||||||
readyRecieve = 0;
|
readyRecieve = 0;
|
||||||
|
lastRecieved = 0;
|
||||||
readingEEPROM = false;
|
readingEEPROM = false;
|
||||||
EEPROMReadingStarted = false;
|
EEPROMReadingStarted = false;
|
||||||
|
|
||||||
@ -77,11 +78,28 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus()));
|
connect(&statusTimer, SIGNAL(timeout()), this, SLOT(checkStatus()));
|
||||||
connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
connect(&sendTimer, SIGNAL(timeout()), this, SLOT(sendNext()));
|
||||||
connect(&statusWatcher, SIGNAL(finished()), this, SLOT(updateStatus()));
|
connect(&statusWatcher, SIGNAL(finished()), this, SLOT(updateStatus()));
|
||||||
connect(&sdWatcher, SIGNAL(finished()), this, SLOT(updateSDStatus()));
|
|
||||||
connect(this, SIGNAL(sdReady()), this, SLOT(initSDprinting()));
|
|
||||||
connect(&progressSDTimer, SIGNAL(timeout()), this, SLOT(checkSDStatus()));
|
connect(&progressSDTimer, SIGNAL(timeout()), this, SLOT(checkSDStatus()));
|
||||||
connect(this, SIGNAL(eepromReady()), this, SLOT(openEEPROMeditor()));
|
connect(this, SIGNAL(eepromReady()), this, SLOT(openEEPROMeditor()));
|
||||||
|
|
||||||
|
qRegisterMetaType<TemperatureReadings>("TemperatureReadings");
|
||||||
|
parser = new Parser();
|
||||||
|
parserThread = new QThread();
|
||||||
|
parser->moveToThread(parserThread);
|
||||||
|
connect(parserThread, &QThread::finished, parser, &QObject::deleteLater);
|
||||||
|
connect(this, &MainWindow::recievedData, parser, &Parser::parse);
|
||||||
|
connect(this, &MainWindow::startedReadingEEPROM, parser, &Parser::setEEPROMReadingMode);
|
||||||
|
connect(parser, &Parser::recievedTemperature, this, &MainWindow::updateTemperature);
|
||||||
|
connect(parser, &Parser::recievedOkNum, this, &MainWindow::recievedOkNum);
|
||||||
|
connect(parser, &Parser::recievedOkWait, this, &MainWindow::recievedWait);
|
||||||
|
connect(parser, &Parser::recievedSDFilesList, this, &MainWindow::initSDprinting);
|
||||||
|
connect(parser, &Parser::recievedEEPROMLine, this, &MainWindow::EEPROMSettingRecieved);
|
||||||
|
connect(parser, &Parser::recievingEEPROMDone, this, &MainWindow::openEEPROMeditor);
|
||||||
|
connect(parser, &Parser::recievedError, this, &MainWindow::recievedError);
|
||||||
|
connect(parser, &Parser::recievedSDDone, this, &MainWindow::recievedSDDone);
|
||||||
|
connect(parser, &Parser::recievedResend, this, &MainWindow::recievedResend);
|
||||||
|
connect(parser, &Parser::recievedSDUpdate, this, &MainWindow::updateSDStatus);
|
||||||
|
parserThread->start();
|
||||||
|
|
||||||
if(settings.value("core/statusinterval").toInt()) statusTimer.setInterval(settings.value("core/statusinterval").toInt());
|
if(settings.value("core/statusinterval").toInt()) statusTimer.setInterval(settings.value("core/statusinterval").toInt());
|
||||||
else statusTimer.setInterval(3000);
|
else statusTimer.setInterval(3000);
|
||||||
statusTimer.start();
|
statusTimer.start();
|
||||||
@ -108,6 +126,8 @@ MainWindow::~MainWindow()
|
|||||||
{
|
{
|
||||||
if(gfile.isOpen()) gfile.close();
|
if(gfile.isOpen()) gfile.close();
|
||||||
if(printer.isOpen()) printer.close();
|
if(printer.isOpen()) printer.close();
|
||||||
|
parserThread->quit();
|
||||||
|
parserThread->wait();
|
||||||
|
|
||||||
if(firstrun) settings.setValue("core/firstrun", true); //firstrun is inverted!
|
if(firstrun) settings.setValue("core/firstrun", true); //firstrun is inverted!
|
||||||
|
|
||||||
@ -457,6 +477,8 @@ void MainWindow::on_haltbtn_clicked()
|
|||||||
|
|
||||||
void MainWindow::readSerial()
|
void MainWindow::readSerial()
|
||||||
{
|
{
|
||||||
|
QByteArray data = printer.readLine();
|
||||||
|
/*
|
||||||
if(printer.canReadLine())
|
if(printer.canReadLine())
|
||||||
{
|
{
|
||||||
QByteArray data = printer.readLine();
|
QByteArray data = printer.readLine();
|
||||||
@ -541,9 +563,9 @@ void MainWindow::readSerial()
|
|||||||
sdFiles.clear();
|
sdFiles.clear();
|
||||||
readingFiles = true; //start reading files from SD
|
readingFiles = true; //start reading files from SD
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
printMsg(QString(data)); //echo
|
emit recievedData(data);
|
||||||
}
|
printMsg(QString(data)); //echo
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::printMsg(const char* text)
|
void MainWindow::printMsg(const char* text)
|
||||||
@ -805,10 +827,14 @@ TemperatureReadings MainWindow::parseStatus(QByteArray data)
|
|||||||
void MainWindow::updateStatus()
|
void MainWindow::updateStatus()
|
||||||
{
|
{
|
||||||
TemperatureReadings r = statusWatcher.future().result();
|
TemperatureReadings r = statusWatcher.future().result();
|
||||||
|
updateTemperature(r);
|
||||||
|
sinceLastTemp.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::updateTemperature(TemperatureReadings r)
|
||||||
|
{
|
||||||
ui->extruderlcd->display(r.e);
|
ui->extruderlcd->display(r.e);
|
||||||
ui->bedlcd->display(r.b);
|
ui->bedlcd->display(r.b);
|
||||||
|
|
||||||
sinceLastTemp.restart();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionPrint_from_SD_triggered()
|
void MainWindow::on_actionPrint_from_SD_triggered()
|
||||||
@ -821,7 +847,7 @@ void MainWindow::on_actionAbout_Qt_triggered()
|
|||||||
qApp->aboutQt();
|
qApp->aboutQt();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::initSDprinting()
|
void MainWindow::initSDprinting(QStringList sdFiles)
|
||||||
{
|
{
|
||||||
SDWindow sdwindow(sdFiles, this); //Made it to 666 lines!
|
SDWindow sdwindow(sdFiles, this); //Made it to 666 lines!
|
||||||
|
|
||||||
@ -870,9 +896,8 @@ void MainWindow::selectSDfile(QString file)
|
|||||||
ui->fileBox->setDisabled(false);
|
ui->fileBox->setDisabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::updateSDStatus()
|
void MainWindow::updateSDStatus(double currentSDbytes)
|
||||||
{
|
{
|
||||||
double currentSDbytes = sdWatcher.future().result();
|
|
||||||
ui->filelines->setText(QString::number(sdBytes)
|
ui->filelines->setText(QString::number(sdBytes)
|
||||||
+ QString("/")
|
+ QString("/")
|
||||||
+ QString::number(currentSDbytes)
|
+ QString::number(currentSDbytes)
|
||||||
@ -909,6 +934,7 @@ void MainWindow::on_actionSet_SD_printing_mode_triggered()
|
|||||||
void MainWindow::requestEEPROMSettings()
|
void MainWindow::requestEEPROMSettings()
|
||||||
{
|
{
|
||||||
userCommands.clear();
|
userCommands.clear();
|
||||||
|
EEPROMSettings.clear();
|
||||||
|
|
||||||
switch(firmware)
|
switch(firmware)
|
||||||
{
|
{
|
||||||
@ -922,7 +948,7 @@ void MainWindow::requestEEPROMSettings()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
readingEEPROM = true;
|
emit startedReadingEEPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionEEPROM_editor_triggered()
|
void MainWindow::on_actionEEPROM_editor_triggered()
|
||||||
@ -948,3 +974,38 @@ void MainWindow::sendEEPROMsettings(QStringList changes)
|
|||||||
//printMsg(str);
|
//printMsg(str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::recievedOkNum(int num)
|
||||||
|
{
|
||||||
|
readyRecieve++;
|
||||||
|
lastRecieved = num;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::recievedWait()
|
||||||
|
{
|
||||||
|
readyRecieve = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::EEPROMSettingRecieved(QString esetting)
|
||||||
|
{
|
||||||
|
EEPROMSettings.append(esetting);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::recievedError()
|
||||||
|
{
|
||||||
|
ErrorWindow errorwindow(this,"Hardware failure");
|
||||||
|
errorwindow.exec();
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::recievedSDDone()
|
||||||
|
{
|
||||||
|
sdprinting=false;
|
||||||
|
ui->progressBar->setValue(0);
|
||||||
|
ui->filename->setText("");
|
||||||
|
ui->fileBox->setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void MainWindow::recievedResend(int num)
|
||||||
|
{
|
||||||
|
if(!sendingChecksum) currentLine--;
|
||||||
|
}
|
||||||
|
|||||||
19
mainwindow.h
19
mainwindow.h
@ -20,6 +20,7 @@
|
|||||||
#include "sdwindow.h"
|
#include "sdwindow.h"
|
||||||
#include "repraptor.h"
|
#include "repraptor.h"
|
||||||
#include "eepromwindow.h"
|
#include "eepromwindow.h"
|
||||||
|
#include "parser.h"
|
||||||
|
|
||||||
using namespace RepRaptor;
|
using namespace RepRaptor;
|
||||||
|
|
||||||
@ -35,6 +36,9 @@ public:
|
|||||||
explicit MainWindow(QWidget *parent = 0);
|
explicit MainWindow(QWidget *parent = 0);
|
||||||
~MainWindow();
|
~MainWindow();
|
||||||
|
|
||||||
|
Parser *parser;
|
||||||
|
QThread *parserThread;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QFile gfile;
|
QFile gfile;
|
||||||
QVector<QString> gcode;
|
QVector<QString> gcode;
|
||||||
@ -46,7 +50,6 @@ protected:
|
|||||||
QElapsedTimer sinceLastTemp;
|
QElapsedTimer sinceLastTemp;
|
||||||
QSettings settings;
|
QSettings settings;
|
||||||
QStringList recentFiles;
|
QStringList recentFiles;
|
||||||
QStringList sdFiles;
|
|
||||||
QStringList EEPROMSettings;
|
QStringList EEPROMSettings;
|
||||||
QFutureWatcher<TemperatureReadings> statusWatcher;
|
QFutureWatcher<TemperatureReadings> statusWatcher;
|
||||||
QFutureWatcher<double> sdWatcher;
|
QFutureWatcher<double> sdWatcher;
|
||||||
@ -73,6 +76,7 @@ private:
|
|||||||
bool chekingSDStatus;
|
bool chekingSDStatus;
|
||||||
int firmware;
|
int firmware;
|
||||||
long int currentLine;
|
long int currentLine;
|
||||||
|
unsigned long int lastRecieved;
|
||||||
int readyRecieve;
|
int readyRecieve;
|
||||||
unsigned long int sdBytes;
|
unsigned long int sdBytes;
|
||||||
QString userCommand;
|
QString userCommand;
|
||||||
@ -91,15 +95,22 @@ private slots:
|
|||||||
void updateRecent();
|
void updateRecent();
|
||||||
void injectCommand(QString command);
|
void injectCommand(QString command);
|
||||||
void updateStatus();
|
void updateStatus();
|
||||||
void initSDprinting();
|
void initSDprinting(QStringList sdFiles);
|
||||||
void selectSDfile(QString file);
|
void selectSDfile(QString file);
|
||||||
void checkSDStatus();
|
void checkSDStatus();
|
||||||
void updateSDStatus();
|
void updateSDStatus(double currentSDbytes);
|
||||||
TemperatureReadings parseStatus(QByteArray data);
|
TemperatureReadings parseStatus(QByteArray data);
|
||||||
double parseSDStatus(QByteArray data);
|
double parseSDStatus(QByteArray data);
|
||||||
void requestEEPROMSettings();
|
void requestEEPROMSettings();
|
||||||
void openEEPROMeditor();
|
void openEEPROMeditor();
|
||||||
void sendEEPROMsettings(QStringList changes);
|
void sendEEPROMsettings(QStringList changes);
|
||||||
|
void updateTemperature(TemperatureReadings r);
|
||||||
|
void EEPROMSettingRecieved(QString esetting);
|
||||||
|
void recievedOkNum(int num);
|
||||||
|
void recievedWait();
|
||||||
|
void recievedError();
|
||||||
|
void recievedSDDone();
|
||||||
|
void recievedResend(int num);
|
||||||
|
|
||||||
void xplus();
|
void xplus();
|
||||||
void yplus();
|
void yplus();
|
||||||
@ -150,6 +161,8 @@ private slots:
|
|||||||
signals:
|
signals:
|
||||||
void sdReady();
|
void sdReady();
|
||||||
void eepromReady();
|
void eepromReady();
|
||||||
|
void recievedData(QByteArray);
|
||||||
|
void startedReadingEEPROM();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // MAINWINDOW_H
|
#endif // MAINWINDOW_H
|
||||||
|
|||||||
@ -897,6 +897,12 @@ STOP</string>
|
|||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QGroupBox" name="fileBox">
|
<widget class="QGroupBox" name="fileBox">
|
||||||
|
<property name="maximumSize">
|
||||||
|
<size>
|
||||||
|
<width>190</width>
|
||||||
|
<height>16777215</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
<property name="title">
|
<property name="title">
|
||||||
<string>File</string>
|
<string>File</string>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
106
parser.cpp
Normal file
106
parser.cpp
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
#include "parser.h"
|
||||||
|
|
||||||
|
Parser::Parser(QObject *parent):
|
||||||
|
QObject(parent)
|
||||||
|
{
|
||||||
|
this->setParent(parent);
|
||||||
|
temperatureRegxp.setCaseSensitivity(Qt::CaseInsensitive);
|
||||||
|
temperatureRegxp.setPatternSyntax(QRegExp::RegExp);
|
||||||
|
temperatureRegxp.setPattern("\\d+\\.\\d+"); // Find float in string
|
||||||
|
|
||||||
|
readingFiles = false;
|
||||||
|
readingEEPROM = false;
|
||||||
|
EEPROMReadingStarted = false;
|
||||||
|
|
||||||
|
QSettings settings;
|
||||||
|
firmware = settings.value("printer/firmware").toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
Parser::~Parser()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Parser::parse(QByteArray data)
|
||||||
|
{
|
||||||
|
if(!data.isEmpty())
|
||||||
|
{
|
||||||
|
if(readingFiles)
|
||||||
|
{
|
||||||
|
if(!data.contains("End file list")) SDFilesList.append(data);
|
||||||
|
else
|
||||||
|
{
|
||||||
|
readingFiles = false;
|
||||||
|
emit recievedSDFilesList(SDFilesList);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(readingEEPROM)
|
||||||
|
{
|
||||||
|
if(firmware == Repetier)
|
||||||
|
{
|
||||||
|
if(data.startsWith("EPR"))
|
||||||
|
{
|
||||||
|
emit recievedEEPROMLine(QString(data));
|
||||||
|
EEPROMReadingStarted = true;
|
||||||
|
}
|
||||||
|
else if(EEPROMReadingStarted)
|
||||||
|
{
|
||||||
|
readingEEPROM = false;
|
||||||
|
EEPROMReadingStarted = false;
|
||||||
|
emit recievingEEPROMDone();
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(data.startsWith("ok"))
|
||||||
|
emit recievedOkNum(data.split(' ').at(1).toInt());
|
||||||
|
else if(data.startsWith("T:"))
|
||||||
|
{
|
||||||
|
TemperatureReadings r;
|
||||||
|
|
||||||
|
if(temperatureRegxp.indexIn(QString(data)) != -1)
|
||||||
|
r.e = temperatureRegxp.cap(0).toDouble();
|
||||||
|
else return;
|
||||||
|
if(temperatureRegxp.indexIn(QString(data), temperatureRegxp.matchedLength()) != -1)
|
||||||
|
r.b = temperatureRegxp.cap(0).toDouble();
|
||||||
|
else return;
|
||||||
|
|
||||||
|
emit recievedTemperature(r);
|
||||||
|
}
|
||||||
|
else if(data.startsWith("wait")) emit recievedOkWait();
|
||||||
|
else if(data.startsWith("rs") || data.startsWith("Resend"))
|
||||||
|
emit recievedResend(data.split(' ').at(0).toInt());
|
||||||
|
else if(data.startsWith("!!")) emit recievedError();
|
||||||
|
else if(data.startsWith("Done")) emit recievedSDDone();
|
||||||
|
else if(data.startsWith("start")) emit recievedStart();
|
||||||
|
else if(data.startsWith("SD pr"))
|
||||||
|
{
|
||||||
|
QString tmp;
|
||||||
|
QString fragment = data.split(' ').at(3);
|
||||||
|
for(int i = 0; fragment.at(i) != '/'; ++i)
|
||||||
|
{
|
||||||
|
tmp += fragment.at(i);
|
||||||
|
}
|
||||||
|
emit recievedSDUpdate(tmp.toDouble());
|
||||||
|
}
|
||||||
|
else if(data.startsWith("Not SD "));
|
||||||
|
else if(data.contains("Begin file list"))
|
||||||
|
{
|
||||||
|
SDFilesList.clear();
|
||||||
|
readingFiles = true; //start reading files from SD
|
||||||
|
}
|
||||||
|
else if(data.contains("REPETIER")) emit recievedFirmware(Repetier);
|
||||||
|
else if(data.contains("MARLIN")) emit recievedFirmware(Marlin);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Parser::setEEPROMReadingMode()
|
||||||
|
{
|
||||||
|
readingEEPROM = true;
|
||||||
|
}
|
||||||
47
parser.h
Normal file
47
parser.h
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
#ifndef PARSETHREAD_H
|
||||||
|
#define PARSETHREAD_H
|
||||||
|
|
||||||
|
#include <QThread>
|
||||||
|
#include <QSettings>
|
||||||
|
|
||||||
|
#include "repraptor.h"
|
||||||
|
|
||||||
|
using namespace RepRaptor;
|
||||||
|
|
||||||
|
class Parser : public QObject
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit Parser(QObject *parent = 0);
|
||||||
|
~Parser();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
QByteArray data;
|
||||||
|
QStringList SDFilesList;
|
||||||
|
int firmware;
|
||||||
|
bool readingFiles;
|
||||||
|
bool readingEEPROM;
|
||||||
|
bool EEPROMReadingStarted;
|
||||||
|
QRegExp temperatureRegxp;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void recievedTemperature(TemperatureReadings);
|
||||||
|
void recievedSDUpdate(double);
|
||||||
|
void recievedEEPROMLine(QString);
|
||||||
|
void recievingEEPROMDone();
|
||||||
|
void recievedSDFilesList(QStringList);
|
||||||
|
void recievedOkWait();
|
||||||
|
void recievedOkNum(int);
|
||||||
|
void recievedStart();
|
||||||
|
void recievedResend(int);
|
||||||
|
void recievedError();
|
||||||
|
void recievedFirmware(int);
|
||||||
|
void recievedSDDone();
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void parse(QByteArray data);
|
||||||
|
void setEEPROMReadingMode();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // PARSETHREAD_H
|
||||||
Loading…
x
Reference in New Issue
Block a user