From c5e0488e63e48cce156f1cde2257ffa8dc6d2106 Mon Sep 17 00:00:00 2001 From: consp Date: Fri, 7 Jan 2022 22:31:53 +0100 Subject: [PATCH 1/4] Added method for storing the bus speeds --- connections/connectionwindow.cpp | 61 ++++++++++++++++++++++++++++---- connections/connectionwindow.h | 3 +- 2 files changed, 56 insertions(+), 8 deletions(-) diff --git a/connections/connectionwindow.cpp b/connections/connectionwindow.cpp index ae852e0b..d086ce94 100644 --- a/connections/connectionwindow.cpp +++ b/connections/connectionwindow.cpp @@ -258,7 +258,8 @@ void ConnectionWindow::handleNewConn() newType = thisDialog->getConnectionType(); newPort = thisDialog->getPortName(); newDriver = thisDialog->getDriverName(); - conn = create(newType, newPort, newDriver); + QVector newBusSpeed; + conn = create(newType, newPort, newDriver, 0, newBusSpeed); if (conn) { connModel->add(conn); @@ -293,6 +294,8 @@ void ConnectionWindow::handleResetConn() { QString port, driver; CANCon::type type; + int busnums; + QVector busSpeeds; int selIdx = ui->tableConnections->selectionModel()->currentIndex().row(); if (selIdx <0) return; @@ -305,13 +308,19 @@ void ConnectionWindow::handleResetConn() type = conn_p->getType(); port = conn_p->getPort(); driver = conn_p->getDriver(); + busnums = conn_p->getNumBuses(); + for (int i = 0; i < busnums; i++) { + CANBus bus; + conn_p->getBusSettings(i, bus); + busSpeeds.append(bus.getSpeed()); + } /* stop and delete connection */ conn_p->stop(); conn_p = nullptr; - conn_p = create(type, port, driver); + conn_p = create(type, port, driver, busnums, busSpeeds); if (conn_p) connModel->replace(selIdx, conn_p); } @@ -476,7 +485,7 @@ void ConnectionWindow::handleSendText() { emit sendDebugData(bytes); } -CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver) +CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QString pDriver, int busNum, QVector busSpeeds) { CANConnection* conn_p; @@ -492,8 +501,18 @@ CANConnection* ConnectionWindow::create(CANCon::type pTye, QString pPortName, QS //set up the debug console to operate if we've selected it. Doing so here allows debugging right away during set up connect(conn_p, SIGNAL(debugOutput(QString)), this, SLOT(getDebugText(QString))); } - /*TODO add return value and checks */ + conn_p->start(); + + connect(this, SIGNAL(updateBusSpeed(int, int)), conn_p, SLOT(updateBusSpeed(int, int))); + // if portNum == 0 will skip + for (int i = 0; i < busNum && i < busSpeeds.count(); i++) { + CANBus bus; + bus.setSpeed(busSpeeds[i]); + emit updateBusSpeed(i, busSpeeds[i]); + } + disconnect(this, SIGNAL(updateBusSpeed(int, int)), conn_p, SLOT(updateBusSpeed(int, int))); + /*TODO add return value and checks */ } return conn_p; } @@ -510,13 +529,30 @@ void ConnectionWindow::loadConnections() QVector portNames = settings.value("connections/portNames").value>(); QVector driverNames = settings.value("connections/driverNames").value>(); QVector devTypes = settings.value("connections/types").value>(); - + QVector busNums = settings.value("connections/busNums").value>(); + QVector busSpeedsT = settings.value("connections/busSpeeds").value>(); + QVector> busSpeeds; //don't load the connections if the three setting arrays above aren't all the same size. - if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count()) return; + if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count() || driverNames.count() != busNums.count()) return; + + // connect tthe bus get/set + + qDebug() << "Loading connections"; + // demangle bus speeds + for (int i = 0, j = 0; i < busNums.count(); i++) { + QVector busSpeed; + for (int k = 0; k < busNums[i] && j+k < busSpeedsT.count(); k++) { + busSpeed.append(busSpeedsT[j+k]); + qDebug() << "Speed " << busSpeedsT[j+k]; + } + busSpeeds.append(busSpeed); + qDebug() << "Load speed" << busNums[i]; + j += busNums[i]; + } for(int i = 0 ; i < portNames.count() ; i++) { - CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i]); + CANConnection* conn_p = create((CANCon::type)devTypes[i], portNames[i], driverNames[i], busNums[i], busSpeeds[i]); /* add connection to model */ connModel->add(conn_p); } @@ -534,6 +570,8 @@ void ConnectionWindow::saveConnections() QVector portNames; QVector devTypes; QVector driverNames; + QVector busNums; + QVector busSpeeds; /* save connections */ foreach(CANConnection* conn_p, conns) @@ -541,11 +579,20 @@ void ConnectionWindow::saveConnections() portNames.append(conn_p->getPort()); devTypes.append(conn_p->getType()); driverNames.append(conn_p->getDriver()); + busNums.append(conn_p->getNumBuses()); + for (int i = 0; i < conn_p->getNumBuses(); i++) { + CANBus bus; + conn_p->getBusSettings(i, bus); + busSpeeds.append(bus.getSpeed()); + qDebug() << "Bus speed " << bus.getSpeed(); + } } settings.setValue("connections/portNames", QVariant::fromValue(portNames)); settings.setValue("connections/types", QVariant::fromValue(devTypes)); settings.setValue("connections/driverNames", QVariant::fromValue(driverNames)); + settings.setValue("connections/busNums", QVariant::fromValue(busNums)); + settings.setValue("connections/busSpeeds", QVariant::fromValue(busSpeeds)); } void ConnectionWindow::moveConnUp() diff --git a/connections/connectionwindow.h b/connections/connectionwindow.h index b13f31f6..7e39a0d8 100644 --- a/connections/connectionwindow.h +++ b/connections/connectionwindow.h @@ -34,6 +34,7 @@ class ConnectionWindow : public QDialog void updateBusSettings(CANBus *bus); void updatePortName(QString port); void sendDebugData(QByteArray bytes); + void updateBusSpeed(int, int); public slots: void getDebugText(QString debugText); @@ -65,7 +66,7 @@ private slots: QVector remoteDeviceIPGVRET; QVector remoteDeviceKayak; - CANConnection* create(CANCon::type pTye, QString pPortName, QString pDriver); + CANConnection* create(CANCon::type pTye, QString pPortName, QString pDriver, int portNum, QVector portSpeeds); void populateBusDetails(int offset); void loadConnections(); void saveConnections(); From 0f7ed9a3d9665687bc7e4c0dd06b851a7256fe28 Mon Sep 17 00:00:00 2001 From: consp Date: Fri, 7 Jan 2022 23:23:48 +0100 Subject: [PATCH 2/4] Added the update bus speed to canconnection to support updating it from the start --- connections/canconnection.cpp | 18 ++++++++++++++++++ connections/canconnection.h | 5 +++++ 2 files changed, 23 insertions(+) diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index ef6e176b..f30861e1 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -155,6 +155,24 @@ void CANConnection::setBusSettings(int pBusIdx, CANBus pBus) } +void CANConnection::updateBusSpeed(int pBusIdx, int speed) +{ + /* make sure we execute in mThread context */ + if( mThread_p && (mThread_p != QThread::currentThread()) ) { + QMetaObject::invokeMethod(this, "updateBusSpeed", + Qt::BlockingQueuedConnection, + Q_ARG(int, pBusIdx), + Q_ARG(int, speed)); + return; + } + + + if (pBusIdx > mNumBuses) return; + + mBusData[pBusIdx].mBus.setSpeed(speed); +} + + bool CANConnection::sendFrame(const CANFrame& pFrame) { /* make sure we execute in mThread context */ diff --git a/connections/canconnection.h b/connections/canconnection.h index 38d1160f..74aae8d5 100644 --- a/connections/canconnection.h +++ b/connections/canconnection.h @@ -143,6 +143,11 @@ public slots: */ bool getBusSettings(int pBusIdx, CANBus& pBus); + /** + * updateBusSpeed + */ + void updateBusSpeed(int pBusIdx, int speed); + /** * @brief suspends/restarts data capture * @param pSuspend: suspends capture if true else restarts it From 05c3b5d10674301c3e4bb64350f94ff3750227f5 Mon Sep 17 00:00:00 2001 From: consp Date: Thu, 20 Jan 2022 21:11:33 +0100 Subject: [PATCH 3/4] Fixed error in case too many busses are attempted to be restored --- connections/canconnection.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/connections/canconnection.cpp b/connections/canconnection.cpp index f30861e1..02ed28d0 100644 --- a/connections/canconnection.cpp +++ b/connections/canconnection.cpp @@ -167,7 +167,7 @@ void CANConnection::updateBusSpeed(int pBusIdx, int speed) } - if (pBusIdx > mNumBuses) return; + if (pBusIdx >= mNumBuses || pBusIdx >= mBusData.length()) return; mBusData[pBusIdx].mBus.setSpeed(speed); } From 6c639ec33c3f0ae4e62fccf89a1bd8fae215ea29 Mon Sep 17 00:00:00 2001 From: consp Date: Sun, 20 Feb 2022 15:18:08 +0100 Subject: [PATCH 4/4] Fixed bug where stored data would not be loaded correctly due to missing variables in settings --- connections/connectionwindow.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/connections/connectionwindow.cpp b/connections/connectionwindow.cpp index d086ce94..87f46064 100644 --- a/connections/connectionwindow.cpp +++ b/connections/connectionwindow.cpp @@ -532,6 +532,13 @@ void ConnectionWindow::loadConnections() QVector busNums = settings.value("connections/busNums").value>(); QVector busSpeedsT = settings.value("connections/busSpeeds").value>(); QVector> busSpeeds; + + // if values not present (e.g. when you update the program) + if (busNums.count() != driverNames.count()) { + busNums = QVector(driverNames.count()); + busSpeedsT = QVector(0); + } + //don't load the connections if the three setting arrays above aren't all the same size. if (portNames.count() != driverNames.count() || devTypes.count() != driverNames.count() || driverNames.count() != busNums.count()) return;