Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gs_usb support in Windows build to support CANable, CAN Bus Debugger CANtact devices #835

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ within the collin80 repos.

It is now possible to use any Qt SerialBus driver (socketcan, Vector, PeakCAN, TinyCAN).

It's now also possible to connect to CANable, CAN Bus Debugger, or any other device using a variant
of the gs_usb protocol natively in Windows. These devices can be connected using socketcan on other
operating systems.

It should, however, be noted that use of a capture device is not required to make use
of this program. It can load and save in several formats:

Expand All @@ -39,6 +43,9 @@ of this program. It can load and save in several formats:
Now this code does not depend on anything other than what is in the source tree or available
from the Qt installer.

For connecting to gs_usb based devices on Windows, this application dynamically links to
candle_api.dll which is licensed under the LGPL-3.0. The source for this DLL is available [here](https://github.com/BennyEvans/candle_dll)

Uses QCustomPlot available at:

http://www.qcustomplot.com/
Expand Down
3 changes: 3 additions & 0 deletions SavvyCAN.pro
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ HEADERS += mainwindow.h \
can_structs.h \
canbridgewindow.h \
canframemodel.h \
connections/gs_usb_driver/gs_usb_definitions.h \
connections/canlogserver.h \
connections/canserver.h \
connections/lawicel_serial.h \
Expand Down Expand Up @@ -248,6 +249,8 @@ win32-msvc* {

win32-g++ {
LIBS += libopengl32
DEFINES += GS_USB_DRIVER_ENABLED
include($$PWD/connections/gs_usb_driver/gs_usb.pri)
}

unix {
Expand Down
12 changes: 12 additions & 0 deletions connections/canbus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CANBus::CANBus()
{
speed = 500000;
samplePoint = 875;
listenOnly = false;
singleWire = false;
active = false;
Expand All @@ -15,6 +16,7 @@ CANBus::CANBus()

bool CANBus::operator==(const CANBus& bus) const{
return speed == bus.speed &&
samplePoint == bus.samplePoint &&
listenOnly == bus.listenOnly &&
singleWire == bus.singleWire &&
active == bus.active &&
Expand All @@ -27,6 +29,10 @@ void CANBus::setSpeed(int newSpeed){
speed = newSpeed;
}

void CANBus::setSamplePoint(int newSamplePoint){
samplePoint = newSamplePoint;
}

void CANBus::setListenOnly(bool mode){
//qDebug() << "CANBUS SetListenOnly = " << mode;
listenOnly = mode;
Expand All @@ -51,6 +57,10 @@ int CANBus::getSpeed() const {
return speed;
}

int CANBus::getSamplePoint() const {
return samplePoint;
}

int CANBus::getDataRate() const {
return dataRate;
}
Expand Down Expand Up @@ -80,6 +90,7 @@ bool CANBus::isCanFD() const {
QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus)
{
pStream << pCanBus.speed;
pStream << pCanBus.samplePoint;
pStream << pCanBus.listenOnly;
pStream << pCanBus.singleWire;
pStream << pCanBus.active;
Expand All @@ -90,6 +101,7 @@ QDataStream& operator<<(QDataStream & pStream, const CANBus& pCanBus)
QDataStream & operator>>(QDataStream & pStream, CANBus& pCanBus)
{
pStream >> pCanBus.speed;
pStream >> pCanBus.samplePoint;
pStream >> pCanBus.listenOnly;
pStream >> pCanBus.singleWire;
pStream >> pCanBus.active;
Expand Down
3 changes: 3 additions & 0 deletions connections/canbus.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
class CANBus
{
int speed;
int samplePoint;
bool listenOnly;
bool singleWire;
bool active; //is this bus turned on?
Expand All @@ -20,13 +21,15 @@ class CANBus
bool operator==(const CANBus&) const;

void setSpeed(int); // new speed
void setSamplePoint(int);
void setListenOnly(bool); //bool for whether to only listen
void setSingleWire(bool); //bool for whether to use single wire mode
void setActive(bool); //whether this bus should be enabled or not.
void setCanFD(bool); // enable or disable CANFD support
void setDataRate(int newSpeed);

int getSpeed() const;
int getSamplePoint() const;
int getDataRate() const;
bool isListenOnly() const;
bool isSingleWire() const;
Expand Down
1 change: 1 addition & 0 deletions connections/canconconst.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace CANCon {
LAWICEL,
CANSERVER,
CANLOGSERVER,
GSUSB,
NONE
};
}
Expand Down
15 changes: 14 additions & 1 deletion connections/canconfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
#include "lawicel_serial.h"
#include "canserver.h"
#include "canlogserver.h"
#include "gs_usb_driver/gs_usb.h"

using namespace CANCon;

CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate)
CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate, int pSamplePoint)
{
switch(pType) {
case SERIALBUS:
Expand All @@ -32,6 +33,18 @@ CANConnection* CanConFactory::create(type pType, QString pPortName, QString pDri
return new CANserver(pPortName);
case CANLOGSERVER:
return new CanLogServer(pPortName);
#ifdef GS_USB_DRIVER_ENABLED
case GSUSB:
{
GSUSBDevice* device = new GSUSBDevice(pPortName, pBusSpeed, pSamplePoint);
if (!device->isDeviceConnected()) {
delete device;
return nullptr;
} else {
return device;
}
}
#endif
default: {}
}

Expand Down
2 changes: 1 addition & 1 deletion connections/canconfactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class CanConFactory
{
public:
static CANConnection* create(CANCon::type, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate);
static CANConnection* create(CANCon::type, QString pPortName, QString pDriverName, int pSerialSpeed, int pBusSpeed, bool pCanFd, int pDataRate, int pSamplePoint);
};

#endif // CANCONFACTORY_H
9 changes: 9 additions & 0 deletions connections/canconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ CANConnection::CANConnection(QString pPort,
CANCon::type pType,
int pSerialSpeed,
int pBusSpeed,
int pSamplePoint,
bool pCanFd,
int pDataRate,
int pNumBuses,
Expand Down Expand Up @@ -40,6 +41,10 @@ CANConnection::CANConnection(QString pPort,
}

if (pBusSpeed > 0) mBusData[0].mBus.setSpeed(pBusSpeed);
if ((pSamplePoint >= 0) && (pSamplePoint <= 1000)) {
mBusData[0].mBus.setSamplePoint(pSamplePoint);
}

mBusData[0].mBus.setCanFD(pCanFd);
if (pDataRate > 0) mBusData[0].mBus.setDataRate(pDataRate);

Expand Down Expand Up @@ -251,6 +256,10 @@ QString CANConnection::getDriver()
return mDriver;
}

int CANConnection::getSerialSpeed(){
return mSerialSpeed;
}

LFQueue<CANFrame>& CANConnection::getQueue() {
return mQueue;
}
Expand Down
7 changes: 7 additions & 0 deletions connections/canconnection.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CANConnection : public QObject
* @param pType: the type of connection @ref CANCon::type
* @param pSerialSpeed: for devices with variable serial speed this is that speed.
* @param pBusSpeed: set an initial speed when opening this connection
* @param pSamplePoint: set if the device supports sample point configuration
* @param pNumBuses: the number of buses the device has
* @param pQueueLen: the length of the lock free queue to use
* @param pUseThread: if set to true, object will be execute in a dedicated thread
Expand All @@ -32,6 +33,7 @@ class CANConnection : public QObject
CANCon::type pType,
int pSerialSpeed,
int pBusSpeed,
int pSamplePoint,
bool pCanFd,
int pDataRate,
int pNumBuses,
Expand Down Expand Up @@ -64,6 +66,11 @@ class CANConnection : public QObject
*/
QString getDriver();

/**
* @brief getSerialSpeed
* @return returns the configured serial speed of the device
*/
int getSerialSpeed();

/**
* @brief getQueue
Expand Down
1 change: 1 addition & 0 deletions connections/canconnectionmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ QVariant CANConnectionModel::data(const QModelIndex &index, int role) const
case CANCon::LAWICEL: return "LAWICEL";
case CANCon::CANSERVER: return "CANserver";
case CANCon::CANLOGSERVER: return "CanLogServer";
case CANCon::GSUSB: return "gs_usb";
default: {}
}
else qDebug() << "Tried to show connection type but connection was nullptr";
Expand Down
2 changes: 1 addition & 1 deletion connections/canlogserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#include "canlogserver.h"

CanLogServer::CanLogServer(QString serverAddressString) :
CANConnection(serverAddressString, "CanLogserver", CANCon::CANLOGSERVER, 0, 0, false, 0, 1, 4000, true),
CANConnection(serverAddressString, "CanLogserver", CANCon::CANLOGSERVER, 0, 0, 0, false, 0, 1, 4000, true),
m_ptcpSocket(new QTcpSocket(this))
{

Expand Down
2 changes: 1 addition & 1 deletion connections/canserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include "canserver.h"

CANserver::CANserver(QString serverAddressString) :
CANConnection(serverAddressString, "CANserver", CANCon::CANSERVER, 0, 0, false, 0, 3, 4000, true),
CANConnection(serverAddressString, "CANserver", CANCon::CANSERVER, 0, 0, 0, false, 0, 3, 4000, true),
_udpClient(new QUdpSocket(this)),
_heartbeatTimer(new QTimer(this))
{
Expand Down
Loading