Additional implementation of new connection system. The GVRET code can
now connect and run its thread.
This commit is contained in:
@@ -126,3 +126,8 @@ void CANConnection::startFrameCapture(int bus)
|
|||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CANConnection::updateBusSettings(CAN_Bus *bus)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
+7
-2
@@ -33,6 +33,11 @@ public:
|
|||||||
CANConnection *getConnection();
|
CANConnection *getConnection();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
//Gentle reminder, CANConnection objects run in their own thread (each one, different thread)
|
||||||
|
//so, for the love of God, do not try to access them directly.
|
||||||
|
//Use the signal/slots system to do indirect calls.
|
||||||
|
//Please and thank you.
|
||||||
class CANConnection : public QObject
|
class CANConnection : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -41,7 +46,7 @@ public:
|
|||||||
CANConnection(CANFrameModel *, int);
|
CANConnection(CANFrameModel *, int);
|
||||||
virtual int getNumBuses();
|
virtual int getNumBuses();
|
||||||
int getBusBase();
|
int getBusBase();
|
||||||
QString getConnTypeName();
|
virtual QString getConnTypeName();
|
||||||
QString getConnPortName();
|
QString getConnPortName();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -59,7 +64,7 @@ public slots:
|
|||||||
virtual void updatePortName(QString); //string version of the port to connect to. This base doesnt know a thing about this value
|
virtual void updatePortName(QString); //string version of the port to connect to. This base doesnt know a thing about this value
|
||||||
virtual void stopFrameCapture(int); //pass bus number
|
virtual void stopFrameCapture(int); //pass bus number
|
||||||
virtual void startFrameCapture(int); //pass bus number. Only if stopped. Defaults to started anyway
|
virtual void startFrameCapture(int); //pass bus number. Only if stopped. Defaults to started anyway
|
||||||
//virtual void updateBusSettings(int); //bus number that was updated.
|
virtual void updateBusSettings(CAN_Bus *bus); //reference to the bus that changed.
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool quit;
|
bool quit;
|
||||||
|
|||||||
@@ -1,10 +1,18 @@
|
|||||||
|
#include "canconnection.h"
|
||||||
#include "canconnectioncontainer.h"
|
#include "canconnectioncontainer.h"
|
||||||
|
|
||||||
CANConnectionContainer::CANConnectionContainer(CANConnection *conn)
|
CANConnectionContainer::CANConnectionContainer(CANConnection *conn)
|
||||||
{
|
{
|
||||||
thread = new QThread();
|
thread = new QThread();
|
||||||
connection = conn;
|
connection = conn;
|
||||||
connection->moveToThread(thread);
|
connection->moveToThread(thread);
|
||||||
|
|
||||||
|
connect(thread, &QThread::finished, conn, &QObject::deleteLater);
|
||||||
|
connect(thread, &QThread::started, conn, &CANConnection::run); //setup timers within the proper thread
|
||||||
|
connect(conn, &CANConnection::frameUpdateRapid, MainWindow::getReference(), &MainWindow::gotFrames, Qt::QueuedConnection);
|
||||||
|
connect(MainWindow::getReference(), &MainWindow::sendCANFrame, conn, &CANConnection::sendFrame, Qt::QueuedConnection);
|
||||||
|
thread->start();
|
||||||
|
thread->setPriority(QThread::HighPriority);
|
||||||
}
|
}
|
||||||
|
|
||||||
CANConnectionContainer::~CANConnectionContainer()
|
CANConnectionContainer::~CANConnectionContainer()
|
||||||
@@ -13,3 +21,8 @@ CANConnectionContainer::~CANConnectionContainer()
|
|||||||
delete thread;
|
delete thread;
|
||||||
delete connection;
|
delete connection;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CANConnection* CANConnectionContainer::getRef()
|
||||||
|
{
|
||||||
|
return connection;
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,17 +2,19 @@
|
|||||||
#define CANCONNECTIONCONTAINER_H
|
#define CANCONNECTIONCONTAINER_H
|
||||||
|
|
||||||
#include "canconnection.h"
|
#include "canconnection.h"
|
||||||
|
#include <Qt>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
#include "mainwindow.h"
|
||||||
|
|
||||||
class CANConnectionContainer
|
class CANConnectionContainer : public QObject
|
||||||
{
|
{
|
||||||
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
CANConnectionContainer(CANConnection *conn);
|
CANConnectionContainer(CANConnection *conn);
|
||||||
~CANConnectionContainer();
|
~CANConnectionContainer();
|
||||||
|
|
||||||
CANConnection* getRef();
|
CANConnection* getRef();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
CANConnection *connection;
|
CANConnection *connection;
|
||||||
QThread *thread;
|
QThread *thread;
|
||||||
|
|||||||
+25
-10
@@ -1,3 +1,5 @@
|
|||||||
|
#include "canconnection.h"
|
||||||
|
#include "canconnectioncontainer.h"
|
||||||
#include "canconnectionmodel.h"
|
#include "canconnectionmodel.h"
|
||||||
|
|
||||||
CANConnectionModel::CANConnectionModel(QObject *parent)
|
CANConnectionModel::CANConnectionModel(QObject *parent)
|
||||||
@@ -71,10 +73,12 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
|||||||
return QString::number(bus.busNum);
|
return QString::number(bus.busNum);
|
||||||
break;
|
break;
|
||||||
case 1: //type
|
case 1: //type
|
||||||
if (conn) conn->getConnTypeName();
|
if (conn) return conn->getConnTypeName();
|
||||||
|
else qDebug() << "Tried to show connection type but connection was NULL";
|
||||||
break;
|
break;
|
||||||
case 2: //port
|
case 2: //port
|
||||||
if (conn) conn->getConnPortName();
|
if (conn) return conn->getConnPortName();
|
||||||
|
else qDebug() << "Tried to show connection port but connection was NULL";
|
||||||
break;
|
break;
|
||||||
case 3: //speed
|
case 3: //speed
|
||||||
return QString::number(bus.speed);
|
return QString::number(bus.speed);
|
||||||
@@ -102,20 +106,31 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
|||||||
void CANConnectionModel::addConnection(CANConnection *conn)
|
void CANConnectionModel::addConnection(CANConnection *conn)
|
||||||
{
|
{
|
||||||
CAN_Bus bus;
|
CAN_Bus bus;
|
||||||
beginResetModel();
|
|
||||||
CANConnectionContainer *cont = new CANConnectionContainer(conn);
|
CANConnectionContainer *cont = new CANConnectionContainer(conn);
|
||||||
connections.append(cont);
|
connections.append(cont);
|
||||||
|
}
|
||||||
|
|
||||||
int numBuses = conn->getNumBuses();
|
void CANConnectionModel::addBus(CAN_Bus &bus)
|
||||||
for (int i = 0; i < numBuses; i++)
|
{
|
||||||
{
|
beginResetModel();
|
||||||
bus.busNum = conn->getBusBase() + i;
|
buses.append(bus);
|
||||||
buses.append(bus);
|
|
||||||
}
|
|
||||||
|
|
||||||
endResetModel();
|
endResetModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CAN_Bus* CANConnectionModel::getBus(int bus)
|
||||||
|
{
|
||||||
|
if (bus < 0) return NULL;
|
||||||
|
if (bus >= buses.count()) return NULL;
|
||||||
|
return &buses[bus];
|
||||||
|
}
|
||||||
|
|
||||||
|
CANConnection* CANConnectionModel::getConnection(int conn)
|
||||||
|
{
|
||||||
|
if (conn < 0) return NULL;
|
||||||
|
if (conn >= connections.count()) return NULL;
|
||||||
|
return connections[conn]->getRef();
|
||||||
|
}
|
||||||
|
|
||||||
CAN_Bus* CANConnectionModel::findBusByNum(int bus)
|
CAN_Bus* CANConnectionModel::findBusByNum(int bus)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < buses.count(); i++)
|
for (int i = 0; i < buses.count(); i++)
|
||||||
|
|||||||
@@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
|
class CANConnectionContainer;
|
||||||
|
|
||||||
class CANConnectionModel : public QAbstractTableModel
|
class CANConnectionModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@@ -22,6 +24,9 @@ public:
|
|||||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||||
|
|
||||||
void addConnection(CANConnection *conn);
|
void addConnection(CANConnection *conn);
|
||||||
|
void addBus(CAN_Bus &bus);
|
||||||
|
CAN_Bus* getBus(int bus);
|
||||||
|
CANConnection* getConnection(int conn);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QList<CANConnectionContainer *> connections;
|
QList<CANConnectionContainer *> connections;
|
||||||
|
|||||||
+37
-1
@@ -88,8 +88,44 @@ void ConnectionWindow::handleOKButton()
|
|||||||
{
|
{
|
||||||
if (ui->rbGVRET->isChecked())
|
if (ui->rbGVRET->isChecked())
|
||||||
{
|
{
|
||||||
SerialWorker *serial = new SerialWorker(canModel, 0);
|
SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount());
|
||||||
connModel->addConnection(serial);
|
connModel->addConnection(serial);
|
||||||
|
|
||||||
|
qDebug() << "Setup initial connection object";
|
||||||
|
|
||||||
|
CAN_Bus bus;
|
||||||
|
bus.active = true;
|
||||||
|
bus.busNum = serial->getBusBase();
|
||||||
|
bus.connection = serial;
|
||||||
|
bus.listenOnly = ui->ckListenOnly->isChecked();
|
||||||
|
bus.singleWire = ui->ckSingleWire->isChecked();
|
||||||
|
|
||||||
|
if (ui->cbSpeed->currentIndex() < 1) bus.speed = 0; //default speed
|
||||||
|
else if (ui->cbSpeed->currentIndex() == 1)
|
||||||
|
{
|
||||||
|
bus.speed = 0;
|
||||||
|
bus.active = false;
|
||||||
|
}
|
||||||
|
else bus.speed = ui->cbSpeed->currentText().toInt();
|
||||||
|
connModel->addBus(bus);
|
||||||
|
|
||||||
|
int numBuses = serial->getNumBuses();
|
||||||
|
for (int i = 1; i < numBuses; i++)
|
||||||
|
{
|
||||||
|
bus.active = false;
|
||||||
|
bus.listenOnly = false;
|
||||||
|
bus.singleWire = false;
|
||||||
|
bus.speed = 250000;
|
||||||
|
bus.busNum = serial->getBusBase() + i;
|
||||||
|
bus.connection = serial;
|
||||||
|
connModel->addBus(bus);
|
||||||
|
qDebug() << "Added bus " << bus.busNum;
|
||||||
|
}
|
||||||
|
|
||||||
|
//call through signal/slot interface without using connect
|
||||||
|
QMetaObject::invokeMethod(serial, "updatePortName",
|
||||||
|
Qt::QueuedConnection,
|
||||||
|
Q_ARG(QString, ui->cbPort->currentText()));
|
||||||
}
|
}
|
||||||
else if (ui->rbKvaser->isChecked())
|
else if (ui->rbKvaser->isChecked())
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-1
@@ -10,6 +10,8 @@
|
|||||||
#include "canconnection.h"
|
#include "canconnection.h"
|
||||||
#include "serialworker.h"
|
#include "serialworker.h"
|
||||||
|
|
||||||
|
class CANConnectionModel;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class ConnectionWindow;
|
class ConnectionWindow;
|
||||||
}
|
}
|
||||||
@@ -38,7 +40,8 @@ public:
|
|||||||
bool getSWMode();
|
bool getSWMode();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void updateConnectionSettings(QString connectionType, QString port, int speed);
|
void updateBusSettings(CAN_Bus *bus);
|
||||||
|
void updatePortName(QString port);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
void setSpeed(int speed0);
|
void setSpeed(int speed0);
|
||||||
|
|||||||
+1
-1
@@ -6,7 +6,7 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>952</width>
|
<width>1009</width>
|
||||||
<height>433</height>
|
<height>433</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
|
|||||||
@@ -109,7 +109,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
|||||||
model->setDBCHandler(dbcHandler);
|
model->setDBCHandler(dbcHandler);
|
||||||
|
|
||||||
connect(ui->actionSetup, SIGNAL(triggered(bool)), SLOT(showConnectionSettingsWindow()));
|
connect(ui->actionSetup, SIGNAL(triggered(bool)), SLOT(showConnectionSettingsWindow()));
|
||||||
connect(ui->actionConnect, SIGNAL(triggered(bool)), this, SLOT(connButtonPress()));
|
|
||||||
connect(ui->actionOpen_Log_File, &QAction::triggered, this, &MainWindow::handleLoadFile);
|
connect(ui->actionOpen_Log_File, &QAction::triggered, this, &MainWindow::handleLoadFile);
|
||||||
connect(ui->actionGraph_Dta, &QAction::triggered, this, &MainWindow::showGraphingWindow);
|
connect(ui->actionGraph_Dta, &QAction::triggered, this, &MainWindow::showGraphingWindow);
|
||||||
connect(ui->actionFrame_Data_Analysis, &QAction::triggered, this, &MainWindow::showFrameDataAnalysis);
|
connect(ui->actionFrame_Data_Analysis, &QAction::triggered, this, &MainWindow::showFrameDataAnalysis);
|
||||||
|
|||||||
@@ -27,6 +27,8 @@
|
|||||||
#include "udsscanwindow.h"
|
#include "udsscanwindow.h"
|
||||||
#include "isotp_interpreterwindow.h"
|
#include "isotp_interpreterwindow.h"
|
||||||
|
|
||||||
|
class ConnectionWindow;
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class MainWindow;
|
class MainWindow;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-2
@@ -245,7 +245,6 @@
|
|||||||
<string>Connection</string>
|
<string>Connection</string>
|
||||||
</property>
|
</property>
|
||||||
<addaction name="actionSetup"/>
|
<addaction name="actionSetup"/>
|
||||||
<addaction name="actionConnect"/>
|
|
||||||
</widget>
|
</widget>
|
||||||
<addaction name="menuFile"/>
|
<addaction name="menuFile"/>
|
||||||
<addaction name="menu_RE_Tools"/>
|
<addaction name="menu_RE_Tools"/>
|
||||||
@@ -350,7 +349,7 @@
|
|||||||
</action>
|
</action>
|
||||||
<action name="actionSetup">
|
<action name="actionSetup">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Set Port</string>
|
<string>Open Connection WIndow</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
<action name="actionConnect">
|
<action name="actionConnect">
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
SerialWorker::SerialWorker(CANFrameModel *model, int base) : CANConnection(model, base)
|
SerialWorker::SerialWorker(CANFrameModel *model, int base) : CANConnection(model, base)
|
||||||
{
|
{
|
||||||
|
qDebug() << "Serial Worker constructor";
|
||||||
serial = NULL;
|
serial = NULL;
|
||||||
rx_state = IDLE;
|
rx_state = IDLE;
|
||||||
rx_step = 0;
|
rx_step = 0;
|
||||||
@@ -39,6 +40,7 @@ SerialWorker::~SerialWorker()
|
|||||||
|
|
||||||
void SerialWorker::run()
|
void SerialWorker::run()
|
||||||
{
|
{
|
||||||
|
qDebug() << "Serial worker thread starting";
|
||||||
ticker = new QTimer;
|
ticker = new QTimer;
|
||||||
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
connect(ticker, SIGNAL(timeout()), this, SLOT(handleTick()));
|
||||||
|
|
||||||
@@ -545,4 +547,20 @@ void SerialWorker::updatePortName(QString portName)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SerialWorker::getNumBuses()
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString SerialWorker::getConnTypeName()
|
||||||
|
{
|
||||||
|
return QString("GVRET");
|
||||||
|
}
|
||||||
|
|
||||||
|
void SerialWorker::updateBusSettings(CAN_Bus *bus)
|
||||||
|
{
|
||||||
|
int busNum = bus->busNum - busBase;
|
||||||
|
if (busNum < 0) return;
|
||||||
|
if (busNum >= numBuses) return;
|
||||||
|
qDebug() << "About to update bus " << busNum << " on GVRET";
|
||||||
|
}
|
||||||
|
|||||||
@@ -38,6 +38,8 @@ public:
|
|||||||
SerialWorker(CANFrameModel *, int);
|
SerialWorker(CANFrameModel *, int);
|
||||||
~SerialWorker();
|
~SerialWorker();
|
||||||
void readSettings();
|
void readSettings();
|
||||||
|
int getNumBuses();
|
||||||
|
QString getConnTypeName() override;
|
||||||
|
|
||||||
private slots: //we receive things in slots
|
private slots: //we receive things in slots
|
||||||
void readSerialData();
|
void readSerialData();
|
||||||
@@ -55,6 +57,7 @@ public slots:
|
|||||||
//void stopFrameCapture(int) override;
|
//void stopFrameCapture(int) override;
|
||||||
//void startFrameCapture(int) override;
|
//void startFrameCapture(int) override;
|
||||||
void updatePortName(QString) override; //string version of the port to connect to. This base doesnt know a thing about this value
|
void updatePortName(QString) override; //string version of the port to connect to. This base doesnt know a thing about this value
|
||||||
|
void updateBusSettings(CAN_Bus *bus) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool doValidation;
|
bool doValidation;
|
||||||
|
|||||||
Reference in New Issue
Block a user