Additional implementation of the new connection scheme. It is now possible to send frames to CANConnection objects indirectly based on registered bus number.

This further abstracts the interface. Things are reasonably stable now for frame reception. Initial work has been done to support frame transmission as well. This is currently less stable but mostly working.
This commit is contained in:
Collin Kidder
2016-03-27 22:37:02 -04:00
parent 3c6f7cb2ea
commit a3cd14e495
18 changed files with 128 additions and 50 deletions
+74 -3
View File
@@ -10,6 +10,10 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
settings = new QSettings();
qRegisterMetaType<CAN_Bus *>("CAN_Bus *");
qRegisterMetaType<const CANFrame *>("const CANFrame *");
qRegisterMetaType<const QList<CANFrame> *>("const QList<CANFrame> *");
connModel = new CANConnectionModel();
ui->tableConnections->setModel(connModel);
@@ -53,6 +57,7 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) :
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);
connect(ui->btnNewConn, &QPushButton::clicked, this, &ConnectionWindow::handleNewConn);
}
ConnectionWindow::~ConnectionWindow()
@@ -68,6 +73,13 @@ void ConnectionWindow::showEvent(QShowEvent* event)
handleConnTypeChanged();
}
void ConnectionWindow::handleNewConn()
{
ui->tableConnections->selectionModel()->clearSelection();
ui->tableConnections->selectionModel()->clearCurrentIndex();
handleConnSelectionChanged();
}
void ConnectionWindow::handleConnTypeChanged()
{
if (ui->rbGVRET->isChecked()) getSerialPorts();
@@ -79,10 +91,29 @@ void ConnectionWindow::handleOKButton()
{
QString conn;
int connType = 0;
int whichRow = ui->tableConnections->selectionModel()->currentIndex().row();
qDebug() << whichRow;
if (ui->tableConnections->selectionModel()->currentIndex().row() >= 0)
if (whichRow > -1)
{
//load settings from GUI into appropriate CAN_Bus entry and then send it off to the appropriate
//CANConnection object
CAN_Bus *bus = connModel->getBus(whichRow);
bus->setListenOnly(ui->ckListenOnly->isChecked());
bus->setSingleWire(ui->ckSingleWire->isChecked());
if (ui->cbSpeed->currentIndex() == 1)
{
bus->speed = 0;
bus->setEnabled(false);
}
else if (ui->cbSpeed->currentIndex() > 1)
{
bus->setSpeed(ui->cbSpeed->currentText().toInt());
}
//call through signal/slot interface without using connect
QMetaObject::invokeMethod(bus->connection, "updateBusSettings",
Qt::QueuedConnection,
Q_ARG(CAN_Bus *, bus));
}
else //new connection
{
@@ -162,13 +193,34 @@ void ConnectionWindow::receiveBusStatus(int bus, int speed, int status)
void ConnectionWindow::handleConnSelectionChanged()
{
int selIdx = ui->tableConnections->selectionModel()->currentIndex().row();
if (selIdx == 0)
qDebug() << selIdx;
if (selIdx == -1)
{
ui->btnOK->setText(tr("Create New Connection"));
ui->cbPort->setEnabled(true);
ui->rbGVRET->setEnabled(true);
ui->rbKvaser->setEnabled(true);
ui->rbSocketCAN->setEnabled(true);
ui->cbPort->setCurrentIndex(0);
ui->ckListenOnly->setChecked(false);
ui->ckSingleWire->setChecked(false);
}
else
{
ui->btnOK->setText(tr("Update Connection Settings"));
ui->cbPort->setEnabled(false);
ui->rbGVRET->setEnabled(false);
ui->rbKvaser->setEnabled(false);
ui->rbSocketCAN->setEnabled(false);
CAN_Bus *bus = connModel->getBus(selIdx);
if (bus->connection->getConnTypeName() == "GVRET") ui->rbGVRET->setChecked(true);
if (bus->connection->getConnTypeName() == "KVASER") ui->rbKvaser->setChecked(true);
if (bus->connection->getConnTypeName() == "SOCKETCAN") ui->rbSocketCAN->setChecked(true);
ui->ckListenOnly->setChecked(bus->isListenOnly());
ui->ckSingleWire->setChecked(bus->isSingleWire());
int speed = bus->getSpeed();
setSpeed(speed);
connModel->refreshView();
}
}
@@ -284,3 +336,22 @@ void ConnectionWindow::handleRevert()
{
}
void ConnectionWindow::sendFrame(const CANFrame *frame)
{
CAN_Bus *bus = connModel->getBus(frame->bus);
if (bus == NULL) return;
QMetaObject::invokeMethod(bus->connection, "sendFrame",
Qt::QueuedConnection,
Q_ARG(const CANFrame *, frame));
}
void ConnectionWindow::sendFrameBatch(const QList<CANFrame> *frames)
{
if (frames->count() == 0) return;
CAN_Bus *bus = connModel->getBus(frames->at(0).bus);
if (bus == NULL) return;
QMetaObject::invokeMethod(bus->connection, "sendFrameBatch",
Qt::QueuedConnection,
Q_ARG(const QList<CANFrame> *, frames));
}
+3
View File
@@ -46,6 +46,8 @@ signals:
public slots:
void setSpeed(int speed0);
void setSWMode(bool mode);
void sendFrame(const CANFrame *);
void sendFrameBatch(const QList<CANFrame> *);
private slots:
void handleOKButton();
@@ -53,6 +55,7 @@ private slots:
void handleConnSelectionChanged();
void handleRemoveConn();
void handleRevert();
void handleNewConn();
void receiveBusStatus(int bus, int speed, int status);
private:
+7
View File
@@ -33,6 +33,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnNewConn">
<property name="text">
<string>New Connection</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
+6 -3
View File
@@ -125,6 +125,7 @@ void FirmwareUploaderWindow::sendFirmwareChunk()
int xorByte = 0;
output->extended = false;
output->len = 7;
output->bus = bus;
output->ID = baseAddress + 0x16;
output->data[0] = currentSendingPosition & 0xFF;
output->data[1] = (currentSendingPosition >> 8) & 0xFF;
@@ -134,7 +135,7 @@ void FirmwareUploaderWindow::sendFirmwareChunk()
output->data[5] = firmwareData[firmwareLocation++];
for (int i = 0; i < 6; i++) xorByte = xorByte ^ output->data[i];
output->data[6] = xorByte;
sendCANFrame(output, bus);
sendCANFrame(output);
timer->start();
}
@@ -142,13 +143,14 @@ void FirmwareUploaderWindow::sendFirmwareEnding()
{
CANFrame *output = new CANFrame;
output->extended = false;
output->bus = bus;
output->len = 4;
output->ID = baseAddress + 0x30;
output->data[0] = 0xC0;
output->data[1] = 0xDE;
output->data[2] = 0xFA;
output->data[3] = 0xDE;
sendCANFrame(output, bus);
sendCANFrame(output);
}
void FirmwareUploaderWindow::handleStartStopTransfer()
@@ -167,6 +169,7 @@ void FirmwareUploaderWindow::handleStartStopTransfer()
CANFrame *output = new CANFrame;
output->extended = false;
output->len = 8;
output->bus = bus;
output->ID = baseAddress;
output->data[0] = 0xDE;
output->data[1] = 0xAD;
@@ -176,7 +179,7 @@ void FirmwareUploaderWindow::handleStartStopTransfer()
output->data[5] = (token >> 8) & 0xFF;
output->data[6] = (token >> 16) & 0xFF;
output->data[7] = (token >> 24) & 0xFF;
sendCANFrame(output, bus);
sendCANFrame(output);
}
else //stop anything in process
{
+1 -1
View File
@@ -20,7 +20,7 @@ public:
~FirmwareUploaderWindow();
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
public slots:
void gotTargettedFrame(int frameLoc);
+1 -7
View File
@@ -18,7 +18,7 @@
*
*/
FramePlaybackWindow::FramePlaybackWindow(const QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent) :
FramePlaybackWindow::FramePlaybackWindow(const QVector<CANFrame> *frames, QWidget *parent) :
QDialog(parent),
ui(new Ui::FramePlaybackWindow)
{
@@ -33,7 +33,6 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector<CANFrame> *frames, Serial
readSettings();
modelFrames = frames;
serialWorker = worker;
playbackTimer = new QTimer();
@@ -70,9 +69,6 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector<CANFrame> *frames, Serial
playbackTimer->setInterval(ui->spinPlaySpeed->value()); //set the timer to the default value of the control
connect(this, SIGNAL(sendCANFrame(const CANFrame*,int)), worker, SLOT(sendFrame(const CANFrame*,int)), Qt::QueuedConnection);
connect(this, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), worker, SLOT(sendFrameBatch(const QList<CANFrame>*)), Qt::QueuedConnection);
QStringList headers;
headers << "Source" << "Loops";
ui->tblSequence->setColumnCount(2);
@@ -85,8 +81,6 @@ FramePlaybackWindow::~FramePlaybackWindow()
{
delete ui;
disconnect(serialWorker);
playbackTimer->stop();
delete playbackTimer;
}
+2 -3
View File
@@ -27,7 +27,7 @@ class FramePlaybackWindow : public QDialog
Q_OBJECT
public:
explicit FramePlaybackWindow(const QVector<CANFrame> *frames, SerialWorker *worker, QWidget *parent = 0);
explicit FramePlaybackWindow(const QVector<CANFrame> *frames, QWidget *parent = 0);
~FramePlaybackWindow();
private slots:
@@ -54,7 +54,7 @@ private slots:
void loadFilters();
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
void sendFrameBatch(const QList<CANFrame> *);
private:
@@ -65,7 +65,6 @@ private:
const QVector<CANFrame> *modelFrames;
int currentPosition;
QTimer *playbackTimer;
SerialWorker *serialWorker;
bool playbackActive;
bool playbackForward;
int whichBusSend;
+2 -2
View File
@@ -151,7 +151,7 @@ void FrameSenderWindow::processIncomingFrame(CANFrame *frame)
sendingData[sd].count++;
doModifiers(sd);
updateGridRow(sd);
sendCANFrame(&sendingData[sd], sendingData[sd].bus);
sendCANFrame(&sendingData[sd]);
}
else //delayed sending frame
{
@@ -354,7 +354,7 @@ void FrameSenderWindow::handleTick()
doModifiers(i);
updateGridRow(i);
qDebug() << "About to try to send a frame";
emit sendCANFrame(&sendingData[i], sendingData[i].bus);
emit sendCANFrame(&sendingData[i]);
if (trigger->ID > 0) trigger->readyCount = false; //reset flag if this is a timed ID trigger
}
}
+1 -1
View File
@@ -31,7 +31,7 @@ private slots:
void updatedFrames(int);
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
private:
Ui::FrameSenderWindow *ui;
+1 -1
View File
@@ -29,7 +29,7 @@ public:
~FuzzingWindow();
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
void sendFrameBatch(const QList<CANFrame> *);
private slots:
+22 -19
View File
@@ -184,8 +184,8 @@ MainWindow::MainWindow(QWidget *parent) :
MainWindow::~MainWindow()
{
serialWorkerThread.quit();
serialWorkerThread.wait();
//serialWorkerThread.quit();
//serialWorkerThread.wait();
//delete worker;
if (graphingWindow)
@@ -339,16 +339,16 @@ void MainWindow::readSettings()
ui->cbAutoScroll->setChecked(true);
}
/*
int cType = settings.value("Main/DefaultConnectionType", 0).toInt();
if (cType == 0) connType = "GVRET";
if (cType == 1) connType = "KVASER";
if (cType == 2) connType = "SOCKETCAN";
portName = settings.value("Main/DefaultConnectionPort", "").toString();
canSpeed0 = -1;
canSpeed1 = -1;
*/
qDebug() << connType;
qDebug() << portName;
//qDebug() << connType;
//qDebug() << portName;
//"Main/SingleWireMode"
@@ -379,11 +379,11 @@ void MainWindow::writeSettings()
void MainWindow::updateConnectionSettings(QString connectionType, QString port, int speed0, int speed1)
{
connType = connectionType;
portName = port;
//connType = connectionType;
//portName = port;
canSpeed0 = speed0;
canSpeed1 = speed1;
//canSpeed0 = speed0;
//canSpeed1 = speed1;
if (isConnected)
{
//emit updateBaudRates(speed0, speed1);
@@ -863,7 +863,7 @@ void MainWindow::showFrameSenderWindow()
else
frameSenderWindow = new FrameSenderWindow(model->getFilteredListReference());
connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, worker, &SerialWorker::sendFrame);
connect(frameSenderWindow, &FrameSenderWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
}
frameSenderWindow->show();
}
@@ -873,9 +873,12 @@ void MainWindow::showPlaybackWindow()
if (!playbackWindow)
{
if (!useFiltered)
playbackWindow = new FramePlaybackWindow(model->getListReference(), worker);
playbackWindow = new FramePlaybackWindow(model->getListReference());
else
playbackWindow = new FramePlaybackWindow(model->getFilteredListReference(), worker);
playbackWindow = new FramePlaybackWindow(model->getFilteredListReference());
connect(playbackWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)), Qt::QueuedConnection);
connect(playbackWindow, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), connectionWindow, SLOT(sendFrameBatch(const QList<CANFrame>*)), Qt::QueuedConnection);
}
playbackWindow->show();
}
@@ -885,8 +888,8 @@ void MainWindow::showFirmwareUploaderWindow()
if (!firmwareUploaderWindow)
{
firmwareUploaderWindow = new FirmwareUploaderWindow(model->getListReference());
connect(firmwareUploaderWindow, SIGNAL(sendCANFrame(const CANFrame*,int)), worker, SLOT(sendFrame(const CANFrame*,int)));
connect(worker, SIGNAL(gotTargettedFrame(int)), firmwareUploaderWindow, SLOT(gotTargettedFrame(int)));
connect(firmwareUploaderWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)));
//connect(worker, SIGNAL(gotTargettedFrame(int)), firmwareUploaderWindow, SLOT(gotTargettedFrame(int)));
}
firmwareUploaderWindow->show();
}
@@ -914,8 +917,8 @@ void MainWindow::showFuzzingWindow()
if (!fuzzingWindow)
{
fuzzingWindow = new FuzzingWindow(model->getListReference());
connect(fuzzingWindow, SIGNAL(sendCANFrame(const CANFrame*,int)), worker, SLOT(sendFrame(const CANFrame*,int)));
connect(fuzzingWindow, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), worker, SLOT(sendFrameBatch(const QList<CANFrame>*)));
connect(fuzzingWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*)));
connect(fuzzingWindow, SIGNAL(sendFrameBatch(const QList<CANFrame>*)), connectionWindow, SLOT(sendFrameBatch(const QList<CANFrame>*)));
}
fuzzingWindow->show();
}
@@ -925,7 +928,7 @@ void MainWindow::showUDSScanWindow()
if (!udsScanWindow)
{
udsScanWindow = new UDSScanWindow(model->getListReference());
connect(udsScanWindow, SIGNAL(sendCANFrame(const CANFrame*,int)), worker, SLOT(sendFrame(const CANFrame*,int)));
connect(udsScanWindow, SIGNAL(sendCANFrame(const CANFrame*,int)), connectionWindow, SLOT(sendFrame(const CANFrame*)));
}
udsScanWindow->show();
}
@@ -935,7 +938,7 @@ void MainWindow::showScriptingWindow()
if (!scriptingWindow)
{
scriptingWindow = new ScriptingWindow(model->getListReference());
connect(scriptingWindow, &ScriptingWindow::sendCANFrame, worker, &SerialWorker::sendFrame);
connect(scriptingWindow, &ScriptingWindow::sendCANFrame, connectionWindow, &ConnectionWindow::sendFrame);
}
scriptingWindow->show();
}
-5
View File
@@ -108,8 +108,6 @@ private:
//canbus related data
CANFrameModel *model;
DBCHandler *dbcHandler;
QThread serialWorkerThread;
SerialWorker *worker;
QByteArray inputBuffer;
QTimer updateTimer;
QTime *elapsedTime;
@@ -147,9 +145,6 @@ private:
QLabel lbStatusDatabase;
int normalRowHeight;
bool isConnected;
QSerialPortInfo portInfo;
QString connType, portName;
int canSpeed0, canSpeed1;
//private methods
void saveDecodedTextFile(QString);
+1 -1
View File
@@ -111,7 +111,7 @@ void ScriptContainer::sendFrame(QJSValue bus, QJSValue id, QJSValue length, QJSV
if (frame.ID > 0x7FF) frame.extended = true;
//qDebug() << "Sending frame from script";
emit sendCANFrame(&frame, frame.bus);
emit sendCANFrame(&frame);
}
void ScriptContainer::gotFrame(const CANFrame &frame)
+1 -1
View File
@@ -32,7 +32,7 @@ private slots:
void tick();
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
private:
QJSEngine scriptEngine;
+1 -1
View File
@@ -33,7 +33,7 @@ private slots:
public slots:
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
private:
void closeEvent(QCloseEvent *event);
+3
View File
@@ -564,4 +564,7 @@ void SerialWorker::updateBusSettings(CAN_Bus *bus)
if (busNum < 0) return;
if (busNum >= numBuses) return;
qDebug() << "About to update bus " << busNum << " on GVRET";
if (busNum == 0) can0Baud = bus->getSpeed();
if (busNum == 1) can1Baud = bus->getSpeed();
updateBaudRates(can0Baud,can1Baud);
}
+1 -1
View File
@@ -210,7 +210,7 @@ void UDSScanWindow::sendNextMsg()
currIdx++;
if (currIdx < sendingFrames.count())
{
emit sendCANFrame(&sendingFrames[currIdx], sendingFrames[currIdx].bus);
emit sendCANFrame(&sendingFrames[currIdx]);
waitTimer->start();
}
else
+1 -1
View File
@@ -18,7 +18,7 @@ public:
~UDSScanWindow();
signals:
void sendCANFrame(const CANFrame *, int);
void sendCANFrame(const CANFrame *);
private slots:
void updatedFrames(int numFrames);