Preliminary pass at converting connection system to use a more generic

approach and support more devices and multiple devices at the same time.
This commit is contained in:
Collin Kidder
2016-03-19 21:40:21 -04:00
parent 8a886ddcc9
commit e7ded7737a
15 changed files with 739 additions and 287 deletions
+8 -2
View File
@@ -48,7 +48,10 @@ SOURCES += main.cpp\
udsscanwindow.cpp \ udsscanwindow.cpp \
can_structs.cpp \ can_structs.cpp \
isotp_interpreterwindow.cpp \ isotp_interpreterwindow.cpp \
isotp_decoder.cpp isotp_decoder.cpp \
canconnectionmodel.cpp \
canconnection.cpp \
canconnectioncontainer.cpp
HEADERS += mainwindow.h \ HEADERS += mainwindow.h \
can_structs.h \ can_structs.h \
@@ -83,7 +86,10 @@ HEADERS += mainwindow.h \
fuzzingwindow.h \ fuzzingwindow.h \
udsscanwindow.h \ udsscanwindow.h \
isotp_interpreterwindow.h \ isotp_interpreterwindow.h \
isotp_decoder.h isotp_decoder.h \
canconnectionmodel.h \
canconnection.h \
canconnectioncontainer.h
FORMS += mainwindow.ui \ FORMS += mainwindow.ui \
graphingwindow.ui \ graphingwindow.ui \
+128
View File
@@ -0,0 +1,128 @@
#include "canconnection.h"
CAN_Bus::CAN_Bus()
{
speed = 250000;
listenOnly = false;
singleWire = false;
active = false;
connection = NULL;
busNum = 0;
}
void CAN_Bus::setSpeed(int newSpeed)
{
speed = newSpeed;
}
void CAN_Bus::setListenOnly(bool mode)
{
listenOnly = mode;
}
void CAN_Bus::setSingleWire(bool mode)
{
singleWire = mode;
}
void CAN_Bus::setEnabled(bool mode)
{
active = mode;
}
void CAN_Bus::setConnection(CANConnection *conn)
{
connection = conn;
}
void CAN_Bus::setBusNum(int num)
{
busNum = num;
}
int CAN_Bus::getSpeed()
{
return speed;
}
int CAN_Bus::getBusNum()
{
return busNum;
}
bool CAN_Bus::isListenOnly()
{
return listenOnly;
}
bool CAN_Bus::isSingleWire()
{
return singleWire;
}
bool CAN_Bus::isActive()
{
return active;
}
CANConnection* CAN_Bus::getConnection()
{
return connection;
}
CANConnection::CANConnection(CANFrameModel *pModel, int base)
{
model = pModel;
numBuses = getNumBuses();
busBase = base;
}
int CANConnection::getNumBuses()
{
return 1;
}
int CANConnection::getBusBase()
{
return busBase;
}
QString CANConnection::getConnTypeName()
{
return QString("Generic");
}
QString CANConnection::getConnPortName()
{
return portName;
}
void CANConnection::run()
{
}
void CANConnection::sendFrame(const CANFrame * frame)
{
}
void CANConnection::sendFrameBatch(const QList<CANFrame> *frames)
{
}
void CANConnection::updatePortName(QString portName)
{
this->portName = portName;
}
void CANConnection::stopFrameCapture(int bus)
{
}
void CANConnection::startFrameCapture(int bus)
{
}
+74
View File
@@ -0,0 +1,74 @@
#ifndef CANCONNECTION_H
#define CANCONNECTION_H
#include <Qt>
#include <QObject>
#include "can_structs.h"
#include "canframemodel.h"
class CANConnection;
class CAN_Bus
{
public:
CAN_Bus();
int busNum;
int speed;
bool listenOnly;
bool singleWire;
bool active; //is this bus turned on?
CANConnection *connection;
void setSpeed(int); // new speed
void setListenOnly(bool); //bool for whether to only listen
void setSingleWire(bool); //bool for whether to use single wire mode
void setEnabled(bool); //whether this bus should be enabled or not.
void setConnection(CANConnection *);
void setBusNum(int);
int getSpeed();
int getBusNum();
bool isListenOnly();
bool isSingleWire();
bool isActive();
CANConnection *getConnection();
};
class CANConnection : public QObject
{
Q_OBJECT
public:
CANConnection(CANFrameModel *, int);
virtual int getNumBuses();
int getBusBase();
QString getConnTypeName();
QString getConnPortName();
signals:
void error(const QString &);
void frameUpdateRapid(int);
void frameUpdate(int);
void connectionSuccess();
void connectionFailure();
void deviceInfo(int, int); //First param = driver version (or version of whatever you want), second param a status byte (listen only, single wire, etc)
public slots:
virtual void run();
virtual void sendFrame(const CANFrame *);
virtual void sendFrameBatch(const QList<CANFrame> *);
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.
protected:
bool quit;
int numBuses;
int busBase; //first bus this class is supposed to handle
QString portName; //for easy access later on
QString connType; //what kind of connection this is (socketcan, kvaser, etc)
bool isConnected; //is the whole device connected? (Is the code connected to the device itself)
CANFrameModel *model;
};
#endif // CANCONNECTION_H
+15
View File
@@ -0,0 +1,15 @@
#include "canconnectioncontainer.h"
CANConnectionContainer::CANConnectionContainer(CANConnection *conn)
{
thread = new QThread();
connection = conn;
connection->moveToThread(thread);
}
CANConnectionContainer::~CANConnectionContainer()
{
//have to stop the actual execution first before deleting
delete thread;
delete connection;
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef CANCONNECTIONCONTAINER_H
#define CANCONNECTIONCONTAINER_H
#include "canconnection.h"
#include <QThread>
class CANConnectionContainer
{
public:
CANConnectionContainer(CANConnection *conn);
~CANConnectionContainer();
CANConnection* getRef();
private:
CANConnection *connection;
QThread *thread;
};
#endif // CANCONNECTIONCONTAINER_H
+130
View File
@@ -0,0 +1,130 @@
#include "canconnectionmodel.h"
CANConnectionModel::CANConnectionModel(QObject *parent)
: QAbstractTableModel(parent)
{
}
QVariant CANConnectionModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (role != Qt::DisplayRole)
return QVariant();
if (orientation == Qt::Horizontal)
{
switch (section)
{
case 0:
return QString(tr("Bus"));
break;
case 1:
return QString(tr("Type"));
break;
case 2:
return QString(tr("Port"));
break;
case 3:
return QString(tr("Speed"));
break;
case 4:
return QString(tr("Listen Only"));
break;
case 5:
return QString(tr("Single Wire"));
break;
case 6:
return QString(tr("Active"));
break;
}
}
else
return QString::number(section + 1);
return QVariant();
}
int CANConnectionModel::rowCount(const QModelIndex &parent) const
{
return buses.count();
}
int CANConnectionModel::columnCount(const QModelIndex &parent) const
{
return 7;
}
QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid())
return QVariant();
if (index.row() >= (buses.count()))
return QVariant();
if (role == Qt::DisplayRole) {
CAN_Bus bus = buses[index.row()];
CANConnection *conn = bus.connection;
switch (index.column())
{
case 0: //bus
return QString::number(bus.busNum);
break;
case 1: //type
if (conn) conn->getConnTypeName();
break;
case 2: //port
if (conn) conn->getConnPortName();
break;
case 3: //speed
return QString::number(bus.speed);
break;
case 4: //Listen Only
if (bus.listenOnly) return QString("True");
else return QString("False");
break;
case 5: //Single Wire
if (bus.singleWire) return QString("True");
else return QString("False");
break;
case 6: //Active
if (bus.active) return QString("True");
else return QString("False");
break;
default:
return QVariant();
}
}
else
return QVariant();
}
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);
}
endResetModel();
}
CAN_Bus* CANConnectionModel::findBusByNum(int bus)
{
for (int i = 0; i < buses.count(); i++)
{
if (buses[i].busNum == bus)
{
return &buses[i];
}
}
return NULL;
}
+33
View File
@@ -0,0 +1,33 @@
#ifndef CANCONNECTIONMODEL_H
#define CANCONNECTIONMODEL_H
#include "canconnection.h"
#include "canconnectioncontainer.h"
#include <QAbstractTableModel>
class CANConnectionModel : public QAbstractTableModel
{
Q_OBJECT
public:
explicit CANConnectionModel(QObject *parent = 0);
// Header:
QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
int columnCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
void addConnection(CANConnection *conn);
private:
QList<CANConnectionContainer *> connections;
QList<CAN_Bus> buses;
CAN_Bus *findBusByNum(int bus);
};
#endif // CANCONNECTIONMODEL_H
+90 -76
View File
@@ -2,7 +2,7 @@
#include "ui_connectionwindow.h" #include "ui_connectionwindow.h"
#include <QtNetwork/QNetworkInterface> #include <QtNetwork/QNetworkInterface>
ConnectionWindow::ConnectionWindow(QWidget *parent) : ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
QDialog(parent), QDialog(parent),
ui(new Ui::ConnectionWindow) ui(new Ui::ConnectionWindow)
{ {
@@ -10,34 +10,34 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
settings = new QSettings(); settings = new QSettings();
connModel = new CANConnectionModel();
ui->tableConnections->setModel(connModel);
canModel = cModel;
ui->tableConnections->setColumnWidth(0, 50);
ui->tableConnections->setColumnWidth(1, 110);
ui->tableConnections->setColumnWidth(2, 110);
ui->tableConnections->setColumnWidth(3, 150);
ui->tableConnections->setColumnWidth(4, 75);
ui->tableConnections->setColumnWidth(5, 75);
ui->tableConnections->setColumnWidth(6, 75);
int temp = settings->value("Main/DefaultConnectionType", 0).toInt(); int temp = settings->value("Main/DefaultConnectionType", 0).toInt();
if (temp == 0) currentConnType = ConnectionType::GVRET_SERIAL; //currentPortName = settings->value("Main/DefaultConnectionPort", "").toString();
if (temp == 1) currentConnType = ConnectionType::KVASER;
if (temp == 2) currentConnType = ConnectionType::SOCKETCAN;
currentPortName = settings->value("Main/DefaultConnectionPort", "").toString(); //currentSpeed1 = -1;
currentSpeed1 = -1;
currentSpeed2 = -1;
ui->ckSingleWire->setChecked(settings->value("Main/SingleWireMode", false).toBool()); ui->ckSingleWire->setChecked(settings->value("Main/SingleWireMode", false).toBool());
ui->cbSpeed0->addItem(tr("<Default>")); ui->cbSpeed->addItem(tr("<Default>"));
ui->cbSpeed0->addItem(tr("Disabled")); ui->cbSpeed->addItem(tr("Disabled"));
ui->cbSpeed0->addItem(tr("125000")); ui->cbSpeed->addItem(tr("125000"));
ui->cbSpeed0->addItem(tr("250000")); ui->cbSpeed->addItem(tr("250000"));
ui->cbSpeed0->addItem(tr("500000")); ui->cbSpeed->addItem(tr("500000"));
ui->cbSpeed0->addItem(tr("1000000")); ui->cbSpeed->addItem(tr("1000000"));
ui->cbSpeed0->addItem(tr("33333")); ui->cbSpeed->addItem(tr("33333"));
ui->cbSpeed1->addItem(tr("<Default>"));
ui->cbSpeed1->addItem(tr("Disabled"));
ui->cbSpeed1->addItem(tr("125000"));
ui->cbSpeed1->addItem(tr("250000"));
ui->cbSpeed1->addItem(tr("500000"));
ui->cbSpeed1->addItem(tr("1000000"));
ui->cbSpeed1->addItem(tr("33333"));
#ifdef Q_OS_LINUX #ifdef Q_OS_LINUX
ui->rbSocketCAN->setEnabled(true); ui->rbSocketCAN->setEnabled(true);
@@ -47,10 +47,12 @@ ConnectionWindow::ConnectionWindow(QWidget *parent) :
ui->rbKvaser->setEnabled(true); ui->rbKvaser->setEnabled(true);
#endif #endif
connect(ui->btnOK, SIGNAL(clicked(bool)), this, SLOT(handleOKButton())); connect(ui->btnOK, &QAbstractButton::clicked, this, &ConnectionWindow::handleOKButton);
connect(ui->rbGVRET, SIGNAL(toggled(bool)), this, SLOT(handleConnTypeChanged())); connect(ui->rbGVRET, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbKvaser, SIGNAL(toggled(bool)), this, SLOT(handleConnTypeChanged())); connect(ui->rbKvaser, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->rbSocketCAN, SIGNAL(toggled(bool)), this, SLOT(handleConnTypeChanged())); connect(ui->rbSocketCAN, &QAbstractButton::toggled, this, &ConnectionWindow::handleConnTypeChanged);
connect(ui->btnRevert, &QPushButton::clicked, this, &ConnectionWindow::handleRevert);
connect(ui->tableConnections->selectionModel(), &QItemSelectionModel::selectionChanged, this, &ConnectionWindow::handleConnSelectionChanged);
} }
ConnectionWindow::~ConnectionWindow() ConnectionWindow::~ConnectionWindow()
@@ -78,6 +80,28 @@ void ConnectionWindow::handleOKButton()
QString conn; QString conn;
int connType = 0; int connType = 0;
if (ui->tableConnections->selectionModel()->currentIndex().row() >= 0)
{
}
else //new connection
{
if (ui->rbGVRET->isChecked())
{
SerialWorker *serial = new SerialWorker(canModel, 0);
connModel->addConnection(serial);
}
else if (ui->rbKvaser->isChecked())
{
}
else if (ui->rbSocketCAN->isChecked())
{
}
}
/*
if (ui->rbGVRET->isChecked()) if (ui->rbGVRET->isChecked())
{ {
conn = "GVRET"; conn = "GVRET";
@@ -100,16 +124,29 @@ void ConnectionWindow::handleOKButton()
} }
currentPortName = getPortName(); currentPortName = getPortName();
currentSpeed1 = getSpeed0(); currentSpeed1 = getSpeed();
currentSpeed2 = getSpeed1();
settings->setValue("Main/DefaultConnectionPort", currentPortName); settings->setValue("Main/DefaultConnectionPort", currentPortName);
settings->setValue("Main/DefaultConnectionType", connType); settings->setValue("Main/DefaultConnectionType", connType);
settings->setValue("Main/SingleWireMode", ui->ckSingleWire->isChecked()); settings->setValue("Main/SingleWireMode", ui->ckSingleWire->isChecked());
emit updateConnectionSettings(conn, getPortName(), getSpeed0(), getSpeed1()); emit updateConnectionSettings(conn, getPortName(), getSpeed());
this->close(); this->close();
*/
}
void ConnectionWindow::handleConnSelectionChanged()
{
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
if (selIdx == 0)
{
ui->btnOK->setText(tr("Create New Connection"));
}
else
{
ui->btnOK->setText(tr("Update Connection Settings"));
}
} }
void ConnectionWindow::getSerialPorts() void ConnectionWindow::getSerialPorts()
@@ -120,7 +157,7 @@ void ConnectionWindow::getSerialPorts()
for (int i = 0; i < ports.count(); i++) for (int i = 0; i < ports.count(); i++)
{ {
ui->cbPort->addItem(ports[i].portName()); ui->cbPort->addItem(ports[i].portName());
if (currentPortName == ports[i].portName()) ui->cbPort->setCurrentIndex(i); //if (currentPortName == ports[i].portName()) ui->cbPort->setCurrentIndex(i);
} }
} }
@@ -147,47 +184,33 @@ void ConnectionWindow::getSocketcanPorts()
} }
} }
void ConnectionWindow::setSpeeds(int speed0, int speed1) void ConnectionWindow::setSpeed(int speed0)
{ {
bool found = false; bool found = false;
qDebug() << speed0 << "X" << speed1; qDebug() << speed0;
for (int i = 0; i < ui->cbSpeed0->count(); i++) for (int i = 0; i < ui->cbSpeed->count(); i++)
{ {
if (ui->cbSpeed0->itemText(i).toInt() == speed0) if (ui->cbSpeed->itemText(i).toInt() == speed0)
{ {
ui->cbSpeed0->setCurrentIndex(i); ui->cbSpeed->setCurrentIndex(i);
found = true; found = true;
} }
} }
if (!found) if (!found)
{ {
ui->cbSpeed0->addItem(QString::number(speed0)); ui->cbSpeed->addItem(QString::number(speed0));
ui->cbSpeed0->setCurrentIndex(ui->cbSpeed0->count() - 1); ui->cbSpeed->setCurrentIndex(ui->cbSpeed->count() - 1);
} }
found = false;
for (int i = 0; i < ui->cbSpeed1->count(); i++)
{
if (ui->cbSpeed1->itemText(i).toInt() == speed1)
{
ui->cbSpeed1->setCurrentIndex(i);
found = true;
}
}
if (!found)
{
ui->cbSpeed1->addItem(QString::number(speed1));
ui->cbSpeed1->setCurrentIndex(ui->cbSpeed1->count() - 1);
}
} }
//-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want. //-1 means leave it at whatever it booted up to. 0 means disable. Otherwise the actual rate we want.
int ConnectionWindow::getSpeed0() int ConnectionWindow::getSpeed()
{ {
switch (ui->cbSpeed0->currentIndex()) switch (ui->cbSpeed->currentIndex())
{ {
case -1: case -1:
return -1; return -1;
@@ -199,26 +222,7 @@ int ConnectionWindow::getSpeed0()
return 0; return 0;
break; break;
default: default:
return (ui->cbSpeed0->currentText().toInt()); return (ui->cbSpeed->currentText().toInt());
break;
}
}
int ConnectionWindow::getSpeed1()
{
switch (ui->cbSpeed1->currentIndex())
{
case -1:
return -1;
break;
case 0:
return -1;
break;
case 1:
return 0;
break;
default:
return (ui->cbSpeed1->currentText().toInt());
break; break;
} }
} }
@@ -235,13 +239,23 @@ ConnectionType::ConnectionType ConnectionWindow::getConnectionType()
if (ui->rbSocketCAN->isChecked()) return ConnectionType::SOCKETCAN; if (ui->rbSocketCAN->isChecked()) return ConnectionType::SOCKETCAN;
} }
void ConnectionWindow::setCAN1SWMode(bool mode) void ConnectionWindow::setSWMode(bool mode)
{ {
ui->ckSingleWire->setChecked(mode); ui->ckSingleWire->setChecked(mode);
} }
bool ConnectionWindow::getCAN1SWMode() bool ConnectionWindow::getSWMode()
{ {
if (ui->ckSingleWire->checkState() == Qt::Checked) return true; if (ui->ckSingleWire->checkState() == Qt::Checked) return true;
return false; return false;
} }
void ConnectionWindow::handleRemoveConn()
{
}
void ConnectionWindow::handleRevert()
{
}
+16 -10
View File
@@ -1,10 +1,14 @@
#ifndef CONNECTIONWINDOW_H #ifndef CONNECTIONWINDOW_H
#define CONNECTIONWINDOW_H #define CONNECTIONWINDOW_H
#include "canconnectionmodel.h"
#include <QSerialPortInfo> #include <QSerialPortInfo>
#include <QDialog> #include <QDialog>
#include <QDebug> #include <QDebug>
#include <QSettings> #include <QSettings>
#include "canconnection.h"
#include "serialworker.h"
namespace Ui { namespace Ui {
class ConnectionWindow; class ConnectionWindow;
@@ -25,34 +29,36 @@ class ConnectionWindow : public QDialog
Q_OBJECT Q_OBJECT
public: public:
explicit ConnectionWindow(QWidget *parent = 0); explicit ConnectionWindow(CANFrameModel *canModel, QWidget *parent = 0);
~ConnectionWindow(); ~ConnectionWindow();
void showEvent(QShowEvent *); void showEvent(QShowEvent *);
int getSpeed0(); int getSpeed();
int getSpeed1();
QString getPortName(); //name of port to connect to QString getPortName(); //name of port to connect to
ConnectionType::ConnectionType getConnectionType(); ConnectionType::ConnectionType getConnectionType();
bool getCAN1SWMode(); bool getSWMode();
signals: signals:
void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1); void updateConnectionSettings(QString connectionType, QString port, int speed);
public slots: public slots:
void setSpeeds(int speed0, int speed1); void setSpeed(int speed0);
void setCAN1SWMode(bool mode); void setSWMode(bool mode);
private slots: private slots:
void handleOKButton(); void handleOKButton();
void handleConnTypeChanged(); void handleConnTypeChanged();
void handleConnSelectionChanged();
void handleRemoveConn();
void handleRevert();
private: private:
Ui::ConnectionWindow *ui; Ui::ConnectionWindow *ui;
QList<QSerialPortInfo> ports; QList<QSerialPortInfo> ports;
QSettings *settings; QSettings *settings;
CANConnectionModel *connModel;
CANFrameModel *canModel;
ConnectionType::ConnectionType currentConnType;
QString currentPortName;
int currentSpeed1, currentSpeed2;
void getSerialPorts(); void getSerialPorts();
void getKvaserPorts(); void getKvaserPorts();
+167 -85
View File
@@ -6,109 +6,191 @@
<rect> <rect>
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>335</width> <width>952</width>
<height>235</height> <height>433</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>Connection Settings</string> <string>Connection Settings</string>
</property> </property>
<layout class="QVBoxLayout" name="verticalLayout"> <layout class="QHBoxLayout" name="horizontalLayout" stretch="2,1">
<item> <item>
<widget class="QGroupBox" name="groupBox"> <layout class="QVBoxLayout" name="verticalLayout">
<property name="title"> <item alignment="Qt::AlignHCenter">
<string>Connection Type</string> <widget class="QLabel" name="label_4">
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QRadioButton" name="rbGVRET">
<property name="text">
<string>GVRET Serial</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbKvaser">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Kvaser</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbSocketCAN">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>SocketCAN</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbPort"/>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text"> <property name="text">
<string>CAN0 Speed</string> <string>Connections:</string>
</property> </property>
</widget> </widget>
</item> </item>
<item row="0" column="1"> <item>
<widget class="QLabel" name="label_3"> <widget class="QTableView" name="tableConnections">
<property name="text"> <property name="selectionMode">
<string>CAN1 Speed</string> <enum>QAbstractItemView::SingleSelection</enum>
</property>
<property name="selectionBehavior">
<enum>QAbstractItemView::SelectRows</enum>
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="0"> <item>
<widget class="QComboBox" name="cbSpeed0"/> <layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QPushButton" name="btnBusActivate">
<property name="text">
<string>Activate Selected Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRemoveBus">
<property name="text">
<string>Remove Selected Connection</string>
</property>
</widget>
</item>
</layout>
</item> </item>
<item row="1" column="1"> <item>
<widget class="QComboBox" name="cbSpeed1"/> <layout class="QHBoxLayout" name="horizontalLayout_6">
<item>
<widget class="QPushButton" name="btnActivateAll">
<property name="text">
<string>Activate All Connections</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnDeactivateAll">
<property name="text">
<string>Deactivate All Connections</string>
</property>
</widget>
</item>
</layout>
</item> </item>
</layout> </layout>
</item> </item>
<item> <item>
<widget class="QCheckBox" name="ckSingleWire"> <layout class="QVBoxLayout" name="verticalLayout_2">
<property name="text"> <item>
<string>Set CAN1 to Single Wire Mode</string> <widget class="QGroupBox" name="groupBox">
</property> <property name="title">
</widget> <string>Connection Type</string>
</item> </property>
<item> <property name="alignment">
<widget class="QPushButton" name="btnOK"> <set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignVCenter</set>
<property name="text"> </property>
<string>Update Settings</string> <layout class="QHBoxLayout" name="horizontalLayout_2">
</property> <item>
</widget> <widget class="QRadioButton" name="rbGVRET">
<property name="text">
<string>GVRET Serial</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbKvaser">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Kvaser</string>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="rbSocketCAN">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>SocketCAN</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<widget class="QLabel" name="label">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Port:</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbPort"/>
</item>
<item>
<widget class="QCheckBox" name="ckSingleWire">
<property name="text">
<string>Single Wire Mode</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="ckListenOnly">
<property name="text">
<string>Listen Only Mode</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3" stretch="1,2">
<item>
<widget class="QLabel" name="label_2">
<property name="text">
<string>CAN Speed</string>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="cbSpeed"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QPushButton" name="btnOK">
<property name="text">
<string>Create New Connection</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnRevert">
<property name="text">
<string>Revert</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</item> </item>
</layout> </layout>
</widget> </widget>
+3 -3
View File
@@ -80,7 +80,7 @@ void FirmwareUploaderWindow::gotTargettedFrame(int frameLoc)
if ((frame.data[6] == ((token >> 16) & 0xFF)) && (frame.data[7] == ((token >> 24) & 0xFF))) if ((frame.data[6] == ((token >> 16) & 0xFF)) && (frame.data[7] == ((token >> 24) & 0xFF)))
{ {
qDebug() << "starting firmware process"; qDebug() << "starting firmware process";
MainWindow::getReference()->setTargettedID(baseAddress + 0x20); //MainWindow::getReference()->setTargettedID(baseAddress + 0x20);
transferInProgress = true; transferInProgress = true;
sendFirmwareChunk(); sendFirmwareChunk();
} }
@@ -163,7 +163,7 @@ void FirmwareUploaderWindow::handleStartStopTransfer()
bus = ui->spinBus->value(); bus = ui->spinBus->value();
baseAddress = Utility::ParseStringToNum(ui->txtBaseAddr->text()); baseAddress = Utility::ParseStringToNum(ui->txtBaseAddr->text());
qDebug() << "Base address: " + QString::number(baseAddress); qDebug() << "Base address: " + QString::number(baseAddress);
MainWindow::getReference()->setTargettedID(baseAddress + 0x10); //MainWindow::getReference()->setTargettedID(baseAddress + 0x10);
CANFrame *output = new CANFrame; CANFrame *output = new CANFrame;
output->extended = false; output->extended = false;
output->len = 8; output->len = 8;
@@ -181,7 +181,7 @@ void FirmwareUploaderWindow::handleStartStopTransfer()
else //stop anything in process else //stop anything in process
{ {
ui->btnStartStop->setText("Start Upload"); ui->btnStartStop->setText("Start Upload");
MainWindow::getReference()->setTargettedID(-1); //MainWindow::getReference()->setTargettedID(-1);
} }
} }
+8 -59
View File
@@ -64,6 +64,7 @@ MainWindow::MainWindow(QWidget *parent) :
//enabling the below line kills performance in every way imaginable. Left here as a warning. Do not do this. //enabling the below line kills performance in every way imaginable. Left here as a warning. Do not do this.
//ui->canFramesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents); //ui->canFramesView->verticalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents);
/*
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);
@@ -81,6 +82,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(this, &MainWindow::settingsUpdated, worker, &SerialWorker::readSettings); connect(this, &MainWindow::settingsUpdated, worker, &SerialWorker::readSettings);
serialWorkerThread.start(); serialWorkerThread.start();
serialWorkerThread.setPriority(QThread::HighPriority); serialWorkerThread.setPriority(QThread::HighPriority);
*/
graphingWindow = NULL; graphingWindow = NULL;
frameInfoWindow = NULL; frameInfoWindow = NULL;
@@ -176,7 +178,7 @@ MainWindow::MainWindow(QWidget *parent) :
model->clearFrames(); model->clearFrames();
//Automatically create the connection window so it can be updated even if we never opened it. //Automatically create the connection window so it can be updated even if we never opened it.
connectionWindow = new ConnectionWindow(); connectionWindow = new ConnectionWindow(model);
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int))); connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
} }
@@ -384,45 +386,7 @@ void MainWindow::updateConnectionSettings(QString connectionType, QString port,
canSpeed1 = speed1; canSpeed1 = speed1;
if (isConnected) if (isConnected)
{ {
emit updateBaudRates(speed0, speed1); //emit updateBaudRates(speed0, speed1);
}
}
void MainWindow::connButtonPress()
{
if (!isConnected)
{
if (connType == "GVRET")
{
QList<QSerialPortInfo> ports;
ports = QSerialPortInfo::availablePorts();
for (int i = 0; i < ports.count(); i++)
{
if (ports[i].portName() == portName)
{
portInfo = ports[i];
//need to create some way to send single wire mode to serial port code
emit sendSerialPort(&portInfo);
lbStatusConnected.setText(tr("Attempting to connect to port ") + portName);
}
}
}
else if (connType == "KVASER")
{
}
else if (connType == "SOCKETCAN")
{
}
}
else
{
emit closeSerialPort();
isConnected = false;
lbStatusConnected.setText(tr("Not Connected"));
ui->actionConnect->setText(tr("Connect"));
} }
} }
@@ -576,16 +540,6 @@ void MainWindow::normalizeTiming()
emit framesUpdated(-2); //claim an all new set of frames because every frame was updated. emit framesUpdated(-2); //claim an all new set of frames because every frame was updated.
} }
void MainWindow::changeBaudRates()
{
int Speed1 = 0, Speed2 = 0;
//Speed1 = ui->cbSpeed1->currentText().toInt();
//Speed2 = ui->cbSpeed2->currentText().toInt();
emit updateBaudRates(Speed1, Speed2);
}
void MainWindow::handleLoadFile() void MainWindow::handleLoadFile()
{ {
QString filename; QString filename;
@@ -785,7 +739,7 @@ void MainWindow::connectionSucceeded(int baud0, int baud1)
ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1); ui->cbSpeed2->setCurrentIndex(ui->cbSpeed2->count() - 1);
} }
*/ */
if (connectionWindow) connectionWindow->setSpeeds(baud0, baud1); if (connectionWindow) connectionWindow->setSpeed(baud0);
//ui->btnConnect->setEnabled(false); //ui->btnConnect->setEnabled(false);
ui->actionConnect->setText(tr("Disconnect")); ui->actionConnect->setText(tr("Disconnect"));
isConnected = true; isConnected = true;
@@ -843,16 +797,11 @@ void MainWindow::gotDeviceInfo(int build, int swCAN)
if (connectionWindow) if (connectionWindow)
{ {
if (swCAN == 1) connectionWindow->setCAN1SWMode(true); if (swCAN == 1) connectionWindow->setSWMode(true);
else connectionWindow->setCAN1SWMode(false); else connectionWindow->setSWMode(false);
} }
} }
void MainWindow::setTargettedID(int id)
{
worker->targetFrameID(id);
}
void MainWindow::showSettingsDialog() void MainWindow::showSettingsDialog()
{ {
if (!settingsDialog) if (!settingsDialog)
@@ -1039,7 +988,7 @@ void MainWindow::showConnectionSettingsWindow()
{ {
if (!connectionWindow) if (!connectionWindow)
{ {
connectionWindow = new ConnectionWindow(); connectionWindow = new ConnectionWindow(model);
connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int))); connect(connectionWindow, SIGNAL(updateConnectionSettings(QString,QString,int,int)), this, SLOT(updateConnectionSettings(QString,QString,int,int)));
} }
connectionWindow->show(); connectionWindow->show();
-6
View File
@@ -39,7 +39,6 @@ public:
explicit MainWindow(QWidget *parent = 0); explicit MainWindow(QWidget *parent = 0);
static QString loadedFileName; static QString loadedFileName;
static MainWindow *getReference(); static MainWindow *getReference();
void setTargettedID(int);
~MainWindow(); ~MainWindow();
private slots: private slots:
@@ -48,7 +47,6 @@ private slots:
void handleSaveFilteredFile(); void handleSaveFilteredFile();
void handleSaveFilters(); void handleSaveFilters();
void handleLoadFilters(); void handleLoadFilters();
void connButtonPress();
void showGraphingWindow(); void showGraphingWindow();
void showFrameDataAnalysis(); void showFrameDataAnalysis();
void clearFrames(); void clearFrames();
@@ -69,7 +67,6 @@ private slots:
void showISOInterpreterWindow(); void showISOInterpreterWindow();
void exitApp(); void exitApp();
void handleSaveDecoded(); void handleSaveDecoded();
void changeBaudRates();
void connectionFailed(); void connectionFailed();
void gotDeviceInfo(int, int); void gotDeviceInfo(int, int);
void connectionSucceeded(int, int); void connectionSucceeded(int, int);
@@ -92,9 +89,6 @@ public slots:
void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1); void updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1);
signals: signals:
void sendSerialPort(QSerialPortInfo *port);
void closeSerialPort();
void updateBaudRates(int, int);
void sendCANFrame(const CANFrame *, int); void sendCANFrame(const CANFrame *, int);
void stopFrameCapturing(); void stopFrameCapturing();
void startFrameCapturing(); void startFrameCapturing();
+36 -23
View File
@@ -5,19 +5,16 @@
#include <QTimer> #include <QTimer>
#include <QSettings> #include <QSettings>
SerialWorker::SerialWorker(CANFrameModel *model, QObject *parent) : QObject(parent) SerialWorker::SerialWorker(CANFrameModel *model, int base) : CANConnection(model, base)
{ {
serial = NULL; serial = NULL;
rx_state = IDLE; rx_state = IDLE;
rx_step = 0; rx_step = 0;
buildFrame = new CANFrame; buildFrame = new CANFrame;
canModel = model;
ticker = NULL; ticker = NULL;
framesRapid = 0; framesRapid = 0;
capturing = true;
gotValidated = true; gotValidated = true;
isAutoRestart = false; isAutoRestart = false;
targetID = -1;
txTimestampBasis = QDateTime::currentMSecsSinceEpoch(); txTimestampBasis = QDateTime::currentMSecsSinceEpoch();
@@ -121,8 +118,8 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
continuousTimeSync = true; continuousTimeSync = true;
serial->write(output); serial->write(output);
if (doValidation) connected = false; if (doValidation) isConnected = false;
else connected = true; else isConnected = true;
connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData())); connect(serial, SIGNAL(readyRead()), this, SLOT(readSerialData()));
if (doValidation) QTimer::singleShot(1000, this, SLOT(connectionTimeout())); if (doValidation) QTimer::singleShot(1000, this, SLOT(connectionTimeout()));
} }
@@ -130,7 +127,7 @@ void SerialWorker::setSerialPort(QSerialPortInfo *port)
void SerialWorker::connectionTimeout() void SerialWorker::connectionTimeout()
{ {
//one second after trying to connect are we actually connected? //one second after trying to connect are we actually connected?
if (!connected) //no? if (!isConnected) //no?
{ {
//then emit the the failure signal and see if anyone cares //then emit the the failure signal and see if anyone cares
qDebug() << "Failed to connect to GVRET at that com port"; qDebug() << "Failed to connect to GVRET at that com port";
@@ -157,7 +154,7 @@ void SerialWorker::readSerialData()
} }
} }
void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0) void SerialWorker::sendFrame(const CANFrame *frame)
{ {
QByteArray buffer; QByteArray buffer;
int c; int c;
@@ -169,12 +166,12 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
//qDebug() << "Sending out frame with id " << frame->ID; //qDebug() << "Sending out frame with id " << frame->ID;
//show our sent frames in the list too. This happens even if we're not connected. //show our sent frames in the list too. This happens even if we're not connected.
canModel->addFrame(tempFrame, false); model->addFrame(tempFrame, false);
framesRapid++; framesRapid++;
if (serial == NULL) return; if (serial == NULL) return;
if (!serial->isOpen()) return; if (!serial->isOpen()) return;
if (!connected) return; if (!isConnected) return;
ID = frame->ID; ID = frame->ID;
if (frame->extended) ID |= 1 << 31; if (frame->extended) ID |= 1 << 31;
@@ -185,7 +182,7 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
buffer[3] = (unsigned char)(ID >> 8); buffer[3] = (unsigned char)(ID >> 8);
buffer[4] = (unsigned char)(ID >> 16); buffer[4] = (unsigned char)(ID >> 16);
buffer[5] = (unsigned char)(ID >> 24); buffer[5] = (unsigned char)(ID >> 24);
buffer[6] = (unsigned char)(bus & 1); buffer[6] = (unsigned char)((frame->bus - this->getBusBase()) & 1);
buffer[7] = (unsigned char)frame->len; buffer[7] = (unsigned char)frame->len;
for (c = 0; c < frame->len; c++) for (c = 0; c < frame->len; c++)
{ {
@@ -203,7 +200,7 @@ void SerialWorker::sendFrame(const CANFrame *frame, int bus = 0)
void SerialWorker::sendFrameBatch(const QList<CANFrame> *frames) void SerialWorker::sendFrameBatch(const QList<CANFrame> *frames)
{ {
sendBulkMutex.lock(); sendBulkMutex.lock();
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));
sendBulkMutex.unlock(); sendBulkMutex.unlock();
} }
@@ -321,15 +318,14 @@ void SerialWorker::procRXChar(unsigned char c)
rx_state = IDLE; rx_state = IDLE;
rx_step = 0; rx_step = 0;
//qDebug() << "emit from serial handler to main form id: " << buildFrame->ID; //qDebug() << "emit from serial handler to main form id: " << buildFrame->ID;
if (capturing) //if (capturing)
{ //{
buildFrame->isReceived = true; buildFrame->isReceived = true;
canModel->addFrame(*buildFrame, false); model->addFrame(*buildFrame, false);
//take the time the frame came in and try to resync the time base. //take the time the frame came in and try to resync the time base.
if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame->timestamp / 1000); if (continuousTimeSync) txTimestampBasis = QDateTime::currentMSecsSinceEpoch() - (buildFrame->timestamp / 1000);
framesRapid++; framesRapid++;
if (buildFrame->ID == targetID) emit gotTargettedFrame(canModel->rowCount() - 1); //}
}
} }
break; break;
} }
@@ -414,8 +410,8 @@ void SerialWorker::procRXChar(unsigned char c)
qDebug() << "Baud 1 = " << can1Baud; qDebug() << "Baud 1 = " << can1Baud;
if (!can1Enabled) can1Baud = 0; if (!can1Enabled) can1Baud = 0;
if (!can0Enabled) can0Baud = 0; if (!can0Enabled) can0Baud = 0;
connected = true; isConnected = true;
emit connectionSuccess(can0Baud, can1Baud); emit connectionSuccess();
break; break;
} }
rx_step++; rx_step++;
@@ -462,7 +458,7 @@ void SerialWorker::handleTick()
{ {
//qDebug() << "Tick!"; //qDebug() << "Tick!";
if (connected) if (isConnected)
{ {
if (!gotValidated && doValidation) if (!gotValidated && doValidation)
{ {
@@ -517,6 +513,7 @@ void SerialWorker::closeSerialPort()
serial = NULL; serial = NULL;
} }
/*
void SerialWorker::stopFrameCapture() void SerialWorker::stopFrameCapture()
{ {
qDebug() << "Stopping frame capture"; qDebug() << "Stopping frame capture";
@@ -528,8 +525,24 @@ void SerialWorker::startFrameCapture()
qDebug() << "Starting up frame capture"; qDebug() << "Starting up frame capture";
capturing = true; capturing = true;
} }
*/
void SerialWorker::targetFrameID(int target) void SerialWorker::updatePortName(QString portName)
{ {
targetID = target; QList<QSerialPortInfo> ports;
CANConnection::updatePortName(portName);
ports = QSerialPortInfo::availablePorts();
for (int i = 0; i < ports.count(); i++)
{
if (portName == ports[i].portName())
{
setSerialPort(&ports[i]);
return;
}
}
} }
+10 -23
View File
@@ -8,6 +8,7 @@
#include <QTimer> #include <QTimer>
#include "can_structs.h" #include "can_structs.h"
#include "canframemodel.h" #include "canframemodel.h"
#include "canconnection.h"
namespace SERIALSTATE { namespace SERIALSTATE {
@@ -29,23 +30,14 @@ enum STATE //keep this enum synchronized with the Arduino firmware project
} }
using namespace SERIALSTATE; using namespace SERIALSTATE;
class SerialWorker : public QObject class SerialWorker : public CANConnection
{ {
Q_OBJECT Q_OBJECT
public: public:
SerialWorker(CANFrameModel *model, QObject *parent = 0); SerialWorker(CANFrameModel *, int);
~SerialWorker(); ~SerialWorker();
void readSettings(); void readSettings();
void targetFrameID(int);
signals: //we emit signals
void error(const QString &);
void frameUpdateRapid(int); //sent *much* more rapidly than the above signal - one param for # of frames
void connectionSuccess(int, int);
void connectionFailure();
void deviceInfo(int, int);
void gotTargettedFrame(int);
private slots: //we receive things in slots private slots: //we receive things in slots
void readSerialData(); void readSerialData();
@@ -54,31 +46,26 @@ private slots: //we receive things in slots
void handleReconnect(); void handleReconnect();
public slots: public slots:
void run(); void run() override;
void setSerialPort(QSerialPortInfo*); void setSerialPort(QSerialPortInfo*);
void closeSerialPort(); void closeSerialPort();
void sendFrame(const CANFrame *, int); void sendFrame(const CANFrame *) override;
void sendFrameBatch(const QList<CANFrame> *); void sendFrameBatch(const QList<CANFrame> *) override;
void updateBaudRates(int, int); void updateBaudRates(int, int);
void stopFrameCapture(); //void stopFrameCapture(int) override;
void startFrameCapture(); //only need to call this if previously stopped. Otherwise it's the default //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
private: private:
QString portName;
bool quit;
bool connected;
bool capturing;
bool doValidation; bool doValidation;
bool gotValidated; bool gotValidated;
bool isAutoRestart; bool isAutoRestart;
bool continuousTimeSync; bool continuousTimeSync;
QSerialPort *serial; QSerialPort *serial;
QSerialPortInfo *currentPort; QSerialPortInfo *currentPort;
CANFrameModel *canModel;
QTimer *ticker; QTimer *ticker;
QMutex sendBulkMutex; QMutex sendBulkMutex;
int framesRapid; int framesRapid;
int targetID;
STATE rx_state; STATE rx_state;
int rx_step; int rx_step;
CANFrame *buildFrame; CANFrame *buildFrame;