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();
|
||||
};
|
||||
|
||||
|
||||
//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
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -41,7 +46,7 @@ public:
|
||||
CANConnection(CANFrameModel *, int);
|
||||
virtual int getNumBuses();
|
||||
int getBusBase();
|
||||
QString getConnTypeName();
|
||||
virtual QString getConnTypeName();
|
||||
QString getConnPortName();
|
||||
|
||||
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 stopFrameCapture(int); //pass bus number
|
||||
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:
|
||||
bool quit;
|
||||
|
||||
@@ -1,10 +1,18 @@
|
||||
#include "canconnection.h"
|
||||
#include "canconnectioncontainer.h"
|
||||
|
||||
CANConnectionContainer::CANConnectionContainer(CANConnection *conn)
|
||||
{
|
||||
thread = new QThread();
|
||||
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()
|
||||
@@ -13,3 +21,8 @@ CANConnectionContainer::~CANConnectionContainer()
|
||||
delete thread;
|
||||
delete connection;
|
||||
}
|
||||
|
||||
CANConnection* CANConnectionContainer::getRef()
|
||||
{
|
||||
return connection;
|
||||
}
|
||||
|
||||
@@ -2,17 +2,19 @@
|
||||
#define CANCONNECTIONCONTAINER_H
|
||||
|
||||
#include "canconnection.h"
|
||||
#include <Qt>
|
||||
#include <QThread>
|
||||
#include "mainwindow.h"
|
||||
|
||||
class CANConnectionContainer
|
||||
class CANConnectionContainer : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
CANConnectionContainer(CANConnection *conn);
|
||||
~CANConnectionContainer();
|
||||
|
||||
CANConnection* getRef();
|
||||
|
||||
|
||||
private:
|
||||
CANConnection *connection;
|
||||
QThread *thread;
|
||||
|
||||
+25
-10
@@ -1,3 +1,5 @@
|
||||
#include "canconnection.h"
|
||||
#include "canconnectioncontainer.h"
|
||||
#include "canconnectionmodel.h"
|
||||
|
||||
CANConnectionModel::CANConnectionModel(QObject *parent)
|
||||
@@ -71,10 +73,12 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||
return QString::number(bus.busNum);
|
||||
break;
|
||||
case 1: //type
|
||||
if (conn) conn->getConnTypeName();
|
||||
if (conn) return conn->getConnTypeName();
|
||||
else qDebug() << "Tried to show connection type but connection was NULL";
|
||||
break;
|
||||
case 2: //port
|
||||
if (conn) conn->getConnPortName();
|
||||
if (conn) return conn->getConnPortName();
|
||||
else qDebug() << "Tried to show connection port but connection was NULL";
|
||||
break;
|
||||
case 3: //speed
|
||||
return QString::number(bus.speed);
|
||||
@@ -102,20 +106,31 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
|
||||
void CANConnectionModel::addConnection(CANConnection *conn)
|
||||
{
|
||||
CAN_Bus bus;
|
||||
beginResetModel();
|
||||
CANConnectionContainer *cont = new CANConnectionContainer(conn);
|
||||
connections.append(cont);
|
||||
}
|
||||
|
||||
int numBuses = conn->getNumBuses();
|
||||
for (int i = 0; i < numBuses; i++)
|
||||
{
|
||||
bus.busNum = conn->getBusBase() + i;
|
||||
buses.append(bus);
|
||||
}
|
||||
|
||||
void CANConnectionModel::addBus(CAN_Bus &bus)
|
||||
{
|
||||
beginResetModel();
|
||||
buses.append(bus);
|
||||
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)
|
||||
{
|
||||
for (int i = 0; i < buses.count(); i++)
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
class CANConnectionContainer;
|
||||
|
||||
class CANConnectionModel : public QAbstractTableModel
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -22,6 +24,9 @@ public:
|
||||
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
|
||||
|
||||
void addConnection(CANConnection *conn);
|
||||
void addBus(CAN_Bus &bus);
|
||||
CAN_Bus* getBus(int bus);
|
||||
CANConnection* getConnection(int conn);
|
||||
|
||||
private:
|
||||
QList<CANConnectionContainer *> connections;
|
||||
|
||||
+37
-1
@@ -88,8 +88,44 @@ void ConnectionWindow::handleOKButton()
|
||||
{
|
||||
if (ui->rbGVRET->isChecked())
|
||||
{
|
||||
SerialWorker *serial = new SerialWorker(canModel, 0);
|
||||
SerialWorker *serial = new SerialWorker(canModel, connModel->rowCount());
|
||||
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())
|
||||
{
|
||||
|
||||
+4
-1
@@ -10,6 +10,8 @@
|
||||
#include "canconnection.h"
|
||||
#include "serialworker.h"
|
||||
|
||||
class CANConnectionModel;
|
||||
|
||||
namespace Ui {
|
||||
class ConnectionWindow;
|
||||
}
|
||||
@@ -38,7 +40,8 @@ public:
|
||||
bool getSWMode();
|
||||
|
||||
signals:
|
||||
void updateConnectionSettings(QString connectionType, QString port, int speed);
|
||||
void updateBusSettings(CAN_Bus *bus);
|
||||
void updatePortName(QString port);
|
||||
|
||||
public slots:
|
||||
void setSpeed(int speed0);
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>952</width>
|
||||
<width>1009</width>
|
||||
<height>433</height>
|
||||
</rect>
|
||||
</property>
|
||||
|
||||
@@ -109,7 +109,6 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
model->setDBCHandler(dbcHandler);
|
||||
|
||||
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->actionGraph_Dta, &QAction::triggered, this, &MainWindow::showGraphingWindow);
|
||||
connect(ui->actionFrame_Data_Analysis, &QAction::triggered, this, &MainWindow::showFrameDataAnalysis);
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include "udsscanwindow.h"
|
||||
#include "isotp_interpreterwindow.h"
|
||||
|
||||
class ConnectionWindow;
|
||||
|
||||
namespace Ui {
|
||||
class MainWindow;
|
||||
}
|
||||
|
||||
+1
-2
@@ -245,7 +245,6 @@
|
||||
<string>Connection</string>
|
||||
</property>
|
||||
<addaction name="actionSetup"/>
|
||||
<addaction name="actionConnect"/>
|
||||
</widget>
|
||||
<addaction name="menuFile"/>
|
||||
<addaction name="menu_RE_Tools"/>
|
||||
@@ -350,7 +349,7 @@
|
||||
</action>
|
||||
<action name="actionSetup">
|
||||
<property name="text">
|
||||
<string>Set Port</string>
|
||||
<string>Open Connection WIndow</string>
|
||||
</property>
|
||||
</action>
|
||||
<action name="actionConnect">
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
|
||||
SerialWorker::SerialWorker(CANFrameModel *model, int base) : CANConnection(model, base)
|
||||
{
|
||||
qDebug() << "Serial Worker constructor";
|
||||
serial = NULL;
|
||||
rx_state = IDLE;
|
||||
rx_step = 0;
|
||||
@@ -39,6 +40,7 @@ SerialWorker::~SerialWorker()
|
||||
|
||||
void SerialWorker::run()
|
||||
{
|
||||
qDebug() << "Serial worker thread starting";
|
||||
ticker = new QTimer;
|
||||
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();
|
||||
void readSettings();
|
||||
int getNumBuses();
|
||||
QString getConnTypeName() override;
|
||||
|
||||
private slots: //we receive things in slots
|
||||
void readSerialData();
|
||||
@@ -55,6 +57,7 @@ public slots:
|
||||
//void stopFrameCapture(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 updateBusSettings(CAN_Bus *bus) override;
|
||||
|
||||
private:
|
||||
bool doValidation;
|
||||
|
||||
Reference in New Issue
Block a user