summaryrefslogtreecommitdiffstats
path: root/src/plugins/canbus/peakcan
diff options
context:
space:
mode:
authorAndre Hartmann <aha_1980@gmx.de>2016-09-07 22:13:41 +0200
committerAndré Hartmann <aha_1980@gmx.de>2016-09-15 09:02:15 +0000
commit3f8eb3be91641f9dba597e4421f9bbf50c5c161e (patch)
tree78c0b922b1d429861b26ee5395a9d7d9b4e6da2e /src/plugins/canbus/peakcan
parent5641c52872eb1ac6dd2a4101ac4274f41c29d7b1 (diff)
PeakCAN: Add support for more CAN channels
Extend the PCI and USB interfaces to the maximum supported by the PeakCAN Basic API. The new constants are taken from a recent pcanbasic.h. [ChangeLog][QtSerialBus][PeakCAN] The PeakCAN Plugin now supports up to 16 USB and 16 PCI CAN channels. Change-Id: I02e8e003e56aafd8546cbb32816e4bd9d9c77861 Reviewed-by: André Hartmann <aha_1980@gmx.de> Reviewed-by: Alex Blasche <alexander.blasche@qt.io>
Diffstat (limited to 'src/plugins/canbus/peakcan')
-rw-r--r--src/plugins/canbus/peakcan/peakcan_symbols_p.h52
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend.cpp87
-rw-r--r--src/plugins/canbus/peakcan/peakcanbackend_p.h2
3 files changed, 81 insertions, 60 deletions
diff --git a/src/plugins/canbus/peakcan/peakcan_symbols_p.h b/src/plugins/canbus/peakcan/peakcan_symbols_p.h
index 456be17..dbbf6b2 100644
--- a/src/plugins/canbus/peakcan/peakcan_symbols_p.h
+++ b/src/plugins/canbus/peakcan/peakcan_symbols_p.h
@@ -83,23 +83,39 @@ extern "C"
#define PCAN_DNGBUS1 0x31 // PCAN-Dongle/LPT interface, channel 1
-#define PCAN_PCIBUS1 0x41 // PCAN-PCI interface, channel 1
-#define PCAN_PCIBUS2 0x42 // PCAN-PCI interface, channel 2
-#define PCAN_PCIBUS3 0x43 // PCAN-PCI interface, channel 3
-#define PCAN_PCIBUS4 0x44 // PCAN-PCI interface, channel 4
-#define PCAN_PCIBUS5 0x45 // PCAN-PCI interface, channel 5
-#define PCAN_PCIBUS6 0x46 // PCAN-PCI interface, channel 6
-#define PCAN_PCIBUS7 0x47 // PCAN-PCI interface, channel 7
-#define PCAN_PCIBUS8 0x48 // PCAN-PCI interface, channel 8
-
-#define PCAN_USBBUS1 0x51 // PCAN-USB interface, channel 1
-#define PCAN_USBBUS2 0x52 // PCAN-USB interface, channel 2
-#define PCAN_USBBUS3 0x53 // PCAN-USB interface, channel 3
-#define PCAN_USBBUS4 0x54 // PCAN-USB interface, channel 4
-#define PCAN_USBBUS5 0x55 // PCAN-USB interface, channel 5
-#define PCAN_USBBUS6 0x56 // PCAN-USB interface, channel 6
-#define PCAN_USBBUS7 0x57 // PCAN-USB interface, channel 7
-#define PCAN_USBBUS8 0x58 // PCAN-USB interface, channel 8
+#define PCAN_PCIBUS1 0x41 // PCAN-PCI interface, channel 1
+#define PCAN_PCIBUS2 0x42 // PCAN-PCI interface, channel 2
+#define PCAN_PCIBUS3 0x43 // PCAN-PCI interface, channel 3
+#define PCAN_PCIBUS4 0x44 // PCAN-PCI interface, channel 4
+#define PCAN_PCIBUS5 0x45 // PCAN-PCI interface, channel 5
+#define PCAN_PCIBUS6 0x46 // PCAN-PCI interface, channel 6
+#define PCAN_PCIBUS7 0x47 // PCAN-PCI interface, channel 7
+#define PCAN_PCIBUS8 0x48 // PCAN-PCI interface, channel 8
+#define PCAN_PCIBUS9 0x409 // PCAN-PCI interface, channel 9
+#define PCAN_PCIBUS10 0x40A // PCAN-PCI interface, channel 10
+#define PCAN_PCIBUS11 0x40B // PCAN-PCI interface, channel 11
+#define PCAN_PCIBUS12 0x40C // PCAN-PCI interface, channel 12
+#define PCAN_PCIBUS13 0x40D // PCAN-PCI interface, channel 13
+#define PCAN_PCIBUS14 0x40E // PCAN-PCI interface, channel 14
+#define PCAN_PCIBUS15 0x40F // PCAN-PCI interface, channel 15
+#define PCAN_PCIBUS16 0x410 // PCAN-PCI interface, channel 16
+
+#define PCAN_USBBUS1 0x51 // PCAN-USB interface, channel 1
+#define PCAN_USBBUS2 0x52 // PCAN-USB interface, channel 2
+#define PCAN_USBBUS3 0x53 // PCAN-USB interface, channel 3
+#define PCAN_USBBUS4 0x54 // PCAN-USB interface, channel 4
+#define PCAN_USBBUS5 0x55 // PCAN-USB interface, channel 5
+#define PCAN_USBBUS6 0x56 // PCAN-USB interface, channel 6
+#define PCAN_USBBUS7 0x57 // PCAN-USB interface, channel 7
+#define PCAN_USBBUS8 0x58 // PCAN-USB interface, channel 8
+#define PCAN_USBBUS9 0x509 // PCAN-USB interface, channel 9
+#define PCAN_USBBUS10 0x50A // PCAN-USB interface, channel 10
+#define PCAN_USBBUS11 0x50B // PCAN-USB interface, channel 11
+#define PCAN_USBBUS12 0x50C // PCAN-USB interface, channel 12
+#define PCAN_USBBUS13 0x50D // PCAN-USB interface, channel 13
+#define PCAN_USBBUS14 0x50E // PCAN-USB interface, channel 14
+#define PCAN_USBBUS15 0x50F // PCAN-USB interface, channel 15
+#define PCAN_USBBUS16 0x510 // PCAN-USB interface, channel 16
#define PCAN_PCCBUS1 0x61 // PCAN-PC Card interface, channel 1
#define PCAN_PCCBUS2 0x62 // PCAN-PC Card interface, channel 2
@@ -225,7 +241,7 @@ extern "C"
#define PCAN_TYPE_DNG_SJA_EPP 0x06 // PCAN-Dongle EPP SJA1000
// Type definitions
-#define TPCANHandle quint8 // Represents a PCAN hardware channel handle
+#define TPCANHandle quint16 // Represents a PCAN hardware channel handle
#define TPCANStatus quint32 // Represents a PCAN status/error code
#define TPCANParameter quint8 // Represents a PCAN parameter to be read or set
#define TPCANDevice quint8 // Represents a PCAN device
diff --git a/src/plugins/canbus/peakcan/peakcanbackend.cpp b/src/plugins/canbus/peakcan/peakcanbackend.cpp
index eb2d4b9..7959cc0 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend.cpp
+++ b/src/plugins/canbus/peakcan/peakcanbackend.cpp
@@ -72,6 +72,46 @@ bool PeakCanBackend::canCreate(QString *errorReason)
#endif
}
+struct PcanChannel{
+ char name[6];
+ TPCANHandle index;
+};
+PcanChannel pcanChannels[] = {
+ { "usb0", PCAN_USBBUS1 },
+ { "usb1", PCAN_USBBUS2 },
+ { "usb2", PCAN_USBBUS3 },
+ { "usb3", PCAN_USBBUS4 },
+ { "usb4", PCAN_USBBUS5 },
+ { "usb5", PCAN_USBBUS6 },
+ { "usb6", PCAN_USBBUS7 },
+ { "usb7", PCAN_USBBUS8 },
+ { "usb8", PCAN_USBBUS9 },
+ { "usb9", PCAN_USBBUS10 },
+ { "usb10", PCAN_USBBUS11 },
+ { "usb11", PCAN_USBBUS12 },
+ { "usb12", PCAN_USBBUS13 },
+ { "usb13", PCAN_USBBUS14 },
+ { "usb14", PCAN_USBBUS15 },
+ { "usb15", PCAN_USBBUS16 },
+ { "pci0", PCAN_PCIBUS1 },
+ { "pci1", PCAN_PCIBUS2 },
+ { "pci2", PCAN_PCIBUS3 },
+ { "pci3", PCAN_PCIBUS4 },
+ { "pci4", PCAN_PCIBUS5 },
+ { "pci5", PCAN_PCIBUS6 },
+ { "pci6", PCAN_PCIBUS7 },
+ { "pci7", PCAN_PCIBUS8 },
+ { "pci8", PCAN_PCIBUS9 },
+ { "pci9", PCAN_PCIBUS10 },
+ { "pci10", PCAN_PCIBUS11 },
+ { "pci11", PCAN_PCIBUS12 },
+ { "pci12", PCAN_PCIBUS13 },
+ { "pci13", PCAN_PCIBUS14 },
+ { "pci14", PCAN_PCIBUS15 },
+ { "pci15", PCAN_PCIBUS16 },
+ { "none", PCAN_NONEBUS }
+};
+
#if defined(Q_OS_WIN32)
class ReadNotifier : public QWinEventNotifier
{
@@ -286,47 +326,12 @@ bool PeakCanBackendPrivate::setConfigurationParameter(int key, const QVariant &v
}
}
-static int channelIndexFromName(const QString &interfaceName)
-{
- if (interfaceName == QStringLiteral("usb0"))
- return PCAN_USBBUS1;
- else if (interfaceName == QStringLiteral("usb1"))
- return PCAN_USBBUS2;
- else if (interfaceName == QStringLiteral("usb2"))
- return PCAN_USBBUS3;
- else if (interfaceName == QStringLiteral("usb3"))
- return PCAN_USBBUS4;
- else if (interfaceName == QStringLiteral("usb4"))
- return PCAN_USBBUS5;
- else if (interfaceName == QStringLiteral("usb5"))
- return PCAN_USBBUS6;
- else if (interfaceName == QStringLiteral("usb6"))
- return PCAN_USBBUS7;
- else if (interfaceName == QStringLiteral("usb7"))
- return PCAN_USBBUS8;
- else if (interfaceName == QStringLiteral("pci0"))
- return PCAN_PCIBUS1;
- else if (interfaceName == QStringLiteral("pci1"))
- return PCAN_PCIBUS2;
- else if (interfaceName == QStringLiteral("pci2"))
- return PCAN_PCIBUS3;
- else if (interfaceName == QStringLiteral("pci3"))
- return PCAN_PCIBUS4;
- else if (interfaceName == QStringLiteral("pci4"))
- return PCAN_PCIBUS5;
- else if (interfaceName == QStringLiteral("pci5"))
- return PCAN_PCIBUS6;
- else if (interfaceName == QStringLiteral("pci6"))
- return PCAN_PCIBUS7;
- else if (interfaceName == QStringLiteral("pci7"))
- return PCAN_PCIBUS8;
- else // TODO: Add other indexes here
- return PCAN_NONEBUS;
-}
-
-void PeakCanBackendPrivate::setupChannel(const QString &interfaceName)
+void PeakCanBackendPrivate::setupChannel(const QByteArray &interfaceName)
{
- channelIndex = channelIndexFromName(interfaceName);
+ const PcanChannel *chn = pcanChannels;
+ while (chn->index != PCAN_NONEBUS && chn->name != interfaceName)
+ ++chn;
+ channelIndex = chn->index;
}
// Calls only when the device is closed
@@ -434,7 +439,7 @@ PeakCanBackend::PeakCanBackend(const QString &name, QObject *parent)
{
Q_D(PeakCanBackend);
- d->setupChannel(name);
+ d->setupChannel(name.toLatin1());
d->setupDefaultConfigurations();
}
diff --git a/src/plugins/canbus/peakcan/peakcanbackend_p.h b/src/plugins/canbus/peakcan/peakcanbackend_p.h
index 9222b83..032495b 100644
--- a/src/plugins/canbus/peakcan/peakcanbackend_p.h
+++ b/src/plugins/canbus/peakcan/peakcanbackend_p.h
@@ -72,7 +72,7 @@ public:
bool open();
void close();
bool setConfigurationParameter(int key, const QVariant &value);
- void setupChannel(const QString &interfaceName);
+ void setupChannel(const QByteArray &interfaceName);
void setupDefaultConfigurations();
QString systemErrorString(int errorCode);
void startWrite();