Skip to content

compability qt6 #1

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

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
10 changes: 8 additions & 2 deletions src/IxxatCanBusPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,17 @@
#include <QtSerialBus/qcanbusfactory.h>
#include "IxxatCanBackend.h"

class IxxatCanBusPlugin : public QObject, public QCanBusFactoryV2
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
#define Q_CANBUS_FACTORY_INTERFACE QCanBusFactory
#else
#define Q_CANBUS_FACTORY_INTERFACE QCanBusFactoryV2
#endif

class IxxatCanBusPlugin : public QObject, public Q_CANBUS_FACTORY_INTERFACE
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QCanBusFactory" FILE "plugin.json")
Q_INTERFACES(QCanBusFactoryV2)
Q_INTERFACES(Q_CANBUS_FACTORY_INTERFACE)

public:
QList<QCanBusDeviceInfo> availableDevices(QString* errorMessage) const override
Expand Down
89 changes: 59 additions & 30 deletions src/ixxatcanbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ QList<QCanBusDeviceInfo> IxxatCanBackend::interfaces()
{
if (VCI_BUS_TYPE(sCaps.BusCtrlTypes[channel]) == VCI_BUS_CAN)
deviceList.append(
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
createDeviceInfo(
QString("ixxatcan"),
QString("VCI%1-CAN%2").arg(sInfo.VciObjectId.AsInt64).arg(channel),
QString(sInfo.UniqueHardwareId.AsChar),
QString(sInfo.Description),
QString("VCI%1-CAN%2-alias").arg(sInfo.VciObjectId.AsInt64).arg(channel),
channel, false, false)
#else
createDeviceInfo(
QString("VCI%1-CAN%2").arg(sInfo.VciObjectId.AsInt64).arg(channel),
QString(sInfo.UniqueHardwareId.AsChar),
QString(sInfo.Description),
channel, false, false)
#endif
);
}
pDevice->Release();
Expand All @@ -44,7 +54,11 @@ QList<QCanBusDeviceInfo> IxxatCanBackend::interfaces()
IxxatCanBackend::IxxatCanBackend(const QString& name)
{
bool ok;
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
const QList<QStringView> dev = QStringView{name}.split(u'-');
#else
auto dev = name.splitRef('-', Qt::SkipEmptyParts, Qt::CaseInsensitive);
#endif
this->devVciId.AsInt64 = dev.first().mid(3).toLongLong();
this->devChannel = dev.last().mid(3).toUInt(&ok);

Expand Down Expand Up @@ -73,10 +87,9 @@ IxxatCanBackend::IxxatCanBackend(const QString& name)

IxxatCanBackend::~IxxatCanBackend()
{
this->close();
closeImpl();
}


bool IxxatCanBackend::OpenSocket()
{
HRESULT hResult = E_FAIL;
Expand Down Expand Up @@ -132,6 +145,7 @@ bool IxxatCanBackend::OpenSocket()
if (hResult != VCI_OK)
return false;

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
if (hasBusStatus())
{
std::function<CanBusStatus()> g = std::bind(&IxxatCanBackend::busStatus, this);
Expand All @@ -140,6 +154,7 @@ bool IxxatCanBackend::OpenSocket()

std::function<void()> f = std::bind(&IxxatCanBackend::resetController, this);
setResetControllerFunction(f);
#endif

return true;
}
Expand Down Expand Up @@ -220,34 +235,44 @@ bool IxxatCanBackend::open()

void IxxatCanBackend::close()
{
receiveNotifier->setEnabled(false);
if (pReader)
{
pReader->Release();
pReader = NULL;
}
if (pWriter)
{
pWriter->Release();
pWriter = NULL;
}
if (pCanChannel)
{
pCanChannel->Release();
pCanChannel = NULL;
}
if (pCanControl)
{
pCanControl->StopLine();
pCanControl->ResetLine();
pCanControl->Release();
pCanControl = NULL;
}
if (pBalObject)
{
pBalObject->Release();
pBalObject = NULL;
}
closeImpl();
}

void IxxatCanBackend::closeImpl()
{
if(receiveNotifier)
{
receiveNotifier->setEnabled(false);
delete receiveNotifier;
receiveNotifier = NULL;
}
if (pReader)
{
pReader->Release();
pReader = NULL;
}
if (pWriter)
{
pWriter->Release();
pWriter = NULL;
}
if (pCanChannel)
{
pCanChannel->Release();
pCanChannel = NULL;
}
if (pCanControl)
{
pCanControl->StopLine();
pCanControl->ResetLine();
pCanControl->Release();
pCanControl = NULL;
}
if (pBalObject)
{
pBalObject->Release();
pBalObject = NULL;
}
}

bool IxxatCanBackend::writeFrame(const QCanBusFrame& newData)
Expand Down Expand Up @@ -419,7 +444,11 @@ bool IxxatCanBackend::hasBusStatus() const
return true;
}

#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
QCanBusDevice::CanBusStatus IxxatCanBackend::busStatus()
#else
QCanBusDevice::CanBusStatus IxxatCanBackend::busStatus() const
#endif
{
CANCHANSTATUS canStatus;
if (!pCanChannel)
Expand Down
7 changes: 7 additions & 0 deletions src/ixxatcanbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,22 @@ class IxxatCanBackend : public QCanBusDevice

bool open() override;
void close() override;
void closeImpl();
bool writeFrame(const QCanBusFrame& newData) override;
QString interpretErrorFrame(const QCanBusFrame& errorFrame) override;

static QList<QCanBusDeviceInfo> interfaces();

private:
#if QT_VERSION >= QT_VERSION_CHECK(6,0,0)
virtual void resetController() override;
virtual bool hasBusStatus() const override;
virtual QCanBusDevice::CanBusStatus busStatus() override;
#else
void resetController();
bool hasBusStatus() const;
QCanBusDevice::CanBusStatus busStatus() const;
#endif

bool OpenSocket();
bool OpenControl();
Expand Down