Merge pull request #109 from andre-hartmann/serialbus-cleanup
Serialbus and general cleanup
This commit is contained in:
@@ -1,8 +1,8 @@
|
|||||||
# SavvyCAN
|
# SavvyCAN
|
||||||
QT based cross platform canbus tool
|
Qt based cross platform canbus tool
|
||||||
(C) 2015-2017 EVTV and Collin Kidder
|
(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
|
This tool is designed to help with visualization, reverse engineering, debugging, and
|
||||||
capturing of canbus frames.
|
capturing of canbus frames.
|
||||||
|
|
||||||
@@ -37,7 +37,7 @@ of this program. It can load and save in several formats:
|
|||||||
## Dependencies
|
## Dependencies
|
||||||
|
|
||||||
Now this code does not depend on anything other than what is in the source tree or available
|
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:
|
Uses QCustomPlot available at:
|
||||||
|
|
||||||
@@ -83,5 +83,5 @@ make
|
|||||||
```
|
```
|
||||||
|
|
||||||
Did that fix it? Great! If not, ensure that you selected SerialBUS support
|
Did that fix it? Great! If not, ensure that you selected SerialBUS support
|
||||||
when you installed QT.
|
when you installed Qt.
|
||||||
|
|
||||||
|
|||||||
+3
-5
@@ -4,9 +4,7 @@
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------
|
#-------------------------------------------------
|
||||||
|
|
||||||
QT += core gui serialbus
|
QT = core gui printsupport qml serialbus serialport widgets
|
||||||
|
|
||||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets serialport printsupport qml
|
|
||||||
|
|
||||||
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
CONFIG(release, debug|release):DEFINES += QT_NO_DEBUG_OUTPUT
|
||||||
|
|
||||||
@@ -34,7 +32,7 @@ SOURCES += main.cpp\
|
|||||||
can_structs.cpp \
|
can_structs.cpp \
|
||||||
motorcontrollerconfigwindow.cpp \
|
motorcontrollerconfigwindow.cpp \
|
||||||
connections/canconnection.cpp \
|
connections/canconnection.cpp \
|
||||||
connections/socketcan.cpp \
|
connections/serialbusconnection.cpp \
|
||||||
connections/canconfactory.cpp \
|
connections/canconfactory.cpp \
|
||||||
connections/gvretserial.cpp \
|
connections/gvretserial.cpp \
|
||||||
connections/canconmanager.cpp \
|
connections/canconmanager.cpp \
|
||||||
@@ -86,7 +84,7 @@ HEADERS += mainwindow.h \
|
|||||||
utils/lfqueue.h \
|
utils/lfqueue.h \
|
||||||
motorcontrollerconfigwindow.h \
|
motorcontrollerconfigwindow.h \
|
||||||
connections/canconnection.h \
|
connections/canconnection.h \
|
||||||
connections/socketcan.h \
|
connections/serialbusconnection.h \
|
||||||
connections/canconconst.h \
|
connections/canconconst.h \
|
||||||
connections/canconfactory.h \
|
connections/canconfactory.h \
|
||||||
connections/gvretserial.h \
|
connections/gvretserial.h \
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include "canconfactory.h"
|
#include "canconfactory.h"
|
||||||
#include "socketcan.h"
|
#include "serialbusconnection.h"
|
||||||
#include "gvretserial.h"
|
#include "gvretserial.h"
|
||||||
|
|
||||||
using namespace CANCon;
|
using namespace CANCon;
|
||||||
@@ -9,7 +9,7 @@ CANConnection* CanConFactory::create(type pType, QString pPortName)
|
|||||||
{
|
{
|
||||||
switch(pType) {
|
switch(pType) {
|
||||||
case SOCKETCAN:
|
case SOCKETCAN:
|
||||||
return new SocketCan(pPortName);
|
return new SerialBusConnection(pPortName);
|
||||||
case GVRET_SERIAL:
|
case GVRET_SERIAL:
|
||||||
return new GVRetSerial(pPortName);
|
return new GVRetSerial(pPortName);
|
||||||
default: {}
|
default: {}
|
||||||
|
|||||||
@@ -5,9 +5,8 @@
|
|||||||
#include <QAbstractTableModel>
|
#include <QAbstractTableModel>
|
||||||
|
|
||||||
#include "canbus.h"
|
#include "canbus.h"
|
||||||
#include "connections/canconnection.h"
|
|
||||||
#include "connectionwindow.h"
|
|
||||||
|
|
||||||
|
class CANConnection;
|
||||||
|
|
||||||
class CANConnectionModel : public QAbstractTableModel
|
class CANConnectionModel : public QAbstractTableModel
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,31 +1,30 @@
|
|||||||
#include <QObject>
|
#include "serialbusconnection.h"
|
||||||
#include <QDebug>
|
|
||||||
|
#include "canconmanager.h"
|
||||||
|
|
||||||
|
#include <QCanBus>
|
||||||
#include <QCanBusFrame>
|
#include <QCanBusFrame>
|
||||||
#include <QDateTime>
|
#include <QDateTime>
|
||||||
|
#include <QDebug>
|
||||||
#include "socketcan.h"
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***********************************/
|
/***********************************/
|
||||||
/**** class definition ****/
|
/**** class definition ****/
|
||||||
/***********************************/
|
/***********************************/
|
||||||
|
|
||||||
SocketCan::SocketCan(QString portName) :
|
SerialBusConnection::SerialBusConnection(QString portName) :
|
||||||
CANConnection(portName, CANCon::SOCKETCAN, 1, 4000, true),
|
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 */
|
mTimer(this) /*NB: set connection as parent of timer to manage it from working thread */
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SocketCan::~SocketCan()
|
SerialBusConnection::~SerialBusConnection()
|
||||||
{
|
{
|
||||||
stop();
|
stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::piStarted()
|
void SerialBusConnection::piStarted()
|
||||||
{
|
{
|
||||||
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
||||||
mTimer.setInterval(1000);
|
mTimer.setInterval(1000);
|
||||||
@@ -36,7 +35,7 @@ void SocketCan::piStarted()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::piSuspend(bool pSuspend)
|
void SerialBusConnection::piSuspend(bool pSuspend)
|
||||||
{
|
{
|
||||||
/* update capSuspended */
|
/* update capSuspended */
|
||||||
setCapSuspended(pSuspend);
|
setCapSuspended(pSuspend);
|
||||||
@@ -47,19 +46,19 @@ void SocketCan::piSuspend(bool pSuspend)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::piStop() {
|
void SerialBusConnection::piStop() {
|
||||||
mTimer.stop();
|
mTimer.stop();
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SocketCan::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
bool SerialBusConnection::piGetBusSettings(int pBusIdx, CANBus& pBus)
|
||||||
{
|
{
|
||||||
return getBusConfig(pBusIdx, pBus);
|
return getBusConfig(pBusIdx, pBus);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
void SerialBusConnection::piSetBusSettings(int pBusIdx, CANBus bus)
|
||||||
{
|
{
|
||||||
CANConStatus stats;
|
CANConStatus stats;
|
||||||
/* sanity checks */
|
/* sanity checks */
|
||||||
@@ -67,8 +66,7 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* disconnect device if we have one connected */
|
/* disconnect device if we have one connected */
|
||||||
if(mDev_p)
|
disconnectDevice();
|
||||||
disconnectDevice();
|
|
||||||
|
|
||||||
/* copy bus config */
|
/* copy bus config */
|
||||||
setBusConfig(0, bus);
|
setBusConfig(0, bus);
|
||||||
@@ -78,17 +76,18 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* create device */
|
/* create device */
|
||||||
mDev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
QString errorString;
|
||||||
|
mDev_p = QCanBus::instance()->createDevice("socketcan", getPort(), &errorString);
|
||||||
if (!mDev_p) {
|
if (!mDev_p) {
|
||||||
disconnectDevice();
|
disconnectDevice();
|
||||||
qDebug() << "can't create device";
|
qDebug() << "Error: createDevice(" << getType() << getPort() << "):" << errorString;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* connect slots */
|
/* connect slots */
|
||||||
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SocketCan::errorReceived);
|
connect(mDev_p, &QCanBusDevice::errorOccurred, this, &SerialBusConnection::errorReceived);
|
||||||
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SocketCan::framesWritten);
|
connect(mDev_p, &QCanBusDevice::framesWritten, this, &SerialBusConnection::framesWritten);
|
||||||
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SocketCan::framesReceived);
|
connect(mDev_p, &QCanBusDevice::framesReceived, this, &SerialBusConnection::framesReceived);
|
||||||
|
|
||||||
/* set configuration */
|
/* set configuration */
|
||||||
/*if (p.useConfigurationEnabled) {
|
/*if (p.useConfigurationEnabled) {
|
||||||
@@ -107,7 +106,7 @@ void SocketCan::piSetBusSettings(int pBusIdx, CANBus bus)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool SocketCan::piSendFrame(const CANFrame& pFrame)
|
bool SerialBusConnection::piSendFrame(const CANFrame& pFrame)
|
||||||
{
|
{
|
||||||
/* sanity checks */
|
/* sanity checks */
|
||||||
if(0 != pFrame.bus || pFrame.len>8)
|
if(0 != pFrame.bus || pFrame.len>8)
|
||||||
@@ -131,16 +130,16 @@ bool SocketCan::piSendFrame(const CANFrame& pFrame)
|
|||||||
|
|
||||||
|
|
||||||
/* disconnect device */
|
/* disconnect device */
|
||||||
void SocketCan::disconnectDevice() {
|
void SerialBusConnection::disconnectDevice() {
|
||||||
if(mDev_p) {
|
if(mDev_p) {
|
||||||
mDev_p->disconnectDevice();
|
mDev_p->disconnectDevice();
|
||||||
delete mDev_p;
|
delete mDev_p;
|
||||||
mDev_p = Q_NULLPTR;
|
mDev_p = nullptr;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const
|
void SerialBusConnection::errorReceived(QCanBusDevice::CanBusError error) const
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case QCanBusDevice::ReadError:
|
case QCanBusDevice::ReadError:
|
||||||
@@ -155,13 +154,13 @@ void SocketCan::errorReceived(QCanBusDevice::CanBusError error) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCan::framesWritten(qint64 count)
|
void SerialBusConnection::framesWritten(qint64 count)
|
||||||
{
|
{
|
||||||
Q_UNUSED(count);
|
Q_UNUSED(count);
|
||||||
//qDebug() << "Number of frames written:" << count;
|
//qDebug() << "Number of frames written:" << count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCan::framesReceived()
|
void SerialBusConnection::framesReceived()
|
||||||
{
|
{
|
||||||
uint64_t timeBasis = CANConManager::getInstance()->getTimeBasis();
|
uint64_t timeBasis = CANConManager::getInstance()->getTimeBasis();
|
||||||
|
|
||||||
@@ -211,7 +210,7 @@ void SocketCan::framesReceived()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SocketCan::testConnection() {
|
void SerialBusConnection::testConnection() {
|
||||||
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
QCanBusDevice* dev_p = QCanBus::instance()->createDevice("socketcan", getPort());
|
||||||
CANConStatus stats;
|
CANConStatus stats;
|
||||||
|
|
||||||
@@ -1,23 +1,19 @@
|
|||||||
#ifndef SocketCan_H
|
#ifndef SERIALBUSCONNECTION_H
|
||||||
#define SocketCan_H
|
#define SERIALBUSCONNECTION_H
|
||||||
|
|
||||||
#include <QObject>
|
|
||||||
#include <QCanBus>
|
|
||||||
#include <QTimer>
|
|
||||||
#include <qthread.h>
|
|
||||||
|
|
||||||
#include "canframemodel.h"
|
|
||||||
#include "canconnection.h"
|
#include "canconnection.h"
|
||||||
#include "canconmanager.h"
|
#include "canframemodel.h"
|
||||||
|
|
||||||
|
#include <QCanBusDevice>
|
||||||
|
#include <QTimer>
|
||||||
|
|
||||||
class SocketCan : public CANConnection
|
class SerialBusConnection : public CANConnection
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
SocketCan(QString portName);
|
SerialBusConnection(QString portName);
|
||||||
virtual ~SocketCan();
|
virtual ~SerialBusConnection();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
@@ -37,9 +33,9 @@ private slots:
|
|||||||
void testConnection();
|
void testConnection();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QCanBusDevice* mDev_p;
|
QCanBusDevice *mDev_p = nullptr;
|
||||||
QTimer mTimer;
|
QTimer mTimer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // SocketCan_H
|
#endif // SERIALBUSCONNECTION_H
|
||||||
@@ -5,6 +5,7 @@
|
|||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QtSerialPort/QSerialPortInfo>
|
#include <QtSerialPort/QSerialPortInfo>
|
||||||
#include "connections/canconmanager.h"
|
#include "connections/canconmanager.h"
|
||||||
|
#include "connections/connectionwindow.h"
|
||||||
#include "utility.h"
|
#include "utility.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+1
-1
@@ -22,7 +22,6 @@
|
|||||||
#include "mainsettingsdialog.h"
|
#include "mainsettingsdialog.h"
|
||||||
#include "firmwareuploaderwindow.h"
|
#include "firmwareuploaderwindow.h"
|
||||||
#include "re/discretestatewindow.h"
|
#include "re/discretestatewindow.h"
|
||||||
#include "connections/connectionwindow.h"
|
|
||||||
#include "scriptingwindow.h"
|
#include "scriptingwindow.h"
|
||||||
#include "re/rangestatewindow.h"
|
#include "re/rangestatewindow.h"
|
||||||
#include "dbc/dbcloadsavewindow.h"
|
#include "dbc/dbcloadsavewindow.h"
|
||||||
@@ -33,6 +32,7 @@
|
|||||||
#include "motorcontrollerconfigwindow.h"
|
#include "motorcontrollerconfigwindow.h"
|
||||||
#include "signalviewerwindow.h"
|
#include "signalviewerwindow.h"
|
||||||
|
|
||||||
|
class CANConnection;
|
||||||
class ConnectionWindow;
|
class ConnectionWindow;
|
||||||
class ISOTP_InterpreterWindow;
|
class ISOTP_InterpreterWindow;
|
||||||
class ScriptingWindow;
|
class ScriptingWindow;
|
||||||
|
|||||||
Reference in New Issue
Block a user