diff --git a/connectionwindow.cpp b/connectionwindow.cpp index ddf526f..3cff915 100644 --- a/connectionwindow.cpp +++ b/connectionwindow.cpp @@ -10,6 +10,10 @@ ConnectionWindow::ConnectionWindow(CANFrameModel *cModel, QWidget *parent) : settings = new QSettings(); + qRegisterMetaType("CAN_Bus *"); + qRegisterMetaType("const CANFrame *"); + qRegisterMetaType *>("const QList *"); + 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 *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 *, frames)); +} diff --git a/connectionwindow.h b/connectionwindow.h index 399c838..b3efdd5 100644 --- a/connectionwindow.h +++ b/connectionwindow.h @@ -46,6 +46,8 @@ signals: public slots: void setSpeed(int speed0); void setSWMode(bool mode); + void sendFrame(const CANFrame *); + void sendFrameBatch(const QList *); 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: diff --git a/connectionwindow.ui b/connectionwindow.ui index 6dbd5fe..db0cd9a 100644 --- a/connectionwindow.ui +++ b/connectionwindow.ui @@ -33,6 +33,13 @@ + + + + New Connection + + + diff --git a/firmwareuploaderwindow.cpp b/firmwareuploaderwindow.cpp index f881ff5..bbf9860 100644 --- a/firmwareuploaderwindow.cpp +++ b/firmwareuploaderwindow.cpp @@ -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 { diff --git a/firmwareuploaderwindow.h b/firmwareuploaderwindow.h index 5371c19..619a3b7 100644 --- a/firmwareuploaderwindow.h +++ b/firmwareuploaderwindow.h @@ -20,7 +20,7 @@ public: ~FirmwareUploaderWindow(); signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); public slots: void gotTargettedFrame(int frameLoc); diff --git a/frameplaybackwindow.cpp b/frameplaybackwindow.cpp index 765f482..0754675 100644 --- a/frameplaybackwindow.cpp +++ b/frameplaybackwindow.cpp @@ -18,7 +18,7 @@ * */ -FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, SerialWorker *worker, QWidget *parent) : +FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, QWidget *parent) : QDialog(parent), ui(new Ui::FramePlaybackWindow) { @@ -33,7 +33,6 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector *frames, Serial readSettings(); modelFrames = frames; - serialWorker = worker; playbackTimer = new QTimer(); @@ -70,9 +69,6 @@ FramePlaybackWindow::FramePlaybackWindow(const QVector *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*)), worker, SLOT(sendFrameBatch(const QList*)), 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; } diff --git a/frameplaybackwindow.h b/frameplaybackwindow.h index 07296dd..2c82753 100644 --- a/frameplaybackwindow.h +++ b/frameplaybackwindow.h @@ -27,7 +27,7 @@ class FramePlaybackWindow : public QDialog Q_OBJECT public: - explicit FramePlaybackWindow(const QVector *frames, SerialWorker *worker, QWidget *parent = 0); + explicit FramePlaybackWindow(const QVector *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 *); private: @@ -65,7 +65,6 @@ private: const QVector *modelFrames; int currentPosition; QTimer *playbackTimer; - SerialWorker *serialWorker; bool playbackActive; bool playbackForward; int whichBusSend; diff --git a/framesenderwindow.cpp b/framesenderwindow.cpp index 91dd13c..e5b722c 100644 --- a/framesenderwindow.cpp +++ b/framesenderwindow.cpp @@ -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 } } diff --git a/framesenderwindow.h b/framesenderwindow.h index e80d585..5560e9e 100644 --- a/framesenderwindow.h +++ b/framesenderwindow.h @@ -31,7 +31,7 @@ private slots: void updatedFrames(int); signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); private: Ui::FrameSenderWindow *ui; diff --git a/fuzzingwindow.h b/fuzzingwindow.h index 4521602..724d84c 100644 --- a/fuzzingwindow.h +++ b/fuzzingwindow.h @@ -29,7 +29,7 @@ public: ~FuzzingWindow(); signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); void sendFrameBatch(const QList *); private slots: diff --git a/mainwindow.cpp b/mainwindow.cpp index 96377c8..4f6cd5f 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -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*)), connectionWindow, SLOT(sendFrameBatch(const QList*)), 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*)), worker, SLOT(sendFrameBatch(const QList*))); + connect(fuzzingWindow, SIGNAL(sendCANFrame(const CANFrame*)), connectionWindow, SLOT(sendFrame(const CANFrame*))); + connect(fuzzingWindow, SIGNAL(sendFrameBatch(const QList*)), connectionWindow, SLOT(sendFrameBatch(const QList*))); } 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(); } diff --git a/mainwindow.h b/mainwindow.h index 03bb1cd..cbe0c0d 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -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); diff --git a/scriptcontainer.cpp b/scriptcontainer.cpp index 236b979..9e14e2d 100644 --- a/scriptcontainer.cpp +++ b/scriptcontainer.cpp @@ -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) diff --git a/scriptcontainer.h b/scriptcontainer.h index b570f12..fd4b33d 100644 --- a/scriptcontainer.h +++ b/scriptcontainer.h @@ -32,7 +32,7 @@ private slots: void tick(); signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); private: QJSEngine scriptEngine; diff --git a/scriptingwindow.h b/scriptingwindow.h index d27620b..179e672 100644 --- a/scriptingwindow.h +++ b/scriptingwindow.h @@ -33,7 +33,7 @@ private slots: public slots: signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); private: void closeEvent(QCloseEvent *event); diff --git a/serialworker.cpp b/serialworker.cpp index a55f9d5..b35d672 100644 --- a/serialworker.cpp +++ b/serialworker.cpp @@ -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); } diff --git a/udsscanwindow.cpp b/udsscanwindow.cpp index 7398477..a4c4f6c 100644 --- a/udsscanwindow.cpp +++ b/udsscanwindow.cpp @@ -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 diff --git a/udsscanwindow.h b/udsscanwindow.h index 1066198..c53114b 100644 --- a/udsscanwindow.h +++ b/udsscanwindow.h @@ -18,7 +18,7 @@ public: ~UDSScanWindow(); signals: - void sendCANFrame(const CANFrame *, int); + void sendCANFrame(const CANFrame *); private slots: void updatedFrames(int numFrames);