summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.qmake.conf2
-rw-r--r--dependencies.yaml7
-rw-r--r--examples/serialbus/can/connectdialog.cpp4
-rw-r--r--examples/serialbus/can/connectdialog.ui9
-rw-r--r--src/plugins/canbus/peakcan/peakcan_symbols_p.h21
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp85
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.h2
-rw-r--r--src/serialbus/doc/src/peakcan.qdoc12
-rw-r--r--src/serialbus/qcanbusdevice.cpp20
-rw-r--r--src/serialbus/qcanbusdevice.h4
-rw-r--r--src/serialbus/qcanbusdeviceinfo.cpp20
-rw-r--r--src/serialbus/qcanbusdeviceinfo.h1
-rw-r--r--src/serialbus/qcanbusdeviceinfo_p.h1
-rw-r--r--src/serialbus/qmodbusclient_p.h1
14 files changed, 179 insertions, 10 deletions
diff --git a/.qmake.conf b/.qmake.conf
index 96f7a81..a93cfcc 100644
--- a/.qmake.conf
+++ b/.qmake.conf
@@ -2,4 +2,4 @@ load(qt_build_config)
CONFIG += warning_clean
DEFINES += QT_NO_FOREACH
-MODULE_VERSION = 5.15.0
+MODULE_VERSION = 6.0.0
diff --git a/dependencies.yaml b/dependencies.yaml
new file mode 100644
index 0000000..42d73b6
--- /dev/null
+++ b/dependencies.yaml
@@ -0,0 +1,7 @@
+dependencies:
+ ../qtbase:
+ ref: 089d54f06ff327f5212cb08fdbcb540066357dd5
+ required: true
+ ../qtserialport:
+ ref: 0dd2e497e12d16946395a6aeb81a4d69e1e2b638
+ required: false
diff --git a/examples/serialbus/can/connectdialog.cpp b/examples/serialbus/can/connectdialog.cpp
index 601ef2c..a0430b4 100644
--- a/examples/serialbus/can/connectdialog.cpp
+++ b/examples/serialbus/can/connectdialog.cpp
@@ -120,6 +120,10 @@ void ConnectDialog::interfaceChanged(const QString &interface)
if (serialNumber.isEmpty())
serialNumber = tr("n/a");
m_ui->serialNumberLabel->setText(tr("Serial: %1").arg(serialNumber));
+ QString alias = info.alias();
+ if (alias.isEmpty())
+ alias = tr("n/a");
+ m_ui->aliasLabel->setText(tr("Alias: %1").arg(alias));
m_ui->channelLabel->setText(tr("Channel: %1").arg(info.channel()));
m_ui->isVirtual->setChecked(info.isVirtual());
m_ui->isFlexibleDataRateCapable->setChecked(info.hasFlexibleDataRate());
diff --git a/examples/serialbus/can/connectdialog.ui b/examples/serialbus/can/connectdialog.ui
index 6d4f261..b4ba898 100644
--- a/examples/serialbus/can/connectdialog.ui
+++ b/examples/serialbus/can/connectdialog.ui
@@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>446</width>
- <height>395</height>
+ <height>418</height>
</rect>
</property>
<property name="windowTitle">
@@ -206,6 +206,13 @@
</widget>
</item>
<item>
+ <widget class="QLabel" name="aliasLabel">
+ <property name="text">
+ <string/>
+ </property>
+ </widget>
+ </item>
+ <item>
<widget class="QLabel" name="channelLabel">
<property name="text">
<string/>
diff --git a/src/plugins/canbus/peakcan/peakcan_symbols_p.h b/src/plugins/canbus/peakcan/peakcan_symbols_p.h
index 12de76f..9031592 100644
--- a/src/plugins/canbus/peakcan/peakcan_symbols_p.h
+++ b/src/plugins/canbus/peakcan/peakcan_symbols_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (c) 2020 Andre Hartmann <aha_1980@gmx.de>
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
@@ -168,7 +169,7 @@
#define PCAN_PCC 0x06U // PCAN-PC Card
// PCAN parameters
-#define PCAN_DEVICE_NUMBER 0x01U // PCAN-USB device number parameter
+#define PCAN_DEVICE_ID 0x01U // Device identifier parameter
#define PCAN_5VOLTS_POWER 0x02U // PCAN-PC Card 5-Volt power parameter
#define PCAN_RECEIVE_EVENT 0x03U // PCAN receive event handler parameter
#define PCAN_MESSAGE_FILTER 0x04U // PCAN message filter parameter
@@ -197,6 +198,8 @@
#define PCAN_BUSSPEED_DATA 0x1BU // Configured CAN data speed as Bits per seconds
#define PCAN_IP_ADDRESS 0x1CU // Remote address of a LAN channel as string in IPv4 format
#define PCAN_LAN_SERVICE_STATUS 0x1DU // Status of the Virtual PCAN-Gateway Service
+#define PCAN_ATTACHED_CHANNELS_COUNT 0x2AU // Get the amount of PCAN channels attached to a system
+#define PCAN_ATTACHED_CHANNELS 0x2BU // Get information about PCAN channels attached to a system
#define FEATURE_FD_CAPABLE 0x01U // Device supports flexible data-rate (CAN-FD)
@@ -225,6 +228,10 @@
#define TRACE_FILE_TIME 0x04U // Includes the start time into the name of the trace file
#define TRACE_FILE_OVERWRITE 0x80U // Causes the overwriting of available traces (same name)
+// Other constants
+#define MAX_LENGTH_HARDWARE_NAME 33 // Maximum length of the name of a device: 32 characters + terminator
+#define MAX_LENGTH_VERSION_STRING 18 // Maximum length of a version string: 17 characters + terminator
+
// PCAN message types
#define PCAN_MESSAGE_STANDARD 0x00U // The PCAN message is a CAN Standard Frame (11-bit identifier)
#define PCAN_MESSAGE_RTR 0x01U // The PCAN message is a CAN Remote-Transfer-Request Frame
@@ -312,6 +319,18 @@ typedef struct tagTPCANMsgFD
quint8 DATA[64]; // Data of the message (DATA[0]..DATA[63])
} TPCANMsgFD;
+// Describes an available PCAN channel
+typedef struct tagTPCANChannelInformation
+{
+ TPCANHandle channel_handle; // PCAN channel handle
+ TPCANDevice device_type; // Kind of PCAN device
+ quint8 controller_number; // CAN-Controller number
+ quint32 device_features; // Device capabilities flag (see FEATURE_*)
+ char device_name[MAX_LENGTH_HARDWARE_NAME]; // Device name
+ quint32 device_id; // Device number
+ quint32 channel_condition; // Availability status of a PCAN-Channel
+} TPCANChannelInformation;
+
#define GENERATE_SYMBOL_VARIABLE(returnType, symbolName, ...) \
typedef returnType (DRV_CALLBACK_TYPE *fp_##symbolName)(__VA_ARGS__); \
static fp_##symbolName symbolName;
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp
index 6e1af1c..0b4cf5b 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.cpp
+++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2017 Denis Shienkov <denis.shienkov@gmail.com>
+** Copyright (c) 2020 Andre Hartmann <aha_1980@gmx.de>
** Copyright (C) 2017 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing/
**
@@ -46,6 +47,7 @@
#include <QtCore/qloggingcategory.h>
#include <algorithm>
+#include <vector>
#ifdef Q_OS_WIN32
# include <QtCore/qwineventnotifier.h>
@@ -64,7 +66,7 @@ Q_GLOBAL_STATIC(QLibrary, pcanLibrary)
bool PeakCanBackend::canCreate(QString *errorReason)
{
#ifdef LINK_LIBPCANBASIC
- return true;
+ Q_UNUSED(errorReason);
#else
static bool symbolsResolved = resolvePeakCanSymbols(pcanLibrary());
if (Q_UNLIKELY(!symbolsResolved)) {
@@ -73,8 +75,17 @@ bool PeakCanBackend::canCreate(QString *errorReason)
*errorReason = pcanLibrary()->errorString();
return false;
}
- return true;
#endif
+
+ char apiVersion[32];
+ TPCANStatus stat = CAN_GetValue(PCAN_NONEBUS, PCAN_API_VERSION, apiVersion, sizeof(apiVersion));
+ if (Q_UNLIKELY(stat != PCAN_ERROR_OK)) {
+ qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "Cannot resolve PCAN-API version!");
+ return false;
+ }
+ qCInfo(QT_CANBUS_PLUGINS_PEAKCAN, "Using PCAN-API version: %s", apiVersion);
+
+ return true;
}
struct PcanChannel{
@@ -117,7 +128,7 @@ static const PcanChannel pcanChannels[] = {
{ "none", PCAN_NONEBUS }
};
-QList<QCanBusDeviceInfo> PeakCanBackend::interfaces()
+QList<QCanBusDeviceInfo> PeakCanBackend::interfacesByChannelCondition()
{
QList<QCanBusDeviceInfo> result;
@@ -143,15 +154,81 @@ QList<QCanBusDeviceInfo> PeakCanBackend::interfaces()
if (chnStat != PCAN_ERROR_OK)
channel = 0;
+ QString alias;
+ quint32 deviceId = 0;
+ const TPCANStatus idStat = ::CAN_GetValue(index, PCAN_DEVICE_ID,
+ &deviceId, sizeof(deviceId));
+ if (idStat == PCAN_ERROR_OK)
+ alias = QString::number(deviceId);
+
result.append(std::move(createDeviceInfo(QLatin1String(pcanChannels[i].name),
QString(), QLatin1String(description),
- channel, false, isFd)));
+ alias, channel, false, isFd)));
+ }
+ }
+
+ return result;
+}
+
+QList<QCanBusDeviceInfo> PeakCanBackend::interfacesByAttachedChannels(bool *ok)
+{
+ *ok = true;
+ quint32 count = 0;
+ const TPCANStatus countStat = ::CAN_GetValue(0, PCAN_ATTACHED_CHANNELS_COUNT,
+ &count, sizeof(count));
+ if (Q_UNLIKELY(countStat != PCAN_ERROR_OK)) {
+ qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "Cannot query PCAN_ATTACHED_CHANNELS_COUNT.");
+ *ok = false;
+ return {};
+ }
+ if (count == 0)
+ return {};
+
+ std::vector<TPCANChannelInformation> infos(count);
+ const TPCANStatus infosStat = ::CAN_GetValue(0, PCAN_ATTACHED_CHANNELS, infos.data(),
+ infos.size() * sizeof(TPCANChannelInformation));
+ if (Q_UNLIKELY(infosStat != PCAN_ERROR_OK)) {
+ qCWarning(QT_CANBUS_PLUGINS_PEAKCAN, "Cannot query PCAN_ATTACHED_CHANNELS.");
+ *ok = false;
+ return {};
+ }
+
+ QList<QCanBusDeviceInfo> result;
+ for (quint32 i = 0; i < count; ++i) {
+ auto info = infos[i];
+ if (info.channel_condition & PCAN_CHANNEL_AVAILABLE) {
+ const quint32 deviceId = info.channel_handle;
+ const auto pcanChannel = std::find_if(std::begin(pcanChannels), std::end(pcanChannels),
+ [deviceId](PcanChannel channel) {
+ return channel.index == deviceId;
+ });
+ const QString name = pcanChannel->name;
+ const QString description = info.device_name;
+ const QString alias = QString::number(info.device_id);
+ const int channel = info.controller_number;
+ const bool isCanFd = (info.device_features & FEATURE_FD_CAPABLE);
+
+ result.append(std::move(createDeviceInfo(name, QString(), description, alias,
+ channel, false, isCanFd)));
}
}
return result;
}
+QList<QCanBusDeviceInfo> PeakCanBackend::interfaces()
+{
+#ifdef Q_OS_WIN
+ bool ok = false;
+ const QList<QCanBusDeviceInfo> attachedChannelsResult = interfacesByAttachedChannels(&ok);
+ if (ok)
+ return attachedChannelsResult;
+#endif
+
+ const QList<QCanBusDeviceInfo> result = interfacesByChannelCondition();
+ return result;
+}
+
#if defined(Q_OS_WIN32)
class PeakCanReadNotifier : public QWinEventNotifier
{
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.h b/src/plugins/canbus/peakcan/peakcanbackend.h
index a9e108e..0ee74c3 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.h
+++ b/src/plugins/canbus/peakcan/peakcanbackend.h
@@ -69,6 +69,8 @@ public:
QString interpretErrorFrame(const QCanBusFrame &errorFrame) override;
static bool canCreate(QString *errorReason);
+ static QList<QCanBusDeviceInfo> interfacesByChannelCondition();
+ static QList<QCanBusDeviceInfo> interfacesByAttachedChannels(bool *ok);
static QList<QCanBusDeviceInfo> interfaces();
private:
diff --git a/src/serialbus/doc/src/peakcan.qdoc b/src/serialbus/doc/src/peakcan.qdoc
index a38ddf7..c10263b 100644
--- a/src/serialbus/doc/src/peakcan.qdoc
+++ b/src/serialbus/doc/src/peakcan.qdoc
@@ -34,10 +34,13 @@
\l{http://www.peak-system.com/}{PEAK-System} CAN adapters.
This plugin requires the PCAN device drivers and the PCAN-Basic library
- version 4.0.0 or higher on Windows (pcanbasic.dll) and Linux (libpcanbasic.so).
- On macOS the plugin requires the PCBUSB library from
+ version 4.4.0 or higher on Windows (pcanbasic.dll) resp. 4.0.0 on Linux
+ (libpcanbasic.so). On macOS the plugin requires the PCBUSB library from
\l{http://www.mac-can.com}{UV Software}.
+ \note QCanBusDeviceInfo::alias() is only supported on Windows and with
+ PCAN-Basic 4.4.0 or higher.
+
\section1 Creating CAN Bus Devices
At first it is necessary to check that QCanBus provides the desired plugin:
@@ -126,6 +129,11 @@
\list
\li QCanBusDevice::resetController()
\li QCanBusDevice::busStatus()
+ \li QCanBusDeviceInfo::alias() (Windows and PCAN-Basic >= 4.4.0 only):
+ Returns the PCAN_DEVICE_ID which can be set to a user defined value
+ from 0..255 resp. 0..4294967295 (depending on the device) with PCAN-View.
+ The default value is 255 resp. 4294967295.
+
\endlist
*/
diff --git a/src/serialbus/qcanbusdevice.cpp b/src/serialbus/qcanbusdevice.cpp
index 5b6c343..eab2a7e 100644
--- a/src/serialbus/qcanbusdevice.cpp
+++ b/src/serialbus/qcanbusdevice.cpp
@@ -984,7 +984,8 @@ void QCanBusDevice::setState(QCanBusDevice::CanBusDeviceState newState)
QCanBusDeviceInfo QCanBusDevice::createDeviceInfo(const QString &name, bool isVirtual,
bool isFlexibleDataRateCapable)
{
- return createDeviceInfo(name, QString(), QString(), 0, isVirtual, isFlexibleDataRateCapable);
+ return createDeviceInfo(name, QString(), QString(), QString(),
+ 0, isVirtual, isFlexibleDataRateCapable);
}
/*!
@@ -998,10 +999,27 @@ QCanBusDeviceInfo QCanBusDevice::createDeviceInfo(const QString &name, const QSt
const QString &description, int channel,
bool isVirtual, bool isFlexibleDataRateCapable)
{
+ return createDeviceInfo(name, serialNumber, description, QString(),
+ channel, isVirtual, isFlexibleDataRateCapable);
+}
+
+/*!
+ \since 6.0
+ Returns a QCanBusDeviceInfo created from the given parameters \a name,
+ \a serialNumber, \a description, \a alias, \a channel, \a isVirtual,
+ and \a isFlexibleDataRateCapable.
+ \internal
+ */
+QCanBusDeviceInfo QCanBusDevice::createDeviceInfo(const QString &name, const QString &serialNumber,
+ const QString &description, const QString &alias,
+ int channel,
+ bool isVirtual, bool isFlexibleDataRateCapable)
+{
QScopedPointer<QCanBusDeviceInfoPrivate> info(new QCanBusDeviceInfoPrivate);
info->name = name;
info->serialNumber = serialNumber;
info->description = description;
+ info->alias = alias;
info->channel = channel;
info->hasFlexibleDataRate = isFlexibleDataRateCapable;
info->isVirtual = isVirtual;
diff --git a/src/serialbus/qcanbusdevice.h b/src/serialbus/qcanbusdevice.h
index 5d2d976..0afd896 100644
--- a/src/serialbus/qcanbusdevice.h
+++ b/src/serialbus/qcanbusdevice.h
@@ -191,6 +191,10 @@ protected:
static QCanBusDeviceInfo createDeviceInfo(const QString &name, const QString &serialNumber,
const QString &description, int channel,
bool isVirtual, bool isFlexibleDataRateCapable);
+ static QCanBusDeviceInfo createDeviceInfo(const QString &name, const QString &serialNumber,
+ const QString &description,
+ const QString &alias, int channel,
+ bool isVirtual, bool isFlexibleDataRateCapable);
};
Q_DECLARE_TYPEINFO(QCanBusDevice::CanBusError, Q_PRIMITIVE_TYPE);
diff --git a/src/serialbus/qcanbusdeviceinfo.cpp b/src/serialbus/qcanbusdeviceinfo.cpp
index 78dcd89..55d15df 100644
--- a/src/serialbus/qcanbusdeviceinfo.cpp
+++ b/src/serialbus/qcanbusdeviceinfo.cpp
@@ -110,6 +110,8 @@ QString QCanBusDeviceInfo::description() const
\since 5.11
Returns the serial number of the CAN bus interface as string, if available.
Otherwise, an empty string is returned.
+
+ \sa alias()
*/
QString QCanBusDeviceInfo::serialNumber() const
{
@@ -117,6 +119,24 @@ QString QCanBusDeviceInfo::serialNumber() const
}
/*!
+ \since 6.0
+ Returns a user defineable alias associated with this CAN bus interface.
+
+ Some CAN bus interfaces can have a user defined alias associated. This is mostly
+ done with the CAN hardware vendors tools. The alias allows to identify this
+ hardware later, especially when multiple interfaces are connected.
+
+ \note In contrast to serialNumber(), the alias is not guaranteed to be unique.
+
+ If that function is not supported by the CAN plugin, an empty string is returned.
+ \sa serialNumber()
+*/
+QString QCanBusDeviceInfo::alias() const
+{
+ return d_ptr->alias;
+}
+
+/*!
\since 5.11
Returns the sequential channel number of the CAN bus interface, starting
with zero. For example, a two channel CAN interface may have the channels
diff --git a/src/serialbus/qcanbusdeviceinfo.h b/src/serialbus/qcanbusdeviceinfo.h
index c46302d..487a94d 100644
--- a/src/serialbus/qcanbusdeviceinfo.h
+++ b/src/serialbus/qcanbusdeviceinfo.h
@@ -67,6 +67,7 @@ public:
QString name() const;
QString description() const;
QString serialNumber() const;
+ QString alias() const;
int channel() const;
bool hasFlexibleDataRate() const;
diff --git a/src/serialbus/qcanbusdeviceinfo_p.h b/src/serialbus/qcanbusdeviceinfo_p.h
index 78c9e1c..637343b 100644
--- a/src/serialbus/qcanbusdeviceinfo_p.h
+++ b/src/serialbus/qcanbusdeviceinfo_p.h
@@ -64,6 +64,7 @@ public:
QString name;
QString description;
QString serialNumber;
+ QString alias;
int channel = 0;
bool hasFlexibleDataRate = false;
bool isVirtual = false;
diff --git a/src/serialbus/qmodbusclient_p.h b/src/serialbus/qmodbusclient_p.h
index f9a0dfb..05c799a 100644
--- a/src/serialbus/qmodbusclient_p.h
+++ b/src/serialbus/qmodbusclient_p.h
@@ -42,6 +42,7 @@
#include <QtSerialBus/qmodbuspdu.h>
#include <private/qmodbusdevice_p.h>
+#include <limits.h>
//
// W A R N I N G