Merge pull request #109 from andre-hartmann/serialbus-cleanup
Serialbus and general cleanup
This commit is contained in:
@@ -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.
|
||||
|
||||
|
||||
+3
-5
@@ -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
|
||||
|
||||
@@ -34,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 \
|
||||
@@ -86,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 \
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <QString>
|
||||
#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: {}
|
||||
|
||||
@@ -5,9 +5,8 @@
|
||||
#include <QAbstractTableModel>
|
||||
|
||||
#include "canbus.h"
|
||||
#include "connections/canconnection.h"
|
||||
#include "connectionwindow.h"
|
||||
|
||||
class CANConnection;
|
||||
|
||||
class CANConnectionModel : public QAbstractTableModel
|
||||
{
|
||||
|
||||
@@ -1,31 +1,30 @@
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include "serialbusconnection.h"
|
||||
|
||||
#include "canconmanager.h"
|
||||
|
||||
#include <QCanBus>
|
||||
#include <QCanBusFrame>
|
||||
#include <QDateTime>
|
||||
|
||||
#include "socketcan.h"
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
/***********************************/
|
||||
/**** 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 */
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
SocketCan::~SocketCan()
|
||||
SerialBusConnection::~SerialBusConnection()
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
|
||||
void SocketCan::piStarted()
|
||||
void SerialBusConnection::piStarted()
|
||||
{
|
||||
connect(&mTimer, SIGNAL(timeout()), this, SLOT(testConnection()));
|
||||
mTimer.setInterval(1000);
|
||||
@@ -36,7 +35,7 @@ void SocketCan::piStarted()
|
||||
}
|
||||
|
||||
|
||||
void SocketCan::piSuspend(bool pSuspend)
|
||||
void SerialBusConnection::piSuspend(bool pSuspend)
|
||||
{
|
||||
/* update capSuspended */
|
||||
setCapSuspended(pSuspend);
|
||||
@@ -47,19 +46,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 */
|
||||
@@ -67,8 +66,7 @@ void SocketCan::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,17 +76,18 @@ void SocketCan::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;
|
||||
}
|
||||
|
||||
/* 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 +106,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,16 +130,16 @@ bool SocketCan::piSendFrame(const CANFrame& pFrame)
|
||||
|
||||
|
||||
/* disconnect device */
|
||||
void SocketCan::disconnectDevice() {
|
||||
void SerialBusConnection::disconnectDevice() {
|
||||
if(mDev_p) {
|
||||
mDev_p->disconnectDevice();
|
||||
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) {
|
||||
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);
|
||||
//qDebug() << "Number of frames written:" << count;
|
||||
}
|
||||
|
||||
void SocketCan::framesReceived()
|
||||
void SerialBusConnection::framesReceived()
|
||||
{
|
||||
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());
|
||||
CANConStatus stats;
|
||||
|
||||
@@ -1,23 +1,19 @@
|
||||
#ifndef SocketCan_H
|
||||
#define SocketCan_H
|
||||
#ifndef SERIALBUSCONNECTION_H
|
||||
#define SERIALBUSCONNECTION_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QCanBus>
|
||||
#include <QTimer>
|
||||
#include <qthread.h>
|
||||
|
||||
#include "canframemodel.h"
|
||||
#include "canconnection.h"
|
||||
#include "canconmanager.h"
|
||||
#include "canframemodel.h"
|
||||
|
||||
#include <QCanBusDevice>
|
||||
#include <QTimer>
|
||||
|
||||
class SocketCan : public CANConnection
|
||||
class SerialBusConnection : public CANConnection
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
SocketCan(QString portName);
|
||||
virtual ~SocketCan();
|
||||
SerialBusConnection(QString portName);
|
||||
virtual ~SerialBusConnection();
|
||||
|
||||
protected:
|
||||
|
||||
@@ -37,9 +33,9 @@ private slots:
|
||||
void testConnection();
|
||||
|
||||
protected:
|
||||
QCanBusDevice* mDev_p;
|
||||
QCanBusDevice *mDev_p = nullptr;
|
||||
QTimer mTimer;
|
||||
};
|
||||
|
||||
|
||||
#endif // SocketCan_H
|
||||
#endif // SERIALBUSCONNECTION_H
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QtSerialPort/QSerialPortInfo>
|
||||
#include "connections/canconmanager.h"
|
||||
#include "connections/connectionwindow.h"
|
||||
#include "utility.h"
|
||||
|
||||
/*
|
||||
|
||||
+1
-1
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user