From 1f2c5a38a0a0ef307765e9536b66dfa37f7c8c53 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 25 Nov 2017 17:13:41 +0100 Subject: [PATCH 1/7] Readme: Fix spelling of Qt --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f4bf143..3b7f7cc 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # SavvyCAN -QT based cross platform canbus tool +Qt based cross platform canbus tool (C) 2015-2017 EVTV and Collin Kidder -A QT5 based cross platform tool which can be used to load, save, and capture canbus frames. +A Qt5 based cross platform tool which can be used to load, save, and capture canbus frames. This tool is designed to help with visualization, reverse engineering, debugging, and capturing of canbus frames. @@ -37,7 +37,7 @@ of this program. It can load and save in several formats: ## Dependencies Now this code does not depend on anything other than what is in the source tree or available -from the QT installer. +from the Qt installer. Uses QCustomPlot available at: @@ -83,5 +83,5 @@ make ``` Did that fix it? Great! If not, ensure that you selected SerialBUS support -when you installed QT. +when you installed Qt. From 380e3c9da20bb21058c8768a67839fbf97094158 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 2 Sep 2017 16:58:56 +0200 Subject: [PATCH 2/7] Project: Remove unneeded scope Qt 4 is not supported at all, as the project requires QtSerialBus. --- SavvyCAN.pro | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 39f0178..6bde517 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -4,9 +4,7 @@ # #------------------------------------------------- -QT += core gui serialbus - -greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport printsupport qml +QT = core gui printsupport qml serialbus serialport widgets CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT From 560701e208dca70916c80f176e8b06a14bf38d5a Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 2 Sep 2017 12:07:04 +0200 Subject: [PATCH 3/7] Untangle include forrest Every change in connectionwindow.h led to a heavy project compile, as the header was included in other headers. Avoid this by using forward declarations and only include connectionwindow.h in the C++ files that actually use it. --- connections/canconnectionmodel.h | 3 +-- mainwindow.cpp | 1 + mainwindow.h | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/connections/canconnectionmodel.h b/connections/canconnectionmodel.h index 190dd27..f4a0094 100644 --- a/connections/canconnectionmodel.h +++ b/connections/canconnectionmodel.h @@ -5,9 +5,8 @@ #include #include "canbus.h" -#include "connections/canconnection.h" -#include "connectionwindow.h" +class CANConnection; class CANConnectionModel : public QAbstractTableModel { diff --git a/mainwindow.cpp b/mainwindow.cpp index c346ff0..9cf225d 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -5,6 +5,7 @@ #include #include #include "connections/canconmanager.h" +#include "connections/connectionwindow.h" #include "utility.h" /* diff --git a/mainwindow.h b/mainwindow.h index abdd0a2..fffe39f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -22,7 +22,6 @@ #include "mainsettingsdialog.h" #include "firmwareuploaderwindow.h" #include "re/discretestatewindow.h" -#include "connections/connectionwindow.h" #include "scriptingwindow.h" #include "re/rangestatewindow.h" #include "dbc/dbcloadsavewindow.h" @@ -33,6 +32,7 @@ #include "motorcontrollerconfigwindow.h" #include "signalviewerwindow.h" +class CANConnection; class ConnectionWindow; class ISOTP_InterpreterWindow; class ScriptingWindow; From 1dd59ed73cb18dd40ff1a83bc12a00b1822b1698 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 2 Sep 2017 10:15:18 +0200 Subject: [PATCH 4/7] SocketCan: Rename to SerialBusConnection QtCanBus is not limited to SocketCAN, it also supports various Windows CAN adapters directly. Also, add the term Connection to describe the inheritance hierarchy better. --- SavvyCAN.pro | 4 +-- connections/canconfactory.cpp | 4 +-- ...{socketcan.cpp => serialbusconnection.cpp} | 34 +++++++++---------- .../{socketcan.h => serialbusconnection.h} | 12 +++---- 4 files changed, 27 insertions(+), 27 deletions(-) rename connections/{socketcan.cpp => serialbusconnection.cpp} (85%) rename connections/{socketcan.h => serialbusconnection.h} (77%) diff --git a/SavvyCAN.pro b/SavvyCAN.pro index 6bde517..1ccb096 100644 --- a/SavvyCAN.pro +++ b/SavvyCAN.pro @@ -32,7 +32,7 @@ SOURCES += main.cpp\ can_structs.cpp \ motorcontrollerconfigwindow.cpp \ connections/canconnection.cpp \ - connections/socketcan.cpp \ + connections/serialbusconnection.cpp \ connections/canconfactory.cpp \ connections/gvretserial.cpp \ connections/canconmanager.cpp \ @@ -84,7 +84,7 @@ HEADERS += mainwindow.h \ utils/lfqueue.h \ motorcontrollerconfigwindow.h \ connections/canconnection.h \ - connections/socketcan.h \ + connections/serialbusconnection.h \ connections/canconconst.h \ connections/canconfactory.h \ connections/gvretserial.h \ diff --git a/connections/canconfactory.cpp b/connections/canconfactory.cpp index 7926001..259fd29 100644 --- a/connections/canconfactory.cpp +++ b/connections/canconfactory.cpp @@ -1,6 +1,6 @@ #include #include "canconfactory.h" -#include "socketcan.h" +#include "serialbusconnection.h" #include "gvretserial.h" using namespace CANCon; @@ -9,7 +9,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName) { switch(pType) { case SOCKETCAN: - return new SocketCan(pPortName); + return new SerialBusConnection(pPortName); case GVRET_SERIAL: return new GVRetSerial(pPortName); default: {} diff --git a/connections/socketcan.cpp b/connections/serialbusconnection.cpp similarity index 85% rename from connections/socketcan.cpp rename to connections/serialbusconnection.cpp index d370784..f348d8a 100644 --- a/connections/socketcan.cpp +++ b/connections/serialbusconnection.cpp @@ -3,7 +3,7 @@ #include #include -#include "socketcan.h" +#include "serialbusconnection.h" @@ -11,7 +11,7 @@ /**** class definition ****/ /***********************************/ -SocketCan::SocketCan(QString portName) : +SerialBusConnection::SerialBusConnection(QString portName) : CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true), mDev_p(NULL), mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */ @@ -19,13 +19,13 @@ SocketCan::SocketCan(QString portName) : } -SocketCan::~SocketCan() +SerialBusConnection::~SerialBusConnection() { stop(); } -void SocketCan::piStarted() +void SerialBusConnection::piStarted() { connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection())); mTimer.setInterval(1000); @@ -36,7 +36,7 @@ void SocketCan::piStarted() } -void SocketCan::piSuspend(bool pSuspend) +void SerialBusConnection::piSuspend(bool pSuspend) { /* update capSuspended */ setCapSuspended(pSuspend); @@ -47,19 +47,19 @@ void SocketCan::piSuspend(bool pSuspend) } -void SocketCan::piStop() { +void SerialBusConnection::piStop() { mTimer.stop(); disconnectDevice(); } -bool SocketCan::piGetBusSettings(int pBusIdx, CANBus& pBus) +bool SerialBusConnection::piGetBusSettings(int pBusIdx, CANBus& pBus) { return getBusConfig(pBusIdx, pBus); } -void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus) +void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) { CANConStatus stats; /* sanity checks */ @@ -86,9 +86,9 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus) } /* connect slots */ - connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCan::errorReceived); - connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCan::framesWritten); - connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCan::framesReceived); + connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SerialBusConnection::errorReceived); + connect(mDev_p, &QCanBusDevice::framesWritten, this, &SerialBusConnection::framesWritten); + connect(mDev_p, &QCanBusDevice::framesReceived, this, &SerialBusConnection::framesReceived); /* set configuration */ /*if (p.useConfigurationEnabled) { @@ -107,7 +107,7 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus) } -bool SocketCan::piSendFrame(const CANFrame& pFrame) +bool SerialBusConnection::piSendFrame(const CANFrame& pFrame) { /* sanity checks */ if(0 != pFrame.bus || pFrame.len>8) @@ -131,7 +131,7 @@ bool SocketCan::piSendFrame(const CANFrame& pFrame) /* disconnect device */ -void SocketCan::disconnectDevice() { +void SerialBusConnection::disconnectDevice() { if(mDev_p) { mDev_p->disconnectDevice(); delete mDev_p; @@ -140,7 +140,7 @@ void SocketCan::disconnectDevice() { } -void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const +void SerialBusConnection::errorReceived(QCanBusDevice::CanBusError error) const { switch (error) { case QCanBusDevice::ReadError: @@ -155,13 +155,13 @@ void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const } } -void SocketCan::framesWritten(qint64 count) +void SerialBusConnection::framesWritten(qint64 count) { Q_UNUSED(count); //qDebug() << "Number of frames written:" << count; } -void SocketCan::framesReceived() +void SerialBusConnection::framesReceived() { uint64_t timeBasis = CANConManager::getInstance()->getTimeBasis(); @@ -211,7 +211,7 @@ void SocketCan::framesReceived() } -void SocketCan::testConnection() { +void SerialBusConnection::testConnection() { QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort()); CANConStatus stats; diff --git a/connections/socketcan.h b/connections/serialbusconnection.h similarity index 77% rename from connections/socketcan.h rename to connections/serialbusconnection.h index debd091..dc6cecf 100644 --- a/connections/socketcan.h +++ b/connections/serialbusconnection.h @@ -1,5 +1,5 @@ -#ifndef SocketCan_H -#define SocketCan_H +#ifndef SERIALBUSCONNECTION_H +#define SERIALBUSCONNECTION_H #include #include @@ -11,13 +11,13 @@ #include "canconmanager.h" -class SocketCan : public CANConnection +class SerialBusConnection : public CANConnection { Q_OBJECT public: - SocketCan(QString portName); - virtual ~SocketCan(); + SerialBusConnection(QString portName); + virtual ~SerialBusConnection(); protected: @@ -42,4 +42,4 @@ protected: }; -#endif // SocketCan_H +#endif // SERIALBUSCONNECTION_H From 15aef1afbe2431e91e68017127f8196042d799b8 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 2 Sep 2017 10:23:09 +0200 Subject: [PATCH 5/7] SerialBusConnection: Order and condence includes By practicing the following rules: (4 and 5 are not needed here) 1. own header 2. project headers 3. Qt headers 4. operating system headers 5. compiler headers --- connections/serialbusconnection.cpp | 10 +++++----- connections/serialbusconnection.h | 10 +++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index f348d8a..b203439 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -1,11 +1,11 @@ -#include -#include -#include -#include - #include "serialbusconnection.h" +#include "canconmanager.h" +#include +#include +#include +#include /***********************************/ /**** class definition ****/ diff --git a/connections/serialbusconnection.h b/connections/serialbusconnection.h index dc6cecf..3090bfc 100644 --- a/connections/serialbusconnection.h +++ b/connections/serialbusconnection.h @@ -1,15 +1,11 @@ #ifndef SERIALBUSCONNECTION_H #define SERIALBUSCONNECTION_H -#include -#include -#include -#include - -#include "canframemodel.h" #include "canconnection.h" -#include "canconmanager.h" +#include "canframemodel.h" +#include +#include class SerialBusConnection : public CANConnection { From 84cb598a0deb15683c81afe7da059564e73a0ed7 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Mon, 4 Sep 2017 22:34:16 +0200 Subject: [PATCH 6/7] SerialBusConnection: Improve connect/disconnect handling * disconnectDevice() already checks mDev_p * use the error description provided by QCanBus::createDevice() --- connections/serialbusconnection.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index b203439..50ebe87 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -67,8 +67,7 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) return; /* disconnect device if we have one connected */ - if(mDev_p) - disconnectDevice(); + disconnectDevice(); /* copy bus config */ setBusConfig(0, bus); @@ -78,10 +77,11 @@ void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus) return; /* create device */ - mDev_p = QCanBus::instance()->createDevice("socketcan", getPort()); + QString errorString; + mDev_p = QCanBus::instance()->createDevice("socketcan", getPort(), &errorString); if (!mDev_p) { disconnectDevice(); - qDebug() << "can't create device"; + qDebug() << "Error: createDevice(" << getType() << getPort() << "):" << errorString; return; } From d69947bf2ffc55f17cbb459a2962bbc4bb7ff249 Mon Sep 17 00:00:00 2001 From: Andre Hartmann Date: Sat, 25 Nov 2017 16:55:46 +0100 Subject: [PATCH 7/7] SerialBusConnection: Use member initialization And as we have full C++11 support, so its also preferred to use nullptr. --- connections/serialbusconnection.cpp | 3 +-- connections/serialbusconnection.h | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/connections/serialbusconnection.cpp b/connections/serialbusconnection.cpp index 50ebe87..f2f4cd2 100644 --- a/connections/serialbusconnection.cpp +++ b/connections/serialbusconnection.cpp @@ -13,7 +13,6 @@ SerialBusConnection::SerialBusConnection(QString portName) : CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true), - mDev_p(NULL), mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */ { } @@ -135,7 +134,7 @@ void SerialBusConnection::disconnectDevice() { if(mDev_p) { mDev_p->disconnectDevice(); delete mDev_p; - mDev_p = Q_NULLPTR; + mDev_p = nullptr; } } diff --git a/connections/serialbusconnection.h b/connections/serialbusconnection.h index 3090bfc..2c9d357 100644 --- a/connections/serialbusconnection.h +++ b/connections/serialbusconnection.h @@ -33,7 +33,7 @@ private slots: void testConnection(); protected: - QCanBusDevice* mDev_p; + QCanBusDevice *mDev_p = nullptr; QTimer mTimer; };