Bug fixes, turn some connections into QT5 syntax, more implementation of scripting interface.
This commit is contained in:
+3
-2
@@ -84,7 +84,7 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
worker = new SerialWorker(model);
|
worker = new SerialWorker(model);
|
||||||
worker->moveToThread(&serialWorkerThread);
|
worker->moveToThread(&serialWorkerThread);
|
||||||
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
connect(&serialWorkerThread, &QThread::finished, worker, &QObject::deleteLater);
|
||||||
connect(&serialWorkerThread, SIGNAL(started()), worker, SLOT(run())); //setup timers within the proper thread
|
connect(&serialWorkerThread, &QThread::started, worker, &SerialWorker::run); //setup timers within the proper thread
|
||||||
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
|
connect(this, &MainWindow::sendSerialPort, worker, &SerialWorker::setSerialPort, Qt::QueuedConnection);
|
||||||
connect(worker, &SerialWorker::frameUpdateTick, this, &MainWindow::gotFrames, Qt::QueuedConnection);
|
connect(worker, &SerialWorker::frameUpdateTick, this, &MainWindow::gotFrames, Qt::QueuedConnection);
|
||||||
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
|
connect(this, &MainWindow::updateBaudRates, worker, &SerialWorker::updateBaudRates, Qt::QueuedConnection);
|
||||||
@@ -995,7 +995,7 @@ void MainWindow::showFrameSenderWindow()
|
|||||||
else
|
else
|
||||||
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
|
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
|
||||||
|
|
||||||
connect(frameSenderWindow, SIGNAL(sendCANFrame(const CANFrame*,int)), worker, SLOT(sendFrame(const CANFrame*,int)));
|
connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, worker, &SerialWorker::sendFrame);
|
||||||
}
|
}
|
||||||
frameSenderWindow->show();
|
frameSenderWindow->show();
|
||||||
}
|
}
|
||||||
@@ -1046,6 +1046,7 @@ void MainWindow::showScriptingWindow()
|
|||||||
if (!scriptingWindow)
|
if (!scriptingWindow)
|
||||||
{
|
{
|
||||||
scriptingWindow = new ScriptingWindow(model->getListReference());
|
scriptingWindow = new ScriptingWindow(model->getListReference());
|
||||||
|
connect(scriptingWindow, &ScriptingWindow::sendCANFrame, worker, &SerialWorker::sendFrame);
|
||||||
}
|
}
|
||||||
scriptingWindow->show();
|
scriptingWindow->show();
|
||||||
}
|
}
|
||||||
|
|||||||
+24
-3
@@ -86,18 +86,39 @@ void ScriptContainer::clearFilters()
|
|||||||
filters.clear();
|
filters.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptContainer::sendFrame(QJSValue id, QJSValue length, QJSValue data)
|
void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSValue data)
|
||||||
{
|
{
|
||||||
qDebug() << "called send frame";
|
CANFrame frame;
|
||||||
|
frame.extended = false;
|
||||||
|
frame.ID = id.toInt();
|
||||||
|
frame.len = length.toInt();
|
||||||
|
if (frame.len < 0) frame.len = 0;
|
||||||
|
if (frame.len > 8) frame.len = 8;
|
||||||
|
|
||||||
|
for (int i = 0; i < frame.len; i++)
|
||||||
|
{
|
||||||
|
frame.data[i] = (uint8_t)data.property(0).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
frame.bus = bus.toInt();
|
||||||
|
if (frame.bus < 0) frame.bus = 0;
|
||||||
|
if (frame.bus > 1) frame.bus = 1;
|
||||||
|
|
||||||
|
if (frame.ID > 0x7FF) frame.extended = true;
|
||||||
|
|
||||||
|
emit sendCANFrame(&frame, frame.bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScriptContainer::gotFrame(const CANFrame &frame)
|
void ScriptContainer::gotFrame(const CANFrame &frame)
|
||||||
{
|
{
|
||||||
|
if (!gotFrameFunction.isCallable()) return; //nothing to do if we can't even call the function
|
||||||
for (int i = 0; i < filters.length(); i++)
|
for (int i = 0; i < filters.length(); i++)
|
||||||
{
|
{
|
||||||
if (filters[i].checkFilter(frame.ID, frame.bus))
|
if (filters[i].checkFilter(frame.ID, frame.bus))
|
||||||
{
|
{
|
||||||
|
QJSValueList args;
|
||||||
|
args << frame.bus << frame.ID << frame.len << frame.data;
|
||||||
|
gotFrameFunction.call(args);
|
||||||
return; //as soon as one filter matches we jump out
|
return; //as soon as one filter matches we jump out
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-1
@@ -26,11 +26,14 @@ public slots:
|
|||||||
void setFilter(QJSValue id, QJSValue mask, QJSValue bus);
|
void setFilter(QJSValue id, QJSValue mask, QJSValue bus);
|
||||||
void setTickInterval(QJSValue interval);
|
void setTickInterval(QJSValue interval);
|
||||||
void clearFilters();
|
void clearFilters();
|
||||||
void sendFrame(QJSValue id, QJSValue length, QJSValue data);
|
void sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSValue data);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void tick();
|
void tick();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sendCANFrame(const CANFrame *, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QJSEngine scriptEngine;
|
QJSEngine scriptEngine;
|
||||||
QJSValue compiledScript;
|
QJSValue compiledScript;
|
||||||
|
|||||||
+30
-9
@@ -4,6 +4,8 @@
|
|||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
|
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::ScriptingWindow)
|
ui(new Ui::ScriptingWindow)
|
||||||
@@ -12,15 +14,13 @@ ScriptingWindow::ScriptingWindow(const QVector<CANFrame> *frames, QWidget *paren
|
|||||||
|
|
||||||
modelFrames = frames;
|
modelFrames = frames;
|
||||||
|
|
||||||
connect(ui->btnLoadScript, SIGNAL(pressed()), this, SLOT(loadNewScript()));
|
connect(ui->btnLoadScript, &QAbstractButton::pressed, this, &ScriptingWindow::loadNewScript);
|
||||||
connect(ui->btnNewScript, SIGNAL(pressed()), this, SLOT(createNewScript()));
|
connect(ui->btnNewScript, &QAbstractButton::pressed, this, &ScriptingWindow::createNewScript);
|
||||||
connect(ui->btnRecompile, SIGNAL(pressed()), this, SLOT(recompileScript()));
|
connect(ui->btnRecompile, &QAbstractButton::pressed, this, &ScriptingWindow::recompileScript);
|
||||||
connect(ui->btnRemoveScript, SIGNAL(pressed()), this, SLOT(deleteCurrentScript()));
|
connect(ui->btnRemoveScript, &QAbstractButton::pressed, this, &ScriptingWindow::deleteCurrentScript);
|
||||||
connect(ui->btnRevertScript, SIGNAL(pressed()), this, SLOT(revertScript()));
|
connect(ui->btnRevertScript, &QAbstractButton::pressed, this, &ScriptingWindow::revertScript);
|
||||||
connect(ui->btnSaveScript, SIGNAL(pressed()), this, SLOT(saveScript()));
|
connect(ui->btnSaveScript, &QAbstractButton::pressed, this, &ScriptingWindow::saveScript);
|
||||||
|
connect(MainWindow::getReference(), &MainWindow::framesUpdated, this, &ScriptingWindow::updatedFrames);
|
||||||
currentScript = new ScriptContainer();
|
|
||||||
currentScript->setErrorWidget(ui->listErrors);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptingWindow::~ScriptingWindow()
|
ScriptingWindow::~ScriptingWindow()
|
||||||
@@ -28,6 +28,25 @@ ScriptingWindow::~ScriptingWindow()
|
|||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ScriptingWindow::updatedFrames(int numFrames)
|
||||||
|
{
|
||||||
|
CANFrame thisFrame;
|
||||||
|
//-1 means all frames deleted and -2 means a full refresh, neither of which we care about here.
|
||||||
|
if (numFrames > 0)
|
||||||
|
{
|
||||||
|
//for every new frame pass it on to each script container. The container will determine if it needs to actually
|
||||||
|
//notify the script and do that if applicable.
|
||||||
|
for (int i = modelFrames->count() - numFrames; i < modelFrames->count(); i++)
|
||||||
|
{
|
||||||
|
thisFrame = modelFrames->at(i);
|
||||||
|
for (int j = 0; j < scripts.length(); j++)
|
||||||
|
{
|
||||||
|
scripts[j]->gotFrame(thisFrame);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ScriptingWindow::loadNewScript()
|
void ScriptingWindow::loadNewScript()
|
||||||
{
|
{
|
||||||
QString filename;
|
QString filename;
|
||||||
@@ -63,6 +82,7 @@ void ScriptingWindow::loadNewScript()
|
|||||||
container->scriptText = contents;
|
container->scriptText = contents;
|
||||||
container->setErrorWidget(ui->listErrors);
|
container->setErrorWidget(ui->listErrors);
|
||||||
container->compileScript();
|
container->compileScript();
|
||||||
|
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
||||||
scripts.append(container);
|
scripts.append(container);
|
||||||
currentScript = container;
|
currentScript = container;
|
||||||
ui->txtScriptSource->setText(container->scriptText);
|
ui->txtScriptSource->setText(container->scriptText);
|
||||||
@@ -82,6 +102,7 @@ void ScriptingWindow::createNewScript()
|
|||||||
container->filePath = QString();
|
container->filePath = QString();
|
||||||
container->scriptText = QString();
|
container->scriptText = QString();
|
||||||
container->setErrorWidget(ui->listErrors);
|
container->setErrorWidget(ui->listErrors);
|
||||||
|
connect(container, &ScriptContainer::sendCANFrame, this, &ScriptingWindow::sendCANFrame);
|
||||||
scripts.append(container);
|
scripts.append(container);
|
||||||
ui->listLoadedScripts->addItem(container->fileName);
|
ui->listLoadedScripts->addItem(container->fileName);
|
||||||
currentScript = container;
|
currentScript = container;
|
||||||
|
|||||||
@@ -27,9 +27,12 @@ private slots:
|
|||||||
void saveScript();
|
void saveScript();
|
||||||
void revertScript();
|
void revertScript();
|
||||||
void recompileScript();
|
void recompileScript();
|
||||||
|
void updatedFrames(int);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void sendCANFrame(const CANFrame *, int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ScriptingWindow *ui;
|
Ui::ScriptingWindow *ui;
|
||||||
|
|||||||
+3
-3
@@ -164,6 +164,8 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
|||||||
canModel->addFrame(tempFrame, false);
|
canModel->addFrame(tempFrame, false);
|
||||||
gotFrames++;
|
gotFrames++;
|
||||||
|
|
||||||
|
if (serial == NULL) return;
|
||||||
|
if (!serial->isOpen()) return;
|
||||||
if (!connected) return;
|
if (!connected) return;
|
||||||
|
|
||||||
ID = frame->ID;
|
ID = frame->ID;
|
||||||
@@ -183,8 +185,6 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
|||||||
}
|
}
|
||||||
buffer[8 + frame->len] = 0;
|
buffer[8 + frame->len] = 0;
|
||||||
|
|
||||||
if (serial == NULL) return;
|
|
||||||
if (!serial->isOpen()) return;
|
|
||||||
//qDebug() << "writing " << buffer.length() << " bytes to serial port";
|
//qDebug() << "writing " << buffer.length() << " bytes to serial port";
|
||||||
serial->write(buffer);
|
serial->write(buffer);
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
|
|||||||
//Don't get carried away here. The GVRET firmware only has finite
|
//Don't get carried away here. The GVRET firmware only has finite
|
||||||
//buffers and besides, the other end will get buried in traffic.
|
//buffers and besides, the other end will get buried in traffic.
|
||||||
void SerialWorker::sendFrameBatch(const QList<CANFrame> *frames)
|
void SerialWorker::sendFrameBatch(const QList<CANFrame> *frames)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < frames->length(); i++) sendFrame(&frames->at(i), frames->at(i).bus);
|
for (int i = 0; i < frames->length(); i++) sendFrame(&frames->at(i), frames->at(i).bus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user